Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5b9798b

Browse files
committedSep 27, 2023
Replace methods removed in BC 1.75
Several methods and classes were deprecated in BC 1.70 and many of those in the org.bouncycastle.asn1.* were removed in 1.75. This commit moves away from removed method and classes so BouncyCastle can be updated to 1.76.
1 parent 1913525 commit 5b9798b

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed
 

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,14 +1072,16 @@ else if ( obj instanceof DERBMPString ) {
10721072
return ASN1.getClass("ObjectId").newInstance(context, runtime.newString(objId), Block.NULL_BLOCK);
10731073
}
10741074

1075-
if ( obj instanceof ASN1ApplicationSpecific ) { // TODO this will likely break in BC version > 1.71
1076-
final ASN1ApplicationSpecific appSpecific = (ASN1ApplicationSpecific) obj;
1077-
IRubyObject tag = runtime.newFixnum( appSpecific.getApplicationTag() );
1078-
IRubyObject tag_class = runtime.newSymbol("APPLICATION");
1079-
final ASN1Sequence sequence = (ASN1Sequence) appSpecific.getObject(SEQUENCE);
1080-
@SuppressWarnings("unchecked")
1081-
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
1082-
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
1075+
if (obj instanceof ASN1TaggedObject) {
1076+
final ASN1TaggedObject taggedObj = (ASN1TaggedObject) obj;
1077+
if (taggedObj.getTagClass() == BERTags.APPLICATION) {
1078+
IRubyObject tag = runtime.newFixnum( taggedObj.getTagNo() );
1079+
IRubyObject tag_class = runtime.newSymbol("APPLICATION");
1080+
final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(true, SEQUENCE);
1081+
@SuppressWarnings("unchecked")
1082+
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
1083+
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
1084+
}
10831085
}
10841086

10851087
if ( obj instanceof ASN1TaggedObject ) {
@@ -1696,13 +1698,13 @@ ASN1Encodable toASN1(final ThreadContext context) {
16961698
}
16971699

16981700
if ( type == DERGeneralString.class ) {
1699-
return DERGeneralString.getInstance( val.asString().getBytes() );
1701+
return new DERGeneralString( val.asString().toString() );
17001702
}
17011703
if ( type == DERVisibleString.class ) {
1702-
return DERVisibleString.getInstance( val.asString().getBytes() );
1704+
return new DERVisibleString( val.asString().toString() );
17031705
}
17041706
if ( type == DERNumericString.class ) {
1705-
return DERNumericString.getInstance( val.asString().getBytes() );
1707+
return new DERNumericString( val.asString().toString() );
17061708
}
17071709

17081710
if ( val instanceof RubyString ) {

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

Lines changed: 2 additions & 2 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.ASN1IA5String;
4142
import org.bouncycastle.asn1.ASN1Object;
4243
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
4344
import org.bouncycastle.asn1.ASN1OctetString;
@@ -46,7 +47,6 @@
4647
import org.bouncycastle.asn1.ASN1String;
4748
import org.bouncycastle.asn1.ASN1TaggedObject;
4849
import org.bouncycastle.asn1.BERTags;
49-
import org.bouncycastle.asn1.DERIA5String;
5050
import org.bouncycastle.asn1.DEROctetString;
5151
import org.bouncycastle.asn1.DERUniversalString;
5252
import org.bouncycastle.asn1.DLSequence;
@@ -620,7 +620,7 @@ private static boolean formatGeneralName(final GeneralName name, final ByteList
620620
case GeneralName.uniformResourceIdentifier:
621621
if ( ! tagged ) out.append('U').append('R').append('I').
622622
append(':');
623-
val = DERIA5String.getInstance(obj).getString();
623+
val = ASN1IA5String.getInstance(obj).getString();
624624
out.append( ByteList.plain(val) );
625625
break;
626626
case GeneralName.directoryName:

‎src/main/java/org/jruby/ext/openssl/impl/PKey.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import org.bouncycastle.asn1.DLSequence;
6868
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
6969
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
70-
import org.bouncycastle.asn1.sec.ECPrivateKeyStructure;
7170
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
7271
import org.bouncycastle.asn1.x509.DSAParameter;
7372
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;

0 commit comments

Comments
 (0)
Please sign in to comment.