Skip to content

Commit

Permalink
Fix conflicts and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dAdAbird committed Sep 16, 2024
1 parent 5dfade8 commit 5fed59c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/access/pg_tde_tdemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ static int pg_tde_file_header_read(char *tde_filename, int fd, TDEFileHeader *fh
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 RelKeyData *pg_tde_get_key_from_cache(Oid rel_id);

#ifndef FRONTEND

Expand All @@ -132,8 +133,6 @@ static void pg_tde_write_one_keydata(int keydata_fd, int32 key_index, RelKeyData
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);

static RelKeyData *pg_tde_get_key_from_cache(Oid rel_id);

/*
* Generate an encrypted key for the relation and store it in the keymap file.
*/
Expand Down Expand Up @@ -1357,12 +1356,13 @@ pg_tde_put_key_into_cache(Oid rel_id, RelKeyData *key)
{
#ifndef FRONTEND
oldCtx = MemoryContextSwitchTo(TopMemoryContext);
#endif
tde_rel_key_cache = palloc(sizeof(RelKeyCache));

tde_rel_key_cache->data = palloc_aligned(pageSize, pageSize, MCXT_ALLOC_ZERO);
#ifndef FRONTEND
MemoryContextSwitchTo(oldCtx);
#else
tde_rel_key_cache = palloc(sizeof(RelKeyCache));
tde_rel_key_cache->data = aligned_alloc(pageSize, pageSize);
memset(tde_rel_key_cache->data, 0, pageSize);
#endif

if (mlock(tde_rel_key_cache->data, pageSize) == -1)
Expand All @@ -1387,10 +1387,11 @@ pg_tde_put_key_into_cache(Oid rel_id, RelKeyData *key)

#ifndef FRONTEND
oldCtx = MemoryContextSwitchTo(TopMemoryContext);
#endif
chachePage = palloc_aligned(pageSize, size, MCXT_ALLOC_ZERO);
#ifndef FRONTEND
MemoryContextSwitchTo(oldCtx);
#else
chachePage = aligned_alloc(pageSize, size);
memset(chachePage, 0, size);
#endif

memcpy(chachePage, tde_rel_key_cache->data, old_size);
Expand Down
2 changes: 1 addition & 1 deletion src/catalog/tde_global_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TDEInitGlobalKeys(const char *dir)
* backend. (see
* https://github.com/Percona-Lab/pg_tde/pull/214#discussion_r1648998317)
*/
pg_tde_put_key_into_map(XLOG_TDE_OID, ikey);
pg_tde_put_key_into_cache(XLOG_TDE_OID, ikey);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/smgr/pg_tde_smgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ tde_mdwritev(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
local_buffers[i] = &local_blocks_aligned[i * BLCKSZ];

BlockNumber bn = blocknum + i;
unsigned char iv[16] = {0,}
unsigned char iv[16] = {0,};
memcpy(iv+4, &bn, sizeof(BlockNumber));

AesEncrypt(rkd->internal_key.key, iv, ((char**)buffers)[i], BLCKSZ, local_buffers[i], &out_len);
Expand Down Expand Up @@ -133,7 +133,7 @@ tde_mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
char *local_blocks_aligned = (char *)TYPEALIGN(PG_IO_ALIGN_SIZE, local_blocks);
int out_len = BLCKSZ;

unsigned char iv[16] = {0,}
unsigned char iv[16] = {0,};
memcpy(iv+4, &blocknum, sizeof(BlockNumber));

AesEncrypt(rkd->internal_key.key, iv, ((char*)buffer), BLCKSZ, local_blocks_aligned, &out_len);
Expand Down Expand Up @@ -180,7 +180,7 @@ tde_mdreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
continue;

BlockNumber bn = blocknum + i;
unsigned char iv[16] = {0,}
unsigned char iv[16] = {0,};
memcpy(iv+4, &bn, sizeof(BlockNumber));

AesDecrypt(rkd->internal_key.key, iv, ((char **)buffers)[i], BLCKSZ, ((char **)buffers)[i], &out_len);
Expand Down

0 comments on commit 5fed59c

Please sign in to comment.