summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVivien Kraus <vivien@planete-kraus.eu>2020-01-01 00:00:00 +0100
committerVivien Kraus <vivien@planete-kraus.eu>2021-06-19 15:44:24 +0200
commit0dd0ab17ebf6d8cef93f007582156548aca4c5dd (patch)
treefc7fd2f8695dc2b1924f12a5321048aa67c50214 /src
parent2fc254c809e42029f28982404870604633b35521 (diff)
Add a function to hash a public key for DPoP.
Diffstat (limited to 'src')
-rw-r--r--src/jwk/ChangeLog4
-rw-r--r--src/jwk/generate-key.c4
-rw-r--r--src/jwk/libwebidoidc-jwk.c14
-rw-r--r--src/scm/webid-oidc/stubs.scm3
4 files changed, 24 insertions, 1 deletions
diff --git a/src/jwk/ChangeLog b/src/jwk/ChangeLog
index ebd0873..88b04e0 100644
--- a/src/jwk/ChangeLog
+++ b/src/jwk/ChangeLog
@@ -6,6 +6,10 @@
2020-11-25 Vivien Kraus <vivien@planete-kraus.eu>
+ * libwebidoidc-jwk.c (jkt): Implement the jkt function.
+
+ * generate-key.c (run): display the hash of the key.
+
* libwebidoidc-jwk.c: new file.
Add the strip function.
diff --git a/src/jwk/generate-key.c b/src/jwk/generate-key.c
index ec8ce76..e875b24 100644
--- a/src/jwk/generate-key.c
+++ b/src/jwk/generate-key.c
@@ -10,6 +10,8 @@
#define _(s) gettext (s)
SCM webidoidc_generate_key_g (SCM args);
+SCM webidoidc_strip_key_g (SCM key);
+SCM webidoidc_jkt_g (SCM key);
extern int init_webidoidc (void);
@@ -48,6 +50,8 @@ run (void *params, int argc, char *argv[])
(scm_from_utf8_keyword ("n-size"),
scm_from_size_t (n_size)));
}
+ scm_display (webidoidc_jkt_g (data), scm_current_error_port ());
+ fprintf (stderr, "\n");
scm_display (data, scm_current_output_port ());
}
diff --git a/src/jwk/libwebidoidc-jwk.c b/src/jwk/libwebidoidc-jwk.c
index 84da5da..71cb71c 100644
--- a/src/jwk/libwebidoidc-jwk.c
+++ b/src/jwk/libwebidoidc-jwk.c
@@ -3,6 +3,7 @@
#define _(s) dgettext (PACKAGE, s)
void webid_oidc_random (size_t len, uint8_t * dst);
+SCM webidoidc_hash_g (SCM alg, SCM payload);
/* Register "generate-key", a guile function to generate a keypair. */
void init_webidoidc_jwk (void);
@@ -173,9 +174,22 @@ SCM_DEFINE (webidoidc_strip_key_g, "strip-key", 1, 0, 0, (SCM key),
scm_throw (unsupported_kty, scm_list_1 (key));
}
+static SCM scm_to_json_string;
+
+SCM_SYMBOL (sha256, "SHA-256");
+
+SCM_DEFINE (webidoidc_jkt_g, "jkt", 1, 0, 0, (SCM key), "Hash a public key.")
+{
+ SCM stripped = webidoidc_strip_key_g (key);
+ SCM as_json = scm_call_1 (scm_to_json_string, stripped);
+ SCM as_bytevector = scm_string_to_utf8 (as_json);
+ return webidoidc_hash_g (sha256, as_bytevector);
+}
+
void
init_webidoidc_jwk (void)
{
+ scm_to_json_string = scm_c_public_ref ("json", "scm->json-string");
#ifndef SCM_MAGIC_SNARFER
#include "libwebidoidc-jwk.x"
#endif /* not SCM_MAGIC_SNARFER */
diff --git a/src/scm/webid-oidc/stubs.scm b/src/scm/webid-oidc/stubs.scm
index 4f2036b..58fe356 100644
--- a/src/scm/webid-oidc/stubs.scm
+++ b/src/scm/webid-oidc/stubs.scm
@@ -46,7 +46,8 @@
(fix-generate-key . generate-key)
(fix-kty . kty)
strip-key
- (fix-hash . hash))
+ (fix-hash . hash)
+ jkt)
;; json reader from guile-json will not behave consistently with
;; SRFI-180 with objects: keys will be mapped to strings, not