Issue Type: Bug Bug
Affects Versions: JRuby 1.7.0.RC2
Assignee: Unassigned
Components: OpenSSL
Created: 17/Oct/12 5:54 PM
Description:

I am hunting down a problem with the multipass gem that started appearing when we switched to jruby. I have narrowed down the problem to jruby generating encrypted data that another openssl implementation (such as MRI Ruby) is unable to decrypt.

See my session below. I encrypt a message in jruby and then successfully decrypt it in jruby. But I am unable to decrypt it in MRI Ruby.

$ rvm use jruby-head
Using /Users/tim/.rvm/gems/jruby-head
$ ruby --version
jruby 1.7.0.RC2 (1.9.3p203) 2012-10-17 10a52b3 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_07-b10 [darwin-x86_64]
$ irb
jruby-1.7.0.RC2 :006 > c = OpenSSL::Cipher::Cipher.new('aes-128-cbc')
 => #<OpenSSL::Cipher::Cipher:0x23a86a12> 
jruby-1.7.0.RC2 :007 > c.encrypt
 => #<OpenSSL::Cipher::Cipher:0x23a86a12> 
jruby-1.7.0.RC2 :008 > c.key = '1234567890123456'
 => "1234567890123456" 
jruby-1.7.0.RC2 :009 > c.padding = 1
 => 1 
jruby-1.7.0.RC2 :010 > encrypted = c.update('secret message') + c.final
 => "\xB4\x15\xE0`\xAC^\xBDq~b.\x96\xB3\xCB$\xD1" 
jruby-1.7.0.RC2 :011 > require 'base64'
 => false 
jruby-1.7.0.RC2 :012 > encoded = Base64.encode64 encrypted
 => "tBXgYKxevXF+Yi6Ws8sk0Q==\n" 
jruby-1.7.0.RC2 :013 > decoded = Base64.decode64 encoded
 => "\xB4\x15\xE0`\xAC^\xBDq~b.\x96\xB3\xCB$\xD1" 
jruby-1.7.0.RC2 :015 > c2 = OpenSSL::Cipher::Cipher.new('aes-128-cbc')
 => #<OpenSSL::Cipher::Cipher:0x73607ba9> 
jruby-1.7.0.RC2 :016 > c2.decrypt
 => #<OpenSSL::Cipher::Cipher:0x73607ba9> 
jruby-1.7.0.RC2 :017 > c2.key = '1234567890123456'
 => "1234567890123456" 
jruby-1.7.0.RC2 :018 > c.padding = 1
 => 1 
jruby-1.7.0.RC2 :019 > c2.padding = 1
 => 1 
jruby-1.7.0.RC2 :020 > decrypted = c2.update(decoded) + c2.final
 => "secret message" 
jruby-1.7.0.RC2 :021 > 

$ rvm use ruby-1.9.3-p194
Using /Users/tim/.rvm/gems/ruby-1.9.3-p194
$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
$ irb
1.9.3p194 :001 > require 'openssl'
 => true 
1.9.3p194 :002 > require 'base64'
 => true 
1.9.3p194 :003 > decoded = Base64.decode64 "tBXgYKxevXF+Yi6Ws8sk0Q==\n"
 => "\xB4\x15\xE0`\xAC^\xBDq~b.\x96\xB3\xCB$\xD1" 
1.9.3p194 :004 > c2 = OpenSSL::Cipher::Cipher.new('aes-128-cbc')
 => #<OpenSSL::Cipher::Cipher:0x007f9843803fa8> 
1.9.3p194 :005 > c2.decrypt
 => #<OpenSSL::Cipher::Cipher:0x007f9843803fa8> 
1.9.3p194 :006 > c2.key = '1234567890123456'
 => "1234567890123456" 
1.9.3p194 :007 > c2.padding = 1
 => 1 
1.9.3p194 :008 > c2.update(decoded) + c2.final
OpenSSL::Cipher::CipherError: bad decrypt
	from (irb):8:in `final'
	from (irb):8
	from /Users/tim/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
1.9.3p194 :009 > 
Environment: jruby 1.7.0.RC2 (1.9.3p203) 2012-10-17 10a52b3 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_07-b10 [darwin-x86_64]
Project: JRuby
Priority: Major Major
Reporter: Tim Olsen
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to