mirror of https://github.com/grpc/grpc-java.git
Make TestUtils able to read from input stream. This makes it easier to pass in an input stream from a resource
This commit is contained in:
parent
529b14c07b
commit
3fef40368d
|
|
@ -88,8 +88,7 @@ public class Http2OkHttpTest extends AbstractTransportTest {
|
||||||
.overrideAuthority(GrpcUtil.authorityFromHostAndPort(
|
.overrideAuthority(GrpcUtil.authorityFromHostAndPort(
|
||||||
TestUtils.TEST_SERVER_HOST, serverPort));
|
TestUtils.TEST_SERVER_HOST, serverPort));
|
||||||
try {
|
try {
|
||||||
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(
|
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(TestUtils.loadCert("ca.pem")));
|
||||||
TestUtils.loadCert("ca.pem")));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -217,11 +217,23 @@ public class TestUtils {
|
||||||
* Creates an SSLSocketFactory which contains {@code certChainFile} as its only root certificate.
|
* Creates an SSLSocketFactory which contains {@code certChainFile} as its only root certificate.
|
||||||
*/
|
*/
|
||||||
public static SSLSocketFactory newSslSocketFactoryForCa(File certChainFile) throws Exception {
|
public static SSLSocketFactory newSslSocketFactoryForCa(File certChainFile) throws Exception {
|
||||||
|
InputStream is = new FileInputStream(certChainFile);
|
||||||
|
try {
|
||||||
|
return newSslSocketFactoryForCa(is);
|
||||||
|
} finally {
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an SSLSocketFactory which contains {@code certChainFile} as its only root certificate.
|
||||||
|
*/
|
||||||
|
public static SSLSocketFactory newSslSocketFactoryForCa(InputStream certChain) throws Exception {
|
||||||
KeyStore ks = KeyStore.getInstance("JKS");
|
KeyStore ks = KeyStore.getInstance("JKS");
|
||||||
ks.load(null, null);
|
ks.load(null, null);
|
||||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||||
X509Certificate cert = (X509Certificate) cf.generateCertificate(
|
X509Certificate cert = (X509Certificate) cf.generateCertificate(
|
||||||
new BufferedInputStream(new FileInputStream(certChainFile)));
|
new BufferedInputStream(certChain));
|
||||||
X500Principal principal = cert.getSubjectX500Principal();
|
X500Principal principal = cert.getSubjectX500Principal();
|
||||||
ks.setCertificateEntry(principal.getName("RFC2253"), cert);
|
ks.setCertificateEntry(principal.getName("RFC2253"), cert);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue