Skip to content

Commit

Permalink
Style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
erm-g committed Jul 8, 2024
1 parent aed2c3b commit 940e7be
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 6 additions & 6 deletions netty/src/test/java/io/grpc/netty/AdvancedTlsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void basicMutualTlsTest() throws Exception {
public void advancedTlsKeyManagerTrustManagerMutualTlsTest() throws Exception {
// Create a server with the key manager and trust manager.
AdvancedTlsX509KeyManager serverKeyManager = new AdvancedTlsX509KeyManager();
serverKeyManager.updateIdentityCredentials(serverKey0, serverCert0);
serverKeyManager.updateIdentityCredentials(serverCert0, serverKey0);
AdvancedTlsX509TrustManager serverTrustManager = AdvancedTlsX509TrustManager.newBuilder()
.setVerification(Verification.CERTIFICATE_ONLY_VERIFICATION)
.build();
Expand All @@ -159,7 +159,7 @@ public void advancedTlsKeyManagerTrustManagerMutualTlsTest() throws Exception {
new SimpleServiceImpl()).build().start();
// Create a client with the key manager and trust manager.
AdvancedTlsX509KeyManager clientKeyManager = new AdvancedTlsX509KeyManager();
clientKeyManager.updateIdentityCredentials(clientKey0, clientCert0);
clientKeyManager.updateIdentityCredentials(clientCert0, clientKey0);
AdvancedTlsX509TrustManager clientTrustManager = AdvancedTlsX509TrustManager.newBuilder()
.setVerification(Verification.CERTIFICATE_AND_HOST_NAME_VERIFICATION)
.build();
Expand All @@ -182,7 +182,7 @@ public void advancedTlsKeyManagerTrustManagerMutualTlsTest() throws Exception {
@Test
public void trustManagerCustomVerifierMutualTlsTest() throws Exception {
AdvancedTlsX509KeyManager serverKeyManager = new AdvancedTlsX509KeyManager();
serverKeyManager.updateIdentityCredentials(serverKey0, serverCert0);
serverKeyManager.updateIdentityCredentials(serverCert0, serverKey0);
// Set server's custom verification based on the information of clientCert0.
AdvancedTlsX509TrustManager serverTrustManager = AdvancedTlsX509TrustManager.newBuilder()
.setVerification(Verification.CERTIFICATE_ONLY_VERIFICATION)
Expand Down Expand Up @@ -221,7 +221,7 @@ public void verifyPeerCertificate(X509Certificate[] peerCertChain, String authTy
new SimpleServiceImpl()).build().start();

AdvancedTlsX509KeyManager clientKeyManager = new AdvancedTlsX509KeyManager();
clientKeyManager.updateIdentityCredentials(clientKey0, clientCert0);
clientKeyManager.updateIdentityCredentials(clientCert0, clientKey0);
// Set client's custom verification based on the information of serverCert0.
AdvancedTlsX509TrustManager clientTrustManager = AdvancedTlsX509TrustManager.newBuilder()
.setVerification(Verification.CERTIFICATE_ONLY_VERIFICATION)
Expand Down Expand Up @@ -275,7 +275,7 @@ public void trustManagerInsecurelySkipAllTest() throws Exception {
AdvancedTlsX509KeyManager serverKeyManager = new AdvancedTlsX509KeyManager();
// Even if we provide bad credentials for the server, the test should still pass, because we
// will configure the client to skip all checks later.
serverKeyManager.updateIdentityCredentials(serverKeyBad, serverCertBad);
serverKeyManager.updateIdentityCredentials(serverCertBad, serverKeyBad);
AdvancedTlsX509TrustManager serverTrustManager = AdvancedTlsX509TrustManager.newBuilder()
.setVerification(Verification.CERTIFICATE_ONLY_VERIFICATION)
.setSslSocketAndEnginePeerVerifier(
Expand All @@ -297,7 +297,7 @@ public void verifyPeerCertificate(X509Certificate[] peerCertChain, String authTy
new SimpleServiceImpl()).build().start();

AdvancedTlsX509KeyManager clientKeyManager = new AdvancedTlsX509KeyManager();
clientKeyManager.updateIdentityCredentials(clientKey0, clientCert0);
clientKeyManager.updateIdentityCredentials(clientCert0, clientKey0);
// Set the client to skip all checks, including traditional certificate verification.
// Note this is very dangerous in production environment - only do so if you are confident on
// what you are doing!
Expand Down
15 changes: 14 additions & 1 deletion util/src/main/java/io/grpc/util/AdvancedTlsX509KeyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,21 @@ public String chooseEngineServerAlias(String keyType, Principal[] issuers,
*
* @param key the private key that is going to be used
* @param certs the certificate chain that is going to be used
* @deprecated Use {@link #updateIdentityCredentials(X509Certificate[], PrivateKey)}
*/
@Deprecated
@InlineMe(replacement = "this.updateIdentityCredentials(certs, key)")
public void updateIdentityCredentials(PrivateKey key, X509Certificate[] certs) {
updateIdentityCredentials(certs, key);
}

/**
* Updates the current cached private key and cert chains.
*
* @param key the private key that is going to be used
* @param certs the certificate chain that is going to be used
*/
public void updateIdentityCredentials(X509Certificate[] certs, PrivateKey key,) {
this.keyInfo = new KeyInfo(checkNotNull(key, "key"), checkNotNull(certs, "certs"));
}

Expand Down Expand Up @@ -271,7 +284,7 @@ private UpdateResult readAndUpdate(File certFile, File keyFile, long oldKeyTime,
FileInputStream certInputStream = new FileInputStream(certFile);
try {
X509Certificate[] certs = CertificateUtils.getX509Certificates(certInputStream);
updateIdentityCredentials(key, certs);
updateIdentityCredentials(certs, key);
return new UpdateResult(true, newKeyTime, newCertTime);
} finally {
certInputStream.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void setUp() throws Exception {
public void credentialSetting() throws Exception {
// Overall happy path checking of public API.
AdvancedTlsX509KeyManager serverKeyManager = new AdvancedTlsX509KeyManager();
serverKeyManager.updateIdentityCredentials(serverKey0, serverCert0);
serverKeyManager.updateIdentityCredentials(serverCert0, serverKey0);
assertEquals(serverKey0, serverKeyManager.getPrivateKey(ALIAS));
assertArrayEquals(serverCert0, serverKeyManager.getCertificateChain(ALIAS));

Expand All @@ -98,11 +98,11 @@ public void credentialSettingParameterValidity() throws Exception {
// Checking edge cases of public API parameter setting.
AdvancedTlsX509KeyManager serverKeyManager = new AdvancedTlsX509KeyManager();
NullPointerException npe = assertThrows(NullPointerException.class, () -> serverKeyManager
.updateIdentityCredentials(null, serverCert0));
.updateIdentityCredentials(serverCert0, null));
assertEquals("key", npe.getMessage());

npe = assertThrows(NullPointerException.class, () -> serverKeyManager
.updateIdentityCredentials(serverKey0, null));
.updateIdentityCredentials(null, serverKey0));
assertEquals("certs", npe.getMessage());

npe = assertThrows(NullPointerException.class, () -> serverKeyManager
Expand Down

0 comments on commit 940e7be

Please sign in to comment.