Skip to content

Commit 195d5a8

Browse files
committed
[fix] restore ASN1TaggedObject#getObject compatibility
making it behave the same as with older BC (1.69)
1 parent b8082de commit 195d5a8

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

src/main/java/org/jruby/ext/openssl/ASN1.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ else if ( obj instanceof DERBMPString ) {
10741074

10751075
if ( obj instanceof ASN1TaggedObject ) {
10761076
final ASN1TaggedObject taggedObj = (ASN1TaggedObject) obj;
1077-
IRubyObject val = decodeObject(context, ASN1, taggedObj.getObject());
1077+
IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject());
10781078
IRubyObject tag = runtime.newFixnum( taggedObj.getTagNo() );
10791079
IRubyObject tag_class = runtime.newSymbol("CONTEXT_SPECIFIC");
10801080
final RubyArray valArr = runtime.newArray(val);
@@ -1134,11 +1134,11 @@ public static IRubyObject decode(final ThreadContext context,
11341134
debugStackTrace(context.runtime, e);
11351135
throw context.runtime.newArgumentError(e.getMessage());
11361136
}
1137-
//catch (RuntimeException e) {
1138-
// final Ruby runtime = context.runtime;
1139-
// debugStackTrace(runtime, e);
1140-
// throw Utils.newRuntimeError(context.runtime, e);
1141-
//}
1137+
catch (RuntimeException e) {
1138+
1139+
debugStackTrace(context.runtime, e);
1140+
throw Utils.newRuntimeError(context.runtime, e);
1141+
}
11421142
}
11431143

11441144
static IRubyObject decodeImpl(final ThreadContext context, IRubyObject obj)

