use of io.grpc.ChannelCredentials in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method from_tls_clientAuthRequire_noClientCert.
@Test
public void from_tls_clientAuthRequire_noClientCert() throws Exception {
ServerCredentials serverCreds = TlsServerCredentials.newBuilder().keyManager(server1Cert, server1Key).trustManager(caCert).clientAuth(TlsServerCredentials.ClientAuth.REQUIRE).build();
ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder().trustManager(caCert).build();
Status status = expectFailedHandshake(channelCreds, serverCreds);
assertEquals(Status.Code.UNAVAILABLE, status.getCode());
StatusException sre = status.asException();
// because of netty/netty#11604 we need to check for both TLSv1.2 and v1.3 behaviors
if (sre.getCause() instanceof SSLHandshakeException) {
assertThat(sre).hasCauseThat().isInstanceOf(SSLHandshakeException.class);
assertThat(sre).hasCauseThat().hasMessageThat().contains("SSLV3_ALERT_HANDSHAKE_FAILURE");
} else {
// Client cert verification is after handshake in TLSv1.3
assertThat(sre).hasCauseThat().hasCauseThat().isInstanceOf(SSLException.class);
assertThat(sre).hasCauseThat().hasMessageThat().contains("CERTIFICATE_REQUIRED");
}
}
use of io.grpc.ChannelCredentials in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method from_tls_managers.
@Test
public void from_tls_managers() throws Exception {
SelfSignedCertificate cert = new SelfSignedCertificate(TestUtils.TEST_SERVER_HOST);
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null);
keyStore.setKeyEntry("mykey", cert.key(), new char[0], new Certificate[] { cert.cert() });
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, new char[0]);
KeyStore certStore = KeyStore.getInstance(KeyStore.getDefaultType());
certStore.load(null);
certStore.setCertificateEntry("mycert", cert.cert());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(certStore);
ServerCredentials serverCreds = TlsServerCredentials.newBuilder().keyManager(keyManagerFactory.getKeyManagers()).trustManager(trustManagerFactory.getTrustManagers()).clientAuth(TlsServerCredentials.ClientAuth.REQUIRE).build();
ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder().keyManager(keyManagerFactory.getKeyManagers()).trustManager(trustManagerFactory.getTrustManagers()).build();
InternalChannelz.Tls tls = expectSuccessfulHandshake(channelCreds, serverCreds);
assertThat(((X509Certificate) tls.remoteCert).getSubjectX500Principal().getName()).isEqualTo("CN=" + TestUtils.TEST_SERVER_HOST);
cert.delete();
}
use of io.grpc.ChannelCredentials in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method from_tls_clientAuthRequire_clientCert.
@Test
public void from_tls_clientAuthRequire_clientCert() throws Exception {
ServerCredentials serverCreds = TlsServerCredentials.newBuilder().keyManager(server1Cert, server1Key).trustManager(caCert).clientAuth(TlsServerCredentials.ClientAuth.REQUIRE).build();
ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder().keyManager(server1Cert, server1Key).trustManager(caCert).build();
InternalChannelz.Tls tls = expectSuccessfulHandshake(channelCreds, serverCreds);
assertThat(((X509Certificate) tls.remoteCert).getSubjectX500Principal().getName()).contains("CN=*.test.google.com");
}
use of io.grpc.ChannelCredentials in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method fromClient_unknown.
@Test
public void fromClient_unknown() {
ProtocolNegotiators.FromChannelCredentialsResult result = ProtocolNegotiators.from(new ChannelCredentials() {
@Override
public ChannelCredentials withoutBearerTokens() {
throw new UnsupportedOperationException();
}
});
assertThat(result.error).isNotNull();
assertThat(result.callCredentials).isNull();
assertThat(result.negotiator).isNull();
}
use of io.grpc.ChannelCredentials in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method from_tls_clientAuthOptional_clientCert.
@Test
public void from_tls_clientAuthOptional_clientCert() throws Exception {
ServerCredentials serverCreds = TlsServerCredentials.newBuilder().keyManager(server1Cert, server1Key).trustManager(caCert).clientAuth(TlsServerCredentials.ClientAuth.OPTIONAL).build();
ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder().keyManager(server1Cert, server1Key).trustManager(caCert).build();
InternalChannelz.Tls tls = expectSuccessfulHandshake(channelCreds, serverCreds);
assertThat(((X509Certificate) tls.remoteCert).getSubjectX500Principal().getName()).contains("CN=*.test.google.com");
}
Aggregations