Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/backend/crypto/kmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct KmgrShmemData
{
CryptoKey intlKeys[KMGR_NUM_DATA_KEYS];
} KmgrShmemData;
static KmgrShmemData *KmgrShmem;
static KmgrShmemData *KmgrShmem = NULL;

/* GUC variables */
char *cluster_key_command = NULL;
Expand Down Expand Up @@ -218,7 +218,7 @@ BootStrapKmgr(void)
Size
KmgrShmemSize(void)
{
if (!FileEncryptionEnabled)
if (!tde_force_switch)
return 0;

return MAXALIGN(sizeof(KmgrShmemData));
Expand All @@ -230,7 +230,7 @@ KmgrShmemInit(void)
{
bool found;

if (!FileEncryptionEnabled)
if (!tde_force_switch)
return;

KmgrShmem = (KmgrShmemData *) ShmemInitStruct("File encryption key manager",
Expand Down
17 changes: 16 additions & 1 deletion src/common/kmgr_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,29 @@ bool
kmgr_unwrap_data_key(PgCipherCtx *ctx, unsigned char *in, int inlen, CryptoKey *out)
{
int outlen;
int out_buffer_len;
unsigned char *out_buffer;

/*
* When call EVP_DecryptUpdate,
* We need to alloc enough buffer
* More detail info see
* https://www.openssl.org/docs/man3.1/man3/EVP_DecryptUpdate.html
*/
out_buffer_len = pg_cipher_blocksize(ctx) + inlen;
out_buffer = (unsigned char *)palloc0(out_buffer_len);

Assert(ctx && in && out);

if (!pg_cipher_keyunwrap(ctx, in, inlen, (unsigned char *) out, &outlen))
if (!pg_cipher_keyunwrap(ctx, in, inlen, (unsigned char *) out_buffer, &outlen))
return false;

Assert(outlen == sizeof(CryptoKey));

memcpy(out, out_buffer, sizeof(CryptoKey));

pfree(out_buffer);

return true;
}

Expand Down