GNUnet 0.21.2
did_helper.c File Reference

helper library for DID related functions More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_namestore_service.h"
#include "gnunet_gns_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "did_helper.h"
#include "jansson.h"
Include dependency graph for did_helper.c:

Go to the source code of this file.

Macros

#define STR_INDIR(x)   #x
 
#define STR(x)   STR_INDIR (x)
 

Functions

char * DID_pkey_to_did (struct GNUNET_CRYPTO_PublicKey *pkey)
 Generate a DID for a given GNUNET public key. More...
 
char * DID_identity_to_did (struct GNUNET_IDENTITY_Ego *ego)
 Generate a DID for a given gnunet EGO. More...
 
enum GNUNET_GenericReturnValue DID_did_to_pkey (const char *did, struct GNUNET_CRYPTO_PublicKey *pkey)
 Return the public key of a DID. More...
 
struct GNUNET_CRYPTO_PublicKeyGNUNET_DID_key_convert_multibase_base64_to_gnunet (char *pkey_str)
 Convert a base 64 encoded public key to a GNUNET key. More...
 
char * DID_key_convert_gnunet_to_multibase_base64 (struct GNUNET_CRYPTO_PublicKey *pkey)
 Convert GNUNET key to a base 64 encoded public key. More...
 
char * DID_pkey_to_did_document (struct GNUNET_CRYPTO_PublicKey *pkey)
 Create a did generate did object. More...
 
char * DID_identity_to_did_document (struct GNUNET_IDENTITY_Ego *ego)
 Generate the default DID document for a GNUNET ego Wrapper around GNUNET_DID_pkey_to_did_document. More...
 

Detailed Description

helper library for DID related functions

Author
Tristan Schwieren

Definition in file did_helper.c.

Macro Definition Documentation

◆ STR_INDIR

#define STR_INDIR (   x)    #x

Definition at line 34 of file did_helper.c.

◆ STR

#define STR (   x)    STR_INDIR (x)

Definition at line 35 of file did_helper.c.

Function Documentation

◆ DID_pkey_to_did()

char * DID_pkey_to_did ( struct GNUNET_CRYPTO_PublicKey pkey)

Generate a DID for a given GNUNET public key.

Return a DID for a given GNUNET public key.

Parameters
pkey
Returns
char* Returns the DID. Caller must free TODO: Check if EdDSA

Definition at line 45 of file did_helper.c.

46{
47 char *pkey_str;
48 char *did_str;
49
51 GNUNET_asprintf (&did_str, "%s%s",
53 pkey_str);
54
55 GNUNET_free (pkey_str);
56 return did_str;
57}
#define GNUNET_DID_METHOD_PREFIX
Definition: did_helper.h:27
static char * pkey
Public key of the zone to look in, in ASCII.
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:568
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_asprintf(), GNUNET_CRYPTO_public_key_to_string(), GNUNET_DID_METHOD_PREFIX, GNUNET_free, and pkey.

Referenced by DID_identity_to_did(), DID_identity_to_did_document(), and DID_pkey_to_did_document().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DID_identity_to_did()

char * DID_identity_to_did ( struct GNUNET_IDENTITY_Ego ego)

Generate a DID for a given gnunet EGO.

Wrapper around GNUNET_DID_pkey_to_did

Parameters
ego
Returns
char* Returns the DID. Caller must free

Definition at line 67 of file did_helper.c.

68{
70
72 return DID_pkey_to_did (&pkey);
73}
char * DID_pkey_to_did(struct GNUNET_CRYPTO_PublicKey *pkey)
Generate a DID for a given GNUNET public key.
Definition: did_helper.c:45
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:529
An identity key as per LSD0001.

References DID_pkey_to_did(), GNUNET_IDENTITY_ego_get_public_key(), and pkey.

Referenced by create_did_ego_lockup_cb(), and process_dids().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DID_did_to_pkey()

enum GNUNET_GenericReturnValue DID_did_to_pkey ( const char *  did,
struct GNUNET_CRYPTO_PublicKey pkey 
)

Return the public key of a DID.

Definition at line 79 of file did_helper.c.

80{
81 char pkey_str[MAX_DID_SPECIFIC_IDENTIFIER_LENGTH + 1]; /* 0-term */
82
83 if ((1 != (sscanf (did,
86 "s", pkey_str))) ||
88 {
89 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not decode given DID: %s\n",
90 did);
91 return GNUNET_NO;
92 }
93
94 return GNUNET_OK;
95}
#define STR(x)
Definition: did_helper.c:35
#define MAX_DID_SPECIFIC_IDENTIFIER_LENGTH
Definition: did_helper.h:28
static char * did
DID Attribute String.
Definition: gnunet-did.c:83
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string(const char *str, struct GNUNET_CRYPTO_PublicKey *key)
Parses a (Base32) string representation of the public key.
Definition: crypto_pkey.c:588
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_WARNING

