Path: blob/master/test/jdk/javax/net/ssl/TLSCommon/interop/AbstractPeer.java
41154 views
/*1* Copyright (c) 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.Path;25import java.util.Collections;26import java.util.HashMap;27import java.util.Map;28import java.util.Objects;2930/*31* Abstract peer implementation.32*/33public abstract class AbstractPeer implements Peer {3435/*36* Peer's log path. The path could be null.37*/38protected Path getLogPath() {39return null;40}4142/*43* Prints the content of log file to stdout.44*/45protected void printLog() throws IOException {46Path logPath = getLogPath();47Objects.requireNonNull(logPath, "Please specify log path.");48System.out.println(Utilities.readFile(logPath).orElse(""));49}5051/*52* Deletes log file if exists.53*/54protected void deleteLog() throws IOException {55Utilities.deleteFile(getLogPath());56}5758/*59* The negotiated application protocol.60*/61public String getNegoAppProtocol() throws SSLTestException {62throw new UnsupportedOperationException("getNegoAppProtocol");63}6465@Override66public void close() throws IOException { }6768public static abstract class Builder implements Peer.Builder {6970// The supported SSL/TLS protocols.71private Protocol[] protocols;7273// The supported cipher suites.74private CipherSuite[] cipherSuites;7576// The trusted CAs and certificates.77private CertTuple certTuple;7879// The server-acceptable SNI server name patterns;80// Or the client-desired SNI server names.81private String[] serverNames;8283// The supported application protocols.84private String[] appProtocols;8586// The supported named groups.87private NamedGroup[] namedGroups;8889private String message = "M";9091private int timeout = Utilities.TIMEOUT;9293// System properties94private final Map<String, String> props = new HashMap<>();9596public Protocol[] getProtocols() {97return protocols;98}99100public Protocol getProtocol() {101return protocols != null && protocols.length > 0102? protocols[0]103: null;104}105106public Builder setProtocols(Protocol... protocols) {107this.protocols = protocols;108return this;109}110111public CipherSuite[] getCipherSuites() {112return cipherSuites;113}114115public CipherSuite getCipherSuite() {116return cipherSuites != null && cipherSuites.length > 0117? cipherSuites[0]118: null;119}120121public Builder setCipherSuites(CipherSuite... cipherSuites) {122this.cipherSuites = cipherSuites;123return this;124}125126public CertTuple getCertTuple() {127return certTuple;128}129130public Builder setCertTuple(CertTuple certTuple) {131this.certTuple = certTuple;132return this;133}134135public String[] getServerNames() {136return serverNames;137}138139public String getServerName() {140return serverNames != null && serverNames.length > 0141? serverNames[0]142: null;143}144145public Builder setServerNames(String... serverNames) {146this.serverNames = serverNames;147return this;148}149150public String[] getAppProtocols() {151return appProtocols;152}153154public String getAppProtocol() {155return appProtocols != null && appProtocols.length > 0156? appProtocols[0]157: null;158}159160public Builder setAppProtocols(String... appProtocols) {161this.appProtocols = appProtocols;162return this;163}164165public NamedGroup[] getNamedGroups() {166return namedGroups;167}168169public Builder setNamedGroups(NamedGroup... namedGroups) {170this.namedGroups = namedGroups;171return this;172}173174public String getMessage() {175return message;176}177178public Builder setMessage(String message) {179this.message = message;180return this;181}182183public int getTimeout() {184return timeout;185}186187public Builder setTimeout(int timeout) {188this.timeout = timeout;189return this;190}191192public Builder addProp(String prop, String value) {193props.put(prop, value);194return this;195}196197public String getProp(String prop) {198return props.get(prop);199}200201public Builder addAllProps(Map<String, String> props) {202this.props.putAll(props);203return this;204}205206public Map<String, String> getAllProps() {207return Collections.unmodifiableMap(props);208}209210public abstract AbstractPeer build() throws Exception;211}212}213214215