The Battle for Wesnoth  1.19.0-dev
Classes | Namespaces | Macros | Functions | Variables
credentials.cpp File Reference
#include "credentials.hpp"
#include "preferences/general.hpp"
#include "serialization/unicode.hpp"
#include "filesystem.hpp"
#include "log.hpp"
#include "serialization/string_utils.hpp"
#include <boost/algorithm/string.hpp>
#include <algorithm>
#include <memory>
#include <openssl/evp.h>
#include <openssl/err.h>
Include dependency graph for credentials.cpp:

Go to the source code of this file.

Classes

class  secure_buffer
 
struct  login_info
 

Namespaces

 preferences
 Modify, read and display user preferences.
 

Macros

#define DBG_CFG   LOG_STREAM(debug , log_config)
 
#define ERR_CFG   LOG_STREAM(err , log_config)
 

Functions

static secure_buffer aes_encrypt (const secure_buffer &plaintext, const secure_buffer &key)
 Encrypts the value of plaintext using key and a hard coded IV using AES. More...
 
static secure_buffer aes_decrypt (const secure_buffer &encrypted, const secure_buffer &key)
 Same as aes_encrypt(), except of course it takes encrypted data as an argument and returns decrypted data. More...
 
static secure_buffer build_key (const std::string &server, const std::string &login)
 Fills a secure_buffer with 32 bytes of deterministically generated bytes, then overwrites it with the system login name, server login name, and server name. More...
 
static secure_buffer escape (const secure_buffer &text)
 
static secure_buffer unescape (const secure_buffer &text)
 
static std::string get_system_username ()
 
static void clear_credentials ()
 
std::string preferences::login ()
 
void preferences::set_login (const std::string &login)
 
bool preferences::remember_password ()
 
void preferences::set_remember_password (bool remember)
 
std::string preferences::password (const std::string &server, const std::string &login)
 
void preferences::set_password (const std::string &server, const std::string &login, const std::string &key)
 
void preferences::load_credentials ()
 
void preferences::save_credentials ()
 

Variables

static lg::log_domain log_config ("config")
 
static std::vector< login_infocredentials
 
static const unsigned char CREDENTIAL_SEPARATOR = '\f'
 
static const std::string EMPTY_LOGIN = "@@"
 

Macro Definition Documentation

◆ DBG_CFG

#define DBG_CFG   LOG_STREAM(debug , log_config)

Definition at line 41 of file credentials.cpp.

◆ ERR_CFG

#define ERR_CFG   LOG_STREAM(err , log_config)

Definition at line 42 of file credentials.cpp.

Function Documentation

◆ aes_decrypt()

static secure_buffer aes_decrypt ( const secure_buffer text,
const secure_buffer key 
)
static

Same as aes_encrypt(), except of course it takes encrypted data as an argument and returns decrypted data.

Definition at line 379 of file credentials.cpp.

References DBG_CFG, ERR_CFG, i, and utils::join().

Referenced by preferences::load_credentials(), and preferences::password().

◆ aes_encrypt()

static secure_buffer aes_encrypt ( const secure_buffer plaintext,
const secure_buffer key 
)
static

Encrypts the value of plaintext using key and a hard coded IV using AES.

Max size of plaintext must not be larger than 1008 bytes.

NOTE: This is not meant to provide strong protections against a determined attacker. This is meant to hide the passwords from malware scanning files for passwords, family/friends poking around, etc.

Parameters
plaintextThe original unencrypted data.
keyThe value to use to encrypt the data. See build_key() for key generation.
Returns
secure_buffer The encrypted data.

Definition at line 288 of file credentials.cpp.

References DBG_CFG, ERR_CFG, i, and utils::join().

Referenced by preferences::save_credentials(), and preferences::set_password().

◆ build_key()

secure_buffer build_key ( const std::string &  server,
const std::string &  login 
)
static

Fills a secure_buffer with 32 bytes of deterministically generated bytes, then overwrites it with the system login name, server login name, and server name.

If this is more than 32 bytes, then it's truncated. If it's less than 32 bytes, then the pre-generated bytes are used to pad it.

Parameters
serverThe server being logged into.
loginThe username being used to login.
Returns
secure_buffer The data to be used as the encryption key.

Definition at line 265 of file credentials.cpp.

References get_system_username(), i, and preferences::login().

Referenced by preferences::load_credentials(), preferences::password(), preferences::save_credentials(), and preferences::set_password().

◆ clear_credentials()

static void clear_credentials ( )
static

◆ escape()

secure_buffer escape ( const secure_buffer text)
static

Definition at line 497 of file credentials.cpp.

References c.

Referenced by preferences::save_credentials().

◆ get_system_username()

static std::string get_system_username ( )
static

◆ unescape()

secure_buffer unescape ( const secure_buffer text)
static

Definition at line 472 of file credentials.cpp.

References c.

Referenced by preferences::load_credentials().

Variable Documentation

◆ CREDENTIAL_SEPARATOR

const unsigned char CREDENTIAL_SEPARATOR = '\f'
static

Definition at line 75 of file credentials.cpp.

Referenced by preferences::load_credentials(), and preferences::save_credentials().

◆ credentials

std::vector<login_info> credentials
static

◆ EMPTY_LOGIN

const std::string EMPTY_LOGIN = "@@"
static

Definition at line 113 of file credentials.cpp.

Referenced by preferences::login().

◆ log_config

lg::log_domain log_config("config") ( "config"  )
static