Package io.grpc.util
Class AdvancedTlsX509KeyManager
- java.lang.Object
-
- javax.net.ssl.X509ExtendedKeyManager
-
- io.grpc.util.AdvancedTlsX509KeyManager
-
- All Implemented Interfaces:
javax.net.ssl.KeyManager,javax.net.ssl.X509KeyManager
public final class AdvancedTlsX509KeyManager extends javax.net.ssl.X509ExtendedKeyManagerAdvancedTlsX509KeyManager is anX509ExtendedKeyManagerthat allows users to configure advanced TLS features, such as private key and certificate chain reloading.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAdvancedTlsX509KeyManager.CloseableMainly used to avoid throwing IO Exceptions in java.io.Closeable.private static classAdvancedTlsX509KeyManager.KeyInfoprivate classAdvancedTlsX509KeyManager.LoadFilePathExecutionprivate static classAdvancedTlsX509KeyManager.UpdateResult
-
Field Summary
Fields Modifier and Type Field Description private AdvancedTlsX509KeyManager.KeyInfokeyInfoprivate static java.util.logging.Loggerlogprivate static intMINIMUM_REFRESH_PERIOD_IN_MINUTES
-
Constructor Summary
Constructors Constructor Description AdvancedTlsX509KeyManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.StringchooseClientAlias(java.lang.String[] keyType, java.security.Principal[] issuers, java.net.Socket socket)java.lang.StringchooseEngineClientAlias(java.lang.String[] keyType, java.security.Principal[] issuers, javax.net.ssl.SSLEngine engine)java.lang.StringchooseEngineServerAlias(java.lang.String keyType, java.security.Principal[] issuers, javax.net.ssl.SSLEngine engine)java.lang.StringchooseServerAlias(java.lang.String keyType, java.security.Principal[] issuers, java.net.Socket socket)java.security.cert.X509Certificate[]getCertificateChain(java.lang.String alias)java.lang.String[]getClientAliases(java.lang.String keyType, java.security.Principal[] issuers)java.security.PrivateKeygetPrivateKey(java.lang.String alias)java.lang.String[]getServerAliases(java.lang.String keyType, java.security.Principal[] issuers)private AdvancedTlsX509KeyManager.UpdateResultreadAndUpdate(java.io.File certFile, java.io.File keyFile, long oldKeyTime, long oldCertTime)Reads the private key and certificates specified in the path locations.voidupdateIdentityCredentials(java.io.File certFile, java.io.File keyFile)Updates certificate chains and the private key from the local file paths.AdvancedTlsX509KeyManager.CloseableupdateIdentityCredentials(java.io.File certFile, java.io.File keyFile, long period, java.util.concurrent.TimeUnit unit, java.util.concurrent.ScheduledExecutorService executor)Schedules aScheduledExecutorServiceto read certificate chains and private key from the local file paths periodically, and update the cached identity credentials if they are both updated.voidupdateIdentityCredentials(java.security.cert.X509Certificate[] certs, java.security.PrivateKey key)Updates the current cached private key and cert chains.voidupdateIdentityCredentials(java.security.PrivateKey key, java.security.cert.X509Certificate[] certs)Deprecated.voidupdateIdentityCredentialsFromFile(java.io.File keyFile, java.io.File certFile)Deprecated.UseupdateIdentityCredentials(File, File)instead.AdvancedTlsX509KeyManager.CloseableupdateIdentityCredentialsFromFile(java.io.File keyFile, java.io.File certFile, long period, java.util.concurrent.TimeUnit unit, java.util.concurrent.ScheduledExecutorService executor)Deprecated.
-
-
-
Field Detail
-
log
private static final java.util.logging.Logger log
-
MINIMUM_REFRESH_PERIOD_IN_MINUTES
private static final int MINIMUM_REFRESH_PERIOD_IN_MINUTES
- See Also:
- Constant Field Values
-
keyInfo
private volatile AdvancedTlsX509KeyManager.KeyInfo keyInfo
-
-
Method Detail
-
getPrivateKey
public java.security.PrivateKey getPrivateKey(java.lang.String alias)
-
getCertificateChain
public java.security.cert.X509Certificate[] getCertificateChain(java.lang.String alias)
-
getClientAliases
public java.lang.String[] getClientAliases(java.lang.String keyType, java.security.Principal[] issuers)
-
chooseClientAlias
public java.lang.String chooseClientAlias(java.lang.String[] keyType, java.security.Principal[] issuers, java.net.Socket socket)
-
chooseEngineClientAlias
public java.lang.String chooseEngineClientAlias(java.lang.String[] keyType, java.security.Principal[] issuers, javax.net.ssl.SSLEngine engine)- Overrides:
chooseEngineClientAliasin classjavax.net.ssl.X509ExtendedKeyManager
-
getServerAliases
public java.lang.String[] getServerAliases(java.lang.String keyType, java.security.Principal[] issuers)
-
chooseServerAlias
public java.lang.String chooseServerAlias(java.lang.String keyType, java.security.Principal[] issuers, java.net.Socket socket)
-
chooseEngineServerAlias
public java.lang.String chooseEngineServerAlias(java.lang.String keyType, java.security.Principal[] issuers, javax.net.ssl.SSLEngine engine)- Overrides:
chooseEngineServerAliasin classjavax.net.ssl.X509ExtendedKeyManager
-
updateIdentityCredentials
@Deprecated @InlineMe(replacement="this.updateIdentityCredentials(certs, key)") @ExperimentalApi("https://github.com/grpc/grpc-java/issues/8024") public void updateIdentityCredentials(java.security.PrivateKey key, java.security.cert.X509Certificate[] certs)
Deprecated.Updates the current cached private key and cert chains.- Parameters:
key- the private key that is going to be usedcerts- the certificate chain that is going to be used
-
updateIdentityCredentials
public void updateIdentityCredentials(java.security.cert.X509Certificate[] certs, java.security.PrivateKey key)Updates the current cached private key and cert chains.- Parameters:
certs- the certificate chain that is going to be usedkey- the private key that is going to be used
-
updateIdentityCredentials
public AdvancedTlsX509KeyManager.Closeable updateIdentityCredentials(java.io.File certFile, java.io.File keyFile, long period, java.util.concurrent.TimeUnit unit, java.util.concurrent.ScheduledExecutorService executor) throws java.io.IOException, java.security.GeneralSecurityException
Schedules aScheduledExecutorServiceto read certificate chains and private key from the local file paths periodically, and update the cached identity credentials if they are both updated. You must close the returned Closeable before calling this method again or other update methods (updateIdentityCredentials(java.security.PrivateKey, java.security.cert.X509Certificate[]),updateIdentityCredentials(File, File)). Before scheduling the task, the method synchronously executesreadAndUpdateonce. The minimum refresh period of 1 minute is enforced.- Parameters:
certFile- the file on disk holding the certificate chainkeyFile- the file on disk holding the private keyperiod- the period between successive read-and-update executionsunit- the time unit of the initialDelay and period parametersexecutor- the executor service we use to read and update the credentials- Returns:
- an object that caller should close when the file refreshes are not needed
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
updateIdentityCredentials
public void updateIdentityCredentials(java.io.File certFile, java.io.File keyFile) throws java.io.IOException, java.security.GeneralSecurityExceptionUpdates certificate chains and the private key from the local file paths.- Parameters:
certFile- the file on disk holding the certificate chainkeyFile- the file on disk holding the private key- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
updateIdentityCredentialsFromFile
@Deprecated @InlineMe(replacement="this.updateIdentityCredentials(certFile, keyFile)") @ExperimentalApi("https://github.com/grpc/grpc-java/issues/8024") public void updateIdentityCredentialsFromFile(java.io.File keyFile, java.io.File certFile) throws java.io.IOException, java.security.GeneralSecurityException
Deprecated.UseupdateIdentityCredentials(File, File)instead.Updates the private key and certificate chains from the local file paths.- Parameters:
keyFile- the file on disk holding the private keycertFile- the file on disk holding the certificate chain- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
updateIdentityCredentialsFromFile
@Deprecated @InlineMe(replacement="this.updateIdentityCredentials(certFile, keyFile, period, unit, executor)") @ExperimentalApi("https://github.com/grpc/grpc-java/issues/8024") public AdvancedTlsX509KeyManager.Closeable updateIdentityCredentialsFromFile(java.io.File keyFile, java.io.File certFile, long period, java.util.concurrent.TimeUnit unit, java.util.concurrent.ScheduledExecutorService executor) throws java.io.IOException, java.security.GeneralSecurityException
Deprecated.Schedules aScheduledExecutorServiceto read private key and certificate chains from the local file paths periodically, and update the cached identity credentials if they are both updated. You must close the returned Closeable before calling this method again or other update methods (updateIdentityCredentials(java.security.PrivateKey, java.security.cert.X509Certificate[]),updateIdentityCredentials(File, File)). Before scheduling the task, the method synchronously executesreadAndUpdateonce. The minimum refresh period of 1 minute is enforced.- Parameters:
keyFile- the file on disk holding the private keycertFile- the file on disk holding the certificate chainperiod- the period between successive read-and-update executionsunit- the time unit of the initialDelay and period parametersexecutor- the executor service we use to read and update the credentials- Returns:
- an object that caller should close when the file refreshes are not needed
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
readAndUpdate
private AdvancedTlsX509KeyManager.UpdateResult readAndUpdate(java.io.File certFile, java.io.File keyFile, long oldKeyTime, long oldCertTime) throws java.io.IOException, java.security.GeneralSecurityException
Reads the private key and certificates specified in the path locations. Updateskeyandcertif both of their modified time changed since last read.- Parameters:
certFile- the file on disk holding the certificate chainkeyFile- the file on disk holding the private keyoldKeyTime- the time when the private key file is modified during last executionoldCertTime- the time when the certificate chain file is modified during last execution- Returns:
- the result of this update execution
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
-