CUBRID Engine  latest
tde.c File Reference
#include <stdlib.h>
#include <assert.h>
#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "heap_file.h"
#include "btree.h"
#include "system_parameter.h"
#include "boot_sr.h"
#include "file_io.h"
#include "error_manager.h"
#include "error_code.h"
#include "log_storage.hpp"
#include "log_volids.hpp"
#include "tde.h"

Go to the source code of this file.

Macros

#define off_signals(new_mask, old_mask)
 
#define restore_signals(old_mask)   sigprocmask(SIG_SETMASK, &(old_mask), NULL)
 

Functions

static int tde_generate_keyinfo (TDE_KEYINFO *keyinfo, int mk_index, const unsigned char *master_key, const time_t created_time, const TDE_DATA_KEY_SET *dks)
 
static int tde_update_keyinfo (THREAD_ENTRY *thread_p, const TDE_KEYINFO *keyinfo)
 
static int tde_create_keys_file (const char *keyfile_fullname)
 
static bool tde_validate_mk (const unsigned char *master_key, const unsigned char *mk_hash)
 
static void tde_make_mk_hash (const unsigned char *master_key, unsigned char *mk_hash)
 
static int tde_load_dks (const unsigned char *master_key, const TDE_KEYINFO *keyinfo)
 
static int tde_create_dk (unsigned char *data_key)
 
static int tde_encrypt_dk (const unsigned char *dk_plain, TDE_DATA_KEY_TYPE dk_type, const unsigned char *master_key, unsigned char *dk_cipher)
 
static int tde_decrypt_dk (const unsigned char *dk_cipher, TDE_DATA_KEY_TYPE dk_type, const unsigned char *master_key, unsigned char *dk_plain)
 
static void tde_dk_nonce (TDE_DATA_KEY_TYPE dk_type, unsigned char *dk_nonce)
 
static int tde_encrypt_internal (const unsigned char *plain_buffer, int length, TDE_ALGORITHM tde_algo, const unsigned char *key, const unsigned char *nonce, unsigned char *cipher_buffer)
 
static int tde_decrypt_internal (const unsigned char *cipher_buffer, int length, TDE_ALGORITHM tde_algo, const unsigned char *key, const unsigned char *nonce, unsigned char *plain_buffer)
 
int tde_initialize (THREAD_ENTRY *thread_p, HFID *keyinfo_hfid)
 
int tde_cipher_initialize (THREAD_ENTRY *thread_p, const HFID *keyinfo_hfid, const char *mk_path_given)
 
bool tde_validate_keys_file (int vdes)
 
int tde_copy_keys_file (THREAD_ENTRY *thread_p, const char *dest_fullname, const char *src_fullname, bool keep_dest_mount, bool keep_src_mount)
 
void tde_make_keys_file_fullname (char *keys_vol_fullname, const char *db_full_name, bool ignore_parm)
 
int tde_get_keyinfo (THREAD_ENTRY *thread_p, TDE_KEYINFO *keyinfo)
 
int tde_change_mk (THREAD_ENTRY *thread_p, const int mk_index, const unsigned char *master_key, const time_t created_time)
 
int tde_load_mk (int vdes, const TDE_KEYINFO *keyinfo, unsigned char *master_key)
 
int tde_encrypt_data_page (const FILEIO_PAGE *iopage_plain, TDE_ALGORITHM tde_algo, bool is_temp, FILEIO_PAGE *iopage_cipher)
 
int tde_decrypt_data_page (const FILEIO_PAGE *iopage_cipher, TDE_ALGORITHM tde_algo, bool is_temp, FILEIO_PAGE *iopage_plain)
 
int tde_encrypt_log_page (const LOG_PAGE *logpage_plain, TDE_ALGORITHM tde_algo, LOG_PAGE *logpage_cipher)
 
int tde_decrypt_log_page (const LOG_PAGE *logpage_cipher, TDE_ALGORITHM tde_algo, LOG_PAGE *logpage_plain)
 
int xtde_get_mk_info (THREAD_ENTRY *thread_p, int *mk_index, time_t *created_time, time_t *set_time)
 
