diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/exchange_api_common.c | 19 | ||||
| -rw-r--r-- | src/lib/exchange_api_common.h | 4 | ||||
| -rw-r--r-- | src/lib/exchange_api_purse_create_with_deposit.c | 30 | ||||
| -rw-r--r-- | src/lib/exchange_api_purse_deposit.c | 46 | 
4 files changed, 85 insertions, 14 deletions
| diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c index 4b36aa93..26ddb3c0 100644 --- a/src/lib/exchange_api_common.c +++ b/src/lib/exchange_api_common.c @@ -1170,13 +1170,22 @@ help_purse_deposit (struct CoinHistoryParseContext *pc,    struct TALER_CoinSpendSignatureP coin_sig;    const char *exchange_base_url;    bool refunded; +  struct TALER_AgeCommitmentHash phac = { 0 };    struct GNUNET_JSON_Specification spec[] = {      GNUNET_JSON_spec_fixed_auto ("purse_pub",                                   &purse_pub),      GNUNET_JSON_spec_fixed_auto ("coin_sig",                                   &coin_sig), +    GNUNET_JSON_spec_mark_optional ( +      GNUNET_JSON_spec_fixed_auto ("h_age_commitment", +                                   &coin_sig), +      NULL),      GNUNET_JSON_spec_string ("exchange_base_url",                               &exchange_base_url), +    GNUNET_JSON_spec_mark_optional ( +      GNUNET_JSON_spec_fixed_auto ("h_age_commitment", +                                   &phac), +      NULL),      GNUNET_JSON_spec_bool ("refunded",                             &refunded),      GNUNET_JSON_spec_end () @@ -1195,6 +1204,8 @@ help_purse_deposit (struct CoinHistoryParseContext *pc,          exchange_base_url,          &purse_pub,          amount, +        &pc->dk->h_key, +        &phac,          pc->coin_pub,          &coin_sig))    { @@ -1560,12 +1571,18 @@ TALER_EXCHANGE_check_purse_coin_conflict_ (    const struct TALER_PurseContractPublicKeyP *purse_pub,    const char *exchange_url,    const json_t *proof, +  struct TALER_DenominationHashP *h_denom_pub, +  struct TALER_AgeCommitmentHash *phac,    struct TALER_CoinSpendPublicKeyP *coin_pub,    struct TALER_CoinSpendSignatureP *coin_sig)  {    const char *partner_url = NULL;    struct TALER_Amount amount;    struct GNUNET_JSON_Specification spec[] = { +    GNUNET_JSON_spec_fixed_auto ("h_denom_pub", +                                 h_denom_pub), +    GNUNET_JSON_spec_fixed_auto ("h_age_commitment", +                                 phac),      GNUNET_JSON_spec_fixed_auto ("coin_sig",                                   coin_sig),      GNUNET_JSON_spec_fixed_auto ("coin_pub", @@ -1594,6 +1611,8 @@ TALER_EXCHANGE_check_purse_coin_conflict_ (          partner_url,          purse_pub,          &amount, +        h_denom_pub, +        phac,          coin_pub,          coin_sig))    { diff --git a/src/lib/exchange_api_common.h b/src/lib/exchange_api_common.h index 5721b376..f4737ca9 100644 --- a/src/lib/exchange_api_common.h +++ b/src/lib/exchange_api_common.h @@ -75,6 +75,8 @@ TALER_EXCHANGE_check_purse_merge_conflict_ (   * @param purse_pub the public key of the purse   * @param exchange_url base URL of our exchange   * @param proof the proof to check + * @param[out] h_denom_pub hash of the coin's denomination + * @param[out] phac age commitment hash of the coin   * @param[out] coin_pub set to the conflicting coin   * @param[out] coin_sig set to the conflicting signature   * @return #GNUNET_OK if the @a proof is OK for @a purse_pub and showing that @a coin_pub was spent using @a coin_sig. @@ -84,6 +86,8 @@ TALER_EXCHANGE_check_purse_coin_conflict_ (    const struct TALER_PurseContractPublicKeyP *purse_pub,    const char *exchange_url,    const json_t *proof, +  struct TALER_DenominationHashP *h_denom_pub, +  struct TALER_AgeCommitmentHash *phac,    struct TALER_CoinSpendPublicKeyP *coin_pub,    struct TALER_CoinSpendSignatureP *coin_sig); diff --git a/src/lib/exchange_api_purse_create_with_deposit.c b/src/lib/exchange_api_purse_create_with_deposit.c index fa1de60b..3a5b7df5 100644 --- a/src/lib/exchange_api_purse_create_with_deposit.c +++ b/src/lib/exchange_api_purse_create_with_deposit.c @@ -55,6 +55,11 @@ struct Deposit    struct TALER_DenominationHashP h_denom_pub;    /** +   * Age restriction hash for the coin. +   */ +  struct TALER_AgeCommitmentHash ahac; + +  /**     * How much did we say the coin contributed.     */    struct TALER_Amount contribution; @@ -375,6 +380,8 @@ handle_purse_create_deposit_finished (void *cls,          {            struct TALER_CoinSpendPublicKeyP coin_pub;            struct TALER_CoinSpendSignatureP coin_sig; +          struct TALER_DenominationHashP h_denom_pub; +          struct TALER_AgeCommitmentHash phac;            bool found = false;            if (GNUNET_OK != @@ -382,6 +389,8 @@ handle_purse_create_deposit_finished (void *cls,                  &pch->purse_pub,                  pch->exchange->url,                  j, +                &h_denom_pub, +                &phac,                  &coin_pub,                  &coin_sig))            { @@ -398,6 +407,20 @@ handle_purse_create_deposit_finished (void *cls,                  GNUNET_memcmp (&coin_pub,                                 &deposit->coin_pub))                continue; +            if (0 != +                GNUNET_memcmp (&deposit->h_denom_pub, +                               &h_denom_pub)) +            { +              found = true; +              break; +            } +            if (0 != +                GNUNET_memcmp (&deposit->ahac, +                               &phac)) +            { +              found = true; +              break; +            }              if (0 ==                  GNUNET_memcmp (&coin_sig,                                 &deposit->coin_sig)) @@ -571,7 +594,6 @@ TALER_EXCHANGE_purse_create_with_deposit (      const struct TALER_AgeCommitmentProof *acp = deposit->age_commitment_proof;      struct Deposit *d = &pch->deposits[i];      json_t *jdeposit; -    struct TALER_AgeCommitmentHash agh;      struct TALER_AgeCommitmentHash *aghp = NULL;      struct TALER_AgeAttestation attest;      struct TALER_AgeAttestation *attestp = NULL; @@ -579,8 +601,8 @@ TALER_EXCHANGE_purse_create_with_deposit (      if (NULL != acp)      {        TALER_age_commitment_hash (&acp->commitment, -                                 &agh); -      aghp = &agh; +                                 &d->ahac); +      aghp = &d->ahac;        if (GNUNET_OK !=            TALER_age_commitment_attest (acp,                                         min_age, @@ -601,6 +623,8 @@ TALER_EXCHANGE_purse_create_with_deposit (        url,        &pch->purse_pub,        &deposit->amount, +      &d->h_denom_pub, +      &d->ahac,        &deposit->coin_priv,        &d->coin_sig);      jdeposit = GNUNET_JSON_PACK ( diff --git a/src/lib/exchange_api_purse_deposit.c b/src/lib/exchange_api_purse_deposit.c index 836183bb..92225101 100644 --- a/src/lib/exchange_api_purse_deposit.c +++ b/src/lib/exchange_api_purse_deposit.c @@ -55,6 +55,11 @@ struct Coin    struct TALER_DenominationHashP h_denom_pub;    /** +   * Age restriction hash for the coin. +   */ +  struct TALER_AgeCommitmentHash ahac; + +  /**     * How much did we say the coin contributed.     */    struct TALER_Amount contribution; @@ -234,6 +239,8 @@ handle_purse_deposit_finished (void *cls,        {          struct TALER_CoinSpendPublicKeyP coin_pub;          struct TALER_CoinSpendSignatureP coin_sig; +        struct TALER_DenominationHashP h_denom_pub; +        struct TALER_AgeCommitmentHash phac;          bool found = false;          if (GNUNET_OK != @@ -241,6 +248,8 @@ handle_purse_deposit_finished (void *cls,                &pch->purse_pub,                pch->base_url,                j, +              &h_denom_pub, +              &phac,                &coin_pub,                &coin_sig))          { @@ -251,18 +260,32 @@ handle_purse_deposit_finished (void *cls,          }          for (unsigned int i = 0; i<pch->num_deposits; i++)          { -          if (0 == GNUNET_memcmp (&coin_pub, -                                  &pch->coins[i].coin_pub)) +          struct Coin *coin = &pch->coins[i]; +          if (0 != GNUNET_memcmp (&coin_pub, +                                  &coin->coin_pub)) +            continue; +          if (0 != +              GNUNET_memcmp (&coin->h_denom_pub, +                             &h_denom_pub)) +          { +            found = true; +            break; +          } +          if (0 != +              GNUNET_memcmp (&coin->ahac, +                             &phac))            { -            if (0 == GNUNET_memcmp (&coin_sig, -                                    &pch->coins[i].coin_sig)) -            { -              /* identical signature => not a conflict */ -              continue; -            }              found = true;              break;            } +          if (0 == GNUNET_memcmp (&coin_sig, +                                  &coin->coin_sig)) +          { +            /* identical signature => not a conflict */ +            continue; +          } +          found = true; +          break;          }          if (! found)          { @@ -488,7 +511,6 @@ TALER_EXCHANGE_purse_deposit (      const struct TALER_AgeCommitmentProof *acp = deposit->age_commitment_proof;      struct Coin *coin = &pch->coins[i];      json_t *jdeposit; -    struct TALER_AgeCommitmentHash ach;      struct TALER_AgeCommitmentHash *achp = NULL;      struct TALER_AgeAttestation attest;      struct TALER_AgeAttestation *attestp = NULL; @@ -496,8 +518,8 @@ TALER_EXCHANGE_purse_deposit (      if (NULL != acp)      {        TALER_age_commitment_hash (&acp->commitment, -                                 &ach); -      achp = &ach; +                                 &coin->ahac); +      achp = &coin->ahac;        if (GNUNET_OK !=            TALER_age_commitment_attest (acp,                                         min_age, @@ -520,6 +542,8 @@ TALER_EXCHANGE_purse_deposit (        pch->base_url,        &pch->purse_pub,        &deposit->amount, +      &coin->h_denom_pub, +      &coin->ahac,        &deposit->coin_priv,        &coin->coin_sig);      jdeposit = GNUNET_JSON_PACK ( | 
