diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-26 14:34:56 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-26 14:34:56 +0000 |
commit | 39670859fe230805056e8128c7c0bf5d5c92665b (patch) | |
tree | 424af2bf213d5a5df41905b21dc17e21af9454a0 /src/gns/plugin_block_gns.c | |
parent | 1cd1726ff32df42d13f6cc469bda4881b1f9fbc0 (diff) | |
download | gnunet-39670859fe230805056e8128c7c0bf5d5c92665b.tar.gz gnunet-39670859fe230805056e8128c7c0bf5d5c92665b.zip |
-doxygen, more block plugin
Diffstat (limited to 'src/gns/plugin_block_gns.c')
-rw-r--r-- | src/gns/plugin_block_gns.c | 80 |
1 files changed, 78 insertions, 2 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 33699a32c..1a33b2d1a 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -61,10 +61,86 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
61 | size_t xquery_size, const void *reply_block, | 61 | size_t xquery_size, const void *reply_block, |
62 | size_t reply_block_size) | 62 | size_t reply_block_size) |
63 | { | 63 | { |
64 | if (type != GNUNET_BLOCK_TYPE_GNS_RECORD) | 64 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) |
65 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 65 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
66 | |||
67 | struct GNUNET_CRYPTO_RsaSignature *signature; | ||
68 | struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose; | ||
69 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key; | ||
70 | char* name; | ||
71 | GNUNET_HashCode pkey_hash; | ||
72 | GNUNET_HashCode query_pkey; | ||
73 | GNUNET_HashCode name_hash; | ||
74 | |||
75 | uint32_t rd_num; | ||
76 | uint32_t type; | ||
77 | struct GNUNET_TIME_AbsoluteNBO; | ||
78 | uint32_t data_length; | ||
79 | uint32_t flags; | ||
80 | |||
81 | char* pos = (char*) reply_block; | ||
82 | signature = pos; | ||
83 | pos += sizeof(struct GNUNET_CRYPTO_RsaSignature); | ||
84 | pos += sizeof(struct GNUNET_CRYPTO_RsaSignaturePurpose); | ||
85 | |||
86 | public_key = pos; | ||
87 | pos += sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); | ||
88 | name = pos; | ||
89 | pos += namelen(name); //Off by 1? | ||
90 | |||
91 | GNUNET_CRYPTO_hash(public_key, | ||
92 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
93 | &pkey_hash); | ||
94 | |||
95 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); | ||
96 | |||
97 | GNUNET_CRYPTO_hash_xor(query, &name_hash, &query_pkey); | ||
66 | 98 | ||
67 | //FIXME check signatures here | 99 | //Check query key against public key |
100 | if (0 != GNUNET_CRYPTO_hash_cmp(&query_pkey, &pkey_hash)) | ||
101 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
102 | |||
103 | rd_count = ntohl(*pos); | ||
104 | pos += sizeof(uint32_t); | ||
105 | |||
106 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | ||
107 | int i = 0; | ||
108 | |||
109 | for (i=0; i<rd_count; i++) | ||
110 | { | ||
111 | rd[i].type = ntohl(*pos); | ||
112 | pos += sizeof(uint32_t); | ||
113 | rd[i].expiration = | ||
114 | GNUNET_TIME_relative_ntoh(*((struct GNUNET_TIME_AbsoluteNBO*)pos)); | ||
115 | pos += sizeof(struct GNUNET_TIME_AbsoluteNBO); | ||
116 | rd[i].data_length = ntohl(*pos); | ||
117 | pos += sizeof(uint32_t); | ||
118 | rd[i].flags = ntohl(*pos); | ||
119 | pos += sizeof(uint32_t); | ||
120 | rd[i].data = pos; | ||
121 | pos += rd[i].data_length; | ||
122 | } | ||
123 | |||
124 | if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (public_key, | ||
125 | name, | ||
126 | rd_count, | ||
127 | rd, | ||
128 | signature)) | ||
129 | { | ||
130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n"); | ||
131 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
132 | } | ||
133 | |||
134 | //Cache | ||
135 | GNUNET_NAMESTORE_record_put (handle, //FIXME where do i get this from? | ||
136 | &pkey_hash, | ||
137 | name, | ||
138 | expiration, //FIXME uh where do i get this from? | ||
139 | rd_count, | ||
140 | rd, | ||
141 | signature, | ||
142 | NULL, //cont | ||
143 | NULL); //cls | ||
68 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 144 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
69 | } | 145 | } |
70 | 146 | ||