chibipub

experimental activitypub node in C
git clone git://jb55.com/chibipub
Log | Files | Refs | README | LICENSE

commit 194d9bd5c09a7085bff5a39f8982f1c8c7c1aee4
parent 12cfbb43467c81acf5a2b05f68f196c66937ac55
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 28 Jul 2021 12:21:40 -0700

don't sigcheck delete activities for now

until I figure this out

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/sigcheck.c | 29++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/sigcheck.c b/src/sigcheck.c @@ -66,6 +66,19 @@ static int hex_bytes(unsigned char *bytes, int n_bytes, char *buf, return 1; } +static int is_delete_activity(struct ubjson *ubjson) +{ + struct json val; + static const char *type_path[] = {"type"}; + + if (!ubjson_lookup(ubjson, type_path, ARRAY_SIZE(type_path), &val)) { + printf("unusual: couldn't determine object type\n"); + return 1; + } + + return val.type == JSON_STRING && !memcmp(val.string, "Delete", val.len); +} + static int get_cached_pubkey(const char *keyid, int keyid_len, struct cursor *arena, unsigned char **pubkey, int *pubkey_size) @@ -139,6 +152,9 @@ static int verify_signature(struct cursor cur, struct cursor arena) init_ubjson(&ubjson, cur.start, cur.p - cur.start); ubjson.data_end = cur.p; + if (is_delete_activity(&ubjson)) + return 2; + static const char *sig_path[] = {"@wssig"}; if (!ubjson_lookup(&ubjson, sig_path, ARRAY_SIZE(sig_path), &sig)) { note_error(&ubjson.errs, "@wssig field not found"); @@ -158,7 +174,7 @@ static int verify_signature(struct cursor cur, struct cursor arena) } if (!get_cached_pubkey(keyid.string, keyid.len, &arena, &pubkey, &pubkey_size)) { - note_error(&ubjson.errs, "no cached pubkey for '%s'", keyid.string); + note_error(&ubjson.errs, "no cached pubkey for '%.*s'", keyid.len, keyid.string); return 0; } @@ -269,6 +285,9 @@ static int gather_keyids(unsigned char *json, int json_len, init_ubjson(&ubjson, ubjson_mem, ubjson_mem_size); ubjson.data_end = ubjson.cur.p; + if (is_delete_activity(&ubjson)) + continue; + if (!ubjson_lookup(&ubjson, path, ARRAY_SIZE(path), &val)) { note_error(&parser.errs, "@wskeyid not found"); return 0; @@ -618,7 +637,7 @@ static int fetch_signatures(unsigned char *json, int json_len, int sigcheck(struct sigcheck *check) { - int count = 0; + int count = 0, res; unsigned char *p, *start, *scratch; size_t flen; struct json_parser jsonp; @@ -647,8 +666,12 @@ int sigcheck(struct sigcheck *check) count++; debug_info("[%d] parse success\n", count); - if (!verify_signature(out_cur, out_cur)) { + res = verify_signature(out_cur, out_cur); + + if (res == 0) { printf("bad signature #%d\n", count); + } else if (res == 1) { + printf("good signature #%d\n", count); } // overwrite last ubjson