Jopenssl encryption is not correct, can not decrypt afterwards
--------------------------------------------------------------

                 Key: JRUBY-4028
                 URL: http://jira.codehaus.org/browse/JRUBY-4028
             Project: JRuby
          Issue Type: Bug
          Components: OpenSSL
    Affects Versions: JRuby-OpenSSL 0.5.2
         Environment: Mac Jruby 1.3.1 Openssl 0.5.2
            Reporter: Anthony Lai
            Priority: Blocker
             Fix For: JRuby-OpenSSL 0.5.2


I am running jopenssl 0.5.2, the encrypted data result is different than using 
ruby openssl.  Not only that, jopenssl will throws an error when trying to 
decrypt the data.  This is working fine with ruby/openssl.  The cipher I used 
is DES-CBC with no padding.  Test case along with results for both ruby and 
jruby are show below

 Setting it to blocker as this affects our release.  Please kindly help as we 
have a very tight deadline to meet and this is a show-stopper for us. 

Test case for irb
===========
irb
require 'openssl'
key =  "0599E113A7EE32A9"
data = 
"1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
c1 = OpenSSL::Cipher::Cipher.new("DES-CBC")
c1.padding = 0
c1.encrypt
c1.key = key
e = c1.update data
e << c1.final

c2 = OpenSSL::Cipher::Cipher.new("DES-CBC")
c2.padding = 0
c2.decrypt
c2.key = key
d = c2.update e
d << c2.final

Test case for Jruby irb (same as above but using jruby/jopenssl)
===============
jruby -S irb
require 'openssl'
key =  "0599E113A7EE32A9"
data = 
"1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
c1 = OpenSSL::Cipher::Cipher.new("DES-CBC")
c1.padding = 0
c1.encrypt
c1.key = key
e = c1.update data
e << c1.final

c2 = OpenSSL::Cipher::Cipher.new("DES-CBC")
c2.padding = 0
c2.decrypt
c2.key = key
d = c2.update e
d << c2.final



Result from irb (Correct behavior, can encrypt and decrypt the data 
successfully using the same key)
===========================
irb
irb(main):001:0> require 'openssl'
=> true
irb(main):002:0> key =  "0599E113A7EE32A9"
=> "0599E113A7EE32A9"
irb(main):003:0> data = 
"1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
=> 
"1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
irb(main):004:0>
irb(main):005:0* c1 = OpenSSL::Cipher::Cipher.new("DES-CBC")
=> #<OpenSSL::Cipher::Cipher:0x101211f68>
irb(main):006:0> c1.padding = 0
=> 0
irb(main):007:0> c1.encrypt
=> #<OpenSSL::Cipher::Cipher:0x101211f68>
irb(main):008:0> c1.key = key
=> "0599E113A7EE32A9"
irb(main):009:0> e = c1.update data
=> 
"Bh\267\365\303\203\212\317\255+(\332=1#x\366\252\336\331\213\031:\274\244\222\357n7\233\233\223]\342TN\202RC10\250\2458\204\347!\270l,\357\352\357\315\303\341L\001\373\244\023\304h03\272\246\"\342\213\256\314\240\340\272YS\375\306\026\306\366\220k\t\346Z\0302\2442\263\336\315\277q\271\255\001:\017I\201\351\177\a\264\352>\003\252k\330\245\362\332\205Si[P\206\323\256\322\034l\325"
irb(main):010:0> e << c1.final
=> 
"Bh\267\365\303\203\212\317\255+(\332=1#x\366\252\336\331\213\031:\274\244\222\357n7\233\233\223]\342TN\202RC10\250\2458\204\347!\270l,\357\352\357\315\303\341L\001\373\244\023\304h03\272\246\"\342\213\256\314\240\340\272YS\375\306\026\306\366\220k\t\346Z\0302\2442\263\336\315\277q\271\255\001:\017I\201\351\177\a\264\352>\003\252k\330\245\362\332\205Si[P\206\323\256\322\034l\325"
irb(main):011:0>
irb(main):012:0* c2 = OpenSSL::Cipher::Cipher.new("DES-CBC")
=> #<OpenSSL::Cipher::Cipher:0x1011ddba0>
irb(main):013:0> c2.padding = 0
=> 0
irb(main):014:0> c2.decrypt
=> #<OpenSSL::Cipher::Cipher:0x1011ddba0>
irb(main):015:0> c2.key = key
=> "0599E113A7EE32A9"
irb(main):016:0> d = c2.update e
=> 
"1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
irb(main):017:0> d << c2.final
=> 
"1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
irb(main):018:0>

Result from Jruby irb (incorrect behavior, errors out when trying to decrypt 
using the same key)
=================
jruby -S irb
irb(main):001:0> require 'openssl'
=> true
irb(main):002:0> key =  "0599E113A7EE32A9"
=> "0599E113A7EE32A9"
irb(main):003:0> data = 
"1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
=> 
"1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
irb(main):004:0>
irb(main):005:0* c1 = OpenSSL::Cipher::Cipher.new("DES-CBC")
=> #<OpenSSL::Cipher::Cipher:0x294ff81a>
irb(main):006:0> c1.padding = 0
=> 0
irb(main):007:0> c1.encrypt
=> #<OpenSSL::Cipher::Cipher:0x294ff81a>
irb(main):008:0> c1.key = key
=> "0599E113A7EE32A9"
irb(main):009:0> e = c1.update data
=> 
"X\235\274\373\261M\273rP\e(\320\322e\371fJH1\213\350\234a\004\361\211\350>2\345\000\354`\272\032!?\270W\275\221\025\241I\253Y\207\330\324c!\370\332\211\273*\275\323\227TB\217\376\324i\fv\357l}\305)\341\tT\330\230l\332\250\227h\202/!\366UZ\202
 
c\0358\362\03165\335\027\304\317\211\202\347\236\031\352\345\375\004o%\025w\350\375\265\e\005C\374\b9\325\334T\267\270"
irb(main):010:0> e << c1.final
=> 
"X\235\274\373\261M\273rP\e(\320\322e\371fJH1\213\350\234a\004\361\211\350>2\345\000\354`\272\032!?\270W\275\221\025\241I\253Y\207\330\324c!\370\332\211\273*\275\323\227TB\217\376\324i\fv\357l}\305)\341\tT\330\230l\332\250\227h\202/!\366UZ\202
 
c\0358\362\03165\335\027\304\317\211\202\347\236\031\352\345\375\004o%\025w\350\375\265\e\005C\374\b9\325\334T\267\270"
irb(main):011:0>
irb(main):012:0* c2 = OpenSSL::Cipher::Cipher.new("DES-CBC")
=> #<OpenSSL::Cipher::Cipher:0x62c639ce>
irb(main):013:0> c2.padding = 0
=> 0
irb(main):014:0> c2.decrypt
=> #<OpenSSL::Cipher::Cipher:0x62c639ce>
irb(main):015:0> c2.key = key
=> "0599E113A7EE32A9"
irb(main):016:0> d = c2.update e
OpenSSL::Cipher::CipherError: No message available
   from (irb):17
irb(main):017:0> d << c2.final
OpenSSL::Cipher::CipherError: Cipher not initialized
   from (irb):18
irb(main):018:0> 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
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