diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 2 | ||||
-rw-r--r-- | src/util/crypto_helper_rsa.c (renamed from src/util/crypto_helper_denom.c) | 66 | ||||
-rw-r--r-- | src/util/denom.c | 16 | ||||
-rw-r--r-- | src/util/secmod_signatures.c | 18 | ||||
-rw-r--r-- | src/util/taler-exchange-secmod-rsa.c | 52 | ||||
-rw-r--r-- | src/util/taler-exchange-secmod-rsa.h | 12 |
6 files changed, 90 insertions, 76 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index eefdcef45..7f2a2314d 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -79,7 +79,7 @@ libtalerutil_la_SOURCES = \ config.c \ crypto.c \ crypto_helper_common.c \ - crypto_helper_denom.c \ + crypto_helper_rsa.c \ crypto_helper_esign.c \ crypto_wire.c \ denom.c \ diff --git a/src/util/crypto_helper_denom.c b/src/util/crypto_helper_rsa.c index 5aa60a24f..8c3be457f 100644 --- a/src/util/crypto_helper_denom.c +++ b/src/util/crypto_helper_rsa.c @@ -26,12 +26,12 @@ #include "crypto_helper_common.h" -struct TALER_CRYPTO_DenominationHelper +struct TALER_CRYPTO_RsaDenominationHelper { /** * Function to call with updates to available key material. */ - TALER_CRYPTO_DenominationKeyStatusCallback dkc; + TALER_CRYPTO_RsaDenominationKeyStatusCallback dkc; /** * Closure for @e dkc @@ -63,7 +63,7 @@ struct TALER_CRYPTO_DenominationHelper * @param[in,out] dh handle to tear down connection of */ static void -do_disconnect (struct TALER_CRYPTO_DenominationHelper *dh) +do_disconnect (struct TALER_CRYPTO_RsaDenominationHelper *dh) { GNUNET_break (0 == close (dh->sock)); dh->sock = -1; @@ -79,7 +79,7 @@ do_disconnect (struct TALER_CRYPTO_DenominationHelper *dh) * @return #GNUNET_OK on success */ static enum GNUNET_GenericReturnValue -try_connect (struct TALER_CRYPTO_DenominationHelper *dh) +try_connect (struct TALER_CRYPTO_RsaDenominationHelper *dh) { if (-1 != dh->sock) return GNUNET_OK; @@ -107,13 +107,13 @@ try_connect (struct TALER_CRYPTO_DenominationHelper *dh) } -struct TALER_CRYPTO_DenominationHelper * -TALER_CRYPTO_helper_denom_connect ( +struct TALER_CRYPTO_RsaDenominationHelper * +TALER_CRYPTO_helper_rsa_connect ( const struct GNUNET_CONFIGURATION_Handle *cfg, - TALER_CRYPTO_DenominationKeyStatusCallback dkc, + TALER_CRYPTO_RsaDenominationKeyStatusCallback dkc, void *dkc_cls) { - struct TALER_CRYPTO_DenominationHelper *dh; + struct TALER_CRYPTO_RsaDenominationHelper *dh; char *unixpath; if (GNUNET_OK != @@ -138,7 +138,7 @@ TALER_CRYPTO_helper_denom_connect ( GNUNET_free (unixpath); return NULL; } - dh = GNUNET_new (struct TALER_CRYPTO_DenominationHelper); + dh = GNUNET_new (struct TALER_CRYPTO_RsaDenominationHelper); dh->dkc = dkc; dh->dkc_cls = dkc_cls; dh->sa.sun_family = AF_UNIX; @@ -150,10 +150,10 @@ TALER_CRYPTO_helper_denom_connect ( if (GNUNET_OK != try_connect (dh)) { - TALER_CRYPTO_helper_denom_disconnect (dh); + TALER_CRYPTO_helper_rsa_disconnect (dh); return NULL; } - TALER_CRYPTO_helper_denom_poll (dh); + TALER_CRYPTO_helper_rsa_poll (dh); return dh; } @@ -166,7 +166,7 @@ TALER_CRYPTO_helper_denom_connect ( * @return #GNUNET_OK on success */ static enum GNUNET_GenericReturnValue -handle_mt_avail (struct TALER_CRYPTO_DenominationHelper *dh, +handle_mt_avail (struct TALER_CRYPTO_RsaDenominationHelper *dh, const struct GNUNET_MessageHeader *hdr) { const struct TALER_CRYPTO_RsaKeyAvailableNotification *kan @@ -196,7 +196,7 @@ handle_mt_avail (struct TALER_CRYPTO_DenominationHelper *dh, { struct TALER_DenominationPublicKey denom_pub; - struct TALER_DenominationHash h_denom_pub; + struct TALER_RsaPubHashP h_rsa; denom_pub.cipher = TALER_DENOMINATION_RSA; denom_pub.details.rsa_public_key @@ -208,14 +208,14 @@ handle_mt_avail (struct TALER_CRYPTO_DenominationHelper *dh, return GNUNET_SYSERR; } GNUNET_CRYPTO_rsa_public_key_hash (denom_pub.details.rsa_public_key, - &h_denom_pub.hash); + &h_rsa.hash); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received RSA key %s (%s)\n", - GNUNET_h2s (&h_denom_pub.hash), + GNUNET_h2s (&h_rsa.hash), section_name); if (GNUNET_OK != - TALER_exchange_secmod_denom_verify ( - &h_denom_pub, + TALER_exchange_secmod_rsa_verify ( + &h_rsa, section_name, GNUNET_TIME_absolute_ntoh (kan->anchor_time), GNUNET_TIME_relative_ntoh (kan->duration_withdraw), @@ -230,7 +230,7 @@ handle_mt_avail (struct TALER_CRYPTO_DenominationHelper *dh, section_name, GNUNET_TIME_absolute_ntoh (kan->anchor_time), GNUNET_TIME_relative_ntoh (kan->duration_withdraw), - &h_denom_pub, + &h_rsa, &denom_pub, &kan->secm_pub, &kan->secm_sig); @@ -248,7 +248,7 @@ handle_mt_avail (struct TALER_CRYPTO_DenominationHelper *dh, * @return #GNUNET_OK on success */ static enum GNUNET_GenericReturnValue -handle_mt_purge (struct TALER_CRYPTO_DenominationHelper *dh, +handle_mt_purge (struct TALER_CRYPTO_RsaDenominationHelper *dh, const struct GNUNET_MessageHeader *hdr) { const struct TALER_CRYPTO_RsaKeyPurgeNotification *pn @@ -261,12 +261,12 @@ handle_mt_purge (struct TALER_CRYPTO_DenominationHelper *dh, } GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received revocation of denomination key %s\n", - GNUNET_h2s (&pn->h_denom_pub.hash)); + GNUNET_h2s (&pn->h_rsa.hash)); dh->dkc (dh->dkc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO, - &pn->h_denom_pub, + &pn->h_rsa, NULL, NULL, NULL); @@ -275,7 +275,7 @@ handle_mt_purge (struct TALER_CRYPTO_DenominationHelper *dh, void -TALER_CRYPTO_helper_denom_poll (struct TALER_CRYPTO_DenominationHelper *dh) +TALER_CRYPTO_helper_rsa_poll (struct TALER_CRYPTO_RsaDenominationHelper *dh) { char buf[UINT16_MAX]; size_t off = 0; @@ -376,9 +376,9 @@ more: struct TALER_BlindedDenominationSignature -TALER_CRYPTO_helper_denom_sign ( - struct TALER_CRYPTO_DenominationHelper *dh, - const struct TALER_DenominationHash *h_denom_pub, +TALER_CRYPTO_helper_rsa_sign ( + struct TALER_CRYPTO_RsaDenominationHelper *dh, + const struct TALER_RsaPubHashP *h_rsa, const void *msg, size_t msg_size, enum TALER_ErrorCode *ec) @@ -404,7 +404,7 @@ TALER_CRYPTO_helper_denom_sign ( sr->header.size = htons (sizeof (buf)); sr->header.type = htons (TALER_HELPER_RSA_MT_REQ_SIGN); sr->reserved = htonl (0); - sr->h_denom_pub = *h_denom_pub; + sr->h_rsa = *h_rsa; memcpy (&sr[1], msg, msg_size); @@ -568,14 +568,14 @@ end: void -TALER_CRYPTO_helper_denom_revoke ( - struct TALER_CRYPTO_DenominationHelper *dh, - const struct TALER_DenominationHash *h_denom_pub) +TALER_CRYPTO_helper_rsa_revoke ( + struct TALER_CRYPTO_RsaDenominationHelper *dh, + const struct TALER_RsaPubHashP *h_rsa) { struct TALER_CRYPTO_RevokeRequest rr = { .header.size = htons (sizeof (rr)), .header.type = htons (TALER_HELPER_RSA_MT_REQ_REVOKE), - .h_denom_pub = *h_denom_pub + .h_rsa = *h_rsa }; if (GNUNET_OK != @@ -593,13 +593,13 @@ TALER_CRYPTO_helper_denom_revoke ( } GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requested revocation of denomination key %s\n", - GNUNET_h2s (&h_denom_pub->hash)); + GNUNET_h2s (&h_rsa->hash)); } void -TALER_CRYPTO_helper_denom_disconnect ( - struct TALER_CRYPTO_DenominationHelper *dh) +TALER_CRYPTO_helper_rsa_disconnect ( + struct TALER_CRYPTO_RsaDenominationHelper *dh) { if (-1 != dh->sock) do_disconnect (dh); diff --git a/src/util/denom.c b/src/util/denom.c index bb1351406..b6b3764da 100644 --- a/src/util/denom.c +++ b/src/util/denom.c @@ -156,6 +156,22 @@ TALER_blinding_secret_create (union TALER_DenominationBlindingKeyP *bs) } +/** + * Hash @a rsa. + * + * @param rsa key to hash + * @param[out] h_rsa where to write the result + */ +void +TALER_rsa_pub_hash (const struct GNUNET_CRYPTO_RsaPublicKey *rsa, + struct TALER_RsaPubHashP *h_rsa) +{ + GNUNET_CRYPTO_rsa_public_key_hash (rsa, + &h_rsa->hash); + +} + + void TALER_denom_pub_hash (const struct TALER_DenominationPublicKey *denom_pub, struct TALER_DenominationHash *denom_hash) diff --git a/src/util/secmod_signatures.c b/src/util/secmod_signatures.c index f49cc20a5..077ce229a 100644 --- a/src/util/secmod_signatures.c +++ b/src/util/secmod_signatures.c @@ -70,8 +70,8 @@ TALER_exchange_secmod_eddsa_verify ( void -TALER_exchange_secmod_denom_sign ( - const struct TALER_DenominationHash *h_denom_pub, +TALER_exchange_secmod_rsa_sign ( + const struct TALER_RsaPubHashP *h_rsa, const char *section_name, struct GNUNET_TIME_Absolute start_sign, struct GNUNET_TIME_Relative duration, @@ -79,9 +79,9 @@ TALER_exchange_secmod_denom_sign ( struct TALER_SecurityModuleSignatureP *secm_sig) { struct TALER_DenominationKeyAnnouncementPS dka = { - .purpose.purpose = htonl (TALER_SIGNATURE_SM_DENOMINATION_KEY), + .purpose.purpose = htonl (TALER_SIGNATURE_SM_RSA_DENOMINATION_KEY), .purpose.size = htonl (sizeof (dka)), - .h_denom_pub = *h_denom_pub, + .h_rsa = *h_rsa, .anchor_time = GNUNET_TIME_absolute_hton (start_sign), .duration_withdraw = GNUNET_TIME_relative_hton (duration) }; @@ -97,8 +97,8 @@ TALER_exchange_secmod_denom_sign ( enum GNUNET_GenericReturnValue -TALER_exchange_secmod_denom_verify ( - const struct TALER_DenominationHash *h_denom_pub, +TALER_exchange_secmod_rsa_verify ( + const struct TALER_RsaPubHashP *h_rsa, const char *section_name, struct GNUNET_TIME_Absolute start_sign, struct GNUNET_TIME_Relative duration, @@ -106,9 +106,9 @@ TALER_exchange_secmod_denom_verify ( const struct TALER_SecurityModuleSignatureP *secm_sig) { struct TALER_DenominationKeyAnnouncementPS dka = { - .purpose.purpose = htonl (TALER_SIGNATURE_SM_DENOMINATION_KEY), + .purpose.purpose = htonl (TALER_SIGNATURE_SM_RSA_DENOMINATION_KEY), .purpose.size = htonl (sizeof (dka)), - .h_denom_pub = *h_denom_pub, + .h_rsa = *h_rsa, .anchor_time = GNUNET_TIME_absolute_hton (start_sign), .duration_withdraw = GNUNET_TIME_relative_hton (duration) }; @@ -117,7 +117,7 @@ TALER_exchange_secmod_denom_verify ( strlen (section_name) + 1, &dka.h_section_name); return - GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_SM_DENOMINATION_KEY, + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_SM_RSA_DENOMINATION_KEY, &dka, &secm_sig->eddsa_signature, &secm_pub->eddsa_pub); diff --git a/src/util/taler-exchange-secmod-rsa.c b/src/util/taler-exchange-secmod-rsa.c index 7133a661b..49121c70e 100644 --- a/src/util/taler-exchange-secmod-rsa.c +++ b/src/util/taler-exchange-secmod-rsa.c @@ -88,7 +88,7 @@ struct DenominationKey /** * Hash of this denomination's public key. */ - struct TALER_DenominationHash h_denom_pub; + struct TALER_RsaPubHashP h_rsa; /** * Time at which this key is supposed to become valid. @@ -258,12 +258,12 @@ notify_client_dk_add (struct TES_Client *client, an->section_name_len = htons ((uint16_t) nlen); an->anchor_time = GNUNET_TIME_absolute_hton (dk->anchor); an->duration_withdraw = GNUNET_TIME_relative_hton (denom->duration_withdraw); - TALER_exchange_secmod_denom_sign (&dk->h_denom_pub, - denom->section, - dk->anchor, - denom->duration_withdraw, - &TES_smpriv, - &an->secm_sig); + TALER_exchange_secmod_rsa_sign (&dk->h_rsa, + denom->section, + dk->anchor, + denom->duration_withdraw, + &TES_smpriv, + &an->secm_sig); an->secm_pub = TES_smpub; p = (void *) &an[1]; memcpy (p, @@ -275,7 +275,7 @@ notify_client_dk_add (struct TES_Client *client, nlen); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Sending RSA denomination key %s (%s)\n", - GNUNET_h2s (&dk->h_denom_pub.hash), + GNUNET_h2s (&dk->h_rsa.hash), denom->section); if (GNUNET_OK != TES_transmit (client->csock, @@ -306,12 +306,12 @@ notify_client_dk_del (struct TES_Client *client, struct TALER_CRYPTO_RsaKeyPurgeNotification pn = { .header.type = htons (TALER_HELPER_RSA_MT_PURGE), .header.size = htons (sizeof (pn)), - .h_denom_pub = dk->h_denom_pub + .h_rsa = dk->h_rsa }; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Sending RSA denomination expiration %s\n", - GNUNET_h2s (&dk->h_denom_pub.hash)); + GNUNET_h2s (&dk->h_rsa.hash)); if (GNUNET_OK != TES_transmit (client->csock, &pn.header)) @@ -345,7 +345,7 @@ handle_sign_request (struct TES_Client *client, GNUNET_assert (0 == pthread_mutex_lock (&keys_lock)); dk = GNUNET_CONTAINER_multihashmap_get (keys, - &sr->h_denom_pub.hash); + &sr->h_rsa.hash); if (NULL == dk) { struct TALER_CRYPTO_SignFailure sf = { @@ -357,7 +357,7 @@ handle_sign_request (struct TES_Client *client, GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Signing request failed, denomination key %s unknown\n", - GNUNET_h2s (&sr->h_denom_pub.hash)); + GNUNET_h2s (&sr->h_rsa.hash)); return TES_transmit (client->csock, &sf.header); } @@ -374,7 +374,7 @@ handle_sign_request (struct TES_Client *client, GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Signing request failed, denomination key %s is not yet valid\n", - GNUNET_h2s (&sr->h_denom_pub.hash)); + GNUNET_h2s (&sr->h_rsa.hash)); return TES_transmit (client->csock, &sf.header); } @@ -382,7 +382,7 @@ handle_sign_request (struct TES_Client *client, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received request to sign over %u bytes with key %s\n", (unsigned int) blinded_msg_size, - GNUNET_h2s (&sr->h_denom_pub.hash)); + GNUNET_h2s (&sr->h_rsa.hash)); GNUNET_assert (dk->rc < UINT_MAX); dk->rc++; GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock)); @@ -470,8 +470,8 @@ setup_key (struct DenominationKey *dk, } buf_size = GNUNET_CRYPTO_rsa_private_key_encode (priv, &buf); - GNUNET_CRYPTO_rsa_public_key_hash (pub, - &dk->h_denom_pub.hash); + TALER_rsa_pub_hash (pub, + &dk->h_rsa); GNUNET_asprintf (&dk->filename, "%s/%s/%llu", keydir, @@ -495,7 +495,7 @@ setup_key (struct DenominationKey *dk, GNUNET_free (buf); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Setup fresh private key %s at %s in `%s' (generation #%llu)\n", - GNUNET_h2s (&dk->h_denom_pub.hash), + GNUNET_h2s (&dk->h_rsa.hash), GNUNET_STRINGS_absolute_time_to_string (dk->anchor), dk->filename, (unsigned long long) key_gen); @@ -505,7 +505,7 @@ setup_key (struct DenominationKey *dk, if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( keys, - &dk->h_denom_pub.hash, + &dk->h_rsa.hash, dk, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { @@ -563,13 +563,13 @@ handle_revoke_request (struct TES_Client *client, GNUNET_assert (0 == pthread_mutex_lock (&keys_lock)); dk = GNUNET_CONTAINER_multihashmap_get (keys, - &rr->h_denom_pub.hash); + &rr->h_rsa.hash); if (NULL == dk) { GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock)); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Revocation request ignored, denomination key %s unknown\n", - GNUNET_h2s (&rr->h_denom_pub.hash)); + GNUNET_h2s (&rr->h_rsa.hash)); return GNUNET_OK; } @@ -877,7 +877,7 @@ update_keys (struct Denomination *denom, GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove ( keys, - &key->h_denom_pub.hash, + &key->h_rsa.hash, key)); if ( (! key->purge) && (0 != unlink (key->filename)) ) @@ -1029,19 +1029,19 @@ parse_key (struct Denomination *denom, dk->denom = denom; dk->anchor = anchor; dk->filename = GNUNET_strdup (filename); - GNUNET_CRYPTO_rsa_public_key_hash (pub, - &dk->h_denom_pub.hash); + TALER_rsa_pub_hash (pub, + &dk->h_rsa); dk->denom_pub = pub; if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( keys, - &dk->h_denom_pub.hash, + &dk->h_rsa.hash, dk, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Duplicate private key %s detected in file `%s'. Skipping.\n", - GNUNET_h2s (&dk->h_denom_pub.hash), + GNUNET_h2s (&dk->h_rsa.hash), filename); GNUNET_CRYPTO_rsa_private_key_free (priv); GNUNET_CRYPTO_rsa_public_key_free (pub); @@ -1063,7 +1063,7 @@ parse_key (struct Denomination *denom, dk); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Imported key %s from `%s'\n", - GNUNET_h2s (&dk->h_denom_pub.hash), + GNUNET_h2s (&dk->h_rsa.hash), filename); } } diff --git a/src/util/taler-exchange-secmod-rsa.h b/src/util/taler-exchange-secmod-rsa.h index 1723560a5..b0fdfbd96 100644 --- a/src/util/taler-exchange-secmod-rsa.h +++ b/src/util/taler-exchange-secmod-rsa.h @@ -35,6 +35,7 @@ GNUNET_NETWORK_STRUCT_BEGIN + /** * Message sent if a key is available. */ @@ -76,7 +77,7 @@ struct TALER_CRYPTO_RsaKeyAvailableNotification */ struct TALER_SecurityModuleSignatureP secm_sig; - /* followed by @e pub_size bytes of the public key */ + /* followed by @e pub_size bytes of the RSA public key */ /* followed by @e section_name bytes of the configuration section name of the denomination of this key */ @@ -102,8 +103,7 @@ struct TALER_CRYPTO_RsaKeyPurgeNotification /** * Hash of the public key of the purged RSA key. */ - // FIXME: wrong type, not hashed with age restriction here! - struct TALER_DenominationHash h_denom_pub; + struct TALER_RsaPubHashP h_rsa; }; @@ -126,8 +126,7 @@ struct TALER_CRYPTO_SignRequest /** * Hash of the public key of the RSA key to use for the signature. */ - // FIXME: wrong type, not hashed with age restriction here! - struct TALER_DenominationHash h_denom_pub; + struct TALER_RsaPubHashP h_rsa; /* followed by message to sign */ }; @@ -151,8 +150,7 @@ struct TALER_CRYPTO_RevokeRequest /** * Hash of the public key of the revoked RSA key. */ - // FIXME: wrong type, not hashed with age restriction here! - struct TALER_DenominationHash h_denom_pub; + struct TALER_RsaPubHashP h_rsa; }; |