org.apache.tomcat.jni.SSLContext Java Examples

The following examples show how to use org.apache.tomcat.jni.SSLContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestOpenSSLConf.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testOpenSSLConfCmdCipher() throws Exception {
    log.info("Found OpenSSL version 0x" + Integer.toHexString(OPENSSL_VERSION));
    SSLHostConfig sslHostConfig;
    if (hasTLS13()) {
        // Ensure TLSv1.3 ciphers aren't returned
        sslHostConfig = initOpenSSLConfCmd("CipherString", ENABLED_CIPHER,
                                           "CipherSuites", "");
    } else {
        sslHostConfig = initOpenSSLConfCmd("CipherString", ENABLED_CIPHER);
    }
    String[] ciphers = sslHostConfig.getEnabledCiphers();
    Assert.assertThat("Wrong HostConfig ciphers", ciphers,
            CoreMatchers.is(EXPECTED_CIPHERS));
    ciphers = SSLContext.getCiphers(sslHostConfig.getOpenSslContext().longValue());
    Assert.assertThat("Wrong native SSL context ciphers", ciphers,
            CoreMatchers.is(EXPECTED_CIPHERS));
}
 
Example #2
Source File: OpenSslContext.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("FinalizeDeclaration")
protected final void finalize() throws Throwable {
    super.finalize();
    synchronized (OpenSslContext.class) {
        if (ctx != 0) {
            SSLContext.free(ctx);
        }
    }

    destroyPools();
}
 
Example #3
Source File: OpenSSLSessionContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Sets the SSL session ticket keys of this context.
 *
 * @param keys The session ticket keys
 */
public void setTicketKeys(byte[] keys) {
    if (keys == null) {
        throw new IllegalArgumentException(sm.getString("sessionContext.nullTicketKeys"));
    }
    SSLContext.setSessionTicketKeys(contextID, keys);
}
 
Example #4
Source File: OpenSslSessionContext.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the SSL session ticket keys of this context.
 */
public void setTicketKeys(byte[] keys) {
    if (keys == null) {
        throw new NullPointerException("keys");
    }
    SSLContext.setSessionTicketKeys(context, keys);
}
 
Example #5
Source File: OpenSslServerSessionContext.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public void setSessionCacheSize(int size) {
    if (size < 0) {
        throw new IllegalArgumentException();
    }
    SSLContext.setSessionCacheSize(context, size);
}
 
Example #6
Source File: OpenSslServerSessionContext.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public void setSessionTimeout(int seconds) {
    if (seconds < 0) {
        throw new IllegalArgumentException();
    }
    SSLContext.setSessionCacheTimeout(context, seconds);
}
 
Example #7
Source File: OpenSSLContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public synchronized void destroy() {
    // Guard against multiple destroyPools() calls triggered by construction exception and finalize() later
    if (aprPoolDestroyed.compareAndSet(0, 1)) {
        if (ctx != 0) {
            SSLContext.free(ctx);
        }
        if (cctx != 0) {
            SSLConf.free(cctx);
        }
        if (aprPool != 0) {
            Pool.destroy(aprPool);
        }
    }
}
 
Example #8
Source File: OpenSSLSessionContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void setSessionTimeout(int seconds) {
    if (seconds < 0) {
        throw new IllegalArgumentException();
    }
    SSLContext.setSessionCacheTimeout(contextID, seconds);
}
 
Example #9
Source File: OpenSSLSessionContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void setSessionCacheSize(int size) {
    if (size < 0) {
        throw new IllegalArgumentException();
    }
    SSLContext.setSessionCacheSize(contextID, size);
}
 
Example #10
Source File: OpenSSLSessionStats.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * @return The current number of sessions in the internal session cache.
 */
public long number() {
    return SSLContext.sessionNumber(context);
}
 
Example #11
Source File: OpenSslServerSessionContext.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSessionCacheEnabled() {
    return SSLContext.getSessionCacheMode(context) == SSL.SSL_SESS_CACHE_SERVER;
}
 
Example #12
Source File: OpenSslServerSessionContext.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public void setSessionCacheEnabled(boolean enabled) {
    long mode = enabled ? SSL.SSL_SESS_CACHE_SERVER : SSL.SSL_SESS_CACHE_OFF;
    SSLContext.setSessionCacheMode(context, mode);
}
 
Example #13
Source File: OpenSslServerSessionContext.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public int getSessionCacheSize() {
    return (int) SSLContext.getSessionCacheSize(context);
}
 
Example #14
Source File: OpenSslServerSessionContext.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public int getSessionTimeout() {
    return (int) SSLContext.getSessionCacheTimeout(context);
}
 
Example #15
Source File: OpenSSLSessionContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public int getSessionTimeout() {
    return (int) SSLContext.getSessionCacheTimeout(contextID);
}
 
