|
5 | 5 |
|
6 | 6 | namespace MySqlConnector.Authentication.Ed25519
|
7 | 7 | {
|
8 |
| - public static class Ed25519 |
| 8 | + /// <summary> |
| 9 | + /// Provides an implementation of the <c>client_ed25519</c> authentication plugin for MariaDB. |
| 10 | + /// </summary> |
| 11 | + /// <remarks>See <a href="https://mariadb.com/kb/en/library/authentication-plugin-ed25519/">Authentication Plugin - ed25519</a>.</remarks> |
| 12 | + public sealed class Ed25519AuthenticationPlugin : IAuthenticationPlugin |
9 | 13 | {
|
10 |
| - public static byte[] Ed25519SignWithPassword(string password, byte[] seed) |
| 14 | + /// <summary> |
| 15 | + /// Registers the Ed25519 authentication plugin with MySqlConnector. You must call this method once before |
| 16 | + /// opening a connection that uses Ed25519 authentication. |
| 17 | + /// </summary> |
| 18 | + public static void Install() |
| 19 | + { |
| 20 | + if (!s_isInstalled) |
| 21 | + { |
| 22 | + AuthenticationPlugins.Register(new Ed25519AuthenticationPlugin()); |
| 23 | + s_isInstalled = true; |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + public string Name => "client_ed25519"; |
| 28 | + |
| 29 | + public byte[] CreateResponse(string password, ReadOnlySpan<byte> authenticationData) |
11 | 30 | {
|
12 | 31 | // Java reference: https://github.com/MariaDB/mariadb-connector-j/blob/master/src/main/java/org/mariadb/jdbc/internal/com/send/authentication/Ed25519PasswordPlugin.java
|
13 | 32 | // C reference: https://github.com/MariaDB/server/blob/592fe954ef82be1bc08b29a8e54f7729eb1e1343/plugin/auth_ed25519/ref10/sign.c#L7
|
@@ -64,10 +83,10 @@ public static byte[] Ed25519SignWithPassword(string password, byte[] seed)
|
64 | 83 | crypto_hash_sha512(nonce,sm + 32,mlen + 32);
|
65 | 84 | */
|
66 | 85 |
|
67 |
| - byte[] sm = new byte[64 + seed.Length]; |
68 |
| - Buffer.BlockCopy(seed, 0, sm, 64, seed.Length); |
| 86 | + byte[] sm = new byte[64 + authenticationData.Length]; |
| 87 | + authenticationData.CopyTo(sm.AsSpan().Slice(64)); |
69 | 88 | Buffer.BlockCopy(az, 32, sm, 32, 32);
|
70 |
| - byte[] nonce = sha512.ComputeHash(sm, 32, seed.Length + 32); |
| 89 | + byte[] nonce = sha512.ComputeHash(sm, 32, authenticationData.Length + 32); |
71 | 90 |
|
72 | 91 | /*** Java
|
73 | 92 | ScalarOps scalar = new ScalarOps();
|
@@ -133,5 +152,11 @@ public static byte[] Ed25519SignWithPassword(string password, byte[] seed)
|
133 | 152 | return result;
|
134 | 153 | }
|
135 | 154 | }
|
| 155 | + |
| 156 | + private Ed25519AuthenticationPlugin() |
| 157 | + { |
| 158 | + } |
| 159 | + |
| 160 | + static bool s_isInstalled; |
136 | 161 | }
|
137 | 162 | }
|
0 commit comments