summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorGravatar default2023-02-02 04:05:50 +0100
committerGravatar default2023-02-02 04:05:50 +0100
commitadff9c55e2689ef11a611d3eaf288f864a619b3c (patch)
treeec29e5b0cc08938e69afa279d7ff80b7e2ead0e4 /http.c
parentMinor header tweaks. (diff)
downloadpenes-snac2-adff9c55e2689ef11a611d3eaf288f864a619b3c.tar.gz
penes-snac2-adff9c55e2689ef11a611d3eaf288f864a619b3c.tar.xz
penes-snac2-adff9c55e2689ef11a611d3eaf288f864a619b3c.zip
New function http_signed_request_raw().
Diffstat (limited to 'http.c')
-rw-r--r--http.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/http.c b/http.c
index 1948f2b..c15280e 100644
--- a/http.c
+++ b/http.c
@@ -11,7 +11,8 @@
11 11
12#include "snac.h" 12#include "snac.h"
13 13
14xs_dict *http_signed_request(snac *snac, const char *method, const char *url, 14xs_dict *http_signed_request_raw(const char *keyid, const char *seckey,
15 const char *method, const char *url,
15 xs_dict *headers, 16 xs_dict *headers,
16 const char *body, int b_size, 17 const char *body, int b_size,
17 int *status, xs_str **payload, int *p_size, 18 int *status, xs_str **payload, int *p_size,
@@ -26,9 +27,8 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
26 xs *hdrs = NULL; 27 xs *hdrs = NULL;
27 char *host; 28 char *host;
28 char *target; 29 char *target;
29 char *seckey;
30 char *k, *v; 30 char *k, *v;
31 d_char *response; 31 xs_dict *response;
32 32
33 date = xs_str_utctime(0, "%a, %d %b %Y %H:%M:%S GMT"); 33 date = xs_str_utctime(0, "%a, %d %b %Y %H:%M:%S GMT");
34 34
@@ -57,8 +57,6 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
57 digest = xs_fmt("SHA-256=%s", s); 57 digest = xs_fmt("SHA-256=%s", s);
58 } 58 }
59 59
60 seckey = xs_dict_get(snac->key, "secret");
61
62 { 60 {
63 /* build the string to be signed */ 61 /* build the string to be signed */
64 xs *s = xs_fmt("(request-target): %s /%s\n" 62 xs *s = xs_fmt("(request-target): %s /%s\n"
@@ -72,11 +70,11 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
72 } 70 }
73 71
74 /* build now the signature header */ 72 /* build now the signature header */
75 signature = xs_fmt("keyId=\"%s#main-key\"," 73 signature = xs_fmt("keyId=\"%s\","
76 "algorithm=\"rsa-sha256\"," 74 "algorithm=\"rsa-sha256\","
77 "headers=\"(request-target) host digest date\"," 75 "headers=\"(request-target) host digest date\","
78 "signature=\"%s\"", 76 "signature=\"%s\"",
79 snac->actor, s64); 77 keyid, s64);
80 78
81 /* transfer the original headers */ 79 /* transfer the original headers */
82 hdrs = xs_dict_new(); 80 hdrs = xs_dict_new();
@@ -104,6 +102,24 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
104} 102}
105 103
106 104
105xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
106 xs_dict *headers,
107 const char *body, int b_size,
108 int *status, xs_str **payload, int *p_size,
109 int timeout)
110/* does a signed HTTP request */
111{
112 xs *keyid = xs_fmt("%s#main-key", snac->actor);
113 char *seckey = xs_dict_get(snac->key, "secret");
114 xs_dict *response;
115
116 response = http_signed_request_raw(keyid, seckey, method, url,
117 headers, body, b_size, status, payload, p_size, timeout);
118
119 return response;
120}
121
122
107static int _check_signature(snac *snac, char *req, char **err) 123static int _check_signature(snac *snac, char *req, char **err)
108/* check the signature */ 124/* check the signature */
109{ 125{