summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorGravatar default2023-01-08 10:19:25 +0100
committerGravatar default2023-01-08 10:19:25 +0100
commit54d1013ea9c5eb27c2d6aa6be4fd6d63a1d7ba6e (patch)
tree72c4d14531c2a69a472c72a863f229722fee7cb1 /http.c
parentDon't use goto in check_signature(). (diff)
downloadsnac2-54d1013ea9c5eb27c2d6aa6be4fd6d63a1d7ba6e.tar.gz
snac2-54d1013ea9c5eb27c2d6aa6be4fd6d63a1d7ba6e.tar.xz
snac2-54d1013ea9c5eb27c2d6aa6be4fd6d63a1d7ba6e.zip
More work in check_signature() error archiving.
Diffstat (limited to '')
-rw-r--r--http.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/http.c b/http.c
index 2e721f1..97154d3 100644
--- a/http.c
+++ b/http.c
@@ -103,7 +103,7 @@ d_char *http_signed_request(snac *snac, char *method, char *url,
103} 103}
104 104
105 105
106static int _check_signature(snac *snac, char *req) 106static int _check_signature(snac *snac, char *req, char **err)
107/* check the signature */ 107/* check the signature */
108{ 108{
109 char *sig_hdr = xs_dict_get(req, "signature"); 109 char *sig_hdr = xs_dict_get(req, "signature");
@@ -140,7 +140,7 @@ static int _check_signature(snac *snac, char *req)
140 } 140 }
141 141
142 if (keyId == NULL || headers == NULL || signature == NULL) { 142 if (keyId == NULL || headers == NULL || signature == NULL) {
143 snac_debug(snac, 0, xs_fmt("check_signature bad signature header")); 143 *err = xs_fmt("bad signature header");
144 return 0; 144 return 0;
145 } 145 }
146 146
@@ -151,13 +151,13 @@ static int _check_signature(snac *snac, char *req)
151 /* the actor must already be here */ 151 /* the actor must already be here */
152 xs *actor = NULL; 152 xs *actor = NULL;
153 if (!valid_status(actor_get(snac, keyId, &actor))) { 153 if (!valid_status(actor_get(snac, keyId, &actor))) {
154 snac_debug(snac, 0, xs_fmt("check_signature unknown actor %s", keyId)); 154 *err = xs_fmt("unknown actor %s", keyId);
155 return 0; 155 return 0;
156 } 156 }
157 157
158 if ((p = xs_dict_get(actor, "publicKey")) == NULL || 158 if ((p = xs_dict_get(actor, "publicKey")) == NULL ||
159 ((pubkey = xs_dict_get(p, "publicKeyPem")) == NULL)) { 159 ((pubkey = xs_dict_get(p, "publicKeyPem")) == NULL)) {
160 snac_debug(snac, 0, xs_fmt("check_signature cannot get pubkey from %s", keyId)); 160 *err = xs_fmt("cannot get pubkey from %s", keyId);
161 return 0; 161 return 0;
162 } 162 }
163 163
@@ -190,9 +190,7 @@ static int _check_signature(snac *snac, char *req)
190 else { 190 else {
191 /* add the header */ 191 /* add the header */
192 if ((hc = xs_dict_get(req, v)) == NULL) { 192 if ((hc = xs_dict_get(req, v)) == NULL) {
193 snac_debug(snac, 0, 193 *err = xs_fmt("cannot find header '%s'", v);
194 xs_fmt("check_signature cannot find header %s", v));
195
196 return 0; 194 return 0;
197 } 195 }
198 196
@@ -204,7 +202,7 @@ static int _check_signature(snac *snac, char *req)
204 } 202 }
205 203
206 if (xs_evp_verify(pubkey, sig_str, strlen(sig_str), signature) != 1) { 204 if (xs_evp_verify(pubkey, sig_str, strlen(sig_str), signature) != 1) {
207 snac_debug(snac, 0, xs_fmt("check_signature rsa verify error %s", keyId)); 205 *err = xs_fmt("RSA verify error %s", keyId);
208 return 0; 206 return 0;
209 } 207 }
210 208
@@ -216,13 +214,16 @@ int check_signature(snac *snac, char *req)
216/* checks the signature and archives the error */ 214/* checks the signature and archives the error */
217{ 215{
218 int ret; 216 int ret;
217 xs *err = NULL;
219 218
220 if ((ret = _check_signature(snac, req)) == 0) { 219 if ((ret = _check_signature(snac, req, &err)) == 0) {
221 xs *ntid = tid(0); 220 xs *ntid = tid(0);
222 xs *fn = xs_fmt("%s/error/check_signature_%s.json", srv_basedir, ntid); 221 xs *fn = xs_fmt("%s/error/check_signature_%s", srv_basedir, ntid);
223 FILE *f; 222 FILE *f;
224 223
225 if ((f = fopen(fn, "w")) != NULL) { 224 if ((f = fopen(fn, "w")) != NULL) {
225 fprintf(f, "Error: %s\nRequest headers:\n", err);
226
226 xs *j = xs_json_dumps_pp(req, 4); 227 xs *j = xs_json_dumps_pp(req, 4);
227 228
228 fwrite(j, strlen(j), 1, f); 229 fwrite(j, strlen(j), 1, f);