use of javax.net.ssl.SSLPeerUnverifiedException in project activemq-artemis by apache.
the class CertificateUtil method getCertsFromChannel.
public static X509Certificate[] getCertsFromChannel(Channel channel) {
X509Certificate[] certificates = null;
ChannelHandler channelHandler = channel.pipeline().get("ssl");
if (channelHandler != null && channelHandler instanceof SslHandler) {
SslHandler sslHandler = (SslHandler) channelHandler;
try {
certificates = sslHandler.engine().getSession().getPeerCertificateChain();
} catch (SSLPeerUnverifiedException e) {
// ignore
}
}
return certificates;
}
use of javax.net.ssl.SSLPeerUnverifiedException in project activemq-artemis by apache.
the class CertificateUtil method getPeerPrincipalFromConnection.
public static Principal getPeerPrincipalFromConnection(RemotingConnection remotingConnection) {
Principal result = null;
if (remotingConnection != null) {
Connection transportConnection = remotingConnection.getTransportConnection();
if (transportConnection instanceof NettyConnection) {
NettyConnection nettyConnection = (NettyConnection) transportConnection;
ChannelHandler channelHandler = nettyConnection.getChannel().pipeline().get("ssl");
if (channelHandler != null && channelHandler instanceof SslHandler) {
SslHandler sslHandler = (SslHandler) channelHandler;
try {
result = sslHandler.engine().getSession().getPeerPrincipal();
} catch (SSLPeerUnverifiedException ignored) {
}
}
}
}
return result;
}
use of javax.net.ssl.SSLPeerUnverifiedException in project okhttp by square.
the class CertificateChainCleanerTest method chainTooLong.
@Test
public void chainTooLong() {
List<HeldCertificate> heldCertificates = chainOfLength(11);
List<Certificate> certificates = new ArrayList<>();
for (HeldCertificate heldCertificate : heldCertificates) {
certificates.add(heldCertificate.certificate());
}
X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate();
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root);
try {
cleaner.clean(certificates, "hostname");
fail();
} catch (SSLPeerUnverifiedException expected) {
}
}
use of javax.net.ssl.SSLPeerUnverifiedException in project okhttp by square.
the class CertificateChainCleanerTest method normalizeUnknownSelfSignedCertificate.
@Test
public void normalizeUnknownSelfSignedCertificate() {
HeldCertificate root = new HeldCertificate.Builder().serialNumber(1L).build();
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get();
try {
cleaner.clean(list(root), "hostname");
fail();
} catch (SSLPeerUnverifiedException expected) {
}
}
use of javax.net.ssl.SSLPeerUnverifiedException in project okhttp by square.
the class ConnectionCoalescingTest method skipsOnRedirectWhenCertificatePinningFails.
@Test
public void skipsOnRedirectWhenCertificatePinningFails() throws Exception {
CertificatePinner pinner = new CertificatePinner.Builder().add("san.com", "sha1/afwiKY3RxoMmLkuRW1l7QsPZTJPwDS2pdDROQjXw8ig=").build();
client = client.newBuilder().certificatePinner(pinner).build();
server.enqueue(new MockResponse().setResponseCode(301).addHeader("Location", url.newBuilder().host("san.com").build()));
server.enqueue(new MockResponse());
try {
execute(url);
fail("expected a failed attempt to connect");
} catch (SSLPeerUnverifiedException expected) {
}
}
Aggregations