diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-28 14:55:25 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-28 14:55:25 +0100 |
commit | 49d4f24f8d031a9301676196bd6a17ea3e54cb62 (patch) | |
tree | 3bb4e1a73fff39eaf68839bba723be63f3ace6ad | |
parent | ea3fac606311d1c14362d387960a4913182b629e (diff) | |
download | exchange-49d4f24f8d031a9301676196bd6a17ea3e54cb62.tar.gz exchange-49d4f24f8d031a9301676196bd6a17ea3e54cb62.zip |
misc cleanup, moving TALER_MINT_config_load to libtalerutil
-rw-r--r-- | src/include/taler_signatures.h | 40 | ||||
-rw-r--r-- | src/include/taler_util.h | 19 | ||||
-rw-r--r-- | src/mint/mint.h | 189 | ||||
-rw-r--r-- | src/mint/mint_common.c | 30 | ||||
-rw-r--r-- | src/mint/mint_db.c | 10 | ||||
-rw-r--r-- | src/mint/taler-mint-dbinit.c | 17 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd.c | 2 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_db.c | 5 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_deposit.c | 67 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_parsing.c | 84 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_parsing.h | 18 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.c | 20 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.h | 12 | ||||
-rw-r--r-- | src/mint/taler-mint-keycheck.c | 3 | ||||
-rw-r--r-- | src/mint/taler-mint-keyup.c | 2 | ||||
-rw-r--r-- | src/mint/taler-mint-reservemod.c | 23 | ||||
-rw-r--r-- | src/mint/test_mint_deposits.c | 7 | ||||
-rw-r--r-- | src/util/util.c | 31 |
18 files changed, 400 insertions, 179 deletions
diff --git a/src/include/taler_signatures.h b/src/include/taler_signatures.h index 90fa421c3..e72c2ed61 100644 --- a/src/include/taler_signatures.h +++ b/src/include/taler_signatures.h | |||
@@ -29,6 +29,7 @@ | |||
29 | #define TALER_SIGNATURES_H | 29 | #define TALER_SIGNATURES_H |
30 | 30 | ||
31 | #include <gnunet/gnunet_util_lib.h> | 31 | #include <gnunet/gnunet_util_lib.h> |
32 | #include "taler_util.h" | ||
32 | 33 | ||
33 | /** | 34 | /** |
34 | * Purpose for signing public keys signed | 35 | * Purpose for signing public keys signed |
@@ -141,6 +142,45 @@ struct TALER_WithdrawRequest | |||
141 | }; | 142 | }; |
142 | 143 | ||
143 | 144 | ||
145 | /** | ||
146 | * Format used to generate the signature on a request to deposit | ||
147 | * a coin into the account of a merchant. | ||
148 | */ | ||
149 | struct TALER_DepositRequest | ||
150 | { | ||
151 | /** | ||
152 | * Purpose must be #TALER_SIGNATURE_DEPOSIT | ||
153 | */ | ||
154 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
155 | |||
156 | /** | ||
157 | * Hash over the contract for which this deposit is made. | ||
158 | */ | ||
159 | struct GNUNET_HashCode h_contract; | ||
160 | |||
161 | /** | ||
162 | * Hash over the wiring information of the merchant. | ||
163 | */ | ||
164 | struct GNUNET_HashCode h_wire; | ||
165 | |||
166 | /** | ||
167 | * Merchant-generated transaction ID to detect duplicate | ||
168 | * transactions. | ||
169 | */ | ||
170 | uint64_t transaction_id GNUNET_PACKED; | ||
171 | |||
172 | /** | ||
173 | * Amount to be deposited. | ||
174 | */ | ||
175 | struct TALER_AmountNBO amount; | ||
176 | |||
177 | /** | ||
178 | * The coin's public key. | ||
179 | */ | ||
180 | struct GNUNET_CRYPTO_EcdsaPublicKey coin_pub; | ||
181 | |||
182 | }; | ||
183 | |||
144 | 184 | ||
145 | /** | 185 | /** |
146 | * FIXME | 186 | * FIXME |
diff --git a/src/include/taler_util.h b/src/include/taler_util.h index 2c5faaa52..ab5ee11df 100644 --- a/src/include/taler_util.h +++ b/src/include/taler_util.h | |||
@@ -73,14 +73,27 @@ void | |||
73 | TALER_gcrypt_init (void); | 73 | TALER_gcrypt_init (void); |
74 | 74 | ||
75 | 75 | ||
76 | /** | ||
77 | * Load configuration by parsing all configuration | ||
78 | * files in the given directory. | ||
79 | * | ||
80 | * @param base_dir directory with the configuration files | ||
81 | * @return NULL on error, otherwise configuration | ||
82 | */ | ||
83 | struct GNUNET_CONFIGURATION_Handle * | ||
84 | TALER_config_load (const char *base_dir); | ||
85 | |||
86 | |||
87 | |||
76 | /* *********************** Amount management ****************** */ | 88 | /* *********************** Amount management ****************** */ |
77 | 89 | ||
78 | 90 | ||
79 | /** | 91 | /** |
80 | * Number of characters (plus 1 for 0-termination) we use to | 92 | * Number of characters (plus 1 for 0-termination) we use to |
81 | * represent currency names (i.e. EUR, USD, etc.). | 93 | * represent currency names (i.e. EUR, USD, etc.). We use |
94 | * 8 for alignment (!). | ||
82 | */ | 95 | */ |
83 | #define TALER_CURRENCY_LEN 4 | 96 | #define TALER_CURRENCY_LEN 8 |
84 | 97 | ||
85 | 98 | ||
86 | GNUNET_NETWORK_STRUCT_BEGIN | 99 | GNUNET_NETWORK_STRUCT_BEGIN |
@@ -127,7 +140,7 @@ struct TALER_Amount | |||
127 | /** | 140 | /** |
128 | * Currency string, left adjusted and padded with zeros. | 141 | * Currency string, left adjusted and padded with zeros. |
129 | */ | 142 | */ |
130 | char currency[4]; | 143 | char currency[TALER_CURRENCY_LEN]; |
131 | }; | 144 | }; |
132 | 145 | ||
133 | 146 | ||
diff --git a/src/mint/mint.h b/src/mint/mint.h index 05e966e1c..0a0e00d04 100644 --- a/src/mint/mint.h +++ b/src/mint/mint.h | |||
@@ -35,6 +35,11 @@ | |||
35 | #define DIR_SIGNKEYS "signkeys" | 35 | #define DIR_SIGNKEYS "signkeys" |
36 | #define DIR_DENOMKEYS "denomkeys" | 36 | #define DIR_DENOMKEYS "denomkeys" |
37 | 37 | ||
38 | /** | ||
39 | * For now, we just do EUR. Should become configurable | ||
40 | * in the future! | ||
41 | */ | ||
42 | #define MINT_CURRENCY "EUR" | ||
38 | 43 | ||
39 | /** | 44 | /** |
40 | * On disk format used for a mint signing key. | 45 | * On disk format used for a mint signing key. |
@@ -63,7 +68,9 @@ struct TALER_MINT_DenomKeyIssuePriv | |||
63 | 68 | ||
64 | 69 | ||
65 | /** | 70 | /** |
66 | * Public information about a coin. | 71 | * Public information about a coin (including the public key |
72 | * of the coin, the denomination key and the signature with | ||
73 | * the denomination key). | ||
67 | */ | 74 | */ |
68 | struct TALER_CoinPublicInfo | 75 | struct TALER_CoinPublicInfo |
69 | { | 76 | { |
@@ -119,6 +126,92 @@ struct CollectableBlindcoin | |||
119 | 126 | ||
120 | 127 | ||
121 | /** | 128 | /** |
129 | * Specification for a /deposit operation. | ||
130 | */ | ||
131 | struct Deposit | ||
132 | { | ||
133 | /** | ||
134 | * Information about the coin that is being deposited. | ||
135 | */ | ||
136 | struct TALER_CoinPublicInfo coin; | ||
137 | |||
138 | /** | ||
139 | * ECDSA signature affirming that the customer intends | ||
140 | * this coin to be deposited at the merchant identified | ||
141 | * by @e h_wire in relation to the contract identified | ||
142 | * by @e h_contract. | ||
143 | */ | ||
144 | struct GNUNET_CRYPTO_EcdsaSignature csig; | ||
145 | |||
146 | /** | ||
147 | * Public key of the merchant. Enables later identification | ||
148 | * of the merchant in case of a need to rollback transactions. | ||
149 | */ | ||
150 | struct GNUNET_CRYPTO_EddsaPublicKey merchant_pub; | ||
151 | |||
152 | /** | ||
153 | * Hash over the contract between merchant and customer | ||
154 | * (remains unknown to the Mint). | ||
155 | */ | ||
156 | struct GNUNET_HashCode h_contract; | ||
157 | |||
158 | /** | ||
159 | * Hash of the (canonical) representation of @e wire, used | ||
160 | * to check the signature on the request. Generated by | ||
161 | * the mint from the detailed wire data provided by the | ||
162 | * merchant. | ||
163 | */ | ||
164 | struct GNUNET_HashCode h_wire; | ||
165 | |||
166 | /** | ||
167 | * Detailed wire information for executing the transaction. | ||
168 | */ | ||
169 | const json_t *wire; | ||
170 | |||
171 | /** | ||
172 | * Merchant-generated transaction ID to detect duplicate | ||
173 | * transactions. | ||
174 | */ | ||
175 | uint64_t transaction_id; | ||
176 | |||
177 | /** | ||
178 | * Fraction of the coin's remaining value to be deposited. | ||
179 | * The coin is identified by @e coin_pub. | ||
180 | */ | ||
181 | struct TALER_Amount amount; | ||
182 | |||
183 | /** | ||
184 | * Type of the deposit (also purpose of the signature). Either | ||
185 | * #TALER_SIGNATURE_DEPOSIT or #TALER_SIGNATURE_INCREMENTAL_DEPOSIT. | ||
186 | */ | ||
187 | uint32_t purpose; // FIXME: bad type, use ENUM! | ||
188 | |||
189 | |||
190 | }; | ||
191 | |||
192 | |||
193 | |||
194 | /** | ||
195 | * FIXME | ||
196 | */ | ||
197 | struct KnownCoin | ||
198 | { | ||
199 | struct TALER_CoinPublicInfo public_info; | ||
200 | |||
201 | /** | ||
202 | * Refreshing session, only valid if | ||
203 | * is_refreshed==1. | ||
204 | */ | ||
205 | struct GNUNET_CRYPTO_EddsaPublicKey refresh_session_pub; | ||
206 | |||
207 | struct TALER_Amount expended_balance; | ||
208 | |||
209 | int is_refreshed; | ||
210 | |||
211 | }; | ||
212 | |||
213 | |||
214 | /** | ||
122 | * Global information for a refreshing session. | 215 | * Global information for a refreshing session. |
123 | */ | 216 | */ |
124 | struct RefreshSession | 217 | struct RefreshSession |
@@ -168,6 +261,9 @@ struct RefreshSession | |||
168 | }; | 261 | }; |
169 | 262 | ||
170 | 263 | ||
264 | |||
265 | |||
266 | |||
171 | /** | 267 | /** |
172 | * For each (old) coin being melted, we have a `struct | 268 | * For each (old) coin being melted, we have a `struct |
173 | * RefreshCommitLink` that allows the user to find the shared secret | 269 | * RefreshCommitLink` that allows the user to find the shared secret |
@@ -214,89 +310,8 @@ struct RefreshCommitCoin | |||
214 | }; | 310 | }; |
215 | 311 | ||
216 | 312 | ||
217 | /** | ||
218 | * FIXME | ||
219 | */ | ||
220 | struct KnownCoin | ||
221 | { | ||
222 | struct TALER_CoinPublicInfo public_info; | ||
223 | |||
224 | /** | ||
225 | * Refreshing session, only valid if | ||
226 | * is_refreshed==1. | ||
227 | */ | ||
228 | struct GNUNET_CRYPTO_EddsaPublicKey refresh_session_pub; | ||
229 | |||
230 | struct TALER_Amount expended_balance; | ||
231 | 313 | ||
232 | int is_refreshed; | ||
233 | 314 | ||
234 | }; | ||
235 | |||
236 | |||
237 | /** | ||
238 | * Specification for a /deposit operation. | ||
239 | */ | ||
240 | struct Deposit | ||
241 | { | ||
242 | /** | ||
243 | * Information about the coin that is being deposited. | ||
244 | */ | ||
245 | struct TALER_CoinPublicInfo coin; | ||
246 | |||
247 | /** | ||
248 | * EdDSA signature affirming that the customer intends | ||
249 | * this coin to be deposited at the merchant identified | ||
250 | * by @e h_wire in relation to the contract identified | ||
251 | * by @e h_contract. | ||
252 | */ | ||
253 | struct GNUNET_CRYPTO_EddsaSignature csig; | ||
254 | |||
255 | /** | ||
256 | * Public key of the merchant. Enables later identification | ||
257 | * of the merchant in case of a need to rollback transactions. | ||
258 | */ | ||
259 | struct GNUNET_CRYPTO_EddsaPublicKey merchant_pub; | ||
260 | |||
261 | /** | ||
262 | * Hash over the contract between merchant and customer | ||
263 | * (remains unknown to the Mint). | ||
264 | */ | ||
265 | struct GNUNET_HashCode h_contract; | ||
266 | |||
267 | /** | ||
268 | * Hash of the (canonical) representation of @e wire, used | ||
269 | * to check the signature on the request. Generated by | ||
270 | * the mint from the detailed wire data provided by the | ||
271 | * merchant. | ||
272 | */ | ||
273 | struct GNUNET_HashCode h_wire; | ||
274 | |||
275 | /** | ||
276 | * Detailed wire information for executing the transaction. | ||
277 | */ | ||
278 | const json_t *wire; | ||
279 | |||
280 | /** | ||
281 | * Merchant-generated transaction ID to detect duplicate | ||
282 | * transactions. | ||
283 | */ | ||
284 | uint64_t transaction_id; | ||
285 | |||
286 | /** | ||
287 | * Fraction of the coin's remaining value to be deposited. | ||
288 | * The coin is identified by @e coin_pub. | ||
289 | */ | ||
290 | struct TALER_AmountNBO amount; | ||
291 | |||
292 | /** | ||
293 | * Type of the deposit (also purpose of the signature). Either | ||
294 | * #TALER_SIGNATURE_DEPOSIT or #TALER_SIGNATURE_INCREMENTAL_DEPOSIT. | ||
295 | */ | ||
296 | uint32_t purpose; // FIXME: bad type, use ENUM! | ||
297 | |||
298 | |||
299 | }; | ||
300 | 315 | ||
301 | 316 | ||
302 | /** | 317 | /** |
@@ -412,16 +427,6 @@ TALER_MINT_read_denom_key (const char *filename, | |||
412 | struct TALER_MINT_DenomKeyIssuePriv *dki); | 427 | struct TALER_MINT_DenomKeyIssuePriv *dki); |
413 | 428 | ||
414 | 429 | ||
415 | /** | ||
416 | * Load the configuration for the mint in the given | ||
417 | * directory. | ||
418 | * | ||
419 | * @param mint_base_dir the mint's base directory | ||
420 | * @return the mint configuratin, or NULL on error | ||
421 | */ | ||
422 | struct GNUNET_CONFIGURATION_Handle * | ||
423 | TALER_MINT_config_load (const char *mint_base_dir); | ||
424 | |||
425 | 430 | ||
426 | int | 431 | int |
427 | TALER_TALER_DB_extract_amount (PGresult *result, | 432 | TALER_TALER_DB_extract_amount (PGresult *result, |
diff --git a/src/mint/mint_common.c b/src/mint/mint_common.c index bb55f30c4..f0ee09110 100644 --- a/src/mint/mint_common.c +++ b/src/mint/mint_common.c | |||
@@ -231,27 +231,11 @@ TALER_MINT_denomkeys_iterate (const char *mint_base_dir, | |||
231 | } | 231 | } |
232 | 232 | ||
233 | 233 | ||
234 | struct GNUNET_CONFIGURATION_Handle * | ||
235 | TALER_MINT_config_load (const char *mint_base_dir) | ||
236 | { | ||
237 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
238 | char *cfg_dir; | ||
239 | int res; | ||
240 | |||
241 | res = GNUNET_asprintf (&cfg_dir, "%s" DIR_SEPARATOR_STR "config", mint_base_dir); | ||
242 | GNUNET_assert (res > 0); | ||
243 | |||
244 | cfg = GNUNET_CONFIGURATION_create (); | ||
245 | res = GNUNET_CONFIGURATION_load_from (cfg, cfg_dir); | ||
246 | GNUNET_free (cfg_dir); | ||
247 | if (GNUNET_OK != res) | ||
248 | return NULL; | ||
249 | return cfg; | ||
250 | } | ||
251 | |||
252 | int | 234 | int |
253 | TALER_TALER_DB_extract_amount_nbo (PGresult *result, unsigned int row, | 235 | TALER_TALER_DB_extract_amount_nbo (PGresult *result, |
254 | int indices[3], struct TALER_AmountNBO *denom_nbo) | 236 | unsigned int row, |
237 | int indices[3], | ||
238 | struct TALER_AmountNBO *denom_nbo) | ||
255 | { | 239 | { |
256 | if ((indices[0] < 0) || (indices[1] < 0) || (indices[2] < 0)) | 240 | if ((indices[0] < 0) || (indices[1] < 0) || (indices[2] < 0)) |
257 | return GNUNET_NO; | 241 | return GNUNET_NO; |
@@ -270,8 +254,10 @@ TALER_TALER_DB_extract_amount_nbo (PGresult *result, unsigned int row, | |||
270 | 254 | ||
271 | 255 | ||
272 | int | 256 | int |
273 | TALER_TALER_DB_extract_amount (PGresult *result, unsigned int row, | 257 | TALER_TALER_DB_extract_amount (PGresult *result, |
274 | int indices[3], struct TALER_Amount *denom) | 258 | unsigned int row, |
259 | int indices[3], | ||
260 | struct TALER_Amount *denom) | ||
275 | { | 261 | { |
276 | struct TALER_AmountNBO denom_nbo; | 262 | struct TALER_AmountNBO denom_nbo; |
277 | int res; | 263 | int res; |
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c index 4c836bf92..c07490805 100644 --- a/src/mint/mint_db.c +++ b/src/mint/mint_db.c | |||
@@ -1925,11 +1925,11 @@ TALER_MINT_DB_get_deposit (PGconn *db_conn, | |||
1925 | EXITIF (GNUNET_OK != | 1925 | EXITIF (GNUNET_OK != |
1926 | TALER_DB_extract_result (result, rs, 0)); | 1926 | TALER_DB_extract_result (result, rs, 0)); |
1927 | EXITIF (GNUNET_OK != | 1927 | EXITIF (GNUNET_OK != |
1928 | TALER_DB_extract_amount_nbo (result, 0, | 1928 | TALER_DB_extract_amount (result, 0, |
1929 | "amount_value", | 1929 | "amount_value", |
1930 | "amount_fraction", | 1930 | "amount_fraction", |
1931 | "amount_currency", | 1931 | "amount_currency", |
1932 | &deposit->amount)); | 1932 | &deposit->amount)); |
1933 | deposit->coin.denom_sig | 1933 | deposit->coin.denom_sig |
1934 | = GNUNET_CRYPTO_rsa_signature_decode (denom_sig_buf, | 1934 | = GNUNET_CRYPTO_rsa_signature_decode (denom_sig_buf, |
1935 | denom_sig_buf_size); | 1935 | denom_sig_buf_size); |
diff --git a/src/mint/taler-mint-dbinit.c b/src/mint/taler-mint-dbinit.c index d877f62c6..3d080b523 100644 --- a/src/mint/taler-mint-dbinit.c +++ b/src/mint/taler-mint-dbinit.c | |||
@@ -95,7 +95,7 @@ TALER_MINT_init_withdraw_tables (PGconn *conn) | |||
95 | } | 95 | } |
96 | PQclear (result); | 96 | PQclear (result); |
97 | 97 | ||
98 | result = PQexec (conn, | 98 | result = PQexec (conn, |
99 | "CREATE TABLE IF NOT EXISTS refresh_sessions " | 99 | "CREATE TABLE IF NOT EXISTS refresh_sessions " |
100 | "(" | 100 | "(" |
101 | " session_pub BYTEA PRIMARY KEY CHECK (length(session_pub) = 32)" | 101 | " session_pub BYTEA PRIMARY KEY CHECK (length(session_pub) = 32)" |
@@ -113,7 +113,7 @@ TALER_MINT_init_withdraw_tables (PGconn *conn) | |||
113 | } | 113 | } |
114 | PQclear (result); | 114 | PQclear (result); |
115 | 115 | ||
116 | result = PQexec (conn, | 116 | result = PQexec (conn, |
117 | "CREATE TABLE IF NOT EXISTS refresh_order " | 117 | "CREATE TABLE IF NOT EXISTS refresh_order " |
118 | "( " | 118 | "( " |
119 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub)" | 119 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub)" |
@@ -130,7 +130,7 @@ TALER_MINT_init_withdraw_tables (PGconn *conn) | |||
130 | PQclear (result); | 130 | PQclear (result); |
131 | 131 | ||
132 | 132 | ||
133 | result = PQexec (conn, | 133 | result = PQexec (conn, |
134 | "CREATE TABLE IF NOT EXISTS refresh_commit_link" | 134 | "CREATE TABLE IF NOT EXISTS refresh_commit_link" |
135 | "(" | 135 | "(" |
136 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub)" | 136 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub)" |
@@ -150,7 +150,7 @@ TALER_MINT_init_withdraw_tables (PGconn *conn) | |||
150 | } | 150 | } |
151 | PQclear (result); | 151 | PQclear (result); |
152 | 152 | ||
153 | result = PQexec (conn, | 153 | result = PQexec (conn, |
154 | "CREATE TABLE IF NOT EXISTS refresh_commit_coin" | 154 | "CREATE TABLE IF NOT EXISTS refresh_commit_coin" |
155 | "(" | 155 | "(" |
156 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub) " | 156 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub) " |
@@ -169,7 +169,7 @@ TALER_MINT_init_withdraw_tables (PGconn *conn) | |||
169 | } | 169 | } |
170 | PQclear (result); | 170 | PQclear (result); |
171 | 171 | ||
172 | result = PQexec (conn, | 172 | result = PQexec (conn, |
173 | "CREATE TABLE IF NOT EXISTS refresh_melt" | 173 | "CREATE TABLE IF NOT EXISTS refresh_melt" |
174 | "(" | 174 | "(" |
175 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub) " | 175 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub) " |
@@ -185,7 +185,7 @@ TALER_MINT_init_withdraw_tables (PGconn *conn) | |||
185 | } | 185 | } |
186 | PQclear (result); | 186 | PQclear (result); |
187 | 187 | ||
188 | result = PQexec (conn, | 188 | result = PQexec (conn, |
189 | "CREATE TABLE IF NOT EXISTS refresh_collectable" | 189 | "CREATE TABLE IF NOT EXISTS refresh_collectable" |
190 | "(" | 190 | "(" |
191 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub) " | 191 | " session_pub BYTEA NOT NULL REFERENCES refresh_sessions (session_pub) " |
@@ -245,7 +245,7 @@ main (int argc, char *const *argv) | |||
245 | GNUNET_GETOPT_OPTION_END | 245 | GNUNET_GETOPT_OPTION_END |
246 | }; | 246 | }; |
247 | 247 | ||
248 | if (GNUNET_GETOPT_run ("taler-mint-serve", options, argc, argv) < 0) | 248 | if (GNUNET_GETOPT_run ("taler-mint-serve", options, argc, argv) < 0) |
249 | return 1; | 249 | return 1; |
250 | 250 | ||
251 | GNUNET_assert (GNUNET_OK == GNUNET_log_setup ("taler-mint-dbinit", "INFO", NULL)); | 251 | GNUNET_assert (GNUNET_OK == GNUNET_log_setup ("taler-mint-dbinit", "INFO", NULL)); |
@@ -256,7 +256,7 @@ main (int argc, char *const *argv) | |||
256 | return 1; | 256 | return 1; |
257 | } | 257 | } |
258 | 258 | ||
259 | cfg = TALER_MINT_config_load (mint_base_dir); | 259 | cfg = TALER_config_load (mint_base_dir); |
260 | if (NULL == cfg) | 260 | if (NULL == cfg) |
261 | { | 261 | { |
262 | fprintf (stderr, "Can't load mint configuration.\n"); | 262 | fprintf (stderr, "Can't load mint configuration.\n"); |
@@ -282,4 +282,3 @@ main (int argc, char *const *argv) | |||
282 | 282 | ||
283 | return 0; | 283 | return 0; |
284 | } | 284 | } |
285 | |||
diff --git a/src/mint/taler-mint-httpd.c b/src/mint/taler-mint-httpd.c index ffd97a1ad..cde603168 100644 --- a/src/mint/taler-mint-httpd.c +++ b/src/mint/taler-mint-httpd.c | |||
@@ -233,7 +233,7 @@ mint_serve_process_config (const char *mint_directory) | |||
233 | char *master_pub_str; | 233 | char *master_pub_str; |
234 | char *db_cfg; | 234 | char *db_cfg; |
235 | 235 | ||
236 | cfg = TALER_MINT_config_load (mint_directory); | 236 | cfg = TALER_config_load (mint_directory); |
237 | if (NULL == cfg) | 237 | if (NULL == cfg) |
238 | { | 238 | { |
239 | fprintf (stderr, | 239 | fprintf (stderr, |
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c index fcc6d915f..49c359a89 100644 --- a/src/mint/taler-mint-httpd_db.c +++ b/src/mint/taler-mint-httpd_db.c | |||
@@ -117,7 +117,7 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection, | |||
117 | 117 | ||
118 | /* coin valid but not known => insert into DB */ | 118 | /* coin valid but not known => insert into DB */ |
119 | known_coin.is_refreshed = GNUNET_NO; | 119 | known_coin.is_refreshed = GNUNET_NO; |
120 | known_coin.expended_balance = TALER_amount_ntoh (deposit->amount); | 120 | known_coin.expended_balance = deposit->amount; |
121 | known_coin.public_info = coin_info; | 121 | known_coin.public_info = coin_info; |
122 | 122 | ||
123 | if (GNUNET_OK != TALER_MINT_DB_insert_known_coin (db_conn, &known_coin)) | 123 | if (GNUNET_OK != TALER_MINT_DB_insert_known_coin (db_conn, &known_coin)) |
@@ -419,8 +419,7 @@ mint_amount_native_zero () | |||
419 | struct TALER_Amount amount; | 419 | struct TALER_Amount amount; |
420 | 420 | ||
421 | memset (&amount, 0, sizeof (amount)); | 421 | memset (&amount, 0, sizeof (amount)); |
422 | // FIXME: load from config | 422 | memcpy (amount.currency, MINT_CURRENCY, strlen (MINT_CURRENCY) + 1); |
423 | memcpy (amount.currency, "EUR", 3); | ||
424 | 423 | ||
425 | return amount; | 424 | return amount; |
426 | } | 425 | } |
diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c index ed0eca8bb..ee9f76d5d 100644 --- a/src/mint/taler-mint-httpd_deposit.c +++ b/src/mint/taler-mint-httpd_deposit.c | |||
@@ -23,9 +23,8 @@ | |||
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * | 24 | * |
25 | * TODO: | 25 | * TODO: |
26 | * - actually verify coin signature | 26 | * - missing 'wire' format check (well-formed SEPA-details) |
27 | * - revisit `struct Deposit` parsing once the struct | 27 | * - ugliy if-construction for deposit type |
28 | * has been finalized | ||
29 | */ | 28 | */ |
30 | #include "platform.h" | 29 | #include "platform.h" |
31 | #include <gnunet/gnunet_util_lib.h> | 30 | #include <gnunet/gnunet_util_lib.h> |
@@ -59,19 +58,25 @@ verify_and_execute_deposit (struct MHD_Connection *connection, | |||
59 | const struct Deposit *deposit) | 58 | const struct Deposit *deposit) |
60 | { | 59 | { |
61 | struct MintKeyState *key_state; | 60 | struct MintKeyState *key_state; |
61 | struct TALER_DepositRequest dr; | ||
62 | 62 | ||
63 | /* FIXME: verify coin signature! */ | 63 | dr.purpose.purpose = htonl (TALER_SIGNATURE_DEPOSIT); |
64 | /* | 64 | dr.purpose.size = htonl (sizeof (struct TALER_DepositRequest)); |
65 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_DEPOSIT, | 65 | dr.h_contract = deposit->h_contract; |
66 | &deposit->purpose, | 66 | dr.h_wire = deposit->h_wire; |
67 | &deposit->coin_sig, | 67 | dr.transaction_id = GNUNET_htonll (deposit->transaction_id); |
68 | &deposit->coin_pub)) | 68 | dr.amount = TALER_amount_hton (deposit->amount); |
69 | dr.coin_pub = deposit->coin.coin_pub; | ||
70 | if (GNUNET_OK != | ||
71 | GNUNET_CRYPTO_ecdsa_verify (TALER_SIGNATURE_DEPOSIT, | ||
72 | &dr.purpose, | ||
73 | &deposit->csig, | ||
74 | &deposit->coin.coin_pub)) | ||
69 | { | 75 | { |
70 | resp = json_pack ("{s:s}", "error", "Signature verfication failed"); | 76 | LOG_WARNING ("Invalid signature on /deposit request\n"); |
71 | return TALER_MINT_reply_arg_invalid (connection, | 77 | return TALER_MINT_reply_arg_invalid (connection, |
72 | "csig"); | 78 | "csig"); |
73 | } | 79 | } |
74 | */ | ||
75 | 80 | ||
76 | key_state = TALER_MINT_key_state_acquire (); | 81 | key_state = TALER_MINT_key_state_acquire (); |
77 | if (GNUNET_YES != | 82 | if (GNUNET_YES != |
@@ -80,10 +85,7 @@ verify_and_execute_deposit (struct MHD_Connection *connection, | |||
80 | { | 85 | { |
81 | LOG_WARNING ("Invalid coin passed for /deposit\n"); | 86 | LOG_WARNING ("Invalid coin passed for /deposit\n"); |
82 | TALER_MINT_key_state_release (key_state); | 87 | TALER_MINT_key_state_release (key_state); |
83 | return TALER_MINT_reply_json_pack (connection, | 88 | return TALER_MINT_reply_coin_invalid (connection); |
84 | MHD_HTTP_NOT_FOUND, | ||
85 | "{s:s}", | ||
86 | "error", "Coin is not valid"); | ||
87 | } | 89 | } |
88 | TALER_MINT_key_state_release (key_state); | 90 | TALER_MINT_key_state_release (key_state); |
89 | 91 | ||
@@ -101,6 +103,7 @@ verify_and_execute_deposit (struct MHD_Connection *connection, | |||
101 | * @param root root of the posted JSON | 103 | * @param root root of the posted JSON |
102 | * @param purpose is this a #TALER_SIGNATURE_DEPOSIT or | 104 | * @param purpose is this a #TALER_SIGNATURE_DEPOSIT or |
103 | * #TALER_SIGNATURE_INCREMENTAL_DEPOSIT // FIXME: bad type, use enum! | 105 | * #TALER_SIGNATURE_INCREMENTAL_DEPOSIT // FIXME: bad type, use enum! |
106 | * @param amount how much should be deposited | ||
104 | * @param wire json describing the wire details (?) | 107 | * @param wire json describing the wire details (?) |
105 | * @return MHD result code | 108 | * @return MHD result code |
106 | */ | 109 | */ |
@@ -108,6 +111,7 @@ static int | |||
108 | parse_and_handle_deposit_request (struct MHD_Connection *connection, | 111 | parse_and_handle_deposit_request (struct MHD_Connection *connection, |
109 | const json_t *root, | 112 | const json_t *root, |
110 | uint32_t purpose, | 113 | uint32_t purpose, |
114 | const struct TALER_Amount *amount, | ||
111 | const json_t *wire) | 115 | const json_t *wire) |
112 | { | 116 | { |
113 | int res; | 117 | int res; |
@@ -155,6 +159,7 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, | |||
155 | return TALER_MINT_reply_arg_invalid (connection, | 159 | return TALER_MINT_reply_arg_invalid (connection, |
156 | "denom_pub"); | 160 | "denom_pub"); |
157 | } | 161 | } |
162 | /* FIXME: check that "wire" is formatted correctly */ | ||
158 | if (NULL == (wire_enc = json_dumps (wire, JSON_COMPACT | JSON_SORT_KEYS))) | 163 | if (NULL == (wire_enc = json_dumps (wire, JSON_COMPACT | JSON_SORT_KEYS))) |
159 | { | 164 | { |
160 | GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub); | 165 | GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub); |
@@ -172,9 +177,7 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, | |||
172 | 177 | ||
173 | deposit.wire = wire; | 178 | deposit.wire = wire; |
174 | deposit.purpose = purpose; | 179 | deposit.purpose = purpose; |
175 | 180 | deposit.amount = *amount; | |
176 | // FIXME: deposit.amount not initialized! | ||
177 | |||
178 | res = verify_and_execute_deposit (connection, | 181 | res = verify_and_execute_deposit (connection, |
179 | &deposit); | 182 | &deposit); |
180 | GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub); | 183 | GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub); |
@@ -212,6 +215,8 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh, | |||
212 | const char *deposit_type; | 215 | const char *deposit_type; |
213 | int res; | 216 | int res; |
214 | uint32_t purpose; | 217 | uint32_t purpose; |
218 | struct TALER_Amount amount; | ||
219 | json_t *f; | ||
215 | 220 | ||
216 | res = TALER_MINT_parse_post_json (connection, | 221 | res = TALER_MINT_parse_post_json (connection, |
217 | connection_cls, | 222 | connection_cls, |
@@ -223,16 +228,35 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh, | |||
223 | if ( (GNUNET_NO == res) || (NULL == json) ) | 228 | if ( (GNUNET_NO == res) || (NULL == json) ) |
224 | return MHD_YES; | 229 | return MHD_YES; |
225 | if (-1 == json_unpack (json, | 230 | if (-1 == json_unpack (json, |
226 | "{s:s, s:o}", | 231 | "{s:s, s:o, f:o}", |
227 | "type", &deposit_type, | 232 | "type", &deposit_type, |
228 | "wire", &wire)) | 233 | "wire", &wire, |
234 | "f", &f)) | ||
229 | { | 235 | { |
230 | GNUNET_break_op (0); | 236 | GNUNET_break_op (0); |
237 | json_decref (json); | ||
231 | return TALER_MINT_reply_json_pack (connection, | 238 | return TALER_MINT_reply_json_pack (connection, |
232 | MHD_HTTP_BAD_REQUEST, | 239 | MHD_HTTP_BAD_REQUEST, |
233 | "{s:s}", | 240 | "{s:s}", |
234 | "error", "Bad format"); | 241 | "error", "Bad format"); |
235 | } | 242 | } |
243 | res = TALER_MINT_parse_amount_json (connection, | ||
244 | f, | ||
245 | &amount); | ||
246 | json_decref (f); | ||
247 | if (GNUNET_SYSERR == res) | ||
248 | { | ||
249 | json_decref (wire); | ||
250 | json_decref (json); | ||
251 | return MHD_NO; | ||
252 | } | ||
253 | if (GNUNET_NO == res) | ||
254 | { | ||
255 | json_decref (wire); | ||
256 | json_decref (json); | ||
257 | return MHD_YES; | ||
258 | } | ||
259 | /* FIXME: use array search and enum, this is ugly */ | ||
236 | if (0 == strcmp ("DIRECT_DEPOSIT", deposit_type)) | 260 | if (0 == strcmp ("DIRECT_DEPOSIT", deposit_type)) |
237 | purpose = TALER_SIGNATURE_DEPOSIT; | 261 | purpose = TALER_SIGNATURE_DEPOSIT; |
238 | else if (0 == strcmp ("INCREMENTAL_DEPOSIT", deposit_type)) | 262 | else if (0 == strcmp ("INCREMENTAL_DEPOSIT", deposit_type)) |
@@ -241,6 +265,7 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh, | |||
241 | { | 265 | { |
242 | GNUNET_break_op (0); | 266 | GNUNET_break_op (0); |
243 | json_decref (wire); | 267 | json_decref (wire); |
268 | json_decref (json); | ||
244 | return TALER_MINT_reply_json_pack (connection, | 269 | return TALER_MINT_reply_json_pack (connection, |
245 | MHD_HTTP_BAD_REQUEST, | 270 | MHD_HTTP_BAD_REQUEST, |
246 | "{s:s}", | 271 | "{s:s}", |
@@ -249,8 +274,10 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh, | |||
249 | res = parse_and_handle_deposit_request (connection, | 274 | res = parse_and_handle_deposit_request (connection, |
250 | json, | 275 | json, |
251 | purpose, | 276 | purpose, |
277 | &amount, | ||
252 | wire); | 278 | wire); |
253 | json_decref (wire); | 279 | json_decref (wire); |
280 | json_decref (json); | ||
254 | return res; | 281 | return res; |
255 | } | 282 | } |
256 | 283 | ||
diff --git a/src/mint/taler-mint-httpd_parsing.c b/src/mint/taler-mint-httpd_parsing.c index c4e28bba7..066f18913 100644 --- a/src/mint/taler-mint-httpd_parsing.c +++ b/src/mint/taler-mint-httpd_parsing.c | |||
@@ -110,8 +110,8 @@ buffer_deinit (struct Buffer *buf) | |||
110 | * @param data the data to append | 110 | * @param data the data to append |
111 | * @param size the size of @a data | 111 | * @param size the size of @a data |
112 | * @param max_size maximum size that the buffer can grow to | 112 | * @param max_size maximum size that the buffer can grow to |
113 | * @return GNUNET_OK on success, | 113 | * @return #GNUNET_OK on success, |
114 | * GNUNET_NO if the buffer can't accomodate for the new data | 114 | * #GNUNET_NO if the buffer can't accomodate for the new data |
115 | */ | 115 | */ |
116 | static int | 116 | static int |
117 | buffer_append (struct Buffer *buf, | 117 | buffer_append (struct Buffer *buf, |
@@ -153,14 +153,14 @@ buffer_append (struct Buffer *buf, | |||
153 | * @param upload_data the POST data | 153 | * @param upload_data the POST data |
154 | * @param upload_data_size number of bytes in @a upload_data | 154 | * @param upload_data_size number of bytes in @a upload_data |
155 | * @param json the JSON object for a completed request | 155 | * @param json the JSON object for a completed request |
156 | * @returns | 156 | * @return |
157 | * GNUNET_YES if json object was parsed or at least | 157 | * #GNUNET_YES if json object was parsed or at least |
158 | * may be parsed in the future (call again); | 158 | * may be parsed in the future (call again); |
159 | * `*json` will be NULL if we need to be called again, | 159 | * `*json` will be NULL if we need to be called again, |
160 | * and non-NULL if we are done. | 160 | * and non-NULL if we are done. |
161 | * GNUNET_NO is request incomplete or invalid | 161 | * #GNUNET_NO is request incomplete or invalid |
162 | * (error message was generated) | 162 | * (error message was generated) |
163 | * GNUNET_SYSERR on internal error | 163 | * #GNUNET_SYSERR on internal error |
164 | * (we could not even queue an error message, | 164 | * (we could not even queue an error message, |
165 | * close HTTP session with MHD_NO) | 165 | * close HTTP session with MHD_NO) |
166 | */ | 166 | */ |
@@ -606,6 +606,78 @@ TALER_MINT_release_parsed_data (struct GNUNET_MINT_ParseFieldSpec *spec) | |||
606 | 606 | ||
607 | 607 | ||
608 | /** | 608 | /** |
609 | * Parse amount specified in JSON format. | ||
610 | * | ||
611 | * @param connection the MHD connection (to report errors) | ||
612 | * @param f json specification of the amount | ||
613 | * @param amount[OUT] set to the amount specified in @a f | ||
614 | * @return | ||
615 | * #GNUNET_YES if parsing was successful | ||
616 | * #GNUNET_NO if json is malformed, error response was generated | ||
617 | * #GNUNET_SYSERR on internal error, error response was not generated | ||
618 | */ | ||
619 | int | ||
620 | TALER_MINT_parse_amount_json (struct MHD_Connection *connection, | ||
621 | json_t *f, | ||
622 | struct TALER_Amount *amount) | ||
623 | { | ||
624 | json_int_t value; | ||
625 | json_int_t fraction; | ||
626 | const char *currency; | ||
627 | struct TALER_Amount a; | ||
628 | |||
629 | if (-1 == json_unpack (f, | ||
630 | "{s:I, s:I, s:s}", | ||
631 | "value", &value, | ||
632 | "fraction", &fraction, | ||
633 | "currency", ¤cy)) | ||
634 | { | ||
635 | LOG_WARNING ("Failed to parse JSON amount specification\n"); | ||
636 | if (MHD_YES != | ||
637 | TALER_MINT_reply_json_pack (connection, | ||
638 | MHD_HTTP_BAD_REQUEST, | ||
639 | "{s:s}", | ||
640 | "error", "Bad format")) | ||
641 | return GNUNET_SYSERR; | ||
642 | return GNUNET_NO; | ||
643 | } | ||
644 | if ( (value < 0) || | ||
645 | (fraction < 0) || | ||
646 | (value > UINT32_MAX) || | ||
647 | (fraction > UINT32_MAX) ) | ||
648 | { | ||
649 | LOG_WARNING ("Amount specified not in allowed range\n"); | ||
650 | if (MHD_YES != | ||
651 | TALER_MINT_reply_json_pack (connection, | ||
652 | MHD_HTTP_BAD_REQUEST, | ||
653 | "{s:s}", | ||
654 | "error", "Amount outside of allowed range")) | ||
655 | return GNUNET_SYSERR; | ||
656 | return GNUNET_NO; | ||
657 | } | ||
658 | if (0 != strcmp (currency, | ||
659 | MINT_CURRENCY)) | ||
660 | { | ||
661 | LOG_WARNING ("Currency specified not supported by this mint\n"); | ||
662 | if (MHD_YES != | ||
663 | TALER_MINT_reply_json_pack (connection, | ||
664 | MHD_HTTP_BAD_REQUEST, | ||
665 | "{s:s, s:s}", | ||
666 | "error", "Currency not supported", | ||
667 | "currency", currency)) | ||
668 | return GNUNET_SYSERR; | ||
669 | return GNUNET_NO; | ||
670 | } | ||
671 | a.value = (uint32_t) value; | ||
672 | a.fraction = (uint32_t) fraction; | ||
673 | GNUNET_assert (strlen (MINT_CURRENCY) < TALER_CURRENCY_LEN); | ||
674 | strcpy (a.currency, MINT_CURRENCY); | ||
675 | *amount = TALER_amount_normalize (a); | ||
676 | return GNUNET_OK; | ||
677 | } | ||
678 | |||
679 | |||
680 | /** | ||
609 | * Extract base32crockford encoded data from request. | 681 | * Extract base32crockford encoded data from request. |
610 | * | 682 | * |
611 | * Queues an error response to the connection if the parameter is missing or | 683 | * Queues an error response to the connection if the parameter is missing or |
diff --git a/src/mint/taler-mint-httpd_parsing.h b/src/mint/taler-mint-httpd_parsing.h index 9c4d8aafe..1c13c9469 100644 --- a/src/mint/taler-mint-httpd_parsing.h +++ b/src/mint/taler-mint-httpd_parsing.h | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include <microhttpd.h> | 26 | #include <microhttpd.h> |
27 | #include <jansson.h> | 27 | #include <jansson.h> |
28 | #include "taler_util.h" | ||
28 | 29 | ||
29 | 30 | ||
30 | /** | 31 | /** |
@@ -216,6 +217,23 @@ TALER_MINT_release_parsed_data (struct GNUNET_MINT_ParseFieldSpec *spec); | |||
216 | 217 | ||
217 | 218 | ||
218 | /** | 219 | /** |
220 | * Parse amount specified in JSON format. | ||
221 | * | ||
222 | * @param connection the MHD connection (to report errors) | ||
223 | * @param f json specification of the amount | ||
224 | * @param amount[OUT] set to the amount specified in @a f | ||
225 | * @return | ||
226 | * #GNUNET_YES if parsing was successful | ||
227 | * #GNUNET_NO if json is malformed, error response was generated | ||
228 | * #GNUNET_SYSERR on internal error, error response was not generated | ||
229 | */ | ||
230 | int | ||
231 | TALER_MINT_parse_amount_json (struct MHD_Connection *connection, | ||
232 | json_t *f, | ||
233 | struct TALER_Amount *amount); | ||
234 | |||
235 | |||
236 | /** | ||
219 | * Extraxt fixed-size base32crockford encoded data from request. | 237 | * Extraxt fixed-size base32crockford encoded data from request. |
220 | * | 238 | * |
221 | * Queues an error response to the connection if the parameter is missing or | 239 | * Queues an error response to the connection if the parameter is missing or |
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index 12d4bced7..432772d79 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c | |||
@@ -125,6 +125,26 @@ TALER_MINT_reply_arg_invalid (struct MHD_Connection *connection, | |||
125 | 125 | ||
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Send a response indicating an invalid coin. (I.e. the signature | ||
129 | * over the public key of the coin does not match a valid signing key | ||
130 | * of this mint). | ||
131 | * | ||
132 | * @param connection the MHD connection to use | ||
133 | * @return MHD result code | ||
134 | */ | ||
135 | int | ||
136 | TALER_MINT_reply_coin_invalid (struct MHD_Connection *connection) | ||
137 | { | ||
138 | /* TODO: may want to be more precise in the future and | ||
139 | distinguish bogus signatures from bogus public keys. */ | ||
140 | return TALER_MINT_reply_json_pack (connection, | ||
141 | MHD_HTTP_NOT_FOUND, | ||
142 | "{s:s}", | ||
143 | "error", "Coin is not valid"); | ||
144 | } | ||
145 | |||
146 | |||
147 | /** | ||
128 | * Send a response indicating a missing argument. | 148 | * Send a response indicating a missing argument. |
129 | * | 149 | * |
130 | * @param connection the MHD connection to use | 150 | * @param connection the MHD connection to use |
diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h index 51abd9fb4..471d73bd1 100644 --- a/src/mint/taler-mint-httpd_responses.h +++ b/src/mint/taler-mint-httpd_responses.h | |||
@@ -78,6 +78,18 @@ TALER_MINT_reply_arg_invalid (struct MHD_Connection *connection, | |||
78 | 78 | ||
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Send a response indicating an invalid coin. (I.e. the signature | ||
82 | * over the public key of the coin does not match a valid signing key | ||
83 | * of this mint). | ||
84 | * | ||
85 | * @param connection the MHD connection to use | ||
86 | * @return MHD result code | ||
87 | */ | ||
88 | int | ||
89 | TALER_MINT_reply_coin_invalid (struct MHD_Connection *connection); | ||
90 | |||
91 | |||
92 | /** | ||
81 | * Send a response indicating a missing argument. | 93 | * Send a response indicating a missing argument. |
82 | * | 94 | * |
83 | * @param connection the MHD connection to use | 95 | * @param connection the MHD connection to use |
diff --git a/src/mint/taler-mint-keycheck.c b/src/mint/taler-mint-keycheck.c index 419baf501..09f59ab2f 100644 --- a/src/mint/taler-mint-keycheck.c +++ b/src/mint/taler-mint-keycheck.c | |||
@@ -162,7 +162,7 @@ main (int argc, char *const *argv) | |||
162 | return 1; | 162 | return 1; |
163 | } | 163 | } |
164 | 164 | ||
165 | kcfg = TALER_MINT_config_load (mintdir); | 165 | kcfg = TALER_config_load (mintdir); |
166 | if (NULL == kcfg) | 166 | if (NULL == kcfg) |
167 | { | 167 | { |
168 | fprintf (stderr, "can't load mint configuration\n"); | 168 | fprintf (stderr, "can't load mint configuration\n"); |
@@ -172,4 +172,3 @@ main (int argc, char *const *argv) | |||
172 | return 1; | 172 | return 1; |
173 | return 0; | 173 | return 0; |
174 | } | 174 | } |
175 | |||
diff --git a/src/mint/taler-mint-keyup.c b/src/mint/taler-mint-keyup.c index 7c35317ce..f8670eb97 100644 --- a/src/mint/taler-mint-keyup.c +++ b/src/mint/taler-mint-keyup.c | |||
@@ -621,7 +621,7 @@ main (int argc, char *const *argv) | |||
621 | } | 621 | } |
622 | ROUND_TO_SECS (now, abs_value_us); | 622 | ROUND_TO_SECS (now, abs_value_us); |
623 | 623 | ||
624 | kcfg = TALER_MINT_config_load (mintdir); | 624 | kcfg = TALER_config_load (mintdir); |
625 | if (NULL == kcfg) | 625 | if (NULL == kcfg) |
626 | { | 626 | { |
627 | fprintf (stderr, "can't load mint configuration\n"); | 627 | fprintf (stderr, "can't load mint configuration\n"); |
diff --git a/src/mint/taler-mint-reservemod.c b/src/mint/taler-mint-reservemod.c index 3dd94f84b..48a9c88b4 100644 --- a/src/mint/taler-mint-reservemod.c +++ b/src/mint/taler-mint-reservemod.c | |||
@@ -38,7 +38,7 @@ static PGconn *db_conn; | |||
38 | /** | 38 | /** |
39 | * Create a new or add to existing reserve. | 39 | * Create a new or add to existing reserve. |
40 | * Fails if currencies do not match. | 40 | * Fails if currencies do not match. |
41 | * | 41 | * |
42 | * @param denom denomination to add | 42 | * @param denom denomination to add |
43 | * | 43 | * |
44 | * @return ... | 44 | * @return ... |
@@ -72,7 +72,7 @@ reservemod_add (struct TALER_Amount denom) | |||
72 | reserve_pub, | 72 | reserve_pub, |
73 | &value, | 73 | &value, |
74 | &fraction, | 74 | &fraction, |
75 | denom.currency, | 75 | denom.currency, |
76 | &exnbo}; | 76 | &exnbo}; |
77 | int param_lengths[] = {32, 4, 4, strlen(denom.currency), 8}; | 77 | int param_lengths[] = {32, 4, 4, strlen(denom.currency), 8}; |
78 | int param_formats[] = {1, 1, 1, 1, 1}; | 78 | int param_formats[] = {1, 1, 1, 1, 1}; |
@@ -81,14 +81,14 @@ reservemod_add (struct TALER_Amount denom) | |||
81 | " expiration_date )" | 81 | " expiration_date )" |
82 | "values ($1,$2,$3,$4,$5);", | 82 | "values ($1,$2,$3,$4,$5);", |
83 | 5, NULL, (const char **) param_values, param_lengths, param_formats, 1); | 83 | 5, NULL, (const char **) param_values, param_lengths, param_formats, 1); |
84 | 84 | ||
85 | if (PGRES_COMMAND_OK != PQresultStatus (result)) | 85 | if (PGRES_COMMAND_OK != PQresultStatus (result)) |
86 | { | 86 | { |
87 | fprintf (stderr, "Insert failed: %s\n", PQresultErrorMessage (result)); | 87 | fprintf (stderr, "Insert failed: %s\n", PQresultErrorMessage (result)); |
88 | return GNUNET_SYSERR; | 88 | return GNUNET_SYSERR; |
89 | } | 89 | } |
90 | } | 90 | } |
91 | else | 91 | else |
92 | { | 92 | { |
93 | struct TALER_Amount old_denom; | 93 | struct TALER_Amount old_denom; |
94 | struct TALER_Amount new_denom; | 94 | struct TALER_Amount new_denom; |
@@ -125,8 +125,8 @@ reservemod_add (struct TALER_Amount denom) | |||
125 | return GNUNET_SYSERR; | 125 | return GNUNET_SYSERR; |
126 | } | 126 | } |
127 | 127 | ||
128 | } | 128 | } |
129 | return GNUNET_OK; | 129 | return GNUNET_OK; |
130 | } | 130 | } |
131 | 131 | ||
132 | 132 | ||
@@ -159,18 +159,18 @@ main (int argc, char *const *argv) | |||
159 | 159 | ||
160 | GNUNET_assert (GNUNET_OK == GNUNET_log_setup ("taler-mint-keycheck", "WARNING", NULL)); | 160 | GNUNET_assert (GNUNET_OK == GNUNET_log_setup ("taler-mint-keycheck", "WARNING", NULL)); |
161 | 161 | ||
162 | if (GNUNET_GETOPT_run ("taler-mint-keyup", options, argc, argv) < 0) | 162 | if (GNUNET_GETOPT_run ("taler-mint-keyup", options, argc, argv) < 0) |
163 | return 1; | 163 | return 1; |
164 | if (NULL == mintdir) | 164 | if (NULL == mintdir) |
165 | { | 165 | { |
166 | fprintf (stderr, "mint directory not given\n"); | 166 | fprintf (stderr, "mint directory not given\n"); |
167 | return 1; | 167 | return 1; |
168 | } | 168 | } |
169 | 169 | ||
170 | reserve_pub = GNUNET_new (struct GNUNET_CRYPTO_EddsaPublicKey); | 170 | reserve_pub = GNUNET_new (struct GNUNET_CRYPTO_EddsaPublicKey); |
171 | if ((NULL == reserve_pub_str) || | 171 | if ((NULL == reserve_pub_str) || |
172 | (GNUNET_OK != GNUNET_STRINGS_string_to_data (reserve_pub_str, | 172 | (GNUNET_OK != GNUNET_STRINGS_string_to_data (reserve_pub_str, |
173 | strlen (reserve_pub_str), | 173 | strlen (reserve_pub_str), |
174 | reserve_pub, | 174 | reserve_pub, |
175 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)))) | 175 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)))) |
176 | { | 176 | { |
@@ -178,7 +178,7 @@ main (int argc, char *const *argv) | |||
178 | return 1; | 178 | return 1; |
179 | } | 179 | } |
180 | 180 | ||
181 | kcfg = TALER_MINT_config_load (mintdir); | 181 | kcfg = TALER_config_load (mintdir); |
182 | if (NULL == kcfg) | 182 | if (NULL == kcfg) |
183 | { | 183 | { |
184 | fprintf (stderr, "can't load mint configuration\n"); | 184 | fprintf (stderr, "can't load mint configuration\n"); |
@@ -212,4 +212,3 @@ main (int argc, char *const *argv) | |||
212 | } | 212 | } |
213 | return 0; | 213 | return 0; |
214 | } | 214 | } |
215 | |||
diff --git a/src/mint/test_mint_deposits.c b/src/mint/test_mint_deposits.c index 776bc15d2..00664cbbf 100644 --- a/src/mint/test_mint_deposits.c +++ b/src/mint/test_mint_deposits.c | |||
@@ -104,9 +104,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
104 | htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)); | 104 | htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)); |
105 | deposit->amount.fraction = | 105 | deposit->amount.fraction = |
106 | htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)); | 106 | htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)); |
107 | strcpy (deposit->amount.currency, "EUR"); | 107 | GNUNET_assert (strlen (MINT_CURRENCY) < sizeof (deposit->amount.currency)); |
108 | strcpy (deposit->amount.currency, MINT_CURRENCY); | ||
108 | /* Copy wireformat */ | 109 | /* Copy wireformat */ |
109 | (void) memcpy (deposit->wire, wire, sizeof (wire)); | 110 | memcpy (deposit->wire, |
111 | wire, | ||
112 | sizeof (wire)); | ||
110 | EXITIF (GNUNET_OK != TALER_MINT_DB_insert_deposit (conn, | 113 | EXITIF (GNUNET_OK != TALER_MINT_DB_insert_deposit (conn, |
111 | deposit)); | 114 | deposit)); |
112 | EXITIF (GNUNET_OK != TALER_MINT_DB_get_deposit (conn, | 115 | EXITIF (GNUNET_OK != TALER_MINT_DB_get_deposit (conn, |
diff --git a/src/util/util.c b/src/util/util.c index 440b49fab..de085d088 100644 --- a/src/util/util.c +++ b/src/util/util.c | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | /** | 17 | /** |
18 | * @file util.c | 18 | * @file util.c |
19 | * @brief Common utility functions | 19 | * @brief Common utility functions; we might choose to move those to GNUnet at some point |
20 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | 20 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> |
21 | * @author Florian Dold | 21 | * @author Florian Dold |
22 | * @author Benedikt Mueller | 22 | * @author Benedikt Mueller |
@@ -60,4 +60,33 @@ TALER_data_to_string_alloc (const void *buf, size_t size) | |||
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
63 | /** | ||
64 | * Load configuration by parsing all configuration | ||
65 | * files in the given directory. | ||
66 | * | ||
67 | * @param base_dir directory with the configuration files | ||
68 | * @return NULL on error, otherwise configuration | ||
69 | */ | ||
70 | struct GNUNET_CONFIGURATION_Handle * | ||
71 | TALER_config_load (const char *base_dir) | ||
72 | { | ||
73 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
74 | char *cfg_dir; | ||
75 | int res; | ||
76 | |||
77 | res = GNUNET_asprintf (&cfg_dir, | ||
78 | "%s" DIR_SEPARATOR_STR "config", | ||
79 | base_dir); | ||
80 | GNUNET_assert (res > 0); | ||
81 | cfg = GNUNET_CONFIGURATION_create (); | ||
82 | res = GNUNET_CONFIGURATION_load_from (cfg, cfg_dir); | ||
83 | GNUNET_free (cfg_dir); | ||
84 | if (GNUNET_OK != res) | ||
85 | return NULL; | ||
86 | return cfg; | ||
87 | } | ||
88 | |||
89 | |||
90 | |||
91 | |||
63 | /* end of util.c */ | 92 | /* end of util.c */ |