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

ASN1 wrong tag encoding for explicit or implicit tagged value #122

Open
chrisliaw opened this issue Jan 27, 2017 · 0 comments
Open

ASN1 wrong tag encoding for explicit or implicit tagged value #122

chrisliaw opened this issue Jan 27, 2017 · 0 comments
Labels

Comments

@chrisliaw
Copy link

chrisliaw commented Jan 27, 2017

It does seems that the encoding of ASN1 is wrong during to_der. Simple test as following

require 'openssl'
i = OpenSSL::ASN1::Integer.new(1,1,:explicit). # result is same if :implicit is used
s = OpenSSL::ASN1::Sequence.new(i)
p s

At this stage, result would be correct:

=> #<OpenSSL::ASN1::Sequence:0x45815ffc @value=[#<OpenSSL::ASN1::Integer:0x35a9782c @value=1, @tag=1, @tagging=:explicit, @infinite_length=false, @tag_class=:CONTEXT_SPECIFIC>], @tag=16, @tagging=nil, @infinite_length=false, @tag_class=:UNIVERSAL>

However after convert to der and decode it back, the result is incorrect

ds = s.to_der
dec = OpenSSL::ASN1.decode(ds)
p dec

Decoding result would be:

=> #<OpenSSL::ASN1::Sequence:0x6b00f608 @value=[#<OpenSSL::ASN1::Integer:0x3e821657 @value=#<OpenSSL::BN:0x615091b8>, @tag=2, @tagging=nil, @infinite_length=false, @tag_class=:UNIVERSAL>], @tag=16, @tagging=nil, @infinite_length=false, @tag_class=:UNIVERSAL>

Note the tag_class should be :CONTEXT_SPECIFIC instead :UNIVERSAL as in result above.

Or I understand the standard wrongly?

Feedback is very much appreciated!

Environment:
jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 Java HotSpot(TM) 64-Bit Server VM 25.112-b16 on 1.8.0_112-b16 +jit [darwin-x86_64]


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.

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

No branches or pull requests

2 participants