diff options
| author | 2022-09-27 07:16:46 +0200 | |
|---|---|---|
| committer | 2022-09-27 07:16:46 +0200 | |
| commit | e550e86afbba28c234ebc15aac17c45de0290fdb (patch) | |
| tree | aa406994a0f7caa32f8f3a375c66553483065a10 /activitypub.c | |
| parent | Backported from xs. (diff) | |
| download | snac2-e550e86afbba28c234ebc15aac17c45de0290fdb.tar.gz snac2-e550e86afbba28c234ebc15aac17c45de0290fdb.tar.xz snac2-e550e86afbba28c234ebc15aac17c45de0290fdb.zip | |
Check the digest before enqueueing.
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c index d792ce2..2347498 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "xs_json.h" | 6 | #include "xs_json.h" |
| 7 | #include "xs_curl.h" | 7 | #include "xs_curl.h" |
| 8 | #include "xs_mime.h" | 8 | #include "xs_mime.h" |
| 9 | #include "xs_openssl.h" | ||
| 9 | 10 | ||
| 10 | #include "snac.h" | 11 | #include "snac.h" |
| 11 | 12 | ||
| @@ -311,7 +312,7 @@ void process_message(snac *snac, char *msg, char *req) | |||
| 311 | 312 | ||
| 312 | timeline_request(snac, in_reply_to, NULL); | 313 | timeline_request(snac, in_reply_to, NULL); |
| 313 | 314 | ||
| 314 | if (timeline_add(snac, id, msg, in_reply_to, NULL)) | 315 | if (timeline_add(snac, id, object, in_reply_to, NULL)) |
| 315 | snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); | 316 | snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); |
| 316 | } | 317 | } |
| 317 | } | 318 | } |
| @@ -551,6 +552,7 @@ int activitypub_post_handler(d_char *req, char *q_path, | |||
| 551 | int status = 202; /* accepted */ | 552 | int status = 202; /* accepted */ |
| 552 | char *i_ctype = xs_dict_get(req, "content-type"); | 553 | char *i_ctype = xs_dict_get(req, "content-type"); |
| 553 | snac snac; | 554 | snac snac; |
| 555 | char *v; | ||
| 554 | 556 | ||
| 555 | if (i_ctype == NULL) | 557 | if (i_ctype == NULL) |
| 556 | return 400; | 558 | return 400; |
| @@ -584,6 +586,18 @@ int activitypub_post_handler(d_char *req, char *q_path, | |||
| 584 | return 404; | 586 | return 404; |
| 585 | } | 587 | } |
| 586 | 588 | ||
| 589 | /* if it has a digest, check it now, because | ||
| 590 | later the payload won't be exactly the same */ | ||
| 591 | if ((v = xs_dict_get(req, "digest")) != NULL) { | ||
| 592 | xs *s1 = xs_sha256_base64(payload, p_size); | ||
| 593 | xs *s2 = xs_fmt("SHA-256=%s", s1); | ||
| 594 | |||
| 595 | if (strcmp(s2, v) == 0) | ||
| 596 | srv_log(xs_fmt("digest check OK")); | ||
| 597 | else | ||
| 598 | srv_log(xs_fmt("digest check FAILED")); | ||
| 599 | } | ||
| 600 | |||
| 587 | enqueue_input(&snac, msg, req); | 601 | enqueue_input(&snac, msg, req); |
| 588 | 602 | ||
| 589 | user_free(&snac); | 603 | user_free(&snac); |