1 | /* |
2 | Copyright (c) 2017, MariaDB |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; version 2 of the License. |
7 | |
8 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License |
14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ |
16 | |
17 | /************************** CLIENT *************************************/ |
18 | |
19 | #include <stdlib.h> |
20 | #include "common.h" |
21 | #include <mysql/client_plugin.h> |
22 | #include <errmsg.h> |
23 | |
24 | #if !defined(__attribute__) && !defined(__GNUC__) |
25 | #define __attribute__(A) |
26 | #endif |
27 | |
28 | static int do_auth(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) |
29 | { |
30 | unsigned char reply[CRYPTO_BYTES + NONCE_BYTES], *pkt; |
31 | int pkt_len; |
32 | |
33 | /* read the nonce */ |
34 | if ((pkt_len= vio->read_packet(vio, &pkt)) != NONCE_BYTES) |
35 | return CR_SERVER_HANDSHAKE_ERR; |
36 | |
37 | /* sign the nonce */ |
38 | crypto_sign(reply, pkt, NONCE_BYTES, |
39 | (unsigned char*)mysql->passwd, strlen(mysql->passwd)); |
40 | |
41 | /* send the signature */ |
42 | if (vio->write_packet(vio, reply, CRYPTO_BYTES)) |
43 | return CR_ERROR; |
44 | |
45 | return CR_OK; |
46 | } |
47 | |
48 | static int init_client(char *unused1 __attribute__((unused)), |
49 | size_t unused2 __attribute__((unused)), |
50 | int unused3 __attribute__((unused)), |
51 | va_list unused4 __attribute__((unused))) |
52 | { |
53 | return 0; |
54 | } |
55 | |
56 | mysql_declare_client_plugin(AUTHENTICATION) |
57 | "client_ed25519" , |
58 | "Sergei Golubchik" , |
59 | "Elliptic curve ED25519 based authentication" , |
60 | {0,1,0}, |
61 | "GPL" , |
62 | NULL, |
63 | init_client, |
64 | NULL, |
65 | NULL, |
66 | do_auth, |
67 | mysql_end_client_plugin; |
68 | |
69 | |