Skip to content

Commit a2800e6

Browse files
committed
Added system property to ignore with faulty extension bytes in OIDs. Relates to github #1758
1 parent 489ff7c commit a2800e6

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

core/src/main/java/org/bouncycastle/asn1/ASN1RelativeOID.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.concurrent.ConcurrentMap;
88

99
import org.bouncycastle.util.Arrays;
10+
import org.bouncycastle.util.Properties;
1011

1112
public class ASN1RelativeOID
1213
extends ASN1Primitive
@@ -254,7 +255,12 @@ static boolean isValidContents(byte[] contents)
254255
for (int i = 0; i < contents.length; ++i)
255256
{
256257
if (subIDStart && (contents[i] & 0xff) == 0x80)
257-
return false;
258+
{
259+
if (!Properties.isOverrideSet("org.bouncycastle.asn1.allow_wrong_oid_enc"))
260+
{
261+
return false;
262+
}
263+
}
258264

259265
subIDStart = (contents[i] & 0x80) == 0;
260266
}

core/src/test/java/org/bouncycastle/asn1/test/ObjectIdentifierTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.bouncycastle.asn1.test;
22

33
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
4+
import org.bouncycastle.util.encoders.Hex;
45
import org.bouncycastle.util.test.SimpleTest;
56
import org.bouncycastle.util.test.TestResult;
67

@@ -24,7 +25,24 @@ public void performTest()
2425
{
2526
isEquals("invalid OID contents", e.getMessage());
2627
}
27-
28+
29+
byte[] faultyOID = Hex.decode("06092A864886FC6B048000");
30+
try
31+
{
32+
ASN1ObjectIdentifier.getInstance(faultyOID);
33+
fail("no exception");
34+
}
35+
catch (Exception e)
36+
{
37+
isEquals("failed to construct object identifier from byte[]: invalid OID contents", e.getMessage());
38+
}
39+
40+
System.setProperty("org.bouncycastle.asn1.allow_wrong_oid_enc", "true");
41+
String oid = ASN1ObjectIdentifier.getInstance(faultyOID).getId();
42+
43+
System.clearProperty("org.bouncycastle.asn1.allow_wrong_oid_enc");
44+
isEquals("1.2.840.114283.4.0", oid);
45+
2846
// exercise the object cache
2947
for (int i = 0; i < 100; i++)
3048
{

0 commit comments

Comments
 (0)