diff --git a/src/access/pg_tde_tdemap.c b/src/access/pg_tde_tdemap.c index 241b980a..d95849f1 100644 --- a/src/access/pg_tde_tdemap.c +++ b/src/access/pg_tde_tdemap.c @@ -110,7 +110,7 @@ pg_tde_create_key_map_entry(const RelFileLocator *newrlocator) TDEPrincipalKey *principal_key; XLogRelKey xlrec; - principal_key = GetPrincipalKey(newrlocator->dbOid, newrlocator->spcOid, NULL); + principal_key = GetPrincipalKey(newrlocator->dbOid, newrlocator->spcOid); if (principal_key == NULL) { ereport(ERROR, @@ -163,12 +163,6 @@ RelKey *tde_rel_key_map = NULL; */ RelKeyData * GetRelationKey(RelFileLocator rel) -{ - return GetRelationKeyWithKeyring(rel, NULL); -} - -RelKeyData * -GetRelationKeyWithKeyring(RelFileLocator rel, GenericKeyring *keyring) { RelKey *curr; RelKeyData *key; @@ -182,7 +176,7 @@ GetRelationKeyWithKeyring(RelFileLocator rel, GenericKeyring *keyring) } } - key = pg_tde_get_key_from_file(&rel, keyring); + key = pg_tde_get_key_from_file(&rel); if (key != NULL) { @@ -996,7 +990,7 @@ pg_tde_free_key_map_entry(const RelFileLocator *rlocator, off_t offset) * reads the key data from the keydata file. */ RelKeyData * -pg_tde_get_key_from_file(const RelFileLocator *rlocator, GenericKeyring *keyring) +pg_tde_get_key_from_file(const RelFileLocator *rlocator) { int32 key_index = 0; TDEPrincipalKey *principal_key; @@ -1012,7 +1006,7 @@ pg_tde_get_key_from_file(const RelFileLocator *rlocator, GenericKeyring *keyring LWLockAcquire(lock_files, LW_SHARED); /* Get/generate a principal key, create the key for relation and get the encrypted key with bytes to write */ - principal_key = GetPrincipalKey(rlocator->dbOid, rlocator->spcOid, keyring); + principal_key = GetPrincipalKey(rlocator->dbOid, rlocator->spcOid); if (principal_key == NULL) { LWLockRelease(lock_files); diff --git a/src/catalog/tde_global_catalog.c b/src/catalog/tde_global_catalog.c index 65d4529c..21218d6d 100644 --- a/src/catalog/tde_global_catalog.c +++ b/src/catalog/tde_global_catalog.c @@ -101,8 +101,7 @@ TDEGlCatKeyInit(void) { RelKeyData *ikey; - ikey = pg_tde_get_key_from_file(&GLOBAL_SPACE_RLOCATOR(XLOG_TDE_OID), - NULL); + ikey = pg_tde_get_key_from_file(&GLOBAL_SPACE_RLOCATOR(XLOG_TDE_OID)); cache_internal_key(ikey, TDE_INTERNAL_XLOG_KEY); } } diff --git a/src/catalog/tde_principal_key.c b/src/catalog/tde_principal_key.c index 29141dee..0844ee36 100644 --- a/src/catalog/tde_principal_key.c +++ b/src/catalog/tde_principal_key.c @@ -206,8 +206,9 @@ save_principal_key_info(TDEPrincipalKeyInfo *principal_key_info) * throws an error. */ TDEPrincipalKey * -GetPrincipalKey(Oid dbOid, Oid spcOid, GenericKeyring *keyring) +GetPrincipalKey(Oid dbOid, Oid spcOid) { + GenericKeyring *keyring; TDEPrincipalKey *principalKey = NULL; TDEPrincipalKeyInfo *principalKeyInfo = NULL; const keyInfo *keyInfo = NULL; @@ -276,17 +277,14 @@ GetPrincipalKey(Oid dbOid, Oid spcOid, GenericKeyring *keyring) return NULL; } + keyring = GetKeyProviderByID(principalKeyInfo->keyringId, dbOid, spcOid); if (keyring == NULL) { - keyring = GetKeyProviderByID(principalKeyInfo->keyringId, dbOid, spcOid); - if (keyring == NULL) - { - LWLockRelease(lock_cache); - LWLockRelease(lock_files); + LWLockRelease(lock_cache); + LWLockRelease(lock_files); - recursion--; - return NULL; - } + recursion--; + return NULL; } keyInfo = KeyringGetKey(keyring, principalKeyInfo->keyId.versioned_name, false, &keyring_ret); @@ -743,7 +741,7 @@ pg_tde_rotate_database_key(PG_FUNCTION_ARGS) ereport(LOG, (errmsg("Rotating principal key to [%s : %s] for the database", new_principal_key_name, new_provider_name))); - current_key = GetPrincipalKey(MyDatabaseId, MyDatabaseTableSpace, NULL); + current_key = GetPrincipalKey(MyDatabaseId, MyDatabaseTableSpace); ret = RotatePrincipalKey(current_key, new_principal_key_name, new_provider_name, ensure_new_key); PG_RETURN_BOOL(ret); } @@ -767,7 +765,7 @@ pg_tde_rotate_global_key(PG_FUNCTION_ARGS) ereport(LOG, (errmsg("Rotating principal key to [%s : %s] for the database", new_principal_key_name, new_provider_name))); - current_key = GetPrincipalKey(GLOBAL_DATA_TDE_OID, GLOBALTABLESPACE_OID, NULL); + current_key = GetPrincipalKey(GLOBAL_DATA_TDE_OID, GLOBALTABLESPACE_OID); ret = RotatePrincipalKey(current_key, new_principal_key_name, new_provider_name, ensure_new_key); PG_RETURN_BOOL(ret); } @@ -820,7 +818,7 @@ pg_tde_get_key_info(PG_FUNCTION_ARGS, Oid dbOid, Oid spcOid) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function returning record called in context that cannot accept type record"))); - principal_key = GetPrincipalKey(dbOid, spcOid, NULL); + principal_key = GetPrincipalKey(dbOid, spcOid); if (principal_key == NULL) { ereport(ERROR, diff --git a/src/include/access/pg_tde_tdemap.h b/src/include/access/pg_tde_tdemap.h index e1f187ad..db629b18 100644 --- a/src/include/access/pg_tde_tdemap.h +++ b/src/include/access/pg_tde_tdemap.h @@ -53,7 +53,6 @@ extern void pg_tde_delete_key_map_entry(const RelFileLocator *rlocator); extern void pg_tde_free_key_map_entry(const RelFileLocator *rlocator, off_t offset); extern RelKeyData *GetRelationKey(RelFileLocator rel); -extern RelKeyData *GetRelationKeyWithKeyring(RelFileLocator rel, GenericKeyring *keyring); extern void pg_tde_delete_tde_files(Oid dbOid, Oid spcOid); @@ -64,7 +63,7 @@ extern bool pg_tde_write_map_keydata_files(off_t map_size, char *m_file_data, of extern RelKeyData* tde_create_rel_key(Oid rel_id, InternalKey *key, TDEPrincipalKeyInfo *principal_key_info); extern RelKeyData *tde_encrypt_rel_key(TDEPrincipalKey *principal_key, RelKeyData *rel_key_data, const RelFileLocator *rlocator); extern RelKeyData *tde_decrypt_rel_key(TDEPrincipalKey *principal_key, RelKeyData *enc_rel_key_data, const RelFileLocator *rlocator); -extern RelKeyData *pg_tde_get_key_from_file(const RelFileLocator *rlocator, GenericKeyring *keyring); +extern RelKeyData *pg_tde_get_key_from_file(const RelFileLocator *rlocator); extern void pg_tde_set_db_file_paths(const RelFileLocator *rlocator, char *map_path, char *keydata_path); diff --git a/src/include/catalog/tde_principal_key.h b/src/include/catalog/tde_principal_key.h index d1f291a0..fb0b9fd1 100644 --- a/src/include/catalog/tde_principal_key.h +++ b/src/include/catalog/tde_principal_key.h @@ -63,7 +63,7 @@ extern LWLock *tde_lwlock_mk_cache(void); extern bool save_principal_key_info(TDEPrincipalKeyInfo *principalKeyInfo); extern Oid GetPrincipalKeyProviderId(void); -extern TDEPrincipalKey* GetPrincipalKey(Oid dbOid, Oid spcOid, GenericKeyring *keyring); +extern TDEPrincipalKey* GetPrincipalKey(Oid dbOid, Oid spcOid); extern bool SetPrincipalKey(const char *key_name, const char *provider_name, bool ensure_new_key); 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); diff --git a/src/smgr/pg_tde_smgr.c b/src/smgr/pg_tde_smgr.c index 0badb8fe..a50a2d24 100644 --- a/src/smgr/pg_tde_smgr.c +++ b/src/smgr/pg_tde_smgr.c @@ -35,7 +35,7 @@ tde_smgr_get_key(SMgrRelation reln) recursion++; - if(GetPrincipalKey(reln->smgr_rlocator.locator.relNumber, reln->smgr_rlocator.locator.spcOid, NULL)==NULL) + if(GetPrincipalKey(reln->smgr_rlocator.locator.relNumber, reln->smgr_rlocator.locator.spcOid)==NULL) { recursion--; return NULL;