javaglassfishssl-certificatekeytool

java.io.IOException: Illegal footer when importing certificate using keytool


When I try to import my certificate to key store using keytool it shows me:

keytool error: java.security.cert.CertificateException: java.io.IOException: Illegal footer: ----END CERTIFICATE-----
java.security.cert.CertificateException: java.io.IOException: Illegal footer: ----END CERTIFICATE-----
        at sun.security.provider.X509Factory.engineGenerateCertificates(X509Factory.java:337)
        at java.security.cert.CertificateFactory.generateCertificates(CertificateFactory.java:462)
        at sun.security.tools.KeyTool.installReply(KeyTool.java:2571)
        at sun.security.tools.KeyTool.doCommands(KeyTool.java:998)
        at sun.security.tools.KeyTool.run(KeyTool.java:340)
        at sun.security.tools.KeyTool.main(KeyTool.java:333)
Caused by: java.io.IOException: Illegal footer: ----END CERTIFICATE-----
        at sun.security.provider.X509Factory.checkHeaderFooter(X509Factory.java:590)
        at sun.security.provider.X509Factory.readOneBlock(X509Factory.java:575)
        at sun.security.provider.X509Factory.parseX509orPKCS7Cert(X509Factory.java:413)
        at sun.security.provider.X509Factory.engineGenerateCertificates(X509Factory.java:335)
        ... 5 more

I have successfully added CA certificate to my key store without any problem. Can anyone help? Is there any syntax error? I'm using Glassfish 3.1.2.2 with java 7.


Solution

  • Use -----END CERTIFICATE----- instead of ----END CERTIFICATE-----

    Java 7 requies the 5 leading -, java 6 likely did not. See source http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/sun/security/provider/X509Factory.java