Search in sources :

Example 11 with X509ExtendedTrustManager

use of javax.net.ssl.X509ExtendedTrustManager in project smarthome by eclipse.

the class ExtensibleTrustManagerImpl method checkClientTrusted.

@Override
public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine sslEngine) throws CertificateException {
    X509ExtendedTrustManager linkedTrustManager = getLinkedTrustMananger(chain, sslEngine);
    if (linkedTrustManager == null) {
        logger.trace("No specific trust manager found, falling back to default");
        defaultTrustManager.checkClientTrusted(chain, authType, sslEngine);
    } else {
        linkedTrustManager.checkClientTrusted(chain, authType, sslEngine);
    }
}
Also used : X509ExtendedTrustManager(javax.net.ssl.X509ExtendedTrustManager)

Example 12 with X509ExtendedTrustManager

use of javax.net.ssl.X509ExtendedTrustManager in project smarthome by eclipse.

the class ExtensibleTrustManagerImpl method checkServerTrusted.

@Override
public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket) throws CertificateException {
    X509ExtendedTrustManager linkedTrustManager = getLinkedTrustMananger(chain);
    if (linkedTrustManager == null) {
        logger.trace("No specific trust manager found, falling back to default");
        defaultTrustManager.checkServerTrusted(chain, authType, socket);
    } else {
        linkedTrustManager.checkServerTrusted(chain, authType, socket);
    }
}
Also used : X509ExtendedTrustManager(javax.net.ssl.X509ExtendedTrustManager)

Example 13 with X509ExtendedTrustManager

use of javax.net.ssl.X509ExtendedTrustManager in project smarthome by eclipse.

the class ExtensibleTrustManagerImpl method getLinkedTrustMananger.

private X509ExtendedTrustManager getLinkedTrustMananger(X509Certificate[] chain) {
    try {
        String commonName = getCommonName(chain[0]);
        X509ExtendedTrustManager trustManager = linkedTrustManager.getOrDefault(commonName, EMPTY_QUEUE).peek();
        if (trustManager != null) {
            logger.trace("Found trustManager by common name: {}", commonName);
            return trustManager;
        }
        Collection<List<?>> subjectAlternatives = getSubjectAlternatives(chain);
        logger.trace("Searching trustManager by Subject Alternative Names: {}", subjectAlternatives);
        // @formatter:off
        return subjectAlternatives.stream().map(e -> e.get(1)).map(Object::toString).map(linkedTrustManager::get).filter(Objects::nonNull).map(Queue::peek).filter(Objects::nonNull).findFirst().orElse(null);
    // @formatter:on
    } catch (CommonNameNotFoundException e) {
        logger.debug("CN not found", e.getMessage());
        return null;
    } catch (CertificateParsingException e) {
        logger.debug("Problem while parsing certificate", e);
        return null;
    }
}
Also used : X509Certificate(java.security.cert.X509Certificate) Socket(java.net.Socket) X500Principal(javax.security.auth.x500.X500Principal) Logger(org.slf4j.Logger) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) CertificateParsingException(java.security.cert.CertificateParsingException) CertificateException(java.security.cert.CertificateException) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) TlsTrustManagerProvider(org.eclipse.smarthome.io.net.http.TlsTrustManagerProvider) SSLEngine(javax.net.ssl.SSLEngine) Objects(java.util.Objects) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) List(java.util.List) Component(org.osgi.service.component.annotations.Component) Map(java.util.Map) X509ExtendedTrustManager(javax.net.ssl.X509ExtendedTrustManager) ExtensibleTrustManager(org.eclipse.smarthome.io.net.http.ExtensibleTrustManager) Queue(java.util.Queue) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) TlsCertificateProvider(org.eclipse.smarthome.io.net.http.TlsCertificateProvider) X509ExtendedTrustManager(javax.net.ssl.X509ExtendedTrustManager) CertificateParsingException(java.security.cert.CertificateParsingException) Objects(java.util.Objects) List(java.util.List)

Example 14 with X509ExtendedTrustManager

use of javax.net.ssl.X509ExtendedTrustManager in project smarthome by eclipse.

the class ExtensibleTrustManagerImpl method checkServerTrusted.

@Override
public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine sslEngine) throws CertificateException {
    X509ExtendedTrustManager linkedTrustManager = getLinkedTrustMananger(chain, sslEngine);
    if (linkedTrustManager == null) {
        logger.trace("No specific trust manager found, falling back to default");
        defaultTrustManager.checkServerTrusted(chain, authType, sslEngine);
    } else {
        linkedTrustManager.checkServerTrusted(chain, authType, sslEngine);
    }
}
Also used : X509ExtendedTrustManager(javax.net.ssl.X509ExtendedTrustManager)

Example 15 with X509ExtendedTrustManager

use of javax.net.ssl.X509ExtendedTrustManager in project smarthome by eclipse.

the class ExtensibleTrustManagerImpl method checkClientTrusted.

@Override
public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket) throws CertificateException {
    X509ExtendedTrustManager linkedTrustManager = getLinkedTrustMananger(chain);
    if (linkedTrustManager == null) {
        logger.trace("No specific trust manager found, falling back to default");
        defaultTrustManager.checkClientTrusted(chain, authType, socket);
    } else {
        linkedTrustManager.checkClientTrusted(chain, authType, socket);
    }
}
Also used : X509ExtendedTrustManager(javax.net.ssl.X509ExtendedTrustManager)

Aggregations

X509ExtendedTrustManager (javax.net.ssl.X509ExtendedTrustManager)25 TrustManager (javax.net.ssl.TrustManager)14 KeyStore (java.security.KeyStore)10 X509Certificate (java.security.cert.X509Certificate)8 CertificateException (java.security.cert.CertificateException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 SSLEngine (javax.net.ssl.SSLEngine)6 Socket (java.net.Socket)5 KeyManager (javax.net.ssl.KeyManager)5 SSLContext (javax.net.ssl.SSLContext)5 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 KeyManagementException (java.security.KeyManagementException)4 KeyStoreException (java.security.KeyStoreException)3 SecureRandom (java.security.SecureRandom)3 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)2 File (java.io.File)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Bootstrap (io.netty.bootstrap.Bootstrap)1