Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIP-39 BD-4535 use proper encrypt key in new fio requests #298

Merged
merged 1 commit into from
Mar 21, 2023
Merged
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
58 changes: 38 additions & 20 deletions contracts/fio.request.obt/fio.request.obt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -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]]
Expand Down Expand Up @@ -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>();
Expand All @@ -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);
Expand Down Expand Up @@ -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>();
Expand All @@ -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>();
Expand Down