GrpcTlsClientCredentials

Available in a dev version: 0․11․0-grpc-186

How to configure

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
}

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
}

Default System Trust Store

If no trust manager is configured, the system's default trust store is used:

val credentials = TlsClientCredentials { }  // Uses system CA certificates

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.

See also

Constructors

Link copied to clipboard
constructor(configure: GrpcTlsClientCredentialsBuilder.() -> Unit = {})

Functions

Link copied to clipboard

Combines client credentials with call credentials.

Link copied to clipboard

Combines client credentials with call credentials.