diff options
Diffstat (limited to 'src/credential/credential_misc.c')
-rw-r--r-- | src/credential/credential_misc.c | 159 |
1 files changed, 80 insertions, 79 deletions
diff --git a/src/credential/credential_misc.c b/src/credential/credential_misc.c index ae208f31f..be6d124a6 100644 --- a/src/credential/credential_misc.c +++ b/src/credential/credential_misc.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | 21 | ||
22 | /** | 22 | /** |
@@ -34,7 +34,7 @@ | |||
34 | #include <inttypes.h> | 34 | #include <inttypes.h> |
35 | 35 | ||
36 | char* | 36 | char* |
37 | GNUNET_CREDENTIAL_credential_to_string (const struct GNUNET_CREDENTIAL_Credential *cred) | 37 | GNUNET_CREDENTIAL_credential_to_string(const struct GNUNET_CREDENTIAL_Credential *cred) |
38 | { | 38 | { |
39 | char *cred_str; | 39 | char *cred_str; |
40 | char *subject_pkey; | 40 | char *subject_pkey; |
@@ -42,29 +42,30 @@ GNUNET_CREDENTIAL_credential_to_string (const struct GNUNET_CREDENTIAL_Credentia | |||
42 | char *signature; | 42 | char *signature; |
43 | 43 | ||
44 | 44 | ||
45 | 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); |
46 | 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); |
47 | GNUNET_STRINGS_base64_encode ((char*)&cred->signature, | 47 | GNUNET_STRINGS_base64_encode((char*)&cred->signature, |
48 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature), | 48 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature), |
49 | &signature); | 49 | &signature); |
50 | GNUNET_asprintf (&cred_str, | 50 | GNUNET_asprintf(&cred_str, |
51 | "%s.%s -> %s | %s | %"SCNu64, | 51 | "%s.%s -> %s | %s | %" SCNu64, |
52 | issuer_pkey, | 52 | issuer_pkey, |
53 | cred->issuer_attribute, | 53 | cred->issuer_attribute, |
54 | subject_pkey, | 54 | subject_pkey, |
55 | signature, | 55 | signature, |
56 | cred->expiration.abs_value_us); | 56 | cred->expiration.abs_value_us); |
57 | GNUNET_free (subject_pkey); | 57 | GNUNET_free(subject_pkey); |
58 | GNUNET_free (issuer_pkey); | 58 | GNUNET_free(issuer_pkey); |
59 | GNUNET_free (signature); | 59 | GNUNET_free(signature); |
60 | return cred_str; | 60 | return cred_str; |
61 | } | 61 | } |
62 | 62 | ||
63 | struct GNUNET_CREDENTIAL_Credential* | 63 | struct GNUNET_CREDENTIAL_Credential* |
64 | GNUNET_CREDENTIAL_credential_from_string (const char* s) | 64 | GNUNET_CREDENTIAL_credential_from_string(const char* s) |
65 | { | 65 | { |
66 | struct GNUNET_CREDENTIAL_Credential *cred; | 66 | struct GNUNET_CREDENTIAL_Credential *cred; |
67 | size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; | 67 | size_t enclen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; |
68 | |||
68 | if (enclen % 5 > 0) | 69 | if (enclen % 5 > 0) |
69 | enclen += 5 - enclen % 5; | 70 | enclen += 5 - enclen % 5; |
70 | enclen /= 5; /* 260/5 = 52 */ | 71 | enclen /= 5; /* 260/5 = 52 */ |
@@ -76,36 +77,36 @@ GNUNET_CREDENTIAL_credential_from_string (const char* s) | |||
76 | struct GNUNET_CRYPTO_EcdsaSignature *sig; | 77 | struct GNUNET_CRYPTO_EcdsaSignature *sig; |
77 | struct GNUNET_TIME_Absolute etime_abs; | 78 | struct GNUNET_TIME_Absolute etime_abs; |
78 | 79 | ||
79 | if (5 != SSCANF (s, | 80 | if (5 != SSCANF(s, |
80 | "%52s.%253s -> %52s | %s | %"SCNu64, | 81 | "%52s.%253s -> %52s | %s | %" SCNu64, |
81 | issuer_pkey, | 82 | issuer_pkey, |
82 | name, | 83 | name, |
83 | subject_pkey, | 84 | subject_pkey, |
84 | signature, | 85 | signature, |
85 | &etime_abs.abs_value_us)) | 86 | &etime_abs.abs_value_us)) |
86 | { | 87 | { |
87 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 88 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
88 | _("Unable to parse CRED record string `%s'\n"), | 89 | _("Unable to parse CRED record string `%s'\n"), |
89 | s); | 90 | s); |
90 | return NULL; | 91 | return NULL; |
91 | } | 92 | } |
92 | cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + strlen (name) + 1); | 93 | cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen(name) + 1); |
93 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, | 94 | GNUNET_CRYPTO_ecdsa_public_key_from_string(subject_pkey, |
94 | strlen (subject_pkey), | 95 | strlen(subject_pkey), |
95 | &cred->subject_key); | 96 | &cred->subject_key); |
96 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, | 97 | GNUNET_CRYPTO_ecdsa_public_key_from_string(issuer_pkey, |
97 | strlen (issuer_pkey), | 98 | strlen(issuer_pkey), |
98 | &cred->issuer_key); | 99 | &cred->issuer_key); |
99 | GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode (signature, | 100 | GNUNET_assert(sizeof(struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode(signature, |
100 | strlen (signature), | 101 | strlen(signature), |
101 | (char**)&sig)); | 102 | (char**)&sig)); |
102 | cred->signature = *sig; | 103 | cred->signature = *sig; |
103 | cred->expiration = etime_abs; | 104 | cred->expiration = etime_abs; |
104 | GNUNET_free (sig); | 105 | GNUNET_free(sig); |
105 | GNUNET_memcpy (&cred[1], | 106 | GNUNET_memcpy(&cred[1], |
106 | name, | 107 | name, |
107 | strlen (name)+1); | 108 | strlen(name) + 1); |
108 | cred->issuer_attribute_len = strlen ((char*)&cred[1]); | 109 | cred->issuer_attribute_len = strlen((char*)&cred[1]); |
109 | cred->issuer_attribute = (char*)&cred[1]; | 110 | cred->issuer_attribute = (char*)&cred[1]; |
110 | return cred; | 111 | return cred; |
111 | } | 112 | } |
@@ -119,50 +120,50 @@ GNUNET_CREDENTIAL_credential_from_string (const char* s) | |||
119 | * @return handle to the queued request | 120 | * @return handle to the queued request |
120 | */ | 121 | */ |
121 | struct GNUNET_CREDENTIAL_Credential * | 122 | struct GNUNET_CREDENTIAL_Credential * |
122 | GNUNET_CREDENTIAL_credential_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | 123 | GNUNET_CREDENTIAL_credential_issue(const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, |
123 | struct GNUNET_CRYPTO_EcdsaPublicKey *subject, | 124 | struct GNUNET_CRYPTO_EcdsaPublicKey *subject, |
124 | const char *attribute, | 125 | const char *attribute, |
125 | struct GNUNET_TIME_Absolute *expiration) | 126 | struct GNUNET_TIME_Absolute *expiration) |
126 | { | 127 | { |
127 | struct CredentialEntry *crd; | 128 | struct CredentialEntry *crd; |
128 | struct GNUNET_CREDENTIAL_Credential *cred; | 129 | struct GNUNET_CREDENTIAL_Credential *cred; |
129 | size_t size; | 130 | size_t size; |
130 | 131 | ||
131 | size = sizeof (struct CredentialEntry) + strlen (attribute) + 1; | 132 | size = sizeof(struct CredentialEntry) + strlen(attribute) + 1; |
132 | crd = GNUNET_malloc (size); | 133 | crd = GNUNET_malloc(size); |
133 | cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + strlen (attribute) + 1); | 134 | cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen(attribute) + 1); |
134 | crd->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | 135 | crd->purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); |
135 | 136 | ||
136 | crd->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | 137 | crd->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); |
137 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, | 138 | GNUNET_CRYPTO_ecdsa_key_get_public(issuer, |
138 | &crd->issuer_key); | 139 | &crd->issuer_key); |
139 | crd->subject_key = *subject; | 140 | crd->subject_key = *subject; |
140 | crd->expiration = GNUNET_htonll (expiration->abs_value_us); | 141 | crd->expiration = GNUNET_htonll(expiration->abs_value_us); |
141 | crd->issuer_attribute_len = htonl (strlen (attribute)+1); | 142 | crd->issuer_attribute_len = htonl(strlen(attribute) + 1); |
142 | GNUNET_memcpy ((char*)&crd[1], | 143 | GNUNET_memcpy((char*)&crd[1], |
143 | attribute, | 144 | attribute, |
144 | strlen (attribute)+1); | 145 | strlen(attribute) + 1); |
145 | if (GNUNET_OK != | 146 | if (GNUNET_OK != |
146 | GNUNET_CRYPTO_ecdsa_sign (issuer, | 147 | GNUNET_CRYPTO_ecdsa_sign(issuer, |
147 | &crd->purpose, | 148 | &crd->purpose, |
148 | &crd->signature)) | 149 | &crd->signature)) |
149 | { | 150 | { |
150 | GNUNET_break (0); | 151 | GNUNET_break(0); |
151 | GNUNET_free (crd); | 152 | GNUNET_free(crd); |
152 | GNUNET_free (cred); | 153 | GNUNET_free(cred); |
153 | return NULL; | 154 | return NULL; |
154 | } | 155 | } |
155 | cred->signature = crd->signature; | 156 | cred->signature = crd->signature; |
156 | cred->expiration = *expiration; | 157 | cred->expiration = *expiration; |
157 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, | 158 | GNUNET_CRYPTO_ecdsa_key_get_public(issuer, |
158 | &cred->issuer_key); | 159 | &cred->issuer_key); |
159 | 160 | ||
160 | cred->subject_key = *subject; | 161 | cred->subject_key = *subject; |
161 | GNUNET_memcpy (&cred[1], | 162 | GNUNET_memcpy(&cred[1], |
162 | attribute, | 163 | attribute, |
163 | strlen (attribute)+1); | 164 | strlen(attribute) + 1); |
164 | cred->issuer_attribute = (char*)&cred[1]; | 165 | cred->issuer_attribute = (char*)&cred[1]; |
165 | GNUNET_free (crd); | 166 | GNUNET_free(crd); |
166 | return cred; | 167 | return cred; |
167 | } | 168 | } |
168 | 169 | ||