Skip to main content

Basic Python Server to execute ACME instead of dump clients

Project description

ACME Management Server (ACMEMS)

[![Build Status](]( [![Build Status](]( [![Python Versions](]( [![PyPi Status](](

[LetsEncrypt]( supports issuing free certificates by communication via ACME - the Automatically Certificate Management Evaluation protocol.

This tools is yet another ACME client ... but as a client/server model.

## Why yet another ACME client

Some aspects are special:

* **ACME handling can be put into own VM / container ...**: The server can be placed into an own VM, container, network segment to limit the security risk on compromised systems.
* **Only the server requires all the ACME dependencies**: The clients require only a SSL tool like OpenSSL and a HTTP client like wget or curl, no python, no build tools. Python with python-acme and its dependencies (PyOpenSSL, PyASN.1, ...) is only needed for the server.
* **Supports distributed web servers**: All `.well-known/acme-challenges` requests for all domains can be served directly by the server. This makes it easy to validate domains when using multiple web server in distributed or fail-over fashion by forwarding all `.well-known/acme-challenges` requests.
* **Only the server needs the ACME account information**: It is not that security relevant, but only the ACME Management Server needs access to the account information / key for the ACME server like LetsEncrypt.
* **Caching CSR signs**: The returned signed certificate of a CSR is cached until the certificate is nearly expired (per default two week). If two machines have manual shared a key and CSR and they reusing both, they will both get from ACMEMS the same certificate back.

## Domain Validations / Challenges.

### HTTP01

The normal webserver must be adjusted to forward `.well-known/acme-challenges` requests to the ACME Management Server - this is a prerequirement and will not be checked/enforced/configured by this tool.

#### Nginx

upstream acme-mgmtserver {
server ...;
server {
# ...
location /.well-known/acme-challenge {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://acme-mgmtserver;
# to support multiple acme mgmt server check challenge on all upstream server:
proxy_next_upstream error timeout http_404;
# ...

This passes all ACME challenges to the management server. `proxy_next_upstream http_404;` can be used to support multiple ACME management servers and search for the response on all servers.

#### Apache

Up to you - I am happy to accept a PR to complete this.

### TLSNI01

`TLSNI01` is currently not supported, but there are few things are missing. Feel free to open a PR or talk to me if you have use for this challenge type.

### DNS01

ACMEMS can instrument DNS servers to serve the needed `TXT` records to validate domain names via `DNS01` challenge. The DNS servers will be updated vis DNS update. Currently there is no security for the updates implemented. We expect that the zone name managed by the name server are second-level domain name (like ``).

## Installation

### Debian Packages

My preferred installation method are distribution packages. `python-acme` and `pyopenssl` are needed in as of 2015Q4 new versions. It is time-consuming to backport all needed dependencies. Therefore I currently only maintain packages for Ubuntu 16.04 LTS Xenial in my own [PPA]( The dependencies were backported to `jessie-backports`, so the PPA should also work with `jessie-backports`.

To use `DNS01` challenge `python-acme` >= 0.9 is needed. The PPA contains a backported version.

### PyPI

The server and all its dependencies are available on PyPi and can be installed by Python package manager like pip e.g. inside a virtualenv.

## Configuration

The configuration is a basic INI file, with multiple key support. The main parts are the blocks to define the account directory, listen information for the http interfaces and the configuration which client is allowed to request certificates for which domains.

# the ACME server to talk to; I recommend to first test
# against the staging system
acme-server =
# account dir; contains
# account.pem - private key to identify against the ACME server
# registration.json - the registration resource as JSON dump
dir = /etc/acmems/account/

# Management interface itself, the clients needs to talk to this
# maximal size for CSR (in bytes)
max-size = 4k
# define which verification block is used by default
default-verification = http
# should be signed certificates be stored
default-storage = file

# Define verification blocks
[verification "http"]
# the challenge type has to be defined first!
type = http01
# listen for HTTP challenge check requests (e.g. from Nginx)

[verification "dns"]
# the challenge type has to be defined first!
type = dns01-dnsUpdate
# which name server needs to be updated now
# time-to-live for the new entries
# timeout for dns update requests

# Storages
[storage "none"]
# this stores nothing and it is the default storage
type = none

[storage "file"]
# caching on disk, the directory must be write for the daemon
type = file
# timespan (currently only in days) until a certificate expiry date
# within the ACMEMS should reissue the certificate

# Define multiple authentification blocks
# a CSR must fulfil all listed authentication methods and must
# only contains listed domains (checks against globs)
[auth "mail"]
# TCP connection must come from one of this IPs

# an additional auth block
[auth "ext"]

# CSR must also be signed by HMAC (via a the secret key)
[auth "mail-secure"]
# uise special verification and storage
verification = dns
storage = file

## Registration

The executable `acme-register` supports to register at the ACME server. This will not be done automatically, you have to call it manually before the first use of the server itself.

Please have a look at the help output for further instructions `acme-register --help`.

A registration could look like this:

> bin/acme-register --gen-key --register --email configs/integration.ini
Generate private key ... done
Initialize ACME client ... done
Register ... done
You need to accept the terms of service at
> bin/acme-register --accept-terms-of-service= configs/integration.ini
Load private key ... done
Initialize ACME client ... done
Refreshing current registration ... done
You need to accept the terms of service at
Accepting ToS at ... done

## Example Client Usage

# generate domain private key (once!)
openssl genrsa 4096 > domain.key

# generate csr to create/renew your certificate
# please generate a new csr for to renew your certificate
openssl req -new -sha256 -key domain.key -subj "/" > domain-201512.csr
# or
openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\,")) > domain-201512.csr

# upload sign csr with shared key
wget --post-file=domain-201512.csr --header="`openssl dgst -sha256 -hmac '$KEY' domain-201512.csr | sed -e 's/HMAC-\(.*\)(.*)= *\(.*\)/Authentication: hmac name=\L\1\E, hash=\2/'`" http://acmese:1313/sign > domain-201512.pem
# upload csr with out sign
wget --post-file=domain-201512.csr http://acmese:1313/sign > domain-201512.pem

## HTTP interface

### Client request

Only POST requests to `/sign` are supported.

The body must be a CSR as PEM format; `Content-Length` header is required, `Content-Type` is currently not evaluated.

To authentication the CSR via HMAC, add a header like:

Authentication: hmac name=sha256 hash=47d5066525a214c759300d884bdd19d8f461a0ad24a2a0b7b705caee6c912228

A complete request could look like:

POST /sign HTTP/1.1
Content-Length: 1586
Authentication: hmac name=sha256, hash=47d5066525a214c759300d884bdd19d8f461a0ad24a2a0b7b705caee6c912228


### Server response

Error code:

* **200**: CSR was signed. Response body contains the certificate and the intermediate certificate in PEM form.
* **403**: Signing is denied, have a look at your auth blocks / authentication methods; are you missing an `Authentication` header?
* **413**: CSR request is too long. You might increase the `max-size` setting.
* **415**: CSR could not be parsed.
* **500**: Internal exception - take a look at the log and report the bug.

## Testing

The server is mostly tests (some boulder error responses are difficult to reproduce). You need `py.test` to run the tests.

The tests marked as `boulder` need a local ACME server listening on `` sends all HTTP01 test challenges to ``. To install boulder take a look at the [Boulder README]( and/or at the prepare scripts for travis to setup boulder (`tests/scripts`).

## Contributing

1. Fork it
2. Create your feature branch (git checkout -b my-new-feature)
3. Add tests for your feature.
4. Add your feature.
5. Commit your changes (git commit -am 'Add some feature')
6. Push to the branch (git push origin my-new-feature)
7. Create new Pull Request

## License

GPL License

Copyright (c) 2015-2016, Malte Swart

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
acme-mgmtserver-0.3.1.tar.gz (20.6 kB) Copy SHA256 hash SHA256 Source None Dec 13, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page