Top Description Inners Fields Constructors Methods
io.grpc

public final Class TlsChannelCredentials

extends ChannelCredentials
Class Inheritance
Imports
com.google.common.io.ByteStreams, java.io.File, .FileInputStream, .IOException, .InputStream, java.util.ArrayList, .Arrays, .Collections, .EnumSet, .List, .Set, javax.net.ssl.KeyManager, .TrustManager

TLS credentials, providing server authentication and encryption. Consumers of this credential must verify they understand the configuration via the incomprehensible() method. Unless overridden by a Feature, server verification should use customary default root certificates.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static enum
TlsChannelCredentials.Feature

Features to understand TLS configuration.

Field Summary

Modifier and TypeField and Description
private final byte[]
private final boolean
private final List<KeyManager>
private final byte[]
private final String
private final byte[]
private final List<TrustManager>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static ChannelCredentials
create()

Use TLS with its defaults.

public byte[]
getCertificateChain()

The certificate chain for the client's identity, as a new byte array.

public List<KeyManager>
getKeyManagers()

Returns the key manager list which provides the client's identity.

public byte[]
getPrivateKey()

The private key for the client's identity, as a new byte array.

public String
getPrivateKeyPassword()

Returns the password to decrypt the private key, or null if unencrypted.

public byte[]
getRootCertificates()

Root trust certificates for verifying the server's identity that override the system's defaults.

public List<TrustManager>
getTrustManagers()

Returns the trust manager list which verifies the server's identity.

public Set<TlsChannelCredentials.Feature>

Returns:

empty set if the caller can adequately understand the configuration
incomprehensible
(Set<TlsChannelCredentials.Feature>
the features understood by the caller
understoodFeatures
)

Returns an empty set if this credential can be adequately understood via the features listed, otherwise returns a hint of features that are lacking to understand the configuration to be used for manual debugging.

public static TlsChannelCredentials.Builder
newBuilder()

Creates a builder for changing default configuration.

private static void
public ChannelCredentials
withoutBearerTokens()

Implements abstract io.grpc.ChannelCredentials.withoutBearerTokens.

Returns the ChannelCredentials stripped of its CallCredentials.

Field Detail

certificateChainback to summary
private final byte[] certificateChain
fakeFeatureback to summary
private final boolean fakeFeature
keyManagersback to summary
private final List<KeyManager> keyManagers
privateKeyback to summary
private final byte[] privateKey
privateKeyPasswordback to summary
private final String privateKeyPassword
rootCertificatesback to summary
private final byte[] rootCertificates
trustManagersback to summary
private final List<TrustManager> trustManagers

Constructor Detail

TlsChannelCredentialsback to summary
pack-priv TlsChannelCredentials(TlsChannelCredentials.Builder builder)

Method Detail

createback to summary
public static ChannelCredentials create()

Use TLS with its defaults.

getCertificateChainback to summary
public byte[] getCertificateChain()

The certificate chain for the client's identity, as a new byte array. Generally should be PEM-encoded. If null, some feature is providing key manager information via a different method or no client identity is available.

getKeyManagersback to summary
public List<KeyManager> getKeyManagers()

Returns the key manager list which provides the client's identity. Entries are scanned checking for specific types, like javax.net.ssl.X509KeyManager. Only a single entry for a type is used. Entries earlier in the list are higher priority. If null, key manager information is provided via a different method or no client identity is available.

getPrivateKeyback to summary
public byte[] getPrivateKey()

The private key for the client's identity, as a new byte array. Generally should be in PKCS#8 format. If encrypted, getPrivateKeyPassword is the decryption key. If unencrypted, the password will be null. If null, some feature is providing key manager information via a different method or no client identity is available.

getPrivateKeyPasswordback to summary
public String getPrivateKeyPassword()

Returns the password to decrypt the private key, or null if unencrypted.

getRootCertificatesback to summary
public byte[] getRootCertificates()

Root trust certificates for verifying the server's identity that override the system's defaults. Generally PEM-encoded with multiple certificates concatenated.

getTrustManagersback to summary
public List<TrustManager> getTrustManagers()

Returns the trust manager list which verifies the server's identity. Entries are scanned checking for specific types, like javax.net.ssl.X509TrustManager. Only a single entry for a type is used. Entries earlier in the list are higher priority. If null, trust manager information is provided via the system's default or a different method.

incomprehensibleback to summary
public Set<TlsChannelCredentials.Feature> incomprehensible(Set<TlsChannelCredentials.Feature> understoodFeatures)

Returns an empty set if this credential can be adequately understood via the features listed, otherwise returns a hint of features that are lacking to understand the configuration to be used for manual debugging.