int xtde_change_mk_without_flock (THREAD_ENTRY *thread_p, const int mk_index)
 
int tde_create_mk (unsigned char *master_key, time_t *created_time)
 
void tde_print_mk (const unsigned char *master_key)
 
int tde_add_mk (int vdes, const unsigned char *master_key, time_t created_time, int *mk_index)
 
int tde_find_mk (int vdes, int mk_index, unsigned char *master_key, time_t *created_time)
 
int tde_find_first_mk (int vdes, int *mk_index, unsigned char *master_key, time_t *created_time)
 
int tde_delete_mk (int vdes, int mk_index)
 
int tde_dump_mks (int vdes, bool print_value)
 
const char * tde_get_algorithm_name (TDE_ALGORITHM tde_algo)
 

Variables

TDE_CIPHER tde_Cipher
 
static OID tde_Keyinfo_oid = OID_INITIALIZER
 
static HFID tde_Keyinfo_hfid = HFID_INITIALIZER
 

Macro Definition Documentation

#define off_signals (   new_mask,
  old_mask 
)
Value:
do { \
sigfillset (&(new_mask)); \
sigdelset (&(new_mask), SIGINT); \
sigdelset (&(new_mask), SIGQUIT); \
sigdelset (&(new_mask), SIGTERM); \
sigdelset (&(new_mask), SIGHUP); \
sigdelset (&(new_mask), SIGABRT); \
sigprocmask (SIG_SETMASK, &(new_mask), &(old_mask)); \
} while (0)

Definition at line 56 of file tde.c.

Referenced by tde_add_mk(), tde_create_keys_file(), tde_delete_mk(), tde_dump_mks(), tde_find_first_mk(), tde_find_mk(), and tde_validate_keys_file().

#define restore_signals (   old_mask)    sigprocmask(SIG_SETMASK, &(old_mask), NULL)

Function Documentation

int tde_change_mk ( THREAD_ENTRY thread_p,
const int  mk_index,
const unsigned char *  master_key,
const time_t  created_time 
)
static int tde_create_dk ( unsigned char *  data_key)
static

Definition at line 802 of file tde.c.

References ARG_FILE_LINE, assert, ER_ERROR_SEVERITY, er_set(), ER_TDE_KEY_CREATION_FAIL, NO_ERROR, NULL, and TDE_DATA_KEY_LENGTH.

Referenced by tde_initialize().

Here is the caller graph for this function:

static int tde_create_keys_file ( const char *  keyfile_fullname)
static
int tde_create_mk ( unsigned char *  master_key,
time_t *  created_time 
)

Definition at line 1311 of file tde.c.

References ARG_FILE_LINE, assert, ER_ERROR_SEVERITY, er_set(), ER_TDE_KEY_CREATION_FAIL, NO_ERROR, NULL, and TDE_MASTER_KEY_LENGTH.

Referenced by tde(), and tde_initialize().

Here is the caller graph for this function:

static int tde_decrypt_dk ( const unsigned char *  dk_cipher,
TDE_DATA_KEY_TYPE  dk_type,
const unsigned char *  master_key,
unsigned char *  dk_plain 
)
static

Definition at line 846 of file tde.c.

References TDE_DATA_KEY_LENGTH, tde_decrypt_internal(), TDE_DK_ALGORITHM, tde_dk_nonce(), and TDE_DK_NONCE_LENGTH.

Referenced by tde_load_dks().

Here is the caller graph for this function:

static int tde_decrypt_internal ( const unsigned char *  cipher_buffer,
int  length,
TDE_ALGORITHM  tde_algo,
const unsigned char *  key,
const unsigned char *  nonce,
unsigned char *  plain_buffer 
)
static
int tde_delete_mk ( int  vdes,
int  mk_index 
)

Definition at line 1569 of file tde.c.

References ARG_FILE_LINE, tde_mk_file_item::created_time, ER_ERROR_SEVERITY, er_set(), ER_TDE_MASTER_KEY_NOT_FOUND, NO_ERROR, off_signals, restore_signals, TDE_MK_FILE_ITEM_OFFSET, and TDE_MK_FILE_ITEM_SIZE.

