< prev index next >

test/jdk/sun/security/util/HostnameMatcher/NullHostnameCheck.java

Print this page
rev 53269 : 8228967: Trust/Key store and SSL context utilities for tests
Reviewed-by: xuelei

*** 1,7 **** /* ! * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 19,49 **** * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLException; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLParameters; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; ! import java.io.ByteArrayInputStream; ! import java.nio.ByteBuffer; ! import java.security.KeyStore; ! import java.security.cert.CertificateException; ! import java.security.cert.X509Certificate; ! import java.util.Base64; /* * @test * @bug 8211339 8234728 * @summary Verify hostname returns an exception instead of null pointer when * creating a new engine * @run main NullHostnameCheck TLSv1 * @run main NullHostnameCheck TLSv1.1 * @run main NullHostnameCheck TLSv1.2 * @run main NullHostnameCheck TLSv1.3 */ --- 19,50 ---- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! import java.nio.ByteBuffer; ! import java.security.cert.CertificateException; ! import java.security.cert.X509Certificate; ! import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLException; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLParameters; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; ! ! import jdk.test.lib.security.KeyStoreUtils; ! import jdk.test.lib.security.SSLContextBuilder; /* * @test * @bug 8211339 8234728 * @summary Verify hostname returns an exception instead of null pointer when * creating a new engine + * @library /test/lib * @run main NullHostnameCheck TLSv1 * @run main NullHostnameCheck TLSv1.1 * @run main NullHostnameCheck TLSv1.2 * @run main NullHostnameCheck TLSv1.3 */
*** 51,70 **** public final class NullHostnameCheck { public static void main(String[] args) throws Exception { String protocol = args[0]; ! KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); ! keyStore.load( ! new ByteArrayInputStream(Base64.getDecoder(). ! decode(keystoreB64)), ! "123456".toCharArray()); ! KeyManagerFactory kmf = KeyManagerFactory.getInstance( ! KeyManagerFactory.getDefaultAlgorithm()); ! kmf.init(keyStore, "123456".toCharArray()); ! SSLContext serverCtx = SSLContext.getInstance(protocol); ! serverCtx.init(kmf.getKeyManagers(), null, null); SSLEngine serverEngine = serverCtx.createSSLEngine("localhost", -1); serverEngine.setUseClientMode(false); SSLContext clientCtx = SSLContext.getInstance(protocol); clientCtx.init(null, new TrustManager[] { --- 52,68 ---- public final class NullHostnameCheck { public static void main(String[] args) throws Exception { String protocol = args[0]; ! String password = "123456"; ! SSLContext serverCtx = SSLContextBuilder.builder() ! .keyStore(KeyStoreUtils.loadKeyStoreBase64( ! keystoreB64, password)) ! .kmfPassphrase(password) ! .protocol(protocol) ! .build(); SSLEngine serverEngine = serverCtx.createSSLEngine("localhost", -1); serverEngine.setUseClientMode(false); SSLContext clientCtx = SSLContext.getInstance(protocol); clientCtx.init(null, new TrustManager[] {
< prev index next >