How do I set the TLS/SNI (https://en.wikipedia.org/wiki/Server_Name_Indication) in the Python/C++ gRPC client API?
In other words, what's the equivalent of setting the -servername
in openssl s_client
?
I have verified my TLS server works by using the correct flags on openssl s_client
:
openssl s_client -connect "myserver.tunnel.dev:4443" -servername "myserver.tunnel.dev"
However, I wasn't able to setup the credentials correct with the Python /C++ API:
uri = "myserver.tunnel.dev:4443"
hostname = "myserver.tunnel.dev"
creds = grpc.ssl_channel_credentials(
root_certificates=dev_cert)
# root_certificates=certificate_chain)
# certificate_chain=certificate_chain)
channel = grpc.secure_channel(uri, creds,
options=(('grpc.ssl_target_name_override', hostname),)
)
This throws:
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, Connect Failed)>
In the ChannelOptions
struct, the closest option I could find is ssl_target_name_override
, which doesn't work either.
Setting options=(('grpc.ssl_target_name_override', hostname),)
should work. This is the right way to override host name. In this case, it seems unnecessary as your uri host and override host are the same. You could turn on some tracing by using the environment variables listed here and see if the handshake is failing or the is there some other reason for connection failure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With