PKIXNameConstraintValidator NPEs on OtherName
The intersectOtherName method of PKIXNameConstraintValidator appears to fail to to account for null input:
https://github.com/bcgit/bc-java/blob/master/core/src/main/java/org/bouncycastle/asn1/x509/PKIXNameConstraintValidator.java#L511-L518
The next intersection down, intersectEmail, however does:
https://github.com/bcgit/bc-java/blob/master/core/src/main/java/org/bouncycastle/asn1/x509/PKIXNameConstraintValidator.java#L530-L557
In practice, this results in intersectPermittedSubtree throwing NPEs whenever a GeneralSubtree containing a OtherName GeneralName is supplied.
Thanks for the report. I think this is now fixed.
Great! Mind linking where this was fixed?
It's now in the current beta: https://www.bouncycastle.org/betas github should update sometime today as well.
Pulled the latest beta (164b05) to check it out, not seeing a behavior change:
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.x509.*;
public class Main {
public static void main(final String[] args) {
GeneralName name = new GeneralName(GeneralName.otherName, new OtherName(new ASN1ObjectIdentifier("1.1"), DERNull.INSTANCE));
GeneralSubtree subtree = new GeneralSubtree(name);
PKIXNameConstraintValidator validator = new PKIXNameConstraintValidator();
validator.intersectPermittedSubtree(subtree);
}
}
yields:
Exception in thread "main" java.lang.NullPointerException
at java.base/java.util.HashSet.<init>(HashSet.java:119)
at org.bouncycastle.asn1.x509.PKIXNameConstraintValidator.intersectOtherName(PKIXNameConstraintValidator.java:513)
at org.bouncycastle.asn1.x509.PKIXNameConstraintValidator.intersectPermittedSubtree(PKIXNameConstraintValidator.java:169)
at org.bouncycastle.asn1.x509.PKIXNameConstraintValidator.intersectPermittedSubtree(PKIXNameConstraintValidator.java:135)
at Main.main(Main.java:12)
Not seeing any commits that seem relevant in the github mirror or upstream git repo. Any chance this didn't get committed?
Hmmmm... try 164b06 - not sure what happened with 164b05, but 06 passes the example
Sure enough, 164b06 works for me as well. Thanks again!
Hello, this issue seems to be resolved, but now there is an unexpected ClassCastException happening. Still related to PKIXNameConstraintsValidator on OtherName
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.x509.*;
import org.bouncycastle.jce.provider.*;
import org.bouncycastle.jce.provider.PKIXNameConstraintValidator;
public class Main {
public static void main(final String[] args) {
GeneralName name = new GeneralName(GeneralName.otherName, new org.bouncycastle.asn1.x509.OtherName(new ASN1ObjectIdentifier("1.1"), DERNull.INSTANCE));
GeneralSubtree subtree = new GeneralSubtree(name);
PKIXNameConstraintValidator validator = new PKIXNameConstraintValidator();
validator.intersectPermittedSubtree(subtree);
validator.addExcludedSubtree(subtree);
try {
validator.checkExcluded(name);
} catch (PKIXNameConstraintValidatorException e) {
e.printStackTrace();
}
try{
validator.checkPermitted(name);
} catch (PKIXNameConstraintValidatorException e) {
e.printStackTrace();
}
}
}
Results in:
org.bouncycastle.jce.provider.PKIXNameConstraintValidatorException: OtherName is from an excluded subtree.
at org.bouncycastle.jce.provider.PKIXNameConstraintValidator.checkExcluded(Unknown Source)
at Main.main(Main.java:18)
Caused by: org.bouncycastle.asn1.x509.NameConstraintValidatorException: OtherName is from an excluded subtree.
at org.bouncycastle.asn1.x509.PKIXNameConstraintValidator.checkExcludedOtherName(Unknown Source)
at org.bouncycastle.asn1.x509.PKIXNameConstraintValidator.checkExcluded(Unknown Source)
... 2 more
Exception in thread "main" java.lang.ClassCastException: org.bouncycastle.asn1.x509.GeneralSubtree cannot be cast to org.bouncycastle.asn1.x509.OtherName
at org.bouncycastle.asn1.x509.PKIXNameConstraintValidator.checkPermittedOtherName(Unknown Source)
at org.bouncycastle.asn1.x509.PKIXNameConstraintValidator.checkPermitted(Unknown Source)
at org.bouncycastle.jce.provider.PKIXNameConstraintValidator.checkPermitted(Unknown Source)
at Main.main(Main.java:24)
It appears as though checkExcludedNameConstraints appropriately calls OtherName.getInstance, however checkPermittedNameConstraints inappropriately casts resulting in this issue:
https://github.com/bcgit/bc-java/blob/master/core/src/main/java/org/bouncycastle/asn1/x509/PKIXNameConstraintValidator.java#L856-L892
Cut https://github.com/bcgit/bc-java/issues/613 for the above comment.