Top Description Inners Fields Constructors Methods
io.grpc

public final Class TlsServerCredentials

extends ServerCredentials
Class Inheritance
Imports
com.google.common.base.Preconditions, 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 identity and encryption. Consumers of this credential must verify they understand the configuration via the incomprehensible() method. Unless overridden by a Feature, server identity is provided via getCertificateChain, getPrivateKey, and getPrivateKeyPassword.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static enum
TlsServerCredentials.ClientAuth

The level of authentication the server should expect from the client.

public static enum
TlsServerCredentials.Feature

Features to understand TLS configuration.

Field Summary

Modifier and TypeField and Description
private final byte[]
private final TlsServerCredentials.ClientAuth
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 ServerCredentials
create(File certChain, File privateKey)

Creates an instance using provided certificate chain and private key.

public static ServerCredentials
create(InputStream certChain, InputStream privateKey)

Creates an instance using provided certificate chain and private key.

public byte[]
getCertificateChain()

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

public TlsServerCredentials.ClientAuth
getClientAuth()

Non-null setting indicating whether the server should expect a client's identity.

public List<KeyManager>
getKeyManagers()

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

public byte[]
getPrivateKey()

The private key for the server'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 client's identity that override the system's defaults.

public List<TrustManager>
getTrustManagers()

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

public Set<TlsServerCredentials.Feature>

Returns:

empty set if the caller can adequately understand the configuration
incomprehensible
(Set<TlsServerCredentials.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 TlsServerCredentials.Builder
newBuilder()

Creates a builder for changing default configuration.

private static void

Field Detail

certificateChainback to summary
private final byte[] certificateChain
clientAuthback to summary
private final TlsServerCredentials.ClientAuth clientAuth
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

TlsServerCredentialsback to summary
pack-priv TlsServerCredentials(TlsServerCredentials.Builder builder)

Method Detail

createback to summary
public static ServerCredentials create(File certChain, File privateKey) throws IOException

Creates an instance using provided certificate chain and private key. Generally they should be PEM-encoded and the key is an unencrypted PKCS#8 key (file headers have "BEGIN CERTIFICATE" and "BEGIN PRIVATE KEY").

createback to summary
public static ServerCredentials create(InputStream certChain, InputStream privateKey) throws IOException

Creates an instance using provided certificate chain and private key. Generally they should be PEM-encoded and the key is an unencrypted PKCS#8 key (file headers have "BEGIN CERTIFICATE" and "BEGIN PRIVATE KEY").

The streams will not be automatically closed.

getCertificateChainback to summary
public byte[] getCertificateChain()

The certificate chain for the server'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.

getClientAuthback to summary
public TlsServerCredentials.ClientAuth getClientAuth()

Non-null setting indicating whether the server should expect a client's identity.

getKeyManagersback to summary
public List<KeyManager> getKeyManagers()

Returns the key manager list which provides the server'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.

getPrivateKeyback to summary
public byte[] getPrivateKey()

The private key for the server'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.

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 client'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 client'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<TlsServerCredentials.Feature> incomprehensible(Set<TlsServerCredentials.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<TlsServerCredentials.Feature>

the features understood by the caller

Returns:Set<TlsServerCredentials.Feature>

empty set if the caller can adequately understand the configuration

newBuilderback to summary
public static TlsServerCredentials.Builder newBuilder()

Creates a builder for changing default configuration. There is no default key manager, so key material must be specified. The default trust manager uses the system's root certificates. By default no client authentication will occur.

requiredFeatureback to summary
private static void requiredFeature(Set<TlsServerCredentials.Feature> understoodFeatures, Set<TlsServerCredentials.Feature> incomprehensible, TlsServerCredentials.Feature feature)
io.grpc back to summary

public final Class TlsServerCredentials.Builder

extends Object
Class Inheritance

Builder for TlsServerCredentials.

Field Summary

Modifier and TypeField and Description
private byte[]
private TlsServerCredentials.ClientAuth
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 ServerCredentials
build()

Construct the credentials.

private void
private void
public TlsServerCredentials.Builder
clientAuth(TlsServerCredentials.ClientAuth clientAuth)

Indicates whether the server should expect a client's identity.

public TlsServerCredentials.Builder
keyManager(File certChain, File privateKey)

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

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

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

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

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

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

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

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

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

public TlsServerCredentials.Builder
requireFakeFeature()

Requires Feature#FAKE to be understood.

public TlsServerCredentials.Builder
trustManager(File rootCerts)

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

public TlsServerCredentials.Builder
trustManager(InputStream rootCerts)

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

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

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

certificateChainback to summary
private byte[] certificateChain
clientAuthback to summary
private TlsServerCredentials.ClientAuth clientAuth
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 ServerCredentials build()

Construct the credentials.

clearKeyManagersback to summary
private void clearKeyManagers()
clearTrustManagersback to summary
private void clearTrustManagers()
clientAuthback to summary
public TlsServerCredentials.Builder clientAuth(TlsServerCredentials.ClientAuth clientAuth)

Indicates whether the server should expect a client's identity. Must not be null. Defaults to ClientAuth#NONE.

keyManagerback to summary
public TlsServerCredentials.Builder keyManager(File certChain, File privateKey) throws IOException

Use the provided certificate chain and private key as the server'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 TlsServerCredentials.Builder keyManager(File certChain, File privateKey, String privateKeyPassword) throws IOException

Use the provided certificate chain and possibly-encrypted private key as the server'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 TlsServerCredentials.Builder keyManager(InputStream certChain, InputStream privateKey) throws IOException

Use the provided certificate chain and private key as the server'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 TlsServerCredentials.Builder keyManager(InputStream certChain, InputStream privateKey, String privateKeyPassword) throws IOException

Use the provided certificate chain and possibly-encrypted private key as the server'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 TlsServerCredentials.Builder keyManager(KeyManager... keyManagers)

Have the provided key manager select the server'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 TlsServerCredentials.Builder requireFakeFeature()

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

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

Use the provided root certificates to verify the client'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 TlsServerCredentials.Builder trustManager(InputStream rootCerts) throws IOException

Use the provided root certificates to verify the client'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 TlsServerCredentials.Builder trustManager(TrustManager... trustManagers)

Have the provided trust manager verify the client'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 TlsServerCredentials.ClientAuth

extends Enum<TlsServerCredentials.ClientAuth>
Class Inheritance

The level of authentication the server should expect from the client.

Field Summary

Modifier and TypeField and Description
public static final TlsServerCredentials.ClientAuth
NONE

Clients will not present any identity.

public static final TlsServerCredentials.ClientAuth
OPTIONAL

Clients are requested to present their identity, but clients without identities are permitted.

public static final TlsServerCredentials.ClientAuth
REQUIRE

Clients are requested to present their identity, and are required to provide a valid identity.

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

NONEback to summary
public static final TlsServerCredentials.ClientAuth NONE

Clients will not present any identity.

OPTIONALback to summary
public static final TlsServerCredentials.ClientAuth OPTIONAL

Clients are requested to present their identity, but clients without identities are permitted.

REQUIREback to summary
public static final TlsServerCredentials.ClientAuth REQUIRE

Clients are requested to present their identity, and are required to provide a valid identity.

Constructor Detail

ClientAuthback to summary
private ClientAuth()

Method Detail

valueOfback to summary
public static TlsServerCredentials.ClientAuth valueOf(String name)
valuesback to summary
public static TlsServerCredentials.ClientAuth[] values()
io.grpc back to summary

public final Enum TlsServerCredentials.Feature

extends Enum<TlsServerCredentials.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 TlsServerCredentials.Feature
CUSTOM_MANAGERS

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

public static final TlsServerCredentials.Feature
FAKE

A feature that no consumer should understand.

public static final TlsServerCredentials.Feature
MTLS

Client certificates may be requested and verified.

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

CUSTOM_MANAGERSback to summary
public static final TlsServerCredentials.Feature CUSTOM_MANAGERS

Key managers and trust managers may be specified as KeyManager and TrustManager objects. This feature by itself only implies getKeyManagers() needs to be observed. But along with MTLS, then getTrustManagers() needs to be observed as well. 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 TlsServerCredentials.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 TlsServerCredentials.Feature MTLS

Client certificates may be requested and verified. This feature requires observing getRootCertificates() and getClientAuth(). The root certificates are used to configure a trust manager for verifying the client'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 TlsServerCredentials.Feature valueOf(String name)
valuesback to summary
public static TlsServerCredentials.Feature[] values()