diff options
Diffstat (limited to 'src/lib/exchange_api_transfers_get.c')
-rw-r--r-- | src/lib/exchange_api_transfers_get.c | 164 |
1 files changed, 78 insertions, 86 deletions
diff --git a/src/lib/exchange_api_transfers_get.c b/src/lib/exchange_api_transfers_get.c index 552536958..dd9b64467 100644 --- a/src/lib/exchange_api_transfers_get.c +++ b/src/lib/exchange_api_transfers_get.c | |||
@@ -85,24 +85,18 @@ check_transfers_get_response_ok ( | |||
85 | const json_t *json) | 85 | const json_t *json) |
86 | { | 86 | { |
87 | json_t *details_j; | 87 | json_t *details_j; |
88 | struct GNUNET_HashCode h_wire; | 88 | struct TALER_EXCHANGE_TransferData td; |
89 | struct GNUNET_TIME_Absolute exec_time; | ||
90 | struct TALER_Amount total_amount; | ||
91 | struct TALER_Amount total_expected; | 89 | struct TALER_Amount total_expected; |
92 | struct TALER_Amount wire_fee; | ||
93 | struct TALER_MerchantPublicKeyP merchant_pub; | 90 | struct TALER_MerchantPublicKeyP merchant_pub; |
94 | unsigned int num_details; | ||
95 | struct TALER_ExchangePublicKeyP exchange_pub; | ||
96 | struct TALER_ExchangeSignatureP exchange_sig; | ||
97 | struct GNUNET_JSON_Specification spec[] = { | 91 | struct GNUNET_JSON_Specification spec[] = { |
98 | TALER_JSON_spec_amount ("total", &total_amount), | 92 | TALER_JSON_spec_amount ("total", &td.total_amount), |
99 | TALER_JSON_spec_amount ("wire_fee", &wire_fee), | 93 | TALER_JSON_spec_amount ("wire_fee", &td.wire_fee), |
100 | GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub), | 94 | GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub), |
101 | GNUNET_JSON_spec_fixed_auto ("h_wire", &h_wire), | 95 | GNUNET_JSON_spec_fixed_auto ("h_wire", &td.h_wire), |
102 | GNUNET_JSON_spec_absolute_time ("execution_time", &exec_time), | 96 | GNUNET_JSON_spec_absolute_time ("execution_time", &td.execution_time), |
103 | GNUNET_JSON_spec_json ("deposits", &details_j), | 97 | GNUNET_JSON_spec_json ("deposits", &details_j), |
104 | GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig), | 98 | GNUNET_JSON_spec_fixed_auto ("exchange_sig", &td.exchange_sig), |
105 | GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub), | 99 | GNUNET_JSON_spec_fixed_auto ("exchange_pub", &td.exchange_pub), |
106 | GNUNET_JSON_spec_end () | 100 | GNUNET_JSON_spec_end () |
107 | }; | 101 | }; |
108 | struct TALER_EXCHANGE_HttpResponse hr = { | 102 | struct TALER_EXCHANGE_HttpResponse hr = { |
@@ -119,22 +113,32 @@ check_transfers_get_response_ok ( | |||
119 | return GNUNET_SYSERR; | 113 | return GNUNET_SYSERR; |
120 | } | 114 | } |
121 | if (GNUNET_OK != | 115 | if (GNUNET_OK != |
122 | TALER_amount_get_zero (total_amount.currency, | 116 | TALER_amount_get_zero (td.total_amount.currency, |
123 | &total_expected)) | 117 | &total_expected)) |
124 | { | 118 | { |
125 | GNUNET_break_op (0); | 119 | GNUNET_break_op (0); |
120 | GNUNET_JSON_parse_free (spec); | ||
126 | return GNUNET_SYSERR; | 121 | return GNUNET_SYSERR; |
127 | } | 122 | } |
128 | num_details = json_array_size (details_j); | 123 | if (GNUNET_OK != |
124 | TALER_EXCHANGE_test_signing_key ( | ||
125 | TALER_EXCHANGE_get_keys (wdh->exchange), | ||
126 | &td.exchange_pub)) | ||
127 | { | ||
128 | GNUNET_break_op (0); | ||
129 | GNUNET_JSON_parse_free (spec); | ||
130 | return GNUNET_SYSERR; | ||
131 | } | ||
132 | td.details_length = json_array_size (details_j); | ||
129 | { | 133 | { |
130 | struct TALER_TrackTransferDetails details[num_details]; | ||
131 | unsigned int i; | ||
132 | struct GNUNET_HashContext *hash_context; | 134 | struct GNUNET_HashContext *hash_context; |
133 | struct TALER_WireDepositDetailP dd; | 135 | struct TALER_TrackTransferDetails *details; |
134 | struct TALER_WireDepositDataPS wdp; | ||
135 | 136 | ||
137 | details = GNUNET_new_array (td.details_length, | ||
138 | struct TALER_TrackTransferDetails); | ||
139 | td.details = details; | ||
136 | hash_context = GNUNET_CRYPTO_hash_context_start (); | 140 | hash_context = GNUNET_CRYPTO_hash_context_start (); |
137 | for (i = 0; i<num_details; i++) | 141 | for (unsigned int i = 0; i<td.details_length; i++) |
138 | { | 142 | { |
139 | struct TALER_TrackTransferDetails *detail = &details[i]; | 143 | struct TALER_TrackTransferDetails *detail = &details[i]; |
140 | struct json_t *detail_j = json_array_get (details_j, i); | 144 | struct json_t *detail_j = json_array_get (details_j, i); |
@@ -147,25 +151,11 @@ check_transfers_get_response_ok ( | |||
147 | GNUNET_JSON_spec_end () | 151 | GNUNET_JSON_spec_end () |
148 | }; | 152 | }; |
149 | 153 | ||
150 | if (GNUNET_OK != | 154 | if ( (GNUNET_OK != |
151 | GNUNET_JSON_parse (detail_j, | 155 | GNUNET_JSON_parse (detail_j, |
152 | spec_detail, | 156 | spec_detail, |
153 | NULL, NULL)) | 157 | NULL, NULL)) || |
154 | { | 158 | (0 > |
155 | GNUNET_break_op (0); | ||
156 | GNUNET_CRYPTO_hash_context_abort (hash_context); | ||
157 | GNUNET_JSON_parse_free (spec); | ||
158 | return GNUNET_SYSERR; | ||
159 | } | ||
160 | /* build up big hash for signature checking later */ | ||
161 | dd.h_contract_terms = detail->h_contract_terms; | ||
162 | dd.execution_time = GNUNET_TIME_absolute_hton (exec_time); | ||
163 | dd.coin_pub = detail->coin_pub; | ||
164 | TALER_amount_hton (&dd.deposit_value, | ||
165 | &detail->coin_value); | ||
166 | TALER_amount_hton (&dd.deposit_fee, | ||
167 | &detail->coin_fee); | ||
168 | if ( (0 > | ||
169 | TALER_amount_add (&total_expected, | 159 | TALER_amount_add (&total_expected, |
170 | &total_expected, | 160 | &total_expected, |
171 | &detail->coin_value)) || | 161 | &detail->coin_value)) || |
@@ -177,71 +167,78 @@ check_transfers_get_response_ok ( | |||
177 | GNUNET_break_op (0); | 167 | GNUNET_break_op (0); |
178 | GNUNET_CRYPTO_hash_context_abort (hash_context); | 168 | GNUNET_CRYPTO_hash_context_abort (hash_context); |
179 | GNUNET_JSON_parse_free (spec); | 169 | GNUNET_JSON_parse_free (spec); |
170 | GNUNET_free (details); | ||
180 | return GNUNET_SYSERR; | 171 | return GNUNET_SYSERR; |
181 | } | 172 | } |
182 | GNUNET_CRYPTO_hash_context_read ( | 173 | /* build up big hash for signature checking later */ |
183 | hash_context, | 174 | { |
184 | &dd, | 175 | struct TALER_WireDepositDetailP dd; |
185 | sizeof (struct TALER_WireDepositDetailP)); | 176 | |
177 | dd.h_contract_terms = detail->h_contract_terms; | ||
178 | dd.execution_time = GNUNET_TIME_absolute_hton (td.execution_time); | ||
179 | dd.coin_pub = detail->coin_pub; | ||
180 | TALER_amount_hton (&dd.deposit_value, | ||
181 | &detail->coin_value); | ||
182 | TALER_amount_hton (&dd.deposit_fee, | ||
183 | &detail->coin_fee); | ||
184 | GNUNET_CRYPTO_hash_context_read (hash_context, | ||
185 | &dd, | ||
186 | sizeof (dd)); | ||
187 | } | ||
186 | } | 188 | } |
187 | /* Check signature */ | 189 | /* Check signature */ |
188 | wdp.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT); | ||
189 | wdp.purpose.size = htonl (sizeof (struct TALER_WireDepositDataPS)); | ||
190 | TALER_amount_hton (&wdp.total, | ||
191 | &total_amount); | ||
192 | TALER_amount_hton (&wdp.wire_fee, | ||
193 | &wire_fee); | ||
194 | wdp.merchant_pub = merchant_pub; | ||
195 | wdp.h_wire = h_wire; | ||
196 | GNUNET_CRYPTO_hash_context_finish (hash_context, | ||
197 | &wdp.h_details); | ||
198 | if (GNUNET_OK != | ||
199 | TALER_EXCHANGE_test_signing_key (TALER_EXCHANGE_get_keys ( | ||
200 | wdh->exchange), | ||
201 | &exchange_pub)) | ||
202 | { | 190 | { |
203 | GNUNET_break_op (0); | 191 | struct TALER_WireDepositDataPS wdp = { |
204 | GNUNET_JSON_parse_free (spec); | 192 | .purpose.purpose = htonl ( |
205 | return GNUNET_SYSERR; | 193 | TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT), |
206 | } | 194 | .purpose.size = htonl (sizeof (wdp)), |
207 | if (GNUNET_OK != | 195 | .merchant_pub = merchant_pub, |
208 | GNUNET_CRYPTO_eddsa_verify ( | 196 | .h_wire = td.h_wire |
209 | TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT, | 197 | }; |
210 | &wdp, | 198 | |
211 | &exchange_sig.eddsa_signature, | 199 | TALER_amount_hton (&wdp.total, |
212 | &exchange_pub.eddsa_pub)) | 200 | &td.total_amount); |
213 | { | 201 | TALER_amount_hton (&wdp.wire_fee, |
214 | GNUNET_break_op (0); | 202 | &td.wire_fee); |
215 | GNUNET_JSON_parse_free (spec); | 203 | GNUNET_CRYPTO_hash_context_finish (hash_context, |
216 | return GNUNET_SYSERR; | 204 | &wdp.h_details); |
205 | if (GNUNET_OK != | ||
206 | GNUNET_CRYPTO_eddsa_verify ( | ||
207 | TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT, | ||
208 | &wdp, | ||
209 | &td.exchange_sig.eddsa_signature, | ||
210 | &td.exchange_pub.eddsa_pub)) | ||
211 | { | ||
212 | GNUNET_break_op (0); | ||
213 | GNUNET_JSON_parse_free (spec); | ||
214 | GNUNET_free (details); | ||
215 | return GNUNET_SYSERR; | ||
216 | } | ||
217 | } | 217 | } |
218 | 218 | ||
219 | if (0 > | 219 | if (0 > |
220 | TALER_amount_subtract (&total_expected, | 220 | TALER_amount_subtract (&total_expected, |
221 | &total_expected, | 221 | &total_expected, |
222 | &wire_fee)) | 222 | &td.wire_fee)) |
223 | { | 223 | { |
224 | GNUNET_break_op (0); | 224 | GNUNET_break_op (0); |
225 | GNUNET_JSON_parse_free (spec); | 225 | GNUNET_JSON_parse_free (spec); |
226 | GNUNET_free (details); | ||
226 | return GNUNET_SYSERR; | 227 | return GNUNET_SYSERR; |
227 | } | 228 | } |
228 | if (0 != | 229 | if (0 != |
229 | TALER_amount_cmp (&total_expected, | 230 | TALER_amount_cmp (&total_expected, |
230 | &total_amount)) | 231 | &td.total_amount)) |
231 | { | 232 | { |
232 | GNUNET_break_op (0); | 233 | GNUNET_break_op (0); |
233 | GNUNET_JSON_parse_free (spec); | 234 | GNUNET_JSON_parse_free (spec); |
235 | GNUNET_free (details); | ||
234 | return GNUNET_SYSERR; | 236 | return GNUNET_SYSERR; |
235 | } | 237 | } |
236 | wdh->cb (wdh->cb_cls, | 238 | wdh->cb (wdh->cb_cls, |
237 | &hr, | 239 | &hr, |
238 | &exchange_pub, | 240 | &td); |
239 | &h_wire, | 241 | GNUNET_free (details); |
240 | exec_time, | ||
241 | &total_amount, | ||
242 | &wire_fee, | ||
243 | num_details, | ||
244 | details); | ||
245 | } | 242 | } |
246 | GNUNET_JSON_parse_free (spec); | 243 | GNUNET_JSON_parse_free (spec); |
247 | TALER_EXCHANGE_transfers_get_cancel (wdh); | 244 | TALER_EXCHANGE_transfers_get_cancel (wdh); |
@@ -322,12 +319,7 @@ handle_transfers_get_finished (void *cls, | |||
322 | } | 319 | } |
323 | wdh->cb (wdh->cb_cls, | 320 | wdh->cb (wdh->cb_cls, |
324 | &hr, | 321 | &hr, |
325 | NULL, | 322 | NULL); |
326 | NULL, | ||
327 | GNUNET_TIME_UNIT_ZERO_ABS, | ||
328 | NULL, | ||
329 | NULL, | ||
330 | 0, NULL); | ||
331 | TALER_EXCHANGE_transfers_get_cancel (wdh); | 323 | TALER_EXCHANGE_transfers_get_cancel (wdh); |
332 | } | 324 | } |
333 | 325 | ||