commit adff9c5

default  ·  2023-02-02 03:05:50 +0000 UTC
parent 4634392
New function http_signed_request_raw().
1 files changed,  +23, -7
M http.c
M http.c
+23, -7
 1@@ -11,7 +11,8 @@
 2 
 3 #include "snac.h"
 4 
 5-xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
 6+xs_dict *http_signed_request_raw(const char *keyid, const char *seckey,
 7+                            const char *method, const char *url,
 8                             xs_dict *headers,
 9                             const char *body, int b_size,
10                             int *status, xs_str **payload, int *p_size,
11@@ -26,9 +27,8 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
12     xs *hdrs = NULL;
13     char *host;
14     char *target;
15-    char *seckey;
16     char *k, *v;
17-    d_char *response;
18+    xs_dict *response;
19 
20     date = xs_str_utctime(0, "%a, %d %b %Y %H:%M:%S GMT");
21 
22@@ -57,8 +57,6 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
23         digest = xs_fmt("SHA-256=%s", s);
24     }
25 
26-    seckey = xs_dict_get(snac->key, "secret");
27-
28     {
29         /* build the string to be signed */
30         xs *s = xs_fmt("(request-target): %s /%s\n"
31@@ -72,11 +70,11 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
32     }
33 
34     /* build now the signature header */
35-    signature = xs_fmt("keyId=\"%s#main-key\","
36+    signature = xs_fmt("keyId=\"%s\","
37                        "algorithm=\"rsa-sha256\","
38                        "headers=\"(request-target) host digest date\","
39                        "signature=\"%s\"",
40-                        snac->actor, s64);
41+                        keyid, s64);
42 
43     /* transfer the original headers */
44     hdrs = xs_dict_new();
45@@ -104,6 +102,24 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
46 }
47 
48 
49+xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
50+                            xs_dict *headers,
51+                            const char *body, int b_size,
52+                            int *status, xs_str **payload, int *p_size,
53+                            int timeout)
54+/* does a signed HTTP request */
55+{
56+    xs *keyid    = xs_fmt("%s#main-key", snac->actor);
57+    char *seckey = xs_dict_get(snac->key, "secret");
58+    xs_dict *response;
59+
60+    response = http_signed_request_raw(keyid, seckey, method, url,
61+                headers, body, b_size, status, payload, p_size, timeout);
62+
63+    return response;
64+}
65+
66+
67 static int _check_signature(snac *snac, char *req, char **err)
68 /* check the signature */
69 {