8157996: Unneeded import in lib/testlibrary/jdk/testlibrary/SimpleSSLContext.java
Reviewed-by: mchung, chegar
This commit is contained in:
parent
6d029e8034
commit
9862c36936
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,8 +23,6 @@
|
|||||||
|
|
||||||
package jdk.testlibrary;
|
package jdk.testlibrary;
|
||||||
|
|
||||||
import com.sun.net.httpserver.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -54,7 +52,7 @@ public class SimpleSSLContext {
|
|||||||
* loads default keystore from SimpleSSLContext
|
* loads default keystore from SimpleSSLContext
|
||||||
* source directory
|
* source directory
|
||||||
*/
|
*/
|
||||||
public SimpleSSLContext () throws IOException {
|
public SimpleSSLContext() throws IOException {
|
||||||
String paths = System.getProperty("test.src.path");
|
String paths = System.getProperty("test.src.path");
|
||||||
StringTokenizer st = new StringTokenizer(paths, File.pathSeparator);
|
StringTokenizer st = new StringTokenizer(paths, File.pathSeparator);
|
||||||
boolean securityExceptions = false;
|
boolean securityExceptions = false;
|
||||||
@ -63,8 +61,10 @@ public class SimpleSSLContext {
|
|||||||
try {
|
try {
|
||||||
File f = new File(path, "jdk/testlibrary/testkeys");
|
File f = new File(path, "jdk/testlibrary/testkeys");
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
init (new FileInputStream(f));
|
try (FileInputStream fis = new FileInputStream(f)) {
|
||||||
return;
|
init(fis);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
// catch and ignore because permission only required
|
// catch and ignore because permission only required
|
||||||
@ -80,13 +80,14 @@ public class SimpleSSLContext {
|
|||||||
/**
|
/**
|
||||||
* loads default keystore from given directory
|
* loads default keystore from given directory
|
||||||
*/
|
*/
|
||||||
public SimpleSSLContext (String dir) throws IOException {
|
public SimpleSSLContext(String dir) throws IOException {
|
||||||
String file = dir+"/testkeys";
|
String file = dir+"/testkeys";
|
||||||
FileInputStream fis = new FileInputStream(file);
|
try (FileInputStream fis = new FileInputStream(file)) {
|
||||||
init(fis);
|
init(fis);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init (InputStream i) throws IOException {
|
private void init(InputStream i) throws IOException {
|
||||||
try {
|
try {
|
||||||
char[] passphrase = "passphrase".toCharArray();
|
char[] passphrase = "passphrase".toCharArray();
|
||||||
KeyStore ks = KeyStore.getInstance("JKS");
|
KeyStore ks = KeyStore.getInstance("JKS");
|
||||||
@ -98,22 +99,22 @@ public class SimpleSSLContext {
|
|||||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
|
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
|
||||||
tmf.init(ks);
|
tmf.init(ks);
|
||||||
|
|
||||||
ssl = SSLContext.getInstance ("TLS");
|
ssl = SSLContext.getInstance("TLS");
|
||||||
ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||||
} catch (KeyManagementException e) {
|
} catch (KeyManagementException e) {
|
||||||
throw new RuntimeException (e.getMessage());
|
throw new RuntimeException(e.getMessage());
|
||||||
} catch (KeyStoreException e) {
|
} catch (KeyStoreException e) {
|
||||||
throw new RuntimeException (e.getMessage());
|
throw new RuntimeException(e.getMessage());
|
||||||
} catch (UnrecoverableKeyException e) {
|
} catch (UnrecoverableKeyException e) {
|
||||||
throw new RuntimeException (e.getMessage());
|
throw new RuntimeException(e.getMessage());
|
||||||
} catch (CertificateException e) {
|
} catch (CertificateException e) {
|
||||||
throw new RuntimeException (e.getMessage());
|
throw new RuntimeException(e.getMessage());
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new RuntimeException (e.getMessage());
|
throw new RuntimeException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSLContext get () {
|
public SSLContext get() {
|
||||||
return ssl;
|
return ssl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user