Class Sha256PasswordPlugin

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] encrypt​(java.security.PublicKey publicKey, java.lang.String password, byte[] seed, java.lang.String passwordCharacterEncoding)
      Encode password with seed and public key.
      static java.security.PublicKey generatePublicKey​(byte[] publicKeyBytes)
      Read public pem key from String.
      void initialize​(java.lang.String authenticationData, byte[] seed, Options options)
      Initialization.
      java.lang.String name()
      Authentication plugin name.
      Buffer process​(PacketOutputStream out, PacketInputStream in, java.util.concurrent.atomic.AtomicInteger sequence)
      Process SHA 256 password plugin authentication.
      static java.security.PublicKey readPublicKeyFromFile​(java.lang.String serverRsaPublicKeyFile)
      Read public Key from file.
      static java.security.PublicKey readPublicKeyFromSocket​(PacketInputStream reader, java.util.concurrent.atomic.AtomicInteger sequence)
      Read public Key from socket.
      java.lang.String type()
      Authentication plugin type.
      • Methods inherited from class java.lang.Object

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

      • authenticationData

        private java.lang.String authenticationData
      • seed

        private byte[] seed
    • Constructor Detail

      • Sha256PasswordPlugin

        public Sha256PasswordPlugin()
    • Method Detail

      • readPublicKeyFromFile

        public static java.security.PublicKey readPublicKeyFromFile​(java.lang.String serverRsaPublicKeyFile)
                                                             throws java.sql.SQLException
        Read public Key from file.
        Parameters:
        serverRsaPublicKeyFile - RSA public key file
        Returns:
        public key
        Throws:
        java.sql.SQLException - if cannot read file or file content is not a public key.
      • readPublicKeyFromSocket

        public static java.security.PublicKey readPublicKeyFromSocket​(PacketInputStream reader,
                                                                      java.util.concurrent.atomic.AtomicInteger sequence)
                                                               throws java.sql.SQLException,
                                                                      java.io.IOException
        Read public Key from socket.
        Parameters:
        reader - input stream reader
        sequence - current exchange sequence
        Returns:
        public key
        Throws:
        java.sql.SQLException - if server return an Error packet or public key cannot be parsed.
        java.io.IOException - if error reading socket
      • generatePublicKey

        public static java.security.PublicKey generatePublicKey​(byte[] publicKeyBytes)
                                                         throws java.sql.SQLException
        Read public pem key from String.
        Parameters:
        publicKeyBytes - public key bytes value
        Returns:
        public key
        Throws:
        java.sql.SQLException - if key cannot be parsed
      • encrypt

        public static byte[] encrypt​(java.security.PublicKey publicKey,
                                     java.lang.String password,
                                     byte[] seed,
                                     java.lang.String passwordCharacterEncoding)
                              throws java.sql.SQLException,
                                     java.io.UnsupportedEncodingException
        Encode password with seed and public key.
        Parameters:
        publicKey - public key
        password - password
        seed - seed
        passwordCharacterEncoding - password encoding
        Returns:
        encoded password
        Throws:
        java.sql.SQLException - if cannot encode password
        java.io.UnsupportedEncodingException - if password encoding is unknown
      • name

        public java.lang.String name()
        Description copied from interface: AuthenticationPlugin
        Authentication plugin name.
        Specified by:
        name in interface AuthenticationPlugin
        Returns:
        authentication plugin name. ex: Mysql native password
      • type

        public java.lang.String type()
        Description copied from interface: AuthenticationPlugin
        Authentication plugin type.
        Specified by:
        type in interface AuthenticationPlugin
        Returns:
        authentication plugin type. ex: mysql_native_password
      • initialize

        public void initialize​(java.lang.String authenticationData,
                               byte[] seed,
                               Options options)
        Initialization.
        Specified by:
        initialize in interface AuthenticationPlugin
        Parameters:
        authenticationData - authentication data (password/token)
        seed - server provided seed
        options - Connection string options
      • process

        public Buffer process​(PacketOutputStream out,
                              PacketInputStream in,
                              java.util.concurrent.atomic.AtomicInteger sequence)
                       throws java.io.IOException,
                              java.sql.SQLException
        Process SHA 256 password plugin authentication. see https://mariadb.com/kb/en/library/authentication-plugin-ed25519/
        Specified by:
        process in interface AuthenticationPlugin
        Parameters:
        out - out stream
        in - in stream
        sequence - packet sequence
        Returns:
        response packet
        Throws:
        java.io.IOException - if socket error
        java.sql.SQLException - if plugin exception