From: Florian Obser Subject: Re: acme-client(1): port numbers in API urls To: Theo Buehler Cc: tech Date: Mon, 09 Jun 2025 01:54:45 +0200 On 2025-06-08 19:26 +02, Theo Buehler wrote: > On Sun, Jun 08, 2025 at 03:07:43PM +0200, Florian Obser wrote: >> This is needed to test against the "pebble" let's encrypt test server. > > fine with it in principle, but thanks for the review, this is much simpler. I think I addressed all your comments: diff --git http.c http.c index a1b714dfacd..1519f9c61f2 100644 --- http.c +++ http.c @@ -303,26 +303,26 @@ http_open(const struct http *http, int headreq, const void *p, size_t psz) if (headreq) c = asprintf(&req, "HEAD %s HTTP/1.0\r\n" - "Host: %s\r\n" + "Host: %s:%d\r\n" "User-Agent: OpenBSD-acme-client\r\n" "\r\n", - http->path, http->host); + http->path, http->host, http->port); else c = asprintf(&req, "GET %s HTTP/1.0\r\n" - "Host: %s\r\n" + "Host: %s:%d\r\n" "User-Agent: OpenBSD-acme-client\r\n" "\r\n", - http->path, http->host); + http->path, http->host, http->port); } else { c = asprintf(&req, "POST %s HTTP/1.0\r\n" - "Host: %s\r\n" + "Host: %s:%d\r\n" "Content-Length: %zu\r\n" "Content-Type: application/jose+json\r\n" "User-Agent: OpenBSD-acme-client\r\n" "\r\n", - http->path, http->host, psz); + http->path, http->host, http->port, psz); } if (c == -1) { diff --git netproc.c netproc.c index b8171658c73..00f24b530ad 100644 --- netproc.c +++ netproc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -106,6 +107,20 @@ url2host(const char *host, short *port, char **path) return NULL; } + /* extract port */ + if ((ep = strchr(url, ':')) != NULL) { + const char *errstr; + + *ep = '\0'; + *port = strtonum(ep + 1, 1, USHRT_MAX, &errstr); + if (errstr != NULL) { + warn("port is %s: %s", errstr, ep + 1); + free(*path); + *path = NULL; + free(url); + return NULL; + } + } return url; } -- In my defence, I have been left unsupervised.