Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

java.lng.Exception: `Input not an X.509 certificate` when importing .pem certificate

Posted on 2016-07-21
4
Medium Priority
?
228 Views
Last Modified: 2016-07-27
I have created a self-signed certificate with makecert, exported it with private key to .pfx file and imported on the server. Then I copied one on the client and tried importing it using keytool. Got an error `Input is not an X.509 certificate`.
So I converted .pfx  certificate to .pem using openssl and tried again - same result.

I did some research and found that I might need to convert it to .der, but it still might not work. Apparently keytool only supports single certificate PEM files. Even though mine is a single certificate, PEM file contains private key information:
    -----BEGIN PRIVATE KEY----
    -----END PRIVATE KEY------


    ----BEGIN CERTIFICATE-----
    ----END CERTIFICATE-------

Open in new window

So I am not sure what should be my next step to ensure import will work when done with keytool on the client.
Can anyone shed some light on this issue?
0
Comment
Question by:YZlat
  • 2
  • 2
4 Comments
 
LVL 65

Expert Comment

by:btan
ID: 41724566
I suggest either you try the online conversion for the sake of testing since it is development key or use openssl
Convert a DER file (.crt .cer .der) to PEM openssl x509 -inform der -in certificate.cer -out certificate.pem

•Convert a PEM file to DER openssl x509 -outform der -in certificate.pem -out certificate.der

•Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

You can add -nocerts to only output the private key or add -nokeys to only output the certificates.
https://www.sslshopper.com/article-most-common-openssl-commands.html
0
 
LVL 65

Expert Comment

by:btan
ID: 41724572
For clarity of PEM and DER which the latter is used for Java platform which is what you are looking at.
The PEM format is usually having extensions such as .pem, .crt, .cer, and .key. They are Base64 encoded ASCII files and contain "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" statements. Server certificates, intermediate certificates, and private keys can all be put into the PEM format.


The DER format is simply a binary form of a certificate instead of the ASCII PEM format. It sometimes has a file extension of .der but it often has a file extension of .cer so the only way to tell the difference between a DER .cer file and a PEM .cer file is to open it in a text editor and look for the BEGIN/END statements. All types of certificates and private keys can be encoded in DER format. DER is typically used with Java platforms.
https://www.sslshopper.com/ssl-converter.html
0
 
LVL 35

Accepted Solution

by:
YZlat earned 0 total points
ID: 41724581
The solution was much simpler - I opened the file in text editor and deleted everything except the lines in between

----BEGIN CERTIFICATE-----
    ----END CERTIFICATE-------

the client machine should not have a private key. So after removing private key and other lines it worked with keytool
0
 
LVL 35

Author Closing Comment

by:YZlat
ID: 41730942
solved it myself
0

Featured Post

Cyber Threats to Small Businesses (Part 2)

The evolving cybersecurity landscape presents SMBs with a host of new threats to their clients, their data, and their bottom line. In part 2 of this blog series, learn three quick processes Webroot’s CISO, Gary Hayslip, recommends to help small businesses beat modern threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are like me and like multiple layers of protection, read on!
Phishing emails are a popular malware delivery vehicle for attack.  While there are many ways for an attacker to increase the chances of success for their phishing emails, one of the most effective methods involves spoofing the message to appear to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question