Path: blob/master/test/jdk/javax/net/ssl/compatibility/Utils.java
41152 views
/*1* Copyright (c) 2017, 2020, Oracle and/or its affiliates. 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*/2223import java.io.IOException;24import java.nio.file.Files;25import java.nio.file.Paths;26import java.util.ArrayList;27import java.util.LinkedHashSet;28import java.util.List;29import java.util.Set;30import java.util.stream.Collectors;31import java.util.stream.Stream;3233import jdk.test.lib.security.CertUtils;3435/*36* Utilities for testing.37*/38public class Utils {3940public static final String PROP_JDK_LIST_FILE = "test.jdk.list.file";4142public static final String PROP_SEC_PROPS_FILE = "test.sec.props.file";43public static final String SEC_PROPS_FILE = System.getProperty(44PROP_SEC_PROPS_FILE,45System.getProperty("test.src") + "/java.security");4647public static final Cert RSA_CERT = new Cert(48KeyAlgorithm.RSA,49SignatureAlgorithm.RSA,50HashAlgorithm.SHA256,51CertUtils.RSA_CERT, CertUtils.RSA_KEY);52public static final Cert ECDSA_CERT = new Cert(53KeyAlgorithm.EC,54SignatureAlgorithm.ECDSA,55HashAlgorithm.SHA256,56CertUtils.ECDSA_CERT, CertUtils.ECDSA_KEY);57public static final Cert ECRSA_CERT = new Cert(58KeyAlgorithm.EC,59SignatureAlgorithm.RSA,60HashAlgorithm.SHA256,61CertUtils.ECRSA_CERT, CertUtils.ECRSA_KEY);62public static final Cert DSA_CERT = new Cert(63KeyAlgorithm.DSA,64SignatureAlgorithm.DSA,65HashAlgorithm.SHA256,66CertUtils.DSA_CERT, CertUtils.DSA_KEY);6768// Retrieves JDK info from the file which is specified by system property69// test.jdk.list.file.70public static Set<JdkInfo> jdkInfoList() {71List<String> jdkList = jdkList();7273Set<JdkInfo> jdkInfoList = new LinkedHashSet<>();74for (String jdkPath : jdkList) {75JdkInfo jdkInfo = new JdkInfo(Paths.get(jdkPath, "bin", "java"));76// JDK version must be unique.77if (!jdkInfoList.add(jdkInfo)) {78System.out.println("The JDK version is duplicate: " + jdkPath);79}80}81return jdkInfoList;82}8384private static List<String> jdkList() {85String listFile = System.getProperty(PROP_JDK_LIST_FILE);86System.out.println("jdk list file: " + listFile);87if (listFile != null && Files.exists(Paths.get(listFile))) {88try (Stream<String> lines = Files.lines(Paths.get(listFile))) {89return lines.filter(line -> {90return !line.trim().isEmpty();91}).collect(Collectors.toList());92} catch (IOException e) {93throw new RuntimeException("Cannot get jdk list", e);94}95} else {96return new ArrayList<>();97}98}99100public static Cert getCert(KeyExAlgorithm keyExAlgorithm) {101if (keyExAlgorithm == KeyExAlgorithm.RSA102|| keyExAlgorithm == KeyExAlgorithm.DHE_RSA103|| keyExAlgorithm == KeyExAlgorithm.ECDHE_RSA) {104return RSA_CERT;105} else if (keyExAlgorithm == KeyExAlgorithm.DHE_DSS) {106return DSA_CERT;107} else if (keyExAlgorithm == KeyExAlgorithm.ECDH_RSA) {108return ECRSA_CERT;109} else {110return ECDSA_CERT;111}112}113}114115116