db: Implement get_collectable_blindcoin

This commit is contained in:
Sree Harsha Totakura 2015-03-07 14:03:01 +01:00
parent 19f05fd20b
commit 6714e6a9cc
3 changed files with 48 additions and 22 deletions

View File

@ -336,7 +336,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
4, NULL); 4, NULL);
PREPARE ("get_collectable_blindcoins", PREPARE ("get_collectable_blindcoins",
"SELECT " "SELECT "
"blind_ev_sig, denom_pub, reserve_sig, reserve_pub " "denom_pub, reserve_sig, reserve_pub "
"FROM collectable_blindcoins " "FROM collectable_blindcoins "
"WHERE blind_ev = $1", "WHERE blind_ev = $1",
1, NULL); 1, NULL);
@ -926,37 +926,35 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn,
const struct GNUNET_HashCode *h_blind, const struct GNUNET_HashCode *h_blind,
struct CollectableBlindcoin *collectable) struct CollectableBlindcoin *collectable)
{ {
// FIXME: check logic!
PGresult *result; PGresult *result;
struct TALER_DB_QueryParam params[] = { struct TALER_DB_QueryParam params[] = {
TALER_DB_QUERY_PARAM_PTR (h_blind), TALER_DB_QUERY_PARAM_PTR (h_blind),
TALER_DB_QUERY_PARAM_END TALER_DB_QUERY_PARAM_END
}; };
char *sig_buf; struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub;
size_t sig_buf_size; char *denom_pub_enc;
size_t denom_pub_enc_size;
int ret;
ret = GNUNET_SYSERR;
denom_pub = NULL;
denom_pub_enc = NULL;
result = TALER_DB_exec_prepared (db_conn, result = TALER_DB_exec_prepared (db_conn,
"get_collectable_blindcoins", "get_collectable_blindcoins",
params); params);
if (PGRES_TUPLES_OK != if (PGRES_TUPLES_OK != PQresultStatus (result))
PQresultStatus (result))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, QUERY_ERR (result);
"Query failed: %s\n", goto cleanup;
PQresultErrorMessage (result));
PQclear (result);
return GNUNET_SYSERR;
} }
if (0 == PQntuples (result)) if (0 == PQntuples (result))
{ {
PQclear (result); ret = GNUNET_NO;
return GNUNET_NO; goto cleanup;
} }
struct TALER_DB_ResultSpec rs[] = { struct TALER_DB_ResultSpec rs[] = {
TALER_DB_RESULT_SPEC_VAR("blind_sig", &sig_buf, &sig_buf_size), TALER_DB_RESULT_SPEC_VAR("denom_pub", &denom_pub_enc, &denom_pub_enc_size),
TALER_DB_RESULT_SPEC("denom_pub", &collectable->denom_pub),
TALER_DB_RESULT_SPEC("reserve_sig", &collectable->reserve_sig), TALER_DB_RESULT_SPEC("reserve_sig", &collectable->reserve_sig),
TALER_DB_RESULT_SPEC("reserve_pub", &collectable->reserve_pub), TALER_DB_RESULT_SPEC("reserve_pub", &collectable->reserve_pub),
TALER_DB_RESULT_SPEC_END TALER_DB_RESULT_SPEC_END
@ -965,11 +963,24 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn,
if (GNUNET_OK != TALER_DB_extract_result (result, rs, 0)) if (GNUNET_OK != TALER_DB_extract_result (result, rs, 0))
{ {
GNUNET_break (0); GNUNET_break (0);
PQclear (result); goto cleanup;
return GNUNET_SYSERR;
} }
denom_pub = GNUNET_CRYPTO_rsa_public_key_decode (denom_pub_enc,
denom_pub_enc_size);
if (NULL == denom_pub)
{
GNUNET_break (0);
goto cleanup;
}
collectable->denom_pub = denom_pub;
ret = GNUNET_YES;
cleanup:
PQclear (result); PQclear (result);
return GNUNET_OK; GNUNET_free_non_null (denom_pub_enc);
if ((GNUNET_YES != ret) && (NULL != denom_pub))
GNUNET_CRYPTO_rsa_public_key_free (denom_pub);
return ret;
} }

View File

@ -284,6 +284,7 @@ TALER_MINT_db_execute_withdraw_sign (struct MHD_Connection *connection,
res = TALER_MINT_reply_withdraw_sign_success (connection, res = TALER_MINT_reply_withdraw_sign_success (connection,
&collectable); &collectable);
GNUNET_CRYPTO_rsa_signature_free (collectable.sig); GNUNET_CRYPTO_rsa_signature_free (collectable.sig);
GNUNET_CRYPTO_rsa_public_key_free (collectable.denom_pub);
return res; return res;
} }
GNUNET_assert (GNUNET_NO == res); GNUNET_assert (GNUNET_NO == res);

View File

@ -36,6 +36,9 @@ static int result;
#define RND_BLK(ptr) \ #define RND_BLK(ptr) \
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr)) GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr))
#define ZR_BLK(ptr) \
memset (ptr, 0, sizeof (*ptr))
/** /**
* Checks if the given reserve has the given amount of balance and expiry * Checks if the given reserve has the given amount of balance and expiry
@ -115,9 +118,12 @@ run (void *cls, char *const *args, const char *cfgfile,
struct DenomKeyPair *dkp; struct DenomKeyPair *dkp;
struct GNUNET_HashCode *h_blind; struct GNUNET_HashCode *h_blind;
struct CollectableBlindcoin cbc; struct CollectableBlindcoin cbc;
struct CollectableBlindcoin cbc2;
db = NULL; db = NULL;
dkp = NULL; dkp = NULL;
ZR_BLK (&cbc2);
if (GNUNET_OK != TALER_MINT_DB_init ("postgres:///taler")) if (GNUNET_OK != TALER_MINT_DB_init ("postgres:///taler"))
{ {
result = 1; result = 1;
@ -167,9 +173,15 @@ run (void *cls, char *const *args, const char *cfgfile,
cbc.denom_pub = dkp->pub; cbc.denom_pub = dkp->pub;
cbc.sig = NULL; cbc.sig = NULL;
memcpy (&cbc.reserve_pub, &reserve_pub, sizeof (reserve_pub)); memcpy (&cbc.reserve_pub, &reserve_pub, sizeof (reserve_pub));
TALER_MINT_DB_insert_collectable_blindcoin (db, FAILIF (GNUNET_OK!= TALER_MINT_DB_insert_collectable_blindcoin (db,
&h_blind, &h_blind,
&cbc); &cbc));
FAILIF (GNUNET_YES != TALER_MINT_DB_get_collectable_blindcoin (db,
&h_blind,
&cbc2));
FAILIF (NULL == cbc2.denom_pub);
FAILIF (0 != memcmp (&cbc2.reserve_sig, &cbc.reserve_sig, sizeof (cbc2.reserve_sig)));
FAILIF (0 != memcmp (&cbc2.reserve_pub, &cbc.reserve_pub, sizeof (cbc2.reserve_pub)));
result = 0; result = 0;
drop: drop:
@ -177,6 +189,8 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_break (GNUNET_OK == TALER_MINT_DB_drop_temporary (db)); GNUNET_break (GNUNET_OK == TALER_MINT_DB_drop_temporary (db));
if (NULL != dkp) if (NULL != dkp)
destroy_denon_key_pair (dkp); destroy_denon_key_pair (dkp);
if (NULL != cbc2.denom_pub)
GNUNET_CRYPTO_rsa_public_key_free (cbc2.denom_pub);
dkp = NULL; dkp = NULL;
} }