Skip to content

Commit 69d546f

Browse files
author
Stefan Eissing
committed
* making a md_result_t object to carry all interesting information about success and failures of renewals.
1 parent 97b7c04 commit 69d546f

28 files changed

Lines changed: 554 additions & 326 deletions

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515

1616
AC_PREREQ([2.69])
17-
AC_INIT([mod_md], [2.0.1], [stefan.eissing@greenbytes.de])
17+
AC_INIT([mod_md], [2.0.2], [stefan.eissing@greenbytes.de])
1818

1919
LT_PREREQ([2.2.6])
2020
LT_INIT()

mod_md.xcodeproj/project.pbxproj

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
B292B2731F2F7C0000FA0E35 /* test_md_util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = test_md_util.c; sourceTree = "<group>"; };
100100
B298D5C2229BE6FC00245316 /* md_status.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = md_status.h; sourceTree = "<group>"; };
101101
B298D5C3229BE6FC00245316 /* md_status.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = md_status.c; sourceTree = "<group>"; };
102+
B298D5C4229E7BF000245316 /* md_result.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = md_result.h; sourceTree = "<group>"; };
103+
B298D5C5229E7BF000245316 /* md_result.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = md_result.c; sourceTree = "<group>"; };
104+
B298D5CC229E8AA600245316 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
102105
B2A93D122292D7A400BC6339 /* httpd.conf.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = httpd.conf.in; sourceTree = "<group>"; };
103106
B2A93D132297E14600BC6339 /* test_0910_cleanups.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = test_0910_cleanups.py; sourceTree = "<group>"; };
104107
B2B330051F39E1D300579179 /* md_acme_acct.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md_acme_acct.c; sourceTree = "<group>"; };
@@ -310,6 +313,15 @@
310313
path = test_drive;
311314
sourceTree = "<group>";
312315
};
316+
B298D5CB229E8AA600245316 /* mod_md_lib */ = {
317+
isa = PBXGroup;
318+
children = (
319+
B298D5CC229E8AA600245316 /* main.c */,
320+
);
321+
name = mod_md_lib;
322+
path = ../../mod_md/mod_md_lib;
323+
sourceTree = "<group>";
324+
};
313325
B2B81EC81F13830600E35CA3 /* ssl */ = {
314326
isa = PBXGroup;
315327
children = (
@@ -347,6 +359,7 @@
347359
B2D31B061EC33CBE007BECC8 /* src */,
348360
B2D309EF1EC1AD26007BECC8 /* test */,
349361
B2FC60761F59894A005B7D9E /* TODO.md */,
362+
B298D5CB229E8AA600245316 /* mod_md_lib */,
350363
);
351364
path = /Users/sei/projects/mod_cert/mod_cert.xcodeproj;
352365
sourceTree = "<absolute>";
@@ -444,6 +457,8 @@
444457
B240521F1EF9145000E36701 /* md_log.h */,
445458
B24052211EF9145000E36701 /* md_reg.c */,
446459
B24052221EF9145000E36701 /* md_reg.h */,
460+
B298D5C5229E7BF000245316 /* md_result.c */,
461+
B298D5C4229E7BF000245316 /* md_result.h */,
447462
B298D5C3229BE6FC00245316 /* md_status.c */,
448463
B298D5C2229BE6FC00245316 /* md_status.h */,
449464
B2B81EBE1F0F981C00E35CA3 /* md_store_fs.c */,
@@ -593,7 +608,7 @@
593608
buildPhases = (
594609
);
595610
buildToolPath = /usr/bin/make;
596-
buildWorkingDirectory = /Users/sei/projects/mod_md;
611+
buildWorkingDirectory = /Users/sei/projects/mod_md/src;
597612
dependencies = (
598613
);
599614
name = all;
@@ -616,11 +631,11 @@
616631
};
617632
buildConfigurationList = B27BBD231A65757700C58A41 /* Build configuration list for PBXProject "mod_md" */;
618633
compatibilityVersion = "Xcode 3.2";
619-
developmentRegion = English;
634+
developmentRegion = en;
620635
hasScannedForEncodings = 0;
621636
knownRegions = (
622-
English,
623637
en,
638+
Base,
624639
);
625640
mainGroup = B2D3099E1EBA227F007BECC8 /* /Users/sei/projects/mod_cert/mod_cert.xcodeproj */;
626641
productRefGroup = B2D3099E1EBA227F007BECC8 /* /Users/sei/projects/mod_cert/mod_cert.xcodeproj */;

mod_md_lib/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// main.c
3+
// mod_md_lib
4+
//
5+
// Created by Stefan Eissing on 29.05.19.
6+
//
7+
8+
#include <stdio.h>
9+
10+
int main(int argc, const char * argv[]) {
11+
// insert code here...
12+
printf("Hello, World!\n");
13+
return 0;
14+
}

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ A2LIB_OBJECTS = \
4040
md_json.c \
4141
md_jws.c \
4242
md_log.c \
43+
md_result.c \
4344
md_reg.c \
4445
md_status.c \
4546
md_store.c \
@@ -60,6 +61,7 @@ A2LIB_HFILES = \
6061
md_json.h \
6162
md_jws.h \
6263
md_log.h \
64+
md_result.h \
6365
md_reg.h \
6466
md_status.h \
6567
md_store.h \

