MySQL  8.0.17
Source Code Documentation
plugin_keyring.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef MYSQL_PLUGIN_KEYRING_INCLUDED
24 #define MYSQL_PLUGIN_KEYRING_INCLUDED
25 
26 /**
27  API for keyring plugin. (MYSQL_KEYRING_PLUGIN)
28 */
29 
30 #include "plugin.h"
31 #define MYSQL_KEYRING_INTERFACE_VERSION 0x0101
32 
33 /**
34  The descriptor structure for the plugin, that is referred from
35  st_mysql_plugin.
36 */
37 
40  /*!
41  Add key to the keyring.
42 
43  Obfuscates and adds the key to the keyring. The key is associated with
44  key_id and user_id (unique key identifier).
45 
46  @param[in] key_id id of the key to store
47  @param[in] key_type type of the key to store
48  @param[in] user_id id of the owner of the key
49  @param[in] key the key itself to be stored. The memory of the key is
50  copied by the keyring, thus the key itself can be freed
51  after it was stored in the keyring.
52  @param[in] key_len the length of the key to be stored
53 
54  @return Operation status
55  @retval 0 OK
56  @retval 1 ERROR
57  */
58  bool (*mysql_key_store)(const char *key_id, const char *key_type,
59  const char *user_id, const void *key, size_t key_len);
60  /*!
61  Fetches key from the keyring.
62 
63  De-obfuscates and retrieves key associated with key_id and user_id from the
64  keyring.
65 
66  @param[in] key_id id of the key to fetch
67  @param[out] key_type type of the fetched key
68  @param[in] user_id id of the owner of the key
69  @param[out] key the fetched key itself. The memory for this key is
70  allocated by the keyring and needs to be freed by the
71  user when no longer needed. Prior to freeing the memory
72  it needs to be obfuscated or zeroed.
73  @param[out] key_len the length of the fetched key
74 
75  @return Operation status
76  @retval 0 OK
77  @retval 1 ERROR
78  */
79  bool (*mysql_key_fetch)(const char *key_id, char **key_type,
80  const char *user_id, void **key, size_t *key_len);
81 
82  /*!
83  Removes key from the keyring.
84 
85  Removes the key associated with key_id and user_id from the
86  keyring.
87 
88  @param[in] key_id id of the key to remove
89  @param[in] user_id id of the owner of the key to remove
90 
91  @return Operation status
92  @retval 0 OK
93  @retval 1 ERROR
94  */
95  bool (*mysql_key_remove)(const char *key_id, const char *user_id);
96 
97  /*!
98  Generates and stores the key.
99 
100  Generates a random key of length key_len, associates it with key_id, user_id
101  and stores it in the keyring.
102 
103  @param[in] key_id id of the key to generate
104  @param[in] key_type type of the key to generate
105  @param[in] user_id id of the owner of the generated key
106  @param[in] key_len length of the key to generate
107 
108  @return Operation status
109  @retval 0 OK
110  @retval 1 ERROR
111  */
112  bool (*mysql_key_generate)(const char *key_id, const char *key_type,
113  const char *user_id, size_t key_len);
114 
115  /**
116  Keys_iterator object refers to an iterator which is used to iterate
117  on a list which refers to Key_metadata. Key_metadata hold information
118  about individual keys keyd_id and user_id. Keys_iterator should be used
119  in following sequence only.
120 
121  void* iterator_ptr;
122  char key_id[64]= { 0 };
123  char user_id[64]= { 0 };
124 
125  plugin_handle->mysql_key_iterator_init(&iterator_ptr);
126 
127  if (iterator_ptr == NULL)
128  report error;
129 
130  while (!(plugin_handle->mysql_key_iterator_get_key(iterator_ptr,
131  key_id, user_id)))
132  {
133  Fetch the keys.
134  Perform operations on the fetched keys.
135  ..
136  }
137  plugin_handle->mysql_key_iterator_deinit(iterator_ptr);
138 
139  init() method accepts a void pointer which is the made to point to
140  Keys_iterator instance. Keys_iterator instance internal pointer points
141  to Key_metadata list. This list holds information about all keys stored
142  in the backed end data store of keyring plugin. After call to init()
143  please check iterator_ptr.
144 
145  get_key() method accepts the above iterator_ptr as IN param and then
146  fills the passes in key_id and user_id with valid values. This can be
147  used to fetch actual key information. Every call to this method will
148  change internal pointers to advance to next position, so that the next
149  call will fetch the next key.
150 
151  deinit() method frees all internal pointers along with iterator_ptr.
152  */
153  /**
154  Initialize an iterator.
155 
156  @param[out] key_iterator Iterator used to fetch individual keys
157  from key_container.
158 
159  @return VOID
160  */
161  void (*mysql_key_iterator_init)(void **key_iterator);
162 
163  /**
164  Deinitialize an iterator.
165 
166  @param[in] key_iterator Iterator used to fetch individual keys
167  from key_container.
168 
169  @return VOID
170  */
171  void (*mysql_key_iterator_deinit)(void *key_iterator);
172 
173  /**
174  Get details of key. Every call to this service will change
175  internal pointers to advance to next position, so that the next call
176  will fetch the next key. In case iterator moves to the end, this service
177  will return error.
178 
179  @param[in] key_iterator Iterator used to fetch individual keys
180  from key_container.
181  @param[out] key_id id of the key
182  @param[out] user_id id of the owner
183 
184  @return Operation status
185  @retval 0 OK
186  @retval 1 ERROR
187  */
188  bool (*mysql_key_iterator_get_key)(void *key_iterator, char *key_id,
189  char *user_id);
190 };
191 #endif
void(* mysql_key_iterator_deinit)(void *key_iterator)
Deinitialize an iterator.
Definition: plugin_keyring.h:171
#define bool
Definition: config_static.h:42
static int key_type
Definition: mi_test1.cc:38
bool(* mysql_key_store)(const char *key_id, const char *key_type, const char *user_id, const void *key, size_t key_len)
Add key to the keyring.
Definition: plugin_keyring.h:58
int interface_version
Definition: plugin_keyring.h:39
bool(* mysql_key_remove)(const char *key_id, const char *user_id)
Removes key from the keyring.
Definition: plugin_keyring.h:95
static const char * key
Definition: suite_stubs.c:14
The descriptor structure for the plugin, that is referred from st_mysql_plugin.
Definition: plugin_keyring.h:38
bool(* mysql_key_fetch)(const char *key_id, char **key_type, const char *user_id, void **key, size_t *key_len)
Fetches key from the keyring.
Definition: plugin_keyring.h:79
bool(* mysql_key_generate)(const char *key_id, const char *key_type, const char *user_id, size_t key_len)
Generates and stores the key.
Definition: plugin_keyring.h:112
void(* mysql_key_iterator_init)(void **key_iterator)
Keys_iterator object refers to an iterator which is used to iterate on a list which refers to Key_met...
Definition: plugin_keyring.h:161
bool(* mysql_key_iterator_get_key)(void *key_iterator, char *key_id, char *user_id)
Get details of key.
Definition: plugin_keyring.h:188