-
Notifications
You must be signed in to change notification settings - Fork 3.9k
core, netty: allow InputStream based certs #4316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,9 @@ | |
import io.netty.handler.ssl.SslContextBuilder; | ||
import io.netty.handler.ssl.SslProvider; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.Provider; | ||
import java.security.Security; | ||
|
@@ -176,6 +178,70 @@ public void basicClientServerIntegrationTest() throws Exception { | |
client.unaryRpc(SimpleRequest.getDefaultInstance()); | ||
} | ||
|
||
/** | ||
* Same as basicClientServerIntegrationTest except we test the InputStream based certs API. | ||
*/ | ||
@Test | ||
public void basicClientServerIntegrationTestInputStreamCerts() throws Exception { | ||
InputStream serverCertChain = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of these InputStreams are passed to our code. This test is not adding any value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These assigned to on lines 193/194 , 218/219 and used immediately after. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only see them passed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, I will remove the test. |
||
InputStream serverPrivateKey = null; | ||
InputStream clientCertChain = null; | ||
InputStream clientPrivateKey = null; | ||
|
||
try { | ||
// Create & start a server. | ||
File serverCertChainFile = TestUtils.loadCert("server1.pem"); | ||
File serverPrivateKeyFile = TestUtils.loadCert("server1.key"); | ||
X509Certificate[] serverTrustedCaCerts = { | ||
TestUtils.loadX509Cert("ca.pem") | ||
}; | ||
serverCertChain = new FileInputStream(serverCertChainFile); | ||
serverPrivateKey = new FileInputStream(serverPrivateKeyFile); | ||
SslContextBuilder sslContextBuilder | ||
= SslContextBuilder.forServer(serverCertChain, serverPrivateKey); | ||
GrpcSslContexts.configure(sslContextBuilder, sslProvider); | ||
sslContextBuilder.trustManager(serverTrustedCaCerts) | ||
.clientAuth(ClientAuth.REQUIRE); | ||
server = NettyServerBuilder.forPort(0) | ||
.sslContext(sslContextBuilder.build()) | ||
.addService(new SimpleServiceImpl()) | ||
.build() | ||
.start(); | ||
|
||
// Create a client. | ||
File clientCertChainFile = TestUtils.loadCert("client.pem"); | ||
File clientPrivateKeyFile = TestUtils.loadCert("client.key"); | ||
X509Certificate[] clientTrustedCaCerts = { | ||
TestUtils.loadX509Cert("ca.pem") | ||
}; | ||
|
||
clientCertChain = new FileInputStream(clientCertChainFile); | ||
clientPrivateKey = new FileInputStream(clientPrivateKeyFile); | ||
channel = clientChannel(server.getPort(), clientContextBuilder | ||
.keyManager(clientCertChain, clientPrivateKey) | ||
.trustManager(clientTrustedCaCerts) | ||
.build()); | ||
} finally { | ||
if (serverCertChain != null) { | ||
serverCertChain.close(); | ||
} | ||
if (serverPrivateKey != null) { | ||
serverPrivateKey.close(); | ||
} | ||
if (clientCertChain != null) { | ||
clientCertChain.close(); | ||
} | ||
if (clientPrivateKey != null) { | ||
clientPrivateKey.close(); | ||
} | ||
} | ||
|
||
SimpleServiceGrpc.SimpleServiceBlockingStub client = SimpleServiceGrpc.newBlockingStub(channel); | ||
|
||
// Send an actual request, via the full GRPC & network stack, and check that a proper | ||
// response comes back. | ||
client.unaryRpc(SimpleRequest.getDefaultInstance()); | ||
} | ||
|
||
/** | ||
* Tests that a server configured to require client authentication refuses to accept connections | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert changes to this file.