Example #16
Source File: OpenSslSessionStats.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the number of sessions that were removed because the maximum session cache size was exceeded.
 */
public long cacheFull() {
    return SSLContext.sessionCacheFull(context);
}
 
Example #17
Source File: OpenSslSessionStats.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the number of successfully retrieved sessions from the external session cache in server mode.
 */
public long cbHits() {
    return SSLContext.sessionCbHits(context);
}
 
Example #18
Source File: OpenSslSessionStats.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the number of start renegotiations in server mode.
 */
public long acceptRenegotiate() {
    return SSLContext.sessionAcceptRenegotiate(context);
}
 
Example #19
Source File: OpenSslSessionStats.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the number of successfully established SSL/TLS sessions in server mode.
 */
public long acceptGood() {
    return SSLContext.sessionAcceptGood(context);
}
 
Example #20
Source File: OpenSslSessionStats.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the number of started SSL/TLS handshakes in server mode.
 */
public long accept() {
    return SSLContext.sessionAccept(context);
}
 
Example #21
Source File: OpenSslSessionStats.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the number of start renegotiations in client mode.
 */
public long connectRenegotiate() {
    return SSLContext.sessionConnectRenegotiate(context);
}
 
Example #22
Source File: OpenSslSessionStats.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the number of successfully established SSL/TLS sessions in client mode.
 */
public long connectGood() {
    return SSLContext.sessionConnectGood(context);
}
 
Example #23
Source File: OpenSslSessionStats.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the number of started SSL/TLS handshakes in client mode.
 */
public long connect() {
    return SSLContext.sessionConnect(context);
}
 
Example #24
Source File: OpenSSLContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public void addCertificate(SSLHostConfigCertificate certificate) throws Exception {
    // Load Server key and certificate
    if (certificate.getCertificateFile() != null) {
        // Set certificate
        SSLContext.setCertificate(ctx,
                SSLHostConfig.adjustRelativePath(certificate.getCertificateFile()),
                SSLHostConfig.adjustRelativePath(certificate.getCertificateKeyFile()),
                certificate.getCertificateKeyPassword(), getCertificateIndex(certificate));
        // Set certificate chain file
        SSLContext.setCertificateChainFile(ctx,
                SSLHostConfig.adjustRelativePath(certificate.getCertificateChainFile()), false);
        // Set revocation
        SSLContext.setCARevocation(ctx,
                SSLHostConfig.adjustRelativePath(
                        sslHostConfig.getCertificateRevocationListFile()),
                SSLHostConfig.adjustRelativePath(
                        sslHostConfig.getCertificateRevocationListPath()));
    } else {
        String alias = certificate.getCertificateKeyAlias();
        X509KeyManager x509KeyManager = certificate.getCertificateKeyManager();
        if (alias == null) {
            alias = "tomcat";
        }
        X509Certificate[] chain = x509KeyManager.getCertificateChain(alias);
        if (chain == null) {
            alias = findAlias(x509KeyManager, certificate);
            chain = x509KeyManager.getCertificateChain(alias);
        }
        PrivateKey key = x509KeyManager.getPrivateKey(alias);
        StringBuilder sb = new StringBuilder(BEGIN_KEY);
        String encoded = BASE64_ENCODER.encodeToString(key.getEncoded());
        if (encoded.endsWith("\n")) {
            encoded = encoded.substring(0, encoded.length() - 1);
        }
        sb.append(encoded);
        sb.append(END_KEY);
        SSLContext.setCertificateRaw(ctx, chain[0].getEncoded(),
                sb.toString().getBytes(StandardCharsets.US_ASCII),
                getCertificateIndex(certificate));
        for (int i = 1; i < chain.length; i++) {
            SSLContext.addChainCertificateRaw(ctx, chain[i].getEncoded());
        }
    }
}
 
Example #25
Source File: OpenSSLSessionContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public int getSessionCacheSize() {
    return (int) SSLContext.getSessionCacheSize(contextID);
}
 
Example #26
Source File: OpenSslSessionStats.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the current number of sessions in the internal session cache.
 */
public long number() {
    return SSLContext.sessionNumber(context);
}
 
Example #27
Source File: OpenSSLSessionStats.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * @return The number of started SSL/TLS handshakes in client mode.
 */
public long connect() {
    return SSLContext.sessionConnect(context);
}
 
Example #28
Source File: OpenSSLSessionStats.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * @return The number of successfully established SSL/TLS sessions in client mode.
 */
public long connectGood() {
    return SSLContext.sessionConnectGood(context);
}
 
Example #29
Source File: OpenSSLSessionStats.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * @return The number of start renegotiations in client mode.
 */
public long connectRenegotiate() {
    return SSLContext.sessionConnectRenegotiate(context);
}
 
Example #30
Source File: OpenSSLSessionStats.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * @return The number of started SSL/TLS handshakes in server mode.
 */
public long accept() {
    return SSLContext.sessionAccept(context);
}