diff options
Diffstat (limited to 'src/mint/taler-mint-httpd_keystate.c')
-rw-r--r-- | src/mint/taler-mint-httpd_keystate.c | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/src/mint/taler-mint-httpd_keystate.c b/src/mint/taler-mint-httpd_keystate.c index c35ed15ad..bbec042e3 100644 --- a/src/mint/taler-mint-httpd_keystate.c +++ b/src/mint/taler-mint-httpd_keystate.c | |||
@@ -48,8 +48,8 @@ static int reload_pipe[2]; | |||
48 | 48 | ||
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Convert the public part of a denomination key | 51 | * Convert the public part of a denomination key issue to a JSON |
52 | * issue to a JSON object. | 52 | * object. |
53 | * | 53 | * |
54 | * @param dki the denomination key issue | 54 | * @param dki the denomination key issue |
55 | * @return a JSON object describing the denomination key isue (public part) | 55 | * @return a JSON object describing the denomination key isue (public part) |
@@ -61,37 +61,45 @@ denom_key_issue_to_json (const struct TALER_MINT_DenomKeyIssue *dki) | |||
61 | size_t buf_len; | 61 | size_t buf_len; |
62 | json_t *dk_json = json_object (); | 62 | json_t *dk_json = json_object (); |
63 | 63 | ||
64 | json_object_set_new (dk_json, "master_sig", | 64 | json_object_set_new (dk_json, |
65 | TALER_JSON_from_data (&dki->signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature))); | 65 | "master_sig", |
66 | json_object_set_new (dk_json, "stamp_start", TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->start))); | 66 | TALER_JSON_from_data (&dki->signature, |
67 | json_object_set_new (dk_json, "stamp_expire_withdraw", TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_withdraw))); | 67 | sizeof (struct GNUNET_CRYPTO_EddsaSignature))); |
68 | json_object_set_new (dk_json, "stamp_expire_deposit", TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_spend))); | 68 | json_object_set_new (dk_json, |
69 | 69 | "stamp_start", | |
70 | TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->start))); | ||
71 | json_object_set_new (dk_json, | ||
72 | "stamp_expire_withdraw", | ||
73 | TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_withdraw))); | ||
74 | json_object_set_new (dk_json, | ||
75 | "stamp_expire_deposit", | ||
76 | TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_spend))); | ||
70 | 77 | ||
71 | buf_len = GNUNET_CRYPTO_rsa_public_key_encode (dki->denom_pub, | 78 | buf_len = GNUNET_CRYPTO_rsa_public_key_encode (dki->denom_pub, |
72 | &buf); | 79 | &buf); |
73 | json_object_set_new (dk_json, "denom_pub", | 80 | json_object_set_new (dk_json, |
81 | "denom_pub", | ||
74 | TALER_JSON_from_data (buf, | 82 | TALER_JSON_from_data (buf, |
75 | buf_len)); | 83 | buf_len)); |
76 | GNUNET_free (buf); | 84 | GNUNET_free (buf); |
77 | json_object_set_new (dk_json, "value", | 85 | json_object_set_new (dk_json, |
86 | "value", | ||
78 | TALER_JSON_from_amount (TALER_amount_ntoh (dki->value))); | 87 | TALER_JSON_from_amount (TALER_amount_ntoh (dki->value))); |
79 | json_object_set_new (dk_json, | 88 | json_object_set_new (dk_json, |
80 | "fee_withdraw", | 89 | "fee_withdraw", |
81 | TALER_JSON_from_amount(TALER_amount_ntoh (dki->fee_withdraw))); | 90 | TALER_JSON_from_amount (TALER_amount_ntoh (dki->fee_withdraw))); |
82 | json_object_set_new (dk_json, | 91 | json_object_set_new (dk_json, |
83 | "fee_deposit", | 92 | "fee_deposit", |
84 | TALER_JSON_from_amount(TALER_amount_ntoh (dki->fee_deposit))); | 93 | TALER_JSON_from_amount (TALER_amount_ntoh (dki->fee_deposit))); |
85 | json_object_set_new (dk_json, | 94 | json_object_set_new (dk_json, |
86 | "fee_refresh", | 95 | "fee_refresh", |
87 | TALER_JSON_from_amount(TALER_amount_ntoh (dki->fee_refresh))); | 96 | TALER_JSON_from_amount (TALER_amount_ntoh (dki->fee_refresh))); |
88 | return dk_json; | 97 | return dk_json; |
89 | } | 98 | } |
90 | 99 | ||
91 | 100 | ||
92 | /** | 101 | /** |
93 | * Convert the public part of a sign key | 102 | * Convert the public part of a sign key issue to a JSON object. |
94 | * issue to a JSON object. | ||
95 | * | 103 | * |
96 | * @param ski the sign key issue | 104 | * @param ski the sign key issue |
97 | * @return a JSON object describing the sign key isue (public part) | 105 | * @return a JSON object describing the sign key isue (public part) |
@@ -111,7 +119,8 @@ sign_key_issue_to_json (const struct TALER_MINT_SignKeyIssue *ski) | |||
111 | "master_sig", | 119 | "master_sig", |
112 | TALER_JSON_from_data (&ski->signature, | 120 | TALER_JSON_from_data (&ski->signature, |
113 | sizeof (struct GNUNET_CRYPTO_EddsaSignature))); | 121 | sizeof (struct GNUNET_CRYPTO_EddsaSignature))); |
114 | json_object_set_new (sk_json, "key", | 122 | json_object_set_new (sk_json, |
123 | "key", | ||
115 | TALER_JSON_from_data (&ski->signkey_pub, | 124 | TALER_JSON_from_data (&ski->signkey_pub, |
116 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))); | 125 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))); |
117 | return sk_json; | 126 | return sk_json; |
@@ -266,7 +275,8 @@ reload_keys () | |||
266 | key_state->sign_keys_array = json_array (); | 275 | key_state->sign_keys_array = json_array (); |
267 | GNUNET_assert (NULL != key_state->sign_keys_array); | 276 | GNUNET_assert (NULL != key_state->sign_keys_array); |
268 | 277 | ||
269 | key_state->denomkey_map = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); | 278 | key_state->denomkey_map = GNUNET_CONTAINER_multihashmap_create (32, |
279 | GNUNET_NO); | ||
270 | GNUNET_assert (NULL != key_state->denomkey_map); | 280 | GNUNET_assert (NULL != key_state->denomkey_map); |
271 | 281 | ||
272 | key_state->reload_time = GNUNET_TIME_absolute_get (); | 282 | key_state->reload_time = GNUNET_TIME_absolute_get (); |
@@ -275,7 +285,8 @@ reload_keys () | |||
275 | TALER_MINT_signkeys_iterate (mintdir, &reload_keys_sign_iter, key_state); | 285 | TALER_MINT_signkeys_iterate (mintdir, &reload_keys_sign_iter, key_state); |
276 | 286 | ||
277 | keys = json_pack ("{s:o, s:o, s:o, s:o}", | 287 | keys = json_pack ("{s:o, s:o, s:o, s:o}", |
278 | "master_pub", TALER_JSON_from_data (&master_pub, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)), | 288 | "master_pub", TALER_JSON_from_data (&master_pub, |
289 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)), | ||
279 | "signkeys", key_state->sign_keys_array, | 290 | "signkeys", key_state->sign_keys_array, |
280 | "denoms", key_state->denom_keys_array, | 291 | "denoms", key_state->denom_keys_array, |
281 | "list_issue_date", TALER_JSON_from_abs (key_state->reload_time)); | 292 | "list_issue_date", TALER_JSON_from_abs (key_state->reload_time)); |
@@ -295,9 +306,10 @@ void | |||
295 | TALER_MINT_key_state_release (struct MintKeyState *key_state) | 306 | TALER_MINT_key_state_release (struct MintKeyState *key_state) |
296 | { | 307 | { |
297 | GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex)); | 308 | GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex)); |
298 | GNUNET_assert (0 != key_state->refcnt); | 309 | GNUNET_assert (0 < key_state->refcnt); |
299 | key_state->refcnt += 1; | 310 | key_state->refcnt--; |
300 | if (key_state->refcnt == 0) { | 311 | if (0 == key_state->refcnt) |
312 | { | ||
301 | GNUNET_free (key_state); | 313 | GNUNET_free (key_state); |
302 | } | 314 | } |
303 | GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex)); | 315 | GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex)); |
@@ -317,9 +329,6 @@ TALER_MINT_key_state_acquire (void) | |||
317 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 329 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
318 | struct MintKeyState *key_state; | 330 | struct MintKeyState *key_state; |
319 | 331 | ||
320 | // FIXME: the locking we have is very coarse-grained, | ||
321 | // using multiple locks might be nicer ... | ||
322 | |||
323 | GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex)); | 332 | GNUNET_assert (0 == pthread_mutex_lock (&internal_key_state_mutex)); |
324 | if (NULL == internal_key_state) | 333 | if (NULL == internal_key_state) |
325 | { | 334 | { |
@@ -327,14 +336,14 @@ TALER_MINT_key_state_acquire (void) | |||
327 | } | 336 | } |
328 | else if (internal_key_state->next_reload.abs_value_us <= now.abs_value_us) | 337 | else if (internal_key_state->next_reload.abs_value_us <= now.abs_value_us) |
329 | { | 338 | { |
330 | GNUNET_assert (0 != internal_key_state->refcnt); | 339 | GNUNET_assert (0 < internal_key_state->refcnt); |
331 | internal_key_state->refcnt--; | 340 | internal_key_state->refcnt--; |
332 | if (0 == internal_key_state->refcnt) | 341 | if (0 == internal_key_state->refcnt) |
333 | GNUNET_free (internal_key_state); | 342 | GNUNET_free (internal_key_state); |
334 | internal_key_state = reload_keys (); | 343 | internal_key_state = reload_keys (); |
335 | } | 344 | } |
336 | key_state = internal_key_state; | 345 | key_state = internal_key_state; |
337 | key_state->refcnt += 1; | 346 | key_state->refcnt++; |
338 | GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex)); | 347 | GNUNET_assert (0 == pthread_mutex_unlock (&internal_key_state_mutex)); |
339 | 348 | ||
340 | return key_state; | 349 | return key_state; |
@@ -353,7 +362,6 @@ struct TALER_MINT_DenomKeyIssuePriv * | |||
353 | TALER_MINT_get_denom_key (const struct MintKeyState *key_state, | 362 | TALER_MINT_get_denom_key (const struct MintKeyState *key_state, |
354 | const struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub) | 363 | const struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub) |
355 | { | 364 | { |
356 | struct TALER_MINT_DenomKeyIssuePriv *issue; | ||
357 | struct GNUNET_HashCode hash; | 365 | struct GNUNET_HashCode hash; |
358 | char *buf; | 366 | char *buf; |
359 | size_t buf_len; | 367 | size_t buf_len; |
@@ -364,8 +372,8 @@ TALER_MINT_get_denom_key (const struct MintKeyState *key_state, | |||
364 | buf_len, | 372 | buf_len, |
365 | &hash); | 373 | &hash); |
366 | GNUNET_free (buf); | 374 | GNUNET_free (buf); |
367 | issue = GNUNET_CONTAINER_multihashmap_get (key_state->denomkey_map, &hash); | 375 | return GNUNET_CONTAINER_multihashmap_get (key_state->denomkey_map, |
368 | return issue; | 376 | &hash); |
369 | } | 377 | } |
370 | 378 | ||
371 | 379 | ||
@@ -479,6 +487,4 @@ TALER_MINT_keys_sign (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | |||
479 | } | 487 | } |
480 | 488 | ||
481 | 489 | ||
482 | |||
483 | |||
484 | /* end of taler-mint-httpd_keystate.c */ | 490 | /* end of taler-mint-httpd_keystate.c */ |