diff options
Diffstat (limited to 'src/credential/delegate_misc.c')
-rw-r--r-- | src/credential/delegate_misc.c | 114 |
1 files changed, 62 insertions, 52 deletions
diff --git a/src/credential/delegate_misc.c b/src/credential/delegate_misc.c index d900ccd1f..5dd8609d6 100644 --- a/src/credential/delegate_misc.c +++ b/src/credential/delegate_misc.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include "gnunet_constants.h" | 30 | #include "gnunet_constants.h" |
31 | #include "gnunet_credential_service.h" | 31 | #include "gnunet_credential_service.h" |
32 | #include "gnunet_signatures.h" | 32 | #include "gnunet_signatures.h" |
33 | #include "delegate.h" | 33 | #include "credential.h" |
34 | #include <inttypes.h> | 34 | #include <inttypes.h> |
35 | 35 | ||
36 | char* | 36 | char* |
@@ -74,7 +74,7 @@ GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *c | |||
74 | struct GNUNET_CREDENTIAL_Delegate* | 74 | struct GNUNET_CREDENTIAL_Delegate* |
75 | GNUNET_CREDENTIAL_delegate_from_string (const char* s) | 75 | GNUNET_CREDENTIAL_delegate_from_string (const char* s) |
76 | { | 76 | { |
77 | struct GNUNET_CREDENTIAL_Delegate *cred; | 77 | struct GNUNET_CREDENTIAL_Delegate *dele; |
78 | size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; | 78 | size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; |
79 | if (enclen % 5 > 0) | 79 | if (enclen % 5 > 0) |
80 | enclen += 5 - enclen % 5; | 80 | enclen += 5 - enclen % 5; |
@@ -118,44 +118,46 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) | |||
118 | if(strcmp(sub_attr,"") == 0) { | 118 | if(strcmp(sub_attr,"") == 0) { |
119 | attr_len = strlen (iss_attr) + 1; | 119 | attr_len = strlen (iss_attr) + 1; |
120 | } else { | 120 | } else { |
121 | attr_len = strlen (iss_attr) + strlen(sub_attr) + 1; | 121 | attr_len = strlen (iss_attr) + strlen(sub_attr) + 2; |
122 | } | 122 | } |
123 | cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); | 123 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); |
124 | 124 | ||
125 | char tmp_str[attr_len]; | 125 | char tmp_str[attr_len]; |
126 | GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); | 126 | GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); |
127 | if(strcmp(sub_attr,"") != 0) { | 127 | if(strcmp(sub_attr,"") != 0) { |
128 | GNUNET_memcpy(tmp_str + strlen(iss_attr), sub_attr, strlen(sub_attr)); | 128 | tmp_str[strlen(iss_attr)] = '\0'; |
129 | GNUNET_memcpy(tmp_str + strlen(iss_attr) + 1, sub_attr, strlen(sub_attr)); | ||
129 | } | 130 | } |
130 | tmp_str[attr_len - 1] = '\0'; | 131 | tmp_str[attr_len - 1] = '\0'; |
131 | 132 | ||
132 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, | 133 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, |
133 | strlen (subject_pkey), | 134 | strlen (subject_pkey), |
134 | &cred->subject_key); | 135 | &dele->subject_key); |
135 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, | 136 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, |
136 | strlen (issuer_pkey), | 137 | strlen (issuer_pkey), |
137 | &cred->issuer_key); | 138 | &dele->issuer_key); |
138 | GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode (signature, | 139 | GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode (signature, |
139 | strlen (signature), | 140 | strlen (signature), |
140 | (char**)&sig)); | 141 | (char**)&sig)); |
141 | cred->signature = *sig; | 142 | dele->signature = *sig; |
142 | cred->expiration = etime_abs; | 143 | dele->expiration = etime_abs; |
143 | GNUNET_free (sig); | 144 | GNUNET_free (sig); |
144 | GNUNET_memcpy (&cred[1], | 145 | |
146 | GNUNET_memcpy (&dele[1], | ||
145 | tmp_str, | 147 | tmp_str, |
146 | attr_len); | 148 | attr_len); |
147 | 149 | ||
148 | cred->issuer_attribute_len = strlen (iss_attr); | 150 | dele->issuer_attribute = (char*)&dele[1]; |
149 | cred->issuer_attribute = strdup(iss_attr); | 151 | dele->issuer_attribute_len = strlen (iss_attr); |
150 | if(strcmp(sub_attr,"") == 0) { | 152 | if(strcmp(sub_attr,"") == 0) { |
151 | cred->subject_attribute_len = 0; | 153 | dele->subject_attribute = NULL; |
152 | cred->subject_attribute = '\0'; | 154 | dele->subject_attribute_len = 0; |
153 | } else { | 155 | } else { |
154 | cred->subject_attribute_len = strlen (sub_attr); | 156 | dele->subject_attribute = (char*)&dele[1] + strlen(iss_attr) + 1; |
155 | cred->subject_attribute = strdup(sub_attr); | 157 | dele->subject_attribute_len = strlen (sub_attr); |
156 | } | 158 | } |
157 | 159 | ||
158 | return cred; | 160 | return dele; |
159 | } | 161 | } |
160 | 162 | ||
161 | /** | 163 | /** |
@@ -163,7 +165,7 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) | |||
163 | * | 165 | * |
164 | * @param issuer the ego that should be used to issue the attribute | 166 | * @param issuer the ego that should be used to issue the attribute |
165 | * @param subject the subject of the attribute | 167 | * @param subject the subject of the attribute |
166 | * @param attribute the name of the attribute | 168 | * @param iss_attr the name of the attribute |
167 | * @return handle to the queued request | 169 | * @return handle to the queued request |
168 | */ | 170 | */ |
169 | 171 | ||
@@ -174,8 +176,8 @@ GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *is | |||
174 | const char *sub_attr, | 176 | const char *sub_attr, |
175 | struct GNUNET_TIME_Absolute *expiration) | 177 | struct GNUNET_TIME_Absolute *expiration) |
176 | { | 178 | { |
177 | struct DelegateEntry *crd; | 179 | struct DelegateEntry *del; |
178 | struct GNUNET_CREDENTIAL_Delegate *cred; | 180 | struct GNUNET_CREDENTIAL_Delegate *dele; |
179 | size_t size; | 181 | size_t size; |
180 | int attr_len; | 182 | int attr_len; |
181 | 183 | ||
@@ -183,68 +185,76 @@ GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *is | |||
183 | // +1 for \0 | 185 | // +1 for \0 |
184 | attr_len = strlen (iss_attr) + 1; | 186 | attr_len = strlen (iss_attr) + 1; |
185 | } else { | 187 | } else { |
186 | attr_len = strlen (iss_attr) + strlen(sub_attr) + 1; | 188 | // +2 for both strings need to be terminated with \0 |
189 | attr_len = strlen (iss_attr) + strlen(sub_attr) + 2; | ||
187 | } | 190 | } |
188 | size = sizeof (struct DelegateEntry) + attr_len; | 191 | size = sizeof (struct DelegateEntry) + attr_len; |
189 | 192 | ||
190 | char tmp_str[attr_len]; | 193 | char tmp_str[attr_len]; |
191 | GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); | 194 | GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); |
192 | if (NULL != sub_attr){ | 195 | if (NULL != sub_attr){ |
193 | GNUNET_memcpy(tmp_str + strlen(iss_attr), sub_attr, strlen(sub_attr)); | 196 | tmp_str[strlen(iss_attr)] = '\0'; |
197 | GNUNET_memcpy(tmp_str + strlen(iss_attr) + 1, sub_attr, strlen(sub_attr)); | ||
194 | } | 198 | } |
195 | tmp_str[attr_len - 1] = '\0'; | 199 | tmp_str[attr_len - 1] = '\0'; |
196 | 200 | ||
197 | crd = GNUNET_malloc (size); | 201 | del = GNUNET_malloc (size); |
198 | crd->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | 202 | del->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); |
199 | crd->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | 203 | del->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); |
200 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, | 204 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, |
201 | &crd->issuer_key); | 205 | &del->issuer_key); |
202 | crd->subject_key = *subject; | 206 | del->subject_key = *subject; |
203 | crd->expiration = GNUNET_htonll (expiration->abs_value_us); | 207 | del->expiration = GNUNET_htonll (expiration->abs_value_us); |
204 | crd->issuer_attribute_len = htonl (strlen (iss_attr) + 1); | 208 | del->issuer_attribute_len = htonl (strlen (iss_attr) + 1); |
205 | if (NULL == sub_attr){ | 209 | if (NULL == sub_attr){ |
206 | crd->subject_attribute_len = htonl (0); | 210 | del->subject_attribute_len = htonl (0); |
207 | } else { | 211 | } else { |
208 | crd->subject_attribute_len = htonl (strlen (sub_attr) + 1); | 212 | del->subject_attribute_len = htonl (strlen (sub_attr) + 1); |
209 | } | 213 | } |
210 | 214 | ||
211 | GNUNET_memcpy (&crd[1], | 215 | GNUNET_memcpy (&del[1], |
212 | tmp_str, | 216 | tmp_str, |
213 | attr_len); | 217 | attr_len); |
214 | 218 | ||
215 | if (GNUNET_OK != | 219 | if (GNUNET_OK != |
216 | GNUNET_CRYPTO_ecdsa_sign (issuer, | 220 | GNUNET_CRYPTO_ecdsa_sign (issuer, |
217 | &crd->purpose, | 221 | &del->purpose, |
218 | &crd->signature)) | 222 | &del->signature)) |
219 | { | 223 | { |
220 | GNUNET_break (0); | 224 | GNUNET_break (0); |
221 | GNUNET_free (crd); | 225 | GNUNET_free (del); |
222 | return NULL; | 226 | return NULL; |
223 | } | 227 | } |
224 | 228 | ||
225 | cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); | 229 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); |
226 | cred->signature = crd->signature; | 230 | dele->signature = del->signature; |
227 | cred->expiration = *expiration; | 231 | dele->expiration = *expiration; |
228 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, | 232 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, |
229 | &cred->issuer_key); | 233 | &dele->issuer_key); |
230 | 234 | ||
231 | cred->subject_key = *subject; | 235 | dele->subject_key = *subject; |
232 | cred->issuer_attribute = strdup(iss_attr); | 236 | |
233 | cred->issuer_attribute_len = strlen(iss_attr); | 237 | // Copy the combined string at the part in the memory where the struct ends |
238 | GNUNET_memcpy (&dele[1], | ||
239 | tmp_str, | ||
240 | attr_len); | ||
241 | |||
242 | dele->issuer_attribute = (char*)&dele[1]; | ||
243 | dele->issuer_attribute_len = strlen(iss_attr); | ||
234 | if (NULL == sub_attr){ | 244 | if (NULL == sub_attr){ |
235 | cred->subject_attribute = '\0'; | 245 | dele->subject_attribute = NULL; |
236 | cred->subject_attribute_len = 0; | 246 | dele->subject_attribute_len = 0; |
237 | } else { | 247 | } else { |
238 | cred->subject_attribute = strdup(sub_attr); | 248 | dele->subject_attribute = (char*)&dele[1] + strlen(iss_attr) + 1; |
239 | cred->subject_attribute_len = strlen(sub_attr); | 249 | dele->subject_attribute_len = strlen(sub_attr); |
240 | } | 250 | } |
241 | 251 | ||
242 | GNUNET_memcpy (&cred[1], | 252 | GNUNET_free (del); |
243 | tmp_str, | 253 | return dele; |
244 | attr_len); | ||
245 | 254 | ||
246 | GNUNET_free (crd); | 255 | // Entweder: strdup und destroy (free auf die subjct_attribute/issuer_attribute) |
247 | return cred; | 256 | // oder: pointer auf cred[1], aber nach jedem string im combined string ein EOS <- besser |
257 | // function comment: cred must be freed by caller, (add missing sub_iss) | ||
248 | } | 258 | } |
249 | 259 | ||
250 | 260 | ||