Path: blob/master/test/jdk/javax/net/ssl/compatibility/JdkInfo.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.nio.file.Path;24import java.util.LinkedHashMap;25import java.util.Map;2627/*28* It represents a JDK with some specific attributes.29* If two JdkInfo instances have the same version value, the instances are30* regarded as equivalent.31*/32public class JdkInfo {3334public static final JdkInfo DEFAULT = new JdkInfo(Jdk.DEFAULT.getPath());3536public final Path javaPath;3738public final String version;39public final String supportedProtocols;40public final String enabledProtocols;41public final String supportedCipherSuites;42public final String enabledCipherSuites;43public final boolean supportsSNI;44public final boolean supportsALPN;4546public JdkInfo(Path javaPath) {47this.javaPath = javaPath;4849String output = jdkAttributes(javaPath);50if (output == null || output.trim().isEmpty()) {51throw new RuntimeException(52"Cannot determine the JDK attributes: " + javaPath);53}5455String[] attributes = Utilities.split(output, Utilities.PARAM_DELIMITER);56version = attributes[0].replaceAll(".*=", "");57supportedProtocols = attributes[1].replaceAll(".*=", "");58enabledProtocols = attributes[2].replaceAll(".*=", "");59supportedCipherSuites = attributes[3].replaceAll(".*=", "");60enabledCipherSuites = attributes[4].replaceAll(".*=", "");61supportsSNI = Boolean.valueOf(attributes[5].replaceAll(".*=", ""));62supportsALPN = Boolean.valueOf(attributes[6].replaceAll(".*=", ""));63}6465// Determines the specific attributes for the specified JDK.66private static String jdkAttributes(Path javaPath) {67Map<String, String> props = new LinkedHashMap<>();68props.put("java.security.properties", Utils.SEC_PROPS_FILE);69return ProcUtils.java(javaPath, JdkInfoUtils.class, props).getOutput();70}7172@Override73public int hashCode() {74return version == null ? 0 : version.hashCode();75}7677@Override78public boolean equals(Object obj) {79if (this == obj) {80return true;81}82if (obj == null) {83return false;84}85if (getClass() != obj.getClass()) {86return false;87}88JdkInfo other = (JdkInfo) obj;89if (version == null) {90if (other.version != null) {91return false;92}93} else if (!version.equals(other.version)) {94return false;95}96return true;97}9899public boolean supportsProtocol(Protocol protocol) {100return supportedProtocols.contains(protocol.name);101}102103public boolean enablesProtocol(Protocol protocol) {104return enabledProtocols.contains(protocol.name);105}106107public boolean supportsCipherSuite(CipherSuite cipherSuite) {108return supportedCipherSuites.contains(cipherSuite.name());109}110111public boolean enablesCipherSuite(CipherSuite cipherSuite) {112return enabledCipherSuites.contains(cipherSuite.name());113}114}115116117