Skip to content

OpenSSL::ASN1 der translation inconsistent #119

Closed
@HoneyryderChuck

Description

@HoneyryderChuck

#to_der doesn't seem to be inconsistent encoding context-specific ASN1 data. This is a gist which hopefully demonstrate the issue:

require "openssl"                                           
int = OpenSSL::ASN1::Integer.new(1)                                   
data = OpenSSL::ASN1::ASN1Data.new([int], 1, :CONTEXT_SPECIFIC)       
puts "original asn:"                                                  
puts data.inspect                                                     
der = data.to_der                                                    
puts "der is: #{der.unpack("H*")}"                           
asn = OpenSSL::ASN1.decode der
puts "asn:"                                                           
puts asn.inspect                                                      

Here is the output against jruby 9.1.6.0 (latest stable as of now):

original asn:
#<OpenSSL::ASN1::ASN1Data:0x7cc55834 @tag=1, @tag_class=:CONTEXT_SPECIFIC, @value=[#OpenSSL::ASN1::Integer:0x37a54f5e @tag=2, @tag_class=:UNIVERSAL, @tagging=nil, @value=1, infinite_length=false>]>
der is: ["810101"]
asn:
#<OpenSSL::ASN1::ASN1Data:0x434a314e @tag=1, @tag_class=:CONTEXT_SPECIFIC, @value=[#OpenSSL::ASN1::OctetString:0x4811fb9e @tag=4, @tag_class=:UNIVERSAL, @tagging=nil, value="\x01", @infinite_length=false>]>

which shows that the original asn can't be encoded and decoded into the same structure.

Here's the output with MRI 2.1:

original asn:                                                                                                         
#<OpenSSL::ASN1::ASN1Data:0x007fb5b8e8dcb0 @tag=1, @value=[#OpenSSL::ASN1::Integer:0x007fb5b8e8dd00 @tag=2, @value=1, @tagging=nil, @tag_class=:UNIVERSAL, @infinite_length=false>], @tag_class=:CONTEXT_SPECIFIC, infinite_length=false> 
der is: ["a103020101"]                                                                                                
asn:                                                                                                                  
#<OpenSSL::ASN1::ASN1Data:0x007fb5b8e8d288 @tag=1, @value=[#OpenSSL::ASN1::Integer:0x007fb5b8e8d2b0 @tag=2, @value=#<OpenSSL::BN:0x007fb5b8e8d2d8>, @tagging=nil, @tag_class=:UNIVERSAL, @infinite_length=false>], tag_class=:CONTEXT_SPECIFIC, @infinite_length=false>              

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions