diff options
author | 2020-09-14 13:49:13 +0000 | |
---|---|---|
committer | 2020-09-14 13:49:13 +0000 | |
commit | ec77e55d0a604fd9fb1cffdfa8e7d8349f2f12e1 (patch) | |
tree | 9ee43d379ec8cf378b578b50cb8eff2c513231b1 | |
parent | Delete some emulator code which has never been used on 64 bit sparc (diff) | |
download | wireguard-openbsd-ec77e55d0a604fd9fb1cffdfa8e7d8349f2f12e1.tar.xz wireguard-openbsd-ec77e55d0a604fd9fb1cffdfa8e7d8349f2f12e1.zip |
Report what's wrong when account creation fails instead of a generic
http error.
OK beck
-rw-r--r-- | usr.sbin/acme-client/extern.h | 3 | ||||
-rw-r--r-- | usr.sbin/acme-client/json.c | 4 | ||||
-rw-r--r-- | usr.sbin/acme-client/netproc.c | 18 |
3 files changed, 19 insertions, 6 deletions
diff --git a/usr.sbin/acme-client/extern.h b/usr.sbin/acme-client/extern.h index 529d3350205..3edf1304582 100644 --- a/usr.sbin/acme-client/extern.h +++ b/usr.sbin/acme-client/extern.h @@ -1,4 +1,4 @@ -/* $Id: extern.h,v 1.18 2020/05/10 17:34:07 florian Exp $ */ +/* $Id: extern.h,v 1.19 2020/09/14 13:49:13 florian Exp $ */ /* * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -259,6 +259,7 @@ int json_parse_order(struct jsmnn *, struct order *); int json_parse_upd_order(struct jsmnn *, struct order *); void json_free_capaths(struct capaths *); int json_parse_capaths(struct jsmnn *, struct capaths *); +char *json_getstr(struct jsmnn *, const char *); char *json_fmt_newcert(const char *); char *json_fmt_chkacc(void); diff --git a/usr.sbin/acme-client/json.c b/usr.sbin/acme-client/json.c index 61d2631359f..13fb81705cc 100644 --- a/usr.sbin/acme-client/json.c +++ b/usr.sbin/acme-client/json.c @@ -1,4 +1,4 @@ -/* $Id: json.c,v 1.19 2020/06/07 13:29:52 florian Exp $ */ +/* $Id: json.c,v 1.20 2020/09/14 13:49:13 florian Exp $ */ /* * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -297,7 +297,7 @@ json_getobj(struct jsmnn *n, const char *name) * that it's the correct type. * Returns NULL on failure. */ -static char * +char * json_getstr(struct jsmnn *n, const char *name) { size_t i; diff --git a/usr.sbin/acme-client/netproc.c b/usr.sbin/acme-client/netproc.c index 7b8152196d1..e8ee5adffd7 100644 --- a/usr.sbin/acme-client/netproc.c +++ b/usr.sbin/acme-client/netproc.c @@ -1,4 +1,4 @@ -/* $Id: netproc.c,v 1.26 2020/05/10 17:34:07 florian Exp $ */ +/* $Id: netproc.c,v 1.27 2020/09/14 13:49:13 florian Exp $ */ /* * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -371,15 +371,27 @@ sreq(struct conn *c, const char *addr, int kid, const char *req, char **loc) static int donewacc(struct conn *c, const struct capaths *p) { + struct jsmnn *j = NULL; int rc = 0; - char *req; + char *req, *detail, *error = NULL; long lc; if ((req = json_fmt_newacc()) == NULL) warnx("json_fmt_newacc"); else if ((lc = sreq(c, p->newaccount, 0, req, &c->kid)) < 0) warnx("%s: bad comm", p->newaccount); - else if (lc != 200 && lc != 201) + else if (lc == 400) { + if ((j = json_parse(c->buf.buf, c->buf.sz)) == NULL) + warnx("%s: bad JSON object", p->newaccount); + else { + detail = json_getstr(j, "detail"); + if (detail != NULL && stravis(&error, detail, VIS_SAFE) + != -1) { + warnx("%s", error); + free(error); + } + } + } else if (lc != 200 && lc != 201) warnx("%s: bad HTTP: %ld", p->newaccount, lc); else if (c->buf.buf == NULL || c->buf.sz == 0) warnx("%s: empty response", p->newaccount); |