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

OpenSSL::ASN1.decode yields OpenSSL::ASN1::Integer instances with a "value" attribute type of OpenSSL::BN #176

Closed
CBonnell opened this issue Dec 13, 2017 · 1 comment

Comments

@CBonnell
Copy link

In OpenSSL gem 2.0.6 (using Ruby 2.4.2) and as far back as Ruby 2.2.1 (if not earlier), creating OpenSSL::ASN1::Integer instances using OpenSSL::ASN1.decode produces instances whose value attribute is of type OpenSSL::BN, not Number (which should probably be documented as Integer) as documented on the docs page for OpenSSL::ASN1::Primitive (http://ruby-doc.org/stdlib-2.4.2/libdoc/openssl/rdoc/OpenSSL/ASN1/Primitive.html).

Either OpenSSL::ASN1.decode should be modified to return OpenSSL::ASN1::Integer instances whose value attribute is of type Integer, not OpenSSL::BN. If this is not palatable from a backwards compatibility standpoint, this discrepancy should at least be documented.

Code to reproduce:

require 'openssl'
puts OpenSSL::ASN1.decode("\x02\x01\x05").value.inspect
puts OpenSSL::ASN1::Integer.new(5).value.inspect

Expected output:

5
5

Actual output:

#OpenSSL::BN:0x007fe7818061f8
5

@CBonnell CBonnell changed the title OpenSSL::ASN1.decode yields OpenSSL::ASN1.Integer instances with a "value" attribute type of OpenSSL:BN OpenSSL::ASN1.decode yields OpenSSL::ASN1::Integer instances with a "value" attribute type of OpenSSL:BN Dec 13, 2017
@CBonnell CBonnell changed the title OpenSSL::ASN1.decode yields OpenSSL::ASN1::Integer instances with a "value" attribute type of OpenSSL:BN OpenSSL::ASN1.decode yields OpenSSL::ASN1::Integer instances with a "value" attribute type of OpenSSL::BN Dec 13, 2017
@rhenium
Copy link
Member

rhenium commented Dec 14, 2017

This behavior goes all the way back to Ruby 1.8.1 in 2003, when OpenSSL::ASN1 was initially introduced. It's not possible to change that because of compatibility. I'll fix the docs.

Regarding OpenSSL::ASN1::Integer.new(5).value returning Integer: it is because OpenSSL::ASN1::Primitive#initialize does not perform type checking. OpenSSL::ASN1::ASN1Data#value simply returns the value.

rhenium added a commit that referenced this issue Dec 14, 2017
The value of 'value' attribute of OpenSSL::ASN1::{Integer,Enumerated}
should be an instance of OpenSSL::BN.

Reference: #176
@rhenium rhenium closed this as completed Dec 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants