From 40624873cbd2eaf3a94185995b14899ea6ab36bf Mon Sep 17 00:00:00 2001 From: Andreas Ebner Date: Wed, 24 Jul 2019 16:29:32 +0200 Subject: Run clang format over some files, experimental implementation of forward algorithm --- src/credential/credential_serialization.c | 310 ++++++++++---------- src/credential/delegate_misc.c | 188 ++++++------ src/credential/gnunet-credential.c | 412 +++++++++++++-------------- src/credential/gnunet-service-credential.c | 206 +++++++++++++- src/credential/plugin_gnsrecord_credential.c | 129 ++++++--- src/credential/test_credential_own.sh | 74 ++++- 6 files changed, 801 insertions(+), 518 deletions(-) (limited to 'src/credential') diff --git a/src/credential/credential_serialization.c b/src/credential/credential_serialization.c index 4e461c654..b14ec26f2 100644 --- a/src/credential/credential_serialization.c +++ b/src/credential/credential_serialization.c @@ -11,17 +11,17 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later - */ +*/ /** * @file credential/credential_serialization.c - * @brief API to serialize and deserialize delegation chains + * @brief API to serialize and deserialize delegation chains * and credentials * @author Martin Schanzenbach */ @@ -41,14 +41,14 @@ * @return the required size to serialize */ size_t -GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count, - const struct - GNUNET_CREDENTIAL_DelegationSet *dsr) +GNUNET_CREDENTIAL_delegation_set_get_size ( + unsigned int ds_count, + const struct GNUNET_CREDENTIAL_DelegationSet *dsr) { unsigned int i; size_t ret; - ret = sizeof(struct DelegationRecordData) * (ds_count); + ret = sizeof (struct DelegationRecordData) * (ds_count); for (i = 0; i < ds_count; i++) { @@ -68,11 +68,11 @@ GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count, * @return the size of the data, -1 on failure */ ssize_t -GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, - const struct - GNUNET_CREDENTIAL_DelegationSet *dsr, - size_t dest_size, - char *dest) +GNUNET_CREDENTIAL_delegation_set_serialize ( + unsigned int d_count, + const struct GNUNET_CREDENTIAL_DelegationSet *dsr, + size_t dest_size, + char *dest) { struct DelegationRecordData rec; unsigned int i; @@ -83,12 +83,10 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, { rec.subject_attribute_len = htonl ((uint32_t) dsr[i].subject_attribute_len); rec.subject_key = dsr[i].subject_key; - if (off + sizeof(rec) > dest_size) + if (off + sizeof (rec) > dest_size) return -1; - GNUNET_memcpy (&dest[off], - &rec, - sizeof(rec)); - off += sizeof(rec); + GNUNET_memcpy (&dest[off], &rec, sizeof (rec)); + off += sizeof (rec); if (0 == dsr[i].subject_attribute_len) continue; if (off + dsr[i].subject_attribute_len > dest_size) @@ -112,12 +110,11 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, - const char *src, - unsigned int d_count, - struct - GNUNET_CREDENTIAL_DelegationSet * - dsr) +GNUNET_CREDENTIAL_delegation_set_deserialize ( + size_t len, + const char *src, + unsigned int d_count, + struct GNUNET_CREDENTIAL_DelegationSet *dsr) { struct DelegationRecordData rec; unsigned int i; @@ -126,15 +123,15 @@ GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, off = 0; for (i = 0; i < d_count; i++) { - if (off + sizeof(rec) > len) + if (off + sizeof (rec) > len) return GNUNET_SYSERR; - GNUNET_memcpy (&rec, &src[off], sizeof(rec)); + GNUNET_memcpy (&rec, &src[off], sizeof (rec)); dsr[i].subject_key = rec.subject_key; - off += sizeof(rec); + off += sizeof (rec); dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len); if (off + dsr[i].subject_attribute_len > len) return GNUNET_SYSERR; - dsr[i].subject_attribute = (char*) &src[off]; + dsr[i].subject_attribute = (char *) &src[off]; off += dsr[i].subject_attribute_len; } return GNUNET_OK; @@ -150,14 +147,14 @@ GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len, * @return the required size to serialize */ size_t -GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, - const struct - GNUNET_CREDENTIAL_Credential *cd) +GNUNET_CREDENTIAL_credentials_get_size ( + unsigned int c_count, + const struct GNUNET_CREDENTIAL_Credential *cd) { unsigned int i; size_t ret; - ret = sizeof(struct CredentialEntry) * (c_count); + ret = sizeof (struct CredentialEntry) * (c_count); for (i = 0; i < c_count; i++) { @@ -176,11 +173,11 @@ GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, * @return the size of the data, -1 on failure */ ssize_t -GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, - const struct - GNUNET_CREDENTIAL_Credential *cd, - size_t dest_size, - char *dest) +GNUNET_CREDENTIAL_credentials_serialize ( + unsigned int c_count, + const struct GNUNET_CREDENTIAL_Credential *cd, + size_t dest_size, + char *dest) { struct CredentialEntry c_rec; unsigned int i; @@ -194,16 +191,14 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, c_rec.subject_key = cd[i].subject_key; c_rec.signature = cd[i].signature; c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); - c_rec.purpose.size = htonl ((sizeof(struct CredentialEntry) - + cd[i].issuer_attribute_len) - sizeof(struct - GNUNET_CRYPTO_EcdsaSignature)); + c_rec.purpose.size = + htonl ((sizeof (struct CredentialEntry) + cd[i].issuer_attribute_len) - + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us); - if (off + sizeof(c_rec) > dest_size) + if (off + sizeof (c_rec) > dest_size) return -1; - GNUNET_memcpy (&dest[off], - &c_rec, - sizeof(c_rec)); - off += sizeof(c_rec); + GNUNET_memcpy (&dest[off], &c_rec, sizeof (c_rec)); + off += sizeof (c_rec); if (off + cd[i].issuer_attribute_len > dest_size) return -1; GNUNET_memcpy (&dest[off], @@ -216,7 +211,6 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, } - /** * Deserialize the given destination * @@ -227,11 +221,11 @@ GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_CREDENTIAL_credentials_deserialize (size_t len, - const char *src, - unsigned int c_count, - struct GNUNET_CREDENTIAL_Credential * - cd) +GNUNET_CREDENTIAL_credentials_deserialize ( + size_t len, + const char *src, + unsigned int c_count, + struct GNUNET_CREDENTIAL_Credential *cd) { struct CredentialEntry c_rec; unsigned int i; @@ -240,15 +234,15 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len, off = 0; for (i = 0; i < c_count; i++) { - if (off + sizeof(c_rec) > len) + if (off + sizeof (c_rec) > len) return GNUNET_SYSERR; - GNUNET_memcpy (&c_rec, &src[off], sizeof(c_rec)); + GNUNET_memcpy (&c_rec, &src[off], sizeof (c_rec)); cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len); cd[i].issuer_key = c_rec.issuer_key; cd[i].subject_key = c_rec.subject_key; cd[i].signature = c_rec.signature; cd[i].expiration.abs_value_us = GNUNET_ntohll (c_rec.expiration); - off += sizeof(c_rec); + off += sizeof (c_rec); if (off + cd[i].issuer_attribute_len > len) return GNUNET_SYSERR; cd[i].issuer_attribute = &src[off]; @@ -258,7 +252,6 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len, } - /** * Calculate how many bytes we will need to serialize * the given delegation chain and credential @@ -270,23 +263,21 @@ GNUNET_CREDENTIAL_credentials_deserialize (size_t len, * @return the required size to serialize */ size_t -GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, - const struct - GNUNET_CREDENTIAL_Delegation *dd, - unsigned int c_count, - const struct - GNUNET_CREDENTIAL_Credential *cd) +GNUNET_CREDENTIAL_delegation_chain_get_size ( + unsigned int d_count, + const struct GNUNET_CREDENTIAL_Delegation *dd, + unsigned int c_count, + const struct GNUNET_CREDENTIAL_Credential *cd) { unsigned int i; size_t ret; - ret = sizeof(struct ChainEntry) * (d_count); + ret = sizeof (struct ChainEntry) * (d_count); for (i = 0; i < d_count; i++) { - GNUNET_assert ((ret - + dd[i].issuer_attribute_len - + dd[i].subject_attribute_len) >= ret); + GNUNET_assert ( + (ret + dd[i].issuer_attribute_len + dd[i].subject_attribute_len) >= ret); ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; } return ret + GNUNET_CREDENTIAL_credentials_get_size (c_count, cd); @@ -304,14 +295,13 @@ GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, * @return the size of the data, -1 on failure */ ssize_t -GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, - const struct - GNUNET_CREDENTIAL_Delegation *dd, - unsigned int c_count, - const struct - GNUNET_CREDENTIAL_Credential *cd, - size_t dest_size, - char *dest) +GNUNET_CREDENTIAL_delegation_chain_serialize ( + unsigned int d_count, + const struct GNUNET_CREDENTIAL_Delegation *dd, + unsigned int c_count, + const struct GNUNET_CREDENTIAL_Credential *cd, + size_t dest_size, + char *dest) { struct ChainEntry rec; unsigned int i; @@ -324,12 +314,10 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len); rec.issuer_key = dd[i].issuer_key; rec.subject_key = dd[i].subject_key; - if (off + sizeof(rec) > dest_size) + if (off + sizeof (rec) > dest_size) return -1; - GNUNET_memcpy (&dest[off], - &rec, - sizeof(rec)); - off += sizeof(rec); + GNUNET_memcpy (&dest[off], &rec, sizeof (rec)); + off += sizeof (rec); if (off + dd[i].issuer_attribute_len > dest_size) return -1; GNUNET_memcpy (&dest[off], @@ -364,14 +352,13 @@ GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, - const char *src, - unsigned int d_count, - struct - GNUNET_CREDENTIAL_Delegation *dd, - unsigned int c_count, - struct - GNUNET_CREDENTIAL_Credential *cd) +GNUNET_CREDENTIAL_delegation_chain_deserialize ( + size_t len, + const char *src, + unsigned int d_count, + struct GNUNET_CREDENTIAL_Delegation *dd, + unsigned int c_count, + struct GNUNET_CREDENTIAL_Credential *cd) { struct ChainEntry rec; unsigned int i; @@ -380,13 +367,13 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, off = 0; for (i = 0; i < d_count; i++) { - if (off + sizeof(rec) > len) + if (off + sizeof (rec) > len) return GNUNET_SYSERR; - GNUNET_memcpy (&rec, &src[off], sizeof(rec)); + GNUNET_memcpy (&rec, &src[off], sizeof (rec)); dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len); dd[i].issuer_key = rec.issuer_key; dd[i].subject_key = rec.subject_key; - off += sizeof(rec); + off += sizeof (rec); if (off + dd[i].issuer_attribute_len > len) return GNUNET_SYSERR; dd[i].issuer_attribute = &src[off]; @@ -404,66 +391,63 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, } int -GNUNET_CREDENTIAL_credential_serialize (struct - GNUNET_CREDENTIAL_Credential *cred, - char **data) +GNUNET_CREDENTIAL_credential_serialize ( + struct GNUNET_CREDENTIAL_Credential *cred, + char **data) { size_t size; struct CredentialEntry *cdata; - size = sizeof(struct CredentialEntry) + strlen (cred->issuer_attribute) + 1; + size = sizeof (struct CredentialEntry) + strlen (cred->issuer_attribute) + 1; *data = GNUNET_malloc (size); - cdata = (struct CredentialEntry*) *data; + cdata = (struct CredentialEntry *) *data; cdata->subject_key = cred->subject_key; cdata->issuer_key = cred->issuer_key; cdata->expiration = GNUNET_htonll (cred->expiration.abs_value_us); cdata->signature = cred->signature; cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1); cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); - cdata->purpose.size = htonl (size - sizeof(struct - GNUNET_CRYPTO_EcdsaSignature)); + cdata->purpose.size = + htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); GNUNET_memcpy (&cdata[1], cred->issuer_attribute, strlen (cred->issuer_attribute)); - if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify ( - GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, - &cdata->purpose, - &cdata->signature, - &cdata->issuer_key)) + if (GNUNET_OK != + GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, + &cdata->purpose, + &cdata->signature, + &cdata->issuer_key)) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Invalid credential\n"); - // return NULL; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n"); + //return NULL; } return size; } -struct GNUNET_CREDENTIAL_Credential* -GNUNET_CREDENTIAL_credential_deserialize (const char*data, - size_t data_size) +struct GNUNET_CREDENTIAL_Credential * +GNUNET_CREDENTIAL_credential_deserialize (const char *data, size_t data_size) { struct GNUNET_CREDENTIAL_Credential *cred; struct CredentialEntry *cdata; char *issuer_attribute; - if (data_size < sizeof(struct CredentialEntry)) + if (data_size < sizeof (struct CredentialEntry)) return NULL; - cdata = (struct CredentialEntry*) data; - if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify ( - GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, - &cdata->purpose, - &cdata->signature, - &cdata->issuer_key)) + cdata = (struct CredentialEntry *) data; + if (GNUNET_OK != + GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, + &cdata->purpose, + &cdata->signature, + &cdata->issuer_key)) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Invalid credential\n"); - // return NULL; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n"); + //return NULL; } - issuer_attribute = (char*) &cdata[1]; + issuer_attribute = (char *) &cdata[1]; - cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + ntohl ( - cdata->issuer_attribute_len)); + cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + + ntohl (cdata->issuer_attribute_len)); cred->issuer_key = cdata->issuer_key; cred->subject_key = cdata->subject_key; @@ -471,7 +455,7 @@ GNUNET_CREDENTIAL_credential_deserialize (const char*data, issuer_attribute, ntohl (cdata->issuer_attribute_len)); cred->signature = cdata->signature; - cred->issuer_attribute = (char*) &cred[1]; + cred->issuer_attribute = (char *) &cred[1]; cred->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); return cred; } @@ -480,51 +464,60 @@ GNUNET_CREDENTIAL_credential_deserialize (const char*data, int GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *dele, - char **data) + char **data) { size_t size; struct DelegateEntry *cdata; int attr_len; // +1 for \0 - if (0 == dele->subject_attribute_len){ + if (0 == dele->subject_attribute_len) + { attr_len = dele->issuer_attribute_len + 1; - } else { + } + else + { attr_len = dele->issuer_attribute_len + dele->subject_attribute_len + 2; } size = sizeof (struct DelegateEntry) + attr_len; char tmp_str[attr_len]; - GNUNET_memcpy(tmp_str, dele->issuer_attribute, dele->issuer_attribute_len); - if (0 != dele->subject_attribute_len){ + GNUNET_memcpy (tmp_str, dele->issuer_attribute, dele->issuer_attribute_len); + if (0 != dele->subject_attribute_len) + { tmp_str[dele->issuer_attribute_len] = '\0'; - GNUNET_memcpy(tmp_str + dele->issuer_attribute_len + 1, dele->subject_attribute, dele->subject_attribute_len); + GNUNET_memcpy (tmp_str + dele->issuer_attribute_len + 1, + dele->subject_attribute, + dele->subject_attribute_len); } tmp_str[attr_len - 1] = '\0'; *data = GNUNET_malloc (size); - cdata = (struct DelegateEntry*)*data; + cdata = (struct DelegateEntry *) *data; cdata->subject_key = dele->subject_key; cdata->issuer_key = dele->issuer_key; cdata->expiration = GNUNET_htonll (dele->expiration.abs_value_us); cdata->signature = dele->signature; cdata->issuer_attribute_len = htonl (dele->issuer_attribute_len + 1); - if (0 == dele->subject_attribute_len){ + if (0 == dele->subject_attribute_len) + { cdata->subject_attribute_len = htonl (0); - } else { + } + else + { cdata->subject_attribute_len = htonl (dele->subject_attribute_len + 1); } cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); - cdata->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); + cdata->purpose.size = + htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); - GNUNET_memcpy (&cdata[1], - tmp_str, - attr_len); + GNUNET_memcpy (&cdata[1], tmp_str, attr_len); - if(GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_DELEGATE, - &cdata->purpose, - &cdata->signature, - &cdata->issuer_key)) + if (GNUNET_OK != + GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_DELEGATE, + &cdata->purpose, + &cdata->signature, + &cdata->issuer_key)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Serialize: Invalid delegate\n"); return 0; @@ -532,9 +525,8 @@ GNUNET_CREDENTIAL_delegate_serialize (struct GNUNET_CREDENTIAL_Delegate *dele, return size; } -struct GNUNET_CREDENTIAL_Delegate* -GNUNET_CREDENTIAL_delegate_deserialize (const char* data, - size_t data_size) +struct GNUNET_CREDENTIAL_Delegate * +GNUNET_CREDENTIAL_delegate_deserialize (const char *data, size_t data_size) { struct GNUNET_CREDENTIAL_Delegate *dele; struct DelegateEntry *cdata; @@ -542,38 +534,40 @@ GNUNET_CREDENTIAL_delegate_deserialize (const char* data, if (data_size < sizeof (struct DelegateEntry)) return NULL; - cdata = (struct DelegateEntry*)data; - if(GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_DELEGATE, - &cdata->purpose, - &cdata->signature, - &cdata->issuer_key)) + cdata = (struct DelegateEntry *) data; + if (GNUNET_OK != + GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_DELEGATE, + &cdata->purpose, + &cdata->signature, + &cdata->issuer_key)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deserialize: Invalid delegate\n"); return NULL; } - attr_combo_str = (char*)&cdata[1]; - int iss_len = ntohl(cdata->issuer_attribute_len); - int sub_len = ntohl(cdata->subject_attribute_len); + attr_combo_str = (char *) &cdata[1]; + int iss_len = ntohl (cdata->issuer_attribute_len); + int sub_len = ntohl (cdata->subject_attribute_len); int attr_combo_len = iss_len + sub_len; - dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_combo_len); + dele = + GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_combo_len); dele->issuer_key = cdata->issuer_key; dele->subject_key = cdata->subject_key; - GNUNET_memcpy (&dele[1], - attr_combo_str, - attr_combo_len); + GNUNET_memcpy (&dele[1], attr_combo_str, attr_combo_len); dele->signature = cdata->signature; - + // Set the pointers for the attributes - dele->issuer_attribute = (char*)&dele[1]; + dele->issuer_attribute = (char *) &dele[1]; dele->issuer_attribute_len = iss_len; dele->subject_attribute_len = sub_len; - if(0 == sub_len){ + if (0 == sub_len) + { dele->subject_attribute = NULL; - } else { - dele->subject_attribute = (char*)&dele[1] + iss_len; - + } + else + { + dele->subject_attribute = (char *) &dele[1] + iss_len; } dele->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); 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 @@ #include "credential.h" #include -char* -GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *cred) +char * +GNUNET_CREDENTIAL_delegate_to_string ( + const struct GNUNET_CREDENTIAL_Delegate *cred) { char *cred_str; char *subject_pkey; @@ -43,26 +44,29 @@ GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *c subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); - GNUNET_STRINGS_base64_encode ((char*)&cred->signature, + GNUNET_STRINGS_base64_encode ((char *) &cred->signature, sizeof (struct GNUNET_CRYPTO_EcdsaSignature), &signature); - if(0 == cred->subject_attribute_len){ + if (0 == cred->subject_attribute_len) + { GNUNET_asprintf (&cred_str, - "%s.%s -> %s | %s | %"SCNu64, - issuer_pkey, - cred->issuer_attribute, - subject_pkey, - signature, - cred->expiration.abs_value_us); - } else { + "%s.%s -> %s | %s | %" SCNu64, + issuer_pkey, + cred->issuer_attribute, + subject_pkey, + signature, + cred->expiration.abs_value_us); + } + else + { GNUNET_asprintf (&cred_str, - "%s.%s -> %s.%s | %s | %"SCNu64, - issuer_pkey, - cred->issuer_attribute, - subject_pkey, - cred->subject_attribute, - signature, - cred->expiration.abs_value_us); + "%s.%s -> %s.%s | %s | %" SCNu64, + issuer_pkey, + cred->issuer_attribute, + subject_pkey, + cred->subject_attribute, + signature, + cred->expiration.abs_value_us); } GNUNET_free (subject_pkey); GNUNET_free (issuer_pkey); @@ -71,8 +75,8 @@ GNUNET_CREDENTIAL_delegate_to_string (const struct GNUNET_CREDENTIAL_Delegate *c return cred_str; } -struct GNUNET_CREDENTIAL_Delegate* -GNUNET_CREDENTIAL_delegate_from_string (const char* s) +struct GNUNET_CREDENTIAL_Delegate * +GNUNET_CREDENTIAL_delegate_from_string (const char *s) { struct GNUNET_CREDENTIAL_Delegate *dele; size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8; @@ -91,7 +95,7 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) // If it's A.a <- B.b... if (6 != SSCANF (s, - "%52s.%253s -> %52s.%253s | %s | %"SCNu64, + "%52s.%253s -> %52s.%253s | %s | %" SCNu64, issuer_pkey, iss_attr, subject_pkey, @@ -101,59 +105,69 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) { // Try if it's A.a <- B if (5 != SSCANF (s, - "%52s.%253s -> %52s | %s | %"SCNu64, - issuer_pkey, - iss_attr, - subject_pkey, - signature, - &etime_abs.abs_value_us)) + "%52s.%253s -> %52s | %s | %" SCNu64, + issuer_pkey, + iss_attr, + subject_pkey, + signature, + &etime_abs.abs_value_us)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to parse DEL record string `%s'\n", s); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unable to parse DEL record string `%s'\n", + s); return NULL; } } // +1 for \0 int attr_len; - if(strcmp(sub_attr,"") == 0) { + if (strcmp (sub_attr, "") == 0) + { attr_len = strlen (iss_attr) + 1; - } else { - attr_len = strlen (iss_attr) + strlen(sub_attr) + 2; + } + else + { + attr_len = strlen (iss_attr) + strlen (sub_attr) + 2; } dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); char tmp_str[attr_len]; - GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); - if(strcmp(sub_attr,"") != 0) { - tmp_str[strlen(iss_attr)] = '\0'; - GNUNET_memcpy(tmp_str + strlen(iss_attr) + 1, sub_attr, strlen(sub_attr)); + GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr)); + if (strcmp (sub_attr, "") != 0) + { + tmp_str[strlen (iss_attr)] = '\0'; + GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1, + sub_attr, + strlen (sub_attr)); } tmp_str[attr_len - 1] = '\0'; - + GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, strlen (subject_pkey), &dele->subject_key); GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey, strlen (issuer_pkey), &dele->issuer_key); - GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode (signature, - strlen (signature), - (char**)&sig)); + GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == + GNUNET_STRINGS_base64_decode (signature, + strlen (signature), + (char **) &sig)); dele->signature = *sig; dele->expiration = etime_abs; GNUNET_free (sig); - GNUNET_memcpy (&dele[1], - tmp_str, - attr_len); + GNUNET_memcpy (&dele[1], tmp_str, attr_len); - dele->issuer_attribute = (char*)&dele[1]; + dele->issuer_attribute = (char *) &dele[1]; dele->issuer_attribute_len = strlen (iss_attr); - if(strcmp(sub_attr,"") == 0) { + if (strcmp (sub_attr, "") == 0) + { dele->subject_attribute = NULL; dele->subject_attribute_len = 0; - } else { - dele->subject_attribute = (char*)&dele[1] + strlen(iss_attr) + 1; + } + else + { + dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1; dele->subject_attribute_len = strlen (sub_attr); } @@ -170,56 +184,62 @@ GNUNET_CREDENTIAL_delegate_from_string (const char* s) */ struct GNUNET_CREDENTIAL_Delegate * -GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, - struct GNUNET_CRYPTO_EcdsaPublicKey *subject, - const char *iss_attr, - const char *sub_attr, - struct GNUNET_TIME_Absolute *expiration) +GNUNET_CREDENTIAL_delegate_issue ( + const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, + struct GNUNET_CRYPTO_EcdsaPublicKey *subject, + const char *iss_attr, + const char *sub_attr, + struct GNUNET_TIME_Absolute *expiration) { struct DelegateEntry *del; struct GNUNET_CREDENTIAL_Delegate *dele; size_t size; int attr_len; - - if (NULL == sub_attr){ + + if (NULL == sub_attr) + { // +1 for \0 attr_len = strlen (iss_attr) + 1; - } else { + } + else + { // +2 for both strings need to be terminated with \0 - attr_len = strlen (iss_attr) + strlen(sub_attr) + 2; + attr_len = strlen (iss_attr) + strlen (sub_attr) + 2; } size = sizeof (struct DelegateEntry) + attr_len; char tmp_str[attr_len]; - GNUNET_memcpy(tmp_str, iss_attr, strlen(iss_attr)); - if (NULL != sub_attr){ - tmp_str[strlen(iss_attr)] = '\0'; - GNUNET_memcpy(tmp_str + strlen(iss_attr) + 1, sub_attr, strlen(sub_attr)); + GNUNET_memcpy (tmp_str, iss_attr, strlen (iss_attr)); + if (NULL != sub_attr) + { + tmp_str[strlen (iss_attr)] = '\0'; + GNUNET_memcpy (tmp_str + strlen (iss_attr) + 1, + sub_attr, + strlen (sub_attr)); } tmp_str[attr_len - 1] = '\0'; - + del = GNUNET_malloc (size); - del->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); + del->purpose.size = + htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); del->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE); - GNUNET_CRYPTO_ecdsa_key_get_public (issuer, - &del->issuer_key); + GNUNET_CRYPTO_ecdsa_key_get_public (issuer, &del->issuer_key); del->subject_key = *subject; del->expiration = GNUNET_htonll (expiration->abs_value_us); del->issuer_attribute_len = htonl (strlen (iss_attr) + 1); - if (NULL == sub_attr){ + if (NULL == sub_attr) + { del->subject_attribute_len = htonl (0); - } else { + } + else + { del->subject_attribute_len = htonl (strlen (sub_attr) + 1); } - GNUNET_memcpy (&del[1], - tmp_str, - attr_len); - + GNUNET_memcpy (&del[1], tmp_str, attr_len); + if (GNUNET_OK != - GNUNET_CRYPTO_ecdsa_sign (issuer, - &del->purpose, - &del->signature)) + GNUNET_CRYPTO_ecdsa_sign (issuer, &del->purpose, &del->signature)) { GNUNET_break (0); GNUNET_free (del); @@ -229,24 +249,24 @@ GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *is dele = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Delegate) + attr_len); dele->signature = del->signature; dele->expiration = *expiration; - GNUNET_CRYPTO_ecdsa_key_get_public (issuer, - &dele->issuer_key); + GNUNET_CRYPTO_ecdsa_key_get_public (issuer, &dele->issuer_key); dele->subject_key = *subject; // Copy the combined string at the part in the memory where the struct ends - GNUNET_memcpy (&dele[1], - tmp_str, - attr_len); + GNUNET_memcpy (&dele[1], tmp_str, attr_len); - dele->issuer_attribute = (char*)&dele[1]; - dele->issuer_attribute_len = strlen(iss_attr); - if (NULL == sub_attr){ + dele->issuer_attribute = (char *) &dele[1]; + dele->issuer_attribute_len = strlen (iss_attr); + if (NULL == sub_attr) + { dele->subject_attribute = NULL; dele->subject_attribute_len = 0; - } else { - dele->subject_attribute = (char*)&dele[1] + strlen(iss_attr) + 1; - dele->subject_attribute_len = strlen(sub_attr); + } + else + { + dele->subject_attribute = (char *) &dele[1] + strlen (iss_attr) + 1; + dele->subject_attribute_len = strlen (sub_attr); } GNUNET_free (del); @@ -256,5 +276,3 @@ GNUNET_CREDENTIAL_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *is // oder: pointer auf cred[1], aber nach jedem string im combined string ein EOS <- besser // function comment: cred must be freed by caller, (add missing sub_iss) } - - diff --git a/src/credential/gnunet-credential.c b/src/credential/gnunet-credential.c index 3d20e7082..55a4653fb 100644 --- a/src/credential/gnunet-credential.c +++ b/src/credential/gnunet-credential.c @@ -251,22 +251,21 @@ do_timeout (void *cls) static void handle_collect_result (void *cls, - unsigned int d_count, - struct GNUNET_CREDENTIAL_Delegation *dc, - unsigned int c_count, - struct GNUNET_CREDENTIAL_Credential *cred) + unsigned int d_count, + struct GNUNET_CREDENTIAL_Delegation *dc, + unsigned int c_count, + struct GNUNET_CREDENTIAL_Credential *cred) { int i; - char* line; + char *line; verify_request = NULL; if (NULL != cred) { - for (i=0;idata = data; rde->data_size = data_size; @@ -523,29 +516,28 @@ get_existing_record (void *cls, rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; GNUNET_assert (NULL != rec_name); add_qe = GNUNET_NAMESTORE_records_store (ns, - &zone_pkey, - rec_name, - rd_count + 1, - rde, - &add_continuation, - &add_qe); + &zone_pkey, + rec_name, + rd_count + 1, + rde, + &add_continuation, + &add_qe); return; } static void -store_cb (void *cls, - const struct GNUNET_IDENTITY_Ego *ego) +store_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) { const struct GNUNET_CONFIGURATION_Handle *cfg = cls; el = NULL; - + ns = GNUNET_NAMESTORE_connect (cfg); if (NULL == ns) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to connect to namestore\n")); + _ ("Failed to connect to namestore\n")); GNUNET_SCHEDULER_shutdown (); return; } @@ -554,23 +546,27 @@ store_cb (void *cls, zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); // TODO maybe dont have to set subject, if only used in if/else can use import here instead!! - if( GNUNET_GNSRECORD_TYPE_DELEGATE == type){ + if (GNUNET_GNSRECORD_TYPE_DELEGATE == type) + { // Parse import struct GNUNET_CREDENTIAL_Delegate *cred; cred = GNUNET_CREDENTIAL_delegate_from_string (import); // Get import subject public key string - char *subject_pubkey_str = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key); + char *subject_pubkey_str = + GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); // Get zone public key string struct GNUNET_CRYPTO_EcdsaPublicKey zone_pubkey; GNUNET_IDENTITY_ego_get_public_key (ego, &zone_pubkey); - char *zone_pubkey_str = GNUNET_CRYPTO_ecdsa_public_key_to_string(&zone_pubkey); + char *zone_pubkey_str = + GNUNET_CRYPTO_ecdsa_public_key_to_string (&zone_pubkey); // Check if the subject key in the signed import matches the zone's key it is issued to - if(strcmp(zone_pubkey_str, subject_pubkey_str) != 0) + if (strcmp (zone_pubkey_str, subject_pubkey_str) != 0) { - fprintf (stderr, "Import signed delegate does not match this ego's public key.\n"); + fprintf (stderr, + "Import signed delegate does not match this ego's public key.\n"); GNUNET_SCHEDULER_shutdown (); return; } @@ -580,18 +576,19 @@ store_cb (void *cls, etime_is_rel = GNUNET_NO; // Prepare the data to be store in the record - data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **)&data); - GNUNET_free(cred); - } else { + data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **) &data); + GNUNET_free (cred); + } + else + { // For all other types e.g. GNUNET_GNSRECORD_TYPE_ATTRIBUTE - if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (type, - subject, - &data, - &data_size)) + if (GNUNET_OK != + GNUNET_GNSRECORD_string_to_value (type, subject, &data, &data_size)) { - fprintf (stderr, "Value `%s' invalid for record type `%s'\n", - subject, - typestring); + fprintf (stderr, + "Value `%s' invalid for record type `%s'\n", + subject, + typestring); GNUNET_SCHEDULER_shutdown (); return; } @@ -603,12 +600,9 @@ store_cb (void *cls, GNUNET_SCHEDULER_shutdown (); return; } - if (GNUNET_OK != parse_expiration (expiration, - &etime_is_rel, - &etime)) + if (GNUNET_OK != parse_expiration (expiration, &etime_is_rel, &etime)) { - fprintf (stderr, "Invalid time format `%s'\n", - expiration); + fprintf (stderr, "Invalid time format `%s'\n", expiration); GNUNET_SCHEDULER_shutdown (); return; } @@ -616,18 +610,17 @@ store_cb (void *cls, // Start lookup add_qe = GNUNET_NAMESTORE_records_lookup (ns, - &zone_pkey, - record_label, - &error_cb, - NULL, - &get_existing_record, - NULL); + &zone_pkey, + record_label, + &error_cb, + NULL, + &get_existing_record, + NULL); return; } static void -sign_cb (void *cls, - const struct GNUNET_IDENTITY_Ego *ego) +sign_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) { const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; struct GNUNET_CREDENTIAL_Delegate *dele; @@ -642,9 +635,13 @@ sign_cb (void *cls, fprintf (stderr, "Please specify a TTL\n"); GNUNET_SCHEDULER_shutdown (); return; - } else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (expiration, &etime_abs)) + } + else if (GNUNET_OK != + GNUNET_STRINGS_fancy_time_to_absolute (expiration, &etime_abs)) { - fprintf (stderr, "%s is not a valid ttl! Only absolute times are accepted!\n", expiration); + fprintf (stderr, + "%s is not a valid ttl! Only absolute times are accepted!\n", + expiration); GNUNET_SCHEDULER_shutdown (); return; } @@ -656,17 +653,19 @@ sign_cb (void *cls, // Subject Public Key token = strtok (subject, " "); - if (key_length == strlen(token)) + if (key_length == strlen (token)) { subject_pubkey_str = token; - } else { - fprintf (stderr, "Key error, wrong length: %ld!\n", strlen(token)); + } + else + { + fprintf (stderr, "Key error, wrong length: %ld!\n", strlen (token)); GNUNET_SCHEDULER_shutdown (); return; } // Subject Attribute(s) token = strtok (NULL, " "); - if(NULL != token) + if (NULL != token) { subject_attr = token; } @@ -674,21 +673,24 @@ sign_cb (void *cls, // work on keys privkey = GNUNET_IDENTITY_ego_get_private_key (ego); - if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pubkey_str, + if (GNUNET_OK != + GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pubkey_str, strlen (subject_pubkey_str), &subject_pkey)) { - fprintf (stderr, "Subject public key `%s' is not well-formed\n", subject_pubkey_str); + fprintf (stderr, + "Subject public key `%s' is not well-formed\n", + subject_pubkey_str); GNUNET_SCHEDULER_shutdown (); return; } // Sign delegate dele = GNUNET_CREDENTIAL_delegate_issue (privkey, - &subject_pkey, - issuer_attr, - subject_attr, - &etime_abs); + &subject_pkey, + issuer_attr, + subject_attr, + &etime_abs); res = GNUNET_CREDENTIAL_delegate_to_string (dele); GNUNET_free (dele); printf ("%s\n", res); @@ -715,18 +717,20 @@ run (void *cls, { cfg = c; - tt = GNUNET_SCHEDULER_add_delayed (timeout, - &do_timeout, NULL); + tt = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, NULL); GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); // Check relevant cmdline parameters - if (GNUNET_YES == create_is) { - if (NULL == ego_name) { + if (GNUNET_YES == create_is) + { + if (NULL == ego_name) + { fprintf (stderr, "Missing option '-ego'\n"); GNUNET_SCHEDULER_shutdown (); return; } - if (NULL == issuer_attr) { + if (NULL == issuer_attr) + { fprintf (stderr, "Missing option '-attribute' for issuer attribute\n"); GNUNET_SCHEDULER_shutdown (); return; @@ -741,16 +745,15 @@ run (void *cls, // Lookup ego, on success call store_cb and store as ATTRIBUTE type type = GNUNET_GNSRECORD_TYPE_ATTRIBUTE; record_label = issuer_attr; - el = GNUNET_IDENTITY_ego_lookup (cfg, - ego_name, - &store_cb, - (void *) cfg); + el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &store_cb, (void *) cfg); return; } - if (GNUNET_YES == create_ss) { + if (GNUNET_YES == create_ss) + { // check if signed parameter has been passed in cmd line call - if (NULL == import) { + if (NULL == import) + { fprintf (stderr, "'import' required\n"); GNUNET_SCHEDULER_shutdown (); return; @@ -759,16 +762,15 @@ run (void *cls, type = GNUNET_GNSRECORD_TYPE_DELEGATE; record_label = GNUNET_GNS_EMPTY_LABEL_AT; // Store subject side - el = GNUNET_IDENTITY_ego_lookup (cfg, - ego_name, - &store_cb, - (void *) cfg); + el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &store_cb, (void *) cfg); return; } - if (GNUNET_YES == sign_ss) { - if (NULL == ego_name) { + if (GNUNET_YES == sign_ss) + { + if (NULL == ego_name) + { fprintf (stderr, "ego required\n"); GNUNET_SCHEDULER_shutdown (); return; @@ -781,82 +783,68 @@ run (void *cls, } // lookup ego and call function sign_cb on success - el = GNUNET_IDENTITY_ego_lookup (cfg, - ego_name, - &sign_cb, - (void *) cfg); + el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &sign_cb, (void *) cfg); return; } - if (GNUNET_YES == collect) { + if (GNUNET_YES == collect) + { if (NULL == issuer_key) { - fprintf (stderr, - _("Issuer public key not well-formed\n")); + fprintf (stderr, _ ("Issuer public key not well-formed\n")); GNUNET_SCHEDULER_shutdown (); return; - } credential = GNUNET_CREDENTIAL_connect (cfg); if (NULL == credential) { - fprintf (stderr, - _("Failed to connect to CREDENTIAL\n")); + fprintf (stderr, _ ("Failed to connect to CREDENTIAL\n")); GNUNET_SCHEDULER_shutdown (); return; } if (NULL == issuer_attr) { - fprintf (stderr, - _("You must provide issuer the attribute\n")); + fprintf (stderr, _ ("You must provide issuer the attribute\n")); GNUNET_SCHEDULER_shutdown (); return; } - if (NULL == ego_name) { - fprintf (stderr, - _("ego required\n")); + if (NULL == ego_name) + { + fprintf (stderr, _ ("ego required\n")); GNUNET_SCHEDULER_shutdown (); return; } - el = GNUNET_IDENTITY_ego_lookup (cfg, - ego_name, - &identity_cb, - (void *) cfg); + el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); return; - - } + } if (NULL == subject) { - fprintf (stderr, - _("Subject public key needed\n")); + fprintf (stderr, _ ("Subject public key needed\n")); GNUNET_SCHEDULER_shutdown (); return; - } - if (GNUNET_OK != - GNUNET_CRYPTO_ecdsa_public_key_from_string (subject, - strlen (subject), - &subject_pkey)) + if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (subject, + strlen (subject), + &subject_pkey)) { fprintf (stderr, - _("Subject public key `%s' is not well-formed\n"), + _ ("Subject public key `%s' is not well-formed\n"), subject); GNUNET_SCHEDULER_shutdown (); return; } - if (GNUNET_YES == verify) { + if (GNUNET_YES == verify) + { if (NULL == issuer_key) { - fprintf (stderr, - _("Issuer public key not well-formed\n")); + fprintf (stderr, _ ("Issuer public key not well-formed\n")); GNUNET_SCHEDULER_shutdown (); return; - } if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key, @@ -864,7 +852,7 @@ run (void *cls, &issuer_pkey)) { fprintf (stderr, - _("Issuer public key `%s' is not well-formed\n"), + _ ("Issuer public key `%s' is not well-formed\n"), issuer_key); GNUNET_SCHEDULER_shutdown (); return; @@ -873,15 +861,13 @@ run (void *cls, if (NULL == credential) { - fprintf (stderr, - _("Failed to connect to CREDENTIAL\n")); + fprintf (stderr, _ ("Failed to connect to CREDENTIAL\n")); GNUNET_SCHEDULER_shutdown (); return; } if (NULL == issuer_attr || NULL == subject_credential) { - fprintf (stderr, - _("You must provide issuer and subject attributes\n")); + fprintf (stderr, _ ("You must provide issuer and subject attributes\n")); GNUNET_SCHEDULER_shutdown (); return; } @@ -891,63 +877,62 @@ run (void *cls, char *tok = strtok (tmp, ","); if (NULL == tok) { - fprintf (stderr, - "Invalid subject credentials\n"); + fprintf (stderr, "Invalid subject credentials\n"); GNUNET_free (tmp); GNUNET_SCHEDULER_shutdown (); return; } int count = 1; int i; - while (NULL != (tok = strtok(NULL, ","))) + while (NULL != (tok = strtok (NULL, ","))) count++; struct GNUNET_CREDENTIAL_Credential credentials[count]; struct GNUNET_CREDENTIAL_Credential *cred; GNUNET_free (tmp); tmp = GNUNET_strdup (subject_credential); tok = strtok (tmp, ","); - for (i=0;iissuer_attribute); - tok = strtok(NULL, ","); + tok = strtok (NULL, ","); GNUNET_free (cred); } - verify_request = GNUNET_CREDENTIAL_verify(credential, - &issuer_pkey, - issuer_attr, //TODO argument - &subject_pkey, - count, - credentials, - &handle_verify_result, - NULL); - for (i=0;ilookup_request = NULL; + vrh = current_set->handle; + vrh->pending_lookups--; + //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:current set %s\n", current_set->issuer_attribute); + + + // Loop record entries + for (uint32_t i = 0; i < rd_count; i++) { + if (GNUNET_GNSRECORD_TYPE_DELEGATE != rd[i].record_type) + continue; + + // Start deserialize into Delegate + struct GNUNET_CREDENTIAL_Delegate *del; + del = GNUNET_CREDENTIAL_delegate_deserialize(rd[i].data, rd[i].data_size); + + // TODO parse subject and issuer attributes which are required for algo solving + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:iss %s %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->issuer_key), del->issuer_attribute); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:sub %s %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->subject_key), del->subject_attribute); + + // Start: Create DQ Entry + dq_entry = GNUNET_new (struct DelegationQueueEntry); + // AND delegations are not possible, only 1 solution + dq_entry->required_solutions = 1; + dq_entry->parent_set = current_set; + + // Insert it into the current set + GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head, + current_set->queue_entries_tail, + dq_entry); + + // Start: Create DS Entry + ds_entry = GNUNET_new (struct DelegationSetQueueEntry); + + // (1) A.a <- A.b.c + // (2) A.b <- D.d + // (3) D.d <- E + // (4) E.c <- F.c + // (5) F.c <- G + // Possibilities: + // 1. complete match: trailer = 0, validate + // 2. partial match: replace + // 3. new solution: replace, add trailer + + //GNUNET_assert(NULL != current_set->attr_trailer); + // TODO only during test + if (NULL == current_set->attr_trailer) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: trailer null\n"); + // for (5) F.c <- G, remember .c when going upwards + ds_entry->attr_trailer = GNUNET_strdup(del->issuer_attribute); + } else { + if (0 == del->subject_attribute_len){ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: new solution\n"); + // new solution + // create new trailer del->issuer_attribute, ds_entry->attr_trailer + GNUNET_asprintf (&ds_entry->attr_trailer, + "%s.%s", + del->issuer_attribute, + current_set->attr_trailer); + } else if(0 == strcmp(del->subject_attribute, current_set->attr_trailer)){ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: complete match\n"); + // complete match + // new trailer == issuer attribute (e.g. (5) to (4)) + // TODO memleak, free trailer before + ds_entry->attr_trailer = GNUNET_strdup(del->issuer_attribute); + } else { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: partial match\n"); + // partial match + + // TODO problem when checking with contains: attr = disco or attr = disc both say success + // ==> therefore: split and check the single attributes + // replace/remove partial match trailer and add the new one + + char *saveptr1, *saveptr2; + char *trail_token; + char *sub_token; + char *tmp_trail = GNUNET_strdup (current_set->attr_trailer); + char *tmp_subattr = GNUNET_strdup (del->subject_attribute); + + // tok both, parent->attr_trailer and del->sub_attr to see how far they match, + // take rest of parent trailer (only when del->sub_attr token is null), and + // create new/actual trailer with del->iss_attr + trail_token = strtok_r (tmp_trail, ".", &saveptr1); + sub_token = strtok_r (tmp_subattr, ".", &saveptr2); + while (NULL != trail_token && NULL != sub_token) + { + if(0 == strcmp(trail_token,sub_token)) + { + // good, matches, remove + } else { + // not relevant for solving the chain, end function here + // TODO how to end this correctly? just return? + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:throwing %s %s\n", trail_token, sub_token); + + // TODO break zum nächsten for + //return; + } + + trail_token = strtok_r (NULL, ".", &saveptr1); + sub_token = strtok_r (NULL, ".", &saveptr2); + } + if(NULL == trail_token) + { + //TODO error, can't happen + } + // do not have to check sub_token == NULL, if both would be NULL + // at the same time, the complete match part above should have triggered already + + // otherwise, above while only ends when sub_token == NULL + GNUNET_asprintf (&ds_entry->attr_trailer, + "%s", + trail_token); + trail_token = strtok_r (NULL, ".", &saveptr1); + while(NULL != trail_token) + { + GNUNET_asprintf (&ds_entry->attr_trailer, + "%s.%s", + current_set->attr_trailer, + trail_token); + trail_token = strtok_r (NULL, ".", &saveptr1); + + } + GNUNET_asprintf (&ds_entry->attr_trailer, + "%s.%s", + del->issuer_attribute, + ds_entry->attr_trailer); + + } + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW: new tailer %s\n", ds_entry->attr_trailer); + + // Start: Credential Chain Entry + // issuer key is subject key, who needs to be contacted to resolve this (forward, therefore subject) + // TODO: new ds_entry struct with subject_key (or one for both with contact_key or sth) + ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); + GNUNET_memcpy (ds_entry->issuer_key, + &del->subject_key, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); + + ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry); + ds_entry->delegation_chain_entry->subject_key = del->subject_key; + if (0 < del->subject_attribute_len) + ds_entry->delegation_chain_entry->subject_attribute = GNUNET_strdup (del->subject_attribute); + ds_entry->delegation_chain_entry->issuer_key = del->issuer_key; + ds_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (del->issuer_attribute); + + // current delegation as parent + ds_entry->parent_queue_entry = dq_entry; + + // TODO verify if end is reached: + // what is required? Only issuer key/attr and attr_trailer new == 0 + + // TODO until good verify check: fixed number of lookups + //vrh->pending_lookups++; + ds_entry->handle = vrh; + + const struct GNUNET_CRYPTO_EcdsaPublicKey *kkey = &del->issuer_key; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "-----------FW: Starting AGAIN %s\n",GNUNET_CRYPTO_ecdsa_public_key_to_string(&del->issuer_key)); + if (0 == vrh->pending_lookups) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n"); + return; + } + GNUNET_GNS_lookup (gns, + GNUNET_GNS_EMPTY_LABEL_AT, + kkey, // subject_key, + GNUNET_GNSRECORD_TYPE_DELEGATE, + GNUNET_GNS_LO_DEFAULT, + &test_resolution, + ds_entry); + + } } static void @@ -732,22 +910,24 @@ backward_resolution (void *cls, vrh->pending_lookups++; ds_entry->handle = vrh; - ds_entry->lookup_request + /*ds_entry->lookup_request = GNUNET_GNS_lookup (gns, lookup_attribute, ds_entry->issuer_key, // issuer_key, GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNS_LO_DEFAULT, &backward_resolution, - ds_entry); - /*GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting\n"); - GNUNET_GNS_lookup (gns, + ds_entry);*/ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(ds_entry->issuer_key)); + vrh->pending_lookups = 5; + ds_entry->lookup_request + = GNUNET_GNS_lookup (gns, GNUNET_GNS_EMPTY_LABEL_AT, - ds_entry->issuer_key, // subject_key, + ds_entry->issuer_key, // issuer_key, GNUNET_GNSRECORD_TYPE_DELEGATE, GNUNET_GNS_LO_DEFAULT, &test_resolution, - ds_entry);*/ + ds_entry); GNUNET_free (lookup_attribute); } } @@ -825,6 +1005,18 @@ delegation_chain_resolution_start (void *cls) GNUNET_GNS_LO_DEFAULT, &backward_resolution, ds_entry); + //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Starting %s\n", GNUNET_CRYPTO_ecdsa_public_key_to_string(&vrh->issuer_key)); + + // TODO we start with example (5) F.c <- G + // => attr_trailer = c + //ds_entry->attr_trailer = "c"; + /*ds_entry->lookup_request = GNUNET_GNS_lookup (gns, + GNUNET_GNS_EMPTY_LABEL_AT, + &vrh->issuer_key, // subject_key, + GNUNET_GNSRECORD_TYPE_DELEGATE, + GNUNET_GNS_LO_DEFAULT, + &test_resolution, + ds_entry);*/ } static int diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c index f2fb0b1a6..90cd2f46a 100644 --- a/src/credential/plugin_gnsrecord_credential.c +++ b/src/credential/plugin_gnsrecord_credential.c @@ -44,13 +44,17 @@ * @return NULL on error, otherwise human-readable representation of the value */ static char * -credential_value_to_string (void *cls, uint32_t type, const void *data, +credential_value_to_string (void *cls, + uint32_t type, + const void *data, size_t data_size) { const char *cdata; - switch (type) { - case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { + switch (type) + { + case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: + { struct GNUNET_CREDENTIAL_DelegationRecord sets; char *attr_str; char *subject_pkey; @@ -63,30 +67,49 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, cdata = data; struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets.set_count)]; - if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize ( - GNUNET_ntohll (sets.data_size), &cdata[sizeof (sets)], - ntohl (sets.set_count), set)) + if (GNUNET_OK != + GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll ( + sets.data_size), + &cdata[sizeof (sets)], + ntohl (sets.set_count), + set)) return NULL; - for (i = 0; i < ntohl (sets.set_count); i++) { + for (i = 0; i < ntohl (sets.set_count); i++) + { subject_pkey = - GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n", + GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%d len attr\n", set[i].subject_attribute_len); - if (0 == set[i].subject_attribute_len) { - if (0 == i) { + if (0 == set[i].subject_attribute_len) + { + if (0 == i) + { GNUNET_asprintf (&attr_str, "%s", subject_pkey); - } else { + } + else + { GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey); GNUNET_free (attr_str); attr_str = tmp_str; } - } else { - if (0 == i) { - GNUNET_asprintf (&attr_str, "%s %s", subject_pkey, + } + else + { + if (0 == i) + { + GNUNET_asprintf (&attr_str, + "%s %s", + subject_pkey, set[i].subject_attribute); - } else { - GNUNET_asprintf (&tmp_str, "%s,%s %s", attr_str, subject_pkey, + } + else + { + GNUNET_asprintf (&tmp_str, + "%s,%s %s", + attr_str, + subject_pkey, set[i].subject_attribute); GNUNET_free (attr_str); attr_str = tmp_str; @@ -96,7 +119,8 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, } return attr_str; } - case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { + case GNUNET_GNSRECORD_TYPE_CREDENTIAL: + { struct GNUNET_CREDENTIAL_Credential *cred; char *cred_str; @@ -105,10 +129,11 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, GNUNET_free (cred); return cred_str; } - case GNUNET_GNSRECORD_TYPE_DELEGATE: { + case GNUNET_GNSRECORD_TYPE_DELEGATE: + { struct GNUNET_CREDENTIAL_Delegate *cred; char *cred_str; - + cred = GNUNET_CREDENTIAL_delegate_deserialize (data, data_size); cred_str = GNUNET_CREDENTIAL_delegate_to_string (cred); GNUNET_free (cred); @@ -132,13 +157,18 @@ credential_value_to_string (void *cls, uint32_t type, const void *data, * @return #GNUNET_OK on success */ static int -credential_string_to_value (void *cls, uint32_t type, const char *s, - void **data, size_t *data_size) +credential_string_to_value (void *cls, + uint32_t type, + const char *s, + void **data, + size_t *data_size) { if (NULL == s) return GNUNET_SYSERR; - switch (type) { - case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { + switch (type) + { + case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: + { struct GNUNET_CREDENTIAL_DelegationRecord *sets; char attr_str[253 + 1]; char subject_pkey[52 + 1]; @@ -154,17 +184,20 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, entries = 0; tmp_data_size = 0; *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecord); - while (NULL != token) { + while (NULL != token) + { // also fills the variables subject_pley and attr_str if "regex"-like match matches = SSCANF (token, "%s %s", subject_pkey, attr_str); - - if (0 == matches) { + + if (0 == matches) + { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Unable to parse ATTR record string `%s'\n"), s); + _ ("Unable to parse ATTR record string `%s'\n"), + s); GNUNET_free (tmp_str); return GNUNET_SYSERR; } - + entries++; token = strtok (NULL, ","); } @@ -172,7 +205,8 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, tmp_str = GNUNET_strdup (s); token = strtok (tmp_str, ","); - if (NULL == token) { + if (NULL == token) + { GNUNET_free (tmp_str); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s); return GNUNET_SYSERR; @@ -181,15 +215,18 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, struct GNUNET_CREDENTIAL_DelegationSet set[entries]; // sets memory to be 0, starting at *set for the size of struct * entries memset (set, 0, sizeof (struct GNUNET_CREDENTIAL_DelegationSet) * entries); - for (i = 0; i < entries; i++) { + for (i = 0; i < entries; i++) + { matches = SSCANF (token, "%s %s", subject_pkey, attr_str); // sets the public key for the set entry - GNUNET_CRYPTO_ecdsa_public_key_from_string ( - subject_pkey, strlen (subject_pkey), &set[i].subject_key); + GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey, + strlen (subject_pkey), + &set[i].subject_key); // If not just key, also set subject attribute (Not A.a <- B but A.a <- B.b) - if (2 == matches) { + if (2 == matches) + { set[i].subject_attribute_len = strlen (attr_str) + 1; set[i].subject_attribute = GNUNET_strdup (attr_str); } @@ -198,17 +235,21 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, } tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set); - if (-1 == tmp_data_size) { + if (-1 == tmp_data_size) + { GNUNET_free (tmp_str); return GNUNET_SYSERR; } *data_size += tmp_data_size; *data = sets = GNUNET_malloc (*data_size); - GNUNET_CREDENTIAL_delegation_set_serialize (entries, set, tmp_data_size, - (char *)&sets[1]); - for (i = 0; i < entries; i++) { + GNUNET_CREDENTIAL_delegation_set_serialize (entries, + set, + tmp_data_size, + (char *) &sets[1]); + for (i = 0; i < entries; i++) + { if (0 != set[i].subject_attribute_len) - GNUNET_free ((char *)set[i].subject_attribute); + GNUNET_free ((char *) set[i].subject_attribute); } sets->set_count = htonl (entries); sets->data_size = GNUNET_htonll (tmp_data_size); @@ -216,18 +257,20 @@ credential_string_to_value (void *cls, uint32_t type, const char *s, GNUNET_free (tmp_str); return GNUNET_OK; } - case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { + case GNUNET_GNSRECORD_TYPE_CREDENTIAL: + { struct GNUNET_CREDENTIAL_Credential *cred; cred = GNUNET_CREDENTIAL_credential_from_string (s); - *data_size = GNUNET_CREDENTIAL_credential_serialize (cred, (char **)data); + *data_size = GNUNET_CREDENTIAL_credential_serialize (cred, (char **) data); return GNUNET_OK; } - case GNUNET_GNSRECORD_TYPE_DELEGATE: { + case GNUNET_GNSRECORD_TYPE_DELEGATE: + { struct GNUNET_CREDENTIAL_Delegate *cred; cred = GNUNET_CREDENTIAL_delegate_from_string (s); - *data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **)data); + *data_size = GNUNET_CREDENTIAL_delegate_serialize (cred, (char **) data); return GNUNET_OK; } diff --git a/src/credential/test_credential_own.sh b/src/credential/test_credential_own.sh index b53825d1b..23935c75a 100755 --- a/src/credential/test_credential_own.sh +++ b/src/credential/test_credential_own.sh @@ -21,8 +21,20 @@ rm -rf `gnunet-config -c test_credential_lookup.conf -s PATHS -o GNUNET_HOME -f` # (4) RegistrarB.student <- Alice -which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30" +which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 10" gnunet-arm -s -c test_credential_lookup.conf + +gnunet-identity -C a -c test_credential_lookup.conf +gnunet-identity -C d -c test_credential_lookup.conf +gnunet-identity -C e -c test_credential_lookup.conf +gnunet-identity -C f -c test_credential_lookup.conf +gnunet-identity -C g -c test_credential_lookup.conf +AKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep a | awk '{print $3}') +DKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep d | awk '{print $3}') +EKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep e | awk '{print $3}') +FKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep f | awk '{print $3}') +GKEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep g | awk '{print $3}') + gnunet-identity -C epub -c test_credential_lookup.conf gnunet-identity -C eorg -c test_credential_lookup.conf gnunet-identity -C stateu -c test_credential_lookup.conf @@ -42,29 +54,55 @@ STATE_STUD_ATTR="student" REG_STUD_ATTR="student" END_ATTR="end" +SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=a --attribute="a" --subject="$AKEY b.c" --ttl="2019-12-12 10:00:00"` +gnunet-credential --createSubjectSide --ego=a --import "$SIGNED" +gnunet-namestore -D -z a + +SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=a --attribute="b" --subject="$DKEY d" --ttl="2019-12-12 10:00:00"` +gnunet-credential --createSubjectSide --ego=d --import "$SIGNED" +gnunet-namestore -D -z d + +SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=d --attribute="d" --subject="$EKEY" --ttl="2019-12-12 10:00:00"` +gnunet-credential --createSubjectSide --ego=e --import "$SIGNED" +gnunet-namestore -D -z e + +SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=e --attribute="c" --subject="$FKEY c" --ttl="2019-12-12 10:00:00"` +gnunet-credential --createSubjectSide --ego=f --import "$SIGNED" +gnunet-namestore -D -z f + +SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=f --attribute="c" --subject="$GKEY" --ttl="2019-12-12 10:00:00"` +gnunet-credential --createSubjectSide --ego=g --import "$SIGNED" +gnunet-namestore -D -z g + + + TEST_CREDENTIAL="mygnunetcreds" # Own issuer side storage: -gnunet-credential --createIssuerSide --ego=epub --attribute="issside" --subject="$EORG_KEY asd" --ttl=5m +#gnunet-credential --createIssuerSide --ego=epub --attribute="issside" --subject="$EORG_KEY asd" --ttl=5m -gnunet-namestore -D -z epub +#gnunet-namestore -D -z epub # Own subject side storage: -SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY" --ttl="2019-12-12 10:00:00"` -gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" +#SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY" --ttl="2019-12-12 10:00:00"` +#gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" -SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY efghijklmno" --ttl="2019-12-12 10:00:00"` -gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" +#SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY efghijklmno" --ttl="2019-12-12 10:00:00"` +#gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" -SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY efghijklmno.pqr" --ttl="2019-12-12 10:00:00"` -gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" +#SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd" --subject="$EORG_KEY efghijklmno.pqr" --ttl="2019-12-12 10:00:00"` +#gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" -SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd.stu" --subject="$EORG_KEY efghijklmno.pqr" --ttl="2019-12-12 10:00:00"` -gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" +#SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=epub --attribute="abcd.stu" --subject="$EORG_KEY efghijklmno.pqr" --ttl="2019-12-12 10:00:00"` +#gnunet-credential --createSubjectSide --ego=eorg --import "$SIGNED" -gnunet-namestore -D -z eorg +#SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=stateu --attribute="aaa" --subject="$EPUB_KEY bbbb" --ttl="2019-12-12 10:00:00"` +#gnunet-credential --createSubjectSide --ego=epub --import "$SIGNED" + +#gnunet-namestore -D -z eorg # (1) EPub assigns the attribute "discount" to all entities that have been assigned "preferred" by EOrg gnunet-namestore -p -z epub -a -n $DISC_ATTR -t ATTR -V "$EORG_KEY $PREF_ATTR" -e 5m -c test_credential_lookup.conf +gnunet-namestore -p -z epub -a -n "random" -t ATTR -V "$GKEY random" -e 5m -c test_credential_lookup.conf # (2) EOrg assigns the attribute "preferred" to all entities that have been assigned "student" by StateU gnunet-namestore -p -z eorg -a -n $PREF_ATTR -t ATTR -V "$STATEU_KEY $STATE_STUD_ATTR" -e 5m -c test_credential_lookup.conf @@ -81,11 +119,13 @@ gnunet-namestore -p -z alice -a -n $TEST_CREDENTIAL -t CRED -V "$CRED" -e 5m -c # Starting to resolve echo "+++++Starting Collect" -CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$EPUB_KEY --attribute=$DISC_ATTR --ego=alice -c test_credential_lookup.conf | paste -d, -s` +CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$EPUB_KEY --attribute="random" --ego=alice -c test_credential_lookup.conf | paste -d, -s` +#CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$EPUB_KEY --attribute=$DISC_ATTR --ego=alice -c test_credential_lookup.conf | paste -d, -s` echo $CREDS echo gnunet-credential --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --credential=\'$CREDS\' -c test_credential_lookup.conf -RES_CRED=`gnunet-credential --verify --issuer=$EPUB_KEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --credential="$CREDS" -c test_credential_lookup.conf` +RES_CRED=`gnunet-credential --verify --issuer=$EPUB_KEY --attribute="random" --subject=$ALICE_KEY --credential="$CREDS" -c test_credential_lookup.conf` +#RES_CRED=`gnunet-credential --verify --issuer=$GKEY --attribute=$DISC_ATTR --subject=$ALICE_KEY --credential="$CREDS" -c test_credential_lookup.conf` # Cleanup properly @@ -93,6 +133,12 @@ gnunet-namestore -z alice -d -n $TEST_CREDENTIAL -t CRED -e never -c test_creden gnunet-namestore -z epub -d -n $DISC_ATTR -t ATTR -c test_credential_lookup.conf gnunet-namestore -z eorg -d -n $PREF_ATTR -t ATTR -c test_credential_lookup.conf gnunet-namestore -z stateu -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf +#gnunet-namestore -z a -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf +#gnunet-namestore -z d -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf +#gnunet-namestore -z e -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf +#gnunet-namestore -z f -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf +#gnunet-namestore -z g -d -n $STATE_STUD_ATTR -t ATTR -c test_credential_lookup.conf + gnunet-arm -e -c test_credential_lookup.conf if [ "$RES_CRED" != "Failed." ] -- cgit v1.2.3