I am trying to create a certification request ( to eventually generateCSR) using challenge passcode which I get from a SCEP server. But there is some issue with the attrs object and so the certification request is not getting created.
The code I wrote-
ASN1Encodable[] attrValues = new ASN1Encodable[1];
attrValues[0] = new Attribute(PKCSObjectIdentifiers.pkcs_9_at_challengePassword, new DERSet(new DERPrintableString(challenge)));
ASN1Set attrs = new DERSet(attrValues);
CertificationRequestInfo requestInfo = new CertificationRequestInfo(new X500Name(subject), pkInfo, attrs);
The error Im getting-
Exception in thread "main" java.lang.IllegalArgumentException: unknown object in factory: org.bouncycastle.asn1.x509.Attribute
at org.bouncycastle.asn1.pkcs.Attribute.getInstance(Attribute.java:37)
at org.bouncycastle.asn1.pkcs.CertificationRequestInfo.validateAttributes(CertificationRequestInfo.java:159)
at org.bouncycastle.asn1.pkcs.CertificationRequestInfo.<init>(CertificationRequestInfo.java:81)
I put empty DERSet instead of attrs the CSR gets generated- CertificationRequestInfo requestInfo = new CertificationRequestInfo(new X500Name(subject), pkInfo, new DERSet());
Can some please tell me where I'm going wrong?
You are using (probably due to an import
) org.bouncycastle.asn1.x509.Attribute
instead of org.bouncycastle.asn1.pkcs.Attribute
. Although implementing the same functionality (and I'm not sure why it is duplicated), these are different classes.