References did, GNUNET_CRYPTO_public_key_from_string(), GNUNET_DID_METHOD_PREFIX, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_OK, MAX_DID_SPECIFIC_IDENTIFIER_LENGTH, pkey, and STR.

Referenced by DID_resolve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DID_key_convert_multibase_base64_to_gnunet()

struct GNUNET_CRYPTO_PublicKey * GNUNET_DID_key_convert_multibase_base64_to_gnunet ( char *  pkey_str)

Convert a base 64 encoded public key to a GNUNET key.

Definition at line 101 of file did_helper.c.

102{
103 return NULL;
104}

◆ DID_key_convert_gnunet_to_multibase_base64()

char * DID_key_convert_gnunet_to_multibase_base64 ( struct GNUNET_CRYPTO_PublicKey pkey)

Convert GNUNET key to a base 64 encoded public key.

Definition at line 110 of file did_helper.c.

113{
114 struct GNUNET_CRYPTO_EddsaPublicKey pubkey = pkey->eddsa_key;
115
116 // This is how to convert out pubkeys to W3c Ed25519-2020 multibase (base64url no padding)
117 char *pkey_base_64;
118 char *pkey_multibase;
119 char pkx[34];
120
121 pkx[0] = 0xed;
122 pkx[1] = 0x01;
123 memcpy (pkx + 2, &pubkey, sizeof (pubkey));
124 GNUNET_STRINGS_base64url_encode (pkx, sizeof (pkx), &pkey_base_64);
125 GNUNET_asprintf (&pkey_multibase, "u%s", pkey_base_64);
126
127 GNUNET_free (pkey_base_64);
128 return pkey_multibase;
129}
static struct GNUNET_CRYPTO_PublicKey pubkey
Public key of the zone to look in.
size_t GNUNET_STRINGS_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
Definition: strings.c:1671
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...

References GNUNET_asprintf(), GNUNET_free, GNUNET_STRINGS_base64url_encode(), pkey, and pubkey.

Referenced by DID_pkey_to_did_document().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DID_pkey_to_did_document()

char * DID_pkey_to_did_document ( struct GNUNET_CRYPTO_PublicKey pkey)

Create a did generate did object.

Generate the default DID document for a GNUNET public key.

Parameters
pkey
Returns
void* Return pointer to the DID Document

Definition at line 138 of file did_helper.c.

139{
140
141 /* FIXME-MSC: This is effectively creating a DID Document default template for
142 * the initial document.
143 * Maybe this can be refactored to generate such a template for an identity?
144 * Even if higher layers add/modify it, there should probably still be a
145 * GNUNET_DID_document_template_from_identity()
146 */
147
148 char *did_str;
149 char *verify_id_str;
150 char *pkey_multibase_str;
151 char *didd_str;
152 json_t *didd_json;
153
154 did_str = DID_pkey_to_did (pkey);
155 GNUNET_asprintf (&verify_id_str, "%s#key-1", did_str);
156
158
159 didd_json = json_pack (
160 "{s:[ss], s:s, s:[{s:s, s:s, s:s, s:s}], s:[s], s:[s]}",
161 "@context",
162 "https://www.w3.org/ns/did/v1",
163 "https://w3id.org/security/suites/ed25519-2020/v1",
164 "id",
165 did_str,
166 "verificationMethod",
167 "id",
168 verify_id_str,
169 "type",
170 "Ed25519VerificationKey2020",
171 "controller",
172 did_str,
173 "publicKeyMultibase",
174 pkey_multibase_str,
175 "authentication",
176 "#key-1",
177 "assertionMethod",
178 "#key-1");
179
180 // Encode DID Document as JSON string
181 didd_str = json_dumps (didd_json, JSON_INDENT (2));
182
183 // Free
184 GNUNET_free (did_str);
185 GNUNET_free (verify_id_str);
186 GNUNET_free (pkey_multibase_str);
187 json_decref (didd_json);
188
189 return didd_str;
190}
char * DID_key_convert_gnunet_to_multibase_base64(struct GNUNET_CRYPTO_PublicKey *pkey)
Convert GNUNET key to a base 64 encoded public key.
Definition: did_helper.c:110

References DID_key_convert_gnunet_to_multibase_base64(), DID_pkey_to_did(), GNUNET_asprintf(), GNUNET_free, and pkey.

Referenced by DID_create_namestore_lookup_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DID_identity_to_did_document()

char * DID_identity_to_did_document ( struct GNUNET_IDENTITY_Ego ego)

Generate the default DID document for a GNUNET ego Wrapper around GNUNET_DID_pkey_to_did_document.

Generate the default DID document for a GNUNET ego.

Definition at line 197 of file did_helper.c.

198{
200
202 return DID_pkey_to_did (&pkey);
203}

References DID_pkey_to_did(), GNUNET_IDENTITY_ego_get_public_key(), and pkey.

Here is the call graph for this function: