Path: blob/master/test/jdk/sun/security/ssl/SignatureScheme/SigAlgosExtTestWithTLS13.java
41152 views
/*1* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test 826318825* @summary If TLS the server and client has no common signature algorithms,26* the connection should fail fast with "No supported signature algorithm".27* This test only covers TLS 1.3, but doesn't cover client authentication.28*29* @library /test/lib30* /javax/net/ssl/templates31*32* @run main/othervm33* -Djdk.tls.server.SignatureSchemes=ecdsa_secp384r1_sha38434* -Djdk.tls.client.SignatureSchemes=ecdsa_secp256r1_sha256,ecdsa_secp384r1_sha38435* -Dtest.expectFail=false36* SigAlgosExtTestWithTLS1337* @run main/othervm38* -Djdk.tls.server.SignatureSchemes=ecdsa_secp384r1_sha38439* -Djdk.tls.client.SignatureSchemes=ecdsa_secp256r1_sha25640* -Dtest.expectFail=true41* SigAlgosExtTestWithTLS1342*/4344import javax.net.ssl.SSLContext;45import javax.net.ssl.SSLHandshakeException;46import javax.net.ssl.SSLSocket;4748public class SigAlgosExtTestWithTLS13 extends SSLSocketTemplate {4950@Override51protected SSLContext createServerSSLContext() throws Exception {52return createSSLContext(53new Cert[] { Cert.CA_ECDSA_SECP256R1, Cert.CA_ECDSA_SECP384R1 },54new Cert[] { Cert.EE_ECDSA_SECP256R1, Cert.EE_ECDSA_SECP384R1 },55getServerContextParameters());56}5758@Override59protected SSLContext createClientSSLContext() throws Exception {60return createSSLContext(61new Cert[] { Cert.CA_ECDSA_SECP256R1, Cert.CA_ECDSA_SECP384R1 },62new Cert[] { Cert.EE_ECDSA_SECP256R1, Cert.EE_ECDSA_SECP384R1 },63getClientContextParameters());64}6566@Override67protected void configureClientSocket(SSLSocket socket) {68socket.setEnabledProtocols(new String[] { "TLSv1.3" });69}7071public static void main(String[] args) throws Exception {72boolean expectFail = Boolean.getBoolean("test.expectFail");73try {74new SigAlgosExtTestWithTLS13().run();75if (expectFail) {76throw new RuntimeException(77"Expected SSLHandshakeException wasn't thrown");78}79} catch (SSLHandshakeException e) {80if (expectFail && e.getMessage().equals(81"No supported signature algorithm")) {82System.out.println("Expected SSLHandshakeException");83} else {84throw e;85}86}87}88}899091