An "understood" feature does not imply the caller is able to fully handle the feature. It simply means the caller understands the feature enough to use the appropriate APIs to read the configuration. The caller may support just a subset of a feature, in which case the caller would need to look at the configuration to determine if only the supported subset is used.

This method may not be as simple as a set difference. There may be multiple features that can independently satisfy a piece of configuration. If the configuration is incomprehensible, all such features would be returned, even though only one may be necessary.

An empty set does not imply that the credentials are fully understood. There may be optional configuration that can be ignored if not understood.

Since Feature is an enum, understoodFeatures should generally be an java.util.EnumSet. understoodFeatures will not be modified.

Parameters
understoodFeatures:Set<TlsChannelCredentials.Feature>

the features understood by the caller

Returns:Set<TlsChannelCredentials.Feature>

empty set if the caller can adequately understand the configuration

newBuilderback to summary
public static TlsChannelCredentials.Builder newBuilder()

Creates a builder for changing default configuration.

requiredFeatureback to summary
private static void requiredFeature(Set<TlsChannelCredentials.Feature> understoodFeatures, Set<TlsChannelCredentials.Feature> incomprehensible, TlsChannelCredentials.Feature feature)
withoutBearerTokensback to summary
public ChannelCredentials withoutBearerTokens()

Implements abstract io.grpc.ChannelCredentials.withoutBearerTokens.

Doc from io.grpc.ChannelCredentials.withoutBearerTokens.

