GNUnet  0.10.x
Functions
credential_misc.c File Reference

Misc API for credentials. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_credential_service.h"
#include "gnunet_signatures.h"
#include "credential.h"
#include <inttypes.h>
Include dependency graph for credential_misc.c:

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 *s)
 
struct GNUNET_CREDENTIAL_CredentialGNUNET_CREDENTIAL_credential_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, struct GNUNET_CRYPTO_EcdsaPublicKey *subject, const char *attribute, struct GNUNET_TIME_Absolute *expiration)
 Issue an attribute to a subject. More...
 

Detailed Description

Misc API for credentials.

Author
Martin Schanzenbach

Definition in file credential_misc.c.

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:2004
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 *  s)

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, SSCANF, 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  if (enclen % 5 > 0)
69  enclen += 5 - enclen % 5;
70  enclen /= 5; /* 260/5 = 52 */
71  char subject_pkey[enclen + 1];
72  char issuer_pkey[enclen + 1];
73  char name[253 + 1];
74  char signature[256]; //TODO max payload size
75 
76  struct GNUNET_CRYPTO_EcdsaSignature *sig;
77  struct GNUNET_TIME_Absolute etime_abs;
78 
79  if (5 != SSCANF (s,
80  "%52s.%253s -> %52s | %s | %"SCNu64,
81  issuer_pkey,
82  name,
83  subject_pkey,
84  signature,
85  &etime_abs.abs_value_us))
86  {
88  _("Unable to parse CRED record string `%s'\n"),
89  s);
90  return NULL;
91  }
92  cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + strlen (name) + 1);
94  strlen (subject_pkey),
95  &cred->subject_key);
97  strlen (issuer_pkey),
98  &cred->issuer_key);
100  strlen (signature),
101  (char**)&sig));
102  cred->signature = *sig;
103  cred->expiration = etime_abs;
104  GNUNET_free (sig);
105  GNUNET_memcpy (&cred[1],
106  name,
107  strlen (name)+1);
108  cred->issuer_attribute_len = strlen ((char*)&cred[1]);
109  cred->issuer_attribute = (char*)&cred[1];
110  return cred;
111 }
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.
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:208
#define GNUNET_memcpy(dst, src, n)
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:2067
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
#define SSCANF
Definition: plibc.h:691
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: