MySQL 9.1.0
Source Code Documentation
keyring_manager.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2016, 2024, Oracle and/or its affiliates.
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, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_HARNESS_KEYRING_MANAGER_INCLUDED
27#define MYSQL_HARNESS_KEYRING_MANAGER_INCLUDED
28
29#include <stdexcept>
30#include <string>
31
32#include "keyring.h"
33#include "keyring/master_key_file.h" // invalid_master_keyfile
34
35namespace mysql_harness {
36
37static const int kMaxKeyringKeyLength = 255;
38
39/**
40 * Initialize an instance of a keyring to be used in the application
41 * from the contents of a file, using the given master key file.
42 *
43 * @param keyring_file_path path to the file where keyring is stored
44 * @param master_key_path path to the file keyring master keys are stored
45 * @param create_if_needed creates the keyring if it doesn't exist yet
46 *
47 * @return false if the keyring had to be created
48 */
49HARNESS_EXPORT bool init_keyring(const std::string &keyring_file_path,
50 const std::string &master_key_path,
51 bool create_if_needed);
52
53/**
54 * Initialize an instance of a keyring to be used in the application
55 * from the contents of a file, using the given master key.
56 *
57 * @param keyring_file_path path to the file where keyring is stored
58 * @param master_key master key for the keyring
59 * @param create_if_needed creates the keyring if it doesn't exist yet
60 *
61 * @return false if the keyring had to be created
62 */
63HARNESS_EXPORT bool init_keyring_with_key(const std::string &keyring_file_path,
64 const std::string &master_key,
65 bool create_if_needed);
66
67/**
68 * Saves the keyring contents to disk.
69 */
70HARNESS_EXPORT void flush_keyring();
71
72/**
73 * Gets a previously initialized singleton instance of the keyring
74 */
75HARNESS_EXPORT Keyring *get_keyring() noexcept;
76
77/**
78 * Clears the keyring singleton.
79 */
80HARNESS_EXPORT void reset_keyring() noexcept;
81} // namespace mysql_harness
82
83#endif
Keyring interface.
Definition: keyring.h:41
Definition: common.h:42
HARNESS_EXPORT void reset_keyring() noexcept
Clears the keyring singleton.
Definition: keyring_manager.cc:214
HARNESS_EXPORT void flush_keyring()
Saves the keyring contents to disk.
Definition: keyring_manager.cc:207
static const int kMaxKeyringKeyLength
Definition: keyring_manager.h:37
HARNESS_EXPORT Keyring * get_keyring() noexcept
Gets a previously initialized singleton instance of the keyring.
Definition: keyring_manager.cc:212
HARNESS_EXPORT bool init_keyring(const std::string &keyring_file_path, const std::string &master_key_path, bool create_if_needed)
Initialize an instance of a keyring to be used in the application from the contents of a file,...
Definition: keyring_manager.cc:145
HARNESS_EXPORT bool init_keyring_with_key(const std::string &keyring_file_path, const std::string &master_key, bool create_if_needed)
Initialize an instance of a keyring to be used in the application from the contents of a file,...
Definition: keyring_manager.cc:186