diff --git a/src/access/pg_tde_slot.c b/src/access/pg_tde_slot.c index 351bb86c..45f22e53 100644 --- a/src/access/pg_tde_slot.c +++ b/src/access/pg_tde_slot.c @@ -481,7 +481,8 @@ const TupleTableSlotOps TTSOpsTDEBufferHeapTuple = { /* A buffer heap tuple table slot can not "own" a minimal tuple. */ .get_minimal_tuple = NULL, .copy_heap_tuple = tdeheap_tts_buffer_heap_copy_heap_tuple, -.copy_minimal_tuple = tdeheap_tts_buffer_heap_copy_minimal_tuple}; + .copy_minimal_tuple = tdeheap_tts_buffer_heap_copy_minimal_tuple +}; /* -------------------------------- * ExecStoreBufferHeapTuple diff --git a/src/access/pg_tde_tdemap.c b/src/access/pg_tde_tdemap.c index 5e211f12..9cb70699 100644 --- a/src/access/pg_tde_tdemap.c +++ b/src/access/pg_tde_tdemap.c @@ -55,15 +55,14 @@ } #endif -#define PG_TDE_MAP_FILENAME "pg_tde.map" -#define PG_TDE_KEYDATA_FILENAME "pg_tde.dat" +#define PG_TDE_MAP_FILENAME "pg_tde.map" +#define PG_TDE_KEYDATA_FILENAME "pg_tde.dat" -#define PG_TDE_FILEMAGIC 0x01454454 /* version ID value = TDE - * 01 */ +#define PG_TDE_FILEMAGIC 0x01454454 /* version ID value = TDE 01 */ -#define MAP_ENTRY_SIZE sizeof(TDEMapEntry) -#define TDE_FILE_HEADER_SIZE sizeof(TDEFileHeader) +#define MAP_ENTRY_SIZE sizeof(TDEMapEntry) +#define TDE_FILE_HEADER_SIZE sizeof(TDEFileHeader) typedef struct TDEFileHeader { @@ -117,21 +116,21 @@ RelKeyCache *tde_rel_key_cache = NULL; static int32 pg_tde_process_map_entry(const RelFileLocator *rlocator, uint32 key_type, char *db_map_path, off_t *offset, bool should_delete); static RelKeyData *pg_tde_read_keydata(char *db_keydata_path, int32 key_index, TDEPrincipalKey *principal_key); -static int pg_tde_open_file_basic(char *tde_filename, int fileFlags, bool ignore_missing); -static int pg_tde_file_header_read(char *tde_filename, int fd, TDEFileHeader *fheader, bool *is_new_file, off_t *bytes_read); +static int pg_tde_open_file_basic(char *tde_filename, int fileFlags, bool ignore_missing); +static int pg_tde_file_header_read(char *tde_filename, int fd, TDEFileHeader *fheader, bool *is_new_file, off_t *bytes_read); static bool pg_tde_read_one_map_entry(int fd, const RelFileLocator *rlocator, int flags, TDEMapEntry *map_entry, off_t *offset); static RelKeyData *pg_tde_read_one_keydata(int keydata_fd, int32 key_index, TDEPrincipalKey *principal_key); -static int pg_tde_open_file(char *tde_filename, TDEPrincipalKeyInfo *principal_key_info, bool should_fill_info, int fileFlags, bool *is_new_file, off_t *offset); +static int pg_tde_open_file(char *tde_filename, TDEPrincipalKeyInfo *principal_key_info, bool should_fill_info, int fileFlags, bool *is_new_file, off_t *offset); static RelKeyData *pg_tde_get_key_from_cache(RelFileNumber rel_number, uint32 key_type); #ifndef FRONTEND -static int pg_tde_file_header_write(char *tde_filename, int fd, TDEPrincipalKeyInfo *principal_key_info, off_t *bytes_written); +static int pg_tde_file_header_write(char *tde_filename, int fd, TDEPrincipalKeyInfo *principal_key_info, off_t *bytes_written); static int32 pg_tde_write_map_entry(const RelFileLocator *rlocator, uint32 entry_type, char *db_map_path, TDEPrincipalKeyInfo *principal_key_info); static off_t pg_tde_write_one_map_entry(int fd, const RelFileLocator *rlocator, uint32 flags, int32 key_index, TDEMapEntry *map_entry, off_t *offset); static void pg_tde_write_keydata(char *db_keydata_path, TDEPrincipalKeyInfo *principal_key_info, int32 key_index, RelKeyData *enc_rel_key_data); static void pg_tde_write_one_keydata(int keydata_fd, int32 key_index, RelKeyData *enc_rel_key_data); -static int keyrotation_init_file(TDEPrincipalKeyInfo *new_principal_key_info, char *rotated_filename, char *filename, bool *is_new_file, off_t *curr_pos); +static int keyrotation_init_file(TDEPrincipalKeyInfo *new_principal_key_info, char *rotated_filename, char *filename, bool *is_new_file, off_t *curr_pos); static void finalize_key_rotation(char *m_path_old, char *k_path_old, char *m_path_new, char *k_path_new); RelKeyData * @@ -263,8 +262,8 @@ tde_encrypt_rel_key(TDEPrincipalKey *principal_key, RelKeyData *rel_key_data, co void pg_tde_delete_tde_files(Oid dbOid, Oid spcOid) { - char db_map_path[MAXPGPATH] = {0}; - char db_keydata_path[MAXPGPATH] = {0}; + char db_map_path[MAXPGPATH] = {0}; + char db_keydata_path[MAXPGPATH] = {0}; /* Set the file paths */ pg_tde_set_db_file_paths(dbOid, spcOid, db_map_path, db_keydata_path); @@ -286,13 +285,13 @@ pg_tde_delete_tde_files(Oid dbOid, Oid spcOid) bool pg_tde_save_principal_key(TDEPrincipalKeyInfo *principal_key_info) { - int map_fd = -1; - int keydata_fd = -1; - off_t curr_pos = 0; - bool is_new_map = false; - bool is_new_key_data = false; - char db_map_path[MAXPGPATH] = {0}; - char db_keydata_path[MAXPGPATH] = {0}; + int ap_fd = -1; + int eydata_fd = -1; + off_t urr_pos = 0; + bool s_new_map = false; + bool s_new_key_data = false; + char b_map_path[MAXPGPATH] = {0}; + char b_keydata_path[MAXPGPATH] = {0}; /* Set the file paths */ pg_tde_set_db_file_paths(principal_key_info->databaseId, @@ -319,7 +318,7 @@ static int pg_tde_file_header_write(char *tde_filename, int fd, TDEPrincipalKeyInfo *principal_key_info, off_t *bytes_written) { TDEFileHeader fheader; - size_t sz = sizeof(TDEPrincipalKeyInfo); + size_t sz = sizeof(TDEPrincipalKeyInfo); Assert(principal_key_info); @@ -363,13 +362,13 @@ pg_tde_file_header_write(char *tde_filename, int fd, TDEPrincipalKeyInfo *princi static int32 pg_tde_write_map_entry(const RelFileLocator *rlocator, uint32 entry_type, char *db_map_path, TDEPrincipalKeyInfo *principal_key_info) { - int map_fd = -1; - int32 key_index = 0; + int map_fd = -1; + int32 key_index = 0; TDEMapEntry map_entry; - bool is_new_file; - off_t curr_pos = 0; - off_t prev_pos = 0; - bool found = false; + bool is_new_file; + off_t curr_pos = 0; + off_t prev_pos = 0; + bool found = false; /* Open and validate file for basic correctness. */ map_fd = pg_tde_open_file(db_map_path, principal_key_info, false, O_RDWR | O_CREAT, &is_new_file, &curr_pos); @@ -419,7 +418,7 @@ pg_tde_write_map_entry(const RelFileLocator *rlocator, uint32 entry_type, char * static off_t pg_tde_write_one_map_entry(int fd, const RelFileLocator *rlocator, uint32 flags, int32 key_index, TDEMapEntry *map_entry, off_t *offset) { - int bytes_written = 0; + int bytes_written = 0; Assert(map_entry); @@ -434,7 +433,7 @@ pg_tde_write_one_map_entry(int fd, const RelFileLocator *rlocator, uint32 flags, /* Add the entry to the file */ if (bytes_written != MAP_ENTRY_SIZE) { - char db_map_path[MAXPGPATH] = {0}; + char db_map_path[MAXPGPATH] = {0}; pg_tde_set_db_file_paths(rlocator->dbOid, rlocator->spcOid, db_map_path, NULL); ereport(FATAL, @@ -444,7 +443,7 @@ pg_tde_write_one_map_entry(int fd, const RelFileLocator *rlocator, uint32 flags, } if (pg_fsync(fd) != 0) { - char db_map_path[MAXPGPATH] = {0}; + char db_map_path[MAXPGPATH] = {0}; pg_tde_set_db_file_paths(rlocator->dbOid, rlocator->spcOid, db_map_path, NULL); ereport(data_sync_elevel(ERROR), @@ -467,9 +466,9 @@ pg_tde_write_one_map_entry(int fd, const RelFileLocator *rlocator, uint32 flags, static void pg_tde_write_keydata(char *db_keydata_path, TDEPrincipalKeyInfo *principal_key_info, int32 key_index, RelKeyData *enc_rel_key_data) { - File fd = -1; - bool is_new_file; - off_t curr_pos = 0; + File fd = -1; + bool is_new_file; + off_t curr_pos = 0; /* Open and validate file for basic correctness. */ fd = pg_tde_open_file(db_keydata_path, principal_key_info, false, O_RDWR | O_CREAT, &is_new_file, &curr_pos); @@ -487,7 +486,7 @@ pg_tde_write_keydata(char *db_keydata_path, TDEPrincipalKeyInfo *principal_key_i static void pg_tde_write_one_keydata(int fd, int32 key_index, RelKeyData *enc_rel_key_data) { - off_t curr_pos; + off_t curr_pos; Assert(fd != -1); @@ -520,9 +519,9 @@ pg_tde_write_one_keydata(int fd, int32 key_index, RelKeyData *enc_rel_key_data) void pg_tde_write_key_map_entry(const RelFileLocator *rlocator, uint32 entry_type, RelKeyData *enc_rel_key_data, TDEPrincipalKeyInfo *principal_key_info) { - int32 key_index = 0; - char db_map_path[MAXPGPATH] = {0}; - char db_keydata_path[MAXPGPATH] = {0}; + int32 key_index = 0; + char db_map_path[MAXPGPATH] = {0}; + char db_keydata_path[MAXPGPATH] = {0}; Assert(rlocator); @@ -543,11 +542,11 @@ pg_tde_write_key_map_entry(const RelFileLocator *rlocator, uint32 entry_type, Re void pg_tde_delete_key_map_entry(const RelFileLocator *rlocator, uint32 key_type) { - int32 key_index = 0; - off_t offset = 0; - LWLock *lock_files = tde_lwlock_enc_keys(); - char db_map_path[MAXPGPATH] = {0}; - char db_keydata_path[MAXPGPATH] = {0}; + int32 key_index = 0; + off_t offset = 0; + LWLock *lock_files = tde_lwlock_enc_keys(); + char db_map_path[MAXPGPATH] = {0}; + char db_keydata_path[MAXPGPATH] = {0}; Assert(rlocator); @@ -589,10 +588,10 @@ pg_tde_delete_key_map_entry(const RelFileLocator *rlocator, uint32 key_type) void pg_tde_free_key_map_entry(const RelFileLocator *rlocator, uint32 key_type, off_t offset) { - int32 key_index = 0; - LWLock *lock_files = tde_lwlock_enc_keys(); - char db_map_path[MAXPGPATH] = {0}; - char db_keydata_path[MAXPGPATH] = {0}; + int32 key_index = 0; + LWLock *lock_files = tde_lwlock_enc_keys(); + char db_map_path[MAXPGPATH] = {0}; + char db_keydata_path[MAXPGPATH] = {0}; Assert(rlocator); @@ -795,16 +794,16 @@ bool pg_tde_write_map_keydata_files(off_t map_size, char *m_file_data, off_t keydata_size, char *k_file_data) { TDEFileHeader *fheader; - char m_path_new[MAXPGPATH]; - char k_path_new[MAXPGPATH]; - int m_fd_new; - int k_fd_new; - bool is_new_file; - off_t curr_pos = 0; - off_t read_pos_tmp = 0; - char db_map_path[MAXPGPATH] = {0}; - char db_keydata_path[MAXPGPATH] = {0}; - bool is_err = false; + char m_path_new[MAXPGPATH]; + char k_path_new[MAXPGPATH]; + int m_fd_new; + int k_fd_new; + bool is_new_file; + off_t curr_pos = 0; + off_t read_pos_tmp = 0; + char db_map_path[MAXPGPATH] = {0}; + char db_keydata_path[MAXPGPATH] = {0}; + bool is_err = false; /* Let's get the header. Buff should start with the map file header. */ fheader = (TDEFileHeader *) m_file_data; @@ -875,14 +874,14 @@ pg_tde_write_map_keydata_files(off_t map_size, char *m_file_data, off_t keydata_ RelKeyData * pg_tde_get_key_from_file(const RelFileLocator *rlocator, uint32 key_type) { - int32 key_index = 0; + int32 key_index = 0; TDEPrincipalKey *principal_key; RelKeyData *rel_key_data; RelKeyData *enc_rel_key_data; - off_t offset = 0; - LWLock *lock_pk = tde_lwlock_enc_keys(); - char db_map_path[MAXPGPATH] = {0}; - char db_keydata_path[MAXPGPATH] = {0}; + off_t offset = 0; + LWLock *lock_pk = tde_lwlock_enc_keys(); + char db_map_path[MAXPGPATH] = {0}; + char db_keydata_path[MAXPGPATH] = {0}; Assert(rlocator); @@ -951,13 +950,13 @@ pg_tde_set_db_file_paths(Oid dbOid, Oid spcOid, char *map_path, char *keydata_pa static int32 pg_tde_process_map_entry(const RelFileLocator *rlocator, uint32 key_type, char *db_map_path, off_t *offset, bool should_delete) { - File map_fd = -1; - int32 key_index = 0; + File map_fd = -1; + int32 key_index = 0; TDEMapEntry map_entry; - bool is_new_file; - bool found = false; - off_t prev_pos = 0; - off_t curr_pos = 0; + bool is_new_file; + bool found = false; + off_t prev_pos = 0; + off_t curr_pos = 0; Assert(offset); @@ -1036,10 +1035,10 @@ pg_tde_process_map_entry(const RelFileLocator *rlocator, uint32 key_type, char * static RelKeyData * pg_tde_read_keydata(char *db_keydata_path, int32 key_index, TDEPrincipalKey *principal_key) { - int fd = -1; + int fd = -1; RelKeyData *enc_rel_key_data; - off_t read_pos = 0; - bool is_new_file; + off_t read_pos = 0; + bool is_new_file; /* Open and validate file for basic correctness. */ fd = pg_tde_open_file(db_keydata_path, &principal_key->keyInfo, false, O_RDONLY, &is_new_file, &read_pos); @@ -1061,7 +1060,7 @@ RelKeyData * tde_decrypt_rel_key(TDEPrincipalKey *principal_key, RelKeyData *enc_rel_key_data, const RelFileLocator *rlocator) { RelKeyData *rel_key_data = NULL; - size_t key_bytes; + size_t key_bytes; AesDecryptKey(principal_key, rlocator, &rel_key_data, enc_rel_key_data, &key_bytes); @@ -1185,8 +1184,8 @@ pg_tde_file_header_read(char *tde_filename, int fd, TDEFileHeader *fheader, bool static bool pg_tde_read_one_map_entry(File map_file, const RelFileLocator *rlocator, int flags, TDEMapEntry *map_entry, off_t *offset) { - bool found; - off_t bytes_read = 0; + bool found; + off_t bytes_read = 0; Assert(map_entry); Assert(offset); @@ -1218,7 +1217,7 @@ static RelKeyData * pg_tde_read_one_keydata(int keydata_fd, int32 key_index, TDEPrincipalKey *principal_key) { RelKeyData *enc_rel_key_data; - off_t read_pos = 0; + off_t read_pos = 0; /* Allocate and fill in the structure */ enc_rel_key_data = (RelKeyData *) palloc(sizeof(RelKeyData)); @@ -1266,12 +1265,12 @@ pg_tde_read_one_keydata(int keydata_fd, int32 key_index, TDEPrincipalKey *princi TDEPrincipalKeyInfo * pg_tde_get_principal_key_info(Oid dbOid, Oid spcOid) { - int fd = -1; + int fd = -1; TDEFileHeader fheader; TDEPrincipalKeyInfo *principal_key_info = NULL; - bool is_new_file = false; - off_t bytes_read = 0; - char db_map_path[MAXPGPATH] = {0}; + bool is_new_file = false; + off_t bytes_read = 0; + char db_map_path[MAXPGPATH] = {0}; /* Set the file paths */ pg_tde_set_db_file_paths(dbOid, spcOid, db_map_path, NULL); @@ -1424,8 +1423,8 @@ pg_tde_put_key_into_cache(RelFileNumber rel_num, uint32 key_type, RelKeyData *ke if (tde_rel_key_cache->len + 1 > (tde_rel_key_cache->cap * sizeof(RelKeyCacheRec)) / sizeof(RelKeyCacheRec)) { - size_t size; - size_t old_size; + size_t size; + size_t old_size; RelKeyCacheRec *chachePage; size = TYPEALIGN(pageSize, (tde_rel_key_cache->cap + 1) * sizeof(RelKeyCacheRec)); diff --git a/src/access/pg_tde_xlog_encrypt.c b/src/access/pg_tde_xlog_encrypt.c index e109d382..84f820b9 100644 --- a/src/access/pg_tde_xlog_encrypt.c +++ b/src/access/pg_tde_xlog_encrypt.c @@ -120,14 +120,14 @@ TDEXLogShmemInit(void) static ssize_t TDEXLogWriteEncryptedPages(int fd, const void *buf, size_t count, off_t offset) { - char iv_prefix[16] = {0,}; - size_t data_size = 0; + char iv_prefix[16] = {0,}; + size_t data_size = 0; XLogPageHeader curr_page_hdr = &EncryptCurrentPageHrd; XLogPageHeader enc_buf_page; RelKeyData *key = GetTdeGlobaleRelationKey(GLOBAL_SPACE_RLOCATOR(XLOG_TDE_OID)); - off_t enc_off; - size_t page_size = XLOG_BLCKSZ - offset % XLOG_BLCKSZ; - uint32 iv_ctr = 0; + off_t enc_off; + size_t page_size = XLOG_BLCKSZ - offset % XLOG_BLCKSZ; + uint32 iv_ctr = 0; #ifdef TDE_XLOG_DEBUG elog(DEBUG1, "write encrypted WAL, pages amount: %d, size: %lu offset: %ld", count / (Size) XLOG_BLCKSZ, count, offset); @@ -226,14 +226,14 @@ tdeheap_xlog_seg_write(int fd, const void *buf, size_t count, off_t offset) ssize_t tdeheap_xlog_seg_read(int fd, void *buf, size_t count, off_t offset) { - ssize_t readsz; - char iv_prefix[16] = {0,}; - size_t data_size = 0; + ssize_t readsz; + char iv_prefix[16] = {0,}; + size_t data_size = 0; XLogPageHeader curr_page_hdr = &DecryptCurrentPageHrd; RelKeyData *key = GetTdeGlobaleRelationKey(GLOBAL_SPACE_RLOCATOR(XLOG_TDE_OID)); - size_t page_size = XLOG_BLCKSZ - offset % XLOG_BLCKSZ; - off_t dec_off; - uint32 iv_ctr = 0; + size_t page_size = XLOG_BLCKSZ - offset % XLOG_BLCKSZ; + off_t dec_off; + uint32 iv_ctr = 0; #ifdef TDE_XLOG_DEBUG elog(DEBUG1, "read from a WAL segment, pages amount: %d, size: %lu offset: %ld", count / (Size) XLOG_BLCKSZ, count, offset); diff --git a/src/catalog/tde_keyring.c b/src/catalog/tde_keyring.c index 954a079a..5558a3aa 100644 --- a/src/catalog/tde_keyring.c +++ b/src/catalog/tde_keyring.c @@ -199,11 +199,11 @@ static uint32 write_key_provider_info(KeyringProvideRecord *provider, Oid database_id, Oid tablespace_id, off_t position, bool redo, bool recovery) { - off_t bytes_written = 0; - off_t curr_pos = 0; - int fd; - int max_provider_id = 0; - char kp_info_path[MAXPGPATH] = {0}; + off_t bytes_written = 0; + off_t curr_pos = 0; + int fd; + int max_provider_id = 0; + char kp_info_path[MAXPGPATH] = {0}; KeyringProvideRecord existing_provider; Assert(provider != NULL); @@ -325,13 +325,13 @@ cleanup_key_provider_info(Oid databaseId, Oid tablespaceId) Datum pg_tde_add_key_provider_internal(PG_FUNCTION_ARGS) { - char *provider_type = text_to_cstring(PG_GETARG_TEXT_PP(0)); - char *provider_name = text_to_cstring(PG_GETARG_TEXT_PP(1)); - char *options = text_to_cstring(PG_GETARG_TEXT_PP(2)); - bool is_global = PG_GETARG_BOOL(3); + char *provider_type = text_to_cstring(PG_GETARG_TEXT_PP(0)); + char *provider_name = text_to_cstring(PG_GETARG_TEXT_PP(1)); + char *options = text_to_cstring(PG_GETARG_TEXT_PP(2)); + bool is_global = PG_GETARG_BOOL(3); KeyringProvideRecord provider; - Oid dbOid = MyDatabaseId; - Oid spcOid = MyDatabaseTableSpace; + Oid dbOid = MyDatabaseId; + Oid spcOid = MyDatabaseTableSpace; if (is_global) { @@ -350,10 +350,10 @@ pg_tde_add_key_provider_internal(PG_FUNCTION_ARGS) Datum pg_tde_list_all_key_providers(PG_FUNCTION_ARGS) { - List *all_providers = GetAllKeyringProviders(MyDatabaseId, MyDatabaseTableSpace); - ListCell *lc; + List *all_providers = GetAllKeyringProviders(MyDatabaseId, MyDatabaseTableSpace); + ListCell *lc; Tuplestorestate *tupstore; - TupleDesc tupdesc; + TupleDesc tupdesc; MemoryContext per_query_ctx; MemoryContext oldcontext; ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; @@ -385,10 +385,10 @@ pg_tde_list_all_key_providers(PG_FUNCTION_ARGS) foreach(lc, all_providers) { - Datum values[PG_TDE_LIST_PROVIDERS_COLS] = {0}; - bool nulls[PG_TDE_LIST_PROVIDERS_COLS] = {0}; + Datum values[PG_TDE_LIST_PROVIDERS_COLS] = {0}; + bool nulls[PG_TDE_LIST_PROVIDERS_COLS] = {0}; GenericKeyring *keyring = (GenericKeyring *) lfirst(lc); - int i = 0; + int i = 0; values[i++] = Int32GetDatum(keyring->key_id); values[i++] = CStringGetTextDatum(keyring->provider_name); @@ -460,12 +460,12 @@ static SimplePtrList * #endif scan_key_provider_file(ProviderScanType scanType, void *scanKey, Oid dbOid, Oid spcOid) { - off_t curr_pos = 0; - int fd; - char kp_info_path[MAXPGPATH] = {0}; + off_t curr_pos = 0; + int fd; + char kp_info_path[MAXPGPATH] = {0}; KeyringProvideRecord provider; #ifndef FRONTEND - List *providers_list = NIL; + List *providers_list = NIL; #else SimplePtrList *providers_list = NULL; #endif diff --git a/src/catalog/tde_keyring_parse_opts.c b/src/catalog/tde_keyring_parse_opts.c index b9b4238c..22564f42 100644 --- a/src/catalog/tde_keyring_parse_opts.c +++ b/src/catalog/tde_keyring_parse_opts.c @@ -100,7 +100,7 @@ typedef struct JsonKeyringState * Caller's options to be set from JSON values. Expected either * `VaultV2Keyring` or `FileKeyring` */ - void *provider_opts; + void *provider_opts; /* * A field hierarchy of the current branch, field[level] is the current @@ -109,17 +109,17 @@ typedef struct JsonKeyringState */ JsonKeyringField field[MAX_JSON_DEPTH]; JsonKeringSemState state; - int level; + int level; /* * The rest of the scalar fields might be in the JSON document but has no * direct value for the caller. Although we need them for the values * extraction or state tracking. */ - char *kring_type; - char *field_type; - char *extern_url; - char *extern_path; + char *kring_type; + char *field_type; + char *extern_url; + char *extern_path; } JsonKeyringState; static JsonParseErrorType json_kring_scalar(void *state, char *token, JsonTokenType tokentype); diff --git a/src/catalog/tde_principal_key.c b/src/catalog/tde_principal_key.c index f51879f2..78d431bd 100644 --- a/src/catalog/tde_principal_key.c +++ b/src/catalog/tde_principal_key.c @@ -43,9 +43,9 @@ typedef struct TdePrincipalKeySharedState { LWLockPadded *Locks; - int hashTrancheId; + int hashTrancheId; dshash_table_handle hashHandle; - void *rawDsaArea; /* DSA area pointer */ + void *rawDsaArea; /* DSA area pointer */ } TdePrincipalKeySharedState; @@ -314,7 +314,7 @@ RotatePrincipalKey(TDEPrincipalKey *current_key, const char *new_key_name, const TDEPrincipalKey new_principal_key; const keyInfo *keyInfo = NULL; GenericKeyring *keyring; - bool is_rotated; + bool is_rotated; MemoryContext keyRotateCtx; MemoryContext oldCtx; @@ -403,8 +403,8 @@ keyInfo * load_latest_versioned_key_name(TDEPrincipalKeyInfo *principal_key_info, GenericKeyring *keyring, bool ensure_new_key) { KeyringReturnCodes kr_ret; - keyInfo *keyInfo = NULL; - int base_version = principal_key_info->keyId.version; + keyInfo *keyInfo = NULL; + int base_version = principal_key_info->keyId.version; Assert(principal_key_info != NULL); Assert(keyring != NULL); @@ -477,9 +477,9 @@ GetPrincipalKeyProviderId(void) { TDEPrincipalKey *principalKey = NULL; TDEPrincipalKeyInfo *principalKeyInfo = NULL; - Oid keyringId = InvalidOid; - Oid dbOid = MyDatabaseId; - LWLock *lock_files = tde_lwlock_enc_keys(); + Oid keyringId = InvalidOid; + Oid dbOid = MyDatabaseId; + LWLock *lock_files = tde_lwlock_enc_keys(); LWLockAcquire(lock_files, LW_SHARED); @@ -548,8 +548,8 @@ static void push_principal_key_to_cache(TDEPrincipalKey *principalKey) { TDEPrincipalKey *cacheEntry = NULL; - Oid databaseId = principalKey->keyInfo.databaseId; - bool found = false; + Oid databaseId = principalKey->keyInfo.databaseId; + bool found = false; cacheEntry = dshash_find_or_insert(get_principal_key_Hash(), &databaseId, &found); @@ -622,10 +622,10 @@ Datum pg_tde_set_principal_key(PG_FUNCTION_ARGS); Datum pg_tde_set_principal_key(PG_FUNCTION_ARGS) { - char *principal_key_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); - char *provider_name = text_to_cstring(PG_GETARG_TEXT_PP(1)); - bool ensure_new_key = PG_GETARG_BOOL(2); - bool ret; + char *principal_key_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); + char *provider_name = text_to_cstring(PG_GETARG_TEXT_PP(1)); + bool ensure_new_key = PG_GETARG_BOOL(2); + bool ret; ereport(LOG, (errmsg("Setting principal key [%s : %s] for the database", principal_key_name, provider_name))); ret = SetPrincipalKey(principal_key_name, provider_name, ensure_new_key); @@ -639,14 +639,14 @@ PG_FUNCTION_INFO_V1(pg_tde_rotate_principal_key_internal); Datum pg_tde_rotate_principal_key_internal(PG_FUNCTION_ARGS) { - char *new_principal_key_name = NULL; - char *new_provider_name = NULL; - bool ensure_new_key; - bool is_global; - bool ret; + char *new_principal_key_name = NULL; + char *new_provider_name = NULL; + bool ensure_new_key; + bool is_global; + bool ret; TDEPrincipalKey *current_key; - Oid dbOid = MyDatabaseId; - Oid spcOid = MyDatabaseTableSpace; + Oid dbOid = MyDatabaseId; + Oid spcOid = MyDatabaseTableSpace; if (!PG_ARGISNULL(0)) new_principal_key_name = text_to_cstring(PG_GETARG_TEXT_PP(0)); @@ -680,9 +680,9 @@ PG_FUNCTION_INFO_V1(pg_tde_principal_key_info_internal); Datum pg_tde_principal_key_info_internal(PG_FUNCTION_ARGS) { - Oid dbOid = MyDatabaseId; - Oid spcOid = MyDatabaseTableSpace; - bool is_global = PG_GETARG_BOOL(0); + Oid dbOid = MyDatabaseId; + Oid spcOid = MyDatabaseTableSpace; + bool is_global = PG_GETARG_BOOL(0); if (is_global) { @@ -696,11 +696,11 @@ pg_tde_principal_key_info_internal(PG_FUNCTION_ARGS) static Datum pg_tde_get_key_info(PG_FUNCTION_ARGS, Oid dbOid, Oid spcOid) { - TupleDesc tupdesc; - Datum values[6]; - bool isnull[6]; - HeapTuple tuple; - Datum result; + TupleDesc tupdesc; + Datum values[6]; + bool isnull[6]; + HeapTuple tuple; + Datum result; TDEPrincipalKey *principal_key; TimestampTz ts; GenericKeyring *keyring; diff --git a/src/common/pg_tde_shmem.c b/src/common/pg_tde_shmem.c index be1262a1..a1ebcad1 100644 --- a/src/common/pg_tde_shmem.c +++ b/src/common/pg_tde_shmem.c @@ -17,24 +17,24 @@ typedef struct TdeSharedState { - LWLock *principalKeyLock; - int principalKeyHashTrancheId; - void *rawDsaArea; /* DSA area pointer to store cache hashes */ + LWLock *principalKeyLock; + int principalKeyHashTrancheId; + void *rawDsaArea; /* DSA area pointer to store cache hashes */ dshash_table_handle principalKeyHashHandle; } TdeSharedState; typedef struct TDELocalState { TdeSharedState *sharedTdeState; - dsa_area **dsa; /* local dsa area for backend attached to the + dsa_area **dsa; /* local dsa area for backend attached to the * dsa area created by postmaster at startup. */ dshash_table *principalKeySharedHash; } TDELocalState; static void tde_shmem_shutdown(int code, Datum arg); -List *registeredShmemRequests = NIL; -bool shmemInited = false; +List *registeredShmemRequests = NIL; +bool shmemInited = false; void RegisterShmemRequest(const TDEShmemSetupRoutine *routine) @@ -46,8 +46,8 @@ RegisterShmemRequest(const TDEShmemSetupRoutine *routine) Size TdeRequiredSharedMemorySize(void) { - Size sz = 0; - ListCell *lc; + Size sz = 0; + ListCell *lc; foreach(lc, registeredShmemRequests) { @@ -81,11 +81,11 @@ TdeShmemInit(void) if (!found) { /* First time through ... */ - char *p = (char *) tdeState; - dsa_area *dsa; - ListCell *lc; - Size used_size = 0; - Size dsa_area_size; + char *p = (char *) tdeState; + dsa_area *dsa; + ListCell *lc; + Size used_size = 0; + Size dsa_area_size; p += MAXALIGN(sizeof(TdeSharedState)); used_size += MAXALIGN(sizeof(TdeSharedState)); diff --git a/src/common/pg_tde_utils.c b/src/common/pg_tde_utils.c index 3a9ada07..ce99a972 100644 --- a/src/common/pg_tde_utils.c +++ b/src/common/pg_tde_utils.c @@ -38,11 +38,11 @@ get_tde_table_am_oid(void) List * get_all_tde_tables(void) { - Relation pg_class; + Relation pg_class; SysScanDesc scan; - HeapTuple tuple; - List *tde_tables = NIL; - Oid am_oid = get_tde_basic_table_am_oid(); + HeapTuple tuple; + List *tde_tables = NIL; + Oid am_oid = get_tde_basic_table_am_oid(); /* Open the pg_class table */ pg_class = table_open(RelationRelationId, AccessShareLock); @@ -76,8 +76,8 @@ get_all_tde_tables(void) int get_tde_tables_count(void) { - List *tde_tables = get_all_tde_tables(); - int count = list_length(tde_tables); + List *tde_tables = get_all_tde_tables(); + int count = list_length(tde_tables); list_free(tde_tables); return count; diff --git a/src/encryption/enc_aes.c b/src/encryption/enc_aes.c index e72acad0..50081dbf 100644 --- a/src/encryption/enc_aes.c +++ b/src/encryption/enc_aes.c @@ -46,12 +46,12 @@ const EVP_CIPHER *cipher = NULL; const EVP_CIPHER *cipher2 = NULL; -int cipher_block_size = 0; +int cipher_block_size = 0; void AesInit(void) { - static int initialized = 0; + static int initialized = 0; if (!initialized) { @@ -106,7 +106,7 @@ AesRunCtr(EVP_CIPHER_CTX **ctxPtr, int enc, const unsigned char *key, const unsi static void AesRunCbc(int enc, const unsigned char *key, const unsigned char *iv, const unsigned char *in, int in_len, unsigned char *out, int *out_len) { - int out_len_final = 0; + int out_len_final = 0; EVP_CIPHER_CTX *ctx = NULL; ctx = EVP_CIPHER_CTX_new(); diff --git a/src/encryption/enc_tde.c b/src/encryption/enc_tde.c index e9739fb5..e3f96676 100644 --- a/src/encryption/enc_tde.c +++ b/src/encryption/enc_tde.c @@ -182,10 +182,10 @@ pg_tde_crypt(const char *iv_prefix, uint32 start_offset, const char *data, uint3 void pg_tde_crypt_tuple(HeapTuple tuple, HeapTuple out_tuple, RelKeyData *key, const char *context) { - char iv_prefix[16] = {0}; - uint32 data_len = tuple->t_len - tuple->t_data->t_hoff; - char *tup_data = (char *) tuple->t_data + tuple->t_data->t_hoff; - char *out_data = (char *) out_tuple->t_data + out_tuple->t_data->t_hoff; + char iv_prefix[16] = {0}; + uint32 data_len = tuple->t_len - tuple->t_data->t_hoff; + char *tup_data = (char *) tuple->t_data + tuple->t_data->t_hoff; + char *out_data = (char *) out_tuple->t_data + out_tuple->t_data->t_hoff; SetIVPrefix(&tuple->t_self, iv_prefix); @@ -214,12 +214,12 @@ PGTdePageAddItemExtended(RelFileLocator rel, int flags) { OffsetNumber off = PageAddItemExtended(page, item, size, offsetNumber, flags); - PageHeader phdr = (PageHeader) page; + PageHeader phdr = (PageHeader) page; unsigned long header_size = ((HeapTupleHeader) item)->t_hoff; - char iv_prefix[16] = {0,}; - char *toAddr = ((char *) phdr) + phdr->pd_upper + header_size; - char *data = item + header_size; - uint32 data_len = size - header_size; + char iv_prefix[16] = {0,}; + char *toAddr = ((char *) phdr) + phdr->pd_upper + header_size; + char *data = item + header_size; + uint32 data_len = size - header_size; /* ctid stored in item is incorrect (not set) at this point */ ItemPointerData ip; diff --git a/src/include/access/pg_tde_ddl.h b/src/include/access/pg_tde_ddl.h index f69b8dfc..ed58588f 100644 --- a/src/include/access/pg_tde_ddl.h +++ b/src/include/access/pg_tde_ddl.h @@ -14,4 +14,4 @@ extern void SetupTdeDDLHooks(void); -#endif /* PG_TDE_DDL_H */ +#endif /* PG_TDE_DDL_H */ diff --git a/src/include/access/pg_tde_slot.h b/src/include/access/pg_tde_slot.h index efbddf46..9a8ed823 100644 --- a/src/include/access/pg_tde_slot.h +++ b/src/include/access/pg_tde_slot.h @@ -29,8 +29,8 @@ typedef struct TDEBufferHeapTupleTableSlot * reference to that buffer. (TTS_FLAG_SHOULDFREE should not be set in * such a case, since presumably base.tuple is pointing into the buffer.) */ - Buffer buffer; /* tuple's buffer, or InvalidBuffer */ - char decrypted_buffer[BLCKSZ]; + Buffer buffer; /* tuple's buffer, or InvalidBuffer */ + char decrypted_buffer[BLCKSZ]; RelKeyData *cached_relation_key; } TDEBufferHeapTupleTableSlot; @@ -47,4 +47,4 @@ extern TupleTableSlot *PGTdeExecStoreBufferHeapTuple(Relation rel, TupleTableSlot *slot, Buffer buffer); -#endif /* PG_TDE_SLOT_H */ +#endif /* PG_TDE_SLOT_H */ diff --git a/src/include/access/pg_tde_tdemap.h b/src/include/access/pg_tde_tdemap.h index 74094d41..4cdd6dc8 100644 --- a/src/include/access/pg_tde_tdemap.h +++ b/src/include/access/pg_tde_tdemap.h @@ -18,14 +18,13 @@ #define MAP_ENTRY_EMPTY 0x00 #define TDE_KEY_TYPE_HEAP_BASIC 0x01 #define TDE_KEY_TYPE_SMGR 0x02 -#define TDE_KEY_TYPE_GLOBAL 0x04 +#define TDE_KEY_TYPE_GLOBAL 0x04 #define MAP_ENTRY_VALID (TDE_KEY_TYPE_HEAP_BASIC | TDE_KEY_TYPE_SMGR | TDE_KEY_TYPE_GLOBAL) typedef struct InternalKey { - uint8 key[INTERNAL_KEY_LEN]; - void *ctx; /* TODO: shouldn't be here / written to the - * disk */ + uint8 key[INTERNAL_KEY_LEN]; + void *ctx; /* TODO: shouldn't be here / written to the disk */ } InternalKey; typedef struct RelKeyData @@ -38,8 +37,8 @@ typedef struct RelKeyData typedef struct XLogRelKey { RelFileLocator rlocator; - uint32 entry_type; - RelKeyData relKey; + uint32 entry_type; + RelKeyData relKey; } XLogRelKey; extern RelKeyData *pg_tde_create_smgr_key(const RelFileLocator *newrlocator); @@ -72,4 +71,4 @@ const char *tde_sprint_key(InternalKey *k); extern RelKeyData *pg_tde_put_key_into_cache(RelFileNumber rel_num, uint32 key_type, RelKeyData *key); -#endif /* PG_TDE_MAP_H */ +#endif /* PG_TDE_MAP_H */ diff --git a/src/include/access/pg_tde_xlog.h b/src/include/access/pg_tde_xlog.h index 1ea24cf7..b548453b 100644 --- a/src/include/access/pg_tde_xlog.h +++ b/src/include/access/pg_tde_xlog.h @@ -37,5 +37,5 @@ static const RmgrData tdeheap_rmgr = { .rm_identify = tdeheap_rmgr_identify }; -#endif /* !FRONTEND */ -#endif /* PG_TDE_XLOG_H */ +#endif /* !FRONTEND */ +#endif /* PG_TDE_XLOG_H */ diff --git a/src/include/access/pg_tde_xlog_encrypt.h b/src/include/access/pg_tde_xlog_encrypt.h index 8ffc1539..4812a9cd 100644 --- a/src/include/access/pg_tde_xlog_encrypt.h +++ b/src/include/access/pg_tde_xlog_encrypt.h @@ -30,6 +30,6 @@ static const XLogSmgr tde_xlog_smgr = { extern void TDEXLogSmgrInit(void); extern void XLogInitGUC(void); -#endif /* PERCONA_EXT */ +#endif /* PERCONA_EXT */ -#endif /* PG_TDE_XLOGENCRYPT_H */ +#endif /* PG_TDE_XLOGENCRYPT_H */ diff --git a/src/include/access/pg_tde_xlog_encrypt_fe.h b/src/include/access/pg_tde_xlog_encrypt_fe.h index ea129086..eca9bc8d 100644 --- a/src/include/access/pg_tde_xlog_encrypt_fe.h +++ b/src/include/access/pg_tde_xlog_encrypt_fe.h @@ -24,6 +24,6 @@ TDEInitGlobalKeys(kring_dir); \ TDEXLogSmgrInit() -#endif /* PERCONA_EXT */ +#endif /* PERCONA_EXT */ -#endif /* PG_TDE_XLOGENCRYPT_FE_H */ +#endif /* PG_TDE_XLOGENCRYPT_FE_H */ diff --git a/src/include/catalog/tde_global_space.h b/src/include/catalog/tde_global_space.h index 42aaa0de..78474960 100644 --- a/src/include/catalog/tde_global_space.h +++ b/src/include/catalog/tde_global_space.h @@ -34,4 +34,4 @@ extern void TDEInitGlobalKeys(const char *dir); -#endif /* TDE_GLOBAL_CATALOG_H */ +#endif /* TDE_GLOBAL_CATALOG_H */ diff --git a/src/include/catalog/tde_keyring.h b/src/include/catalog/tde_keyring.h index c394aafd..4dcde79b 100644 --- a/src/include/catalog/tde_keyring.h +++ b/src/include/catalog/tde_keyring.h @@ -25,7 +25,7 @@ #define MAX_PROVIDER_NAME_LEN 128 /* pg_tde_key_provider's provider_name * size */ #define MAX_VAULT_V2_KEY_LEN 128 /* From hashi corp docs */ -#define MAX_KEYRING_OPTION_LEN 1024 +#define MAX_KEYRING_OPTION_LEN 1024 typedef enum ProviderType { UNKNOWN_KEY_PROVIDER, @@ -37,40 +37,39 @@ typedef enum ProviderType typedef struct GenericKeyring { ProviderType type; /* Must be the first field */ - Oid key_id; - char provider_name[MAX_PROVIDER_NAME_LEN]; - char options[MAX_KEYRING_OPTION_LEN]; /* User provided options - * string */ + Oid key_id; + char provider_name[MAX_PROVIDER_NAME_LEN]; + char options[MAX_KEYRING_OPTION_LEN]; /* User provided options string */ } GenericKeyring; typedef struct FileKeyring { GenericKeyring keyring; /* Must be the first field */ - char file_name[MAXPGPATH]; + char file_name[MAXPGPATH]; } FileKeyring; typedef struct VaultV2Keyring { GenericKeyring keyring; /* Must be the first field */ - char vault_token[MAX_VAULT_V2_KEY_LEN]; - char vault_url[MAXPGPATH]; - char vault_ca_path[MAXPGPATH]; - char vault_mount_path[MAXPGPATH]; + char vault_token[MAX_VAULT_V2_KEY_LEN]; + char vault_url[MAXPGPATH]; + char vault_ca_path[MAXPGPATH]; + char vault_mount_path[MAXPGPATH]; } VaultV2Keyring; /* This record goes into key provider info file */ typedef struct KeyringProvideRecord { - int provider_id; - char provider_name[MAX_PROVIDER_NAME_LEN]; - char options[MAX_KEYRING_OPTION_LEN]; + int provider_id; + char provider_name[MAX_PROVIDER_NAME_LEN]; + char options[MAX_KEYRING_OPTION_LEN]; ProviderType provider_type; } KeyringProvideRecord; typedef struct KeyringProviderXLRecord { - Oid database_id; - Oid tablespace_id; - off_t offset_in_file; + Oid database_id; + Oid tablespace_id; + off_t offset_in_file; KeyringProvideRecord provider; } KeyringProviderXLRecord; @@ -85,4 +84,4 @@ extern uint32 redo_key_provider_info(KeyringProviderXLRecord *xlrec); extern bool ParseKeyringJSONOptions(ProviderType provider_type, void *out_opts, char *in_buf, int buf_len); -#endif /* TDE_KEYRING_H */ +#endif /* TDE_KEYRING_H */ diff --git a/src/include/catalog/tde_principal_key.h b/src/include/catalog/tde_principal_key.h index ca297ce0..26dc1a11 100644 --- a/src/include/catalog/tde_principal_key.h +++ b/src/include/catalog/tde_principal_key.h @@ -19,23 +19,23 @@ #include "storage/lwlock.h" #endif -#define DEFAULT_PRINCIPAL_KEY_VERSION 1 +#define DEFAULT_PRINCIPAL_KEY_VERSION 1 #define PRINCIPAL_KEY_NAME_LEN TDE_KEY_NAME_LEN #define MAX_PRINCIPAL_KEY_VERSION_NUM 100000 typedef struct TDEPrincipalKeyId { - uint32 version; - char name[PRINCIPAL_KEY_NAME_LEN]; - char versioned_name[PRINCIPAL_KEY_NAME_LEN + 4]; + uint32 version; + char name[PRINCIPAL_KEY_NAME_LEN]; + char versioned_name[PRINCIPAL_KEY_NAME_LEN + 4]; } TDEPrincipalKeyId; typedef struct TDEPrincipalKeyInfo { - Oid databaseId; - Oid tablespaceId; - Oid userId; - Oid keyringId; + Oid databaseId; + Oid tablespaceId; + Oid userId; + Oid keyringId; struct timeval creationTime; TDEPrincipalKeyId keyId; } TDEPrincipalKeyInfo; @@ -44,15 +44,15 @@ typedef struct TDEPrincipalKey { TDEPrincipalKeyInfo keyInfo; unsigned char keyData[MAX_KEY_DATA_SIZE]; - uint32 keyLength; + uint32 keyLength; } TDEPrincipalKey; typedef struct XLogPrincipalKeyRotate { - Oid databaseId; - off_t map_size; - off_t keydata_size; - char buff[FLEXIBLE_ARRAY_MEMBER]; + Oid databaseId; + off_t map_size; + off_t keydata_size; + char buff[FLEXIBLE_ARRAY_MEMBER]; } XLogPrincipalKeyRotate; #define SizeoOfXLogPrincipalKeyRotate offsetof(XLogPrincipalKeyRotate, buff) @@ -74,4 +74,4 @@ extern bool SetPrincipalKey(const char *key_name, const char *provider_name, boo extern bool RotatePrincipalKey(TDEPrincipalKey *current_key, const char *new_key_name, const char *new_provider_name, bool ensure_new_key); extern bool xl_tde_perform_rotate_key(XLogPrincipalKeyRotate *xlrec); -#endif /* PG_TDE_PRINCIPAL_KEY_H */ +#endif /* PG_TDE_PRINCIPAL_KEY_H */ diff --git a/src/include/common/pg_tde_shmem.h b/src/include/common/pg_tde_shmem.h index 680e03f2..db555bf2 100644 --- a/src/include/common/pg_tde_shmem.h +++ b/src/include/common/pg_tde_shmem.h @@ -23,7 +23,7 @@ typedef enum /* Must be the last entry in the enum */ TDE_LWLOCK_COUNT -} TDELockTypes; +} TDELockTypes; typedef struct TDEShmemSetupRoutine { @@ -34,24 +34,24 @@ typedef struct TDEShmemSetupRoutine * area acquired. The argument to the function is the start of the shared * memory address that can be used to store the shared data structures. */ - Size (*init_shared_state) (void *raw_dsa_area); + Size (*init_shared_state) (void *raw_dsa_area); /* * shmem_startup gets called at the time of postmaster shutdown */ - void (*shmem_kill) (int code, Datum arg); + void (*shmem_kill) (int code, Datum arg); /* * The callback must return the size of the shared memory acquired. */ - Size (*required_shared_mem_size) (void); + Size (*required_shared_mem_size) (void); /* * Gets called after all shared memory structures are initialized and here * you can create shared memory hash tables or any other shared objects * that needs to live in DSA area. */ - void (*init_dsa_area_objects) (dsa_area *dsa, void *raw_dsa_area); + void (*init_dsa_area_objects) (dsa_area *dsa, void *raw_dsa_area); } TDEShmemSetupRoutine; /* Interface to register the shared memory requests */ @@ -60,4 +60,4 @@ extern void TdeShmemInit(void); extern Size TdeRequiredSharedMemorySize(void); extern int TdeRequiredLocksCount(void); -#endif /* PG_TDE_SHMEM_H */ +#endif /* PG_TDE_SHMEM_H */ diff --git a/src/include/common/pg_tde_utils.h b/src/include/common/pg_tde_utils.h index c41bf408..b49c409e 100644 --- a/src/include/common/pg_tde_utils.h +++ b/src/include/common/pg_tde_utils.h @@ -17,8 +17,8 @@ extern Oid get_tde_basic_table_am_oid(void); extern Oid get_tde_table_am_oid(void); extern List *get_all_tde_tables(void); extern int get_tde_tables_count(void); -#endif /* !FRONTEND */ +#endif /* !FRONTEND */ extern char *pg_tde_get_tde_file_dir(Oid dbOid, Oid spcOid); extern void pg_tde_set_globalspace_dir(const char *dir); -#endif /* PG_TDE_UTILS_H */ +#endif /* PG_TDE_UTILS_H */ diff --git a/src/include/encryption/enc_aes.h b/src/include/encryption/enc_aes.h index 882e3dba..5d3901e3 100644 --- a/src/include/encryption/enc_aes.h +++ b/src/include/encryption/enc_aes.h @@ -16,11 +16,11 @@ #define NUM_AES_BLOCKS_IN_BATCH 200 #define DATA_BYTES_PER_AES_BATCH (NUM_AES_BLOCKS_IN_BATCH * AES_BLOCK_SIZE) -void AesInit(void); +void AesInit(void); extern void Aes128EncryptedZeroBlocks(void *ctxPtr, const unsigned char *key, const char *iv_prefix, uint64_t blockNumber1, uint64_t blockNumber2, unsigned char *out); /* Only used for testing */ extern void AesEncrypt(const unsigned char *key, const unsigned char *iv, const unsigned char *in, int in_len, unsigned char *out, int *out_len); extern void AesDecrypt(const unsigned char *key, const unsigned char *iv, const unsigned char *in, int in_len, unsigned char *out, int *out_len); -#endif /* ENC_AES_H */ +#endif /* ENC_AES_H */ diff --git a/src/include/encryption/enc_tde.h b/src/include/encryption/enc_tde.h index e25c9ae1..f7732ed6 100644 --- a/src/include/encryption/enc_tde.h +++ b/src/include/encryption/enc_tde.h @@ -55,4 +55,4 @@ extern OffsetNumber extern void AesEncryptKey(const TDEPrincipalKey *principal_key, const RelFileLocator *rlocator, RelKeyData *rel_key_data, RelKeyData **p_enc_rel_key_data, size_t *enc_key_bytes); extern void AesDecryptKey(const TDEPrincipalKey *principal_key, const RelFileLocator *rlocator, RelKeyData **p_rel_key_data, RelKeyData *enc_rel_key_data, size_t *key_bytes); -#endif /* ENC_TDE_H */ +#endif /* ENC_TDE_H */ diff --git a/src/include/keyring/keyring_api.h b/src/include/keyring/keyring_api.h index 5c67a579..147302de 100644 --- a/src/include/keyring/keyring_api.h +++ b/src/include/keyring/keyring_api.h @@ -17,19 +17,19 @@ typedef struct keyName { - char name[TDE_KEY_NAME_LEN]; + char name[TDE_KEY_NAME_LEN]; } keyName; typedef struct keyData { unsigned char data[MAX_KEY_DATA_SIZE]; - unsigned len; + unsigned len; } keyData; typedef struct keyInfo { - keyName name; - keyData data; + keyName name; + keyData data; } keyInfo; typedef enum KeyringReturnCodes @@ -42,7 +42,7 @@ typedef enum KeyringReturnCodes KEYRING_CODE_INVALID_RESPONSE, KEYRING_CODE_INVALID_KEY_SIZE, KEYRING_CODE_DATA_CORRUPTED -} KeyringReturnCodes; +} KeyringReturnCodes; typedef struct TDEKeyringRoutine { @@ -57,4 +57,4 @@ extern keyInfo *KeyringGetKey(GenericKeyring *keyring, const char *key_name, boo extern keyInfo *KeyringGenerateNewKeyAndStore(GenericKeyring *keyring, const char *key_name, unsigned key_len, bool throw_error); extern keyInfo *KeyringGenerateNewKey(const char *key_name, unsigned key_len); -#endif /* KEYRING_API_H */ +#endif /* KEYRING_API_H */ diff --git a/src/include/keyring/keyring_curl.h b/src/include/keyring/keyring_curl.h index 8f1a282d..6eef5ada 100644 --- a/src/include/keyring/keyring_curl.h +++ b/src/include/keyring/keyring_curl.h @@ -21,12 +21,12 @@ typedef struct CurlString { - char *ptr; - size_t len; + char *ptr; + size_t len; } CurlString; extern CURL * keyringCurl; -bool curlSetupSession(const char *url, const char *caFile, CurlString *outStr); +bool curlSetupSession(const char *url, const char *caFile, CurlString *outStr); #endif /* //KEYRING_CURL_H */ diff --git a/src/include/keyring/keyring_file.h b/src/include/keyring/keyring_file.h index 804f71d5..9945dbd7 100644 --- a/src/include/keyring/keyring_file.h +++ b/src/include/keyring/keyring_file.h @@ -14,4 +14,4 @@ extern bool InstallFileKeyring(void); -#endif /* KEYRING_FILE_H */ +#endif /* KEYRING_FILE_H */ diff --git a/src/include/keyring/keyring_vault.h b/src/include/keyring/keyring_vault.h index 16d4eeac..c86a963c 100644 --- a/src/include/keyring/keyring_vault.h +++ b/src/include/keyring/keyring_vault.h @@ -14,4 +14,4 @@ extern bool InstallVaultV2Keyring(void); -#endif /* // KEYRING_FILE_H */ +#endif /* KEYRING_FILE_H */ diff --git a/src/include/pg_tde.h b/src/include/pg_tde.h index 069f14ab..c9c38727 100644 --- a/src/include/pg_tde.h +++ b/src/include/pg_tde.h @@ -10,8 +10,8 @@ typedef struct XLogExtensionInstall { - Oid database_id; - Oid tablespace_id; + Oid database_id; + Oid tablespace_id; } XLogExtensionInstall; typedef void (*pg_tde_on_ext_install_callback) (int tde_tbl_count, XLogExtensionInstall *ext_info, bool redo, void *arg); @@ -19,4 +19,4 @@ typedef void (*pg_tde_on_ext_install_callback) (int tde_tbl_count, XLogExtension extern void on_ext_install(pg_tde_on_ext_install_callback function, void *arg); extern void extension_install_redo(XLogExtensionInstall *xlrec); -#endif /* PG_TDE_H */ +#endif /* PG_TDE_H */ diff --git a/src/include/pg_tde_defines.h b/src/include/pg_tde_defines.h index ba4925bc..529b2449 100644 --- a/src/include/pg_tde_defines.h +++ b/src/include/pg_tde_defines.h @@ -47,4 +47,4 @@ /* ---------- */ -#endif /* PG_TDE_DEFINES_H */ +#endif /* PG_TDE_DEFINES_H */ diff --git a/src/include/pg_tde_defs.h b/src/include/pg_tde_defs.h index 1402c6a8..6d33312c 100644 --- a/src/include/pg_tde_defs.h +++ b/src/include/pg_tde_defs.h @@ -13,4 +13,4 @@ extern const char *pg_tde_package_string(void); extern const char *pg_tde_package_name(void); extern const char *pg_tde_package_version(void); -#endif /* PG_TDE_DEFS_H */ +#endif /* PG_TDE_DEFS_H */ diff --git a/src/include/pg_tde_event_capture.h b/src/include/pg_tde_event_capture.h index a0ff3e0c..e3c15ff4 100644 --- a/src/include/pg_tde_event_capture.h +++ b/src/include/pg_tde_event_capture.h @@ -15,16 +15,16 @@ typedef enum TdeCreateEventType TDE_UNKNOWN_CREATE_EVENT, TDE_TABLE_CREATE_EVENT, TDE_INDEX_CREATE_EVENT -} TdeCreateEventType; +} TdeCreateEventType; typedef struct TdeCreateEvent { TdeCreateEventType eventType; /* DDL statement type */ - bool encryptMode; /* true when the table uses encryption */ - Oid baseTableOid; /* Oid of table on which index is being + bool encryptMode; /* true when the table uses encryption */ + Oid baseTableOid; /* Oid of table on which index is being * created on. For create table statement this * contains InvalidOid */ - RangeVar *relation; /* Reference to the parsed relation from + RangeVar *relation; /* Reference to the parsed relation from * create statement */ } TdeCreateEvent; diff --git a/src/include/smgr/pg_tde_smgr.h b/src/include/smgr/pg_tde_smgr.h index d56c9ac0..72070adf 100644 --- a/src/include/smgr/pg_tde_smgr.h +++ b/src/include/smgr/pg_tde_smgr.h @@ -12,4 +12,4 @@ extern void RegisterStorageMgr(void); -#endif /* PG_TDE_SMGR_H */ +#endif /* PG_TDE_SMGR_H */ diff --git a/src/include/transam/pg_tde_xact_handler.h b/src/include/transam/pg_tde_xact_handler.h index 4cde60f7..524f8acb 100644 --- a/src/include/transam/pg_tde_xact_handler.h +++ b/src/include/transam/pg_tde_xact_handler.h @@ -18,4 +18,4 @@ extern void pg_tde_subxact_callback(SubXactEvent event, SubTransactionId mySubid extern void RegisterEntryForDeletion(const RelFileLocator *rlocator, off_t map_entry_offset, bool atCommit); -#endif /* PG_TDE_XACT_HANDLER_H */ +#endif /* PG_TDE_XACT_HANDLER_H */ diff --git a/src/keyring/keyring_api.c b/src/keyring/keyring_api.c index 05465eba..c0b8bde5 100644 --- a/src/keyring/keyring_api.c +++ b/src/keyring/keyring_api.c @@ -23,7 +23,7 @@ typedef struct KeyProviders } KeyProviders; #ifndef FRONTEND -List *registeredKeyProviders = NIL; +List *registeredKeyProviders = NIL; #else SimplePtrList registeredKeyProviders = {NULL, NULL}; #endif @@ -33,7 +33,7 @@ static KeyProviders *find_key_provider(ProviderType type); static KeyProviders * find_key_provider(ProviderType type) { - ListCell *lc; + ListCell *lc; foreach(lc, registeredKeyProviders) { @@ -132,7 +132,7 @@ KeyringStoreKey(GenericKeyring *keyring, keyInfo *key, bool throw_error) keyInfo * KeyringGenerateNewKey(const char *key_name, unsigned key_len) { - keyInfo *key; + keyInfo *key; Assert(key_len <= 32); key = palloc(sizeof(keyInfo)); @@ -149,7 +149,7 @@ KeyringGenerateNewKey(const char *key_name, unsigned key_len) keyInfo * KeyringGenerateNewKeyAndStore(GenericKeyring *keyring, const char *key_name, unsigned key_len, bool throw_error) { - keyInfo *key = KeyringGenerateNewKey(key_name, key_len); + keyInfo *key = KeyringGenerateNewKey(key_name, key_len); if (key == NULL) { diff --git a/src/keyring/keyring_curl.c b/src/keyring/keyring_curl.c index 5c2a58e7..69312171 100644 --- a/src/keyring/keyring_curl.c +++ b/src/keyring/keyring_curl.c @@ -14,13 +14,13 @@ #include "keyring/keyring_curl.h" #include "pg_tde_defines.h" -CURL *keyringCurl = NULL; +CURL *keyringCurl = NULL; static size_t write_func(void *ptr, size_t size, size_t nmemb, struct CurlString *s) { - size_t new_len = s->len + size * nmemb; + size_t new_len = s->len + size * nmemb; s->ptr = repalloc(s->ptr, new_len + 1); if (s->ptr == NULL) diff --git a/src/keyring/keyring_file.c b/src/keyring/keyring_file.c index 0163a4c4..714a20b4 100644 --- a/src/keyring/keyring_file.c +++ b/src/keyring/keyring_file.c @@ -44,11 +44,11 @@ InstallFileKeyring(void) static keyInfo * get_key_by_name(GenericKeyring *keyring, const char *key_name, bool throw_error, KeyringReturnCodes * return_code) { - keyInfo *key = NULL; - int fd = -1; + keyInfo *key = NULL; + int fd = -1; FileKeyring *file_keyring = (FileKeyring *) keyring; - off_t bytes_read = 0; - off_t curr_pos = 0; + off_t bytes_read = 0; + off_t curr_pos = 0; *return_code = KEYRING_CODE_SUCCESS; @@ -99,9 +99,9 @@ get_key_by_name(GenericKeyring *keyring, const char *key_name, bool throw_error, static KeyringReturnCodes set_key_by_name(GenericKeyring *keyring, keyInfo *key, bool throw_error) { - off_t bytes_written = 0; - off_t curr_pos = 0; - int fd; + off_t bytes_written = 0; + off_t curr_pos = 0; + int fd; FileKeyring *file_keyring = (FileKeyring *) keyring; keyInfo *existing_key; KeyringReturnCodes return_code = KEYRING_CODE_SUCCESS; diff --git a/src/keyring/keyring_vault.c b/src/keyring/keyring_vault.c index 792f296f..75f8f2d8 100644 --- a/src/keyring/keyring_vault.c +++ b/src/keyring/keyring_vault.c @@ -38,14 +38,14 @@ typedef enum JRESP_EXPECT_TOP_DATA, JRESP_EXPECT_DATA, JRESP_EXPECT_KEY -} JsonVaultRespSemState; +} JsonVaultRespSemState; typedef enum { JRESP_F_UNUSED, JRESP_F_KEY -} JsonVaultRespField; +} JsonVaultRespField; typedef struct JsonVaultRespState { @@ -88,7 +88,7 @@ curl_setup_token(VaultV2Keyring *keyring) { if (curlList == NULL) { - char tokenHeader[256]; + char tokenHeader[256]; strcpy(tokenHeader, "X-Vault-Token:"); strcat(tokenHeader, keyring->vault_token); @@ -170,12 +170,12 @@ static KeyringReturnCodes set_key_by_name(GenericKeyring *keyring, keyInfo *key, bool throw_error) { VaultV2Keyring *vault_keyring = (VaultV2Keyring *) keyring; - char url[VAULT_URL_MAX_LEN]; - CurlString str; - long httpCode = 0; - char jsonText[512]; + char url[VAULT_URL_MAX_LEN]; + CurlString str; + long httpCode = 0; + char jsonText[512]; char keyData[64]; - int keyLen = 0; + int keyLen = 0; Assert(key != NULL); @@ -185,7 +185,7 @@ set_key_by_name(GenericKeyring *keyring, keyInfo *key, bool throw_error) */ /* Simpler than using the limited pg json api */ keyLen = pg_b64_encode((char *) key->data.data, key->data.len, keyData, 64); - keyData[ keyLen] = 0; + keyData[keyLen] = 0; snprintf(jsonText, 512, "{\"data\":{\"key\":\"%s\"}}", keyData); @@ -220,10 +220,10 @@ static keyInfo * get_key_by_name(GenericKeyring *keyring, const char *key_name, bool throw_error, KeyringReturnCodes * return_code) { VaultV2Keyring *vault_keyring = (VaultV2Keyring *) keyring; - keyInfo *key = NULL; - char url[VAULT_URL_MAX_LEN]; - CurlString str; - long httpCode = 0; + keyInfo *key = NULL; + char url[VAULT_URL_MAX_LEN]; + CurlString str; + long httpCode = 0; JsonParseErrorType json_error; JsonLexContext *jlex = NULL; JsonVaultRespState parse; diff --git a/src/pg_tde.c b/src/pg_tde.c index 14c89f37..165ca524 100644 --- a/src/pg_tde.c +++ b/src/pg_tde.c @@ -45,15 +45,15 @@ PG_MODULE_MAGIC; struct OnExtInstall { pg_tde_on_ext_install_callback function; - void *arg; + void *arg; }; static struct OnExtInstall on_ext_install_list[MAX_ON_INSTALLS]; static int on_ext_install_index = 0; static void run_extension_install_callbacks(XLogExtensionInstall *xlrec, bool redo); -void _PG_init(void); -Datum pg_tde_extension_initialize(PG_FUNCTION_ARGS); -Datum pg_tde_version(PG_FUNCTION_ARGS); +void _PG_init(void); +Datum pg_tde_extension_initialize(PG_FUNCTION_ARGS); +Datum pg_tde_version(PG_FUNCTION_ARGS); static shmem_startup_hook_type prev_shmem_startup_hook = NULL; static shmem_request_hook_type prev_shmem_request_hook = NULL; @@ -176,8 +176,8 @@ on_ext_install(pg_tde_on_ext_install_callback function, void *arg) static void run_extension_install_callbacks(XLogExtensionInstall *xlrec, bool redo) { - int i; - int tde_table_count = 0; + int i; + int tde_table_count = 0; /* * Get the number of tde tables in this database should always be zero. diff --git a/src/smgr/pg_tde_smgr.c b/src/smgr/pg_tde_smgr.c index b840d03e..952d911a 100644 --- a/src/smgr/pg_tde_smgr.c +++ b/src/smgr/pg_tde_smgr.c @@ -19,11 +19,11 @@ typedef struct TDESMgrRelationData * for md.c; per-fork arrays of the number of open segments * (md_num_open_segs) and the segments themselves (md_seg_fds). */ - int md_num_open_segs[MAX_FORKNUM + 1]; + int md_num_open_segs[MAX_FORKNUM + 1]; struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1]; - bool encrypted_relation; - RelKeyData relKey; + bool encrypted_relation; + RelKeyData relKey; } TDESMgrRelationData; typedef TDESMgrRelationData * TDESMgrRelation; @@ -142,9 +142,9 @@ tde_mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, } else { - char *local_blocks = palloc(BLCKSZ * (1 + 1)); - char *local_blocks_aligned = (char *) TYPEALIGN(PG_IO_ALIGN_SIZE, local_blocks); - int out_len = BLCKSZ; + char *local_blocks = palloc(BLCKSZ * (1 + 1)); + char *local_blocks_aligned = (char *) TYPEALIGN(PG_IO_ALIGN_SIZE, local_blocks); + int out_len = BLCKSZ; unsigned char iv[16] = { 0, }; @@ -164,7 +164,7 @@ static void tde_mdreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks) { - int out_len = BLCKSZ; + int out_len = BLCKSZ; TDESMgrRelation tdereln = (TDESMgrRelation) reln; RelKeyData *rkd = &tdereln->relKey; diff --git a/src/transam/pg_tde_xact_handler.c b/src/transam/pg_tde_xact_handler.c index e8b5e1d5..a96e88fc 100644 --- a/src/transam/pg_tde_xact_handler.c +++ b/src/transam/pg_tde_xact_handler.c @@ -20,10 +20,10 @@ typedef struct PendingMapEntryDelete { - off_t map_entry_offset; /* map entry offset */ + off_t map_entry_offset; /* map entry offset */ RelFileLocator rlocator; /* main for use as relation OID */ - bool atCommit; /* T=delete at commit; F=delete at abort */ - int nestLevel; /* xact nesting level of request */ + bool atCommit; /* T=delete at commit; F=delete at abort */ + int nestLevel; /* xact nesting level of request */ struct PendingMapEntryDelete *next; /* linked-list link */ } PendingMapEntryDelete;