aboutsummaryrefslogtreecommitdiff
path: root/src/credential/plugin_gnsrecord_credential.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2016-11-20 00:23:49 +0100
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2016-11-20 00:23:49 +0100
commit18f106166cf64cc72206cd35301276aa21ca100a (patch)
treea5f472d1d7f76366a9cfc23189ee5a44d7b2f38d /src/credential/plugin_gnsrecord_credential.c
parent691aa85bfaec80c08330db772499a123b2ac2373 (diff)
downloadgnunet-18f106166cf64cc72206cd35301276aa21ca100a.tar.gz
gnunet-18f106166cf64cc72206cd35301276aa21ca100a.zip
- move towards verification
Diffstat (limited to 'src/credential/plugin_gnsrecord_credential.c')
-rw-r--r--src/credential/plugin_gnsrecord_credential.c48
1 files changed, 21 insertions, 27 deletions
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index 6ae3b8980..3ff00737b 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -58,7 +58,6 @@ credential_value_to_string (void *cls,
58 char *subject_pkey; 58 char *subject_pkey;
59 char *issuer_pkey; 59 char *issuer_pkey;
60 uint32_t cf; // Credential flags 60 uint32_t cf; // Credential flags
61 uint32_t mdd; // Max delegation depth
62 if (data_size < sizeof (struct GNUNET_CREDENTIAL_RecordData)) 61 if (data_size < sizeof (struct GNUNET_CREDENTIAL_RecordData))
63 return NULL; /* malformed */ 62 return NULL; /* malformed */
64 memcpy (&cred, 63 memcpy (&cred,
@@ -68,14 +67,12 @@ credential_value_to_string (void *cls,
68 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred.subject_key); 67 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred.subject_key);
69 issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred.issuer_key); 68 issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred.issuer_key);
70 cf = ntohl (cred.credential_flags); 69 cf = ntohl (cred.credential_flags);
71 mdd = ntohl (cred.max_delegation_depth);
72 70
73 GNUNET_asprintf (&cred_str, 71 GNUNET_asprintf (&cred_str,
74 "%s %s %u %u %s", 72 "%s %s %u %s",
75 subject_pkey, 73 subject_pkey,
76 issuer_pkey, 74 issuer_pkey,
77 (unsigned int) cf, 75 (unsigned int) cf,
78 (unsigned int) mdd,
79 &cdata[sizeof (cred)]); 76 &cdata[sizeof (cred)]);
80 GNUNET_free (subject_pkey); 77 GNUNET_free (subject_pkey);
81 GNUNET_free (issuer_pkey); 78 GNUNET_free (issuer_pkey);
@@ -112,26 +109,24 @@ credential_string_to_value (void *cls,
112 return GNUNET_SYSERR; 109 return GNUNET_SYSERR;
113 switch (type) 110 switch (type)
114 { 111 {
115 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: 112 case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
116 { 113 {
117 struct GNUNET_CREDENTIAL_RecordData *cred; 114 struct GNUNET_CREDENTIAL_RecordData *cred;
118 unsigned int cf; // credential flags 115 unsigned int cf; // credential flags
119 unsigned int mdd; // max delegation depth
120 116
121 size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; 117 size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
122 if (enclen % 5 > 0) 118 if (enclen % 5 > 0)
123 enclen += 5 - enclen % 5; 119 enclen += 5 - enclen % 5;
124 enclen /= 5; /* 260/5 = 52 */ 120 enclen /= 5; /* 260/5 = 52 */
125 char subject_pkey[enclen + 1]; 121 char subject_pkey[enclen + 1];
126 char issuer_pkey[enclen + 1]; 122 char issuer_pkey[enclen + 1];
127 char name[253 + 1]; 123 char name[253 + 1];
128 124
129 if (5 != SSCANF (s, 125 if (5 != SSCANF (s,
130 "%52s %52s %u %u %253s", 126 "%52s %52s %u %253s",
131 subject_pkey, 127 subject_pkey,
132 issuer_pkey, 128 issuer_pkey,
133 &cf, 129 &cf,
134 &mdd,
135 name)) 130 name))
136 { 131 {
137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -148,18 +143,17 @@ credential_string_to_value (void *cls,
148 strlen (issuer_pkey), 143 strlen (issuer_pkey),
149 &cred->issuer_key); 144 &cred->issuer_key);
150 cred->credential_flags = htonl (cf); 145 cred->credential_flags = htonl (cf);
151 cred->max_delegation_depth = htonl (mdd);
152 GNUNET_memcpy (&cred[1], 146 GNUNET_memcpy (&cred[1],
153 name, 147 name,
154 strlen (name)); 148 strlen (name));
155 149
156 150
157 *data = GNUNET_strdup (s); 151 *data = GNUNET_strdup (s);
158 *data_size = strlen (s); 152 *data_size = strlen (s);
159 return GNUNET_OK; 153 return GNUNET_OK;
160 } 154 }
161 default: 155 default:
162 return GNUNET_SYSERR; 156 return GNUNET_SYSERR;
163 } 157 }
164} 158}
165 159
@@ -186,13 +180,13 @@ static struct {
186 */ 180 */
187static uint32_t 181static uint32_t
188credential_typename_to_number (void *cls, 182credential_typename_to_number (void *cls,
189 const char *gns_typename) 183 const char *gns_typename)
190{ 184{
191 unsigned int i; 185 unsigned int i;
192 186
193 i=0; 187 i=0;
194 while ( (name_map[i].name != NULL) && 188 while ( (name_map[i].name != NULL) &&
195 (0 != strcasecmp (gns_typename, name_map[i].name)) ) 189 (0 != strcasecmp (gns_typename, name_map[i].name)) )
196 i++; 190 i++;
197 return name_map[i].number; 191 return name_map[i].number;
198} 192}
@@ -207,13 +201,13 @@ credential_typename_to_number (void *cls,
207 */ 201 */
208static const char * 202static const char *
209credential_number_to_typename (void *cls, 203credential_number_to_typename (void *cls,
210 uint32_t type) 204 uint32_t type)
211{ 205{
212 unsigned int i; 206 unsigned int i;
213 207
214 i=0; 208 i=0;
215 while ( (name_map[i].name != NULL) && 209 while ( (name_map[i].name != NULL) &&
216 (type != name_map[i].number) ) 210 (type != name_map[i].number) )
217 i++; 211 i++;
218 return name_map[i].name; 212 return name_map[i].name;
219} 213}