chibipub

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

commit cb7b55daa664285f5de4db448d03e40f4a5c1ee7
parent 40634c2de9d6c7b255581d0707c20e603859cb45
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 25 Oct 2021 13:14:50 -0700

fix hashes

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

Diffstat:
Msrc/ap_json.c | 6++++--
Msrc/main.c | 3++-
Msrc/post.c | 16++++++++--------
3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/ap_json.c b/src/ap_json.c @@ -251,7 +251,7 @@ static int handle_wsdigest(struct ap_json *a) struct cursor *c = &p->cur; size_t b64_len; unsigned char hash[32]; - unsigned char b64[128]; + char b64[128]; unsigned char *pos; if (!handle_key(a, "@wsdigest")) { @@ -264,11 +264,13 @@ static int handle_wsdigest(struct ap_json *a) } sha256_hash(hash, a->req->body, a->req->body_len); + // TODO: this might be broken... base64_encode(hash, 32, b64, sizeof(b64), &b64_len); pos = c->p; - if (!(push_str(c, "SHA-256=") && push_data(c, b64, b64_len) )) { + if (!(push_str(c, "SHA-256=") && + push_data(c, (unsigned char*)b64, b64_len) )) { return 0; } diff --git a/src/main.c b/src/main.c @@ -323,7 +323,8 @@ static int handle_request(struct http_req *req, struct cursor *arena) { http_log(req); - if (starts_with(req->path, "/.well-known/webfinger?resource=acct:")) { + if (starts_with(req->path, "/.well-known/webfinger?resource=acct:") || + starts_with(req->path, "/?resource=acct:")) { return handle_webfinger(req); } else if (is_post(req) && patheq(req, "/inbox")) { return handle_inbox_request(req, arena); diff --git a/src/post.c b/src/post.c @@ -67,7 +67,7 @@ static int make_id(const char *activity, const char *dt, const char *content, unsigned char buffer[32]) { - debug("make_id: hashing '%s%s'", dt, content); + debug("make_id: hashing '%s%s%s'", activity, dt, content); blake3_hasher hasher; blake3_hasher_init(&hasher); @@ -116,18 +116,18 @@ int create_post(struct chibipub *pub, struct post *post) assert(ok); hex_bytes(rawid, sizeof(rawid), note_id, 64); - note_id[64] = '\0'; + note_id[32] = '\0'; // create_id = H("create" + formatted_pubdate + note_id) ok = make_id("create", pubdate, note_id, rawid); assert(ok); hex_bytes(rawid, sizeof(rawid), create_id, 64); - create_id[64] = '\0'; + create_id[32] = '\0'; fprintf(outbox, "{"); // we can just use the first 16 bytes of our id as the shortid - writekv("id", "\"https://%s/obj/cr_%.*s\",", pub->hostname, 32, create_id); + writekv("id", "\"https://%s/obj/cr_%s\",", pub->hostname, create_id); writekv("type", "\"Create\","); writekv("published", "\"%s\",", pubdate); @@ -135,7 +135,7 @@ int create_post(struct chibipub *pub, struct post *post) writekv("cc", "[\"https://%s/followers\"],", pub->hostname); writekv("object", "{"); - writekv("id", "\"https://%s/obj/note_%.*s\",", pub->hostname, 32, note_id); + writekv("id", "\"https://%s/obj/note_%s\",", pub->hostname, note_id); writekv("type", "\"Note\","); writekv("summary", "null,"); @@ -143,15 +143,15 @@ int create_post(struct chibipub *pub, struct post *post) writekv("inReplyTo", "\"%s\",", post->in_reply_to); writekv("published", "\"%s\",", pubdate); - writekv("url", "\"https://%s/obj/note_%.*s\",", pub->hostname, 32, note_id); + writekv("url", "\"https://%s/obj/note_%s\",", pub->hostname, note_id); // TODO: multiuser writekv("attributedTo", "\"https://%s\",", pub->hostname); writekv("to", "[\"https://www.w3.org/ns/activitystreams#Public\"],"); writekv("cc", "[\"https://%s/followers\"],", pub->hostname); writekv("sensitive", "false,"); - writekv("atomUri", "\"https://%s/obj/note_%.*s\",", pub->hostname, 32, note_id); - writekv("inReplyToAtomUri", "\"https://%s/obj/note_%.*s\",", pub->hostname, 32, note_id); + writekv("atomUri", "\"https://%s/obj/note_%s\",", pub->hostname, note_id); + writekv("inReplyToAtomUri", "\"https://%s/obj/note_%s\",", pub->hostname, note_id); writekv("content", "\"%s\"", post->content); // TODO: attachments