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

Fix applying DES-CBC when using OpenSSL 3 #51

Merged
merged 1 commit into from
May 4, 2022

Conversation

paulvt
Copy link
Contributor

@paulvt paulvt commented May 4, 2022

After calling #final on the cipher object, it will return garbage from that moment forward. The cipher object can therefore not be reused in the iteration over keys. Reinitialize it everytime instead.

This seems to be new behaviour in Ruby/OpenSSL3. See also:
https://ruby.github.io/openssl/OpenSSL/Cipher.html#class-OpenSSL::Cipher-label-Calling+Cipher-23final

This fixes #50.

After calling `#final` on the cipher object, it will return garbage from
that moment forward. The cipher object can therefore not be reused in
the iteration over keys. Reinitialize it everytime instead.

This seems to be new behaviour in Ruby/OpenSSL3. See also:
https://ruby.github.io/openssl/OpenSSL/Cipher.html#class-OpenSSL::Cipher-label-Calling+Cipher-23final
@mwrock mwrock merged commit 72163c5 into WinRb:master May 4, 2022
@paulvt paulvt deleted the fix-apply-des-openssl branch May 4, 2022 20:23
@adfoster-r7
Copy link

adfoster-r7 commented Jul 20, 2022

We're hitting this issue with one of our Ruby gems too 👍

The work around I had before finding this pull request was:

       def apply_des(plain, keys)
         dec = OpenSSL::Cipher.new("des-cbc").encrypt
         dec.padding = 0
         keys.map {|k|
+          dec.reset
+          dec.iv = "\x00" * 8
           dec.key = k
           dec.update(plain) + dec.final
         }
       end

@adfoster-r7
Copy link

Ah, it doesn't look like this patch is available in the latest rubyntlm release on RubyGems

@mwrock It'd be great if this could be released as a patch version, let me know if I can help in anyway 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests fails on Ruby 3/OpenSSL 3
3 participants