Skip to content

Commit cf8bf0b

Browse files
committed
encryption key management plugin api
1 parent c8997c3 commit cf8bf0b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+696
-344
lines changed

cmake/abi_check.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ IF(CMAKE_COMPILER_IS_GNUCC AND RUN_ABI_CHECK)
4444
${CMAKE_SOURCE_DIR}/include/mysql/client_plugin.h
4545
${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth.h
4646
${CMAKE_SOURCE_DIR}/include/mysql/plugin_password_validation.h
47+
${CMAKE_SOURCE_DIR}/include/mysql/plugin_encryption_key_management.h
4748
)
4849

4950
ADD_CUSTOM_TARGET(abi_check ALL

include/my_crypt_key_management.h

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
#ifndef MYSYS_MY_CRYPT_KEY_MANAGMENT_H_
3-
#define MYSYS_MY_CRYPT_KEY_MANAGMENT_H_
2+
#ifndef INCLUDE_MY_CRYPT_KEY_MANAGMENT_INCLUDED
3+
#define INCLUDE_MY_CRYPT_KEY_MANAGMENT_INCLUDED
44

55
#include "my_global.h"
66
#include "my_pthread.h"
@@ -18,63 +18,17 @@ extern uint opt_debug_encryption_key_version;
1818
#endif /* DBUG_OFF */
1919

2020
C_MODE_START
21-
/**
22-
* function returning latest key version
23-
*/
24-
typedef int (* GetLatestCryptoKeyVersionFunc_t)();
25-
26-
/**
27-
* function returning if the key exists
28-
*/
29-
typedef unsigned int (* HasKeyVersionFunc_t)(unsigned int version);
30-
31-
/**
32-
* function returning the key size
33-
*/
34-
typedef int (* GetKeySizeFunc_t)(unsigned int version);
35-
36-
/**
37-
* function returning a key for a key version
38-
*/
39-
typedef int (* GetCryptoKeyFunc_t)(unsigned int version,
40-
unsigned char* key,
41-
unsigned keybufsize);
42-
43-
/**
44-
* function returning an iv for a key version
45-
*/
46-
typedef int (* GetCryptoIVFunc_t)(unsigned int version,
47-
unsigned char* iv,
48-
unsigned ivbufsize);
49-
50-
51-
struct CryptoKeyFuncs_t
52-
{
53-
GetLatestCryptoKeyVersionFunc_t getLatestCryptoKeyVersionFunc;
54-
HasKeyVersionFunc_t hasCryptoKeyFunc;
55-
GetKeySizeFunc_t getCryptoKeySize;
56-
GetCryptoKeyFunc_t getCryptoKeyFunc;
57-
GetCryptoIVFunc_t getCryptoIVFunc;
58-
};
59-
60-
/**
61-
* Install functions to use for key management
62-
*/
63-
void
64-
InstallCryptoKeyFunctions(const struct CryptoKeyFuncs_t* cryptoKeyFuncs);
6521

6622
/**
6723
* Functions to interact with key management
6824
*/
6925

70-
int GetLatestCryptoKeyVersion();
71-
unsigned int HasCryptoKey(unsigned int version);
72-
int GetCryptoKeySize(unsigned int version);
73-
int GetCryptoKey(unsigned int version, unsigned char* key_buffer,
74-
unsigned int size);
75-
int GetCryptoIV(unsigned int version, unsigned char* key_buffer,
76-
unsigned int size);
26+
uint get_latest_encryption_key_version();
27+
uint has_encryption_key(uint version);
28+
uint get_encryption_key_size(uint version);
29+
int get_encryption_key(uint version, uchar* key, uint size);
30+
int get_encryption_iv(uint version, uchar* iv, uint size);
7731

7832
C_MODE_END
7933

80-
#endif // MYSYS_MY_CRYPT_KEY_MANAGMENT_H_
34+
#endif // INCLUDE_MY_CRYPT_KEY_MANAGMENT_INCLUDED

include/mysql/plugin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ typedef struct st_mysql_xid MYSQL_XID;
8888
#define MYSQL_AUDIT_PLUGIN 5
8989
#define MYSQL_REPLICATION_PLUGIN 6
9090
#define MYSQL_AUTHENTICATION_PLUGIN 7
91-
#define MYSQL_KEY_MANAGEMENT_PLUGIN 9
9291
#define MYSQL_MAX_PLUGIN_TYPE_NUM 10 /* The number of plugin types */
9392

9493
/* MariaDB plugin types */
95-
#define MariaDB_PASSWORD_VALIDATION_PLUGIN 8
94+
#define MariaDB_PASSWORD_VALIDATION_PLUGIN 8
95+
#define MariaDB_ENCRYPTION_KEY_MANAGEMENT_PLUGIN 9
9696

9797
/* We use the following strings to define licenses for plugins */
9898
#define PLUGIN_LICENSE_PROPRIETARY 0
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#ifndef MYSQL_PLUGIN_ENCRYPTION_KEY_MANAGEMENT_INCLUDED
2+
/* Copyright (C) 2014 Sergei Golubchik and 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
16+
17+
/**
18+
@file
19+
20+
Encryption key Management Plugin API.
21+
22+
This file defines the API for server plugins that manage encryption
23+
keys for MariaDB on-disk data encryption.
24+
*/
25+
26+
#define MYSQL_PLUGIN_ENCRYPTION_KEY_MANAGEMENT_INCLUDED
27+
28+
#include <mysql/plugin.h>
29+
30+
#define MariaDB_ENCRYPTION_KEY_MANAGEMENT_INTERFACE_VERSION 0x0100
31+
32+
#define BAD_ENCRYPTION_KEY_VERSION (~0U)
33+
34+
/**
35+
Encryption key management plugin descriptor
36+
*/
37+
struct st_mariadb_encryption_key_management
38+
{
39+
int interface_version; /**< version plugin uses */
40+
41+
/**
42+
function returning latest key version.
43+
44+
@return a version or BAD_ENCRYPTION_KEY_VERSION to indicate an error.
45+
*/
46+
unsigned int (*get_latest_key_version)();
47+
48+
/** function returning if a key of the given version exists */
49+
unsigned int (*has_key_version)(unsigned int version);
50+
51+
/** function returning the key size in bytes */
52+
unsigned int (*get_key_size)(unsigned int version);
53+
54+
/**
55+
function returning a key for a key version
56+
57+
the key is put in 'key' buffer, that has size of 'keybufsize' bytes.
58+
59+
@return 0 on success, non-zero on failure
60+
*/
61+
int (*get_key)(unsigned int version, unsigned char* key, unsigned int keybufsize);
62+
63+
/**
64+
function returning an IV for a key version
65+
66+
the IV is put in 'iv' buffer, that has size of 'ivbufsize' bytes.
67+
68+
@return 0 on success, non-zero on failure
69+
*/
70+
int (*get_iv)(unsigned int version, unsigned char* iv, unsigned int ivbufsize);
71+
};
72+
#endif
73+

0 commit comments

Comments
 (0)