diff options
Diffstat (limited to 'src/hello/hello-ng.c')
-rw-r--r-- | src/hello/hello-ng.c | 99 |
1 files changed, 41 insertions, 58 deletions
diff --git a/src/hello/hello-ng.c b/src/hello/hello-ng.c index 2d60b04f3..29ab17f9b 100644 --- a/src/hello/hello-ng.c +++ b/src/hello/hello-ng.c | |||
@@ -41,9 +41,9 @@ struct SignedAddress | |||
41 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | 41 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * When does the address expire. | 44 | * When was the address generated. |
45 | */ | 45 | */ |
46 | struct GNUNET_TIME_AbsoluteNBO expiration; | 46 | struct GNUNET_TIME_AbsoluteNBO mono_time; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Hash of the address. | 49 | * Hash of the address. |
@@ -57,18 +57,19 @@ struct SignedAddress | |||
57 | * | 57 | * |
58 | * @param address text address at @a communicator to sign | 58 | * @param address text address at @a communicator to sign |
59 | * @param nt network type of @a address | 59 | * @param nt network type of @a address |
60 | * @param expiration how long is @a address valid | 60 | * @param mono_time monotonic time at which @a address was valid |
61 | * @param private_key signing key to use | 61 | * @param private_key signing key to use |
62 | * @param result[out] where to write address record (allocated) | 62 | * @param result[out] where to write address record (allocated) |
63 | * @param result_size[out] set to size of @a result | 63 | * @param result_size[out] set to size of @a result |
64 | */ | 64 | */ |
65 | void | 65 | void |
66 | GNUNET_HELLO_sign_address (const char *address, | 66 | GNUNET_HELLO_sign_address ( |
67 | enum GNUNET_NetworkType nt, | 67 | const char *address, |
68 | struct GNUNET_TIME_Absolute expiration, | 68 | enum GNUNET_NetworkType nt, |
69 | const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, | 69 | struct GNUNET_TIME_Absolute mono_time, |
70 | void **result, | 70 | const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, |
71 | size_t *result_size) | 71 | void **result, |
72 | size_t *result_size) | ||
72 | { | 73 | { |
73 | struct SignedAddress sa; | 74 | struct SignedAddress sa; |
74 | struct GNUNET_CRYPTO_EddsaSignature sig; | 75 | struct GNUNET_CRYPTO_EddsaSignature sig; |
@@ -76,24 +77,19 @@ GNUNET_HELLO_sign_address (const char *address, | |||
76 | 77 | ||
77 | sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); | 78 | sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); |
78 | sa.purpose.size = htonl (sizeof (sa)); | 79 | sa.purpose.size = htonl (sizeof (sa)); |
79 | sa.expiration = GNUNET_TIME_absolute_hton (expiration); | 80 | sa.mono_time = GNUNET_TIME_absolute_hton (mono_time); |
80 | GNUNET_CRYPTO_hash (address, | 81 | GNUNET_CRYPTO_hash (address, strlen (address), &sa.h_addr); |
81 | strlen (address), | ||
82 | &sa.h_addr); | ||
83 | GNUNET_assert (GNUNET_YES == | 82 | GNUNET_assert (GNUNET_YES == |
84 | GNUNET_CRYPTO_eddsa_sign (private_key, | 83 | GNUNET_CRYPTO_eddsa_sign (private_key, &sa.purpose, &sig)); |
85 | &sa.purpose, | ||
86 | &sig)); | ||
87 | sig_str = NULL; | 84 | sig_str = NULL; |
88 | (void) GNUNET_STRINGS_base64_encode (&sig, | 85 | (void) GNUNET_STRINGS_base64_encode (&sig, sizeof (sig), &sig_str); |
89 | sizeof (sig), | 86 | *result_size = |
90 | &sig_str); | 87 | 1 + GNUNET_asprintf ((char **) result, |
91 | *result_size = 1 + GNUNET_asprintf ((char **) result, | 88 | "%s;%llu;%u;%s", |
92 | "%s;%llu;%u;%s", | 89 | sig_str, |
93 | sig_str, | 90 | (unsigned long long) mono_time.abs_value_us, |
94 | (unsigned long long) expiration.abs_value_us, | 91 | (unsigned int) nt, |
95 | (unsigned int) nt, | 92 | address); |
96 | address); | ||
97 | GNUNET_free (sig_str); | 93 | GNUNET_free (sig_str); |
98 | } | 94 | } |
99 | 95 | ||
@@ -105,15 +101,15 @@ GNUNET_HELLO_sign_address (const char *address, | |||
105 | * @param raw_size size of @a raw | 101 | * @param raw_size size of @a raw |
106 | * @param pid public key to use for signature verification | 102 | * @param pid public key to use for signature verification |
107 | * @param nt[out] set to network type | 103 | * @param nt[out] set to network type |
108 | * @param expiration[out] how long is the address valid | 104 | * @param mono_time[out] when was the address generated |
109 | * @return NULL on error, otherwise the address | 105 | * @return NULL on error, otherwise the address |
110 | */ | 106 | */ |
111 | char * | 107 | char * |
112 | GNUNET_HELLO_extract_address (const void *raw, | 108 | GNUNET_HELLO_extract_address (const void *raw, |
113 | size_t raw_size, | 109 | size_t raw_size, |
114 | const struct GNUNET_PeerIdentity *pid, | 110 | const struct GNUNET_PeerIdentity *pid, |
115 | enum GNUNET_NetworkType *nt, | 111 | enum GNUNET_NetworkType *nt, |
116 | struct GNUNET_TIME_Absolute *expiration) | 112 | struct GNUNET_TIME_Absolute *mono_time) |
117 | { | 113 | { |
118 | const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key; | 114 | const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key; |
119 | const char *raws = raw; | 115 | const char *raws = raw; |
@@ -123,7 +119,7 @@ GNUNET_HELLO_extract_address (const void *raw, | |||
123 | const char *sc2; | 119 | const char *sc2; |
124 | const char *sc3; | 120 | const char *sc3; |
125 | const char *raw_addr; | 121 | const char *raw_addr; |
126 | struct GNUNET_TIME_Absolute raw_expiration; | 122 | struct GNUNET_TIME_Absolute raw_mono_time; |
127 | struct SignedAddress sa; | 123 | struct SignedAddress sa; |
128 | struct GNUNET_CRYPTO_EddsaSignature *sig; | 124 | struct GNUNET_CRYPTO_EddsaSignature *sig; |
129 | 125 | ||
@@ -132,40 +128,30 @@ GNUNET_HELLO_extract_address (const void *raw, | |||
132 | GNUNET_break_op (0); | 128 | GNUNET_break_op (0); |
133 | return NULL; | 129 | return NULL; |
134 | } | 130 | } |
135 | if (NULL == (sc = strchr (raws, | 131 | if (NULL == (sc = strchr (raws, ';'))) |
136 | ';'))) | ||
137 | { | 132 | { |
138 | GNUNET_break_op (0); | 133 | GNUNET_break_op (0); |
139 | return NULL; | 134 | return NULL; |
140 | } | 135 | } |
141 | if (NULL == (sc2 = strchr (sc + 1, | 136 | if (NULL == (sc2 = strchr (sc + 1, ';'))) |
142 | ';'))) | ||
143 | { | 137 | { |
144 | GNUNET_break_op (0); | 138 | GNUNET_break_op (0); |
145 | return NULL; | 139 | return NULL; |
146 | } | 140 | } |
147 | if (NULL == (sc3 = strchr (sc2 + 1, | 141 | if (NULL == (sc3 = strchr (sc2 + 1, ';'))) |
148 | ';'))) | ||
149 | { | 142 | { |
150 | GNUNET_break_op (0); | 143 | GNUNET_break_op (0); |
151 | return NULL; | 144 | return NULL; |
152 | } | 145 | } |
153 | if (1 != sscanf (sc + 1, | 146 | if (1 != sscanf (sc + 1, "%llu;%u;", &raw_us, &raw_nt)) |
154 | "%llu;%u;", | ||
155 | &raw_us, | ||
156 | &raw_nt)) | ||
157 | { | 147 | { |
158 | GNUNET_break_op (0); | 148 | GNUNET_break_op (0); |
159 | return NULL; | 149 | return NULL; |
160 | } | 150 | } |
161 | raw_expiration.abs_value_us = raw_us; | 151 | raw_mono_time.abs_value_us = raw_us; |
162 | if (0 == GNUNET_TIME_absolute_get_remaining (raw_expiration).rel_value_us) | ||
163 | return NULL; /* expired */ | ||
164 | sig = NULL; | 152 | sig = NULL; |
165 | if (sizeof (struct GNUNET_CRYPTO_EddsaSignature) != | 153 | if (sizeof (struct GNUNET_CRYPTO_EddsaSignature) != |
166 | GNUNET_STRINGS_base64_decode (raws, | 154 | GNUNET_STRINGS_base64_decode (raws, sc - raws, (void **) &sig)) |
167 | sc - raws, | ||
168 | (void **) &sig)) | ||
169 | { | 155 | { |
170 | GNUNET_break_op (0); | 156 | GNUNET_break_op (0); |
171 | GNUNET_free_non_null (sig); | 157 | GNUNET_free_non_null (sig); |
@@ -175,22 +161,20 @@ GNUNET_HELLO_extract_address (const void *raw, | |||
175 | 161 | ||
176 | sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); | 162 | sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); |
177 | sa.purpose.size = htonl (sizeof (sa)); | 163 | sa.purpose.size = htonl (sizeof (sa)); |
178 | sa.expiration = GNUNET_TIME_absolute_hton (raw_expiration); | 164 | sa.mono_time = GNUNET_TIME_absolute_hton (raw_mono_time); |
179 | GNUNET_CRYPTO_hash (raw_addr, | 165 | GNUNET_CRYPTO_hash (raw_addr, strlen (raw_addr), &sa.h_addr); |
180 | strlen (raw_addr), | ||
181 | &sa.h_addr); | ||
182 | if (GNUNET_YES != | 166 | if (GNUNET_YES != |
183 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, | 167 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, |
184 | &sa.purpose, | 168 | &sa.purpose, |
185 | sig, | 169 | sig, |
186 | public_key)) | 170 | public_key)) |
187 | { | 171 | { |
188 | GNUNET_break_op (0); | 172 | GNUNET_break_op (0); |
189 | GNUNET_free (sig); | 173 | GNUNET_free (sig); |
190 | return NULL; | 174 | return NULL; |
191 | } | 175 | } |
192 | GNUNET_free (sig); | 176 | GNUNET_free (sig); |
193 | *expiration = raw_expiration; | 177 | *mono_time = raw_mono_time; |
194 | *nt = (enum GNUNET_NetworkType) raw_nt; | 178 | *nt = (enum GNUNET_NetworkType) raw_nt; |
195 | return GNUNET_strdup (raw_addr); | 179 | return GNUNET_strdup (raw_addr); |
196 | } | 180 | } |
@@ -202,7 +186,7 @@ GNUNET_HELLO_extract_address (const void *raw, | |||
202 | * | 186 | * |
203 | * @param address a peer's address | 187 | * @param address a peer's address |
204 | * @return NULL if the address is mal-formed, otherwise the prefix | 188 | * @return NULL if the address is mal-formed, otherwise the prefix |
205 | */ | 189 | */ |
206 | char * | 190 | char * |
207 | GNUNET_HELLO_address_to_prefix (const char *address) | 191 | GNUNET_HELLO_address_to_prefix (const char *address) |
208 | { | 192 | { |
@@ -211,6 +195,5 @@ GNUNET_HELLO_address_to_prefix (const char *address) | |||
211 | dash = strchr (address, '-'); | 195 | dash = strchr (address, '-'); |
212 | if (NULL == dash) | 196 | if (NULL == dash) |
213 | return NULL; | 197 | return NULL; |
214 | return GNUNET_strndup (address, | 198 | return GNUNET_strndup (address, dash - address); |
215 | dash - address); | ||
216 | } | 199 | } |