diff options
author | Andreas Ebner <pansy007@googlemail.com> | 2019-07-24 16:29:32 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-10-07 12:15:32 +0200 |
commit | 40624873cbd2eaf3a94185995b14899ea6ab36bf (patch) | |
tree | 0bcc45fc8ba74c7b218ed2b32fc8b7482a42a37c /src/credential/delegate_misc.c | |
parent | 5091edcec16455febee99afec20e0ffe6cc59c21 (diff) | |
download | gnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.tar.gz gnunet-40624873cbd2eaf3a94185995b14899ea6ab36bf.zip |
Run clang format over some files, experimental implementation of forward algorithm
Diffstat (limited to 'src/credential/delegate_misc.c')
-rw-r--r-- | src/credential/delegate_misc.c | 188 |
1 files changed, 103 insertions, 85 deletions
diff --git a/src/credential/delegate_misc.c b/src/credential/delegate_misc.c index 5dd8609d6..e29859e8c 100644 --- a/src/credential/delegate_misc.c +++ b/src/credential/delegate_misc.c | |||
@@ -33,8 +33,9 @@ | |||
33 | #include "credential.h" | 33 | #include "credential.h" |
34 | #include <inttypes.h> | 34 | #include <inttypes.h> |
35 | 35 | ||
36 | char* | 36 | char * |
37 | GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *cred) | 37 | GNUNET_CREDENTIAL_delegate_to_string ( |
38 | const struct GNUNET_CREDENTIAL_Delegate *cred) | ||
38 | { | 39 | { |
39 | char *cred_str; | 40 | char *cred_str; |
40 | char *subject_pkey; | 41 | char *subject_pkey; |
@@ -43,26 +44,29 @@ GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *c | |||
43 | 44 | ||
44 | subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); | 45 | subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); |
45 | issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); | 46 | issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); |
46 | GNUNET_STRINGS_base64_encode ((char*)&cred->signature, | 47 | GNUNET_STRINGS_base64_encode ((char *) &cred->signature, |
47 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature), | 48 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature), |
48 | &signature); | 49 | &signature); |
49 | if(0 == cred->subject_attribute_len){ | 50 | if (0 == cred->subject_attribute_len) |
51 | { | ||
50 | GNUNET_asprintf (&cred_str, | 52 | GNUNET_asprintf (&cred_str, |
51 | "%s.%s -> %s | %s | %"SCNu64, | 53 | "%s.%s -> %s | %s | %" SCNu64, |
52 | issuer_pkey, | 54 | issuer_pkey, |
53 | cred->issuer_attribute, | 55 | cred->issuer_attribute, |
54 | subject_pkey, | 56 | subject_pkey, |
55 | signature, | 57 | signature, |
56 | cred->expiration.abs_value_us); | 58 | cred->expiration.abs_value_us); |
57 | } else { | 59 | } |
60 | else | ||
61 | { | ||
58 | GNUNET_asprintf (&cred_str, | 62 | GNUNET_asprintf (&cred_str, |
59 | "%s.%s -> %s.%s | %s | %"SCNu64, | 63 | "%s.%s -> %s.%s | %s | %" SCNu64, |
60 | issuer_pkey, | 64 | issuer_pkey, |
61 | cred->issuer_attribute, | 65 | cred->issuer_attribute, |
62 | subject_pkey, | 66 | subject_pkey, |
63 | cred->subject_attribute, | 67 | cred->subject_attribute, |
64 | signature, | 68 | signature, |
65 | cred->expiration.abs_value_us); | 69 | cred->expiration.abs_value_us); |
66 | } | 70 | } |
67 | GNUNET_free (subject_pkey); | 71 | GNUNET_free (subject_pkey); |
68 | GNUNET_free (issuer_pkey); | 72 | GNUNET_free (issuer_pkey); |
@@ -71,8 +75,8 @@ GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *c | |||
71 | return cred_str; | 75 | return cred_str; |
72 | } | 76 | } |
73 | 77 | ||
74 | struct GNUNET_CREDENTIAL_Delegate* | 78 | struct GNUNET_CREDENTIAL_Delegate * |
75 | GNUNET_CREDENTIAL_delegate_from_string (const char* s) | 79 | GNUNET_CREDENTIAL_delegate_from_string (const char *s) |
76 | { | 80 | { |
77 | struct GNUNET_CREDENTIAL_Delegate *dele; | 81 | struct GNUNET_CREDENTIAL_Delegate *dele; |
78 | size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; | 82 | size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; |
@@ -91,7 +95,7 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) | |||
91 | 95 | ||
92 | // If it's A.a <- B.b... | 96 | // If it's A.a <- B.b... |
93 | if (6 != SSCANF (s, | 97 | if (6 != SSCANF (s, |
94 | "%52s.%253s -> %52s.%253s | %s | %"SCNu64, | 98 | "%52s.%253s -> %52s.%253s | %s | %" SCNu64, |
95 | issuer_pkey, | 99 | issuer_pkey, |
96 | iss_attr, | 100 | iss_attr, |
97 | subject_pkey, | 101 | subject_pkey, |
@@ -101,59 +105,69 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) | |||
101 | { | 105 | { |
102 | // Try if it's A.a <- B | 106 | // Try if it's A.a <- B |
103 | if (5 != SSCANF (s, | 107 | if (5 != SSCANF (s, |
104 | "%52s.%253s -> %52s | %s | %"SCNu64, | 108 | "%52s.%253s -> %52s | %s | %" SCNu64, |
105 | issuer_pkey, | 109 | issuer_pkey, |
106 | iss_attr, | 110 | iss_attr, |
107 | subject_pkey, | 111 | subject_pkey, |
108 | signature, | 112 | signature, |
109 | &etime_abs.abs_value_us)) | 113 | &etime_abs.abs_value_us)) |
110 | { | 114 | { |
111 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to parse DEL record string `%s'\n", s); | 115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
116 | "Unable to parse DEL record string `%s'\n", | ||
117 | s); | ||
112 | return NULL; | 118 | return NULL; |
113 | } | 119 | } |
114 | } | 120 | } |
115 | 121 | ||
116 | // +1 for \0 | 122 | // +1 for \0 |
117 | int attr_len; | 123 | int attr_len; |
118 | if(strcmp(sub_attr,"") == 0) { | 124 | if (strcmp (sub_attr, "") == 0) |
125 | { | ||
119 | attr_len = strlen (iss_attr) + 1; | 126 | attr_len = strlen (iss_attr) + 1; |
120 | } else { | 127 | } |
121 | attr_len = strlen (iss_attr) + strlen(sub_attr) + 2; | 128 | else |
129 | { | ||
130 | attr_len = strlen (iss_attr) + strlen (sub_attr) + 2; | ||
122 | } | 131 | } |
123 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); | 132 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); |
124 | 133 | ||
125 | char tmp_str[attr_len]; | 134 | char tmp_str[attr_len]; |
126 | GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); | 135 | GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr)); |
127 | if(strcmp(sub_attr,"") != 0) { | 136 | if (strcmp (sub_attr, "") != 0) |
128 | tmp_str[strlen(iss_attr)] = '\0'; | 137 | { |
129 | GNUNET_memcpy(tmp_str + strlen(iss_attr) + 1, sub_attr, strlen(sub_attr)); | 138 | tmp_str[strlen (iss_attr)] = '\0'; |
139 | GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1, | ||
140 | sub_attr, | ||
141 | strlen (sub_attr)); | ||
130 | } | 142 | } |
131 | tmp_str[attr_len - 1] = '\0'; | 143 | tmp_str[attr_len - 1] = '\0'; |
132 | 144 | ||
133 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, | 145 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, |
134 | strlen (subject_pkey), | 146 | strlen (subject_pkey), |
135 | &dele->subject_key); | 147 | &dele->subject_key); |
136 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, | 148 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, |
137 | strlen (issuer_pkey), | 149 | strlen (issuer_pkey), |
138 | &dele->issuer_key); | 150 | &dele->issuer_key); |
139 | GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode (signature, | 151 | GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == |
140 | strlen (signature), | 152 | GNUNET_STRINGS_base64_decode (signature, |
141 | (char**)&sig)); | 153 | strlen (signature), |
154 | (char **) &sig)); | ||
142 | dele->signature = *sig; | 155 | dele->signature = *sig; |
143 | dele->expiration = etime_abs; | 156 | dele->expiration = etime_abs; |
144 | GNUNET_free (sig); | 157 | GNUNET_free (sig); |
145 | 158 | ||
146 | GNUNET_memcpy (&dele[1], | 159 | GNUNET_memcpy (&dele[1], tmp_str, attr_len); |
147 | tmp_str, | ||
148 | attr_len); | ||
149 | 160 | ||
150 | dele->issuer_attribute = (char*)&dele[1]; | 161 | dele->issuer_attribute = (char *) &dele[1]; |
151 | dele->issuer_attribute_len = strlen (iss_attr); | 162 | dele->issuer_attribute_len = strlen (iss_attr); |
152 | if(strcmp(sub_attr,"") == 0) { | 163 | if (strcmp (sub_attr, "") == 0) |
164 | { | ||
153 | dele->subject_attribute = NULL; | 165 | dele->subject_attribute = NULL; |
154 | dele->subject_attribute_len = 0; | 166 | dele->subject_attribute_len = 0; |
155 | } else { | 167 | } |
156 | dele->subject_attribute = (char*)&dele[1] + strlen(iss_attr) + 1; | 168 | else |
169 | { | ||
170 | dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1; | ||
157 | dele->subject_attribute_len = strlen (sub_attr); | 171 | dele->subject_attribute_len = strlen (sub_attr); |
158 | } | 172 | } |
159 | 173 | ||
@@ -170,56 +184,62 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) | |||
170 | */ | 184 | */ |
171 | 185 | ||
172 | struct GNUNET_CREDENTIAL_Delegate * | 186 | struct GNUNET_CREDENTIAL_Delegate * |
173 | GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | 187 | GNUNET_CREDENTIAL_delegate_issue ( |
174 | struct GNUNET_CRYPTO_EcdsaPublicKey *subject, | 188 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, |
175 | const char *iss_attr, | 189 | struct GNUNET_CRYPTO_EcdsaPublicKey *subject, |
176 | const char *sub_attr, | 190 | const char *iss_attr, |
177 | struct GNUNET_TIME_Absolute *expiration) | 191 | const char *sub_attr, |
192 | struct GNUNET_TIME_Absolute *expiration) | ||
178 | { | 193 | { |
179 | struct DelegateEntry *del; | 194 | struct DelegateEntry *del; |
180 | struct GNUNET_CREDENTIAL_Delegate *dele; | 195 | struct GNUNET_CREDENTIAL_Delegate *dele; |
181 | size_t size; | 196 | size_t size; |
182 | int attr_len; | 197 | int attr_len; |
183 | 198 | ||
184 | if (NULL == sub_attr){ | 199 | if (NULL == sub_attr) |
200 | { | ||
185 | // +1 for \0 | 201 | // +1 for \0 |
186 | attr_len = strlen (iss_attr) + 1; | 202 | attr_len = strlen (iss_attr) + 1; |
187 | } else { | 203 | } |
204 | else | ||
205 | { | ||
188 | // +2 for both strings need to be terminated with \0 | 206 | // +2 for both strings need to be terminated with \0 |
189 | attr_len = strlen (iss_attr) + strlen(sub_attr) + 2; | 207 | attr_len = strlen (iss_attr) + strlen (sub_attr) + 2; |
190 | } | 208 | } |
191 | size = sizeof (struct DelegateEntry) + attr_len; | 209 | size = sizeof (struct DelegateEntry) + attr_len; |
192 | 210 | ||
193 | char tmp_str[attr_len]; | 211 | char tmp_str[attr_len]; |
194 | GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); | 212 | GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr)); |
195 | if (NULL != sub_attr){ | 213 | if (NULL != sub_attr) |
196 | tmp_str[strlen(iss_attr)] = '\0'; | 214 | { |
197 | GNUNET_memcpy(tmp_str + strlen(iss_attr) + 1, sub_attr, strlen(sub_attr)); | 215 | tmp_str[strlen (iss_attr)] = '\0'; |
216 | GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1, | ||
217 | sub_attr, | ||
218 | strlen (sub_attr)); | ||
198 | } | 219 | } |
199 | tmp_str[attr_len - 1] = '\0'; | 220 | tmp_str[attr_len - 1] = '\0'; |
200 | 221 | ||
201 | del = GNUNET_malloc (size); | 222 | del = GNUNET_malloc (size); |
202 | del->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | 223 | del->purpose.size = |
224 | htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | ||
203 | del->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); | 225 | del->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); |
204 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, | 226 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, &del->issuer_key); |
205 | &del->issuer_key); | ||
206 | del->subject_key = *subject; | 227 | del->subject_key = *subject; |
207 | del->expiration = GNUNET_htonll (expiration->abs_value_us); | 228 | del->expiration = GNUNET_htonll (expiration->abs_value_us); |
208 | del->issuer_attribute_len = htonl (strlen (iss_attr) + 1); | 229 | del->issuer_attribute_len = htonl (strlen (iss_attr) + 1); |
209 | if (NULL == sub_attr){ | 230 | if (NULL == sub_attr) |
231 | { | ||
210 | del->subject_attribute_len = htonl (0); | 232 | del->subject_attribute_len = htonl (0); |
211 | } else { | 233 | } |
234 | else | ||
235 | { | ||
212 | del->subject_attribute_len = htonl (strlen (sub_attr) + 1); | 236 | del->subject_attribute_len = htonl (strlen (sub_attr) + 1); |
213 | } | 237 | } |
214 | 238 | ||
215 | GNUNET_memcpy (&del[1], | 239 | GNUNET_memcpy (&del[1], tmp_str, attr_len); |
216 | tmp_str, | 240 | |
217 | attr_len); | ||
218 | |||
219 | if (GNUNET_OK != | 241 | if (GNUNET_OK != |
220 | GNUNET_CRYPTO_ecdsa_sign (issuer, | 242 | GNUNET_CRYPTO_ecdsa_sign (issuer, &del->purpose, &del->signature)) |
221 | &del->purpose, | ||
222 | &del->signature)) | ||
223 | { | 243 | { |
224 | GNUNET_break (0); | 244 | GNUNET_break (0); |
225 | GNUNET_free (del); | 245 | GNUNET_free (del); |
@@ -229,24 +249,24 @@ GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *is | |||
229 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); | 249 | dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); |
230 | dele->signature = del->signature; | 250 | dele->signature = del->signature; |
231 | dele->expiration = *expiration; | 251 | dele->expiration = *expiration; |
232 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, | 252 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, &dele->issuer_key); |
233 | &dele->issuer_key); | ||
234 | 253 | ||
235 | dele->subject_key = *subject; | 254 | dele->subject_key = *subject; |
236 | 255 | ||
237 | // Copy the combined string at the part in the memory where the struct ends | 256 | // Copy the combined string at the part in the memory where the struct ends |
238 | GNUNET_memcpy (&dele[1], | 257 | GNUNET_memcpy (&dele[1], tmp_str, attr_len); |
239 | tmp_str, | ||
240 | attr_len); | ||
241 | 258 | ||
242 | dele->issuer_attribute = (char*)&dele[1]; | 259 | dele->issuer_attribute = (char *) &dele[1]; |
243 | dele->issuer_attribute_len = strlen(iss_attr); | 260 | dele->issuer_attribute_len = strlen (iss_attr); |
244 | if (NULL == sub_attr){ | 261 | if (NULL == sub_attr) |
262 | { | ||
245 | dele->subject_attribute = NULL; | 263 | dele->subject_attribute = NULL; |
246 | dele->subject_attribute_len = 0; | 264 | dele->subject_attribute_len = 0; |
247 | } else { | 265 | } |
248 | dele->subject_attribute = (char*)&dele[1] + strlen(iss_attr) + 1; | 266 | else |
249 | dele->subject_attribute_len = strlen(sub_attr); | 267 | { |
268 | dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1; | ||
269 | dele->subject_attribute_len = strlen (sub_attr); | ||
250 | } | 270 | } |
251 | 271 | ||
252 | GNUNET_free (del); | 272 | GNUNET_free (del); |
@@ -256,5 +276,3 @@ GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *is | |||
256 | // oder: pointer auf cred[1], aber nach jedem string im combined string ein EOS <- besser | 276 | // 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) | 277 | // function comment: cred must be freed by caller, (add missing sub_iss) |
258 | } | 278 | } |
259 | |||
260 | |||