finalizeOrder method
Will finalize the order by sending a POST request to the order's finalize url including the
given csr
in the payload. The given csr
will be transformed in the necessary base64url encoding.
RFC : datatracker.ietf.org/doc/html/rfc8555#page-47
When attempting to finalize the order the CA may not immediately return
the certificate. In this case we will wait 4 seconds and try again
to fetch the certificate (url). This usually works on the first try but
we allow you to set the retry limit via retries
which defaults to 5.
Implementation
Future<Order?> finalizeOrder(Order order, String csr,
{int retries = 5}) async {
var transformedCsr = AcmeUtils.formatCsrBase64Url(csr);
try {
Order? persistent;
var firstpass = true;
Results results;
do {
if (firstpass) {
results = await _finalizeOrder(order, transformedCsr);
} else {
results = await _retry(order, transformedCsr);
}
firstpass = false;
retries--;
/// the CA was stilling processing the order
} while (results.response.data['status'] == 'processing' && retries > 0);
if (results.response.data['status'] != 'valid') {
persistent = null;
} else {
persistent = results.order;
}
return persistent;
} on DioException catch (e) {
print(e.response!.data!.toString());
}
return null;
}