API to add constraints on SSL for key size
See original GitHub issueIs your feature request related to a problem? Please describe.
I have a gRPC server which is using mutual TLS and I want to reject connections from clients who have a public key size less than 2048 bits.
Describe the solution you’d like
There should be an API in the SslContextBuilder
class to set SSL key size related constraints
Describe alternatives you’ve considered
I was able to achieve the same using a ServerInterceptor
by doing something like this
public class SSLInterceptor implements ServerInterceptor {
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
try {
SSLSession sslSession = call.getAttributes().get(Grpc.TRANSPORT_ATTR_SSL_SESSION);
RSAPublicKeyImpl pk = (RSAPublicKeyImpl) sslSession.getPeerCertificates()[0].getPublicKey();
if (pk.getModulus().bitLength() < 2048) {
// reject call
}
// proceed with the call
} catch (SSLPeerUnverifiedException e) {
// do something
}
...
}
}
This is a bad way to do it because
- The validation is being done after the connection is already established.
- The validation is only triggered when a request/call is made.
- Every single call involves an extra overhead of validation.
- In case of a validation failure, only the call is rejected but not the connection to the client.
In an ideal scenario
- The validation is done during the connection establishment phase. (or some point during the creation of the channel between client and server)
- The validation failure would prevent the connection from being created and not set it up and disconnect later.
- A client is only validated once per session and all the calls made during that session do not incur any overhead.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Certificates does not conform to algorithm constraints ...
Solution. Background. The CA API Gateway ensures the security of message traffic by requiring that protected services using SSL or TLS?are ...
Read more >Java Algorithm constraints check failed on key RSA with size ...
When my java applications call it, they fail because their policy is set to only accept RSA < 2048 keySize. I contacted AWS...
Read more >So you're making an RSA key for an HTTPS certificate. What ...
So you're about to make an RSA key for an SSL certificate. What key size should you use? OpenSSL now use a 2048...
Read more >Getting certificates ready in AWS Certificate Manager
As such, the requirements and constraints of a custom domain name SSL/TLS certificate are dictated by CloudFront. For example, the maximum size of...
Read more >AlgorithmConstraints (Java Platform SE 7 ) - Oracle Help Center
This interface specifies constraints for cryptographic algorithms, keys (key sizes), and other algorithm parameters. AlgorithmConstraints objects are ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@adityavikasd, I’d suggest making your own TrustManagerFactory. It seems you could extend TrustManagerFactory and override all the methods, delegating to another instance, except for getTrustManagers() in which you would write custom logic to return your trust manager instead of the default one.
The other potential option is to implement TrustManagerFactorySpi. You will still need to delegate to a real instance, so maybe create one with something like
(TrustManagerFactorySpi) Security.getProvider("JSSE").getService("TrustManagerFactory", TrustManagerFactory.getDefaultAlgorithm()).newInstance(null)
. I’d probably start with providing the “real” Provider to the TrustManagerFactorySpi.I’ve never done any of that before, but they seem like avenues try. I realize that the Java API is quite opaque, but it’s also all we have.
Thanks for the help. I was able to implement this. By creating my own
TrustManagerFactorySp
,TrustManagerFactorySpi
andTrustManager
.The Java security API seem so twisted though!