summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-09-29 14:44:24 +0200
committerdefault <nobody@localhost>2022-09-29 14:44:24 +0200
commit392c014c26ccf8c5281b3bc7f33024f1f3b3f990 (patch)
tree0c64839f9a82528b31d0636fc5cfdd687ddc364d /http.c
parentc680f15d4ea418b1b5e9c494be9bf4daa0eb6d49 (diff)
New function check_signature() (incomplete).
Diffstat (limited to 'http.c')
-rw-r--r--http.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/http.c b/http.c
index 7c9b598..8062806 100644
--- a/http.c
+++ b/http.c
@@ -99,3 +99,57 @@ d_char *http_signed_request(snac *snac, char *method, char *url,
return response;
}
+
+
+int check_signature(snac *snac, char *req)
+/* check the signature */
+{
+ char *sig_hdr = xs_dict_get(req, "signature");
+ xs *keyId = NULL;
+ xs *headers = NULL;
+ xs *signature = NULL;
+ char *pubkey;
+ char *p;
+
+ {
+ /* extract the values */
+ xs *l = xs_split(sig_hdr, ",");
+ char *v;
+
+ p = l;
+ while (xs_list_iter(&p, &v)) {
+ if (xs_startswith(v, "keyId"))
+ keyId = xs_crop(xs_dup(v), 7, -1);
+ else
+ if (xs_startswith(v, "headers"))
+ headers = xs_crop(xs_dup(v), 9, -1);
+ else
+ if (xs_startswith(v, "signature"))
+ signature = xs_crop(xs_dup(v), 12, -1);
+ }
+ }
+
+ if (keyId == NULL || headers == NULL || signature == NULL) {
+ snac_debug(snac, 1, xs_fmt("bad signature header"));
+ return 0;
+ }
+
+ /* strip the # from the keyId */
+ if ((p = strchr(keyId, '#')) != NULL)
+ *p = '\0';
+
+ /* the actor must already be here */
+ xs *actor = NULL;
+ if (!valid_status(actor_get(snac, keyId, &actor))) {
+ snac_debug(snac, 1, xs_fmt("check_signature unknown actor %s", keyId));
+ return 0;
+ }
+
+ if ((p = xs_dict_get(actor, "publicKey")) == NULL ||
+ ((pubkey = xs_dict_get(p, "publicKeyPem")) == NULL)) {
+ snac_debug(snac, 1, xs_fmt("cannot get pubkey from actor %s", keyId));
+ return 0;
+ }
+
+ return 1;
+}