bcr666 wrote:
> Here are the methods that you requested.
>
> private static KeyManager[] getKeyManagers() throws
> KeyStoreException, NoSuchAlgorithmException, CertificateException,
> FileNotFoundException, IOException, UnrecoverableKeyException {
> KeyStore ks = KeyStore.getInstance("JKS");
>
> ks.load(new FileInputStream(KEYSTORE_FILE_NAME),
> KEYSTORE_PASS.toCharArray());
>
> KeyManagerFactory tmf =
> KeyManagerFactory.getInstance(KeyManagerFactory.ge tDefaultAlgorithm());
> tmf.init(ks, KEYSTORE_PASS.toCharArray());
>
> return tmf.getKeyManagers();
> }
>
> private static TrustManager[] getTrustManagers() throws
> KeyStoreException, NoSuchAlgorithmException, CertificateException,
> FileNotFoundException, IOException, UnrecoverableKeyException {
> KeyStore ks = KeyStore.getInstance("JKS");
> ks.load(new FileInputStream(KEYSTORE_FILE_NAME),
> KEYSTORE_PASS.toCharArray());
>
> TrustManagerFactory tmf =
> TrustManagerFactory.getInstance(KeyManagerFactory. getDefaultAlgorithm());
> tmf.init(ks);
>
> return tmf.getTrustManagers();
> }
IMHO you should create the KeyStore once and pass it as parameter
to the two methods.
> If I use the code you gave me how do I use the X509Certificate to
> secure the connection?
The code I gave you allows to read in the certificate and key.
After that you can add the certificate and the key to the
keystore. The Keystore is then used by the FtpsServer. How it
uses it is implementation dependend. E.g. the SSLSocket
and SSLServerSocket-classes just load all available keys
and certificates that are marked to be used as TLS Client
and TLS Server. They then use the first fitting key (which
is dependent on the result of the SSL handshake) will then
be used.
If you want a specific key to be used instead of the first
fitting one, you have to write your own implementation of
KeyManager and TrustManager (which is not very hard, they
only consist of four methods each AFAIR).
Regards, Lothar
--
Lothar Kimmeringer E-Mail:
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!