How to import a .cer certificate into a java keystore?

后端 未结 8 930
有刺的猬
有刺的猬 2020-11-22 15:38

During the development of a Java webservice client I ran into a problem. Authentication for the webservice is using a client certificate, a username and a password. The clie

8条回答
  •  难免孤独
    2020-11-22 16:25

    The certificate that you already have is probably the server's certificate, or the certificate used to sign the server's certificate. You will need it so that your web service client can authenticate the server.

    But if additionally you need to perform client authentication with SSL, then you need to get your own certificate, to authenticate your web service client. For this you need to create a certificate request; the process involves creating your own private key, and the corresponding public key, and attaching that public key along with some of your info (email, name, domain name, etc) to a file that's called the certificate request. Then you send that certificate request to the company that's already asked you for it, and they will create your certificate, by signing your public key with their private key, and they'll send you back an X509 file with your certificate, which you can now add to your keystore, and you'll be ready to connect to a web service using SSL requiring client authentication.

    To generate your certificate request, use "keytool -certreq -alias -file -keypass -keystore ". Send the resulting file to the company that's going to sign it.

    When you get back your certificate, run "keytool -importcert -alias -keypass -keystore ".

    You may need to used -storepass in both cases if the keystore is protected (which is a good idea).

提交回复
热议问题