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 <http://www.gnu.org/licenses/>.
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
*/
* @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++)
{
* @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;
{
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)
* @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;
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;
* @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++)
{
* @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;
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],
}
-
/**
* Deserialize the given destination
*
* @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;
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];
}
-
/**
* Calculate how many bytes we will need to serialize
* the given delegation chain and credential
* @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);
* @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;
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],
* @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;
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];
}
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;
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;
}
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;
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;
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);
#include "credential.h"
#include <inttypes.h>
-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;
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);
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;
// 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,
{
// 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);
}
*/
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);
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);
// 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)
}
-
-
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;i<c_count;i++)
+ for (i = 0; i < c_count; i++)
{
line = GNUNET_CREDENTIAL_credential_to_string (&cred[i]);
- printf ("%s\n",
- line);
+ printf ("%s\n", line);
GNUNET_free (line);
}
}
struct GNUNET_CREDENTIAL_Credential *cred)
{
int i;
- char* iss_key;
- char* sub_key;
+ char *iss_key;
+ char *sub_key;
verify_request = NULL;
if (NULL == cred)
printf ("Failed.\n");
else
{
- printf("Delegation Chain:\n");
- for (i=0;i<d_count;i++)
+ printf ("Delegation Chain:\n");
+ for (i = 0; i < d_count; i++)
{
iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].issuer_key);
sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&dc[i].subject_key);
if (0 != dc[i].subject_attribute_len)
{
- printf ("(%d) %s.%s <- %s.%s\n", i,
- iss_key, dc[i].issuer_attribute,
- sub_key, dc[i].subject_attribute);
- } else {
- printf ("(%d) %s.%s <- %s\n", i,
- iss_key, dc[i].issuer_attribute,
+ printf ("(%d) %s.%s <- %s.%s\n",
+ i,
+ iss_key,
+ dc[i].issuer_attribute,
+ sub_key,
+ dc[i].subject_attribute);
+ }
+ else
+ {
+ printf ("(%d) %s.%s <- %s\n",
+ i,
+ iss_key,
+ dc[i].issuer_attribute,
sub_key);
}
GNUNET_free (iss_key);
GNUNET_free (sub_key);
}
- printf("\nCredentials:\n");
- for (i=0;i<c_count;i++)
+ printf ("\nCredentials:\n");
+ for (i = 0; i < c_count; i++)
{
iss_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].issuer_key);
sub_key = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred[i].subject_key);
- printf ("%s.%s <- %s\n",
- iss_key, cred[i].issuer_attribute,
- sub_key);
+ printf ("%s.%s <- %s\n", iss_key, cred[i].issuer_attribute, sub_key);
GNUNET_free (iss_key);
GNUNET_free (sub_key);
-
}
printf ("Successful.\n");
}
* @param ego an ego known to identity service, or NULL
*/
static void
-identity_cb (void *cls,
- const struct GNUNET_IDENTITY_Ego *ego)
+identity_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
{
const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
struct GNUNET_CREDENTIAL_Credential *cred;
if (NULL != ego_name)
{
fprintf (stderr,
- _("Ego `%s' not known to identity service\n"),
+ _ ("Ego `%s' not known to identity service\n"),
ego_name);
}
GNUNET_SCHEDULER_shutdown ();
if (GNUNET_YES == collect)
{
-
+
if (GNUNET_OK !=
GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_key,
strlen (issuer_key),
&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 ();
}
privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
- collect_request = GNUNET_CREDENTIAL_collect(credential,
- &issuer_pkey,
- issuer_attr, //TODO argument
- privkey,
- &handle_collect_result,
- NULL);
+ collect_request = GNUNET_CREDENTIAL_collect (credential,
+ &issuer_pkey,
+ issuer_attr, //TODO argument
+ privkey,
+ &handle_collect_result,
+ NULL);
return;
}
if (NULL == expiration)
{
- fprintf (stderr,
- "Please specify a TTL\n");
+ fprintf (stderr, "Please specify a TTL\n");
GNUNET_SCHEDULER_shutdown ();
return;
- } else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expiration,
- &etime_rel))
+ }
+ else if (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_time_to_relative (expiration, &etime_rel))
{
etime_abs = GNUNET_TIME_relative_to_absolute (etime_rel);
- } 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!\n",
- expiration);
+ fprintf (stderr, "%s is not a valid ttl!\n", expiration);
GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_free_non_null (ego_name);
ego_name = NULL;
cred = GNUNET_CREDENTIAL_credential_issue (privkey,
- &subject_pkey,
- issuer_attr,
- &etime_abs);
+ &subject_pkey,
+ issuer_attr,
+ &etime_abs);
res = GNUNET_CREDENTIAL_credential_to_string (cred);
GNUNET_free (cred);
*/
static int
parse_expiration (const char *expirationstring,
- int *etime_is_rel,
- uint64_t *etime)
+ int *etime_is_rel,
+ uint64_t *etime)
{
// copied from namestore/gnunet-namestore.c
struct GNUNET_TIME_Relative etime_rel;
struct GNUNET_TIME_Absolute etime_abs;
-
- if (0 == strcmp (expirationstring,
- "never"))
+
+ if (0 == strcmp (expirationstring, "never"))
{
*etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
*etime_is_rel = GNUNET_NO;
return GNUNET_OK;
}
if (GNUNET_OK ==
- GNUNET_STRINGS_fancy_time_to_relative (expirationstring,
- &etime_rel))
+ GNUNET_STRINGS_fancy_time_to_relative (expirationstring, &etime_rel))
{
*etime_is_rel = GNUNET_YES;
*etime = etime_rel.rel_value_us;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Storing record with relative expiration time of %s\n",
- GNUNET_STRINGS_relative_time_to_string (etime_rel,
- GNUNET_NO));
+ "Storing record with relative expiration time of %s\n",
+ GNUNET_STRINGS_relative_time_to_string (etime_rel, GNUNET_NO));
return GNUNET_OK;
}
if (GNUNET_OK ==
- GNUNET_STRINGS_fancy_time_to_absolute (expirationstring,
- &etime_abs))
+ GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs))
{
*etime_is_rel = GNUNET_NO;
*etime = etime_abs.abs_value_us;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Storing record with absolute expiration time of %s\n",
- GNUNET_STRINGS_absolute_time_to_string (etime_abs));
+ "Storing record with absolute expiration time of %s\n",
+ GNUNET_STRINGS_absolute_time_to_string (etime_abs));
return GNUNET_OK;
}
return GNUNET_SYSERR;
static void
error_cb (void *cls)
{
- fprintf(stderr, "Error occured during lookup, shutting down.\n");
+ fprintf (stderr, "Error occured during lookup, shutting down.\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
static void
-add_continuation (void *cls,
- int32_t success,
- const char *emsg)
+add_continuation (void *cls, int32_t success, const char *emsg)
{
// TODO what does that do, can I somehow parse an empty callback on success or do I have to set the qe* to NULL?
struct GNUNET_NAMESTORE_QueueEntry **qe = cls;
static void
get_existing_record (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
- const char *rec_name,
- unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
+ const char *rec_name,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
{
struct GNUNET_GNSRECORD_Data rdn[rd_count + 1];
struct GNUNET_GNSRECORD_Data *rde;
memset (rdn, 0, sizeof (struct GNUNET_GNSRECORD_Data));
- GNUNET_memcpy (&rdn[1],
- rd,
- rd_count * sizeof (struct GNUNET_GNSRECORD_Data));
+ GNUNET_memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_GNSRECORD_Data));
rde = &rdn[0];
rde->data = data;
rde->data_size = data_size;
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;
}
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;
}
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;
}
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;
}
// 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;
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;
}
// 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;
}
// 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);
{
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;
// 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;
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;
}
// 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,
&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;
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;
}
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;i<count;i++)
+ for (i = 0; i < count; i++)
{
cred = GNUNET_CREDENTIAL_credential_from_string (tok);
GNUNET_memcpy (&credentials[i],
cred,
sizeof (struct GNUNET_CREDENTIAL_Credential));
credentials[i].issuer_attribute = GNUNET_strdup (cred->issuer_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;i<count;i++)
+ verify_request = GNUNET_CREDENTIAL_verify (credential,
+ &issuer_pkey,
+ issuer_attr, //TODO argument
+ &subject_pkey,
+ count,
+ credentials,
+ &handle_verify_result,
+ NULL);
+ for (i = 0; i < count; i++)
{
- GNUNET_free ((char*)credentials[i].issuer_attribute);
+ GNUNET_free ((char *) credentials[i].issuer_attribute);
}
GNUNET_free (tmp);
- } else if (GNUNET_YES == create_cred) {
+ }
+ else if (GNUNET_YES == create_cred)
+ {
if (NULL == ego_name)
{
- fprintf (stderr,
- _("Issuer ego required\n"));
+ fprintf (stderr, _ ("Issuer 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;
- } else {
+ }
+ else
+ {
fprintf (stderr,
- _("Please specify name to lookup, subject key and issuer key!\n"));
+ _ (
+ "Please specify name to lookup, subject key and issuer key!\n"));
GNUNET_SCHEDULER_shutdown ();
}
return;
GNUNET_GETOPT_option_string ('s',
"subject",
"PKEY",
- gettext_noop ("The public key of the subject to lookup the credential for, or for issuer side storage: subject and its attributes"),
+ gettext_noop ("The public key of the subject to lookup the"
+ "credential for, or for issuer side storage: subject and its attributes"),
&subject),
GNUNET_GETOPT_option_string ('b',
"credential",
GNUNET_GETOPT_option_string ('T',
"ttl",
"EXP",
- gettext_noop ("The time to live for the credential. e.g. 5m, 6h, \"1990-12-30 12:00:00\""),
+ gettext_noop ("The time to live for the credential."
+ "e.g. 5m, 6h, \"1990-12-30 12:00:00\""),
&expiration),
GNUNET_GETOPT_option_flag ('g',
"collect",
return 2;
GNUNET_log_setup ("gnunet-credential", "WARNING", NULL);
- ret =
- (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-credential",
- _("GNUnet credential resolver tool"),
- options,
- &run, NULL)) ? 0 : 1;
- GNUNET_free ((void*) argv);
+ ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-credential",
+ _ ("GNUnet credential resolver tool"),
+ options,
+ &run,
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
uint32_t rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Yo, im Test und so\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-----------FW:Got %d entries\n", rd_count);
+
+ struct VerifyRequestHandle *vrh;
+ struct DelegationSetQueueEntry *current_set;
+ struct DelegationSetQueueEntry *ds_entry;
+ struct DelegationQueueEntry *dq_entry;
+
+ current_set = cls;
+ // set handle to NULL (as el = NULL)
+ current_set->lookup_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
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);
}
}
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
* @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;
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;
}
return attr_str;
}
- case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
+ case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
+ {
struct GNUNET_CREDENTIAL_Credential *cred;
char *cred_str;
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);
* @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];
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, ",");
}
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;
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);
}
}
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);
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;
}
# (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
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
# 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
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." ]