diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-28 17:36:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-28 17:36:58 +0000 |
commit | d69f0353b867c65c84e46ac710d93685e25a4ed8 (patch) | |
tree | ed93bb1149ca6bc76c9c5e6c33a8a5ea791edb3b /src/namestore | |
parent | 748324f617d0e4ff81de0e73c074d5314ace7dfd (diff) | |
download | gnunet-d69f0353b867c65c84e46ac710d93685e25a4ed8.tar.gz gnunet-d69f0353b867c65c84e46ac710d93685e25a4ed8.zip |
-namestore cleanup and fixes -- wip
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 257 |
1 files changed, 113 insertions, 144 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 25af987b5..95f9efac8 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -145,10 +145,6 @@ struct GNUNET_NAMESTORE_CryptoContainer | |||
145 | */ | 145 | */ |
146 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; | 146 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; |
147 | 147 | ||
148 | /** | ||
149 | * Zone's public key | ||
150 | */ | ||
151 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey; | ||
152 | }; | 148 | }; |
153 | 149 | ||
154 | 150 | ||
@@ -294,7 +290,6 @@ zone_to_disk_it (void *cls, | |||
294 | (void) write_key_to_file(c->filename, c); | 290 | (void) write_key_to_file(c->filename, c); |
295 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value)); | 291 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value)); |
296 | GNUNET_CRYPTO_rsa_key_free (c->privkey); | 292 | GNUNET_CRYPTO_rsa_key_free (c->privkey); |
297 | GNUNET_free (c->pubkey); | ||
298 | GNUNET_free (c->filename); | 293 | GNUNET_free (c->filename); |
299 | GNUNET_free (c); | 294 | GNUNET_free (c); |
300 | return GNUNET_OK; | 295 | return GNUNET_OK; |
@@ -980,8 +975,8 @@ handle_create_record_it (void *cls, | |||
980 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 975 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
981 | "Matching record for %s' exists, no change required!\n", | 976 | "Matching record for %s' exists, no change required!\n", |
982 | crc->name); | 977 | crc->name); |
983 | res = GNUNET_NO; | 978 | crc->res = GNUNET_NO; |
984 | goto end; | 979 | return; |
985 | } | 980 | } |
986 | else | 981 | else |
987 | { | 982 | { |
@@ -1023,7 +1018,6 @@ handle_create_record_it (void *cls, | |||
1023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to put record for `%s' in database \n", crc->name); | 1018 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to put record for `%s' in database \n", crc->name); |
1024 | res = GNUNET_YES; | 1019 | res = GNUNET_YES; |
1025 | 1020 | ||
1026 | end: | ||
1027 | GNUNET_free_non_null (rd_new); | 1021 | GNUNET_free_non_null (rd_new); |
1028 | 1022 | ||
1029 | switch (res) { | 1023 | switch (res) { |
@@ -1067,9 +1061,8 @@ handle_record_create (void *cls, | |||
1067 | struct GNUNET_SERVER_Client *client, | 1061 | struct GNUNET_SERVER_Client *client, |
1068 | const struct GNUNET_MessageHeader *message) | 1062 | const struct GNUNET_MessageHeader *message) |
1069 | { | 1063 | { |
1070 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); | ||
1071 | struct GNUNET_NAMESTORE_Client *nc; | 1064 | struct GNUNET_NAMESTORE_Client *nc; |
1072 | struct RecordCreateMessage *rp_msg; | 1065 | const struct RecordCreateMessage *rp_msg; |
1073 | struct GNUNET_NAMESTORE_CryptoContainer *cc; | 1066 | struct GNUNET_NAMESTORE_CryptoContainer *cc; |
1074 | struct CreateRecordContext crc; | 1067 | struct CreateRecordContext crc; |
1075 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 1068 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
@@ -1082,31 +1075,29 @@ handle_record_create (void *cls, | |||
1082 | size_t msg_size_exp; | 1075 | size_t msg_size_exp; |
1083 | size_t rd_ser_len; | 1076 | size_t rd_ser_len; |
1084 | size_t key_len; | 1077 | size_t key_len; |
1085 | uint32_t rid = 0; | 1078 | uint32_t rid; |
1086 | char *pkey_tmp; | 1079 | const char *pkey_tmp; |
1087 | char *name_tmp; | 1080 | const char *name_tmp; |
1088 | char *rd_ser; | 1081 | const char *rd_ser; |
1089 | int rd_count; | 1082 | unsigned int rd_count; |
1090 | 1083 | int res; | |
1091 | int res = GNUNET_SYSERR; | 1084 | struct GNUNET_NAMESTORE_RecordData rd; |
1092 | crc.res = GNUNET_SYSERR; | ||
1093 | 1085 | ||
1086 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1087 | "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); | ||
1094 | if (ntohs (message->size) < sizeof (struct RecordCreateMessage)) | 1088 | if (ntohs (message->size) < sizeof (struct RecordCreateMessage)) |
1095 | { | 1089 | { |
1096 | GNUNET_break_op (0); | 1090 | GNUNET_break (0); |
1097 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1091 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1098 | return; | 1092 | return; |
1099 | } | 1093 | } |
1100 | 1094 | if (NULL == (nc = client_lookup (client))) | |
1101 | nc = client_lookup(client); | ||
1102 | if (nc == NULL) | ||
1103 | { | 1095 | { |
1104 | GNUNET_break_op (0); | 1096 | GNUNET_break (0); |
1105 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1097 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1106 | return; | 1098 | return; |
1107 | } | 1099 | } |
1108 | 1100 | rp_msg = (const struct RecordCreateMessage *) message; | |
1109 | rp_msg = (struct RecordCreateMessage *) message; | ||
1110 | rid = ntohl (rp_msg->gns_header.r_id); | 1101 | rid = ntohl (rp_msg->gns_header.r_id); |
1111 | name_len = ntohs (rp_msg->name_len); | 1102 | name_len = ntohs (rp_msg->name_len); |
1112 | msg_size = ntohs (message->size); | 1103 | msg_size = ntohs (message->size); |
@@ -1114,79 +1105,81 @@ handle_record_create (void *cls, | |||
1114 | rd_ser_len = ntohs (rp_msg->rd_len); | 1105 | rd_ser_len = ntohs (rp_msg->rd_len); |
1115 | key_len = ntohs (rp_msg->pkey_len); | 1106 | key_len = ntohs (rp_msg->pkey_len); |
1116 | msg_size_exp = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len; | 1107 | msg_size_exp = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len; |
1117 | 1108 | if ( (msg_size != msg_size_exp) || (1 != rd_count) ) | |
1118 | if (msg_size != msg_size_exp) | ||
1119 | { | 1109 | { |
1120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size); | 1110 | GNUNET_break (0); |
1121 | GNUNET_break_op (0); | 1111 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1122 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1123 | return; | 1112 | return; |
1124 | } | 1113 | } |
1125 | 1114 | if ((0 == name_len) || (name_len > MAX_NAME_LEN)) | |
1126 | if ((name_len == 0) || (name_len > MAX_NAME_LEN)) | ||
1127 | { | 1115 | { |
1128 | GNUNET_break_op (0); | 1116 | GNUNET_break (0); |
1129 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1117 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1130 | return; | 1118 | return; |
1131 | } | 1119 | } |
1132 | 1120 | pkey_tmp = (const char *) &rp_msg[1]; | |
1133 | pkey_tmp = (char *) &rp_msg[1]; | ||
1134 | name_tmp = &pkey_tmp[key_len]; | 1121 | name_tmp = &pkey_tmp[key_len]; |
1135 | rd_ser = &name_tmp[name_len]; | 1122 | rd_ser = &name_tmp[name_len]; |
1136 | |||
1137 | if (name_tmp[name_len -1] != '\0') | 1123 | if (name_tmp[name_len -1] != '\0') |
1138 | { | 1124 | { |
1139 | GNUNET_break_op (0); | 1125 | GNUNET_break (0); |
1140 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1126 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1141 | return; | 1127 | return; |
1142 | } | 1128 | } |
1143 | 1129 | if (NULL == (pkey = GNUNET_CRYPTO_rsa_decode_key (pkey_tmp, key_len))) | |
1144 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | ||
1145 | |||
1146 | res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd); | ||
1147 | if ((res != GNUNET_OK) || (rd_count != 1)) | ||
1148 | { | 1130 | { |
1149 | GNUNET_break_op (0); | 1131 | GNUNET_break (0); |
1150 | goto send; | 1132 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1133 | return; | ||
1134 | } | ||
1135 | if (GNUNET_OK != | ||
1136 | GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, 1, &rd)) | ||
1137 | { | ||
1138 | GNUNET_break (0); | ||
1139 | GNUNET_CRYPTO_rsa_key_free (pkey); | ||
1140 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1141 | return; | ||
1151 | } | 1142 | } |
1152 | /* Extracting and converting private key */ | 1143 | /* Extracting and converting private key */ |
1153 | pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | 1144 | GNUNET_CRYPTO_rsa_key_get_public (pkey, &pub); |
1154 | GNUNET_assert (pkey != NULL); | 1145 | GNUNET_CRYPTO_short_hash (&pub, |
1155 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); | 1146 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1156 | GNUNET_CRYPTO_short_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); | 1147 | &pubkey_hash); |
1157 | GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); | 1148 | GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); |
1158 | 1149 | ||
1159 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) | 1150 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) |
1160 | { | 1151 | { |
1161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_short_h2s(&pubkey_hash)); | 1152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1162 | 1153 | "Received new private key for zone `%s'\n", | |
1154 | GNUNET_short_h2s(&pubkey_hash)); | ||
1163 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | 1155 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); |
1164 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | 1156 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key (pkey_tmp, key_len); |
1165 | cc->pubkey = GNUNET_malloc(sizeof (pub)); | ||
1166 | memcpy (cc->pubkey, &pub, sizeof(pub)); | ||
1167 | cc->zone = pubkey_hash; | 1157 | cc->zone = pubkey_hash; |
1168 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1158 | GNUNET_assert (GNUNET_YES == |
1159 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, | ||
1160 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1169 | } | 1161 | } |
1170 | 1162 | ||
1163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1164 | "Creating record for name `%s' in zone `%s'\n", | ||
1165 | name_tmp, GNUNET_short_h2s(&pubkey_hash)); | ||
1171 | crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); | 1166 | crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); |
1172 | crc.res = GNUNET_SYSERR; | 1167 | crc.res = GNUNET_SYSERR; |
1173 | crc.pkey = pkey; | 1168 | crc.pkey = pkey; |
1174 | crc.pubkey = &pub; | 1169 | crc.pubkey = &pub; |
1175 | crc.rd = rd; | 1170 | crc.rd = &rd; |
1176 | crc.name = name_tmp; | 1171 | crc.name = name_tmp; |
1177 | 1172 | ||
1178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s(&pubkey_hash)); | ||
1179 | |||
1180 | /* Get existing records for name */ | 1173 | /* Get existing records for name */ |
1181 | res = GSN_database->iterate_records(GSN_database->cls, &pubkey_hash, name_tmp, 0, &handle_create_record_it, &crc); | 1174 | res = GSN_database->iterate_records (GSN_database->cls, &pubkey_hash, name_tmp, 0, |
1175 | &handle_create_record_it, &crc); | ||
1182 | if (res != GNUNET_SYSERR) | 1176 | if (res != GNUNET_SYSERR) |
1183 | res = GNUNET_OK; | 1177 | res = GNUNET_OK; |
1184 | GNUNET_CRYPTO_rsa_key_free(pkey); | 1178 | GNUNET_CRYPTO_rsa_key_free (pkey); |
1185 | pkey = NULL; | ||
1186 | 1179 | ||
1187 | /* Send response */ | 1180 | /* Send response */ |
1188 | send: | 1181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_CREATE_RESPONSE"); | 1182 | "Sending `%s' message\n", "RECORD_CREATE_RESPONSE"); |
1190 | rcr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE); | 1183 | rcr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE); |
1191 | rcr_msg.gns_header.header.size = htons (sizeof (struct RecordCreateResponseMessage)); | 1184 | rcr_msg.gns_header.header.size = htons (sizeof (struct RecordCreateResponseMessage)); |
1192 | rcr_msg.gns_header.r_id = htonl (rid); | 1185 | rcr_msg.gns_header.r_id = htonl (rid); |
@@ -1196,8 +1189,9 @@ send: | |||
1196 | rcr_msg.op_result = htonl (GNUNET_NO); | 1189 | rcr_msg.op_result = htonl (GNUNET_NO); |
1197 | else | 1190 | else |
1198 | rcr_msg.op_result = htonl (GNUNET_SYSERR); | 1191 | rcr_msg.op_result = htonl (GNUNET_SYSERR); |
1199 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rcr_msg, GNUNET_NO); | 1192 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, |
1200 | 1193 | &rcr_msg.gns_header.header, | |
1194 | GNUNET_NO); | ||
1201 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1195 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1202 | } | 1196 | } |
1203 | 1197 | ||
@@ -1248,15 +1242,16 @@ handle_record_remove_it (void *cls, | |||
1248 | const struct GNUNET_NAMESTORE_RecordData *rd, | 1242 | const struct GNUNET_NAMESTORE_RecordData *rd, |
1249 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 1243 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
1250 | { | 1244 | { |
1245 | static struct GNUNET_CRYPTO_RsaSignature dummy_signature; | ||
1251 | struct RemoveRecordContext *rrc = cls; | 1246 | struct RemoveRecordContext *rrc = cls; |
1252 | unsigned int c; | 1247 | unsigned int c; |
1253 | int res; | ||
1254 | int found; | 1248 | int found; |
1255 | unsigned int rd_count_new; | 1249 | unsigned int rd_count_new; |
1256 | 1250 | ||
1257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name `%s 'currently has %u records\n", name, rd_count); | 1251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1258 | 1252 | "Name `%s 'currently has %u records\n", | |
1259 | if (rd_count == 0) | 1253 | name, rd_count); |
1254 | if (0 == rd_count) | ||
1260 | { | 1255 | { |
1261 | /* Could not find record to remove */ | 1256 | /* Could not find record to remove */ |
1262 | rrc->op_res = 1; | 1257 | rrc->op_res = 1; |
@@ -1290,17 +1285,20 @@ handle_record_remove_it (void *cls, | |||
1290 | return; | 1285 | return; |
1291 | } | 1286 | } |
1292 | 1287 | ||
1293 | if (rd_count-1 == 0) | 1288 | if (1 == rd_count) |
1294 | { | 1289 | { |
1295 | struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; | 1290 | struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; |
1296 | GNUNET_CRYPTO_short_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); | 1291 | |
1297 | res = GSN_database->remove_records (GSN_database->cls, | ||
1298 | &pubkey_hash, | ||
1299 | name); | ||
1300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1301 | "No records left for name `%s', removing name\n", | 1293 | "No records left for name `%s', removing name\n", |
1302 | name, res); | 1294 | name); |
1303 | if (GNUNET_OK != res) | 1295 | GNUNET_CRYPTO_short_hash (zone_key, |
1296 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
1297 | &pubkey_hash); | ||
1298 | if (GNUNET_OK != | ||
1299 | GSN_database->remove_records (GSN_database->cls, | ||
1300 | &pubkey_hash, | ||
1301 | name)) | ||
1304 | { | 1302 | { |
1305 | /* Could not remove records from database */ | 1303 | /* Could not remove records from database */ |
1306 | rrc->op_res = 3; | 1304 | rrc->op_res = 3; |
@@ -1310,9 +1308,8 @@ handle_record_remove_it (void *cls, | |||
1310 | return; | 1308 | return; |
1311 | } | 1309 | } |
1312 | 1310 | ||
1313 | rd_count_new = rd_count -1; | 1311 | rd_count_new = rd_count - 1; |
1314 | struct GNUNET_NAMESTORE_RecordData rd_new[rd_count_new]; | 1312 | struct GNUNET_NAMESTORE_RecordData rd_new[rd_count_new]; |
1315 | |||
1316 | unsigned int c2 = 0; | 1313 | unsigned int c2 = 0; |
1317 | for (c = 0; c < rd_count; c++) | 1314 | for (c = 0; c < rd_count; c++) |
1318 | { | 1315 | { |
@@ -1325,26 +1322,18 @@ handle_record_remove_it (void *cls, | |||
1325 | } | 1322 | } |
1326 | 1323 | ||
1327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name `%s' now has %u records\n", name, rd_count_new); | 1324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name `%s' now has %u records\n", name, rd_count_new); |
1328 | 1325 | if (GNUNET_OK != | |
1329 | /* Create dummy signature */ | 1326 | GSN_database->put_records(GSN_database->cls, |
1330 | struct GNUNET_CRYPTO_RsaSignature dummy_signature; | 1327 | zone_key, |
1331 | memset (&dummy_signature, '\0', sizeof (dummy_signature)); | 1328 | expire, |
1332 | 1329 | name, | |
1333 | 1330 | rd_count_new, rd_new, | |
1334 | /* Put records */ | 1331 | &dummy_signature)) |
1335 | res = GSN_database->put_records(GSN_database->cls, | ||
1336 | zone_key, | ||
1337 | expire, | ||
1338 | name, | ||
1339 | rd_count_new, rd_new, | ||
1340 | &dummy_signature); | ||
1341 | if (GNUNET_OK != res) | ||
1342 | { | 1332 | { |
1343 | /* Could not put records into database */ | 1333 | /* Could not put records into database */ |
1344 | rrc->op_res = 4; | 1334 | rrc->op_res = 4; |
1345 | return; | 1335 | return; |
1346 | } | 1336 | } |
1347 | |||
1348 | rrc->op_res = 0; | 1337 | rrc->op_res = 0; |
1349 | } | 1338 | } |
1350 | 1339 | ||
@@ -1385,19 +1374,16 @@ handle_record_remove (void *cls, | |||
1385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE"); | 1374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE"); |
1386 | if (ntohs (message->size) < sizeof (struct RecordRemoveMessage)) | 1375 | if (ntohs (message->size) < sizeof (struct RecordRemoveMessage)) |
1387 | { | 1376 | { |
1388 | GNUNET_break_op (0); | 1377 | GNUNET_break (0); |
1389 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1378 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1390 | return; | 1379 | return; |
1391 | } | 1380 | } |
1392 | 1381 | if (NULL == (nc = client_lookup(client))) | |
1393 | nc = client_lookup(client); | ||
1394 | if (nc == NULL) | ||
1395 | { | 1382 | { |
1396 | GNUNET_break_op (0); | 1383 | GNUNET_break (0); |
1397 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1384 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1398 | return; | 1385 | return; |
1399 | } | 1386 | } |
1400 | |||
1401 | rr_msg = (const struct RecordRemoveMessage *) message; | 1387 | rr_msg = (const struct RecordRemoveMessage *) message; |
1402 | rid = ntohl (rr_msg->gns_header.r_id); | 1388 | rid = ntohl (rr_msg->gns_header.r_id); |
1403 | name_len = ntohs (rr_msg->name_len); | 1389 | name_len = ntohs (rr_msg->name_len); |
@@ -1406,67 +1392,50 @@ handle_record_remove (void *cls, | |||
1406 | key_len = ntohs (rr_msg->pkey_len); | 1392 | key_len = ntohs (rr_msg->pkey_len); |
1407 | msg_size = ntohs (message->size); | 1393 | msg_size = ntohs (message->size); |
1408 | 1394 | ||
1409 | if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1395 | if ((name_len >=MAX_NAME_LEN) || (0 == name_len)) |
1410 | { | 1396 | { |
1411 | GNUNET_break_op (0); | 1397 | GNUNET_break (0); |
1412 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1398 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1413 | return; | ||
1414 | } | ||
1415 | |||
1416 | if ((name_len >=MAX_NAME_LEN) || (name_len == 0)) | ||
1417 | { | ||
1418 | GNUNET_break_op (0); | ||
1419 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1420 | return; | 1399 | return; |
1421 | } | 1400 | } |
1422 | |||
1423 | msg_size_exp = sizeof (struct RecordRemoveMessage) + key_len + name_len + rd_ser_len; | 1401 | msg_size_exp = sizeof (struct RecordRemoveMessage) + key_len + name_len + rd_ser_len; |
1424 | if (msg_size != msg_size_exp) | 1402 | if (msg_size != msg_size_exp) |
1425 | { | 1403 | { |
1426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size); | 1404 | GNUNET_break (0); |
1427 | GNUNET_break_op (0); | 1405 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1428 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1429 | return; | 1406 | return; |
1430 | } | 1407 | } |
1431 | |||
1432 | pkey_tmp = (const char *) &rr_msg[1]; | 1408 | pkey_tmp = (const char *) &rr_msg[1]; |
1433 | name_tmp = &pkey_tmp[key_len]; | 1409 | name_tmp = &pkey_tmp[key_len]; |
1434 | rd_ser = &name_tmp[name_len]; | 1410 | rd_ser = &name_tmp[name_len]; |
1435 | 1411 | if ('\0' != name_tmp[name_len -1]) | |
1436 | |||
1437 | if ((name_len == 0) || (name_len > MAX_NAME_LEN)) | ||
1438 | { | 1412 | { |
1439 | GNUNET_break_op (0); | 1413 | GNUNET_break (0); |
1440 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1414 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1441 | return; | 1415 | return; |
1442 | } | 1416 | } |
1443 | 1417 | if (NULL == (pkey = GNUNET_CRYPTO_rsa_decode_key (pkey_tmp, key_len))) | |
1444 | if (name_tmp[name_len -1] != '\0') | ||
1445 | { | 1418 | { |
1446 | GNUNET_break_op (0); | 1419 | GNUNET_break (0); |
1447 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1420 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1448 | return; | 1421 | return; |
1449 | } | 1422 | } |
1450 | 1423 | GNUNET_CRYPTO_rsa_key_get_public (pkey, &pub); | |
1451 | /* Extracting and converting private key */ | ||
1452 | pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | ||
1453 | GNUNET_assert (pkey != NULL); | ||
1454 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); | ||
1455 | GNUNET_CRYPTO_short_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); | 1424 | GNUNET_CRYPTO_short_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); |
1456 | GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); | 1425 | GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); |
1457 | 1426 | ||
1458 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) | 1427 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (zonekeys, &long_hash)) |
1459 | { | 1428 | { |
1460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1461 | "Received new private key for zone `%s'\n", | 1430 | "Received new private key for zone `%s'\n", |
1462 | GNUNET_short_h2s(&pubkey_hash)); | 1431 | GNUNET_short_h2s(&pubkey_hash)); |
1463 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | 1432 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); |
1464 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | 1433 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key (pkey_tmp, key_len); |
1465 | cc->pubkey = GNUNET_malloc(sizeof (pub)); | ||
1466 | memcpy (cc->pubkey, &pub, sizeof(pub)); | ||
1467 | cc->zone = pubkey_hash; | 1434 | cc->zone = pubkey_hash; |
1468 | 1435 | GNUNET_assert (GNUNET_YES == | |
1469 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1436 | GNUNET_CONTAINER_multihashmap_put (zonekeys, |
1437 | &long_hash, cc, | ||
1438 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1470 | } | 1439 | } |
1471 | 1440 | ||
1472 | 1441 | ||
@@ -2231,6 +2200,7 @@ zonekey_file_it (void *cls, const char *filename) | |||
2231 | struct GNUNET_HashCode long_hash; | 2200 | struct GNUNET_HashCode long_hash; |
2232 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; | 2201 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; |
2233 | struct GNUNET_NAMESTORE_CryptoContainer *c; | 2202 | struct GNUNET_NAMESTORE_CryptoContainer *c; |
2203 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | ||
2234 | 2204 | ||
2235 | if ((NULL == filename) || | 2205 | if ((NULL == filename) || |
2236 | (NULL == strstr(filename, ".zkey"))) | 2206 | (NULL == strstr(filename, ".zkey"))) |
@@ -2244,12 +2214,11 @@ zonekey_file_it (void *cls, const char *filename) | |||
2244 | return GNUNET_OK; | 2214 | return GNUNET_OK; |
2245 | } | 2215 | } |
2246 | c = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | 2216 | c = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); |
2247 | c->pubkey = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
2248 | c->privkey = privkey; | 2217 | c->privkey = privkey; |
2249 | GNUNET_CRYPTO_rsa_key_get_public(privkey, c->pubkey); | 2218 | GNUNET_CRYPTO_rsa_key_get_public (privkey, &pubkey); |
2250 | GNUNET_CRYPTO_short_hash(c->pubkey, | 2219 | GNUNET_CRYPTO_short_hash (&pubkey, |
2251 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 2220 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
2252 | &c->zone); | 2221 | &c->zone); |
2253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2254 | "Found zonefile for zone `%s'\n", GNUNET_short_h2s (&c->zone)); | 2223 | "Found zonefile for zone `%s'\n", GNUNET_short_h2s (&c->zone)); |
2255 | GNUNET_CRYPTO_short_hash_double (&c->zone, &long_hash); | 2224 | GNUNET_CRYPTO_short_hash_double (&c->zone, &long_hash); |