Class CachingSha2PasswordPlugin
- java.lang.Object
-
- org.mariadb.jdbc.plugin.authentication.standard.CachingSha2PasswordPlugin
-
- All Implemented Interfaces:
AuthenticationPlugin
public class CachingSha2PasswordPlugin extends java.lang.Object implements AuthenticationPlugin
Mysql caching sha2 password plugin
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
authenticationData
private Configuration
conf
private HostAddress
hostAddress
private byte[]
seed
static java.lang.String
TYPE
plugin name
-
Constructor Summary
Constructors Constructor Description CachingSha2PasswordPlugin()
-
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)
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, Configuration conf, HostAddress hostAddress)
Initialized data.ReadableByteBuf
process(Writer out, Reader in, Context context)
Process native password plugin authentication.static java.security.PublicKey
readPublicKeyFromFile(java.lang.String serverRsaPublicKeyFile)
Read public Key from file.static byte[]
sha256encryptPassword(java.lang.CharSequence password, byte[] seed)
Send an SHA-2 encrypted password.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
-
Methods inherited from interface org.mariadb.jdbc.plugin.AuthenticationPlugin
hash, isMitMProof, requireSsl
-
-
-
-
Field Detail
-
TYPE
public static final java.lang.String TYPE
plugin name- See Also:
- Constant Field Values
-
authenticationData
private java.lang.String authenticationData
-
seed
private byte[] seed
-
conf
private Configuration conf
-
hostAddress
private HostAddress hostAddress
-
-
Method Detail
-
sha256encryptPassword
public static byte[] sha256encryptPassword(java.lang.CharSequence password, byte[] seed)
Send an SHA-2 encrypted password. encryption XOR(SHA256(password), SHA256(seed, SHA256(SHA256(password))))- Parameters:
password
- passwordseed
- seed- Returns:
- encrypted pwd
-
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 having an error reading file or file content is not a public key.
-
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) throws java.sql.SQLException
Encode password with seed and public key.- Parameters:
publicKey
- public keypassword
- passwordseed
- seed- Returns:
- encoded password
- Throws:
java.sql.SQLException
- if cannot encode password
-
type
public java.lang.String type()
Description copied from interface:AuthenticationPlugin
Authentication plugin type.- Specified by:
type
in interfaceAuthenticationPlugin
- Returns:
- authentication plugin type. ex: mysql_native_password
-
initialize
public void initialize(java.lang.String authenticationData, byte[] seed, Configuration conf, HostAddress hostAddress)
Initialized data.- Specified by:
initialize
in interfaceAuthenticationPlugin
- Parameters:
authenticationData
- authentication data (password/token)seed
- server provided seedconf
- Connection string optionshostAddress
- host information
-
process
public ReadableByteBuf process(Writer out, Reader in, Context context) throws java.io.IOException, java.sql.SQLException
Process native password plugin authentication. see https://mariadb.com/kb/en/library/authentication-plugin-mysql_native_password/- Specified by:
process
in interfaceAuthenticationPlugin
- Parameters:
out
- out streamin
- in streamcontext
- connection context- Returns:
- response packet
- Throws:
java.io.IOException
- if socket errorjava.sql.SQLException
- if plugin exception
-
-