forked from grpc/grpc-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
netty: Per-rpc authority verification against peer cert subject names (…
…grpc#11724) Per-rpc verification of authority specified via call options or set by the LB API against peer cert's subject names.
- Loading branch information
1 parent
57124d6
commit cdab410
Showing
19 changed files
with
1,228 additions
and
83 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
core/src/main/java/io/grpc/internal/AuthorityVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2025 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.grpc.internal; | ||
|
||
import io.grpc.Status; | ||
|
||
/** Verifier for the outgoing authority pseudo-header against peer cert. */ | ||
public interface AuthorityVerifier { | ||
Status verifyAuthority(String authority); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.grpc.internal; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.security.GeneralSecurityException; | ||
import java.security.KeyStore; | ||
import java.security.cert.Certificate; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.CertificateFactory; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Collection; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.TrustManagerFactory; | ||
import javax.security.auth.x500.X500Principal; | ||
|
||
/** | ||
* Contains certificate/key PEM file utility method(s) for internal usage. | ||
*/ | ||
public final class CertificateUtils { | ||
/** | ||
* Creates X509TrustManagers using the provided CA certs. | ||
*/ | ||
public static TrustManager[] createTrustManager(InputStream rootCerts) | ||
throws GeneralSecurityException { | ||
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); | ||
try { | ||
ks.load(null, null); | ||
} catch (IOException ex) { | ||
// Shouldn't really happen, as we're not loading any data. | ||
throw new GeneralSecurityException(ex); | ||
} | ||
X509Certificate[] certs = CertificateUtils.getX509Certificates(rootCerts); | ||
for (X509Certificate cert : certs) { | ||
X500Principal principal = cert.getSubjectX500Principal(); | ||
ks.setCertificateEntry(principal.getName("RFC2253"), cert); | ||
} | ||
|
||
TrustManagerFactory trustManagerFactory = | ||
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); | ||
trustManagerFactory.init(ks); | ||
return trustManagerFactory.getTrustManagers(); | ||
} | ||
|
||
private static X509Certificate[] getX509Certificates(InputStream inputStream) | ||
throws CertificateException { | ||
CertificateFactory factory = CertificateFactory.getInstance("X.509"); | ||
Collection<? extends Certificate> certs = factory.generateCertificates(inputStream); | ||
return certs.toArray(new X509Certificate[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
core/src/main/java/io/grpc/internal/NoopSslSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright 2024 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.grpc.internal; | ||
|
||
import java.security.Principal; | ||
import java.security.cert.Certificate; | ||
import javax.net.ssl.SSLPeerUnverifiedException; | ||
import javax.net.ssl.SSLSession; | ||
import javax.net.ssl.SSLSessionContext; | ||
|
||
/** A no-op ssl session, to facilitate overriding only the required methods in specific | ||
* implementations. | ||
*/ | ||
public class NoopSslSession implements SSLSession { | ||
@Override | ||
public byte[] getId() { | ||
return new byte[0]; | ||
} | ||
|
||
@Override | ||
public SSLSessionContext getSessionContext() { | ||
return null; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public javax.security.cert.X509Certificate[] getPeerCertificateChain() { | ||
throw new UnsupportedOperationException("This method is deprecated and marked for removal. " | ||
+ "Use the getPeerCertificates() method instead."); | ||
} | ||
|
||
@Override | ||
public long getCreationTime() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long getLastAccessedTime() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void invalidate() { | ||
} | ||
|
||
@Override | ||
public boolean isValid() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void putValue(String s, Object o) { | ||
} | ||
|
||
@Override | ||
public Object getValue(String s) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void removeValue(String s) { | ||
} | ||
|
||
@Override | ||
public String[] getValueNames() { | ||
return new String[0]; | ||
} | ||
|
||
@Override | ||
public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { | ||
return new Certificate[0]; | ||
} | ||
|
||
@Override | ||
public Certificate[] getLocalCertificates() { | ||
return new Certificate[0]; | ||
} | ||
|
||
@Override | ||
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Principal getLocalPrincipal() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getCipherSuite() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getProtocol() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPeerHost() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getPeerPort() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getPacketBufferSize() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getApplicationBufferSize() { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.