Programmatically adding a trusted cert in Java

前端 未结 3 1998
太阳男子
太阳男子 2021-02-15 01:47

I use SSL to communicate between two components written in Java. I can\'t use a CA, so I have to self-sign everything. Unfortunately, this means that when I try to handshake, I

相关标签:
3条回答
  • 2021-02-15 02:03

    Why don't you create your own CA and sign your certificates with that? Then all you would need to do is install the CA own certificate on the machines and every certificate signed by that CA would validate.

    0 讨论(0)
  • 2021-02-15 02:03

    Why would you need to do this, you are not validating that the client is who they say they are you are only using the certs to encrypt the comms, so a custom trust manager that allows all certs is all you need. What you are asking is possible and from memory also involves a custom trust manager to validate the certificates and store them in the keystore. I can't remember the details, but at least you know it is possible to do it.

    0 讨论(0)
  • 2021-02-15 02:29

    Yes it is possible.

    There is some code here that I've used before. I had to modify it to do what I wanted and I suspect that you will too but this should get you close - you aren't trying to import a key so theoretically you should be able to simplify things. In any case you can get an idea of what you'll need.

    The JDK JavaDoc for java.security.KeyStore is pretty useful too.

    0 讨论(0)
提交回复
热议问题