Search in sources :

Example 1 with ProviderHostnameVerifier

use of com.yahoo.athenz.instance.provider.ProviderHostnameVerifier in project athenz by yahoo.

the class InstanceHttpProvider method initialize.

@Override
public void initialize(String provider, String providerEndpoint, KeyStore keyStore) {
    ProviderHostnameVerifier hostnameVerifier = new ProviderHostnameVerifier(provider);
    int readTimeout = Integer.parseInt(System.getProperty(PROP_READ_TIMEOUT, "30000"));
    int connectTimeout = Integer.parseInt(System.getProperty(PROP_CONNECT_TIMEOUT, "30000"));
    client = new InstanceProviderClient(providerEndpoint, hostnameVerifier, connectTimeout, readTimeout);
}
Also used : ProviderHostnameVerifier(com.yahoo.athenz.instance.provider.ProviderHostnameVerifier) InstanceProviderClient(com.yahoo.athenz.instance.provider.InstanceProviderClient)

Example 2 with ProviderHostnameVerifier

use of com.yahoo.athenz.instance.provider.ProviderHostnameVerifier in project athenz by yahoo.

the class ProviderHostnameVerifierTest method testHostnameVerifier.

@Test
public void testHostnameVerifier() throws IOException {
    SSLSession session = Mockito.mock(SSLSession.class);
    Path path = Paths.get("src/test/resources/athenz.instanceid.pem");
    String pem = new String(Files.readAllBytes(path));
    X509Certificate cert = Crypto.loadX509Certificate(pem);
    Certificate[] certs = new Certificate[1];
    certs[0] = cert;
    Mockito.when(session.getPeerCertificates()).thenReturn(certs);
    ProviderHostnameVerifier verifier1 = new ProviderHostnameVerifier("athenz.production");
    assertTrue(verifier1.verify("athenz", session));
    ProviderHostnameVerifier verifier2 = new ProviderHostnameVerifier("athenz.production2");
    assertFalse(verifier2.verify("athenz", session));
}
Also used : Path(java.nio.file.Path) ProviderHostnameVerifier(com.yahoo.athenz.instance.provider.ProviderHostnameVerifier) SSLSession(javax.net.ssl.SSLSession) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) Test(org.testng.annotations.Test)

Example 3 with ProviderHostnameVerifier

use of com.yahoo.athenz.instance.provider.ProviderHostnameVerifier in project athenz by yahoo.

the class ProviderHostnameVerifierTest method testHostnameVerifierNullCerts.

@Test
public void testHostnameVerifierNullCerts() throws IOException {
    SSLSession session = Mockito.mock(SSLSession.class);
    Mockito.when(session.getPeerCertificates()).thenReturn(null);
    ProviderHostnameVerifier verifier1 = new ProviderHostnameVerifier("athenz.production");
    assertFalse(verifier1.verify("athenz", session));
}
Also used : ProviderHostnameVerifier(com.yahoo.athenz.instance.provider.ProviderHostnameVerifier) SSLSession(javax.net.ssl.SSLSession) Test(org.testng.annotations.Test)

Aggregations

ProviderHostnameVerifier (com.yahoo.athenz.instance.provider.ProviderHostnameVerifier)3 SSLSession (javax.net.ssl.SSLSession)2 Test (org.testng.annotations.Test)2 InstanceProviderClient (com.yahoo.athenz.instance.provider.InstanceProviderClient)1 Path (java.nio.file.Path)1 Certificate (java.security.cert.Certificate)1 X509Certificate (java.security.cert.X509Certificate)1