src/md.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ struct md_t {
119119

120120
#define MD_KEY_ACCOUNT "account"
121121
#define MD_KEY_ACME_TLS_1 "acme-tls/1"
122+
#define MD_KEY_ACTIVITY "activity"
122123
#define MD_KEY_AGREEMENT "agreement"
123124
#define MD_KEY_AUTHORIZATIONS "authorizations"
124125
#define MD_KEY_BITS "bits"
@@ -159,6 +160,7 @@ struct md_t {
159160
#define MD_KEY_ORDERS "orders"
160161
#define MD_KEY_PERMANENT "permanent"
161162
#define MD_KEY_PKEY "privkey"
163+
#define MD_KEY_PROBLEM "problem"
162164
#define MD_KEY_PROTO "proto"
163165
#define MD_KEY_REGISTRATION "registration"
164166
#define MD_KEY_RENEW "renew"
@@ -246,7 +248,7 @@ md_t *md_get_by_dns_overlap(struct apr_array_header_t *mds, const md_t *md);
246248
* Find the managed domain in the list that, for the given md,
247249
* has the same name, or the most number of overlaps in domains
248250
*/
249-
md_t *md_find_closest_match(apr_array_header_t *mds, const md_t *md);
251+
md_t *md_find_closest_match(struct apr_array_header_t *mds, const md_t *md);
250252

251253
/**
252254
* Create and empty md record, structures initialized.

src/md_acme.c

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "md_http.h"
3131
#include "md_log.h"
3232
#include "md_store.h"
33+
#include "md_result.h"
3334
#include "md_util.h"
3435
#include "md_version.h"
3536

@@ -327,24 +328,24 @@ static apr_status_t md_acme_req_send(md_acme_req_t *req)
327328
{
328329
apr_status_t rv;
329330
md_acme_t *acme = req->acme;
330-
const char *body = NULL, *error;
331+
const char *body = NULL;
332+
md_result_t *result;
331333

332334
assert(acme->url);
333335

334336
md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, 0, req->p,
335337
"sending req: %s %s", req->method, req->url);
338+
result = md_result_make(req->p, APR_SUCCESS);
339+
336340
if (strcmp("GET", req->method) && strcmp("HEAD", req->method)) {
337341
if (acme->version == MD_ACME_VERSION_UNKNOWN) {
338-
if (APR_SUCCESS != (rv = md_acme_setup(acme, &error))) {
339-
return rv;
340-
}
342+
rv = md_acme_setup(acme, result);
343+
if (APR_SUCCESS != rv) goto leave;
341344
}
342-
if (!acme->nonce) {
343-
if (APR_SUCCESS != (rv = acme->new_nonce_fn(acme))) {
344-
md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, rv, req->p,
345-
"error retrieving new nonce from ACME server");
346-
return rv;
347-
}
345+
if (!acme->nonce && (APR_SUCCESS != (rv = acme->new_nonce_fn(acme)))) {
346+
md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, rv, req->p,
347+
"error retrieving new nonce from ACME server");
348+
goto leave;
348349
}
349350

350351
apr_table_set(req->prot_hdrs, "nonce", acme->nonce);
@@ -355,51 +356,49 @@ static apr_status_t md_acme_req_send(md_acme_req_t *req)
355356
}
356357

357358
rv = req->on_init? req->on_init(req, req->baton) : APR_SUCCESS;
359+
if (APR_SUCCESS != rv) goto leave;
358360

359-
if ((rv == APR_SUCCESS) && req->req_json) {
361+
if (req->req_json) {
360362
body = md_json_writep(req->req_json, req->p, MD_JSON_FMT_INDENT);
361363
if (!body) {
362-
rv = APR_EINVAL;
364+
rv = APR_EINVAL; goto leave;
363365
}
364366
}
365367

366-
if (rv == APR_SUCCESS) {
367-
if (body && md_log_is_level(req->p, MD_LOG_TRACE2)) {
368-
md_log_perror(MD_LOG_MARK, MD_LOG_TRACE2, 0, req->p,
369-
"req: %s %s, body:\n%s", req->method, req->url, body);
370-
}
371-
else {
372-
md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, 0, req->p,
373-
"req: %s %s", req->method, req->url);
374-
}
375-
376-
if (!strcmp("GET", req->method)) {
377-
rv = md_http_GET(req->acme->http, req->url, NULL, on_response, req);
378-
}
379-
else if (!strcmp("POST", req->method)) {
380-
rv = md_http_POSTd(req->acme->http, req->url, NULL, "application/jose+json",
381-
body, body? strlen(body) : 0, on_response, req);
382-
}
383-
else if (!strcmp("HEAD", req->method)) {
384-
rv = md_http_HEAD(req->acme->http, req->url, NULL, on_response, req);
385-
}
386-
else {
387-
md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, req->p,
388-
"HTTP method %s against: %s", req->method, req->url);
389-
rv = APR_ENOTIMPL;
390-
}
391-
md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, rv, req->p, "req sent");
392-
393-
if (APR_EAGAIN == rv && req->max_retries > 0) {
394-
--req->max_retries;
395-
return md_acme_req_send(req);
396-
}
397-
req = NULL;
368+
if (body && md_log_is_level(req->p, MD_LOG_TRACE2)) {
369+
md_log_perror(MD_LOG_MARK, MD_LOG_TRACE2, 0, req->p,
370+
"req: %s %s, body:\n%s", req->method, req->url, body);
398371
}
399-
400-
if (req) {
401-
md_acme_req_done(req);
372+
else {
373+
md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, 0, req->p,
374+
"req: %s %s", req->method, req->url);
375+
}
376+
377+
if (!strcmp("GET", req->method)) {
378+
rv = md_http_GET(req->acme->http, req->url, NULL, on_response, req);
402379
}
380+
else if (!strcmp("POST", req->method)) {
381+
rv = md_http_POSTd(req->acme->http, req->url, NULL, "application/jose+json",
382+
body, body? strlen(body) : 0, on_response, req);
383+
}
384+
else if (!strcmp("HEAD", req->method)) {
385+
rv = md_http_HEAD(req->acme->http, req->url, NULL, on_response, req);
386+
}
387+
else {
388+
md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, req->p,
389+
"HTTP method %s against: %s", req->method, req->url);
390+
rv = APR_ENOTIMPL;
391+
}
392+
md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, rv, req->p, "req sent");
393+
394+
if (APR_EAGAIN == rv && req->max_retries > 0) {
395+
--req->max_retries;
396+
rv = md_acme_req_send(req);
397+
}
398+
req = NULL;
399+
400+
leave:
401+
if (req) md_acme_req_done(req);
403402
return rv;
404403
}
405404

@@ -599,14 +598,13 @@ apr_status_t md_acme_create(md_acme_t **pacme, apr_pool_t *p, const char *url,
599598
}
600599

601600

602-
apr_status_t md_acme_setup(md_acme_t *acme, const char **perror)
601+
apr_status_t md_acme_setup(md_acme_t *acme, md_result_t *result)
603602
{
604603
apr_status_t rv;
605604
md_json_t *json;
606605
const char *s;
607606

608607
assert(acme->url);
609-
*perror = NULL;
610608
acme->version = MD_ACME_VERSION_UNKNOWN;
611609

612610
if (!acme->http && APR_SUCCESS != (rv = md_http_create(&acme->http, acme->p,
@@ -619,15 +617,15 @@ apr_status_t md_acme_setup(md_acme_t *acme, const char **perror)
619617

620618
rv = md_acme_get_json(&json, acme, acme->url, acme->p);
621619
if (APR_SUCCESS != rv) {
622-
*perror = apr_psprintf(acme->p,
620+
md_result_printf(result, rv,
623621
"Unsuccessful in contacting ACME server at <%s>. If this problem persists, "
624622
"please check your network connectivity from your Apache server to the "
625623
"ACME server. Also, older servers might have trouble verifying the certificates "
626624
"of the ACME server. You can check if you are able to contact it manually via the "
627625
"curl command. Sometimes, the ACME server might be down for maintenance, "
628626
"so failing to contact it is not an immediate problem. Apache will "
629627
"continue retrying this.", acme->url);
630-
md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, 0, acme->p, "%s", *perror);
628+
md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, rv, acme->p, "%s", result->detail);
631629
goto out;
632630
}
633631

@@ -663,11 +661,11 @@ apr_status_t md_acme_setup(md_acme_t *acme, const char **perror)
663661
}
664662

665663
if (MD_ACME_VERSION_UNKNOWN == acme->version) {
666-
*perror = apr_psprintf(acme->p,
664+
md_result_printf(result, APR_EINVAL,
667665
"Unable to understand ACME server response from <%s>. "
668666
"Wrong ACME protocol version or link?", acme->url);
669-
md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, 0, acme->p, "%s", *perror);
670-
rv = APR_EINVAL;
667+
md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, 0, acme->p, "%s", result->detail);
668+
rv = result->status;
671669
}
672670
out:
673671
return rv;

src/md_acme.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct md_acme_acct_t;
2929
struct md_acmev2_acct_t;
3030
struct md_proto_t;
3131
struct md_store_t;
32+
struct md_result_t;
3233

3334
#define MD_PROTO_ACME "ACME"
3435

@@ -147,7 +148,7 @@ apr_status_t md_acme_create(md_acme_t **pacme, apr_pool_t *p, const char *url,
147148
*
148149
* @param acme the ACME server to contact
149150
*/
150-
apr_status_t md_acme_setup(md_acme_t *acme, const char **perror);
151+
apr_status_t md_acme_setup(md_acme_t *acme, struct md_result_t *result);
151152

152153
/**************************************************************************************************/
153154
/* account handling */

0 commit comments

Comments
 (0)