diff options
Diffstat (limited to 'src/identity/gnunet-service-identity.c')
-rw-r--r-- | src/identity/gnunet-service-identity.c | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index bdacf3ba0..6cdb1c2f7 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -57,7 +57,7 @@ struct Ego | |||
57 | /** | 57 | /** |
58 | * Private key of the ego. | 58 | * Private key of the ego. |
59 | */ | 59 | */ |
60 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | 60 | struct GNUNET_IDENTITY_PrivateKey pk; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * String identifier for the ego. | 63 | * String identifier for the ego. |
@@ -538,8 +538,8 @@ handle_get_default_message (void *cls, | |||
538 | * @return 0 if the keys are equal | 538 | * @return 0 if the keys are equal |
539 | */ | 539 | */ |
540 | static int | 540 | static int |
541 | key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, | 541 | key_cmp (const struct GNUNET_IDENTITY_PrivateKey *pk1, |
542 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2) | 542 | const struct GNUNET_IDENTITY_PrivateKey *pk2) |
543 | { | 543 | { |
544 | return GNUNET_memcmp (pk1, pk2); | 544 | return GNUNET_memcmp (pk1, pk2); |
545 | } | 545 | } |
@@ -738,10 +738,10 @@ handle_create_message (void *cls, | |||
738 | send_result_code (client, 0, NULL); | 738 | send_result_code (client, 0, NULL); |
739 | fn = get_ego_filename (ego); | 739 | fn = get_ego_filename (ego); |
740 | (void) GNUNET_DISK_directory_create_for_file (fn); | 740 | (void) GNUNET_DISK_directory_create_for_file (fn); |
741 | if (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey) != | 741 | if (sizeof(struct GNUNET_IDENTITY_PrivateKey) != |
742 | GNUNET_DISK_fn_write (fn, | 742 | GNUNET_DISK_fn_write (fn, |
743 | &crm->private_key, | 743 | &crm->private_key, |
744 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey), | 744 | sizeof(struct GNUNET_IDENTITY_PrivateKey), |
745 | GNUNET_DISK_PERM_USER_READ | 745 | GNUNET_DISK_PERM_USER_READ |
746 | | GNUNET_DISK_PERM_USER_WRITE)) | 746 | | GNUNET_DISK_PERM_USER_WRITE)) |
747 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); | 747 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); |
@@ -1038,6 +1038,67 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm) | |||
1038 | } | 1038 | } |
1039 | 1039 | ||
1040 | 1040 | ||
1041 | static int | ||
1042 | read_from_file (const char *filename, | ||
1043 | void *buf, | ||
1044 | size_t buf_size) | ||
1045 | { | ||
1046 | int fd; | ||
1047 | struct stat sb; | ||
1048 | |||
1049 | fd = open (filename, | ||
1050 | O_RDONLY); | ||
1051 | if (-1 == fd) | ||
1052 | { | ||
1053 | memset (buf, | ||
1054 | 0, | ||
1055 | buf_size); | ||
1056 | return GNUNET_SYSERR; | ||
1057 | } | ||
1058 | if (0 != fstat (fd, | ||
1059 | &sb)) | ||
1060 | { | ||
1061 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1062 | "stat", | ||
1063 | filename); | ||
1064 | GNUNET_assert (0 == close (fd)); | ||
1065 | memset (buf, | ||
1066 | 0, | ||
1067 | buf_size); | ||
1068 | return GNUNET_SYSERR; | ||
1069 | } | ||
1070 | if (sb.st_size != buf_size) | ||
1071 | { | ||
1072 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1073 | "File `%s' has wrong size (%llu), expected %llu bytes\n", | ||
1074 | filename, | ||
1075 | (unsigned long long) sb.st_size, | ||
1076 | (unsigned long long) buf_size); | ||
1077 | GNUNET_assert (0 == close (fd)); | ||
1078 | memset (buf, | ||
1079 | 0, | ||
1080 | buf_size); | ||
1081 | return GNUNET_SYSERR; | ||
1082 | } | ||
1083 | if (buf_size != | ||
1084 | read (fd, | ||
1085 | buf, | ||
1086 | buf_size)) | ||
1087 | { | ||
1088 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1089 | "read", | ||
1090 | filename); | ||
1091 | GNUNET_assert (0 == close (fd)); | ||
1092 | memset (buf, | ||
1093 | 0, | ||
1094 | buf_size); | ||
1095 | return GNUNET_SYSERR; | ||
1096 | } | ||
1097 | GNUNET_assert (0 == close (fd)); | ||
1098 | return GNUNET_OK; | ||
1099 | } | ||
1100 | |||
1101 | |||
1041 | /** | 1102 | /** |
1042 | * Process the given file from the "EGODIR". Parses the file | 1103 | * Process the given file from the "EGODIR". Parses the file |
1043 | * and creates the respective 'struct Ego' in memory. | 1104 | * and creates the respective 'struct Ego' in memory. |
@@ -1063,9 +1124,9 @@ process_ego_file (void *cls, | |||
1063 | } | 1124 | } |
1064 | ego = GNUNET_new (struct Ego); | 1125 | ego = GNUNET_new (struct Ego); |
1065 | if (GNUNET_OK != | 1126 | if (GNUNET_OK != |
1066 | GNUNET_CRYPTO_ecdsa_key_from_file (filename, | 1127 | read_from_file (filename, |
1067 | GNUNET_NO, | 1128 | &ego->pk, |
1068 | &ego->pk)) | 1129 | sizeof (ego->pk))) |
1069 | { | 1130 | { |
1070 | GNUNET_free (ego); | 1131 | GNUNET_free (ego); |
1071 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1132 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |