Class Sha256PasswordPlugin

java.lang.Object
org.mariadb.jdbc.internal.com.send.authentication.Sha256PasswordPlugin
All Implemented Interfaces:
AuthenticationPlugin

public class Sha256PasswordPlugin extends Object implements AuthenticationPlugin
  • Field Details

    • authenticationData

      private String authenticationData
    • options

      private Options options
    • seed

      private byte[] seed
  • Constructor Details

    • Sha256PasswordPlugin

      public Sha256PasswordPlugin()
  • Method Details

    • readPublicKeyFromFile

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

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

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

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

      public 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 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(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, AtomicInteger sequence) throws IOException, 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:
      IOException - if socket error
      SQLException - if plugin exception