MySQL 9.1.0
Source Code Documentation
keyring_generator_service_impl_template.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_SERVICE_IMPL_TEMPLATE_INCLUDED
25#define KEYRING_GENERATOR_SERVICE_IMPL_TEMPLATE_INCLUDED
26
27#include <functional> /* std::function */
28#include <sstream>
29
30#include <my_dbug.h>
31#include <mysql/components/services/log_builtins.h> /* LogComponentErr */
32#include <mysqld_error.h>
33
37
39
42
43/**
44 Generate data and store in keyring
45
46 @param [in] data_id Data Identifier
47 @param [in] auth_id Authorization ID
48 @param [in] data_type Type of data. Assumed null terminated.
49 @param [in] data_size Size of the data to be generated
50 @param [in] keyring_operations Reference to the object
51 that handles cache and backend
52 @param [in] callbacks Handle to component specific callbacks
53
54 @returns status of the operation
55 @retval false Success - Key generated and stored in keyring.
56 @retval true Failure
57*/
58template <typename Backend, typename Data_extension = data::Data>
60 const char *data_id, const char *auth_id, const char *data_type,
61 size_t data_size,
63 Component_callbacks &callbacks) {
64 try {
65 if (!callbacks.keyring_initialized()) {
66 LogComponentErr(INFORMATION_LEVEL,
67 ER_NOTE_KEYRING_COMPONENT_NOT_INITIALIZED);
68 return true;
69 }
70
71 if (data_id == nullptr || !*data_id) {
72 LogComponentErr(INFORMATION_LEVEL,
73 ER_NOTE_KEYRING_COMPONENT_EMPTY_DATA_ID);
74 assert(false);
75 return true;
76 }
77
78 if (data_size > keyring_operations.maximum_data_length()) {
79 LogComponentErr(INFORMATION_LEVEL,
80 ER_NOTE_KEYRING_COMPONENT_WRITE_MAXIMUM_DATA_LENGTH,
81 keyring_operations.maximum_data_length());
82 return true;
83 }
84
85 Metadata metadata(data_id, auth_id);
86 if (keyring_operations.generate(metadata, data_type, data_size)) {
87 LogComponentErr(INFORMATION_LEVEL,
88 ER_NOTE_KEYRING_COMPONENT_GENERATE_FAILED, data_id,
89 (auth_id == nullptr || !*auth_id) ? "NULL" : auth_id);
90 return true;
91 }
92 return false;
93 } catch (...) {
94 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "generate",
95 "keyring_generate");
96 return true;
97 }
98}
99
100} // namespace keyring_common::service_implementation
101
102#endif // !KEYRING_GENERATOR_SERVICE_IMPL_TEMPLATE_INCLUDED
Common metadata.
Definition: meta.h:38
Keyring operations A class to perform operations on keyring.
Definition: operations.h:482
bool generate(const meta::Metadata &metadata, const data::Type type, size_t length)
Generate API.
Definition: operations.h:632
size_t maximum_data_length() const
Maximum data length supported.
Definition: operations.h:778
bool keyring_initialized()
Keyring component status.
Definition: component_callbacks.cc:28
@ ERROR_LEVEL
Definition: my_loglevel.h:43
@ INFORMATION_LEVEL
Definition: my_loglevel.h:45
Definition: keyring_encryption_service_impl_template.h:56
bool generate_template(const char *data_id, const char *auth_id, const char *data_type, size_t data_size, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Generate data and store in keyring.
Definition: keyring_generator_service_impl_template.h:59