-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[misc] parsec fingerprint hash using either java 15 or BouncyCastle
- Loading branch information
Showing
9 changed files
with
120 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ParsecPasswordPluginTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
// Copyright (c) 2012-2014 Monty Program Ab | ||
// Copyright (c) 2015-2024 MariaDB Corporation Ab | ||
package org.mariadb.jdbc.plugin.authentication.standard; | ||
|
||
import java.io.IOException; | ||
import java.security.*; | ||
import java.sql.SQLException; | ||
import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters; | ||
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters; | ||
|
||
/** Parsec password plugin utility */ | ||
public class ParsecPasswordPluginTool { | ||
|
||
public static byte[] process(byte[] rawPrivateKey) | ||
throws SQLException, | ||
IOException, | ||
InvalidAlgorithmParameterException, | ||
NoSuchAlgorithmException { | ||
Ed25519PrivateKeyParameters privateKeyRebuild = | ||
new Ed25519PrivateKeyParameters(rawPrivateKey, 0); | ||
Ed25519PublicKeyParameters publicKeyRebuild = privateKeyRebuild.generatePublicKey(); | ||
return publicKeyRebuild.getEncoded(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...main/java15/org/mariadb/jdbc/plugin/authentication/standard/ParsecPasswordPluginTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
// Copyright (c) 2012-2014 Monty Program Ab | ||
// Copyright (c) 2015-2024 MariaDB Corporation Ab | ||
package org.mariadb.jdbc.plugin.authentication.standard; | ||
|
||
import java.io.IOException; | ||
import java.security.*; | ||
import java.security.spec.NamedParameterSpec; | ||
import java.sql.SQLException; | ||
import java.util.Arrays; | ||
|
||
/** Parsec password plugin utility*/ | ||
public class ParsecPasswordPluginTool { | ||
|
||
public static byte[] process(byte[] rawPrivateKey) | ||
throws SQLException, IOException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { | ||
|
||
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("Ed25519"); | ||
keyPairGenerator.initialize(NamedParameterSpec.ED25519, new StaticSecureRandom(rawPrivateKey)); | ||
|
||
// public key in SPKI format; the last 32 bytes are the raw public key | ||
byte[] spki = | ||
keyPairGenerator | ||
.generateKeyPair() | ||
.getPublic() | ||
.getEncoded(); | ||
byte[] rawPublicKey = | ||
Arrays.copyOfRange(spki, spki.length - 32, spki.length); | ||
return rawPublicKey; | ||
} | ||
|
||
private static class StaticSecureRandom extends SecureRandom { | ||
private byte[] privateKey; | ||
|
||
public StaticSecureRandom(byte[] privateKey) { | ||
this.privateKey = privateKey; | ||
} | ||
|
||
public void nextBytes(byte[] bytes) { | ||
System.arraycopy(privateKey, 0, bytes, 0, privateKey.length); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters