Skip to content

Improving completeness of ASN1 encoding/decoding #335

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

Merged
merged 11 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
adding basic constructive tests from upstream
commenting out the one I could only half port, as no BC parser supports random tagged objects
  • Loading branch information
HoneyryderChuck committed Jun 30, 2025
commit ab34440b46dbe66f28f65d9bb49c20c84815698f
4 changes: 3 additions & 1 deletion src/main/java/org/jruby/ext/openssl/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,10 @@ private static IRubyObject decodeImpl(final ThreadContext context, final RubyMod
}
final int length = asn1[ ++offset ] & 0xFF;
final boolean isIndefiniteLength = length == 0x80;
IRubyObject decoded;

decoded = decodeObject(context, ASN1, readObject(in));

IRubyObject decoded = decodeObject(context, ASN1, readObject(in));
final boolean isUniversal = ((ASN1Data) decoded).isUniversal(context);

if (isIndefiniteLength) {
Expand Down
34 changes: 13 additions & 21 deletions src/test/ruby/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,27 +553,19 @@ def test_basic_primitive
#

def test_basic_constructed
#octet_string = OpenSSL::ASN1::OctetString.new(B(%w{ AB CD }))
# TODO: Import Issue
# OpenSSL::ASN1::ASN1Error: Constructive shall only be used with indefinite length
#encode_test B(%w{ 20 00 }), OpenSSL::ASN1::Constructive.new([], 0)
#encode_test B(%w{ 21 00 }), OpenSSL::ASN1::Constructive.new([], 1, nil, :UNIVERSAL)
#encode_test B(%w{ A1 00 }), OpenSSL::ASN1::Constructive.new([], 1, nil, :CONTEXT_SPECIFIC)
#encode_test B(%w{ 21 04 04 02 AB CD }), OpenSSL::ASN1::Constructive.new([octet_string], 1)
# Java::JavaLang::UnsupportedOperationException:
# #<OpenSSL::ASN1::Constructive:0x4fc256ec @tag=1, @value=[#<OpenSSL::ASN1::OctetString:0x7fc56d61
# @tag=4, @value="\xAB\xCD", @tag_class=:UNIVERSAL, @tagging=nil, @indefinite_length=false>],
# @tag_class=:CONTEXT_SPECIFIC, @tagging=:EXPLICIT, @indefinite_length=true>
# org.jruby.ext.openssl.ASN1$Constructive.toDER(ASN1.java:1881)
# org.jruby.ext.openssl.ASN1$ASN1Data.to_der(ASN1.java:1414)
# org.jruby.ext.openssl.ASN1$Constructive.to_der(ASN1.java:1858)
#obj = OpenSSL::ASN1::Constructive.new([octet_string], 1)
#obj.indefinite_length = true
#encode_decode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
# (see above) Java::JavaLang::UnsupportedOperationException
#obj = OpenSSL::ASN1::Constructive.new([octet_string, OpenSSL::ASN1::EndOfContent.new], 1)
#obj.indefinite_length = true
#encode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
octet_string = OpenSSL::ASN1::OctetString.new(B(%w{ AB CD }))
encode_test B(%w{ 20 00 }), OpenSSL::ASN1::Constructive.new([], 0)
encode_test B(%w{ 21 00 }), OpenSSL::ASN1::Constructive.new([], 1, nil, :UNIVERSAL)
encode_test B(%w{ A1 00 }), OpenSSL::ASN1::Constructive.new([], 1, nil, :CONTEXT_SPECIFIC)
encode_test B(%w{ 21 04 04 02 AB CD }), OpenSSL::ASN1::Constructive.new([octet_string], 1)
obj = OpenSSL::ASN1::Constructive.new([octet_string], 1)
obj.indefinite_length = true
encode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
# TODO: BC doesn't support decoding indef constructive asn1s from unsupported tag types.
# encode_decode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
obj = OpenSSL::ASN1::Constructive.new([octet_string, OpenSSL::ASN1::EndOfContent.new], 1)
obj.indefinite_length = true
encode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
end

def test_constructive
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy