1/*
2 Copyright (c) 2015 MariaDB Corporation
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 St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17/**
18 Debug key management plugin.
19 It's used to debug the encryption code with a fixed keys that change
20 only on user request.
21
22 It does not support different key ids, the only valid key id is 1.
23
24 THIS IS AN EXAMPLE ONLY! ENCRYPTION KEYS ARE HARD-CODED AND *NOT* SECRET!
25 DO NOT USE THIS PLUGIN IN PRODUCTION! EVER!
26*/
27
28#include <my_global.h>
29#include <mysql/plugin_encryption.h>
30#include <string.h>
31#include <myisampack.h>
32
33#define KEY_SIZE 16
34
35static uint key_version;
36
37static MYSQL_SYSVAR_UINT(version, key_version, PLUGIN_VAR_RQCMDARG,
38 "Latest key version", NULL, NULL, 1, 0, UINT_MAX, 1);
39
40static struct st_mysql_sys_var* sysvars[] = {
41 MYSQL_SYSVAR(version),
42 NULL
43};
44
45static unsigned int get_latest_key_version(unsigned int keyid)
46{
47 if (keyid != 1)
48 return ENCRYPTION_KEY_VERSION_INVALID;
49
50 return key_version;
51}
52
53static unsigned int get_key(unsigned int keyid, unsigned int version,
54 unsigned char* dstbuf, unsigned *buflen)
55{
56 if (keyid != 1)
57 return ENCRYPTION_KEY_VERSION_INVALID;
58
59 if (*buflen < KEY_SIZE)
60 {
61 *buflen= KEY_SIZE;
62 return ENCRYPTION_KEY_BUFFER_TOO_SMALL;
63 }
64 *buflen= KEY_SIZE;
65 if (!dstbuf)
66 return 0;
67
68 memset(dstbuf, 0, KEY_SIZE);
69 mi_int4store(dstbuf, version);
70 return 0;
71}
72
73struct st_mariadb_encryption debug_key_management_plugin= {
74 MariaDB_ENCRYPTION_INTERFACE_VERSION,
75 get_latest_key_version,
76 get_key,
77 // use default encrypt/decrypt functions
78 0, 0, 0, 0, 0
79};
80
81/*
82 Plugin library descriptor
83*/
84maria_declare_plugin(debug_key_management)
85{
86 MariaDB_ENCRYPTION_PLUGIN,
87 &debug_key_management_plugin,
88 "debug_key_management",
89 "Sergei Golubchik",
90 "Debug key management plugin",
91 PLUGIN_LICENSE_GPL,
92 NULL,
93 NULL,
94 0x0100,
95 NULL,
96 sysvars,
97 "1.0",
98 MariaDB_PLUGIN_MATURITY_EXPERIMENTAL
99}
100maria_declare_plugin_end;
101