package testssl;
import com.perforce.p4java.exception.AccessException;
import com.perforce.p4java.exception.ConnectionException;
import com.perforce.p4java.exception.P4JavaException;
import com.perforce.p4java.impl.mapbased.rpc.RpcPropertyDefs;
import com.perforce.p4java.option.server.TrustOptions;
import com.perforce.p4java.server.IOptionsServer;
import com.perforce.p4java.server.ServerFactory;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Properties;
/**
* Connect and login to an SSL enabled p4d.
*
* @author jbrown
*/
public class GetSSLServer {
public static final String[] SUPPORTED_PROTOCOLS = new String[] {
"TLSv1",
"TLSv1.1",
"TLSv1.2",
"TLSv1.3"};
/**
* GetSSLServer p4javaUrl protocol
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("java: " + System.getProperty("java.version"));
if (args.length < 2) {
printSyntax();
System.exit(1);
}
String serverUrl = args[0];
String tlsVersion = args[1];
if ( ! Arrays.stream(SUPPORTED_PROTOCOLS).anyMatch(str -> str.equals(tlsVersion))) {
System.out.println("Unsupported TLS version: " + args[1]);
printSyntax();
System.exit(1);
}
// com.perforce.p4java.Log.setLogCallback(LogCallBack());
// IServer server = null;
IOptionsServer server = null;
// pw = null;
try {
Properties props = new Properties();
props.putAll(System.getProperties());
props.put(RpcPropertyDefs.RPC_SECURE_SOCKET_ENABLED_PROTOCOLS_NICK,tlsVersion);
server = ServerFactory.getOptionsServer(serverUrl, props);
server.addTrust(new TrustOptions().setForce(true).setAutoAccept(true));
System.out.println("Connecting to " + serverUrl);
server.connect();
System.out.println("Success!");
} catch (P4JavaException | URISyntaxException e) {
System.out.flush();
e.printStackTrace(System.out);
System.out.flush();
} finally {
if (server != null) {
try {
server.disconnect();
} catch (ConnectionException | AccessException ex ) {
// don't care.
// ex.printStackTrace(System.out);
}
}
}
}
private static void printSyntax() {
System.out.println("Syntax: GetSSLServer <p4javaUrl> <tls-version");
System.out.println(" tls versions: " + String.join(",",SUPPORTED_PROTOCOLS ));
System.out.println(" sample p4javaUri: p4javassl://HOST:PORT");
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
28029 |
Joel Brown |
New: for testing SSL handshakes to p4d enabled servers. |
|
|