Search in sources :

Example 1 with SSLContextConfigurator

use of org.glassfish.grizzly.ssl.SSLContextConfigurator in project jersey by jersey.

the class Server method start.

/**
     * Start SSL-secured HTTP test server.
     *
     * @throws IOException in case there is an error while reading server key store or trust store.
     * @return an instance of the started SSL-secured HTTP test server.
     */
public static Server start() throws IOException {
    // Grizzly ssl configuration
    SSLContextConfigurator sslContext = new SSLContextConfigurator();
    // set up security context
    // contains server keypair
    sslContext.setKeyStoreFile(KEYSTORE_SERVER_FILE);
    sslContext.setKeyStorePass(KEYSTORE_SERVER_PWD);
    // contains client certificate
    sslContext.setTrustStoreFile(TRUSTORE_SERVER_FILE);
    sslContext.setTrustStorePass(TRUSTORE_SERVER_PWD);
    ResourceConfig rc = new ResourceConfig();
    rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);
    final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
    // start Grizzly embedded server //
    LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
    grizzlyServer.start();
    return new Server(grizzlyServer);
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) SSLContextConfigurator(org.glassfish.grizzly.ssl.SSLContextConfigurator)

Example 2 with SSLContextConfigurator

use of org.glassfish.grizzly.ssl.SSLContextConfigurator in project jersey by jersey.

the class Server method start.

/**
     * Start SSL-secured HTTP test server.
     *
     * @throws IOException in case there is an error while reading server key store or trust store.
     * @return an instance of the started SSL-secured HTTP test server.
     */
public static Server start(String keystore) throws IOException {
    final InputStream trustStore = Server.class.getResourceAsStream(SERVER_TRUST_STORE);
    final InputStream keyStore = Server.class.getResourceAsStream(keystore);
    // Grizzly ssl configuration
    SSLContextConfigurator sslContext = new SSLContextConfigurator();
    // set up security context
    // contains server key pair
    sslContext.setKeyStoreBytes(ByteStreams.toByteArray(keyStore));
    sslContext.setKeyStorePass("asdfgh");
    // contains client certificate
    sslContext.setTrustStoreBytes(ByteStreams.toByteArray(trustStore));
    sslContext.setTrustStorePass("asdfgh");
    ResourceConfig rc = new ResourceConfig();
    rc.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY));
    rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);
    final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
    // start Grizzly embedded server //
    LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
    grizzlyServer.start();
    return new Server(grizzlyServer);
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) InputStream(java.io.InputStream) LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) SSLContextConfigurator(org.glassfish.grizzly.ssl.SSLContextConfigurator)

Example 3 with SSLContextConfigurator

use of org.glassfish.grizzly.ssl.SSLContextConfigurator in project graylog2-server by Graylog2.

the class JerseyService method buildSslEngineConfigurator.

private SSLEngineConfigurator buildSslEngineConfigurator(Path certFile, Path keyFile, String keyPassword) throws GeneralSecurityException, IOException {
    if (keyFile == null || !Files.isRegularFile(keyFile) || !Files.isReadable(keyFile)) {
        throw new InvalidKeyException("Unreadable or missing private key: " + keyFile);
    }
    if (certFile == null || !Files.isRegularFile(certFile) || !Files.isReadable(certFile)) {
        throw new CertificateException("Unreadable or missing X.509 certificate: " + certFile);
    }
    final SSLContextConfigurator sslContext = new SSLContextConfigurator();
    final char[] password = firstNonNull(keyPassword, "").toCharArray();
    final KeyStore keyStore = PemKeyStore.buildKeyStore(certFile, keyFile, password);
    sslContext.setKeyStorePass(password);
    sslContext.setKeyStoreBytes(KeyStoreUtils.getBytes(keyStore, password));
    if (!sslContext.validateConfiguration(true)) {
        throw new IllegalStateException("Couldn't initialize SSL context for HTTP server");
    }
    return new SSLEngineConfigurator(sslContext.createSSLContext(false), false, false, false);
}
Also used : SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) CertificateException(java.security.cert.CertificateException) InvalidKeyException(java.security.InvalidKeyException) KeyStore(java.security.KeyStore) PemKeyStore(org.graylog2.shared.security.tls.PemKeyStore) SSLContextConfigurator(org.glassfish.grizzly.ssl.SSLContextConfigurator)

Example 4 with SSLContextConfigurator

use of org.glassfish.grizzly.ssl.SSLContextConfigurator in project ddf by codice.

the class SecureStubServer method getSslConfig.

private SSLContextConfigurator getSslConfig() throws IOException {
    SSLContextConfigurator defaultConfig = SSLContextConfigurator.DEFAULT_CONFIG;
    if (!defaultConfig.validateConfiguration(true)) {
        String keystoreServer = createCertificateStore("keystore_server");
        String truststoreServer = createCertificateStore("truststore_server");
        defaultConfig.setKeyStoreFile(keystoreServer);
        defaultConfig.setKeyStorePass("secret");
        defaultConfig.setTrustStoreFile(truststoreServer);
        defaultConfig.setTrustStorePass("secret");
    }
    return defaultConfig;
}
Also used : SSLContextConfigurator(org.glassfish.grizzly.ssl.SSLContextConfigurator)

Aggregations

SSLContextConfigurator (org.glassfish.grizzly.ssl.SSLContextConfigurator)4 SSLEngineConfigurator (org.glassfish.grizzly.ssl.SSLEngineConfigurator)3 HttpServer (org.glassfish.grizzly.http.server.HttpServer)2 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)2 InputStream (java.io.InputStream)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyStore (java.security.KeyStore)1 CertificateException (java.security.cert.CertificateException)1 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)1 PemKeyStore (org.graylog2.shared.security.tls.PemKeyStore)1