MySQL 8.0.39
Source Code Documentation
keyring_generator.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef KEYRING_GENERATOR_INCLUDED
25#define KEYRING_GENERATOR_INCLUDED
26
28
29/**
30 @ingroup group_keyring_component_services_inventory
31
32 Key generator service provides a way to generate random data
33 and store it in keyring backend.
34
35 Data stored within keyring should be uniquely identified using:
36 1. Data ID
37 An identifier associated with data - supplied by keyring APIs' callers
38 2. Auth ID
39 An identifier associated with owner of the data - suppled by keyring
40 APIs' callers. If Auth ID is not provided, key is treated as an internal
41 key. Such a key shalll not be accessible to database users using
42 SQL interface
43
44 This service does not return generated data back to user.
45 For that, Keyring reader service should be used.
46
47 @code
48 bool generate_key(const char *data_id, const char *auth_id,
49 const char *data_type, size_t data_size) {
50 my_service<SERVICE_TYPE(keyring_generator)> keyring_generator(
51 "keyring_reader_generator", m_reg_srv);
52 if (!keyring_generator.is_valid()) {
53 return true;
54 }
55
56 if (keyring_generator->generate(data_id, auth_id, data_type, data_size) ==
57 true) {
58 return true;
59 }
60 return false;
61 }
62 @endcode
63*/
64
65BEGIN_SERVICE_DEFINITION(keyring_generator)
66
67/**
68 Generate random data of length data_size and
69 store it in keyring using identifiers as (data_id, auth_id).
70
71 Data_type value is implementation specific. It associates type
72 label with data which may be an important indicator for certain
73 backends.
74
75 Examples: AES, SECRET
76
77 Note: If components want to support aes_encryption service,
78 it must support storing data of type AES.
79
80 If error object is not initialized, the method will initialize it if returns
81 false. Caller will be responsible for freeing error state in such cases.
82 No error object will be created or modified if return value is true.
83
84 The action should be atomic from caller's point of view.
85 As much as possible, deligate data generation to keyring backend.
86
87 @note Implementation can restrict type and/or size of data that can be
88 stored in keyring.
89
90 @param [in] data_id Data Identifier. Byte string.
91 @param [in] auth_id Authorization ID. Byte string.
92 @param [in] data_type Type of data. ASCII. Null terminated.
93 @param [in] data_size Size of the data to be generated
94
95 @returns status of the operation
96 @retval false Success - Key generated and stored in keyring.
97 @retval truen Failure
98*/
99
100DECLARE_BOOL_METHOD(generate, (const char *data_id, const char *auth_id,
101 const char *data_type, size_t data_size));
102
103END_SERVICE_DEFINITION(keyring_generator)
104
105#endif // !KEYRING_GENERATOR_INCLUDED
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:112