List of usage examples for io.netty.handler.ssl SslContextBuilder trustManager
public SslContextBuilder trustManager(TrustManager trustManager)
From source file:org.springframework.vault.config.ClientHttpConnectorFactory.java
License:Apache License
private static void configureSsl(SslConfiguration sslConfiguration, SslContextBuilder sslContextBuilder) { try {//from www . j a v a 2s . c o m if (sslConfiguration.getTrustStoreConfiguration().isPresent()) { sslContextBuilder .trustManager(createTrustManagerFactory(sslConfiguration.getTrustStoreConfiguration())); } if (sslConfiguration.getKeyStoreConfiguration().isPresent()) { sslContextBuilder.keyManager(createKeyManagerFactory(sslConfiguration.getKeyStoreConfiguration())); } } catch (GeneralSecurityException | IOException e) { throw new IllegalStateException(e); } }
From source file:ratpack.config.internal.module.NettySslContextDeserializer.java
License:Apache License
@SuppressWarnings("Duplicates") @Override//from ww w .jav a 2s . com public SslContext deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectNode node = jp.readValueAsTree(); try { String keyStoreFile = node.path("keystoreFile").asText(); String keyStorePassword = node.path("keystorePassword").asText(); String trustStoreFile = node.path("truststoreFile").asText(); String trustStorePassword = node.path("truststorePassword").asText(); if (keyStoreFile.isEmpty()) { throw new IllegalStateException("keystoreFile must be set if any ssl properties are set"); } else if (keyStorePassword.isEmpty()) { throw new IllegalStateException("keystorePassword must be set if any ssl properties are set"); } else if (!trustStoreFile.isEmpty() && trustStorePassword.isEmpty()) { throw new IllegalStateException( "truststorePassword must be specified when truststoreFile is specified"); } KeyManagerFactory keyManagerFactory; try (InputStream is = Files.newInputStream(Paths.get(keyStoreFile))) { keyManagerFactory = SslContexts.keyManagerFactory(is, keyStorePassword.toCharArray()); } SslContextBuilder builder = SslContextBuilder.forServer(keyManagerFactory); if (!trustStoreFile.isEmpty()) { try (InputStream is = Files.newInputStream(Paths.get(trustStoreFile))) { builder.trustManager(SslContexts.trustManagerFactory(is, trustStorePassword.toCharArray())); } } return builder.build(); } catch (GeneralSecurityException ex) { throw Exceptions.uncheck(ex); } }