Re: ftp ssl cert
bcr666 wrote:
I need to write a ftp/ssl program (done actually) but I need to secure
it, and I was provided 2 files from the destination (keycert.txt &
trusted.txt).
The keycert.txt has the following in it:
-----BEGIN ENCRYPTED PRIVATE KEY-----
MII ...snip...
-----END ENCRYPTED PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MII ...snip...
-----END CERTIFICATE-----
The trusted.txt has the following in it:
-----BEGIN CERTIFICATE-----
MII ...snip...
-----END CERTIFICATE-----=
This is the so called PEM-format, the text between the
markers is a base64 coded DER-encoded data.
Notice the MII in the certificate/key areas. I suspect that it is RSA.
can also be Diffie Helman or EC-keys, that is one of the infor-
mations in the DER-encoded data.
I guess I'm supposed to import these into a keystore
then use
.....
KeyManager keyManager = null;
TrustManager trustManager = null;
try {
keyManager = getKeyManagers()[0];
trustManager = getTrustManagers()[0];
}
catch (Exception ex) {
ex.printStackTrace();
}
ftps.setControlEncoding("UTF-8");
ftps.setKeyManager(keyManager);
ftps.setTrustManager(trustManager);
looks OK to me without knowing what happens at getKeyManagers
and getTrustManagers.
Can someone tell me if I'm on the right track,
Looks OK.
and how to import the
files into a keystore?
If you use BouncyCastle:
PEMReader reader = new PEMReader(new FileInputStream("keycert.txt"));
PrivateKey key = (PrivateKey) reader.readObject();
X509Certificate cert = (X509Certificate) reader.readObject();
It's possible that the reader returns a KeyPair instead of the
private key instance but that should be easy to find out.
Regards, Lothar
--
Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!