Error Importing Certificate file Using Keytool
Hello Folks
I am trying to import a certificate file provided by our Ldap Admin,
I get the following error
Please let me know if you have an idea why am i getting it.
Does the size of the Key file matter ? it s around 4kb
C:\j2sdk1.4.2_08\jre\lib\security>keytool -import -alias ldapsecurity -trustcace
rts -file SOTROOT.cer -storepass changeit -noprompt -keystore ldapstore
sun.security.pkcs.ParsingException: X509.ObjectIdentifier() -- data isn't an obj
ect ID (tag = 48)
at sun.security.pkcs.PKCS7.parse(PKCS7.java:118)
at sun.security.pkcs.PKCS7.<init>(PKCS7.java:68)
at sun.security.provider.X509Factory.parseX509orPKCS7Cert(X509Factory.ja
va:530)
at sun.security.provider.X509Factory.engineGenerateCertificates(X509Fact
ory.java:407)
at java.security.cert.CertificateFactory.generateCertificates(Certificat
eFactory.java:511)
at sun.security.tools.KeyTool.installReply(KeyTool.java:1193)
at sun.security.tools.KeyTool.doCommands(KeyTool.java:504)
at sun.security.tools.KeyTool.run(KeyTool.java:124)
at sun.security.tools.KeyTool.main(KeyTool.java:118)
Caused by: java.io.IOException: X509.ObjectIdentifier() -- data isn't an object
ID (tag = 48)
at sun.security.util.ObjectIdentifier.<init>(ObjectIdentifier.java:134)
at sun.security.util.DerInputStream.getOID(DerInputStream.java:250)
at sun.security.pkcs.ContentInfo.<init>(ContentInfo.java:120)
at sun.security.pkcs.PKCS7.parse(PKCS7.java:136)
at sun.security.pkcs.PKCS7.parse(PKCS7.java:115)
... 8 more
keytool error: java.security.cert.CertificateException: X509.ObjectIdentifier()
-- data isn't an object ID (tag = 48)
Thanks
Surendra
# 1
Is your certificate binary or ASCII? If ASCII, please make sure that the first and last line of it all starts with "--". Some certificate has extra descriptions before the real data, they must be removed before feeding to keytool.
# 2
This is how my certificate file looks like--BEGIN CERTIFICATE--####################################--END CERTIFICATE--
# 3
Can i Import a public key with RSA (4096 bits ) into the KeyStore Will it cause any problem. Is that the cause of the exception ?
What do i need to do if i am provided with such kind of certificate ?
Does the certificate needs to be reissued so that a 1024 Bit private key(keyEntry) can be generated.
Thanks and appreciate your response
Surendra
# 4
When keytool tries to do a certificate import, it first tries the X.509 format, and then the PKCS 7 format. Looking at your error output, keytool already goes to the 2nd phase (trying PKCS 7). However, the BEGIN CERTIFICATE- shows it should be more likely an X.509 format, and the error message shows the 1st byte is 48, which looks even more likely an X.509.
So I suspect the file is X.509 but the parsing process has some error and keytool fallback to PKCS7. Can you try "keytool -printcert" your file? This should reveal the X.509 parsing error.
# 5
Just see your new post, I don't think it's the 4096 reason.
# 6
It failed the printcert command So its failing the second step in the PKCS7 parsing.
C:\j2sdk1.4.2_08\jre\lib\security>keytool -printcert -file SOTROOT.cer
sun.security.pkcs.ParsingException: X509.ObjectIdentifier() -- data isn't an obj
ect ID (tag = 48)
at sun.security.pkcs.PKCS7.parse(PKCS7.java:118)
at sun.security.pkcs.PKCS7.<init>(PKCS7.java:68)
at sun.security.provider.X509Factory.parseX509orPKCS7Cert(X509Factory.ja
va:530)
at sun.security.provider.X509Factory.engineGenerateCertificates(X509Fact
ory.java:407)
at java.security.cert.CertificateFactory.generateCertificates(Certificat
eFactory.java:511)
at sun.security.tools.KeyTool.doPrintCert(KeyTool.java:1021)
at sun.security.tools.KeyTool.doCommands(KeyTool.java:539)
at sun.security.tools.KeyTool.run(KeyTool.java:124)
at sun.security.tools.KeyTool.main(KeyTool.java:118)
Caused by: java.io.IOException: X509.ObjectIdentifier() -- data isn't an object
ID (tag = 48)
at sun.security.util.ObjectIdentifier.<init>(ObjectIdentifier.java:134)
at sun.security.util.DerInputStream.getOID(DerInputStream.java:250)
at sun.security.pkcs.ContentInfo.<init>(ContentInfo.java:120)
at sun.security.pkcs.PKCS7.parse(PKCS7.java:136)
at sun.security.pkcs.PKCS7.parse(PKCS7.java:115)
... 8 more
keytool error: java.lang.Exception: Failed to parse input
# 7
Sorry, I didn't realize that printcert also try the PKCS 7 format. Can you try this little program? http://www.exampledepot.com/egs/java.security.cert/ImportCert.html
# 8
I am getting the following exceptionCertificate Exception :java.security.cert.CertificateParsingException: java.io.IOException: subject key, Unknown key spec: Invalid RSA modulus size.
# 9
Can you show the full stack trace for the exception?
# 10
java.security.cert.CertificateParsingException: java.io.IOException: subject key, Unknown key spec: Invalid RSA modulus size.
at sun.security.x509.X509CertInfo.<init>(X509CertInfo.java:155)
at sun.security.x509.X509CertImpl.parse(X509CertImpl.java:1679)
at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:173)
at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:101)
at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:389)
at us.tn.state.trust.service.LDAPTest.importCertificate(LDAPTest.java:31)
at us.tn.state.trust.service.LDAPTest.main(LDAPTest.java:19)
Caused by: java.io.IOException: subject key, Unknown key spec: Invalid RSA modulus size.
at sun.security.x509.X509Key.parse(X509Key.java:155)
at sun.security.x509.CertificateX509Key.<init>(CertificateX509Key.java:58)
at sun.security.x509.X509CertInfo.parse(X509CertInfo.java:706)
at sun.security.x509.X509CertInfo.<init>(X509CertInfo.java:153)
... 6 more
# 11
Can you post your cert here?
# 12
--BEGIN CERTIFICATE--
MIIHezCCBWOgAwIBAgIQEdE5AWMMyrJKS9NSM4/mTjANBgkqhkiG9w0BAQUFADCB
hzESMBAGCgmSJomT8ixkARkWAnVzMRIwEAYKCZImiZPyLGQBGRYCdG4xFTATBgoJ
kiaJk/IsZAEZFgVzdGF0ZTETMBEGCgmSJomT8ixkARkWA2FkczExMC8GA1UEAxMo
U3RhdGUgb2YgVGVubmVzc2VlIE9JUiBMQU4gRW50ZXJwcmlzZSBDQTAeFw0wNTA3
MjIxNzMyMzRaFw0yNTA3MjIxNzM5MDBaMIGHMRIwEAYKCZImiZPyLGQBGRYCdXMx
EjAQBgoJkiaJk/IsZAEZFgJ0bjEVMBMGCgmSJomT8ixkARkWBXN0YXRlMRMwEQYK
CZImiZPyLGQBGRYDYWRzMTEwLwYDVQQDEyhTdGF0ZSBvZiBUZW5uZXNzZWUgT0lS
IExBTiBFbnRlcnByaX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ERTIFICATE--
# 13
Have a search in JDK 1.4.2 doc and read the restriction here -- http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html#AppESeems you have to use a later version.
# 14
The problem is with the version of the JDK i downloaded 1.5.0_12 and no restrictions version of the JCE.Thanks for your responses.