diff options
Diffstat (limited to 'src/mint/mint_db.c')
-rw-r--r-- | src/mint/mint_db.c | 114 |
1 files changed, 78 insertions, 36 deletions
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c index 6ce60fc45..60ad14493 100644 --- a/src/mint/mint_db.c +++ b/src/mint/mint_db.c | |||
@@ -54,25 +54,44 @@ static char *TALER_MINT_db_connection_cfg_str; | |||
54 | if (cond) { GNUNET_break (0); goto EXITIF_exit; } \ | 54 | if (cond) { GNUNET_break (0); goto EXITIF_exit; } \ |
55 | } while (0) | 55 | } while (0) |
56 | 56 | ||
57 | |||
58 | /** | ||
59 | * Locate the response for a /withdraw request under the | ||
60 | * key of the hash of the blinded message. | ||
61 | * | ||
62 | * @param db_conn database connection to use | ||
63 | * @param h_blind hash of the blinded message | ||
64 | * @param collectable corresponding collectable coin (blind signature) | ||
65 | * if a coin is found | ||
66 | * @return #GNUNET_SYSERR on internal error | ||
67 | * #GNUNET_NO if the collectable was not found | ||
68 | * #GNUNET_YES on success | ||
69 | */ | ||
57 | int | 70 | int |
58 | TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn, | 71 | TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn, |
59 | struct TALER_RSA_BlindedSignaturePurpose *blind_ev, | 72 | const struct GNUNET_HashCode *h_blind, |
60 | struct CollectableBlindcoin *collectable) | 73 | struct CollectableBlindcoin *collectable) |
61 | { | 74 | { |
62 | PGresult *result; | 75 | PGresult *result; |
63 | struct TALER_DB_QueryParam params[] = { | 76 | struct TALER_DB_QueryParam params[] = { |
64 | TALER_DB_QUERY_PARAM_PTR (blind_ev), | 77 | TALER_DB_QUERY_PARAM_PTR (h_blind), |
65 | TALER_DB_QUERY_PARAM_END | 78 | TALER_DB_QUERY_PARAM_END |
66 | }; | 79 | }; |
67 | result = TALER_DB_exec_prepared (db_conn, "get_collectable_blindcoins", params); | 80 | char *sig_buf; |
81 | size_t sig_buf_size; | ||
82 | |||
83 | result = TALER_DB_exec_prepared (db_conn, | ||
84 | "get_collectable_blindcoins", | ||
85 | params); | ||
68 | 86 | ||
69 | if (PGRES_TUPLES_OK != PQresultStatus (result)) | 87 | if (PGRES_TUPLES_OK != PQresultStatus (result)) |
70 | { | 88 | { |
71 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Query failed: %s\n", PQresultErrorMessage (result)); | 89 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
90 | "Query failed: %s\n", | ||
91 | PQresultErrorMessage (result)); | ||
72 | PQclear (result); | 92 | PQclear (result); |
73 | return GNUNET_SYSERR; | 93 | return GNUNET_SYSERR; |
74 | } | 94 | } |
75 | |||
76 | if (0 == PQntuples (result)) | 95 | if (0 == PQntuples (result)) |
77 | { | 96 | { |
78 | PQclear (result); | 97 | PQclear (result); |
@@ -80,7 +99,7 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn, | |||
80 | } | 99 | } |
81 | 100 | ||
82 | struct TALER_DB_ResultSpec rs[] = { | 101 | struct TALER_DB_ResultSpec rs[] = { |
83 | TALER_DB_RESULT_SPEC("blind_ev_sig", &collectable->ev_sig), | 102 | TALER_DB_RESULT_SPEC_VAR("blind_sig", &sig_buf, &sig_buf_size), |
84 | TALER_DB_RESULT_SPEC("denom_pub", &collectable->denom_pub), | 103 | TALER_DB_RESULT_SPEC("denom_pub", &collectable->denom_pub), |
85 | TALER_DB_RESULT_SPEC("reserve_sig", &collectable->reserve_sig), | 104 | TALER_DB_RESULT_SPEC("reserve_sig", &collectable->reserve_sig), |
86 | TALER_DB_RESULT_SPEC("reserve_pub", &collectable->reserve_pub), | 105 | TALER_DB_RESULT_SPEC("reserve_pub", &collectable->reserve_pub), |
@@ -93,43 +112,66 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn, | |||
93 | PQclear (result); | 112 | PQclear (result); |
94 | return GNUNET_SYSERR; | 113 | return GNUNET_SYSERR; |
95 | } | 114 | } |
96 | (void) memcpy (&collectable->ev, blind_ev, sizeof (struct TALER_RSA_BlindedSignaturePurpose)); | ||
97 | PQclear (result); | 115 | PQclear (result); |
98 | return GNUNET_OK; | 116 | return GNUNET_OK; |
99 | } | 117 | } |
100 | 118 | ||
101 | 119 | ||
120 | /** | ||
121 | * Store collectable bit coin under the corresponding | ||
122 | * hash of the blinded message. | ||
123 | * | ||
124 | * @param db_conn database connection to use | ||
125 | * @param h_blind hash of the blinded message | ||
126 | * @param collectable corresponding collectable coin (blind signature) | ||
127 | * if a coin is found | ||
128 | * @return #GNUNET_SYSERR on internal error | ||
129 | * #GNUNET_NO if the collectable was not found | ||
130 | * #GNUNET_YES on success | ||
131 | */ | ||
102 | int | 132 | int |
103 | TALER_MINT_DB_insert_collectable_blindcoin (PGconn *db_conn, | 133 | TALER_MINT_DB_insert_collectable_blindcoin (PGconn *db_conn, |
134 | const struct GNUNET_HashCode *h_blind, | ||
104 | const struct CollectableBlindcoin *collectable) | 135 | const struct CollectableBlindcoin *collectable) |
105 | { | 136 | { |
106 | PGresult *result; | 137 | PGresult *result; |
107 | struct TALER_DB_QueryParam params[] = { | 138 | char *sig_buf; |
108 | TALER_DB_QUERY_PARAM_PTR (&collectable->ev), | 139 | size_t sig_buf_size; |
109 | TALER_DB_QUERY_PARAM_PTR (&collectable->ev_sig), | 140 | |
110 | TALER_DB_QUERY_PARAM_PTR (&collectable->denom_pub), | 141 | sig_buf_size = GNUNET_CRYPTO_rsa_signature_encode (collectable->sig, |
111 | TALER_DB_QUERY_PARAM_PTR (&collectable->reserve_pub), | 142 | &sig_buf); |
112 | TALER_DB_QUERY_PARAM_PTR (&collectable->reserve_sig), | 143 | { |
113 | TALER_DB_QUERY_PARAM_END | 144 | struct TALER_DB_QueryParam params[] = { |
114 | }; | 145 | TALER_DB_QUERY_PARAM_PTR (&h_blind), |
115 | result = TALER_DB_exec_prepared (db_conn, "insert_collectable_blindcoins", params); | 146 | TALER_DB_QUERY_PARAM_PTR_SIZED (sig_buf, sig_buf_size), |
147 | TALER_DB_QUERY_PARAM_PTR (&collectable->denom_pub), | ||
148 | TALER_DB_QUERY_PARAM_PTR (&collectable->reserve_pub), | ||
149 | TALER_DB_QUERY_PARAM_PTR (&collectable->reserve_sig), | ||
150 | TALER_DB_QUERY_PARAM_END | ||
151 | }; | ||
116 | 152 | ||
117 | if (PGRES_COMMAND_OK != PQresultStatus (result)) | 153 | result = TALER_DB_exec_prepared (db_conn, |
118 | { | 154 | "insert_collectable_blindcoins", |
119 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Query failed: %s\n", PQresultErrorMessage (result)); | 155 | params); |
120 | PQclear (result); | 156 | if (PGRES_COMMAND_OK != PQresultStatus (result)) |
121 | return GNUNET_SYSERR; | 157 | { |
122 | } | 158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
159 | "Query failed: %s\n", | ||
160 | PQresultErrorMessage (result)); | ||
161 | PQclear (result); | ||
162 | return GNUNET_SYSERR; | ||
163 | } | ||
123 | 164 | ||
124 | if (0 != strcmp ("1", PQcmdTuples (result))) | 165 | if (0 != strcmp ("1", PQcmdTuples (result))) |
125 | { | 166 | { |
126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Insert failed (updated '%s' tupes instead of '1')\n", | 167 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
127 | PQcmdTuples (result)); | 168 | "Insert failed (updated '%s' tupes instead of '1')\n", |
169 | PQcmdTuples (result)); | ||
170 | PQclear (result); | ||
171 | return GNUNET_SYSERR; | ||
172 | } | ||
128 | PQclear (result); | 173 | PQclear (result); |
129 | return GNUNET_SYSERR; | ||
130 | } | 174 | } |
131 | |||
132 | PQclear (result); | ||
133 | return GNUNET_OK; | 175 | return GNUNET_OK; |
134 | } | 176 | } |
135 | 177 | ||
@@ -730,7 +772,7 @@ int | |||
730 | TALER_MINT_DB_insert_refresh_order (PGconn *db_conn, | 772 | TALER_MINT_DB_insert_refresh_order (PGconn *db_conn, |
731 | uint16_t newcoin_index, | 773 | uint16_t newcoin_index, |
732 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, | 774 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, |
733 | const struct TALER_RSA_PublicKeyBinaryEncoded *denom_pub) | 775 | const struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub) |
734 | { | 776 | { |
735 | uint16_t newcoin_index_nbo = htons (newcoin_index); | 777 | uint16_t newcoin_index_nbo = htons (newcoin_index); |
736 | struct TALER_DB_QueryParam params[] = { | 778 | struct TALER_DB_QueryParam params[] = { |
@@ -1267,7 +1309,7 @@ int | |||
1267 | TALER_MINT_DB_get_refresh_order (PGconn *db_conn, | 1309 | TALER_MINT_DB_get_refresh_order (PGconn *db_conn, |
1268 | uint16_t newcoin_index, | 1310 | uint16_t newcoin_index, |
1269 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, | 1311 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, |
1270 | struct TALER_RSA_PublicKeyBinaryEncoded *denom_pub) | 1312 | struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub) |
1271 | { | 1313 | { |
1272 | uint16_t newcoin_index_nbo = htons (newcoin_index); | 1314 | uint16_t newcoin_index_nbo = htons (newcoin_index); |
1273 | 1315 | ||
@@ -1315,7 +1357,7 @@ int | |||
1315 | TALER_MINT_DB_insert_refresh_collectable (PGconn *db_conn, | 1357 | TALER_MINT_DB_insert_refresh_collectable (PGconn *db_conn, |
1316 | uint16_t newcoin_index, | 1358 | uint16_t newcoin_index, |
1317 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, | 1359 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, |
1318 | const struct TALER_RSA_Signature *ev_sig) | 1360 | const struct GNUNET_CRYPTO_rsa_Signature *ev_sig) |
1319 | { | 1361 | { |
1320 | uint16_t newcoin_index_nbo = htons (newcoin_index); | 1362 | uint16_t newcoin_index_nbo = htons (newcoin_index); |
1321 | struct TALER_DB_QueryParam params[] = { | 1363 | struct TALER_DB_QueryParam params[] = { |
@@ -1343,7 +1385,7 @@ int | |||
1343 | TALER_MINT_DB_get_refresh_collectable (PGconn *db_conn, | 1385 | TALER_MINT_DB_get_refresh_collectable (PGconn *db_conn, |
1344 | uint16_t newcoin_index, | 1386 | uint16_t newcoin_index, |
1345 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, | 1387 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, |
1346 | struct TALER_RSA_Signature *ev_sig) | 1388 | struct GNUNET_CRYPTO_rsa_Signature *ev_sig) |
1347 | { | 1389 | { |
1348 | 1390 | ||
1349 | uint16_t newcoin_index_nbo = htons (newcoin_index); | 1391 | uint16_t newcoin_index_nbo = htons (newcoin_index); |
@@ -1394,7 +1436,7 @@ TALER_MINT_DB_insert_refresh_melt (PGconn *db_conn, | |||
1394 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, | 1436 | const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub, |
1395 | uint16_t oldcoin_index, | 1437 | uint16_t oldcoin_index, |
1396 | const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub, | 1438 | const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub, |
1397 | const struct TALER_RSA_PublicKeyBinaryEncoded *denom_pub) | 1439 | const struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub) |
1398 | { | 1440 | { |
1399 | uint16_t oldcoin_index_nbo = htons (oldcoin_index); | 1441 | uint16_t oldcoin_index_nbo = htons (oldcoin_index); |
1400 | struct TALER_DB_QueryParam params[] = { | 1442 | struct TALER_DB_QueryParam params[] = { |
@@ -1499,8 +1541,8 @@ TALER_db_get_link (PGconn *db_conn, | |||
1499 | for (i = 0; i < PQntuples (result); i++) | 1541 | for (i = 0; i < PQntuples (result); i++) |
1500 | { | 1542 | { |
1501 | struct LinkDataEnc link_data_enc; | 1543 | struct LinkDataEnc link_data_enc; |
1502 | struct TALER_RSA_PublicKeyBinaryEncoded denom_pub; | 1544 | struct GNUNET_CRYPTO_rsa__PublicKey *denom_pub; |
1503 | struct TALER_RSA_Signature ev_sig; | 1545 | struct GNUNET_CRYPTO_rsa_Signature *sig; |
1504 | struct TALER_DB_ResultSpec rs[] = { | 1546 | struct TALER_DB_ResultSpec rs[] = { |
1505 | TALER_DB_RESULT_SPEC("link_vector_enc", &link_data_enc), | 1547 | TALER_DB_RESULT_SPEC("link_vector_enc", &link_data_enc), |
1506 | TALER_DB_RESULT_SPEC("denom_pub", &denom_pub), | 1548 | TALER_DB_RESULT_SPEC("denom_pub", &denom_pub), |