pgjdbc/pgjdbc — pull request #27 by davecramer (2013-01-11 13:41:09+00:00)
Title: DbKeyStoreFactory

...ndan Jurd

It seems that the most common way to deal with this situation is to
specify the keystore file and the password via system properties
(javax.net.ssl.keyStore et. al.), but that wasn't suitable in my case.
I needed to be able to load the keystore from a Resource file
embedded in the compiled JAR.

The class I came up with is attached. It builds on the WrappedFactory
provided in jdbc-postgres. All the implementer needs to do is
override the two abstract methods to provide an InputStream of the key
store, and the password to access it. The InputStream could be a
FileInputStream, or an InputStream returned by getResource(), or
whatever.

This class uses the same keystore for KeyManager (selecting the
key/cert to send as the client) and for TrustManager (verifying the
server's certificate against trusted CAs). It could easily be
extended to allow for two separate keystores by adding another couple
of methods.