ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/net/TestClientCertTls13.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/net/TestClientCertTls13.java
Status
scanned
Type
file
Name
TestClientCertTls13.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
5672 (5.5 KB)
MD5
3030a276108dd520294ec041d0c57c1f
SHA1
dfb44fea9b46ac7e1d43b32be4f6d0de5434faca
SHA256
bfd512179444798bb3ff69fa3b8521edb1e152a11164fdbc3258d53277490bd7
SHA512

      
    
SHA1_git
79209acf4b06daa281c9a9f6f2f00b87c1f83ac8
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestClientCertTls13.java | 5.5 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.util.net; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.connector.Connector; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; import org.apache.tomcat.jni.AprStatus; import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.net.openssl.OpenSSLStatus; /** * The keys and certificates used in this file are all available in svn and were * generated using a test CA the files for which are in the Tomcat PMC private * repository since not all of them are AL2 licensed. * * The JSSE implementation of TLSv1.3 only supports authentication during the * initial handshake. This test requires TLSv1.3 on client and server so it is * skipped unless running on a Java version that supports TLSv1.3. */ @RunWith(Parameterized.class) public class TestClientCertTls13 extends TomcatBaseTest { @Parameterized.Parameters(name = "{0}") public static Collection<Object[]> parameters() { List<Object[]> parameterSets = new ArrayList<>(); parameterSets.add(new Object[] { "JSSE", Boolean.FALSE, "org.apache.tomcat.util.net.jsse.JSSEImplementation", Boolean.FALSE}); parameterSets.add(new Object[] { "OpenSSL", Boolean.TRUE, "org.apache.tomcat.util.net.openssl.OpenSSLImplementation", Boolean.TRUE}); parameterSets.add(new Object[] { "OpenSSL-FFM", Boolean.TRUE, "org.apache.tomcat.util.net.openssl.panama.OpenSSLImplementation", Boolean.FALSE}); return parameterSets; } @Parameter(0) public String connectorName; @Parameter(1) public boolean useOpenSSL; @Parameter(2) public String sslImplementationName; @Parameter(3) public boolean initSslImplementation; @Test public void testClientCertGet() throws Exception { Tomcat tomcat = getTomcatInstance(); tomcat.start(); Assume.assumeFalse("LibreSSL does not allow PHA", TesterSupport.isOpenSSLVariant(sslImplementationName, OpenSSLStatus.Name.LIBRESSL)); ByteChunk res = getUrl("https://localhost:" + getPort() + "/protected"); Assert.assertEquals("OK-" + TesterSupport.ROLE, res.toString()); } @Test public void testClientCertPost() throws Exception { Tomcat tomcat = getTomcatInstance(); tomcat.start(); Assume.assumeFalse("LibreSSL does not allow PHA", TesterSupport.isOpenSSLVariant(sslImplementationName, OpenSSLStatus.Name.LIBRESSL)); int size = 32 * 1024; byte[] body = new byte[size]; Arrays.fill(body, TesterSupport.DATA); // Protected resource ByteChunk res = new ByteChunk(); int rc = postUrl(body, "https://localhost:" + getPort() + "/protected", res, null); Assert.assertEquals(200, rc); Assert.assertEquals("OK-" + size, res.toString()); } @Override public void setUp() throws Exception { super.setUp(); Tomcat tomcat = getTomcatInstance(); TesterSupport.configureClientCertContext(tomcat); TesterSupport.configureClientSsl(); Connector connector = tomcat.getConnector(); TesterSupport.configureSSLImplementation(tomcat, sslImplementationName, useOpenSSL); if (useOpenSSL) { // getOpenSSLVersion() requires that the listener has been initialised if (initSslImplementation) { tomcat.getServer().findLifecycleListeners()[0].lifecycleEvent( new LifecycleEvent(tomcat.getServer(), Lifecycle.BEFORE_INIT_EVENT, null)); } Assume.assumeTrue(AprStatus.getOpenSSLVersion() >= 0x1010100f || OpenSSLStatus.getVersion() >= 0x1010100f); } // Tests default to TLSv1.2 when client cert auth is used // Need to override some of the previous settings SSLHostConfig[] sslHostConfigs = connector.findSslHostConfigs(); Assert.assertNotNull(sslHostConfigs); Assert.assertEquals(1, sslHostConfigs.length); SSLHostConfig sslHostConfig = sslHostConfigs[0]; // TLS 1.3 support sslHostConfig.setProtocols(Constants.SSL_PROTO_TLSv1_3); // And add force authentication to occur on the initial handshake sslHostConfig.setCertificateVerification("required"); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
19.83
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9