|
@@ -13,8 +13,67 @@ d_char *http_signed_request(snac *snac, char *method, char *url,
|
|
|
d_char *headers,
|
|
|
d_char *body, int b_size,
|
|
|
int *status, d_char **payload, int *p_size)
|
|
|
-
|
|
|
+
|
|
|
{
|
|
|
- return xs_http_request(method, url, headers,
|
|
|
- body, b_size, status, payload, p_size);
|
|
|
+ xs *l1;
|
|
|
+ xs *date;
|
|
|
+ xs *digest;
|
|
|
+ xs *s64;
|
|
|
+ xs *signature;
|
|
|
+ char *host;
|
|
|
+ char *target;
|
|
|
+ char *seckey;
|
|
|
+
|
|
|
+ date = xs_utc_time("%a, %d %b %Y %H:%M:%S GMT");
|
|
|
+
|
|
|
+ {
|
|
|
+ xs *s = xs_replace(url, "https:/" "/", "");
|
|
|
+ l1 = xs_split_n(s, "/", 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ host = xs_list_get(l1, 0);
|
|
|
+
|
|
|
+ if (xs_list_len(l1) == 2)
|
|
|
+ target = xs_list_get(l1, 1);
|
|
|
+ else
|
|
|
+ target = "";
|
|
|
+
|
|
|
+
|
|
|
+ if (body != NULL)
|
|
|
+ digest = xs_sha256_hex(body, b_size);
|
|
|
+ else
|
|
|
+ digest = xs_sha256_hex("", 0);
|
|
|
+
|
|
|
+ seckey = xs_dict_get(snac->key, "secret");
|
|
|
+
|
|
|
+ {
|
|
|
+
|
|
|
+ xs *s = xs_fmt("(request-target): %s /%s\n"
|
|
|
+ "host: %s\n"
|
|
|
+ "digest: SHA-256=%s\n"
|
|
|
+ "date: %s",
|
|
|
+ strcmp(method, "POST") == 0 ? "post" : "get",
|
|
|
+ target, host, digest, date);
|
|
|
+
|
|
|
+ s64 = xs_rsa_sign(seckey, s, strlen(s));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ signature = xs_fmt("keyId=\"%s#main-key\","
|
|
|
+ "algorithm=\"rsa-sha256\","
|
|
|
+ "headers=\"(request-target) host digest date\","
|
|
|
+ "signature=\"%s\"",
|
|
|
+ snac->actor, s64);
|
|
|
+
|
|
|
+
|
|
|
+ headers = xs_dict_append(headers, "content-type", "application/activity+json");
|
|
|
+ headers = xs_dict_append(headers, "date", date);
|
|
|
+ headers = xs_dict_append(headers, "signature", signature);
|
|
|
+ headers = xs_dict_append(headers, "digest", digest);
|
|
|
+ headers = xs_dict_append(headers, "user-agent", "snac/2.x");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return NULL;
|
|
|
}
|