MySQL 9.0.0
Source Code Documentation
Rpl_encryption_header Class Referenceabstract

This is the base class to serialize and deserialize a replication log file encryption header. More...

#include <rpl_log_encryption.h>

Inheritance diagram for Rpl_encryption_header:
[legend]

Public Member Functions

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

Static Public Member Functions

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 int ENCRYPTION_MAGIC_SIZE = 4
 
static const char * ENCRYPTION_MAGIC = "\xfd\x62\x69\x6e"
 

Static Protected Attributes

static const int VERSION_OFFSET = ENCRYPTION_MAGIC_SIZE
 
static const int VERSION_SIZE = 1
 
static const int OPTIONAL_FIELD_OFFSET = VERSION_OFFSET + VERSION_SIZE
 

Static Private Attributes

static const char m_default_version = 1
 

Detailed Description

This is the base class to serialize and deserialize a replication log file encryption header.

The new encrypted binary log file format is composed of two parts:

    +---------------------+
    |  Encryption Header  |
    +---------------------+
    |   Encrypted Data    |
    +---------------------+

The encryption header exists only in the begin of encrypted replication log files.

  +------------------------+----------------------------------------------+
  | MAGIC HEADER (4 bytes) | Replication logs encryption version (1 byte) |
  +------------------------+----------------------------------------------+
  |                Version specific encryption header data                |
  +-----------------------------------------------------------------------+
                           Encryption Header Format
Encryption Header Format
Name Format Description
Magic Header 4 Bytes The content is always 0xFD62696E. It is similar to Binlog Magic Header. Binlog magic header is: 0xFE62696e.
Replication logs encryption version 1 Byte The replication logs encryption version defines how the header shall be deserialized and how the Encrypted Data shall be decrypted.
Version specific encryption data header Depends on the version field Data required to fetch a replication key from keyring and deserialize the Encrypted Data.

Constructor & Destructor Documentation

◆ ~Rpl_encryption_header()

Rpl_encryption_header::~Rpl_encryption_header ( )
virtual

Member Function Documentation

◆ decrypt_file_password()

virtual Key_string Rpl_encryption_header::decrypt_file_password ( )
pure virtual

Decrypt the file password.

Implemented in Rpl_encryption_header_v1.

◆ deserialize()

virtual bool Rpl_encryption_header::deserialize ( Basic_istream istream)
pure virtual

Deserialize encryption header from a stream.

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

Implemented in Rpl_encryption_header_v1.

◆ encrypt_file_password()

virtual bool Rpl_encryption_header::encrypt_file_password ( Key_string  password_str)
pure virtual

Encrypt a file password using current replication encryption master key.

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

Implemented in Rpl_encryption_header_v1.

◆ generate_new_file_password()

virtual Key_string Rpl_encryption_header::generate_new_file_password ( )
pure virtual

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.

Implemented in Rpl_encryption_header_v1.

◆ get_decryptor()

virtual std::unique_ptr< Stream_cipher > Rpl_encryption_header::get_decryptor ( )
pure virtual

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

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

Implemented in Rpl_encryption_header_v1.

◆ get_encryptor()

virtual std::unique_ptr< Stream_cipher > Rpl_encryption_header::get_encryptor ( )
pure virtual

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

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

Implemented in Rpl_encryption_header_v1.

◆ get_header()

std::unique_ptr< Rpl_encryption_header > Rpl_encryption_header::get_header ( Basic_istream istream)
static

Deserialize the replication encrypted log file header from the given stream.

This function shall be called right after reading the magic from the stream. It will read the version of the encrypted log file header, instantiate a proper Rpl_encryption_header based on version and delegate the rest of the header deserialization to the new instance.

Parameters
istreamThe stream containing the header to deserialize.
Returns
A Rpl_encryption_header on success or nullptr on failure.

◆ get_header_size()

virtual int Rpl_encryption_header::get_header_size ( )
pure virtual

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.

Implemented in Rpl_encryption_header_v1.

◆ get_key_type()

const char * Rpl_encryption_header::get_key_type ( )
static

Return the default header version encryption key type.

Returns
The encrypted key type.

◆ get_new_default_header()

std::unique_ptr< Rpl_encryption_header > Rpl_encryption_header::get_new_default_header ( )
static

Generate a new replication encryption header based on the default replication encrypted log file header version.

Returns
A Rpl_encryption_header of default version.

◆ get_version()

virtual char Rpl_encryption_header::get_version ( ) const
pure virtual

Get the header version.

Returns
The header version.

Implemented in Rpl_encryption_header_v1.

◆ key_id_prefix()

std::string Rpl_encryption_header::key_id_prefix ( )
static

Build a key id prefix using default header version.

Returns
A key ID prefix.

◆ key_id_with_suffix()

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

Build a key id using the given suffix using default header version.

Parameters
[in]suffixThe suffix used to build key id.
Returns
A key ID with a suffix.

◆ seqno_to_key_id()

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

Build a key id using the given sequence number using default header version.

Parameters
[in]seqnoThe sequence number used to build key id.
Returns
A key ID with a sequence number.

◆ serialize()

virtual bool Rpl_encryption_header::serialize ( Basic_ostream ostream)
pure virtual

Serialize the header into an output stream.

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

Implemented in Rpl_encryption_header_v1.

Member Data Documentation

◆ ENCRYPTION_MAGIC

const char * Rpl_encryption_header::ENCRYPTION_MAGIC = "\xfd\x62\x69\x6e"
static

◆ ENCRYPTION_MAGIC_SIZE

const int Rpl_encryption_header::ENCRYPTION_MAGIC_SIZE = 4
static

◆ m_default_version

const char Rpl_encryption_header::m_default_version = 1
staticprivate

◆ OPTIONAL_FIELD_OFFSET

const int Rpl_encryption_header::OPTIONAL_FIELD_OFFSET = VERSION_OFFSET + VERSION_SIZE
staticprotected

◆ VERSION_OFFSET

const int Rpl_encryption_header::VERSION_OFFSET = ENCRYPTION_MAGIC_SIZE
staticprotected

◆ VERSION_SIZE

const int Rpl_encryption_header::VERSION_SIZE = 1
staticprotected

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