use of javax.net.ssl.SSLPeerUnverifiedException in project cas by apereo.
the class ValidateEndpointCommand method tlsConnectionReport.
private static void tlsConnectionReport(final HttpsURLConnection httpsConnection) {
val systemTrustManagers = getSystemTrustManagers();
final Certificate[] certificates;
try {
certificates = httpsConnection.getServerCertificates();
} catch (final SSLPeerUnverifiedException e) {
LoggingUtils.error(LOGGER, e);
throw new RuntimeException(e);
}
val serverCertificates = Arrays.copyOf(certificates, certificates.length, X509Certificate[].class);
LOGGER.info("Server provided certs: ");
for (val certificate : serverCertificates) {
val validity = FunctionUtils.doAndHandle(o -> {
certificate.checkValidity();
return "valid";
}, e -> "invalid: " + e.getMessage()).apply(certificate);
LOGGER.info("\tsubject: [{}]", certificate.getSubjectDN().getName());
LOGGER.info("\tissuer: [{}]", certificate.getIssuerDN().getName());
LOGGER.info("\texpiration: [{}] - [{}] [{}]", certificate.getNotBefore(), certificate.getNotAfter(), validity);
LOGGER.info("\ttrust anchor [{}]", checkTrustedCertStatus(certificate, systemTrustManagers));
LOGGER.info("---");
}
}
use of javax.net.ssl.SSLPeerUnverifiedException in project JGroups by belaban.
the class CertficateCNMatcher method verify.
public void verify(SSLSession session) throws SecurityException {
Principal principal = null;
try {
principal = session.getPeerPrincipal();
String name = principal.getName();
Matcher m = pattern.matcher(name);
boolean find = m.find();
if (!find)
throw new SecurityException(String.format("pattern '%s' not found in peer certificate '%s'", cn_name, name));
else
System.out.printf("** pattern '%s' found in peer certificate '%s'\n", cn_name, name);
} catch (SSLPeerUnverifiedException e) {
throw new SecurityException(e);
}
}
use of javax.net.ssl.SSLPeerUnverifiedException in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeEventTest method before.
@Before
public void before(TestContext context) {
vertx = Vertx.vertx();
final Async async = context.async();
vertx.eventBus().consumer("hello", (Message<JsonObject> msg) -> msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value"))));
vertx.eventBus().consumer("echo", (Message<JsonObject> msg) -> msg.reply(msg.body()));
vertx.setPeriodic(1000, __ -> vertx.eventBus().send("ping", new JsonObject().put("value", "hi")));
sslKeyPairCerts = new SSLKeyPairCerts().createTwoWaySSL();
TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("hello")).addInboundPermitted(new PermittedOptions().setAddress("echo")).addInboundPermitted(new PermittedOptions().setAddress("test")).addOutboundPermitted(new PermittedOptions().setAddress("echo")).addOutboundPermitted(new PermittedOptions().setAddress("ping")), new NetServerOptions().setClientAuth(ClientAuth.REQUEST).setSsl(true).setTrustStoreOptions(sslKeyPairCerts.getServerTrustStore()).setKeyStoreOptions(sslKeyPairCerts.getServerKeyStore()), be -> {
logger.info("Handled a bridge event " + be.getRawMessage());
if (be.socket().isSsl()) {
try {
for (Certificate c : be.socket().peerCertificates()) {
logger.info(((X509Certificate) c).getSubjectDN().toString());
}
} catch (SSLPeerUnverifiedException e) {
throw new RuntimeException("Failed to get peer certificates chain", e);
}
}
be.complete(true);
});
bridge.listen(7000, res -> {
context.assertTrue(res.succeeded());
async.complete();
});
}
use of javax.net.ssl.SSLPeerUnverifiedException in project hono by eclipse.
the class X509AuthHandlerTest method testParseCredentialsIncludesMqttClientId.
/**
* Verifies that the handler includes the MQTT client identifier in the authentication
* information retrieved from a device's CONNECT packet.
*
* @param ctx The vert.x test context.
* @throws SSLPeerUnverifiedException if the client certificate cannot be determined.
*/
@SuppressWarnings("unchecked")
@Test
public void testParseCredentialsIncludesMqttClientId(final VertxTestContext ctx) throws SSLPeerUnverifiedException {
// GIVEN an auth handler configured with an auth provider
final JsonObject authInfo = new JsonObject().put(RequestResponseApiConstants.FIELD_PAYLOAD_SUBJECT_DN, "CN=device").put(RequestResponseApiConstants.FIELD_PAYLOAD_TENANT_ID, "tenant");
when(clientAuth.validateClientCertificate(any(Certificate[].class), any(List.class), (SpanContext) any())).thenReturn(Future.succeededFuture(authInfo));
// WHEN trying to authenticate a request that contains a client certificate
final X509Certificate clientCert = getClientCertificate("CN=device", "CN=tenant");
final SSLSession sslSession = mock(SSLSession.class);
when(sslSession.getPeerCertificates()).thenReturn(new X509Certificate[] { clientCert });
final MqttEndpoint endpoint = mock(MqttEndpoint.class);
when(endpoint.isSsl()).thenReturn(true);
when(endpoint.sslSession()).thenReturn(sslSession);
when(endpoint.clientIdentifier()).thenReturn("mqtt-device");
final MqttConnectContext context = MqttConnectContext.fromConnectPacket(endpoint, span);
authHandler.parseCredentials(context).onComplete(ctx.succeeding(info -> {
ctx.verify(() -> {
assertThat(info.getString(RequestResponseApiConstants.FIELD_PAYLOAD_SUBJECT_DN)).isEqualTo("CN=device");
assertThat(info.getString(RequestResponseApiConstants.FIELD_PAYLOAD_TENANT_ID)).isEqualTo("tenant");
assertThat(info.getString(X509AuthHandler.PROPERTY_CLIENT_IDENTIFIER)).isEqualTo("mqtt-device");
});
ctx.completeNow();
}));
}
use of javax.net.ssl.SSLPeerUnverifiedException in project fabric8 by jboss-fuse.
the class KubernetesHelper method isServiceSsl.
public static boolean isServiceSsl(String host, int port, boolean trustAllCerts) {
try {
LOG.info("Checking if a service is SSL on " + host + ":" + port);
SSLSocketFactory sslsocketfactory;
if (trustAllCerts) {
sslsocketfactory = TrustEverythingSSLTrustManager.getTrustingSSLSocketFactory();
} else {
sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
Socket socket = sslsocketfactory.createSocket();
// Connect, with an explicit timeout value
socket.connect(new InetSocketAddress(host, port), 1 * 1000);
try {
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
// Write a test byte to get a reaction :)
out.write(1);
while (in.available() > 0) {
System.out.print(in.read());
}
return true;
} finally {
LOG.info("Checked if a service is SSL on " + host + ":" + port);
socket.close();
}
} catch (SSLHandshakeException e) {
LOG.error("SSL handshake failed - this probably means that you need to trust the kubernetes root SSL certificate or set the environment variable " + Utils.convertSystemPropertyNameToEnvVar(io.fabric8.kubernetes.client.Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY), e);
} catch (SSLProtocolException e) {
LOG.error("SSL protocol error", e);
} catch (SSLKeyException e) {
LOG.error("Bad SSL key", e);
} catch (SSLPeerUnverifiedException e) {
LOG.error("Could not verify server", e);
} catch (SSLException e) {
LOG.debug("Address does not appear to be SSL-enabled - falling back to http", e);
} catch (IOException e) {
LOG.debug("Failed to validate service", e);
}
return false;
}
Aggregations