Referenced by tde().

Here is the caller graph for this function:

static void tde_dk_nonce ( TDE_DATA_KEY_TYPE  dk_type,
unsigned char *  dk_nonce 
)
inlinestatic

Definition at line 863 of file tde.c.

References assert, NULL, TDE_DATA_KEY_TYPE_LOG, TDE_DATA_KEY_TYPE_PERM, TDE_DATA_KEY_TYPE_TEMP, and TDE_DK_NONCE_LENGTH.

Referenced by tde_decrypt_dk(), and tde_encrypt_dk().

Here is the caller graph for this function:

int tde_dump_mks ( int  vdes,
bool  print_value 
)
static int tde_encrypt_dk ( const unsigned char *  dk_plain,
TDE_DATA_KEY_TYPE  dk_type,
const unsigned char *  master_key,
unsigned char *  dk_cipher 
)
static

Definition at line 826 of file tde.c.

References TDE_DATA_KEY_LENGTH, TDE_DK_ALGORITHM, tde_dk_nonce(), TDE_DK_NONCE_LENGTH, and tde_encrypt_internal().

Referenced by tde_generate_keyinfo().

Here is the caller graph for this function:

static int tde_encrypt_internal ( const unsigned char *  plain_buffer,
int  length,
TDE_ALGORITHM  tde_algo,
const unsigned char *  key,
const unsigned char *  nonce,
unsigned char *  cipher_buffer 
)
static
int tde_find_first_mk ( int  vdes,
int *  mk_index,
unsigned char *  master_key,
time_t *  created_time 
)
int tde_find_mk ( int  vdes,
int  mk_index,
unsigned char *  master_key,
time_t *  created_time 
)
static int tde_generate_keyinfo ( TDE_KEYINFO keyinfo,
int  mk_index,
const unsigned char *  master_key,
const time_t  created_time,
const TDE_DATA_KEY_SET dks 
)
static
static int tde_load_dks ( const unsigned char *  master_key,
const TDE_KEYINFO keyinfo 
)
static
int tde_load_mk ( int  vdes,
const TDE_KEYINFO keyinfo,
unsigned char *  master_key 
)
static void tde_make_mk_hash ( const unsigned char *  master_key,
unsigned char *  mk_hash 
)
static

Definition at line 782 of file tde.c.

References assert, NULL, and TDE_MASTER_KEY_LENGTH.

Referenced by tde_generate_keyinfo(), and tde_validate_mk().

Here is the caller graph for this function:

void tde_print_mk ( const unsigned char *  master_key)

Definition at line 1332 of file tde.c.

References i, and TDE_MASTER_KEY_LENGTH.

Referenced by tde(), and tde_dump_mks().

Here is the caller graph for this function:

bool tde_validate_keys_file ( int  vdes)

Definition at line 358 of file tde.c.

References CUBRID_MAGIC_KEYS, CUBRID_MAGIC_MAX_LENGTH, off_signals, and restore_signals.

Referenced by boot_reset_mk_after_restart_from_backup(), logpb_restore(), tde_cipher_initialize(), tde_copy_keys_file(), and tde_initialize().

Here is the caller graph for this function:

static bool tde_validate_mk ( const unsigned char *  master_key,
const unsigned char *  mk_hash 
)
static

Definition at line 762 of file tde.c.

References tde_make_mk_hash(), and TDE_MASTER_KEY_LENGTH.

Referenced by tde_load_mk(), and xtde_change_mk_without_flock().

Here is the caller graph for this function:

int xtde_get_mk_info ( THREAD_ENTRY thread_p,
int *  mk_index,
time_t *  created_time,
time_t *  set_time 
)

Variable Documentation

HFID tde_Keyinfo_hfid = HFID_INITIALIZER
static

Definition at line 72 of file tde.c.

OID tde_Keyinfo_oid = OID_INITIALIZER
static

Definition at line 71 of file tde.c.