mirror of https://github.com/grpc/grpc-java.git
Move TLS certificates.
- Move certificates to src/main/resources folder. - Update the code that loads the certificates to make use of Java's resources API.
This commit is contained in:
parent
303482ad3c
commit
44574944b9
|
|
@ -216,10 +216,8 @@ public class TestServiceClient {
|
||||||
SslContext sslContext = null;
|
SslContext sslContext = null;
|
||||||
if (useTestCa) {
|
if (useTestCa) {
|
||||||
try {
|
try {
|
||||||
String dir = "integration-testing/certs";
|
sslContext = SslContext.newClientContext(Util.loadCert("ca.pem"));
|
||||||
sslContext = SslContext.newClientContext(
|
} catch (Exception ex) {
|
||||||
new File(dir + "/ca.pem"));
|
|
||||||
} catch (SSLException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,10 +134,8 @@ public class TestServiceServer {
|
||||||
executor = Executors.newSingleThreadScheduledExecutor();
|
executor = Executors.newSingleThreadScheduledExecutor();
|
||||||
SslContext sslContext = null;
|
SslContext sslContext = null;
|
||||||
if (useTls) {
|
if (useTls) {
|
||||||
String dir = "integration-testing/certs";
|
sslContext = SslContext.newServerContext(Util.loadCert("server1.pem"),
|
||||||
sslContext = SslContext.newServerContext(
|
Util.loadCert("server1.key"));
|
||||||
new File(dir + "/server1.pem"),
|
|
||||||
new File(dir + "/server1.key"));
|
|
||||||
}
|
}
|
||||||
server = NettyServerBuilder.forPort(port)
|
server = NettyServerBuilder.forPort(port)
|
||||||
.sslContext(sslContext)
|
.sslContext(sslContext)
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,12 @@ import io.grpc.proto.ProtoUtils;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -54,9 +59,8 @@ public class Util {
|
||||||
* Picks an unused port.
|
* Picks an unused port.
|
||||||
*/
|
*/
|
||||||
public static int pickUnusedPort() {
|
public static int pickUnusedPort() {
|
||||||
ServerSocket serverSocket = null;
|
|
||||||
try {
|
try {
|
||||||
serverSocket = new ServerSocket(0);
|
ServerSocket serverSocket = new ServerSocket(0);
|
||||||
int port = serverSocket.getLocalPort();
|
int port = serverSocket.getLocalPort();
|
||||||
serverSocket.close();
|
serverSocket.close();
|
||||||
return port;
|
return port;
|
||||||
|
|
@ -65,6 +69,29 @@ public class Util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a file from the resources folder.
|
||||||
|
*
|
||||||
|
* @param name name of a file in src/main/resources/certs.
|
||||||
|
*/
|
||||||
|
public static File loadCert(String name) throws IOException {
|
||||||
|
InputStream in = Util.class.getResourceAsStream("/certs/" + name);
|
||||||
|
File tmpFile = File.createTempFile(name, "");
|
||||||
|
tmpFile.deleteOnExit();
|
||||||
|
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter(tmpFile));
|
||||||
|
try {
|
||||||
|
int b;
|
||||||
|
while ((b = in.read()) != -1) {
|
||||||
|
writer.write(b);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmpFile;
|
||||||
|
}
|
||||||
|
|
||||||
public static void assertEquals(MessageLite expected, MessageLite actual) {
|
public static void assertEquals(MessageLite expected, MessageLite actual) {
|
||||||
if (expected == null || actual == null) {
|
if (expected == null || actual == null) {
|
||||||
Assert.assertEquals(expected, actual);
|
Assert.assertEquals(expected, actual);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue