Search in sources :

Example 1 with SSLPeer

use of de.carne.certmgr.certs.net.SSLPeer in project certmgr by hdecarne.

the class UserCertStore method createFromServer.

/**
 * Create a certificate store backed up by server provided certificate data.
 *
 * @param protocol The protocol to use for accessing the server.
 * @param host The host to retrieve the certificate data from.
 * @param port The port to retrieve the certificate data from.
 * @return The created certificate store.
 * @throws IOException if an I/O error occurs while reading/decoding certificate data.
 */
public static UserCertStore createFromServer(SSLPeer.Protocol protocol, String host, int port) throws IOException {
    SSLPeer sslPeer = SSLPeer.getInstance(host, port);
    Certificate[] certificates = sslPeer.readCertificates(protocol);
    CertObjectStore certObjects = new CertObjectStore();
    if (certificates != null) {
        for (Certificate certificate : certificates) {
            if (certificate instanceof X509Certificate) {
                certObjects.addCRT((X509Certificate) certificate);
            } else {
                LOG.warning("Ignoring unsupported certificate of type ''{0}''", certificates.getClass().getName());
            }
        }
    }
    return createFromCertObjects(certObjects);
}
Also used : SSLPeer(de.carne.certmgr.certs.net.SSLPeer) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

SSLPeer (de.carne.certmgr.certs.net.SSLPeer)1 Certificate (java.security.cert.Certificate)1 X509Certificate (java.security.cert.X509Certificate)1