FairSSL Edition of Simple-ACME
==============================

This is a pre-configured build of Simple-ACME distributed by FairSSL
(https://www.fairssl.dk). It is identical to the official release with
the following modifications:

1. settings_default.json - merged overrides
   - ACME directory pointed to FairSSL: https://fairssl.dk/acme
   - Max domains raised to 250
   - Scheduled task set to start at 01:00 server time with a random delay
     of up to 4 hours, so a renewal runs between 01:00 and 05:00 (see
     "When the renewal runs" below)
   - RenewalDays set to 365 (ARI handles actual renewal timing)
   - RenewalMinimumValidDays set to 7 as the fallback renewal window
   - Notification script set to Scripts\FairSSLResultNotification.ps1
     (Notification.Script, also run after a successful issuance or renewal)

2. Scripts\FairSSLResultNotification.ps1 - added
   PowerShell script that simple-acme runs as its notification script
   (the Notification.Script setting) after every run has been saved: the
   first issuance, each renewal and a failed renewal. It reports the result
   of that run back to your FairSSL control panel so you can monitor every
   certificate and server in one place and be alerted when a renewal or an
   installation fails. An installation step that fails, for example an
   installation script that ends with exit 1, is reported as an
   installation failure with simple-acme's first error message. For the
   Deploy-*.ps1 scripts that install through a background worker (below),
   a successful run is reported without an installation result; the
   worker reports each installation attempt itself.

   It sends ONLY the following to https://fairssl.dk over HTTPS:
     - kid                your ACME account URL at FairSSL
     - renewal_id         the Simple-ACME renewal identifier (a local GUID)
     - domain             the certificate's primary domain name
     - thumbprint         the certificate's public SHA1 fingerprint
     - status             the overall renewal result
     - install_status     whether the certificate installed successfully
     - install_error_code / install_error_string  a short code and message on failure
     - error_messages     up to ten of simple-acme's error messages from the run
     - event_type         simple-acme's event type for the run
     - friendly_name      the renewal's friendly name
     - expiry_at          the certificate's expiry date
     - machine_name       this computer's name
     - script_version / client_version / simple_acme_version
     - installations      for each installation step of the renewal: the
                          plugin (script, iis, none ...), and for an
                          installation script its file name, the SHA-256
                          of the script file as it lies on this server,
                          and the $ScriptVersion written in it, if any
     - stores             the store plugins of the renewal (pemfiles,
                          certificatestore ...)
     - os_version         the Windows version, for example
                          Windows Server 2019 Standard (10.0.17763.6893)
     - powershell_version the PowerShell version that runs the script
     - key_type           the certificate's key type and size
                          (RSA 2048, ECDSA P-256 ...)
     - certificate_sha256 the certificate's public SHA-256 fingerprint
     - the sending server's IP address (as seen by our web server)

   With the script name, its SHA-256 and its version, your control panel
   shows whether an installation script is the newest FairSSL has
   released, an older released version, or a file FairSSL has not
   released (changed, or your own), and FairSSL can tell you when a
   newer script is in the download. The Deploy-*.ps1 scripts that install
   through a background worker send the same fields about themselves with
   each installation attempt, and with them the model and version the
   appliance states when the script reads them (device_model and
   device_version, for example PA-VM and PAN-OS 11.2.16-h2).

   It NEVER sends private keys, certificate contents, CSRs, credentials,
   the contents of a script, script parameters, the folder a script lies
   in or the simple-acme log. It always ends with exit
   code 0 after one attempt, so it can never fail a renewal or hold it up
   longer than that attempt, and
   it writes one line to the simple-acme log saying whether FairSSL received
   the report. A report FairSSL has not confirmed waits in the
   FairSSL-pending folder beside simple-acme's renewal files and is sent
   again in the background after 1, 5 and 15 minutes and then every hour
   until FairSSL confirms it; after a restart the next renewal simple-acme
   processes continues.
   Where it sends is the line $DefaultReportUrl near the top of the
   script; in this download it holds FairSSL's address. The Deploy-*.ps1
   scripts that report have the same line. An empty address there, or
   -ReportUrl '' in a command, means the script sends nothing.
   To turn the notification script off altogether, set "Path" under
   "Notification" > "Script" to "":
     "Notification": { "Script": { "Path": "" } }
   Do it in settings_default.json before the first run of wacs.exe. Once
   wacs.exe has run, settings.json exists in the same folder: do it there.
   A report that is already waiting in FairSSL-pending is still sent.

3. Additional Scripts\*.ps1 installation scripts - added
   Optional installation scripts used by FairSSL ACME Easy Guides.
   ImportExchange.v3.ps1 enables the certificate on Microsoft Exchange. It
   loads the Exchange management tools locally (no WinRM remoting), so it
   works on any Exchange server including non-domain-joined Edge Transport
   servers, auto-detects the server role and version, and enables only the
   supported services. Add -Hybrid for Office 365 hybrid deployments. It
   keeps the internal transport certificate Exchange had before, and it
   exits with an error when a service or the hybrid configuration could not
   be set.
   ImportADFS-WAP.v1.ps1 enables the certificate on Microsoft AD FS or
   Microsoft Web Application Proxy (WAP). The two roles sit behind the same
   federation hostname and are easy to mix up, so the script detects which
   role service this server runs (adfssrv or appproxysvc), states the detected
   role in the log, and applies the matching installation.
   On AD FS it grants the AD FS service account read access to the private key
   and assigns the SSL + Service-Communications certificate. It is farm-aware:
   on a secondary node it skips primary-only changes, and it tolerates the
   farm-wide SSL binding not being ready yet so the last node to renew applies
   it (Windows Server 2016 and later; on 2012 R2 each node sets its own). On WAP it reads the names in the certificate and binds it to the AD FS
   federation proxy and/or any published application whose external address
   the certificate covers; run it on each WAP server (use the same key and CSR
   so every server presents the identical certificate). Both role paths load
   their PowerShell module locally (no WinRM remoting), so they work on
   domain-joined or workgroup DMZ servers.
   ImportADFS.v2.ps1 and ImportWAP.v1.ps1 remain as compatibility wrappers for
   renewals created with earlier bundles; they forward to ImportADFS-WAP.v1.ps1.
   ImportDynamicsCRM.v1.ps1 installs the certificate on Dynamics CRM 2016 /
   Dynamics 365 CE 9.x on-premises with claims-based authentication and IFD:
   key access for CRMAppPool, ClaimsSettings when the subject changes (run
   that first renewal as a CRM Deployment Administrator), the CRM website's
   https bindings, iisreset, and the CRM relying party trusts when AD FS runs
   on the same server. If a step fails it puts CRM back on the previous
   certificate.
   ImportPRTG.ps1 deploys PEM files to PRTG Network Monitor.
   ImportSQLFairSSL.ps1 sets the certificate on one SQL Server instance,
   grants the instance's service account read access to the private key,
   restarts that instance only, and reports success when SQL Server has
   loaded the certificate. On a server with several instances, name the
   instance as the second script parameter.
   ImportCustomWindows.ps1 is a template for Windows services that need
   certificate store, PFX, and PEM outputs. Deploy-FortiGate.ps1,
   Deploy-FortiMail.ps1, Deploy-FortiManager.ps1, Deploy-FortiWeb.ps1,
   Deploy-FortiADC.ps1, Deploy-FortiNAC.ps1, Deploy-PaloAlto.ps1 and
   Install-NetScalerCert.ps1 deploy PEM certificates to supported
   appliances.
   Deploy-FortiGate.ps1 and Deploy-FortiMail.ps1 hand the installation to
   a scheduled task, "FairSSL FortiGate <id>" or "FairSSL FortiMail <id>",
   that runs as SYSTEM without a time limit and retries until the
   appliance serves the certificate. Each keeps its files, including the
   appliance password until it is done, in C:\ProgramData\FairSSL\FortiGate
   or C:\ProgramData\FairSSL\FortiMail, readable only by SYSTEM and
   Administrators, and reports each attempt to FairSSL with the fields
   listed under 2, plus its own log of that attempt (never the password,
   a key or a certificate). Deploy-FortiGate.ps1 reports an attempt as
   failed only when the certificate is still not installed 15 minutes
   after the first failed attempt; until then it reports that it is still
   trying, which sends no mail. A change the FortiGate accepted and does
   not show yet is never a failure, and NO_ROLE is reported at once. It finds the VDOMs of a FortiGate with
   multiple VDOMs itself and takes no VDOM parameter.

   Deploy-PaloAlto.ps1 works the same way for Palo Alto firewalls and
   Panorama over the PAN-OS XML API: its task is "FairSSL PaloAlto <id>",
   its files are in C:\ProgramData\FairSSL\PaloAlto, and the API key
   comes from simple-acme's vault. Run it once with -NewApiKey to create
   the key and store it there.

   Deploy-FortiWeb.ps1 now uses the same hook and SYSTEM worker shape over
   REST v2.0, measured on FortiWeb-VM 8.0.8. Use -Username, -ServerPolicyName
   and -Port (default 443); store the password in simple-acme's vault as
   fortiweb (wacs.exe: O, S, A). The script reads the vault itself (see
   "Device secrets" below), so the password is never on a command line.
   The worker protects its password with DPAPI LocalMachine and restricts
   C:\ProgramData\FairSSL\FortiWeb to SYSTEM and Administrators.
   It pins management HTTPS before sending credentials; an unexpected change
   refuses MGMT_CERT_CHANGED. -ManagementCertSha256 can pin it up front.
   Leaf/key and intermediates are imported separately; existing leaf and CA
   objects are reused, including device-assigned Inter_Cert_<n> names.
   An own fssl-cag-<12 hex> intermediate group is selected on the policy.
   -SniDomain copies the policy's SNI group and changes only its plain member.
   All writes are read back. Service TLS at -ServiceHost/-ServicePort (or
   the policy VIP) is advisory: warnings do not override API confirmation.
   It retains new and previous objects and deletes only older own unused
   objects in its history. Retries run after 1, 2, 5, 10, 30 minutes then
   hourly forever, with boot resume and a durable report outbox.
   Calls with only the old parameters retain CredentialManager, port 8443,
   leaf-only import and optional -IntermediateGroupName; they recommend
   the new FortiWeb (Windows Agent) guide. No secrets or PEM are reported.

   Deploy-FortiADC.ps1 uses the same SYSTEM worker over pinned management
   HTTPS, default port 443. Give -Vdom and -VirtualServerName; store the
   REST API administrator key through wacs.exe's hidden O, S, A prompt as
   fortiadc (read as under "Device secrets"). The key travels only in the
   APITOKEN header, never in a URL or on a command line.
   DPAPI LocalMachine protects the job secret under
   C:\ProgramData\FairSSL\FortiADC (SYSTEM and Administrators only).
   The first leaf SHA-256 is pinned per management host/port; an unexpected
   change refuses MGMT_CERT_CHANGED. -ManagementCertSha256 pins up front.
   The FortiADC REST contract matches fortiadc-api 2.0.5: /api/<resource>,
   ?vdom= when VDOMs are on, payload 0 for writes. It imports leaf/key and
   intermediates separately, reuses held certificates under any name,
   resolves duplicate CA replies by read-back, and omits roots. An fssl-
   local group copies all original members with only the selected member's
   leaf and intermediate_cag changed, then the whole client SSL profile is
   read, changed and PUT back pointing at the copy. Other virtual servers
   sharing that profile change too. -ReplaceCertificate selects a member
   when neither an earlier own, default nor only member decides it.
   Every write is read back. VIP TLS (optional -ServiceHost/-ServicePort
   and -ServiceSni) is advisory: the device API decides success.
   Current and previous groups stay. Cleanup deletes only unused fssl-
   objects recorded in this job's history, never a CA object. Retries run
   after 1, 2, 5, 10, 30 minutes then hourly forever, with boot resume and a
   durable report outbox. Reports include no API key, secret, key or PEM.
   Requires PowerShell 3.0+ and .NET Framework 4.5+.

   Deploy-FortiNAC.ps1 follows the sslbrain fortinac 2.0.5 contract for
   FortiNAC 9.x / FortiNAC-F 7.x, REST API v2 over HTTPS on port 8443.
   Store the API token through wacs.exe's hidden O, S, A prompt as fortinac
   (read as under "Device secrets"); use -Target portal (or tomcat, agent,
   radsec, radius) and -RenewalId '{RenewalId}'. Uploads the RSA
   leaf/key and intermediate chain together, then restarts only that target
   if required. Existing certificates/intermediates are no error. Every
   write is read back; served TLS is advisory and the API decides success.
   Management leaf SHA-256 is pinned before sending the token; an unexpected
   change refuses MGMT_CERT_CHANGED. -ManagementCertSha256 pins up front.
   For tomcat (Admin UI), the new leaf is accepted before upload and kept.
   The SYSTEM task has no time limit, boot resume, DPAPI LocalMachine job
   secrets under C:\ProgramData\FairSSL\FortiNAC (SYSTEM/Administrators
   only), retries after 1, 2, 5, 10, 30 minutes then hourly forever, and a
   durable report outbox. No secret, key or PEM is reported or logged.
   PowerShell 3.0+ / .NET Framework 4.5+.

   Deploy-FortiManager.ps1 uses the same hook and SYSTEM worker shape over
   HTTPS JSON-RPC with a REST API administrator's Bearer API key (7.2.2+).
   Store the key in simple-acme's vault as fortimanager (wacs.exe: O, S, A);
   the script reads the vault itself (see "Device secrets" below). Jobs and DPAPI LocalMachine secrets are kept under
   C:\ProgramData\FairSSL\FortiManager (SYSTEM and Administrators only).
   The first management leaf SHA-256 is pinned per host and port; an
   unexpected change is refused as MGMT_CERT_CHANGED. -ManagementCertSha256
   may pin it before first contact. Only its own verified switch updates
   the pin. To accept an intentional external change, verify it and remove
   that host's .pins.json file. Objects are fssl-<id6>-<fp12>; the same leaf
   is reused. It sets admin_server_cert, reads back and checks HTTPS for
   the new leaf, and attempts rollback if HTTPS stops. New and previous
   objects stay; only older own objects recorded by the job are deleted.
   Intermediates are reused or added in FortiManager's CA store, from which
   it serves the chain; CA objects are never deleted. On 8.0.2 switching
   restarted HTTPS and dropped the update response. A leaf-only handshake
   warns without failing the deployment.
   Retries: 1, 2, 5, 10, 30 minutes then hourly forever, also after reboot;
   rollback waits a day, a new leaf starts at once. Reports include the
   worker's attempt log and metadata, never API keys or PEM material;
   unconfirmed reports remain in the outbox. PowerShell 3.0+ / .NET 4.5+.

   Device secrets (Deploy-FortiGate, -FortiWeb, -FortiManager, -FortiADC,
   -FortiNAC):
   simple-acme puts a {vault://json/<name>} script parameter into
   powershell.exe's command line, where any local process can read it.
   These scripts therefore take only the secret's name (-SecretName, with
   the device's name as default) and read simple-acme's vault themselves:
   the secrets.json files under its configuration folder (and
   Secrets.Json.FilePath), DPAPI LocalMachine values included. One name
   stored with the same value for several ACME servers is fine; different
   values are taken from the vault next to the renewal, or from -VaultFile.
   Each also takes the secret itself as a parameter instead (-Password
   for FortiGate and FortiWeb, -ApiKey for FortiManager and FortiADC,
   -ApiToken for FortiNAC). simple-acme then keeps it in the renewal's
   settings and writes it in its log, and it is on powershell.exe's
   command line at every renewal. A {vault://...} reference in that
   parameter which simple-acme did not replace (no secret of that name
   is stored for the ACME server) stops the script at once with a
   message saying so.
   Deploy-FortiGate.ps1 without -Password and without a vault secret of
   that name reads Windows Credential Manager (-CredentialTarget), as
   installations made from earlier guides do.
   Install-NetScalerCert.ps1 takes the NetScaler login as -UserName and
   -Password: '{vault://json/netscaler}' for a password stored in
   simple-acme's vault (wacs.exe --vaultstore), or the password itself.
   Either way simple-acme puts the password on powershell.exe's command
   line while the script runs.
   Without -Password it reads Windows Credential Manager through
   -CredentialTarget, as installations made from earlier guides do.
   Deploy-FortiMail.ps1 takes -Password, '{vault://json/fortimail}' in
   its guide, which simple-acme puts on powershell.exe's command line
   while the script runs.
   The Fortinet Windows guides also store the ACME account's EAB key in
   the vault, as fairssl-eab; wacs.exe reads it itself through
   --eab-key "vault://json/fairssl-eab", so it is not on a command line.

   Scripts\Modules\Posh-SSH - added
   Posh-SSH 4.0.0, unchanged from the PowerShell Gallery; its source is at
   https://github.com/darkoperator/Posh-SSH and its licence in licenses\.
   Deploy-FortiGate.ps1 and Deploy-FortiMail.ps1 load it from this folder,
   so nothing has to be installed.

   FairSSL's own scripts are free to use under the Apache License 2.0,
   with any ACME service. Each is also published as a single file, with
   its guide, at https://sslbrain.com/free-acme-scripts/ (the address at
   the top of the script).

4. Scripts\*.ps1 - upstream reference scripts - added
   As of Simple-ACME v2.4.0 the reference scripts are no longer shipped
   inside the program download. To keep them available we fetch the
   Installation scripts from the official reference-scripts project
   (https://github.com/simple-acme/reference-scripts) and place them in
   Scripts\, the folder Simple-ACME runs scripts from. These are upstream
   community scripts: review and test them before use. The FairSSL scripts
   (above) are added last and always take precedence on any name clash.

5. Certificates\ folder - added
   An empty folder created next to Scripts so the installation scripts have
   a predictable location to read and write certificate files.

6. NOTICE and licenses\ - added
   Who made what in this download and under which licence: FairSSL's
   scripts and simple-acme (Apache License 2.0), Posh-SSH (BSD 3-Clause),
   SSH.NET and BouncyCastle (MIT).

7. fairssl-readme.txt - this file

When the renewal runs
---------------------
simple-acme creates one Windows scheduled task that checks every day
whether a certificate is due, and requests and installs it in the same
run. The task starts at ScheduledTask.StartBoundary (01:00:00, server
time) plus a random delay of up to ScheduledTask.RandomDelay (04:00:00),
so the run starts between 01:00 and 05:00. A server that was off at that
time runs the task when it is started again. Some installations restart
a service or disconnect users for a moment. To choose another time,
change these two values in the "ScheduledTask" section
(hours:minutes:seconds); the example starts the run between 03:30 and
04:00, and "RandomDelay": "00:00:00" starts it at StartBoundary exactly:

  "ScheduledTask": {
    "StartBoundary": "03:30:00",
    "RandomDelay": "00:30:00"
  }

Before the first run of wacs.exe (the folder has no settings.json yet):
  Edit them in settings_default.json. The first run copies
  settings_default.json to settings.json and creates the task from it.
  After that, settings_default.json is not read again.

After the first run (settings.json exists; storing a secret with wacs.exe
counts as a run):
  1. Edit them in settings.json, in the same folder as wacs.exe.
  2. Open PowerShell as administrator in that folder and run once:
       .\wacs.exe --setuptaskscheduler
     It deletes the task and creates it again with the new values.

Do not change the task in Task Scheduler itself: simple-acme creates it
from settings.json, and a change made there is lost when simple-acme
creates the task again.

Servers that share one key and CSR and so present the same certificate
(an AD FS farm, WAP servers behind a load balancer): set RandomDelay to
00:00:00 on every server, and StartBoundary to a time you choose on one
server and exactly one minute later on all the others, for example
02:17:00 and 02:18:00. The first server gets the certificate, and the
others receive the same one.

The upstream Simple-ACME source code is available at
https://github.com/simple-acme/simple-acme and the reference scripts at
https://github.com/simple-acme/reference-scripts.

Download: https://www.fairssl.dk/get/simple-acme
Support:  https://www.fairssl.dk
