0

I have a file which contains:

-----BEGIN CERTIFICATE-----
(many lines of 64 bytes)
-----END CERTIFICATE-----

I use keytool.exe -printcert -file (myfile) it outputs like this

Certificate[1]:
Owner: CN=www.mydomain.xxxxxx  

(bah bah bah............)  
(bah bah bah............)  

Certificate[2]:
Owner: CN=Thawte SSL CA, O="Thawte, Inc.", C=US  

(bah bah bah............)  
(bah bah bah............)  

Certificate[3]:
Owner: CN=thawte Primary Root CA, OU="(c) 2006 thawte, Inc. - For authorized use only", OU=Certification Services Division, O="thawte, Inc.", C=US  

(bah bah bah............)  
(bah bah bah............)  

Is it normal that it contains 3 certs?
Is it called cert chain?
What can I do if I want to import this file to a keystore?
I've tried over and over again using

keytool.exe -import -alias (myalias) -trustcacerts -file (thisfile)  -keystore (mykeystore)`  

but it keeps telling me

 java.lang.Exception: Input not an X.509 certificate
dawud
  • 15,096
  • 3
  • 42
  • 61

1 Answers1

1

The keytool requires certificate chains to be provided in PKCS#7 format (usually .p7b file extension) but you have it as a PEM file (which is rather used by software like Apache, nginx etc.).

From the keytool manual (-importcert option):

-importcert:
Reads the certificate or certificate chain (where the latter is supplied in a PKCS#7 formatted reply) ...


To convert the file you can use the openssl utility (if you have it at hand):

openssl crl2pkcs7 -certfile cert.pem -out cert.p7b -nocrl

Where cert.pem is your current certificate file and cert.p7b the one to use for the import.

Lukas
  • 1,004
  • 6
  • 14
  • I get error --> error reading the file, (my file).pem error loading certificates 4700:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1304: 4700:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:380:Type=X509_CINF 4700:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:748:Field=cert_info, Type=X509 4700:error:0907400D:PEM routines:PEM_X509_INFO_read_bio:ASN1 lib:pem_info.c:256: –  Aug 22 '13 at 04:13