GNUnet 0.22.2
did_helper.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "platform.h"
27#include "gnunet_util_lib.h"
29#include "gnunet_gns_service.h"
31#include "did_helper.h"
32#include "jansson.h"
33
34#define STR_INDIR(x) #x
35#define STR(x) STR_INDIR (x)
36
44char*
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}
58
66char*
68{
70
72 return DID_pkey_to_did (&pkey);
73}
74
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}
96
100char *
103 pkey)
104{
105 struct GNUNET_CRYPTO_EddsaPublicKey pubkey = pkey->eddsa_key;
106
107 // This is how to convert out pubkeys to W3c Ed25519-2020 multibase (base64url no padding)
108 char *pkey_base_64;
109 char *pkey_multibase;
110 char pkx[34];
111
112 pkx[0] = 0xed;
113 pkx[1] = 0x01;
114 memcpy (pkx + 2, &pubkey, sizeof (pubkey));
115 GNUNET_STRINGS_base64url_encode (pkx, sizeof (pkx), &pkey_base_64);
116 GNUNET_asprintf (&pkey_multibase, "u%s", pkey_base_64);
117
118 GNUNET_free (pkey_base_64);
119 return pkey_multibase;
120}
121
128char *
130{
131
132 /* FIXME-MSC: This is effectively creating a DID Document default template for
133 * the initial document.
134 * Maybe this can be refactored to generate such a template for an identity?
135 * Even if higher layers add/modify it, there should probably still be a
136 * GNUNET_DID_document_template_from_identity()
137 */
138
139 char *did_str;
140 char *verify_id_str;
141 char *pkey_multibase_str;
142 char *didd_str;
143 json_t *didd_json;
144
145 did_str = DID_pkey_to_did (pkey);
146 GNUNET_asprintf (&verify_id_str, "%s#key-1", did_str);
147
149
150 didd_json = json_pack (
151 "{s:[ss], s:s, s:[{s:s, s:s, s:s, s:s}], s:[s], s:[s]}",
152 "@context",
153 "https://www.w3.org/ns/did/v1",
154 "https://w3id.org/security/suites/ed25519-2020/v1",
155 "id",
156 did_str,
157 "verificationMethod",
158 "id",
159 verify_id_str,
160 "type",
161 "Ed25519VerificationKey2020",
162 "controller",
163 did_str,
164 "publicKeyMultibase",
165 pkey_multibase_str,
166 "authentication",
167 "#key-1",
168 "assertionMethod",
169 "#key-1");
170
171 // Encode DID Document as JSON string
172 didd_str = json_dumps (didd_json, JSON_INDENT (2));
173
174 // Free
175 GNUNET_free (did_str);
176 GNUNET_free (verify_id_str);
177 GNUNET_free (pkey_multibase_str);
178 json_decref (didd_json);
179
180 return didd_str;
181}
182
187char *
189{
191
193 return DID_pkey_to_did (&pkey);
194}
#define STR(x)
Definition: did_helper.c:35
enum GNUNET_GenericReturnValue DID_did_to_pkey(const char *did, struct GNUNET_CRYPTO_PublicKey *pkey)
Return the public key of a DID.
Definition: did_helper.c:79
char * DID_pkey_to_did_document(struct GNUNET_CRYPTO_PublicKey *pkey)
Create a did generate did object.
Definition: did_helper.c:129
char * DID_pkey_to_did(struct GNUNET_CRYPTO_PublicKey *pkey)
Generate a DID for a given GNUNET public key.
Definition: did_helper.c:45
char * DID_identity_to_did(struct GNUNET_IDENTITY_Ego *ego)
Generate a DID for a given gnunet EGO.
Definition: did_helper.c:67
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.
Definition: did_helper.c:188
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:101
helper library for DID related functions
#define MAX_DID_SPECIFIC_IDENTIFIER_LENGTH
Definition: did_helper.h:28
#define GNUNET_DID_METHOD_PREFIX
Definition: did_helper.h:27
static char * did
DID Attribute String.
Definition: gnunet-did.c:83
static char * pkey
Public key of the zone to look in, in ASCII.
static struct GNUNET_CRYPTO_PublicKey pubkey
Public key of the zone to look in.
API to the GNS service.
API that can be used to manipulate GNS record data.
API that can be used to store naming information on a GNUnet node;.
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
#define GNUNET_log(kind,...)
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:379
GNUNET_GenericReturnValue
Named constants for return values.
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:399
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_STRINGS_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
Definition: strings.c:1648
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
An identity key as per LSD0001.
Handle for an ego.
Definition: identity.h:37