-refactor internal API to use new EncrptedContract struct where applicable

This commit is contained in:
Christian Grothoff 2022-06-05 00:36:19 +02:00
parent efa0ca4ec1
commit 21a1c715ee
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
5 changed files with 33 additions and 77 deletions

View File

@ -369,13 +369,9 @@ create_transaction (void *cls,
} }
/* 3) if present, persist contract */ /* 3) if present, persist contract */
in_conflict = true; in_conflict = true;
// FIXME: combine econtract arguments into one!
qs = TEH_plugin->insert_contract (TEH_plugin->cls, qs = TEH_plugin->insert_contract (TEH_plugin->cls,
pcc->purse_pub, pcc->purse_pub,
&pcc->econtract.contract_pub, &pcc->econtract,
pcc->econtract.econtract_size,
pcc->econtract.econtract,
&pcc->econtract.econtract_sig,
&in_conflict); &in_conflict);
if (qs < 0) if (qs < 0)
{ {
@ -393,14 +389,10 @@ create_transaction (void *cls,
struct TALER_EncryptedContract econtract; struct TALER_EncryptedContract econtract;
struct GNUNET_HashCode h_econtract; struct GNUNET_HashCode h_econtract;
// FIXME: combine econtract arguments into one!
qs = TEH_plugin->select_contract_by_purse ( qs = TEH_plugin->select_contract_by_purse (
TEH_plugin->cls, TEH_plugin->cls,
pcc->purse_pub, pcc->purse_pub,
&econtract.contract_pub, &econtract);
&econtract.econtract_sig,
&econtract.econtract_size,
&econtract.econtract);
if (qs <= 0) if (qs <= 0)
{ {
if (GNUNET_DB_STATUS_SOFT_ERROR == qs) if (GNUNET_DB_STATUS_SOFT_ERROR == qs)

View File

@ -411,13 +411,9 @@ purse_transaction (void *cls,
{ {
bool in_conflict = true; bool in_conflict = true;
// FIXME: combine econtract args!
qs = TEH_plugin->insert_contract (TEH_plugin->cls, qs = TEH_plugin->insert_contract (TEH_plugin->cls,
&rpc->purse_pub, &rpc->purse_pub,
&rpc->econtract.contract_pub, &rpc->econtract,
rpc->econtract.econtract_size,
rpc->econtract.econtract,
&rpc->econtract.econtract_sig,
&in_conflict); &in_conflict);
if (qs < 0) if (qs < 0)
{ {
@ -435,15 +431,10 @@ purse_transaction (void *cls,
struct TALER_EncryptedContract econtract; struct TALER_EncryptedContract econtract;
struct GNUNET_HashCode h_econtract; struct GNUNET_HashCode h_econtract;
/* FIXME: change API to only pass econtract
instead of all members! */
qs = TEH_plugin->select_contract_by_purse ( qs = TEH_plugin->select_contract_by_purse (
TEH_plugin->cls, TEH_plugin->cls,
&rpc->purse_pub, &rpc->purse_pub,
&econtract.contract_pub, &econtract);
&econtract.econtract_sig,
&econtract.econtract_size,
&econtract.econtract);
if (qs <= 0) if (qs <= 0)
{ {
if (GNUNET_DB_STATUS_SOFT_ERROR == qs) if (GNUNET_DB_STATUS_SOFT_ERROR == qs)

View File

@ -13959,21 +13959,14 @@ postgres_select_contract (void *cls,
* *
* @param cls the @e cls of this struct with the plugin-specific state * @param cls the @e cls of this struct with the plugin-specific state
* @param purse_pub key to lookup the contract by * @param purse_pub key to lookup the contract by
* @param[out] pub_ckey set to the ephemeral DH used to encrypt the contract
* @param[out] econtract_sig set to the signature over the encrypted contract
* @param[out] econtract_size set to the number of bytes in @a econtract
* @param[out] econtract set to the encrypted contract on success, to be freed by the caller * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
* @return transaction status code * @return transaction status code
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
postgres_select_contract_by_purse (void *cls, postgres_select_contract_by_purse (
const struct void *cls,
TALER_PurseContractPublicKeyP *purse_pub, const struct TALER_PurseContractPublicKeyP *purse_pub,
struct TALER_ContractDiffiePublicP *pub_ckey, struct TALER_EncryptedContract *econtract)
struct TALER_PurseContractSignatureP *
econtract_sig,
size_t *econtract_size,
void **econtract)
{ {
struct PostgresClosure *pg = cls; struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -13982,12 +13975,12 @@ postgres_select_contract_by_purse (void *cls,
}; };
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("pub_ckey", GNUNET_PQ_result_spec_auto_from_type ("pub_ckey",
pub_ckey), &econtract->contract_pub),
GNUNET_PQ_result_spec_auto_from_type ("contract_sig", GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
econtract_sig), &econtract->econtract_sig),
GNUNET_PQ_result_spec_variable_size ("e_contract", GNUNET_PQ_result_spec_variable_size ("e_contract",
econtract, &econtract->econtract,
econtract_size), &econtract->econtract_size),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
@ -14004,10 +13997,7 @@ postgres_select_contract_by_purse (void *cls,
* *
* @param cls the @e cls of this struct with the plugin-specific state * @param cls the @e cls of this struct with the plugin-specific state
* @param purse_pub the purse the contract is associated with (must exist) * @param purse_pub the purse the contract is associated with (must exist)
* @param pub_ckey ephemeral key for DH used to encrypt the contract
* @param econtract_size number of bytes in @a econtract
* @param econtract the encrypted contract * @param econtract the encrypted contract
* @param[out] econtract_sig set to the signature over the encrypted contract
* @param[out] in_conflict set to true if @a econtract * @param[out] in_conflict set to true if @a econtract
* conflicts with an existing contract; * conflicts with an existing contract;
* in this case, the return value will be * in this case, the return value will be
@ -14018,20 +14008,17 @@ static enum GNUNET_DB_QueryStatus
postgres_insert_contract ( postgres_insert_contract (
void *cls, void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub, const struct TALER_PurseContractPublicKeyP *purse_pub,
const struct TALER_ContractDiffiePublicP *pub_ckey, const struct TALER_EncryptedContract *econtract,
size_t econtract_size,
const void *econtract,
const struct TALER_PurseContractSignatureP *econtract_sig,
bool *in_conflict) bool *in_conflict)
{ {
struct PostgresClosure *pg = cls; struct PostgresClosure *pg = cls;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (purse_pub), GNUNET_PQ_query_param_auto_from_type (purse_pub),
GNUNET_PQ_query_param_auto_from_type (pub_ckey), GNUNET_PQ_query_param_auto_from_type (&econtract->contract_pub),
GNUNET_PQ_query_param_fixed_size (econtract, GNUNET_PQ_query_param_fixed_size (econtract->econtract,
econtract_size), econtract->econtract_size),
GNUNET_PQ_query_param_auto_from_type (econtract_sig), GNUNET_PQ_query_param_auto_from_type (&econtract->econtract_sig),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
@ -14042,31 +14029,28 @@ postgres_insert_contract (
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs)
return qs; return qs;
{ {
struct TALER_ContractDiffiePublicP pub_ckey2; struct TALER_EncryptedContract econtract2;
struct TALER_PurseContractSignatureP esig2;
size_t econtract_size2;
void *econtract2;
qs = postgres_select_contract_by_purse (pg, qs = postgres_select_contract_by_purse (pg,
purse_pub, purse_pub,
&pub_ckey2,
&esig2,
&econtract_size2,
&econtract2); &econtract2);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{ {
GNUNET_break (0); GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
if ( (0 == GNUNET_memcmp (&pub_ckey2, if ( (0 == GNUNET_memcmp (&econtract->contract_pub,
pub_ckey)) && &econtract2.contract_pub)) &&
(econtract_size2 == econtract_size) && (econtract2.econtract_size ==
(0 == memcmp (econtract2, econtract->econtract_size) &&
econtract, (0 == memcmp (econtract2.econtract,
econtract_size)) ) econtract->econtract,
econtract->econtract_size)) )
{ {
GNUNET_free (econtract2.econtract);
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
} }
GNUNET_free (econtract2.econtract);
*in_conflict = true; *in_conflict = true;
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
} }

View File

@ -24,6 +24,7 @@
#include <jansson.h> #include <jansson.h>
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_db_lib.h> #include <gnunet/gnunet_db_lib.h>
#include "taler_json_lib.h"
#include "taler_signatures.h" #include "taler_signatures.h"
@ -4779,9 +4780,6 @@ struct TALER_EXCHANGEDB_Plugin
* Function called to persist an encrypted contract associated with a reserve. * Function called to persist an encrypted contract associated with a reserve.
* *
* @param cls the @e cls of this struct with the plugin-specific state * @param cls the @e cls of this struct with the plugin-specific state
* @param purse_pub the purse the contract is associated with (must exist)
* @param pub_ckey ephemeral key for DH used to encrypt the contract
* @param econtract_size number of bytes in @a econtract
* @param econtract the encrypted contract * @param econtract the encrypted contract
* @param[out] econtract_sig set to the signature over the encrypted contract * @param[out] econtract_sig set to the signature over the encrypted contract
* @param[out] in_conflict set to true if @a econtract * @param[out] in_conflict set to true if @a econtract
@ -4793,10 +4791,7 @@ struct TALER_EXCHANGEDB_Plugin
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
(*insert_contract)(void *cls, (*insert_contract)(void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub, const struct TALER_PurseContractPublicKeyP *purse_pub,
const struct TALER_ContractDiffiePublicP *pub_ckey, const struct TALER_EncryptedContract *econtract,
size_t econtract_size,
const void *econtract,
const struct TALER_PurseContractSignatureP *econtract_sig,
bool *in_conflict); bool *in_conflict);
@ -4820,14 +4815,12 @@ struct TALER_EXCHANGEDB_Plugin
size_t *econtract_size, size_t *econtract_size,
void **econtract); void **econtract);
/** /**
* Function called to retrieve an encrypted contract. * Function called to retrieve an encrypted contract.
* *
* @param cls the @e cls of this struct with the plugin-specific state * @param cls the @e cls of this struct with the plugin-specific state
* @param purse_pub key to lookup the contract by * @param purse_pub key to lookup the contract by
* @param[out] pub_ckey set to the ephemeral DH used to encrypt the contract
* @param[out] econtract_sig set to the signature over the encrypted contract
* @param[out] econtract_size set to the number of bytes in @a econtract
* @param[out] econtract set to the encrypted contract on success, to be freed by the caller * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
* @return transaction status code * @return transaction status code
*/ */
@ -4835,10 +4828,7 @@ struct TALER_EXCHANGEDB_Plugin
(*select_contract_by_purse)( (*select_contract_by_purse)(
void *cls, void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub, const struct TALER_PurseContractPublicKeyP *purse_pub,
struct TALER_ContractDiffiePublicP *pub_ckey, struct TALER_EncryptedContract *econtract);
struct TALER_PurseContractSignatureP *econtract_sig,
size_t *econtract_size,
void **econtract);
/** /**

View File

@ -254,7 +254,6 @@ TALER_EXCHANGE_purse_create_with_deposit (
CURL *eh; CURL *eh;
struct TALER_PurseContractSignatureP purse_sig; struct TALER_PurseContractSignatureP purse_sig;
struct TALER_EncryptedContract econtract; struct TALER_EncryptedContract econtract;
struct TALER_ContractDiffiePublicP contract_pub;
char arg_str[sizeof (pch->purse_pub) * 2 + 32]; char arg_str[sizeof (pch->purse_pub) * 2 + 32];
char *url; char *url;
uint32_t min_age = 0; uint32_t min_age = 0;
@ -402,10 +401,10 @@ TALER_EXCHANGE_purse_create_with_deposit (
&econtract.econtract, &econtract.econtract,
&econtract.econtract_size); &econtract.econtract_size);
GNUNET_CRYPTO_ecdhe_key_get_public (&contract_priv->ecdhe_priv, GNUNET_CRYPTO_ecdhe_key_get_public (&contract_priv->ecdhe_priv,
&contract_pub.ecdhe_pub); &econtract.contract_pub.ecdhe_pub);
TALER_wallet_econtract_upload_sign (econtract.econtract, TALER_wallet_econtract_upload_sign (econtract.econtract,
econtract.econtract_size, econtract.econtract_size,
&contract_pub, &econtract.contract_pub,
purse_priv, purse_priv,
&econtract.econtract_sig); &econtract.econtract_sig);
} }