diff options
| author | 2023-12-10 10:27:45 +0100 | |
|---|---|---|
| committer | 2023-12-10 10:27:45 +0100 | |
| commit | 90179f84596e7885fade4552cbeac0beb5c53303 (patch) | |
| tree | ecae50149124ee87fbe91fc6131176bcc28baeb0 | |
| parent | Minor reordering code to process_input_message(). (diff) | |
| download | penes-snac2-90179f84596e7885fade4552cbeac0beb5c53303.tar.gz penes-snac2-90179f84596e7885fade4552cbeac0beb5c53303.tar.xz penes-snac2-90179f84596e7885fade4552cbeac0beb5c53303.zip | |
activitypub_request() may have a NULL user.
In the NULL user case, only non-signed requests will be done,
but it's probably enough for actor requests in most cases.
| -rw-r--r-- | activitypub.c | 21 | ||||
| -rw-r--r-- | http.c | 4 |
2 files changed, 13 insertions, 12 deletions
diff --git a/activitypub.c b/activitypub.c index 0764fa2..a852256 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -60,18 +60,22 @@ const char *default_avatar_base64(void) | |||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | int activitypub_request(snac *snac, const char *url, xs_dict **data) | 63 | int activitypub_request(snac *user, const char *url, xs_dict **data) |
| 64 | /* request an object */ | 64 | /* request an object */ |
| 65 | { | 65 | { |
| 66 | int status; | 66 | int status = 0; |
| 67 | xs *response = NULL; | 67 | xs *response = NULL; |
| 68 | xs *payload = NULL; | 68 | xs *payload = NULL; |
| 69 | int p_size; | 69 | int p_size; |
| 70 | char *ctype; | 70 | char *ctype; |
| 71 | 71 | ||
| 72 | /* get from the net */ | 72 | *data = NULL; |
| 73 | response = http_signed_request(snac, "GET", url, | 73 | |
| 74 | NULL, NULL, 0, &status, &payload, &p_size, 0); | 74 | if (user != NULL) { |
| 75 | /* get from the net */ | ||
| 76 | response = http_signed_request(user, "GET", url, | ||
| 77 | NULL, NULL, 0, &status, &payload, &p_size, 0); | ||
| 78 | } | ||
| 75 | 79 | ||
| 76 | if (status == 0 || (status >= 500 && status <= 599)) { | 80 | if (status == 0 || (status >= 500 && status <= 599)) { |
| 77 | /* I found an instance running Misskey that returned | 81 | /* I found an instance running Misskey that returned |
| @@ -107,14 +111,11 @@ int activitypub_request(snac *snac, const char *url, xs_dict **data) | |||
| 107 | status = 500; | 111 | status = 500; |
| 108 | } | 112 | } |
| 109 | 113 | ||
| 110 | if (!valid_status(status)) | ||
| 111 | *data = NULL; | ||
| 112 | |||
| 113 | return status; | 114 | return status; |
| 114 | } | 115 | } |
| 115 | 116 | ||
| 116 | 117 | ||
| 117 | int actor_request(snac *snac, const char *actor, xs_dict **data) | 118 | int actor_request(snac *user, const char *actor, xs_dict **data) |
| 118 | /* request an actor */ | 119 | /* request an actor */ |
| 119 | { | 120 | { |
| 120 | int status, status2; | 121 | int status, status2; |
| @@ -128,7 +129,7 @@ int actor_request(snac *snac, const char *actor, xs_dict **data) | |||
| 128 | 129 | ||
| 129 | if (status != 200) { | 130 | if (status != 200) { |
| 130 | /* actor data non-existent or stale: get from the net */ | 131 | /* actor data non-existent or stale: get from the net */ |
| 131 | status2 = activitypub_request(snac, actor, &payload); | 132 | status2 = activitypub_request(user, actor, &payload); |
| 132 | 133 | ||
| 133 | if (valid_status(status2)) { | 134 | if (valid_status(status2)) { |
| 134 | /* renew data */ | 135 | /* renew data */ |
| @@ -120,7 +120,7 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url, | |||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | 122 | ||
| 123 | int check_signature(snac *snac, xs_dict *req, xs_str **err) | 123 | int check_signature(snac *user, xs_dict *req, xs_str **err) |
| 124 | /* check the signature */ | 124 | /* check the signature */ |
| 125 | { | 125 | { |
| 126 | char *sig_hdr = xs_dict_get(req, "signature"); | 126 | char *sig_hdr = xs_dict_get(req, "signature"); |
| @@ -173,7 +173,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err) | |||
| 173 | 173 | ||
| 174 | xs *actor = NULL; | 174 | xs *actor = NULL; |
| 175 | 175 | ||
| 176 | if (!valid_status(actor_request(snac, keyId, &actor))) { | 176 | if (!valid_status(actor_request(user, keyId, &actor))) { |
| 177 | *err = xs_fmt("unknown actor %s", keyId); | 177 | *err = xs_fmt("unknown actor %s", keyId); |
| 178 | return 0; | 178 | return 0; |
| 179 | } | 179 | } |