diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-18 18:53:12 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-18 18:53:12 +0200 |
commit | 7b4623706c3a87b444362ca27027d9bfb1aa25ae (patch) | |
tree | e546a3407f4465be9110fffeaab3ae38c5f8c3b2 /src/util | |
parent | cb68cc7e5b03a03f335e121def044034978adf17 (diff) | |
parent | 17985453c560300dba044617bafdb8f682d29e4c (diff) |
Merge branch 'master' of git+ssh://taler.net/var/git/mint
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/crypto.c | 46 | ||||
-rw-r--r-- | src/util/json.c | 133 | ||||
-rw-r--r-- | src/util/os_installation.c | 2 | ||||
-rw-r--r-- | src/util/test_crypto.c | 16 | ||||
-rw-r--r-- | src/util/test_json.c | 146 | ||||
-rw-r--r-- | src/util/test_wireformats.c | 55 | ||||
-rw-r--r-- | src/util/wireformats.c | 20 |
7 files changed, 320 insertions, 98 deletions
diff --git a/src/util/crypto.c b/src/util/crypto.c index 562377e37..6e78259eb 100644 --- a/src/util/crypto.c +++ b/src/util/crypto.c @@ -50,7 +50,7 @@ fatal_error_handler (void *cls, /** * Initialize libgcrypt. */ -void +void __attribute__ ((constructor)) TALER_gcrypt_init () { gcry_set_fatalerror_handler (&fatal_error_handler, @@ -219,7 +219,7 @@ TALER_refresh_decrypt (const struct TALER_RefreshLinkEncrypted *input, ret = GNUNET_new (struct TALER_RefreshLinkDecrypted); memcpy (&ret->coin_priv, buf, - sizeof (union TALER_CoinSpendPrivateKeyP)); + sizeof (struct TALER_CoinSpendPrivateKeyP)); ret->blinding_key.rsa_blinding_key = GNUNET_CRYPTO_rsa_blinding_key_decode (&buf[sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)], input->blinding_key_enc_size); @@ -295,7 +295,7 @@ TALER_refresh_link_encrypted_decode (const char *buf, { struct TALER_RefreshLinkEncrypted *rle; - if (buf_len < sizeof (union TALER_CoinSpendPrivateKeyP)) + if (buf_len < sizeof (struct TALER_CoinSpendPrivateKeyP)) return NULL; if (buf_len >= GNUNET_MAX_MALLOC_CHECKED) { @@ -303,9 +303,9 @@ TALER_refresh_link_encrypted_decode (const char *buf, return NULL; } rle = GNUNET_malloc (sizeof (struct TALER_RefreshLinkEncrypted) + - buf_len - sizeof (union TALER_CoinSpendPrivateKeyP)); + buf_len - sizeof (struct TALER_CoinSpendPrivateKeyP)); rle->blinding_key_enc = (const char *) &rle[1]; - rle->blinding_key_enc_size = buf_len - sizeof (union TALER_CoinSpendPrivateKeyP); + rle->blinding_key_enc_size = buf_len - sizeof (struct TALER_CoinSpendPrivateKeyP); memcpy (rle->coin_priv_enc, buf, buf_len); @@ -326,12 +326,12 @@ TALER_refresh_link_encrypted_encode (const struct TALER_RefreshLinkEncrypted *rl { char *buf; - if (rle->blinding_key_enc_size >= GNUNET_MAX_MALLOC_CHECKED - sizeof (union TALER_CoinSpendPrivateKeyP)) + if (rle->blinding_key_enc_size >= GNUNET_MAX_MALLOC_CHECKED - sizeof (struct TALER_CoinSpendPrivateKeyP)) { GNUNET_break (0); return NULL; } - *buf_len = sizeof (union TALER_CoinSpendPrivateKeyP) + rle->blinding_key_enc_size; + *buf_len = sizeof (struct TALER_CoinSpendPrivateKeyP) + rle->blinding_key_enc_size; buf = GNUNET_malloc (*buf_len); memcpy (buf, rle->coin_priv_enc, @@ -376,7 +376,7 @@ TALER_test_coin_valid (const struct TALER_CoinPublicInfo *coin_public_info) * private key and the coin's public key. * * @param secret_enc encrypted link secret - * @param transfer_priv transfer private key + * @param trans_priv transfer private key * @param coin_pub coin public key * @param[out] secret set to the shared secret * @return #GNUNET_OK on success, #GNUNET_SYSERR on error @@ -384,15 +384,15 @@ TALER_test_coin_valid (const struct TALER_CoinPublicInfo *coin_public_info) int TALER_link_decrypt_secret (const struct TALER_EncryptedLinkSecretP *secret_enc, const struct TALER_TransferPrivateKeyP *trans_priv, - const union TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_CoinSpendPublicKeyP *coin_pub, struct TALER_LinkSecretP *secret) { struct TALER_TransferSecretP transfer_secret; if (GNUNET_OK != - GNUNET_CRYPTO_ecc_ecdh (&trans_priv->ecdhe_priv, - &coin_pub->ecdhe_pub, - &transfer_secret.key)) + GNUNET_CRYPTO_ecdh_eddsa (&trans_priv->ecdhe_priv, + &coin_pub->eddsa_pub, + &transfer_secret.key)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -415,7 +415,7 @@ TALER_link_decrypt_secret (const struct TALER_EncryptedLinkSecretP *secret_enc, * public key and the coin's private key. * * @param secret_enc encrypted link secret - * @param transfer_pub transfer public key + * @param trans_pub transfer public key * @param coin_priv coin private key * @param[out] secret set to the shared secret * @return #GNUNET_OK on success, #GNUNET_SYSERR on error @@ -423,15 +423,15 @@ TALER_link_decrypt_secret (const struct TALER_EncryptedLinkSecretP *secret_enc, int TALER_link_decrypt_secret2 (const struct TALER_EncryptedLinkSecretP *secret_enc, const struct TALER_TransferPublicKeyP *trans_pub, - const union TALER_CoinSpendPrivateKeyP *coin_priv, + const struct TALER_CoinSpendPrivateKeyP *coin_priv, struct TALER_LinkSecretP *secret) { struct TALER_TransferSecretP transfer_secret; if (GNUNET_OK != - GNUNET_CRYPTO_ecc_ecdh (&coin_priv->ecdhe_priv, - &trans_pub->ecdhe_pub, - &transfer_secret.key)) + GNUNET_CRYPTO_eddsa_ecdh (&coin_priv->eddsa_priv, + &trans_pub->ecdhe_pub, + &transfer_secret.key)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -454,14 +454,14 @@ TALER_link_decrypt_secret2 (const struct TALER_EncryptedLinkSecretP *secret_enc, * * @param secret link secret to encrypt * @param coin_pub coin public key - * @param transfer_priv[out] set to transfer private key - * @param transfer_pub[out] set to transfer public key + * @param[out] trans_priv set to transfer private key + * @param[out] trans_pub set to transfer public key * @param[out] secret_enc set to the encryptd @a secret * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int TALER_link_encrypt_secret (const struct TALER_LinkSecretP *secret, - const union TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_CoinSpendPublicKeyP *coin_pub, struct TALER_TransferPrivateKeyP *trans_priv, struct TALER_TransferPublicKeyP *trans_pub, struct TALER_EncryptedLinkSecretP *secret_enc) @@ -471,9 +471,9 @@ TALER_link_encrypt_secret (const struct TALER_LinkSecretP *secret, pk = GNUNET_CRYPTO_ecdhe_key_create (); if (GNUNET_OK != - GNUNET_CRYPTO_ecc_ecdh (pk, - &coin_pub->ecdhe_pub, - &transfer_secret.key)) + GNUNET_CRYPTO_ecdh_eddsa (pk, + &coin_pub->eddsa_pub, + &transfer_secret.key)) { GNUNET_break (0); GNUNET_free (pk); diff --git a/src/util/json.c b/src/util/json.c index 1cc04fe83..34e41e0d7 100644 --- a/src/util/json.c +++ b/src/util/json.c @@ -21,7 +21,6 @@ #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include "taler_util.h" -#include "taler_json_lib.h" /** * Shorthand for exit jumps. @@ -84,6 +83,9 @@ TALER_json_from_abs (struct GNUNET_TIME_Absolute stamp) json_t *j; char *mystr; int ret; + + if (stamp.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) + return json_string ("never"); ret = GNUNET_asprintf (&mystr, "%llu", (long long) (stamp.abs_value_us / (1000 * 1000))); @@ -129,58 +131,94 @@ TALER_json_from_eddsa_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpo /** - * Convert a signature (with purpose) to a JSON object representation. + * Convert RSA public key to JSON. * - * @param purpose purpose of the signature - * @param signature the signature - * @return the JSON reporesentation of the signature with purpose + * @param pk public key to convert + * @return corresponding JSON encoding */ json_t * -TALER_json_from_ecdsa_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, - const struct GNUNET_CRYPTO_EcdsaSignature *signature) +TALER_json_from_rsa_public_key (struct GNUNET_CRYPTO_rsa_PublicKey *pk) { - json_t *root; - json_t *el; - - root = json_object (); - - el = json_integer ((json_int_t) ntohl (purpose->size)); - json_object_set_new (root, "size", el); + char *buf; + size_t buf_len; + json_t *ret; - el = json_integer ((json_int_t) ntohl (purpose->purpose)); - json_object_set_new (root, "purpose", el); + buf_len = GNUNET_CRYPTO_rsa_public_key_encode (pk, + &buf); + ret = TALER_json_from_data (buf, + buf_len); + GNUNET_free (buf); + return ret; +} - el = TALER_json_from_data (purpose, - ntohl (purpose->size)); - json_object_set_new (root, "ecdsa_val", el); - el = TALER_json_from_data (signature, - sizeof (struct GNUNET_CRYPTO_EddsaSignature)); - json_object_set_new (root, "ecdsa_sig", el); +/** + * Convert JSON to RSA public key. + * + * @param pk JSON encoding to convert + * @return corresponding public key + */ +struct GNUNET_CRYPTO_rsa_PublicKey * +TALER_json_to_rsa_public_key (json_t *json) +{ + const char *enc; + char *buf; + size_t len; + size_t buf_len; + struct GNUNET_CRYPTO_rsa_PublicKey *pk; - return root; + buf = NULL; + EXITIF (NULL == (enc = json_string_value (json))); + len = strlen (enc); + buf_len = (len * 5) / 8; + buf = GNUNET_malloc (buf_len); + EXITIF (GNUNET_OK != + GNUNET_STRINGS_string_to_data (enc, + len, + buf, + buf_len)); + EXITIF (NULL == (pk = GNUNET_CRYPTO_rsa_public_key_decode (buf, + buf_len))); + GNUNET_free (buf); + return pk; + EXITIF_exit: + GNUNET_free_non_null (buf); + return NULL; } /** - * Convert RSA public key to JSON. + * Convert JSON to RSA signature. * - * @param pk public key to convert - * @return corresponding JSON encoding + * @param pk JSON encoding to convert + * @return corresponding signature */ -json_t * -TALER_json_from_rsa_public_key (struct GNUNET_CRYPTO_rsa_PublicKey *pk) +struct GNUNET_CRYPTO_rsa_Signature * +TALER_json_to_rsa_signature (json_t *json) { + const char *enc; char *buf; + size_t len; size_t buf_len; - json_t *ret; + struct GNUNET_CRYPTO_rsa_Signature *sig; - buf_len = GNUNET_CRYPTO_rsa_public_key_encode (pk, - &buf); - ret = TALER_json_from_data (buf, - buf_len); + buf = NULL; + EXITIF (NULL == (enc = json_string_value (json))); + len = strlen (enc); + buf_len = (len * 5) / 8; + buf = GNUNET_malloc (buf_len); + EXITIF (GNUNET_OK != + GNUNET_STRINGS_string_to_data (enc, + len, + buf, + buf_len)); + EXITIF (NULL == (sig = GNUNET_CRYPTO_rsa_signature_decode (buf, + buf_len))); GNUNET_free (buf); - return ret; + return sig; + EXITIF_exit: + GNUNET_free_non_null (buf); + return NULL; } @@ -229,20 +267,6 @@ TALER_json_from_data (const void *data, /** - * Convert binary hash to a JSON string with the base32crockford - * encoding. - * - * @param hc binary data - * @return json string that encodes @a hc - */ -json_t * -TALER_json_from_hash (const struct GNUNET_HashCode *hc) -{ - return TALER_json_from_data (hc, sizeof (struct GNUNET_HashCode)); -} - - -/** * Parse given JSON object to Amount * * @param json the json object representing Amount @@ -262,10 +286,13 @@ TALER_json_to_amount (json_t *json, &error, JSON_STRICT, "{s:s, s:I, s:I}", - "curreny", ¤cy, + "currency", ¤cy, "value", &value, "fraction", &fraction)); EXITIF (3 < strlen (currency)); + EXITIF (TALER_CURRENCY_LEN <= strlen (currency)); + strcpy (r_amount->currency, + currency); r_amount->value = (uint32_t) value; r_amount->fraction = (uint32_t) fraction; return GNUNET_OK; @@ -291,6 +318,12 @@ TALER_json_to_abs (json_t *json, GNUNET_assert (NULL != abs); EXITIF (NULL == (str = json_string_value (json))); + if (0 == strcasecmp (str, + "never")) + { + *abs = GNUNET_TIME_UNIT_FOREVER_ABS; + return GNUNET_OK; + } EXITIF (1 > sscanf (str, "%llu", &abs_value_s)); abs->abs_value_us = abs_value_s * 1000 * 1000; return GNUNET_OK; @@ -317,7 +350,7 @@ TALER_json_to_data (json_t *json, EXITIF (NULL == (enc = json_string_value (json))); len = strlen (enc); - EXITIF ((((len * 5) / 8) + ((((len * 5) % 8) == 0) ? 0 : 1)) == out_size); + EXITIF (((len * 5) / 8) != out_size); EXITIF (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, len, out, out_size)); return GNUNET_OK; EXITIF_exit: diff --git a/src/util/os_installation.c b/src/util/os_installation.c index ad89f4e58..1308fa3f3 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c @@ -454,7 +454,7 @@ os_get_exec_path () * @return a pointer to the dir path (to be freed by the caller) */ char * -TALER_os_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) +TALER_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) { size_t n; const char *dirname; diff --git a/src/util/test_crypto.c b/src/util/test_crypto.c index ce946dd53..a5313195a 100644 --- a/src/util/test_crypto.c +++ b/src/util/test_crypto.c @@ -71,7 +71,7 @@ test_basics () GNUNET_assert (NULL != rld); GNUNET_assert (0 == memcmp (&rld->coin_priv, &rl.coin_priv, - sizeof (union TALER_CoinSpendPrivateKeyP))); + sizeof (struct TALER_CoinSpendPrivateKeyP))); GNUNET_assert (0 == GNUNET_CRYPTO_rsa_blinding_key_cmp (rl.blinding_key.rsa_blinding_key, rld->blinding_key.rsa_blinding_key)); @@ -121,21 +121,21 @@ test_rled () static int test_high_level () { - struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; + struct GNUNET_CRYPTO_EddsaPrivateKey *pk; struct TALER_LinkSecretP secret; struct TALER_LinkSecretP secret2; - union TALER_CoinSpendPublicKeyP coin_pub; - union TALER_CoinSpendPrivateKeyP coin_priv; + struct TALER_CoinSpendPublicKeyP coin_pub; + struct TALER_CoinSpendPrivateKeyP coin_priv; struct TALER_TransferPrivateKeyP trans_priv; struct TALER_TransferPublicKeyP trans_pub; struct TALER_EncryptedLinkSecretP secret_enc; - pk = GNUNET_CRYPTO_ecdsa_key_create (); + pk = GNUNET_CRYPTO_eddsa_key_create (); GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &secret, sizeof (secret)); - GNUNET_CRYPTO_ecdsa_key_get_public (pk, - &coin_pub.ecdsa_pub); + GNUNET_CRYPTO_eddsa_key_get_public (pk, + &coin_pub.eddsa_pub); GNUNET_assert (GNUNET_OK == TALER_link_encrypt_secret (&secret, &coin_pub, @@ -151,7 +151,7 @@ test_high_level () memcmp (&secret, &secret2, sizeof (secret))); - coin_priv.ecdsa_priv = *pk; + coin_priv.eddsa_priv = *pk; GNUNET_assert (GNUNET_OK == TALER_link_decrypt_secret2 (&secret_enc, &trans_pub, diff --git a/src/util/test_json.c b/src/util/test_json.c index 9eb72fb8c..6d887f489 100644 --- a/src/util/test_json.c +++ b/src/util/test_json.c @@ -24,6 +24,142 @@ #include "taler_json_lib.h" +/** + * Test amount conversion from/to JSON. + * + * @return 0 on success + */ +static int +test_amount () +{ + json_t *j; + struct TALER_Amount a1; + struct TALER_Amount a2; + + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:4.3", + &a1)); + j = TALER_json_from_amount (&a1); + GNUNET_assert (NULL != j); + GNUNET_assert (GNUNET_OK == + TALER_json_to_amount (j, + &a2)); + GNUNET_assert (0 == + TALER_amount_cmp (&a1, + &a2)); + json_decref (j); + return 0; +} + + +/** + * Test time conversion from/to JSON. + * + * @return 0 on success + */ +static int +test_time () +{ + json_t *j; + struct GNUNET_TIME_Absolute a1; + struct GNUNET_TIME_Absolute a2; + + a1 = GNUNET_TIME_absolute_get (); + a1.abs_value_us -= a1.abs_value_us % 1000000; /* round! */ + j = TALER_json_from_abs (a1); + GNUNET_assert (NULL != j); + GNUNET_assert (GNUNET_OK == + TALER_json_to_abs (j, + &a2)); + GNUNET_assert (a1.abs_value_us == + a2.abs_value_us); + json_decref (j); + + a1 = GNUNET_TIME_UNIT_FOREVER_ABS; + j = TALER_json_from_abs (a1); + GNUNET_assert (NULL != j); + GNUNET_assert (GNUNET_OK == + TALER_json_to_abs (j, + &a2)); + GNUNET_assert (a1.abs_value_us == + a2.abs_value_us); + json_decref (j); + return 0; +} + + +/** + * Test raw (binary) conversion from/to JSON. + * + * @return 0 on success + */ +static int +test_raw () +{ + char blob[256]; + char blob2[256]; + unsigned int i; + json_t *j; + + for (i=0;i<=256;i++) + { + memset (blob, i, i); + j = TALER_json_from_data (blob, i); + GNUNET_assert (NULL != j); + GNUNET_assert (GNUNET_OK == + TALER_json_to_data (j, + blob2, + i)); + GNUNET_assert (0 == + memcmp (blob, + blob2, + i)); + } + return 0; +} + + +/** + * Test rsa conversions from/to JSON. + * + * @return 0 on success + */ +static int +test_rsa () +{ + struct GNUNET_CRYPTO_rsa_PublicKey *pub; + struct GNUNET_CRYPTO_rsa_PublicKey *pub2; + struct GNUNET_CRYPTO_rsa_Signature *sig; + struct GNUNET_CRYPTO_rsa_Signature *sig2; + struct GNUNET_CRYPTO_rsa_PrivateKey *priv; + char msg[] = "Hello"; + json_t *jp; + json_t *js; + + priv = GNUNET_CRYPTO_rsa_private_key_create (1024); + pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); + sig = GNUNET_CRYPTO_rsa_sign (priv, + msg, + sizeof (msg)); + GNUNET_assert (NULL != (jp = TALER_json_from_rsa_public_key (pub))); + GNUNET_assert (NULL != (js = TALER_json_from_rsa_signature (sig))); + GNUNET_assert (NULL != (pub2 = TALER_json_to_rsa_public_key (jp))); + GNUNET_assert (NULL != (sig2 = TALER_json_to_rsa_signature (js))); + GNUNET_break (0 == + GNUNET_CRYPTO_rsa_signature_cmp (sig, + sig2)); + GNUNET_break (0 == + GNUNET_CRYPTO_rsa_public_key_cmp (pub, + pub2)); + GNUNET_CRYPTO_rsa_signature_free (sig); + GNUNET_CRYPTO_rsa_signature_free (sig2); + GNUNET_CRYPTO_rsa_private_key_free (priv); + GNUNET_CRYPTO_rsa_public_key_free (pub); + GNUNET_CRYPTO_rsa_public_key_free (pub2); + return 0; +} + + int main(int argc, const char *const argv[]) @@ -31,7 +167,15 @@ main(int argc, GNUNET_log_setup ("test-json", "WARNING", NULL); - /* FIXME: implement test... */ + if (0 != test_amount ()) + return 1; + if (0 != test_time ()) + return 1; + if (0 != test_raw ()) + return 1; + if (0 != test_rsa ()) + return 1; + /* FIXME: test EdDSA signature conversion... */ return 0; } diff --git a/src/util/test_wireformats.c b/src/util/test_wireformats.c index 26ec4b79f..ebb96604c 100644 --- a/src/util/test_wireformats.c +++ b/src/util/test_wireformats.c @@ -24,7 +24,8 @@ #include "taler_util.h" #include "taler_json_lib.h" -static const char * const json_wire_str = +/* Valid SEPA data */ +static const char * const valid_wire_str = "{ \"type\":\"SEPA\", \ \"IBAN\":\"DE67830654080004822650\", \ \"name\":\"GNUnet e.V.\", \ @@ -33,7 +34,40 @@ static const char * const json_wire_str = \"r\":123456789, \ \"address\": \"foobar\"}"; -int main(int argc, const char *const argv[]) +/* IBAN has wrong country code */ +static const char * const invalid_wire_str = + "{ \"type\":\"SEPA\", \ +\"IBAN\":\"XX67830654080004822650\", \ +\"name\":\"GNUnet e.V.\", \ +\"bic\":\"GENODEF1SLR\", \ +\"edate\":\"1449930207000\", \ +\"r\":123456789, \ +\"address\": \"foobar\"}"; + +/* IBAN has wrong checksum */ +static const char * const invalid_wire_str2 = + "{ \"type\":\"SEPA\", \ +\"IBAN\":\"DE67830654080004822651\", \ +\"name\":\"GNUnet e.V.\", \ +\"bic\":\"GENODEF1SLR\", \ +\"edate\":\"1449930207000\", \ +\"r\":123456789, \ +\"address\": \"foobar\"}"; + +/* Unsupported wireformat type */ +static const char * const unsupported_wire_str = + "{ \"type\":\"unsupported\", \ +\"IBAN\":\"DE67830654080004822650\", \ +\"name\":\"GNUnet e.V.\", \ +\"bic\":\"GENODEF1SLR\", \ +\"edate\":\"1449930207000\", \ +\"r\":123456789, \ +\"address\": \"foobar\"}"; + + +int +main(int argc, + const char *const argv[]) { json_t *wire; json_error_t error; @@ -41,13 +75,18 @@ int main(int argc, const char *const argv[]) GNUNET_log_setup ("test-json-validations", "WARNING", NULL); (void) memset(&error, 0, sizeof(error)); - wire = json_loads (json_wire_str, 0, &error); - if (NULL == wire) - { - TALER_json_warn (error); - return 2; - } + GNUNET_assert (NULL != (wire = json_loads (unsupported_wire_str, 0, NULL))); + GNUNET_assert (1 != TALER_json_validate_wireformat ("unsupported", wire)); + json_decref (wire); + GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str, 0, NULL))); + GNUNET_assert (1 != TALER_json_validate_wireformat ("SEPA", wire)); + json_decref (wire); + GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str2, 0, NULL))); + GNUNET_assert (1 != TALER_json_validate_wireformat ("SEPA", wire)); + json_decref (wire); + GNUNET_assert (NULL != (wire = json_loads (valid_wire_str, 0, &error))); ret = TALER_json_validate_wireformat ("SEPA", wire); + json_decref (wire); if (1 == ret) return 0; return 1; diff --git a/src/util/wireformats.c b/src/util/wireformats.c index df32f2d3d..7ea4fd067 100644 --- a/src/util/wireformats.c +++ b/src/util/wireformats.c @@ -22,7 +22,6 @@ #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include "taler_util.h" -#include "taler_json_lib.h" /** * Shorthand for exit jumps. @@ -298,10 +297,11 @@ validate_iban (const char *iban) dividend += remainder * (pow (10, nread)); remainder = dividend % 97; } - EXITIF (1 != remainder); - GNUNET_free (nbuf); - return GNUNET_YES; - + if (1 == remainder) + { + GNUNET_free (nbuf); + return GNUNET_YES; + } EXITIF_exit: GNUNET_free (nbuf); return GNUNET_NO; @@ -346,7 +346,13 @@ validate_sepa (const json_t *wire) "r", &r, "address", &address)); EXITIF (0 != strcmp (type, "SEPA")); - EXITIF (1 != validate_iban (iban)); + if (1 != validate_iban (iban)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "IBAN `%s' invalid\n", + iban); + return GNUNET_NO; + } return GNUNET_YES; EXITIF_exit: return GNUNET_NO; @@ -394,7 +400,7 @@ TALER_json_validate_wireformat (const char *type, if (0 == strcasecmp (format_handlers[i].type, type)) return format_handlers[i].handler (wire); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Wireformat `%s' not supported\n", type); return GNUNET_NO; |