diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-18 11:58:09 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-18 11:58:09 +0000 |
commit | ba7d316cff500d0bffee07994f970b80f811d089 (patch) | |
tree | f2447a588c89b775b0abc1f0c313b3f9a20eb872 /src/gnsrecord | |
parent | fe41d052396d6d63c0ad3ff10852f3289418b0db (diff) | |
download | gnunet-ba7d316cff500d0bffee07994f970b80f811d089.tar.gz gnunet-ba7d316cff500d0bffee07994f970b80f811d089.zip |
-fix testcase to not use expired records
Diffstat (limited to 'src/gnsrecord')
-rw-r--r-- | src/gnsrecord/gnsrecord_crypto.c | 19 | ||||
-rw-r--r-- | src/gnsrecord/test_gnsrecord_crypto.c | 26 |
2 files changed, 29 insertions, 16 deletions
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c index 0d173c26e..336fb93c2 100644 --- a/src/gnsrecord/gnsrecord_crypto.c +++ b/src/gnsrecord/gnsrecord_crypto.c | |||
@@ -93,9 +93,19 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
93 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 93 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
94 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 94 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
95 | uint32_t rd_count_nbo; | 95 | uint32_t rd_count_nbo; |
96 | unsigned int i; | ||
96 | 97 | ||
97 | if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE) | 98 | if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE) |
98 | return NULL; | 99 | return NULL; |
100 | /* sanity check */ | ||
101 | for (i=0;i<rd_count;i++) | ||
102 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | ||
103 | { | ||
104 | /* encrypted blocks must never have relative expiration times, skip! */ | ||
105 | GNUNET_break (0); | ||
106 | return NULL; | ||
107 | } | ||
108 | /* serialize */ | ||
99 | rd_count_nbo = htonl (rd_count); | 109 | rd_count_nbo = htonl (rd_count); |
100 | memcpy (payload, &rd_count_nbo, sizeof (uint32_t)); | 110 | memcpy (payload, &rd_count_nbo, sizeof (uint32_t)); |
101 | GNUNET_assert (payload_len == | 111 | GNUNET_assert (payload_len == |
@@ -108,9 +118,10 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
108 | sizeof (struct GNUNET_TIME_AbsoluteNBO)); | 118 | sizeof (struct GNUNET_TIME_AbsoluteNBO)); |
109 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | 119 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); |
110 | block->expiration_time = GNUNET_TIME_absolute_hton (expire); | 120 | block->expiration_time = GNUNET_TIME_absolute_hton (expire); |
121 | /* encrypt and sign */ | ||
111 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, | 122 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, |
112 | label, | 123 | label, |
113 | "gns"); | 124 | "gns"); |
114 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, | 125 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, |
115 | &block->derived_key); | 126 | &block->derived_key); |
116 | GNUNET_CRYPTO_ecdsa_key_get_public (key, | 127 | GNUNET_CRYPTO_ecdsa_key_get_public (key, |
@@ -118,8 +129,8 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
118 | derive_block_aes_key (&iv, &skey, label, &pkey); | 129 | derive_block_aes_key (&iv, &skey, label, &pkey); |
119 | GNUNET_break (payload_len + sizeof (uint32_t) == | 130 | GNUNET_break (payload_len + sizeof (uint32_t) == |
120 | GNUNET_CRYPTO_symmetric_encrypt (payload, payload_len + sizeof (uint32_t), | 131 | GNUNET_CRYPTO_symmetric_encrypt (payload, payload_len + sizeof (uint32_t), |
121 | &skey, &iv, | 132 | &skey, &iv, |
122 | &block[1])); | 133 | &block[1])); |
123 | if (GNUNET_OK != | 134 | if (GNUNET_OK != |
124 | GNUNET_CRYPTO_ecdsa_sign (dkey, | 135 | GNUNET_CRYPTO_ecdsa_sign (dkey, |
125 | &block->purpose, | 136 | &block->purpose, |
diff --git a/src/gnsrecord/test_gnsrecord_crypto.c b/src/gnsrecord/test_gnsrecord_crypto.c index 91bafdf21..89e65e69b 100644 --- a/src/gnsrecord/test_gnsrecord_crypto.c +++ b/src/gnsrecord/test_gnsrecord_crypto.c | |||
@@ -53,12 +53,12 @@ static struct GNUNET_GNSRECORD_Data * | |||
53 | create_record (int count) | 53 | create_record (int count) |
54 | { | 54 | { |
55 | unsigned int c; | 55 | unsigned int c; |
56 | struct GNUNET_GNSRECORD_Data * rd; | 56 | struct GNUNET_GNSRECORD_Data *rd; |
57 | 57 | ||
58 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); | 58 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); |
59 | for (c = 0; c < count; c++) | 59 | for (c = 0; c < count; c++) |
60 | { | 60 | { |
61 | rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us; | 61 | rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; |
62 | rd[c].record_type = TEST_RECORD_TYPE; | 62 | rd[c].record_type = TEST_RECORD_TYPE; |
63 | rd[c].data_size = TEST_RECORD_DATALEN; | 63 | rd[c].data_size = TEST_RECORD_DATALEN; |
64 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); | 64 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); |
@@ -70,23 +70,21 @@ create_record (int count) | |||
70 | 70 | ||
71 | static void | 71 | static void |
72 | rd_decrypt_cb (void *cls, | 72 | rd_decrypt_cb (void *cls, |
73 | unsigned int rd_count, | 73 | unsigned int rd_count, |
74 | const struct GNUNET_GNSRECORD_Data *rd) | 74 | const struct GNUNET_GNSRECORD_Data *rd) |
75 | { | 75 | { |
76 | char rd_cmp_data[TEST_RECORD_DATALEN]; | 76 | char rd_cmp_data[TEST_RECORD_DATALEN]; |
77 | |||
78 | int c; | 77 | int c; |
79 | 78 | ||
80 | GNUNET_assert (RECORDS == rd_count); | 79 | GNUNET_assert (RECORDS == rd_count); |
81 | GNUNET_assert (NULL != rd); | 80 | GNUNET_assert (NULL != rd); |
82 | 81 | ||
83 | memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); | 82 | memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); |
84 | |||
85 | for (c = 0; c < rd_count; c++) | 83 | for (c = 0; c < rd_count; c++) |
86 | { | 84 | { |
87 | GNUNET_assert (TEST_RECORD_TYPE == rd[c].record_type); | 85 | GNUNET_assert (TEST_RECORD_TYPE == rd[c].record_type); |
88 | GNUNET_assert (TEST_RECORD_DATALEN == rd[c].data_size); | 86 | GNUNET_assert (TEST_RECORD_DATALEN == rd[c].data_size); |
89 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[c].data, TEST_RECORD_DATALEN)); | 87 | GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[c].data, TEST_RECORD_DATALEN)); |
90 | } | 88 | } |
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 89 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
92 | "Block was decrypted successfully \n"); | 90 | "Block was decrypted successfully \n"); |
@@ -103,9 +101,13 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
103 | 101 | ||
104 | /* load privat key */ | 102 | /* load privat key */ |
105 | char *hostkey_file; | 103 | char *hostkey_file; |
106 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | 104 | GNUNET_asprintf(&hostkey_file, |
107 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 105 | "zonefiles%s%s", |
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | 106 | DIR_SEPARATOR_STR, |
107 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
109 | "Using zonekey file `%s'\n", | ||
110 | hostkey_file); | ||
109 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | 111 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); |
110 | GNUNET_free (hostkey_file); | 112 | GNUNET_free (hostkey_file); |
111 | GNUNET_assert (privkey != NULL); | 113 | GNUNET_assert (privkey != NULL); |