Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attr_encrypted via encryption throwing "must specify iv" error #205

Open
pkemble opened this issue Jan 2, 2022 · 1 comment
Open

attr_encrypted via encryption throwing "must specify iv" error #205

pkemble opened this issue Jan 2, 2022 · 1 comment
Labels
< v5 v5 of devise-two-factor is a major change to support Rails 7 and beyond

Comments

@pkemble
Copy link

pkemble commented Jan 2, 2022

I have just a very basic devise single user app and i'm trying to implement 2fa. I have the following:

def qrcode(user)
issuer = 'outlet-dev' #TODO environment specific here
label = "#{issuer}:#{current_user.email}"
if user.encrypted_otp_secret.nil?
user.encrypted_otp_secret = User.generate_otp_secret
user.save!
end
qrcode = user.otp_provisioning_uri(label, issuer: issuer)
end

I get a value stored in the 'encrypted_otp_secret' column, but the other two remain empty (encrypted_otp_secret_iv / _salt) which causes the user.otp_provisioning_uri(label, issuer: issuer) part to fail.

Are the iv and salt values supposed to be automatically filled?

devise 4.8.1
devise-two-factor 4.0.1
attr_encrypted 3.1.0
rails 6.1.4.4
ruby 3.0.0

Thanks!

@bsedat bsedat added the < v5 v5 of devise-two-factor is a major change to support Rails 7 and beyond label Jul 8, 2022
@doconnor-clintel
Copy link

This is a bit of a pain. You can redefine attr_encrypted and manually specify an iv:

When you do:

  devise :two_factor_authenticatable,  otp_secret_encryption_key: ......

It does

attr_encrypted :otp_secret, key: '(your key from before)', mode: .... but misses out an octal 12 bit iv: param.

Luckily, you can define this one the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
< v5 v5 of devise-two-factor is a major change to support Rails 7 and beyond
Projects
None yet
Development

No branches or pull requests

3 participants