MySQL 8.0.40
Source Code Documentation
Rpl_encryption_header_v1 Class Reference

#include <rpl_log_encryption.h>

Inheritance diagram for Rpl_encryption_header_v1:
[legend]

Public Member Functions

 Rpl_encryption_header_v1 ()=default
 
 ~Rpl_encryption_header_v1 () override
 
bool serialize (Basic_ostream *ostream) override
 Serialize the header into an output stream. More...
 
bool deserialize (Basic_istream *istream) override
 Deserialize encryption header from a stream. More...
 
char get_version () const override
 Get the header version. More...
 
int get_header_size () override
 Return the header size to be taken into account when serializing an deserializing encrypted file headers from replication log files. More...
 
Key_string decrypt_file_password () override
 Decrypt the file password. More...
 
std::unique_ptr< Stream_cipherget_encryptor () override
 Factory to generate ciphers to encrypt streams based on current header. More...
 
std::unique_ptr< Stream_cipherget_decryptor () override
 Factory to generate ciphers to decrypt streams based on current header. More...
 
Key_string generate_new_file_password () override
 Setup the header with current master key and generates a new random file password. More...
 
bool encrypt_file_password (Key_string password_str) override
 Encrypt a file password using current replication encryption master key. More...
 
- Public Member Functions inherited from Rpl_encryption_header
virtual ~Rpl_encryption_header ()
 

Static Public Member Functions

static std::string key_id_prefix ()
 Build a key id prefix. More...
 
static std::string seqno_to_key_id (uint32_t seqno)
 Build a key id using the given sequence number. More...
 
static std::string key_id_with_suffix (const char *suffix)
 Build a key id using the given suffix. More...
 
- Static Public Member Functions inherited from Rpl_encryption_header
static std::unique_ptr< Rpl_encryption_headerget_header (Basic_istream *istream)
 Deserialize the replication encrypted log file header from the given stream. More...
 
static std::unique_ptr< Rpl_encryption_headerget_new_default_header ()
 Generate a new replication encryption header based on the default replication encrypted log file header version. More...
 
static std::string key_id_prefix ()
 Build a key id prefix using default header version. More...
 
static std::string seqno_to_key_id (uint32_t seqno)
 Build a key id using the given sequence number using default header version. More...
 
static std::string key_id_with_suffix (const char *suffix)
 Build a key id using the given suffix using default header version. More...
 
static const char * get_key_type ()
 Return the default header version encryption key type. More...
 

Static Public Attributes

static const char * KEY_TYPE = "AES"
 
static const int KEY_LENGTH = 32
 
static const int HEADER_SIZE = 512
 
static const int IV_FIELD_SIZE = 16
 
static const int PASSWORD_FIELD_SIZE = 32
 
- Static Public Attributes inherited from Rpl_encryption_header
static const int ENCRYPTION_MAGIC_SIZE = 4
 
static const char * ENCRYPTION_MAGIC = "\xfd\x62\x69\x6e"
 

Private Types

enum  Field_type { KEY_ID = 1 , ENCRYPTED_FILE_PASSWORD = 2 , IV_FOR_FILE_PASSWORD = 3 }
 

Private Attributes

char m_version = 1
 
std::string m_key_id
 
Key_string m_encrypted_password
 
Key_string m_iv
 

Static Private Attributes

static const char * KEY_ID_PREFIX = "MySQLReplicationKey"
 

Additional Inherited Members

- Static Protected Attributes inherited from Rpl_encryption_header
static const int VERSION_OFFSET = ENCRYPTION_MAGIC_SIZE
 
static const int VERSION_SIZE = 1
 
static const int OPTIONAL_FIELD_OFFSET = VERSION_OFFSET + VERSION_SIZE
 

Detailed Description

  +------------------------+----------------------------------------------+
  | MAGIC HEADER (4 bytes) | Replication logs encryption version (1 byte) |
  +------------------------+----------------------------------------------+
  |             Replication Encryption Key ID (60 to 69 bytes)            |
  +-----------------------------------------------------------------------+
  |                   Encrypted File Password (33 bytes)                  |
  +-----------------------------------------------------------------------+
  |               IV For Encrypting File Password (17 bytes)              |
  +-----------------------------------------------------------------------+
  |                       Padding (388 to 397 bytes)                      |
  +-----------------------------------------------------------------------+
              Encrypted binary log file header format version 1
Encrypted binary log file header format version 1
Name Format Description
Replication Encryption Key ID Variable length field that uses Type, Length, Value (TLV) format. Type takes 1 byte. Length takes 1 byte. Values takes Length bytes. ID of the key that shall be retrieved from keyring to be used to decrypt the file password field.
Encrypted File Password Fixed length field that uses Type, Value format. Type takes 1 byte. Value takes 32 bytes. It is the encrypted file password.
IV for Encrypting File Password Fixed length field that uses Type, Value format. Type takes 1 byte. Value takes 16 bytes. The iv, together with the key, is used to encrypt/decrypt the file password.
Padding Variable length, all bytes are 0. Encryption header has 512 bytes. Above fields don't take all bytes. All unused bytes are filled with 0 as padding.

Member Enumeration Documentation

◆ Field_type

Enumerator
KEY_ID 
ENCRYPTED_FILE_PASSWORD 
IV_FOR_FILE_PASSWORD 

Constructor & Destructor Documentation

◆ Rpl_encryption_header_v1()

Rpl_encryption_header_v1::Rpl_encryption_header_v1 ( )
default

◆ ~Rpl_encryption_header_v1()

Rpl_encryption_header_v1::~Rpl_encryption_header_v1 ( )
override

Member Function Documentation

◆ decrypt_file_password()

Key_string Rpl_encryption_header_v1::decrypt_file_password ( )
overridevirtual

Decrypt the file password.

Implements Rpl_encryption_header.

◆ deserialize()

bool Rpl_encryption_header_v1::deserialize ( Basic_istream istream)
overridevirtual

Deserialize encryption header from a stream.

Parameters
[in]istreamThe input stream for deserializing the encryption header.
Return values
falseSuccess.
trueError.

Implements Rpl_encryption_header.

◆ encrypt_file_password()

bool Rpl_encryption_header_v1::encrypt_file_password ( Key_string  password_str)
overridevirtual

Encrypt a file password using current replication encryption master key.

Parameters
[in]password_strThe plain file password.
Return values
falseSuccess.
trueError.

Implements Rpl_encryption_header.

◆ generate_new_file_password()

Key_string Rpl_encryption_header_v1::generate_new_file_password ( )
overridevirtual

Setup the header with current master key and generates a new random file password.

This function shall be called when creating new replication log files.

Returns
The new file password, or an empty password if error happens.

Implements Rpl_encryption_header.

◆ get_decryptor()

std::unique_ptr< Stream_cipher > Rpl_encryption_header_v1::get_decryptor ( )
overridevirtual

Factory to generate ciphers to decrypt streams based on current header.

Returns
A Stream_cipher for this header version or nullptr on failure.

Implements Rpl_encryption_header.

◆ get_encryptor()

std::unique_ptr< Stream_cipher > Rpl_encryption_header_v1::get_encryptor ( )
overridevirtual

Factory to generate ciphers to encrypt streams based on current header.

Returns
A Stream_cipher for this header version or nullptr on failure.

Implements Rpl_encryption_header.

◆ get_header_size()

int Rpl_encryption_header_v1::get_header_size ( )
overridevirtual

Return the header size to be taken into account when serializing an deserializing encrypted file headers from replication log files.

Returns
The size of the header for the header version.

Implements Rpl_encryption_header.

◆ get_version()

char Rpl_encryption_header_v1::get_version ( ) const
overridevirtual

Get the header version.

Returns
The header version.

Implements Rpl_encryption_header.

◆ key_id_prefix()

std::string Rpl_encryption_header_v1::key_id_prefix ( )
static

Build a key id prefix.

◆ key_id_with_suffix()

std::string Rpl_encryption_header_v1::key_id_with_suffix ( const char *  suffix)
static

Build a key id using the given suffix.

Parameters
[in]suffixThe suffix used to build key id.

◆ seqno_to_key_id()

std::string Rpl_encryption_header_v1::seqno_to_key_id ( uint32_t  seqno)
static

Build a key id using the given sequence number.

Parameters
[in]seqnoThe sequence number used to build key id.

◆ serialize()

bool Rpl_encryption_header_v1::serialize ( Basic_ostream ostream)
overridevirtual

Serialize the header into an output stream.

Parameters
ostreamThe output stream to serialize the header.
Return values
falseSuccess.
trueError.

Implements Rpl_encryption_header.

Member Data Documentation

◆ HEADER_SIZE

const int Rpl_encryption_header_v1::HEADER_SIZE = 512
static

◆ IV_FIELD_SIZE

const int Rpl_encryption_header_v1::IV_FIELD_SIZE = 16
static

◆ KEY_ID_PREFIX

const char * Rpl_encryption_header_v1::KEY_ID_PREFIX = "MySQLReplicationKey"
staticprivate

◆ KEY_LENGTH

const int Rpl_encryption_header_v1::KEY_LENGTH = 32
static

◆ KEY_TYPE

const char * Rpl_encryption_header_v1::KEY_TYPE = "AES"
static

◆ m_encrypted_password

Key_string Rpl_encryption_header_v1::m_encrypted_password
private

◆ m_iv

Key_string Rpl_encryption_header_v1::m_iv
private

◆ m_key_id

std::string Rpl_encryption_header_v1::m_key_id
private

◆ m_version

char Rpl_encryption_header_v1::m_version = 1
private

◆ PASSWORD_FIELD_SIZE

const int Rpl_encryption_header_v1::PASSWORD_FIELD_SIZE = 32
static

The documentation for this class was generated from the following files: