LetsEncryptTls constructor

LetsEncryptTls({
  1. List<Domain> domains = const [],
  2. DomainPolicy? allowDomain,
  3. String? onDemandEmail,
  4. EmailResolver? onDemandEmailResolver,
  5. required String cacheDir,
  6. bool production = false,
  7. bool autoIssue = true,
  8. Duration renewBefore = const Duration(days: 5),
  9. int challengePort = 80,
  10. int securePort = 443,
})

Creates an ACME provider.

Provide seed domains (provisioned on start), an allowDomain policy for on-demand issuance, or both. On-demand issuance requires a contact email: a fixed onDemandEmail, or an onDemandEmailResolver to resolve it per host (e.g. a per-tenant lookup).

Set autoIssue to false to serve only certificates already cached in cacheDir, never contacting the CA. Use renewBefore to widen the margin in which a certificate is renewed.

Implementation

factory LetsEncryptTls({
  List<Domain> domains = const [],
  DomainPolicy? allowDomain,
  String? onDemandEmail,
  EmailResolver? onDemandEmailResolver,
  required String cacheDir,
  bool production = false,
  bool autoIssue = true,
  Duration renewBefore = const Duration(days: 5),
  int challengePort = 80,
  int securePort = 443,
}) {
  if (domains.isEmpty && allowDomain == null) {
    throw const ValidationException(
      'Provide seed domains and/or an allowDomain policy',
    );
  }
  if (allowDomain != null &&
      (onDemandEmail == null || onDemandEmail.isEmpty) &&
      onDemandEmailResolver == null) {
    throw const ValidationException(
      'onDemandEmail or onDemandEmailResolver is required when '
      'allowDomain is set',
    );
  }
  if (renewBefore <= Duration.zero) {
    throw const ValidationException('renewBefore must be positive');
  }
  final certificates = CertificatesHandlerIO(Directory(cacheDir));
  final letsEncrypt = LetsEncrypt(
    certificates,
    production: production,
    port: challengePort,
    securePort: securePort,
  )..minCertificateValidityTime = renewBefore;
  return LetsEncryptTls._(
    domains,
    cacheDir,
    production,
    securePort,
    allowDomain,
    onDemandEmail,
    onDemandEmailResolver,
    autoIssue,
    renewBefore,
    certificates,
    letsEncrypt,
  );
}