@@ -468,6 +468,7 @@ void acme_config_init(ACME_Config *config,
468468 config -> dont_verify_cert = false;
469469 config -> trace_bytes = false;
470470 config -> logger = NULL ;
471+ config -> force_renewal_period = -1 ;
471472
472473 config -> email = email ;
473474 config -> country = country ;
@@ -584,6 +585,7 @@ int acme_init(ACME *acme, ACME_Config *config)
584585 acme -> dont_verify_cert = config -> dont_verify_cert ;
585586 acme -> trace_bytes = config -> trace_bytes ;
586587 acme -> logger = config -> logger ;
588+ acme -> force_renewal_period = config -> force_renewal_period ;
587589
588590 acme -> agree_tos = config -> agree_tos ;
589591
@@ -638,14 +640,29 @@ int acme_init(ACME *acme, ACME_Config *config)
638640 log (acme -> logger , S ("Certificate file '{}' not found. Continuing without a certificate.\n" ), V (config -> certificate_file ));
639641 } else {
640642
643+ Time current_time = get_current_time ();
644+ if (current_time == INVALID_TIME ) {
645+ log (acme -> logger , S ("Couldn't read the time.\n" ), V ());
646+ acme_free (acme );
647+ return -1 ;
648+ }
649+
641650 Time certificate_expiry ;
642651 ret = get_chain_expiry (certificate , & certificate_expiry );
643652 if (ret < 0 ) {
644653 log (acme -> logger , S ("Couldn't determine expiry of certificate file '{}'.\n" ), V (config -> certificate_file ));
645654 acme_free (acme );
646655 return -1 ;
647656 }
648- log (acme -> logger , S ("Certificate will expire at {} UNIX time\n" ), V (certificate_expiry / 1000 ));
657+ log (acme -> logger , S ("Certificate will expire in {} seconds\n" ), V ((certificate_expiry - current_time ) / 1000 ));
658+
659+ if (acme -> force_renewal_period > -1 ) {
660+ Time expiry_limit = current_time + acme -> force_renewal_period ;
661+ if (expiry_limit < certificate_expiry ) {
662+ certificate_expiry = expiry_limit ;
663+ log (acme -> logger , S ("Forcing certificate renewal in {} seconds\n" ), V (acme -> force_renewal_period / 1000 ));
664+ }
665+ }
649666
650667 string certificate_key ;
651668 ret = file_read_all (acme -> certificate_key_file , & certificate_key );
@@ -937,7 +954,7 @@ static int complete_account_creation_request(ACME *acme, CHTTP_Response *respons
937954 log (acme -> logger , S ("ACME account was created. The account key was stored in '{}'\n" ), V (acme -> account_key_file ));
938955 } else {
939956 ASSERT (response -> status == 200 );
940- log (acme -> logger , S ("Existing ACME account found" ), V ());
957+ log (acme -> logger , S ("Existing ACME account found\n " ), V ());
941958 }
942959
943960 BIO_free (bio );
@@ -1464,13 +1481,27 @@ static int complete_certificate_download_request(ACME *acme, CHTTP_Response *res
14641481 ASSERT (certificate .ptr != NULL );
14651482 ASSERT (certificate .len > 0 );
14661483
1484+ Time current_time = get_current_time ();
1485+ if (current_time == INVALID_TIME ) {
1486+ log (acme -> logger , S ("Couldn't read the time.\n" ), V ());
1487+ return -1 ;
1488+ }
1489+
14671490 Time certificate_expiry ;
14681491 int ret = get_chain_expiry (certificate , & certificate_expiry );
14691492 if (ret < 0 ) {
14701493 log (acme -> logger , S ("Couldn't determine expiry of the newly issued certificate.\n" ), V ());
14711494 return -1 ;
14721495 }
1473- log (acme -> logger , S ("Certificate will expire {} UNIX time\n" ), V (certificate_expiry / 1000 ));
1496+ log (acme -> logger , S ("Certificate will expire in {} seconds\n" ), V ((certificate_expiry - current_time ) / 1000 ));
1497+
1498+ if (acme -> force_renewal_period > -1 ) {
1499+ Time expiry_limit = current_time + acme -> force_renewal_period ;
1500+ if (expiry_limit < certificate_expiry ) {
1501+ certificate_expiry = expiry_limit ;
1502+ log (acme -> logger , S ("Forcing certificate renewal in {} seconds\n" ), V (acme -> force_renewal_period / 1000 ));
1503+ }
1504+ }
14741505
14751506 acme -> certificate .ptr = malloc (certificate .len ); // TODO: allocstr
14761507 if (acme -> certificate .ptr == NULL ) {
@@ -1611,6 +1642,9 @@ void acme_process_timeout(ACME *acme, CHTTP_Client *client)
16111642 break ;
16121643 case ACME_STATE_WAIT :
16131644 {
1645+ if (acme -> certificate_expiry > current_time )
1646+ break ;
1647+
16141648 // Free previous order data before starting a new certificate order
16151649 reset_order_data (acme );
16161650 if (send_order_creation_request (acme , acme -> client ) < 0 ) {
0 commit comments