src/main/java/org/jruby/ext/openssl/X509Extension.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.bouncycastle.asn1.ASN1EncodableVector;
3939
import org.bouncycastle.asn1.ASN1Encoding;
4040
import org.bouncycastle.asn1.ASN1Integer;
41+
import org.bouncycastle.asn1.ASN1Object;
4142
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
4243
import org.bouncycastle.asn1.ASN1OctetString;
4344
import org.bouncycastle.asn1.ASN1Primitive;
@@ -426,10 +427,10 @@ public RubyString value(final ThreadContext context) {
426427
for ( int i = 0; i < size; i++ ) {
427428
final ASN1Encodable enc = seq.getObjectAt(i);
428429
if (enc instanceof ASN1TaggedObject) {
429-
ASN1Primitive obj = ((ASN1TaggedObject) enc).getObject();
430+
ASN1Primitive obj = ((ASN1TaggedObject) enc).getBaseObject().toASN1Primitive();
430431
switch( ((ASN1TaggedObject) enc).getTagNo() ) {
431432
case 0 :
432-
ASN1Primitive keyid = obj;
433+
ASN1Primitive keyid = obj.toASN1Primitive();
433434
val.append(keyid_);
434435
hexBytes( keyidBytes(keyid), val );
435436
break;
@@ -595,7 +596,7 @@ private RubyString rawValueAsString(final ThreadContext context) throws IOExcept
595596

596597
private static byte[] keyidBytes(ASN1Primitive keyid) throws IOException {
597598
if ( keyid instanceof ASN1TaggedObject ) {
598-
keyid = ((ASN1TaggedObject) keyid).getObject();
599+
keyid = ((ASN1TaggedObject) keyid).getBaseObject().toASN1Primitive();
599600
}
600601
if ( keyid instanceof ASN1OctetString ) {
601602
return ((ASN1OctetString) keyid).getOctets();

src/main/java/org/jruby/ext/openssl/impl/EncContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static EncContent fromASN1(final ASN1Encodable content) {
157157
ec.setContentType( ASN1Registry.oid2nid(contentType) );
158158
ec.setAlgorithm(AlgorithmIdentifier.getInstance(sequence.getObjectAt(1)));
159159
if(sequence.size() > 2 && sequence.getObjectAt(2) instanceof ASN1TaggedObject && ((ASN1TaggedObject)(sequence.getObjectAt(2))).getTagNo() == 0) {
160-
ASN1Encodable ee = ((ASN1TaggedObject)(sequence.getObjectAt(2))).getObject();
160+
ASN1Encodable ee = ((ASN1TaggedObject)(sequence.getObjectAt(2))).getBaseObject().toASN1Primitive();
161161
if ( ee instanceof ASN1Sequence && ((ASN1Sequence) ee).size() > 0 ) {
162162
ByteList combinedOctets = new ByteList();
163163
Enumeration enm = ((ASN1Sequence)ee).getObjects();

src/main/java/org/jruby/ext/openssl/impl/PKCS7.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static PKCS7 fromASN1(ASN1Encodable obj) throws PKCS7Exception {
143143
ASN1Encodable content = size == 1 ? null : ((ASN1Sequence) obj).getObjectAt(1);
144144

145145
if (content != null && content instanceof ASN1TaggedObject && ((ASN1TaggedObject) content).getTagNo() == 0) {
146-
content = ((ASN1TaggedObject) content).getObject();
146+
content = ((ASN1TaggedObject) content).getBaseObject().toASN1Primitive();
147147
}
148148
p7.initiateWith(nid, content);
149149
}

src/main/java/org/jruby/ext/openssl/impl/Signed.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,13 @@ public static Signed fromASN1(ASN1Encodable content) throws PKCS7Exception{
292292
int index = 3;
293293
ASN1Encodable tmp = sequence.getObjectAt(index);
294294
if((tmp instanceof ASN1TaggedObject) && ((ASN1TaggedObject)tmp).getTagNo() == 0) {
295-
certificates = ((ASN1TaggedObject)tmp).getObject();
295+
certificates = ((ASN1TaggedObject)tmp).getBaseObject().toASN1Primitive();
296296
index++;
297297
}
298298

299299
tmp = sequence.getObjectAt(index);
300300
if((tmp instanceof ASN1TaggedObject) && ((ASN1TaggedObject)tmp).getTagNo() == 1) {
301-
crls = ((ASN1TaggedObject)tmp).getObject();
301+
crls = ((ASN1TaggedObject)tmp).getBaseObject().toASN1Primitive();
302302
index++;
303303
}
304304

src/main/java/org/jruby/ext/openssl/x509store/PEMInputOutput.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,8 @@ private static X509AuxCertificate readAuxCertificate(final BufferedReader in, fi
13621362
else trust = Collections.emptyList();
13631363

13641364
if ( obj instanceof ASN1TaggedObject && ((ASN1TaggedObject) obj).getTagNo() == 0 ) {
1365-
reject = new ArrayList<String>();
1366-
final ASN1Sequence rejectSeq = (ASN1Sequence) ((ASN1TaggedObject) obj).getObject();
1365+
final ASN1Sequence rejectSeq = (ASN1Sequence) ((ASN1TaggedObject) obj).getBaseObject().toASN1Primitive();
1366+
reject = new ArrayList<>(rejectSeq.size());
13671367
for( int i = 0; i < rejectSeq.size(); i++ ) {
13681368
reject.add( ((ASN1ObjectIdentifier) rejectSeq.getObjectAt(i)).getId() );
13691369
}
@@ -1387,8 +1387,8 @@ private static X509AuxCertificate readAuxCertificate(final BufferedReader in, fi
13871387
else keyid = null;
13881388

13891389
if ( obj instanceof ASN1TaggedObject && ((ASN1TaggedObject) obj).getTagNo() == 1 ) {
1390-
other = new ArrayList<ASN1Primitive>();
1391-
final ASN1Sequence otherSeq = (ASN1Sequence) ((ASN1TaggedObject) obj).getObject();
1390+
final ASN1Sequence otherSeq = (ASN1Sequence) ((ASN1TaggedObject) obj).getBaseObject().toASN1Primitive();
1391+
other = new ArrayList<>(otherSeq.size());
13921392
for( int i = 0; i < otherSeq.size(); i++ ) {
13931393
other.add( (ASN1Primitive) otherSeq.getObjectAt(i) );
13941394
}

0 commit comments

Comments
 (0)