MySQL 8.4.2
Source Code Documentation
password_vault.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 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 SRC_ROUTER_INCLUDE_MYSQLROUTER_WINDOWS_PASSWORD_VAULT_H_
27#define SRC_ROUTER_INCLUDE_MYSQLROUTER_WINDOWS_PASSWORD_VAULT_H_
28
29#include <map>
30#include <string>
31
33 public:
34 /** @brief Create an instance of the vault.
35 *
36 * On creation the vault cache is initialized with the contents of the vault
37 * file at %APPDATA%/MySQL/MySQL Router/mysql_router_user_data.dat.
38 * The passwords are stored in the cache in cleartext.
39 */
41
42 /** @brief wipes the contents of the vault cache.
43 */
45
46 /** @brief Updates a pair (section name, password) in the vault cache.
47 *
48 * If the record for the given section name & password does not exits, it is
49 * created. If it exists it is just updated with the new password.
50 *
51 * @param section_name The name of the configuration section to store in the
52 * vault.
53 * @param password The password, in clear text, of the user in the
54 * configuration section to store in the vault.
55 */
56 void update_password(const std::string &section_name,
57 const std::string &password);
58
59 /** @brief Retrieves the password, in clear text, for the given section as
60 * is stored in the vault.
61 *
62 * @param section_name The name of the configuration section for which to
63 * retrieve the password.
64 * @param out_password Output parameter. The password in clear text if the
65 * section name was found in the vault.
66 * @return true if a password was retrieved for the given section, false if
67 * the section name could not be found in the vault.
68 */
69 bool get_password(const std::string &section_name,
70 std::string &out_password) const;
71
72 /** @brief Removes the password from the vault for the given section name.
73 *
74 * After executing this method for a fiven section name, the method
75 * get_password will return false for the same section name.
76 *
77 * @param section_name The name of the configuration section for which to
78 * remove the password.
79 */
80 void remove_password(const std::string &section_name);
81
82 /** @brief Stores the vault cache into persistent storage in encrypted form.
83 *
84 * The vault location in persistent storage is
85 * %APPDATA%/MySQL/MySQL Router/mysql_router_user_data.dat.
86 */
88
89 /** @brief Wipes the contents of the vault file.
90 *
91 * NOTE: The delete the vault cache (in memory) created for an instance of
92 * PasswordVault is done automatically in the destructor.
93 */
95
96 private:
98 std::string get_vault_path() const;
99 // Password cache as pairs <section_name, password>
100 std::map<std::string, std::string> _passwords;
101 void password_scrambler(std::string &pass);
102};
103
104#endif // SRC_ROUTER_INCLUDE_MYSQLROUTER_WINDOWS_PASSWORD_VAULT_H_
Definition: password_vault.h:32
void remove_password(const std::string &section_name)
Removes the password from the vault for the given section name.
bool get_password(const std::string &section_name, std::string &out_password) const
Retrieves the password, in clear text, for the given section as is stored in the vault.
std::string get_vault_path() const
void load_passwords()
void update_password(const std::string &section_name, const std::string &password)
Updates a pair (section name, password) in the vault cache.
void store_passwords()
Stores the vault cache into persistent storage in encrypted form.
void clear_passwords()
Wipes the contents of the vault file.
std::map< std::string, std::string > _passwords
Definition: password_vault.h:100
void password_scrambler(std::string &pass)
PasswordVault()
Create an instance of the vault.
~PasswordVault()
wipes the contents of the vault cache.
static char * password
Definition: mysql_secure_installation.cc:58