Skip to content

Commit 8f51457

Browse files
author
Xudong Ma
committed
Rename getSslSocketFactoryForCertainCert to be newSslSocketFactoryForCa.
Fixes grpc#560
1 parent c740312 commit 8f51457

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@
3333

3434
import com.squareup.okhttp.ConnectionSpec;
3535
import com.squareup.okhttp.TlsVersion;
36-
3736
import io.grpc.ChannelImpl;
3837
import io.grpc.testing.TestUtils;
3938
import io.grpc.transport.netty.GrpcSslContexts;
4039
import io.grpc.transport.netty.NettyServerBuilder;
4140
import io.grpc.transport.okhttp.OkHttpChannelBuilder;
4241
import io.netty.handler.ssl.SupportedCipherSuiteFilter;
43-
4442
import org.junit.AfterClass;
4543
import org.junit.BeforeClass;
4644
import org.junit.runner.RunWith;
@@ -83,8 +81,8 @@ protected ChannelImpl createChannel() {
8381
.build())
8482
.overrideHostForAuthority(TestUtils.TEST_SERVER_HOST);
8583
try {
86-
builder.sslSocketFactory(TestUtils.getSslSocketFactoryForCertainCert(
87-
TestUtils.loadCert("ca.pem")));
84+
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(
85+
TestUtils.loadCert("ca.pem")));
8886
} catch (Exception e) {
8987
throw new RuntimeException(e);
9088
}

testing/src/main/java/io/grpc/testing/TestUtils.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,29 @@ public static File loadCert(String name) throws IOException {
220220
}
221221

222222
/**
223-
* Returns a SSLSocketFactory which uses the certificate specified in certChainFile.
223+
* Deprecated, please use {@link #newSslSocketFactoryForCa(File)} instead.
224224
*/
225+
@Deprecated
225226
public static SSLSocketFactory getSslSocketFactoryForCertainCert(File certChainFile)
226227
throws Exception {
228+
return newSslSocketFactoryForCa(certChainFile);
229+
}
230+
231+
/**
232+
* Creates an SSLSocketFactory which contains {@code certChainFile} as its only root certificate.
233+
*/
234+
public static SSLSocketFactory newSslSocketFactoryForCa(File certChainFile) throws Exception {
227235
KeyStore ks = KeyStore.getInstance("JKS");
228236
ks.load(null, null);
229237
CertificateFactory cf = CertificateFactory.getInstance("X.509");
230238
X509Certificate cert = (X509Certificate) cf.generateCertificate(
231-
new BufferedInputStream(new FileInputStream(certChainFile)));
239+
new BufferedInputStream(new FileInputStream(certChainFile)));
232240
X500Principal principal = cert.getSubjectX500Principal();
233241
ks.setCertificateEntry(principal.getName("RFC2253"), cert);
234242

235243
// Set up trust manager factory to use our key store.
236244
TrustManagerFactory trustManagerFactory =
237-
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
245+
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
238246
trustManagerFactory.init(ks);
239247
SSLContext context = SSLContext.getInstance("TLS");
240248
context.init(null, trustManagerFactory.getTrustManagers(), null);

0 commit comments

Comments
 (0)