I am using the Rust's tonic library for GRPC with TLS.
I get the following error
thread 'main' panicked at 'Failed to create request insight client: tonic::transport::Error(Transport,
hyper::Error(Connect, Custom { kind: InvalidData, error: InvalidCertificate(NotValidForName) }))'
The same certificate works for other languages.
curl --cacert <path to cert> -vv <server>
shows the expected certificate subject name.
This is how the ClientTlsConfig and Channel is created:
let tls = ClientTlsConfig::new()
.domain_name("server") // <server> matches the certificate subject name
.ca_certificate(Certificate::from_pem(client_ca_data));
let channel = Channel::from_shared(endpoint.to_string()) // endpoint is http://server:50051
.unwrap()
.tls_config(tls_config)?
.connect()
.await?;
It is not clear what the next steps are.
I had the same issue when using the
rustlsto establish connection between server and the client. Apparently, the rust is strict in handling such errors according to RFC regulations. Please use the following bash script to regenerate the key and self-signed certificates for your case. The generated files will exist underkeysdirectory. Remember to change the[alt_names]based on your settings.Please make sure that the client has the
rootCA.crtin your code. Something like this: