getCertificate method
Fetches the certificate with the complete chain from the ACME server.
Implementation
Future<List<String>?> getCertificate(Order order) async {
var jws = await _createJWS(order.certificate!, useKid: true);
var body = json.encode(jws.toJson());
var headers = {'Content-Type': 'application/jose+json'};
try {
var response = await Dio().post(
order.certificate!,
data: body,
options: Options(headers: headers),
);
var certs = <String>[];
var data = response.data as String;
var b = StringBuffer();
for (var line in LineSplitter.split(data)) {
if (line.isEmpty) {
continue;
}
b.write(line);
if (line == X509Utils.END_CERT) {
certs.add(b.toString());
b.clear();
}
}
nonce = response.headers.map[HEADER_REPLAY_NONCE]!.first;
return certs;
} on DioException catch (e) {
print(e.response!.data!.toString());
}
return null;
}