From 0a0d408591b8262f12258ea66d7918727e8273c6 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Mon, 20 Mar 2023 11:03:55 -0600 Subject: [PATCH] FIP-39 BD-4535 use proper encrypt key in new fio requests FIP-39 BD-4535 user proper encrypt key in new fio requests. --- contracts/fio.request.obt/fio.request.obt.cpp | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/contracts/fio.request.obt/fio.request.obt.cpp b/contracts/fio.request.obt/fio.request.obt.cpp index 67fe47ee..c1c792d5 100644 --- a/contracts/fio.request.obt/fio.request.obt.cpp +++ b/contracts/fio.request.obt/fio.request.obt.cpp @@ -26,6 +26,7 @@ namespace fioio { fiorequest_contexts_table fiorequestContextsTable; fiorequest_status_table fiorequestStatusTable; fionames_table fionames; + fionameinfo_table fionameinfo; domains_table domains; eosio_names_table clientkeys; fiofee_table fiofees; @@ -42,6 +43,7 @@ namespace fioio { fiorequestContextsTable(_self, _self.value), fiorequestStatusTable(_self, _self.value), fionames(AddressContract, AddressContract.value), + fionameinfo(AddressContract,AddressContract.value), domains(AddressContract, AddressContract.value), fiofees(FeeContract, FeeContract.value), clientkeys(AddressContract, AddressContract.value), @@ -53,6 +55,37 @@ namespace fioio { appConfig = configsSingleton.get_or_default(config()); } + + inline string get_encrypt_key(const uint64_t fionameid,const uint64_t acct) { + auto fionameinfobynameid = fionameinfo.get_index<"byfionameid"_n>(); + auto fionameinfo_iter = fionameinfobynameid.find(fionameid); + if(fionameinfo_iter == fionameinfobynameid.end()){ + auto account_iter = clientkeys.find(acct); + fio_400_assert(account_iter != clientkeys.end(), "acct", to_string(acct), + "No client key found for account in account map", + ErrorClientKeyNotFound); + return account_iter->clientkey; + + }else { + //now check for multiples. no duplicates permitted in table. + int countem = 0; + string retval = ""; + while (fionameinfo_iter != fionameinfobynameid.end()) { + if ( (fionameinfo_iter->datadesc.compare(FIO_REQUEST_CONTENT_ENCRYPTION_PUB_KEY_DATA_DESC) == 0) && (fionameinfo_iter->fionameid == fionameid)) { + retval = fionameinfo_iter->datavalue; + countem++; + }else if (fionameinfo_iter->fionameid != fionameid){ + break; + } + fionameinfo_iter++; + } + fio_400_assert(countem == 1, "datadesc", FIO_REQUEST_CONTENT_ENCRYPTION_PUB_KEY_DATA_DESC, + "handle info error -- multiple data values present for datadesc ", + ErrorInvalidValue); + return retval; + } + } + //TEMP MIGRATION ACTION // @abi action [[eosio::action]] @@ -174,11 +207,7 @@ namespace fioio { fio_400_assert(present_time <= domexp, "payer_fio_address", payer_fio_address, "FIO Domain expired", ErrorDomainExpired); - auto account_iter = clientkeys.find(payer_acct); - fio_400_assert(account_iter != clientkeys.end(), "payer_fio_address", payer_fio_address, - "No such FIO Address", - ErrorClientKeyNotFound); - string payer_key = account_iter->clientkey; // Index 0 is FIO + string payer_key = get_encrypt_key(fioname_iter->id,payer_acct); nameHash = string_to_uint128_hash(payee_fio_address.c_str()); namesbyname = fionames.get_index<"byname"_n>(); @@ -191,11 +220,7 @@ namespace fioio { fio_403_assert(payer_acct == aactor.value, ErrorSignature); uint64_t payee_acct = fioname_iter2->owner_account; - account_iter = clientkeys.find(payee_acct); - fio_400_assert(account_iter != clientkeys.end(), "payee_fio_address", payee_fio_address, - "No such FIO Address", - ErrorClientKeyNotFound); - string payee_key = account_iter->clientkey; + string payee_key = get_encrypt_key(fioname_iter2->id,payee_acct); //begin fees, bundle eligible fee logic uint128_t endpoint_hash = string_to_uint128_hash(RECORD_OBT_DATA_ENDPOINT); @@ -357,11 +382,8 @@ namespace fioio { ErrorFioNameNotReg); uint64_t payer_acct = fioname_iter2->owner_account; - auto account_iter = clientkeys.find(payer_acct); - fio_400_assert(account_iter != clientkeys.end(), "payer_fio_address", payer_fio_address, - "No such FIO Address", - ErrorClientKeyNotFound); - string payer_key = account_iter->clientkey; // Index 0 is FIO + string payer_key = get_encrypt_key(fioname_iter2->id, payer_acct); + nameHash = string_to_uint128_hash(payee_fio_address.c_str()); namesbyname = fionames.get_index<"byname"_n>(); @@ -371,11 +393,7 @@ namespace fioio { ErrorFioNameNotReg); uint64_t payee_acct = fioname_iter->owner_account; - account_iter = clientkeys.find(payee_acct); - fio_400_assert(account_iter != clientkeys.end(), "payee_fio_address", payee_fio_address, - "No such FIO Address", - ErrorClientKeyNotFound); - string payee_key = account_iter->clientkey; + string payee_key = get_encrypt_key( fioname_iter->id, payee_acct); const uint128_t domHash = string_to_uint128_hash(payeefa.fiodomain.c_str()); auto domainsbyname = domains.get_index<"byname"_n>();