GNUnet  0.10.x
Functions
credential_misc.h File Reference

Credential helper functions. More...

#include "gnunet_credential_service.h"
Include dependency graph for credential_misc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * GNUNET_CREDENTIAL_credential_to_string (const struct GNUNET_CREDENTIAL_Credential *cred)
 
struct GNUNET_CREDENTIAL_CredentialGNUNET_CREDENTIAL_credential_from_string (const char *str)
 

Detailed Description

Credential helper functions.

Definition in file credential_misc.h.

Function Documentation

◆ GNUNET_CREDENTIAL_credential_to_string()

char* GNUNET_CREDENTIAL_credential_to_string ( const struct GNUNET_CREDENTIAL_Credential cred)

Definition at line 37 of file credential_misc.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CREDENTIAL_Credential::expiration, GNUNET_asprintf(), GNUNET_CRYPTO_ecdsa_public_key_to_string(), GNUNET_free, GNUNET_STRINGS_base64_encode(), GNUNET_CREDENTIAL_Credential::issuer_attribute, GNUNET_CREDENTIAL_Credential::issuer_key, issuer_pkey, GNUNET_CREDENTIAL_Credential::signature, GNUNET_CREDENTIAL_Credential::subject_key, and subject_pkey.

Referenced by credential_value_to_string(), handle_collect_result(), and identity_cb().

38 {
39  char *cred_str;
40  char *subject_pkey;
41  char *issuer_pkey;
42  char *signature;
43 
44 
48  sizeof(struct GNUNET_CRYPTO_EcdsaSignature),
49  &signature);
50  GNUNET_asprintf(&cred_str,
51  "%s.%s -> %s | %s | %" SCNu64,
52  issuer_pkey,
53  cred->issuer_attribute,
54  subject_pkey,
55  signature,
56  cred->expiration.abs_value_us);
57  GNUNET_free(subject_pkey);
58  GNUNET_free(issuer_pkey);
59  GNUNET_free(signature);
60  return cred_str;
61 }
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_pkey
Issuer key.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey
Subject key.
uint64_t abs_value_us
The actual value.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
an ECC signature using ECDSA
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1856
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:334
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
const char * issuer_attribute
The attribute.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_credential_from_string()

struct GNUNET_CREDENTIAL_Credential* GNUNET_CREDENTIAL_credential_from_string ( const char *  str)

Definition at line 64 of file credential_misc.c.

References _, GNUNET_TIME_Absolute::abs_value_us, GNUNET_CREDENTIAL_Credential::expiration, GNUNET_assert, GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_STRINGS_base64_decode(), GNUNET_CREDENTIAL_Credential::issuer_attribute_len, GNUNET_CREDENTIAL_Credential::issuer_key, issuer_pkey, name, GNUNET_CREDENTIAL_Credential::signature, GNUNET_CREDENTIAL_Credential::subject_key, and subject_pkey.

Referenced by credential_string_to_value(), and run().

65 {
66  struct GNUNET_CREDENTIAL_Credential *cred;
67  size_t enclen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
68 
69  if (enclen % 5 > 0)
70  enclen += 5 - enclen % 5;
71  enclen /= 5; /* 260/5 = 52 */
72  char subject_pkey[enclen + 1];
73  char issuer_pkey[enclen + 1];
74  char name[253 + 1];
75  char signature[256]; //TODO max payload size
76 
77  struct GNUNET_CRYPTO_EcdsaSignature *sig;
78  struct GNUNET_TIME_Absolute etime_abs;
79 
80  if (5 != sscanf(s,
81  "%52s.%253s -> %52s | %s | %" SCNu64,
82  issuer_pkey,
83  name,
84  subject_pkey,
85  signature,
86  &etime_abs.abs_value_us))
87  {
89  _("Unable to parse CRED record string `%s'\n"),
90  s);
91  return NULL;
92  }
93  cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen(name) + 1);
95  strlen(subject_pkey),
96  &cred->subject_key);
98  strlen(issuer_pkey),
99  &cred->issuer_key);
101  strlen(signature),
102  (char**)&sig));
103  cred->signature = *sig;
104  cred->expiration = etime_abs;
105  GNUNET_free(sig);
106  GNUNET_memcpy(&cred[1],
107  name,
108  strlen(name) + 1);
109  cred->issuer_attribute_len = strlen((char*)&cred[1]);
110  cred->issuer_attribute = (char*)&cred[1];
111  return cred;
112 }
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_pkey
Issuer key.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey
Subject key.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
an ECC signature using ECDSA
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1920
const char * name
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
const char * issuer_attribute
The attribute.
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:468
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint32_t issuer_attribute_len
Length of the attribute.
Here is the call graph for this function:
Here is the caller graph for this function: