开发者

Bouncycastle: CertificateFactory.generateCertificate gives "sequence wrong size for a certificate" on one machine but not on another

I’m trying to open a p7b file and read the CA certificates out of it. Below is my code. It works fine in one machine but in another machine the call to certFactory.generateCertificate throws exception

Error Message:java.lang.IllegalArgumentException: sequence w开发者_开发知识库rong size for a certificate

On both machines I have the same p7b file, and the same bouncycastle jars. The machine where is works is a Windows Xp and the one where it doesn’t work is a Windows 2007 server machine. It is a 64 bit machine but I’m using the 32 bit jvm only.

    CertificateFactory certFactory = CertificateFactory.getInstance("X.509",
            new BouncyCastleProvider());
    java.security.cert.Certificate cert = null;
    FileInputStream inStream = new FileInputStream("");
    ArrayList<java.security.cert.Certificate> certificates = new ArrayList<java.security.cert.Certificate>();
    CAService caService = null;
    caService.getCertificateAuthority().setCaCerts(new ArrayList<String>());

    while ((cert = certFactory.generateCertificate(inStream)) != null)
    {
        certificates.add(cert);
        StringWriter swrtr = new StringWriter();
        PEMWriter writer = new PEMWriter(swrtr);
        writer.writeObject(cert);
        writer.flush();
        caService.getCertificateAuthority().getCaCerts().add(swrtr.toString());
    }

I even wrote a standalone program and I’m running even explicitly specifying the java.exe to use but I’m facing the same exception on that machine alone.

c:\jdk1.5.0_14\jre\bin\java.exe -classpath .;bcprov-jdk15-143.jar MSCAConfigurator

Exception in thread "main" java.security.cert.CertificateException: java.lang.IllegalArgumentException: sequence wrong size for a certificate
        at org.bouncycastle.jce.provider.JDKX509CertificateFactory.engineGenerateCertificate(Unknown Source)
        at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:271)
        at MSCAConfigurator.main(MSCAConfigurator.java:31)
Caused by: java.lang.IllegalArgumentException: sequence wrong size for a certificate
        at org.bouncycastle.asn1.x509.X509CertificateStructure.<init>(Unknown Source)
        at org.bouncycastle.asn1.x509.X509CertificateStructure.getInstance(Unknown Source)
        at org.bouncycastle.jce.provider.JDKX509CertificateFactory.readPEMCertificate(Unknown Source)

I have the unlimited strength policy jars present.

C:\jdk1.5.0_14\jre\lib\security>dir *.jar

Volume in drive C has no label.

Volume Serial Number is D214-CB94

Directory of C:\jdk1.5.0_14\jre\lib\security

09/13/2004 04:12 PM 2,486 local_policy.jar

09/13/2004 04:12 PM 2,472 US_export_policy.jar

What’s wrong with this machine? Someone please help before I shoot myself.


Cross-posted and apparently resolved the issue here http://www.coderanch.com/t/528193/Security/CertificateFactory-generateCertificate-gives-sequence-wrong


According to the javadocs, CertificateFactory.generateCertificates() support the PKCS#7 format but CertificateFactory.generateCertificate() does not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