Class LazyKeyManager

  • All Implemented Interfaces:
    javax.net.ssl.KeyManager, javax.net.ssl.X509KeyManager

    public class LazyKeyManager
    extends java.lang.Object
    implements javax.net.ssl.X509KeyManager
    A Key manager that only loads the keys, if necessary.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private javax.security.auth.callback.CallbackHandler cbh  
      private java.security.cert.X509Certificate[] cert  
      private java.lang.String certfile  
      private boolean defaultfile  
      private PSQLException error  
      private java.security.PrivateKey key  
      private java.lang.String keyfile  
    • Constructor Summary

      Constructors 
      Constructor Description
      LazyKeyManager​(java.lang.String certfile, java.lang.String keyfile, javax.security.auth.callback.CallbackHandler cbh, boolean defaultfile)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String chooseClientAlias​(java.lang.String[] keyType, java.security.Principal[] issuers, java.net.Socket socket)  
      java.lang.String chooseServerAlias​(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.PrivateKey getPrivateKey​(java.lang.String alias)  
      java.lang.String[] getServerAliases​(java.lang.String keyType, java.security.Principal[] issuers)  
      private static byte[] readFileFully​(java.lang.String path)  
      void throwKeyManagerException()
      getCertificateChain and getPrivateKey cannot throw exeptions, therefore any exception is stored in error and can be raised by this method.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • cert

        private java.security.cert.X509Certificate[] cert
      • key

        private java.security.PrivateKey key
      • certfile

        private java.lang.String certfile
      • keyfile

        private java.lang.String keyfile
      • cbh

        private javax.security.auth.callback.CallbackHandler cbh
      • defaultfile

        private boolean defaultfile
    • Constructor Detail

      • LazyKeyManager

        public LazyKeyManager​(java.lang.String certfile,
                              java.lang.String keyfile,
                              javax.security.auth.callback.CallbackHandler cbh,
                              boolean defaultfile)
        Constructor. certfile and keyfile can be null, in that case no certificate is presented to the server.
        Parameters:
        certfile - certfile
        keyfile - key file
        cbh - callback handler
        defaultfile - default file
    • Method Detail

      • throwKeyManagerException

        public void throwKeyManagerException()
                                      throws PSQLException
        getCertificateChain and getPrivateKey cannot throw exeptions, therefore any exception is stored in error and can be raised by this method.
        Throws:
        PSQLException - if any exception is stored in error and can be raised
      • chooseClientAlias

        public java.lang.String chooseClientAlias​(java.lang.String[] keyType,
                                                  java.security.Principal[] issuers,
                                                  java.net.Socket socket)
        Specified by:
        chooseClientAlias in interface javax.net.ssl.X509KeyManager
      • chooseServerAlias

        public java.lang.String chooseServerAlias​(java.lang.String keyType,
                                                  java.security.Principal[] issuers,
                                                  java.net.Socket socket)
        Specified by:
        chooseServerAlias in interface javax.net.ssl.X509KeyManager
      • getCertificateChain

        public java.security.cert.X509Certificate[] getCertificateChain​(java.lang.String alias)
        Specified by:
        getCertificateChain in interface javax.net.ssl.X509KeyManager
      • getClientAliases

        public java.lang.String[] getClientAliases​(java.lang.String keyType,
                                                   java.security.Principal[] issuers)
        Specified by:
        getClientAliases in interface javax.net.ssl.X509KeyManager
      • readFileFully

        private static byte[] readFileFully​(java.lang.String path)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • getPrivateKey

        public java.security.PrivateKey getPrivateKey​(java.lang.String alias)
        Specified by:
        getPrivateKey in interface javax.net.ssl.X509KeyManager
      • getServerAliases

        public java.lang.String[] getServerAliases​(java.lang.String keyType,
                                                   java.security.Principal[] issuers)
        Specified by:
        getServerAliases in interface javax.net.ssl.X509KeyManager