Returns the ChannelCredentials stripped of its CallCredentials. In the future, this may strip only some of the CallCredentials, preserving call credentials that are safe from replay attacks (e.g., if the token is bound to the channel's certificate).

Annotations
@Override
io.grpc back to summary

public final Class TlsChannelCredentials.Builder

extends Object
Class Inheritance

Builder for TlsChannelCredentials.

Field Summary

Modifier and TypeField and Description
private byte[]
private boolean
private List<KeyManager>
private byte[]
private String
private byte[]
private List<TrustManager>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public ChannelCredentials
build()

Construct the credentials.

private void
private void
public TlsChannelCredentials.Builder
keyManager(File certChain, File privateKey)

Use the provided certificate chain and private key as the client's identity.

public TlsChannelCredentials.Builder
keyManager(File certChain, File privateKey, String privateKeyPassword)

Use the provided certificate chain and possibly-encrypted private key as the client's identity.

public TlsChannelCredentials.Builder
keyManager(InputStream certChain, InputStream privateKey)

Use the provided certificate chain and private key as the client's identity.

public TlsChannelCredentials.Builder
keyManager(InputStream certChain, InputStream privateKey, String privateKeyPassword)

Use the provided certificate chain and possibly-encrypted private key as the client's identity.

public TlsChannelCredentials.Builder
keyManager(KeyManager... keyManagers)

Have the provided key manager select the client's identity.

public TlsChannelCredentials.Builder
requireFakeFeature()

Requires Feature#FAKE to be understood.

public TlsChannelCredentials.Builder
trustManager(File rootCerts)

Use the provided root certificates to verify the server's identity instead of the system's default.

public TlsChannelCredentials.Builder
trustManager(InputStream rootCerts)

Use the provided root certificates to verify the server's identity instead of the system's default.

public TlsChannelCredentials.Builder
trustManager(TrustManager... trustManagers)

Have the provided trust manager verify the server's identity instead of the system's default.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

certificateChainback to summary
private byte[] certificateChain
fakeFeatureback to summary
private boolean fakeFeature
keyManagersback to summary
private List<KeyManager> keyManagers
privateKeyback to summary
private byte[] privateKey
privateKeyPasswordback to summary
private String privateKeyPassword
rootCertificatesback to summary
private byte[] rootCertificates
trustManagersback to summary
private List<TrustManager> trustManagers

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public ChannelCredentials build()

Construct the credentials.

clearKeyManagersback to summary
private void clearKeyManagers()
clearTrustManagersback to summary
private void clearTrustManagers()
keyManagerback to summary
public TlsChannelCredentials.Builder keyManager(File certChain, File privateKey) throws IOException

Use the provided certificate chain and private key as the client's identity. Generally they should be PEM-encoded and the key is an unencrypted PKCS#8 key (file headers have "BEGIN CERTIFICATE" and "BEGIN PRIVATE KEY").

keyManagerback to summary
public TlsChannelCredentials.Builder keyManager(File certChain, File privateKey, String privateKeyPassword) throws IOException

Use the provided certificate chain and possibly-encrypted private key as the client's identity. Generally they should be PEM-encoded and the key is a PKCS#8 key. If the private key is unencrypted, then password must be null.

keyManagerback to summary
public TlsChannelCredentials.Builder keyManager(InputStream certChain, InputStream privateKey) throws IOException

Use the provided certificate chain and private key as the client's identity. Generally they should be PEM-encoded and the key is an unencrypted PKCS#8 key (file headers have "BEGIN CERTIFICATE" and "BEGIN PRIVATE KEY").

keyManagerback to summary
public TlsChannelCredentials.Builder keyManager(InputStream certChain, InputStream privateKey, String privateKeyPassword) throws IOException

Use the provided certificate chain and possibly-encrypted private key as the client's identity. Generally they should be PEM-encoded and the key is a PKCS#8 key. If the private key is unencrypted, then password must be null.

keyManagerback to summary
public TlsChannelCredentials.Builder keyManager(KeyManager... keyManagers)

Have the provided key manager select the client's identity. Although multiple are allowed, only the first instance implementing a particular interface is used. So generally there will just be a single entry and it implements javax.net.ssl.X509KeyManager.

requireFakeFeatureback to summary
public TlsChannelCredentials.Builder requireFakeFeature()

Requires Feature#FAKE to be understood. For use in testing consumers of this credential.

trustManagerback to summary
public TlsChannelCredentials.Builder trustManager(File rootCerts) throws IOException

Use the provided root certificates to verify the server's identity instead of the system's default. Generally they should be PEM-encoded with all the certificates concatenated together (file header has "BEGIN CERTIFICATE", and would occur once per certificate).

trustManagerback to summary
public TlsChannelCredentials.Builder trustManager(InputStream rootCerts) throws IOException

Use the provided root certificates to verify the server's identity instead of the system's default. Generally they should be PEM-encoded with all the certificates concatenated together (file header has "BEGIN CERTIFICATE", and would occur once per certificate).

trustManagerback to summary
public TlsChannelCredentials.Builder trustManager(TrustManager... trustManagers)

Have the provided trust manager verify the server's identity instead of the system's default. Although multiple are allowed, only the first instance implementing a particular interface is used. So generally there will just be a single entry and it implements javax.net.ssl.X509TrustManager.

io.grpc back to summary

public final Enum TlsChannelCredentials.Feature

extends Enum<TlsChannelCredentials.Feature>
Class Inheritance

Features to understand TLS configuration. Additional enum values may be added in the future.

Field Summary

Modifier and TypeField and Description
public static final TlsChannelCredentials.Feature
CUSTOM_MANAGERS

Key managers and trust managers may be specified as KeyManager and TrustManager objects.

public static final TlsChannelCredentials.Feature
FAKE

A feature that no consumer should understand.

public static final TlsChannelCredentials.Feature
MTLS

Client identity may be provided and server verification can be tuned.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static TlsChannelCredentials.Feature
public static TlsChannelCredentials.Feature[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CUSTOM_MANAGERSback to summary
public static final TlsChannelCredentials.Feature CUSTOM_MANAGERS

Key managers and trust managers may be specified as KeyManager and TrustManager objects. This feature requires observing getKeyManagers() and getTrustManagers(). Generally MTLS should also be supported, as that is the more common method of configuration. When a manager is non-null, then it is wholly responsible for key or trust material and usage; there is no need to check other manager sources like getCertificateChain() or getPrivateKey() (if KeyManager is available), or getRootCertificates() (if TrustManager is available).

If other manager sources are available (e.g., getPrivateKey() != null), then they may be alternative representations of the same configuration and the consumer is free to use those alternative representations if it prefers. But before doing so it must first check that it understands that alternative representation by using incomprehensible without the CUSTOM_MANAGERS feature.

FAKEback to summary
public static final TlsChannelCredentials.Feature FAKE

A feature that no consumer should understand. It should be used for unit testing to confirm a call to incomprehensible() is implemented properly.

MTLSback to summary
public static final TlsChannelCredentials.Feature MTLS

Client identity may be provided and server verification can be tuned. This feature requires observing getCertificateChain, getPrivateKey, and getPrivateKeyPassword as well as getRootCertificates(). The certificate chain and private key are used to configure a key manager to provide the client's identity. If no certificate chain and private key are provided the client will have no identity. The root certificates are used to configure a trust manager for verifying the server's identity. If no root certificates are provided the trust manager will default to the system's root certificates.

Constructor Detail

Featureback to summary
private Feature()

Method Detail

valueOfback to summary
public static TlsChannelCredentials.Feature valueOf(String name)
valuesback to summary
public static TlsChannelCredentials.Feature[] values()