Skip to content
Dashboard

Encryption

View as Markdown

SSL and TLS

Read and change the SSL mode of a domain, whether HTTPS is forced, its TLS profile and its HSTS header.

TLS 1.3origin

This part of the API controls how a domain speaks HTTPS: the SSL mode, the redirect from HTTP to HTTPS, the lowest TLS version it accepts and the HSTS header. The paths start with /v2/cdn/ssl/{domain_public_id}/, where the id is the public id of the domain, taken from the domains list.

The examples on this page use these shell variables:

export DIAMWALL_API_KEY="your key"
export SSL="https://api.diamwall.com/v2/cdn/ssl/your-domain-public-id"

The settings are split into three groups. Each one has a read and an edit of its own, at the same path:

Group Path Fields you can change
ssl settings/ssl/ mode, force_https
tls settings/tls/ profile
hsts settings/hsts/ enabled, max_age_seconds, include_subdomains, preload

An edit of one group never touches another. Changing HSTS or the SSL mode does not move the TLS profile.

Every read answers in the same form. Here is the ssl group:

curl "$SSL/settings/ssl/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY"
{
"revision": "sha256:4dbac6895cfc...",
"consistency": "verified",
"publication": { "status": "verified", "rollout": "unknown" },
"data": {
"mode": { "state": "resolved", "value": "full" },
"force_https": { "state": "resolved", "value": true },
"origin_ports_consistent": { "state": "resolved", "value": true }
}
}
  • Each field comes back as { "state": "resolved", "value": ... }. A field with a state of unknown has no value. Treat it as unavailable, never as false, 0 or off, and do not write over it on a guess.
  • consistency is verified, degraded or unknown.
  • publication.status is verified when the CDN verified what it published, and unknown otherwise. publication.rollout is always unknown.
  • The query string is not read.

Every edit is a PATCH that needs the ETag header of a read of the same group, sent back unchanged in If-Match:

ETAG=$(curl -s -o /dev/null -D - "$SSL/settings/ssl/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
| tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')
  • Without If-Match the edit answers 428 PRECONDITION_REQUIRED.
  • If the group changed since your read, the edit answers 412 REVISION_MISMATCH. Read again and retry.
  • A successful edit answers 200 with the group as it is now, in the same form as a read, and a new ETag header for your next edit.
  • An ETag belongs to its group. Read settings/tls/ before you edit settings/tls/.

Send only the fields that change. A field you leave out keeps its value. A boolean you leave out is never read as false.

curl "$SSL/settings/ssl/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY"
Field Meaning
mode The SSL mode of the domain. See the table below.
force_https Whether a request over HTTP is sent on to HTTPS.
origin_ports_consistent Read-only. false means the origin ports of the domain are inconsistent and deserve a warning. true means no warning. It cannot be written.
mode Meaning
off No HTTPS
flexible HTTPS between the visitor and the network
full HTTPS to the origin too
other A mode this API does not know. Only seen on a read. Show it as it is, never as off.

Send mode, force_https or both. mode is off, flexible or full, in lower case. force_https is a JSON boolean.

curl -X PATCH "$SSL/settings/ssl/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
-H "Content-Type: application/json" \
-H "If-Match: $ETAG" \
-d '{ "mode": "full" }'

The TLS profile is the lowest version of TLS the domain accepts.

curl "$SSL/settings/tls/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY"
{
"revision": "sha256:0d74f618848c...",
"consistency": "verified",
"publication": { "status": "verified", "rollout": "unknown" },
"data": {
"profile": { "state": "resolved", "value": "1.3" }
}
}
profile Can you select it?
1.3 Yes
1.2 Yes
1.1, 1.0 No. A domain that is already on one is shown on it.
legacy No. Any other profile this API does not know.

Show an older profile as what it is, never as 1.2.

The body is exactly profile, the string "1.2" or "1.3". The number 1.3 is refused.

TLS_ETAG=$(curl -s -o /dev/null -D - "$SSL/settings/tls/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
| tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')
curl -X PATCH "$SSL/settings/tls/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
-H "Content-Type: application/json" \
-H "If-Match: $TLS_ETAG" \
-d '{ "profile": "1.3" }'

With HSTS on, the domain answers with a header that tells browsers to use HTTPS for it.

curl "$SSL/settings/hsts/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY"
{
"revision": "sha256:48615bfb7850...",
"consistency": "verified",
"publication": { "status": "verified", "rollout": "unknown" },
"data": {
"enabled": { "state": "resolved", "value": true },
"max_age_seconds": { "state": "resolved", "value": 31536000 },
"include_subdomains": { "state": "resolved", "value": true },
"preload": { "state": "resolved", "value": false }
}
}
Field Meaning An edit takes
enabled Whether the domain answers with the HSTS header A JSON boolean
max_age_seconds How long a browser remembers to use HTTPS for the domain, in seconds A whole number from 0 to 63072000 (two years)
include_subdomains Whether the header covers the subdomains too A JSON boolean
preload Whether the header asks browsers to preload the domain A JSON boolean

A read shows max_age_seconds as it is stored, so it can show a value above the range an edit takes.

Read settings/hsts/ to get its ETag, then send at least one of the four fields:

curl -X PATCH "$SSL/settings/hsts/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
-H "Content-Type: application/json" \
-H "If-Match: $HSTS_ETAG" \
-d '{ "enabled": true, "max_age_seconds": 31536000 }'

Some fields depend on each other. These combinations are refused with 400 INVALID_REQUEST:

Refused Why
enabled: true with max_age_seconds: 0 HSTS that is on needs an age above 0.
preload: true with include_subdomains: false Preload needs the subdomains included.
preload: true with a max_age_seconds under 31536000 Preload needs an age of at least one year.

The rules apply to the settings as they would be after the edit. If you send only preload, it is checked against the age and the subdomain setting the domain already has.

  • Strict values. Nothing is converted. "true", 1 and null are not booleans, and a field the group does not have is refused. A refused field is named in fields, except a field the API does not know.
  • No body or an empty one. A request with no body answers 400 INVALID_REQUEST. On ssl and hsts, a body of {} answers 400 NO_CHANGES.
  • Refused before anything is written. A 400 or a 428 writes nothing.
  • Credits. Each domain has a budget of 3000 credits a minute, shared by everyone who calls the API for that domain. Every call on this page costs 8 credits.
  • What costs nothing. An edit refused with 400 or 428 before it reaches the CDN spends none of the domain’s credits. A read answered from the API’s short-lived copy spends none either, but still counts toward the user limit.
  • Out of credits. The call answers 429 TOO_MANY_REQUESTS, with the wait in details.retry_after_seconds and in the Retry-After header.
  • Permissions. Reads need ssl.view on the domain. Edits need ssl.edit. Being able to read the settings does not let you change them.
Status Code What happened
400 INVALID_REQUEST A field is wrong, two fields do not go together, or the body is missing. The answer names the fields in fields when it can.
400 NO_CHANGES An edit of ssl or hsts was sent with an empty body.
400 INVALID_PRECONDITION The If-Match header is not valid. Send the ETag back exactly as it came.
409 DOMAIN_WITHOUT_KEY The domain is not active on the network yet.
409 DOMAIN_BUSY Something else is changing the domain right now. Try again shortly.
409 DOMAIN_REPLACEMENT_PENDING The domain is being renamed. Nothing was written.
412 REVISION_MISMATCH The group changed since your read. details.current_revision has the current one. Read again and retry.
415 UNSUPPORTED_MEDIA_TYPE The body is not JSON. Nothing was written.
428 PRECONDITION_REQUIRED The If-Match header is missing.
429 TOO_MANY_REQUESTS The domain is out of credits for now.
502 FILE_SERVER_NO_ANSWER The CDN gave no usable answer. A read changed nothing and can be sent again.
502 FILE_SERVER_OUTCOME_UNKNOWN The edit may have been written. Read the group before you repeat it.
503 STATE_CHANGING The state of the domain is changing. An edit was refused. Read again before you send the change again.

The errors that come from the key itself, such as API_KEY_IP_NOT_ALLOWED, are on the Errors page.

Each row opens the endpoint in the API reference, with every parameter, rule and response.

Loading the endpoints...