MySQL 8.0.39
Source Code Documentation
keyring_writer_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_WRITER_SERVICE_IMPL_TEMPLATE_INCLUDED
25#define KEYRING_WRITER_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
38
39namespace keyring_common {
40namespace service_implementation {
41
45
46/**
47 Store data in keyring
48
49 @param [in] data_id Data Identifier
50 @param [in] auth_id Authorization ID
51 @param [in] data Data to be stored
52 @param [in] data_size Size of data to be stored
53 @param [in] data_type Type of data
54 @param [in] keyring_operations Reference to the object
55 that handles cache and backend
56 @param [in] callbacks Handle to component specific callbacks
57
58 @returns status of the operation
59 @retval false Success
60 @retval true Failure
61*/
62
63template <typename Backend, typename Data_extension = data::Data>
65 const char *data_id, const char *auth_id, const unsigned char *data,
66 size_t data_size, const char *data_type,
69 try {
70 if (callbacks.keyring_initialized() == false) {
71 return true;
72 }
73
74 if (data_id == nullptr || !*data_id) {
75 assert(false);
76 return true;
77 }
78
79 if (data_size > keyring_operations.maximum_data_length()) {
80 LogComponentErr(INFORMATION_LEVEL,
81 ER_NOTE_KEYRING_COMPONENT_WRITE_MAXIMUM_DATA_LENGTH,
82 keyring_operations.maximum_data_length());
83 return true;
84 }
85
86 Metadata metadata(data_id, auth_id);
87 Data data_to_be_stored({reinterpret_cast<const char *>(data), data_size},
88 {data_type, data_type ? strlen(data_type) : 0});
89 if (keyring_operations.store(metadata, data_to_be_stored) == true) {
90 LogComponentErr(INFORMATION_LEVEL, ER_NOTE_KEYRING_COMPONENT_STORE_FAILED,
91 data_id,
92 (auth_id == nullptr || !*auth_id) ? "NULL" : auth_id);
93 return true;
94 }
95 return false;
96 } catch (...) {
97 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "store",
98 "keyring_writer");
99 return true;
100 }
101}
102
103/**
104 Remove data from keyring
105
106 @param [in] data_id Data Identifier
107 @param [in] auth_id Authorization ID
108 @param [in] keyring_operations Reference to the object
109 that handles cache and backend
110 @param [in] callbacks Handle to component specific callbacks
111
112 @returns status of the operation
113 @retval false Success - Key removed successfully or key not present.
114 @retval true Failure
115*/
116template <typename Backend, typename Data_extension = data::Data>
118 const char *data_id, const char *auth_id,
121 try {
122 if (callbacks.keyring_initialized() == false) {
123 return true;
124 }
125
126 if (data_id == nullptr || !*data_id) {
127 assert(false);
128 return true;
129 }
130
131 Metadata metadata(data_id, auth_id);
132 if (keyring_operations.erase(metadata) == true) {
133 LogComponentErr(INFORMATION_LEVEL,
134 ER_NOTE_KEYRING_COMPONENT_REMOVE_FAILED, data_id,
135 (auth_id == nullptr || !*auth_id) ? "NULL" : auth_id);
136 return true;
137 }
138 return false;
139 } catch (...) {
140 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "remove",
141 "keyring_writer");
142 return true;
143 }
144}
145
146} // namespace service_implementation
147} // namespace keyring_common
148
149#endif // !KEYRING_WRITER_SERVICE_IMPL_TEMPLATE_INCLUDED
static const sasl_callback_t callbacks[]
Definition: auth_ldap_sasl_client.h:45
Sensitive data storage.
Definition: data.h:40
Common metadata.
Definition: meta.h:39
Keyring operations A class to perform operations on keyring.
Definition: operations.h:483
bool erase(const meta::Metadata &metadata)
Remove API.
Definition: operations.h:610
bool store(const meta::Metadata &metadata, const data::Data &data)
Store API.
Definition: operations.h:571
size_t maximum_data_length() const
Maximum data length supported.
Definition: operations.h:779
@ ERROR_LEVEL
Definition: my_loglevel.h:43
@ INFORMATION_LEVEL
Definition: my_loglevel.h:45
bool store_template(const char *data_id, const char *auth_id, const unsigned char *data, size_t data_size, const char *data_type, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Store data in keyring.
Definition: keyring_writer_service_impl_template.h:64
bool remove_template(const char *data_id, const char *auth_id, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Remove data from keyring.
Definition: keyring_writer_service_impl_template.h:117
Definition: keyring_encryption_service_definition.h:32