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 get a SunCertPathBuilderException. I can create my own X509TrustManager that just trusts everything, but that sort of defeats the purpose of having a signed cert.
I would like, when first making the connection, to prompt the user with "SSL handshake with invalid cert. Add cert to store?" or something so they could have it added for them to their certificate store, like web browsers do at sites with invalid certs. I can find plenty of examples online of adding a cert to the store through the commandline, but I can't figure out how to do it programmatically. Is there a way to do this?
truststore.setEntry("dummy", new KeyStore.TrustedCertificateEntry(cert), null);rather thansetKeyEntry. (I'd been getting errors like "KeyStoreException: Key protection algorithm not found ... Unsupported key type".) If you already have a cert, like for a remote partner negotiating a connection, you should be able to use that cert inTrustedCertificateEntry(cert)instead of generating your own.