aboutsummaryrefslogtreecommitdiff
path: root/src/block/plugin_block_dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/block/plugin_block_dns.c')
-rw-r--r--src/block/plugin_block_dns.c105
1 files changed, 55 insertions, 50 deletions
diff --git a/src/block/plugin_block_dns.c b/src/block/plugin_block_dns.c
index 681a659ae..0cf8c50e9 100644
--- a/src/block/plugin_block_dns.c
+++ b/src/block/plugin_block_dns.c
@@ -48,14 +48,13 @@
48 */ 48 */
49static enum GNUNET_BLOCK_EvaluationResult 49static enum GNUNET_BLOCK_EvaluationResult
50block_plugin_dns_evaluate (void *cls, 50block_plugin_dns_evaluate (void *cls,
51 enum GNUNET_BLOCK_Type type, 51 enum GNUNET_BLOCK_Type type,
52 const GNUNET_HashCode *query, 52 const GNUNET_HashCode * query,
53 struct GNUNET_CONTAINER_BloomFilter **bf, 53 struct GNUNET_CONTAINER_BloomFilter **bf,
54 int32_t bf_mutator, 54 int32_t bf_mutator,
55 const void *xquery, 55 const void *xquery,
56 size_t xquery_size, 56 size_t xquery_size,
57 const void *reply_block, 57 const void *reply_block, size_t reply_block_size)
58 size_t reply_block_size)
59{ 58{
60 switch (type) 59 switch (type)
61 { 60 {
@@ -66,37 +65,43 @@ block_plugin_dns_evaluate (void *cls,
66 if (reply_block_size == 0) 65 if (reply_block_size == 0)
67 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 66 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
68 67
69 if (reply_block_size != sizeof(struct GNUNET_DNS_Record)) 68 if (reply_block_size != sizeof (struct GNUNET_DNS_Record))
70 { 69 {
71 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: reply_block_size=%d != %d\n", reply_block_size, sizeof(struct GNUNET_DNS_Record)); 70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
72 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 71 "DNS-Block is invalid: reply_block_size=%d != %d\n",
73 } 72 reply_block_size, sizeof (struct GNUNET_DNS_Record));
74 73 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
75 const struct GNUNET_DNS_Record* rec = reply_block; 74 }
76 75
77 if (ntohl(rec->purpose.size) != sizeof(struct GNUNET_DNS_Record) - sizeof(struct GNUNET_CRYPTO_RsaSignature)) 76 const struct GNUNET_DNS_Record *rec = reply_block;
78 { 77
79 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 78 if (ntohl (rec->purpose.size) !=
80 "DNS-Block is invalid: rec->purpose.size=%d != %d\n", 79 sizeof (struct GNUNET_DNS_Record) -
81 ntohl(rec->purpose.size), 80 sizeof (struct GNUNET_CRYPTO_RsaSignature))
82 sizeof(struct GNUNET_DNS_Record) - sizeof(struct GNUNET_CRYPTO_RsaSignature)); 81 {
83 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
84 } 83 "DNS-Block is invalid: rec->purpose.size=%d != %d\n",
85 84 ntohl (rec->purpose.size),
86 if (GNUNET_TIME_relative_get_zero().rel_value == GNUNET_TIME_absolute_get_remaining(rec->expiration_time).rel_value) 85 sizeof (struct GNUNET_DNS_Record) -
87 { 86 sizeof (struct GNUNET_CRYPTO_RsaSignature));
88 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n"); 87 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
89 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 88 }
90 } 89
91 90 if (GNUNET_TIME_relative_get_zero ().rel_value ==
92 if (GNUNET_OK != GNUNET_CRYPTO_rsa_verify (htonl(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD), 91 GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value)
93 &rec->purpose, 92 {
94 &rec->signature, 93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n");
95 &rec->peer)) 94 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
96 { 95 }
97 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: invalid signature\n"); 96
98 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 97 if (GNUNET_OK !=
99 } 98 GNUNET_CRYPTO_rsa_verify (htonl (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD),
99 &rec->purpose, &rec->signature, &rec->peer))
100 {
101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
102 "DNS-Block is invalid: invalid signature\n");
103 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
104 }
100 105
101 /* How to decide whether there are no more? */ 106 /* How to decide whether there are no more? */
102 return GNUNET_BLOCK_EVALUATION_OK_MORE; 107 return GNUNET_BLOCK_EVALUATION_OK_MORE;
@@ -119,15 +124,15 @@ block_plugin_dns_evaluate (void *cls,
119 */ 124 */
120static int 125static int
121block_plugin_dns_get_key (void *cls, 126block_plugin_dns_get_key (void *cls,
122 enum GNUNET_BLOCK_Type type, 127 enum GNUNET_BLOCK_Type type,
123 const void *block, 128 const void *block,
124 size_t block_size, 129 size_t block_size, GNUNET_HashCode * key)
125 GNUNET_HashCode *key)
126{ 130{
127 if (type != GNUNET_BLOCK_TYPE_DNS) 131 if (type != GNUNET_BLOCK_TYPE_DNS)
128 return GNUNET_SYSERR; 132 return GNUNET_SYSERR;
129 const struct GNUNET_DNS_Record* rec = block; 133 const struct GNUNET_DNS_Record *rec = block;
130 memcpy(key, &rec->service_descriptor, sizeof(GNUNET_HashCode)); 134
135 memcpy (key, &rec->service_descriptor, sizeof (GNUNET_HashCode));
131 return GNUNET_OK; 136 return GNUNET_OK;
132} 137}
133 138
@@ -137,11 +142,11 @@ block_plugin_dns_get_key (void *cls,
137void * 142void *
138libgnunet_plugin_block_dns_init (void *cls) 143libgnunet_plugin_block_dns_init (void *cls)
139{ 144{
140 static enum GNUNET_BLOCK_Type types[] = 145 static enum GNUNET_BLOCK_Type types[] =
141 { 146 {
142 GNUNET_BLOCK_TYPE_DNS, 147 GNUNET_BLOCK_TYPE_DNS,
143 GNUNET_BLOCK_TYPE_ANY /* end of list */ 148 GNUNET_BLOCK_TYPE_ANY /* end of list */
144 }; 149 };
145 struct GNUNET_BLOCK_PluginFunctions *api; 150 struct GNUNET_BLOCK_PluginFunctions *api;
146 151
147 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions)); 152 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));