GrpcTlsClientCredentials
Available in a dev version: 0․11․0-grpc-186
How to configure
class GrpcTlsClientCredentials(configure: GrpcTlsClientCredentialsBuilder.() -> Unit = {}) : GrpcClientCredentials(source)
TLS/SSL credentials for secure transport.
TLS credentials establish an encrypted connection to the gRPC server using TLS/SSL. This credential type supports both server authentication (standard TLS) and mutual TLS (mTLS) where the client also authenticates to the server.
Server Authentication (TLS)
Verify the server's identity using a trust manager with root certificates:
val tlsCredentials = GrpcTlsClientCredentials {
trustManager(serverCertPem)
}
val client = GrpcClient("example.com", 443) {
credentials = tlsCredentials
}Content copied to clipboard
Mutual TLS (mTLS)
For mutual authentication, provide both trust manager and key manager:
val credentials = GrpcTlsClientCredentials {
trustManager(caCertPem) // Server's CA certificate
keyManager(clientCertPem, clientKeyPem) // Client's certificate and private key
}Content copied to clipboard
Default System Trust Store
If no trust manager is configured, the system's default trust store is used:
val credentials = TlsClientCredentials { } // Uses system CA certificatesContent copied to clipboard
Note: The server certificate's Common Name (CN) or Subject Alternative Name (SAN) must match the authority specified in the client configuration, or the connection will fail.