diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-27 11:41:34 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-27 11:41:34 +0000 |
commit | c2aea607aa8549280909eb2eefbd63eea2384b1e (patch) | |
tree | 5beb9cd33338150b2f552bc7ad696553d751938c /src/gns/gnunet-service-gns.c | |
parent | a48e053620c5081570710ff072fd857ba73b0f8d (diff) | |
download | gnunet-c2aea607aa8549280909eb2eefbd63eea2384b1e.tar.gz gnunet-c2aea607aa8549280909eb2eefbd63eea2384b1e.zip |
-fixes, added loading external trusted keys
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 80 |
1 files changed, 60 insertions, 20 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 7772d19c8..070eae4d2 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -949,36 +949,37 @@ put_some_records(void) | |||
949 | /* put a few records into namestore */ | 949 | /* put a few records into namestore */ |
950 | char* ipA = "1.2.3.4"; | 950 | char* ipA = "1.2.3.4"; |
951 | char* ipB = "5.6.7.8"; | 951 | char* ipB = "5.6.7.8"; |
952 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key = GNUNET_CRYPTO_rsa_key_create (); struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *bob; | 952 | //struct GNUNET_CRYPTO_RsaPrivateKey *bob_key = GNUNET_CRYPTO_rsa_key_create (); |
953 | bob = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 953 | //struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *bob; |
954 | //bob = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
954 | 955 | ||
955 | GNUNET_CRYPTO_rsa_key_get_public (bob_key, bob); | 956 | //GNUNET_CRYPTO_rsa_key_get_public (bob_key, bob); |
956 | 957 | ||
957 | GNUNET_HashCode *bob_zone = GNUNET_malloc(sizeof(GNUNET_HashCode)); | 958 | //GNUNET_HashCode *bob_zone = GNUNET_malloc(sizeof(GNUNET_HashCode)); |
958 | 959 | ||
959 | GNUNET_CRYPTO_hash(bob, GNUNET_CRYPTO_RSA_KEY_LENGTH, bob_zone); | 960 | //GNUNET_CRYPTO_hash(bob, GNUNET_CRYPTO_RSA_KEY_LENGTH, bob_zone); |
960 | 961 | ||
961 | struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr)); | 962 | struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr)); |
962 | struct in_addr *bob_web = GNUNET_malloc(sizeof(struct in_addr)); | 963 | struct in_addr *bob_web = GNUNET_malloc(sizeof(struct in_addr)); |
963 | struct GNUNET_NAMESTORE_RecordData rda; | 964 | struct GNUNET_NAMESTORE_RecordData rda; |
964 | struct GNUNET_NAMESTORE_RecordData rdb; | 965 | //struct GNUNET_NAMESTORE_RecordData rdb; |
965 | struct GNUNET_NAMESTORE_RecordData rdb_web; | 966 | //struct GNUNET_NAMESTORE_RecordData rdb_web; |
966 | 967 | ||
967 | GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice)); | 968 | GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice)); |
968 | GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob_web)); | 969 | //GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob_web)); |
969 | 970 | ||
970 | rda.data_size = sizeof(struct in_addr); | 971 | rda.data_size = sizeof(struct in_addr); |
971 | rdb_web.data_size = sizeof(struct in_addr); | 972 | //rdb_web.data_size = sizeof(struct in_addr); |
972 | rdb.data_size = sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); | 973 | //rdb.data_size = sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); |
973 | rda.data = alice; | 974 | rda.data = alice; |
974 | rdb.data = bob; | 975 | //rdb.data = bob; |
975 | rdb_web.data = bob_web; | 976 | //rdb_web.data = bob_web; |
976 | rda.record_type = GNUNET_GNS_RECORD_TYPE_A; | 977 | rda.record_type = GNUNET_GNS_RECORD_TYPE_A; |
977 | rdb_web.record_type = GNUNET_GNS_RECORD_TYPE_A; | 978 | //rdb_web.record_type = GNUNET_GNS_RECORD_TYPE_A; |
978 | rdb.record_type = GNUNET_GNS_RECORD_PKEY; | 979 | //rdb.record_type = GNUNET_GNS_RECORD_PKEY; |
979 | rdb_web.expiration = GNUNET_TIME_absolute_get_forever (); | 980 | //rdb_web.expiration = GNUNET_TIME_absolute_get_forever (); |
980 | rda.expiration = GNUNET_TIME_absolute_get_forever (); | 981 | rda.expiration = GNUNET_TIME_absolute_get_forever (); |
981 | rdb.expiration = GNUNET_TIME_absolute_get_forever (); | 982 | //rdb.expiration = GNUNET_TIME_absolute_get_forever (); |
982 | 983 | ||
983 | //alice.gnunet A IN 1.2.3.4 | 984 | //alice.gnunet A IN 1.2.3.4 |
984 | GNUNET_NAMESTORE_record_create (namestore_handle, | 985 | GNUNET_NAMESTORE_record_create (namestore_handle, |
@@ -987,7 +988,7 @@ put_some_records(void) | |||
987 | &rda, | 988 | &rda, |
988 | NULL, | 989 | NULL, |
989 | NULL); | 990 | NULL); |
990 | 991 | /* | |
991 | //www.bob.gnunet A IN 5.6.7.8 | 992 | //www.bob.gnunet A IN 5.6.7.8 |
992 | GNUNET_NAMESTORE_record_create (namestore_handle, | 993 | GNUNET_NAMESTORE_record_create (namestore_handle, |
993 | zone_key, | 994 | zone_key, |
@@ -1004,6 +1005,7 @@ put_some_records(void) | |||
1004 | NULL, //Signature | 1005 | NULL, //Signature |
1005 | NULL, //Cont | 1006 | NULL, //Cont |
1006 | NULL); //cls | 1007 | NULL); //cls |
1008 | */ | ||
1007 | } | 1009 | } |
1008 | 1010 | ||
1009 | void | 1011 | void |
@@ -1117,6 +1119,31 @@ put_gns_record(void *cls, | |||
1117 | 1119 | ||
1118 | } | 1120 | } |
1119 | 1121 | ||
1122 | void | ||
1123 | put_trusted(char* name, char* keyfile) | ||
1124 | { | ||
1125 | struct GNUNET_NAMESTORE_RecordData rd; | ||
1126 | struct GNUNET_CRYPTO_RsaPrivateKey *key; | ||
1127 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey; | ||
1128 | pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
1129 | |||
1130 | key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | ||
1131 | GNUNET_CRYPTO_rsa_key_get_public (key, pkey); | ||
1132 | rd.data = pkey; | ||
1133 | rd.expiration = GNUNET_TIME_absolute_get_forever (); | ||
1134 | rd.data_size = sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); | ||
1135 | rd.record_type = GNUNET_GNS_RECORD_PKEY; | ||
1136 | |||
1137 | GNUNET_NAMESTORE_record_create (namestore_handle, | ||
1138 | zone_key, | ||
1139 | name, | ||
1140 | &rd, | ||
1141 | NULL, | ||
1142 | NULL); | ||
1143 | } | ||
1144 | |||
1145 | |||
1146 | |||
1120 | /** | 1147 | /** |
1121 | * Periodically iterate over our zone and store everything in dht | 1148 | * Periodically iterate over our zone and store everything in dht |
1122 | * | 1149 | * |
@@ -1163,6 +1190,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1163 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Init GNS\n"); | 1190 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Init GNS\n"); |
1164 | char* keyfile; | 1191 | char* keyfile; |
1165 | char* trusted_entities; | 1192 | char* trusted_entities; |
1193 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | ||
1166 | 1194 | ||
1167 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "gns", | 1195 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "gns", |
1168 | "ZONEKEY", &keyfile)) | 1196 | "ZONEKEY", &keyfile)) |
@@ -1172,10 +1200,12 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1172 | GNUNET_SCHEDULER_shutdown(0); | 1200 | GNUNET_SCHEDULER_shutdown(0); |
1173 | return; | 1201 | return; |
1174 | } | 1202 | } |
1203 | |||
1175 | zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 1204 | zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
1205 | GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey); | ||
1176 | //zone_key = GNUNET_CRYPTO_rsa_key_create (); | 1206 | //zone_key = GNUNET_CRYPTO_rsa_key_create (); |
1177 | 1207 | ||
1178 | GNUNET_CRYPTO_hash(zone_key, GNUNET_CRYPTO_RSA_KEY_LENGTH, | 1208 | GNUNET_CRYPTO_hash(&pkey, GNUNET_CRYPTO_RSA_KEY_LENGTH, |
1179 | &zone_hash); | 1209 | &zone_hash); |
1180 | 1210 | ||
1181 | nc = GNUNET_SERVER_notification_context_create (server, 1); | 1211 | nc = GNUNET_SERVER_notification_context_create (server, 1); |
@@ -1240,10 +1270,20 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1240 | trusted_entities++; | 1270 | trusted_entities++; |
1241 | *trusted_entities = '\0'; | 1271 | *trusted_entities = '\0'; |
1242 | trusted_entities++; | 1272 | trusted_entities++; |
1243 | 1273 | ||
1244 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Adding %s:%s to root zone\n", | 1274 | if (GNUNET_YES == GNUNET_DISK_file_test (trusted_key)) |
1275 | { | ||
1276 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Adding %s:%s to root zone\n", | ||
1245 | trusted_name, | 1277 | trusted_name, |
1246 | trusted_key); | 1278 | trusted_key); |
1279 | put_trusted(trusted_name, trusted_key); | ||
1280 | } | ||
1281 | else | ||
1282 | { | ||
1283 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Keyfile %s does not exist!\n", | ||
1284 | trusted_key); | ||
1285 | //put_trusted(trusted_name, trusted_key); //FIXME for testing | ||
1286 | } | ||
1247 | } | 1287 | } |
1248 | 1288 | ||
1249 | } | 1289 | } |