aboutsummaryrefslogtreecommitdiff
path: root/src/credential/plugin_gnsrecord_credential.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2016-12-07 14:56:57 +0100
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2016-12-07 14:56:57 +0100
commit671f7c5fb4dcb596a2b6d065c2cd5f39be3fb431 (patch)
treeaed247d008042de00dd238cf2433c881521d12ed /src/credential/plugin_gnsrecord_credential.c
parent3ea628e269dc3ebec59336cfb2f883161a031662 (diff)
downloadgnunet-671f7c5fb4dcb596a2b6d065c2cd5f39be3fb431.tar.gz
gnunet-671f7c5fb4dcb596a2b6d065c2cd5f39be3fb431.zip
- add delegation resolution
Diffstat (limited to 'src/credential/plugin_gnsrecord_credential.c')
-rw-r--r--src/credential/plugin_gnsrecord_credential.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index 90ac393d0..ece4be1e3 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -65,10 +65,15 @@ credential_value_to_string (void *cls,
65 sizeof (attr)); 65 sizeof (attr));
66 cdata = data; 66 cdata = data;
67 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&attr.subject_key); 67 subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&attr.subject_key);
68 GNUNET_asprintf (&attr_str, 68 if (data_size == sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData))
69 "%s.%s", 69 {
70 subject_pkey, 70 return subject_pkey;
71 &cdata[sizeof (attr)]); 71 } else {
72 GNUNET_asprintf (&attr_str,
73 "%s %s",
74 subject_pkey,
75 &cdata[sizeof (attr)]);
76 }
72 GNUNET_free (subject_pkey); 77 GNUNET_free (subject_pkey);
73 return attr_str; 78 return attr_str;
74 } 79 }
@@ -82,7 +87,7 @@ credential_value_to_string (void *cls,
82 char *signature; 87 char *signature;
83 const char *expiration; 88 const char *expiration;
84 89
85 90
86 if (data_size < sizeof (struct GNUNET_CREDENTIAL_CredentialRecordData)) 91 if (data_size < sizeof (struct GNUNET_CREDENTIAL_CredentialRecordData))
87 return NULL; /* malformed */ 92 return NULL; /* malformed */
88 memcpy (&cred, 93 memcpy (&cred,
@@ -136,6 +141,41 @@ credential_string_to_value (void *cls,
136 return GNUNET_SYSERR; 141 return GNUNET_SYSERR;
137 switch (type) 142 switch (type)
138 { 143 {
144 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE:
145 {
146 struct GNUNET_CREDENTIAL_AttributeRecordData *attr;
147 char attr_str[253 + 1];
148 char subject_pkey[52 + 1];
149 int matches = 0;
150 matches = SSCANF (s,
151 "%s %s",
152 subject_pkey,
153 attr_str);
154 if (0 == matches)
155 {
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
157 _("Unable to parse ATTR record string `%s'\n"),
158 s);
159 return GNUNET_SYSERR;
160
161 }
162 if (1 == matches) {
163 *data_size = sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData);
164 } else if (2 == matches) {
165 *data_size = sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData) + strlen (attr_str) + 1;
166 }
167 *data = attr = GNUNET_malloc (*data_size);
168 GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey,
169 strlen (subject_pkey),
170 &attr->subject_key);
171 if (NULL != attr_str)
172 GNUNET_memcpy (&attr[1],
173 attr_str,
174 strlen (attr_str));
175
176
177 return GNUNET_OK;
178 }
139 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: 179 case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
140 { 180 {
141 struct GNUNET_CREDENTIAL_CredentialRecordData *cred; 181 struct GNUNET_CREDENTIAL_CredentialRecordData *cred;
@@ -183,7 +223,7 @@ credential_string_to_value (void *cls,
183 cred->expiration = GNUNET_htonll (etime_abs.abs_value_us); 223 cred->expiration = GNUNET_htonll (etime_abs.abs_value_us);
184 cred->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); 224 cred->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
185 cred->purpose.size = htonl (strlen (name) + 1 + sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 225 cred->purpose.size = htonl (strlen (name) + 1 + sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
186 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + sizeof (uint64_t)); 226 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + sizeof (uint64_t));
187 GNUNET_free (sig); 227 GNUNET_free (sig);
188 GNUNET_memcpy (&cred[1], 228 GNUNET_memcpy (&cred[1],
189 name, 229 name,
@@ -207,6 +247,7 @@ static struct {
207 uint32_t number; 247 uint32_t number;
208} name_map[] = { 248} name_map[] = {
209 { "CRED", GNUNET_GNSRECORD_TYPE_CREDENTIAL }, 249 { "CRED", GNUNET_GNSRECORD_TYPE_CREDENTIAL },
250 { "ATTR", GNUNET_GNSRECORD_TYPE_ATTRIBUTE },
210 { NULL, UINT32_MAX } 251 { NULL, UINT32_MAX }
211}; 252};
212 253