diff options
Diffstat (limited to 'src/credential/credential_misc.c')
-rw-r--r-- | src/credential/credential_misc.c | 168 |
1 files changed, 87 insertions, 81 deletions
diff --git a/src/credential/credential_misc.c b/src/credential/credential_misc.c index bc8a28912..13435273e 100644 --- a/src/credential/credential_misc.c +++ b/src/credential/credential_misc.c | |||
@@ -34,7 +34,8 @@ | |||
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 |
38 | GNUNET_CREDENTIAL_Credential *cred) | ||
38 | { | 39 | { |
39 | char *cred_str; | 40 | char *cred_str; |
40 | char *subject_pkey; | 41 | char *subject_pkey; |
@@ -42,26 +43,26 @@ GNUNET_CREDENTIAL_credential_to_string(const struct GNUNET_CREDENTIAL_Credential | |||
42 | char *signature; | 43 | char *signature; |
43 | 44 | ||
44 | 45 | ||
45 | subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key); | 46 | 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); | 47 | issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); |
47 | GNUNET_STRINGS_base64_encode((char*)&cred->signature, | 48 | GNUNET_STRINGS_base64_encode ((char*) &cred->signature, |
48 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature), | 49 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature), |
49 | &signature); | 50 | &signature); |
50 | GNUNET_asprintf(&cred_str, | 51 | GNUNET_asprintf (&cred_str, |
51 | "%s.%s -> %s | %s | %" SCNu64, | 52 | "%s.%s -> %s | %s | %" SCNu64, |
52 | issuer_pkey, | 53 | issuer_pkey, |
53 | cred->issuer_attribute, | 54 | cred->issuer_attribute, |
54 | subject_pkey, | 55 | subject_pkey, |
55 | signature, | 56 | signature, |
56 | cred->expiration.abs_value_us); | 57 | cred->expiration.abs_value_us); |
57 | GNUNET_free(subject_pkey); | 58 | GNUNET_free (subject_pkey); |
58 | GNUNET_free(issuer_pkey); | 59 | GNUNET_free (issuer_pkey); |
59 | GNUNET_free(signature); | 60 | GNUNET_free (signature); |
60 | return cred_str; | 61 | return cred_str; |
61 | } | 62 | } |
62 | 63 | ||
63 | struct GNUNET_CREDENTIAL_Credential* | 64 | struct GNUNET_CREDENTIAL_Credential* |
64 | GNUNET_CREDENTIAL_credential_from_string(const char* s) | 65 | GNUNET_CREDENTIAL_credential_from_string (const char*s) |
65 | { | 66 | { |
66 | struct GNUNET_CREDENTIAL_Credential *cred; | 67 | struct GNUNET_CREDENTIAL_Credential *cred; |
67 | size_t enclen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; | 68 | size_t enclen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; |
@@ -72,42 +73,46 @@ GNUNET_CREDENTIAL_credential_from_string(const char* s) | |||
72 | char subject_pkey[enclen + 1]; | 73 | char subject_pkey[enclen + 1]; |
73 | char issuer_pkey[enclen + 1]; | 74 | char issuer_pkey[enclen + 1]; |
74 | char name[253 + 1]; | 75 | char name[253 + 1]; |
75 | char signature[256]; //TODO max payload size | 76 | char signature[256]; // TODO max payload size |
76 | 77 | ||
77 | struct GNUNET_CRYPTO_EcdsaSignature *sig; | 78 | struct GNUNET_CRYPTO_EcdsaSignature *sig; |
78 | struct GNUNET_TIME_Absolute etime_abs; | 79 | struct GNUNET_TIME_Absolute etime_abs; |
79 | 80 | ||
80 | if (5 != sscanf(s, | 81 | if (5 != sscanf (s, |
81 | "%52s.%253s -> %52s | %s | %" SCNu64, | 82 | "%52s.%253s -> %52s | %s | %" SCNu64, |
82 | issuer_pkey, | 83 | issuer_pkey, |
83 | name, | 84 | name, |
84 | subject_pkey, | 85 | subject_pkey, |
85 | signature, | 86 | signature, |
86 | &etime_abs.abs_value_us)) | 87 | &etime_abs.abs_value_us)) |
87 | { | 88 | { |
88 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 89 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
89 | _("Unable to parse CRED record string `%s'\n"), | 90 | _ ("Unable to parse CRED record string `%s'\n"), |
90 | s); | 91 | s); |
91 | return NULL; | 92 | return NULL; |
92 | } | 93 | } |
93 | cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen(name) + 1); | 94 | cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen ( |
94 | GNUNET_CRYPTO_ecdsa_public_key_from_string(subject_pkey, | 95 | name) + 1); |
95 | strlen(subject_pkey), | 96 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, |
96 | &cred->subject_key); | 97 | strlen (subject_pkey), |
97 | GNUNET_CRYPTO_ecdsa_public_key_from_string(issuer_pkey, | 98 | &cred->subject_key); |
98 | strlen(issuer_pkey), | 99 | GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, |
99 | &cred->issuer_key); | 100 | strlen (issuer_pkey), |
100 | GNUNET_assert(sizeof(struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode(signature, | 101 | &cred->issuer_key); |
101 | strlen(signature), | 102 | GNUNET_assert (sizeof(struct GNUNET_CRYPTO_EcdsaSignature) == |
102 | (char**)&sig)); | 103 | GNUNET_STRINGS_base64_decode (signature, |
104 | strlen ( | ||
105 | signature), | ||
106 | ( | ||
107 | char**) &sig)); | ||
103 | cred->signature = *sig; | 108 | cred->signature = *sig; |
104 | cred->expiration = etime_abs; | 109 | cred->expiration = etime_abs; |
105 | GNUNET_free(sig); | 110 | GNUNET_free (sig); |
106 | GNUNET_memcpy(&cred[1], | 111 | GNUNET_memcpy (&cred[1], |
107 | name, | 112 | name, |
108 | strlen(name) + 1); | 113 | strlen (name) + 1); |
109 | cred->issuer_attribute_len = strlen((char*)&cred[1]); | 114 | cred->issuer_attribute_len = strlen ((char*) &cred[1]); |
110 | cred->issuer_attribute = (char*)&cred[1]; | 115 | cred->issuer_attribute = (char*) &cred[1]; |
111 | return cred; | 116 | return cred; |
112 | } | 117 | } |
113 | 118 | ||
@@ -120,51 +125,52 @@ GNUNET_CREDENTIAL_credential_from_string(const char* s) | |||
120 | * @return handle to the queued request | 125 | * @return handle to the queued request |
121 | */ | 126 | */ |
122 | struct GNUNET_CREDENTIAL_Credential * | 127 | struct GNUNET_CREDENTIAL_Credential * |
123 | GNUNET_CREDENTIAL_credential_issue(const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | 128 | GNUNET_CREDENTIAL_credential_issue (const struct |
124 | struct GNUNET_CRYPTO_EcdsaPublicKey *subject, | 129 | GNUNET_CRYPTO_EcdsaPrivateKey *issuer, |
125 | const char *attribute, | 130 | struct GNUNET_CRYPTO_EcdsaPublicKey *subject, |
126 | struct GNUNET_TIME_Absolute *expiration) | 131 | const char *attribute, |
132 | struct GNUNET_TIME_Absolute *expiration) | ||
127 | { | 133 | { |
128 | struct CredentialEntry *crd; | 134 | struct CredentialEntry *crd; |
129 | struct GNUNET_CREDENTIAL_Credential *cred; | 135 | struct GNUNET_CREDENTIAL_Credential *cred; |
130 | size_t size; | 136 | size_t size; |
131 | 137 | ||
132 | size = sizeof(struct CredentialEntry) + strlen(attribute) + 1; | 138 | size = sizeof(struct CredentialEntry) + strlen (attribute) + 1; |
133 | crd = GNUNET_malloc(size); | 139 | crd = GNUNET_malloc (size); |
134 | cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen(attribute) + 1); | 140 | cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen ( |
135 | crd->purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); | 141 | attribute) + 1); |
142 | crd->purpose.size = htonl (size - sizeof(struct | ||
143 | GNUNET_CRYPTO_EcdsaSignature)); | ||
136 | 144 | ||
137 | crd->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | 145 | crd->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); |
138 | GNUNET_CRYPTO_ecdsa_key_get_public(issuer, | 146 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, |
139 | &crd->issuer_key); | 147 | &crd->issuer_key); |
140 | crd->subject_key = *subject; | 148 | crd->subject_key = *subject; |
141 | crd->expiration = GNUNET_htonll(expiration->abs_value_us); | 149 | crd->expiration = GNUNET_htonll (expiration->abs_value_us); |
142 | crd->issuer_attribute_len = htonl(strlen(attribute) + 1); | 150 | crd->issuer_attribute_len = htonl (strlen (attribute) + 1); |
143 | GNUNET_memcpy((char*)&crd[1], | 151 | GNUNET_memcpy ((char*) &crd[1], |
144 | attribute, | 152 | attribute, |
145 | strlen(attribute) + 1); | 153 | strlen (attribute) + 1); |
146 | if (GNUNET_OK != | 154 | if (GNUNET_OK != |
147 | GNUNET_CRYPTO_ecdsa_sign(issuer, | 155 | GNUNET_CRYPTO_ecdsa_sign (issuer, |
148 | &crd->purpose, | 156 | &crd->purpose, |
149 | &crd->signature)) | 157 | &crd->signature)) |
150 | { | 158 | { |
151 | GNUNET_break(0); | 159 | GNUNET_break (0); |
152 | GNUNET_free(crd); | 160 | GNUNET_free (crd); |
153 | GNUNET_free(cred); | 161 | GNUNET_free (cred); |
154 | return NULL; | 162 | return NULL; |
155 | } | 163 | } |
156 | cred->signature = crd->signature; | 164 | cred->signature = crd->signature; |
157 | cred->expiration = *expiration; | 165 | cred->expiration = *expiration; |
158 | GNUNET_CRYPTO_ecdsa_key_get_public(issuer, | 166 | GNUNET_CRYPTO_ecdsa_key_get_public (issuer, |
159 | &cred->issuer_key); | 167 | &cred->issuer_key); |
160 | 168 | ||
161 | cred->subject_key = *subject; | 169 | cred->subject_key = *subject; |
162 | GNUNET_memcpy(&cred[1], | 170 | GNUNET_memcpy (&cred[1], |
163 | attribute, | 171 | attribute, |
164 | strlen(attribute) + 1); | 172 | strlen (attribute) + 1); |
165 | cred->issuer_attribute = (char*)&cred[1]; | 173 | cred->issuer_attribute = (char*) &cred[1]; |
166 | GNUNET_free(crd); | 174 | GNUNET_free (crd); |
167 | return cred; | 175 | return cred; |
168 | } | 176 | } |
169 | |||
170 | |||