acme_client 1.3.0 copy "acme_client: ^1.3.0" to clipboard
acme_client: ^1.3.0 copied to clipboard

ACME client which allows you to obtain a HTTPS Certificate from any ACME CA such as Lets Encrypt.

example/acme_client_example.dart

import 'dart:convert';
import 'dart:io';

import 'package:acme_client/src/acme_client.dart';
import 'package:acme_client/src/constants.dart';
import 'package:acme_client/src/model/identifiers.dart';
import 'package:acme_client/src/model/order.dart';
import 'package:basic_utils/basic_utils.dart';

void main(List<String> args) async {
  var privateKeyPem =
      '''-----BEGIN RSA PRIVATE KEY----- ... -----END RSA PRIVATE KEY-----''';

  var publicKeyPem =
      '''-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----''';

  var csr =
      '''-----BEGIN CERTIFICATE REQUEST----- ... -----END CERTIFICATE REQUEST-----''';

  var cn = 'foobar.com';

  var client = AcmeClient(
    'https://acme-staging-v02.api.letsencrypt.org',
    privateKeyPem,
    publicKeyPem,
    true,
    ['mailto:jon@doe.com'],
  );
  await client.init();

  var order = Order();
  var identifier = Identifiers(type: 'dns', value: cn);
  order.identifiers = [identifier];
  print('Order certificate for $cn');
  var newOrder = await client.order(order);

  print('Fetch authorization data for order');
  var auth = await client.getAuthorization(newOrder!);
  print('Place the following DNS record in the corresponding zone file:');
  print(DnsUtils.toBind(auth!.first.getDnsDcvData().rRecord));
  print('Press any key if you are ready to trigger the challenge check');
  stdin.readLineSync(encoding: utf8);

  var self = await client.selfDNSTest(auth.first.getDnsDcvData());
  if (!self) {
    print('Selftest failed, no DNS record found');
    exit(0);
  }

  var authValid = await client.validate(auth.first.challenges!
      .firstWhere((element) => element.type == VALIDATION_DNS));

  if (!authValid) {
    print('Authorization failed, exit');
    exit(0);
  }
  print('Authorization successfull, finalize order');
  await Future.delayed(Duration(seconds: 1));
  var ready = await client.isReady(newOrder);
  if (!ready) {
    print('Order is not ready ...');
    exit(0);
  }
  print('Order is ready, finalize order');

  var persistent = await client.finalizeOrder(newOrder, csr);

  var certs = await client.getCertificate(persistent!);
  print(certs);
}
1
likes
140
pub points
7%
popularity

Publisher

unverified uploader

ACME client which allows you to obtain a HTTPS Certificate from any ACME CA such as Lets Encrypt.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

basic_utils, dio, jose, json_annotation

More

Packages that depend on acme_client