Encryption
SSL and TLS
Read and change the SSL mode of a domain, whether HTTPS is forced, its TLS profile and its HSTS header.
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"How the three groups work
Section titled “How the three groups work”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.
Reading a group
Section titled “Reading a group”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 astateofunknownhas novalue. Treat it as unavailable, never asfalse,0oroff, and do not write over it on a guess. consistencyisverified,degradedorunknown.publication.statusisverifiedwhen the CDN verified what it published, andunknownotherwise.publication.rolloutis alwaysunknown.- The query string is not read.
Edits need the latest revision
Section titled “Edits need the latest revision”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-Matchthe edit answers428 PRECONDITION_REQUIRED. - If the group changed since your read, the edit answers
412 REVISION_MISMATCH. Read again and retry. - A successful edit answers
200with the group as it is now, in the same form as a read, and a newETagheader for your next edit. - An
ETagbelongs to its group. Readsettings/tls/before you editsettings/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.
SSL mode and forced HTTPS
Section titled “SSL mode and forced HTTPS”Read the SSL settings
Section titled “Read the SSL settings”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. |
Change the SSL settings
Section titled “Change the SSL settings”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" }'curl -X PATCH "$SSL/settings/ssl/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "force_https": true }'curl -X PATCH "$SSL/settings/ssl/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "mode": "flexible", "force_https": false }'TLS profile
Section titled “TLS profile”The TLS profile is the lowest version of TLS the domain accepts.
Read the TLS profile
Section titled “Read the TLS profile”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.
Select a TLS profile
Section titled “Select a TLS profile”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.
Read the HSTS settings
Section titled “Read the HSTS settings”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.
Change the HSTS settings
Section titled “Change the HSTS settings”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 }'curl -X PATCH "$SSL/settings/hsts/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $HSTS_ETAG" \ -d '{ "max_age_seconds": 63072000, "include_subdomains": true, "preload": true }'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": false }'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.
Rules for every edit
Section titled “Rules for every edit”- Strict values. Nothing is converted.
"true",1andnullare not booleans, and a field the group does not have is refused. A refused field is named infields, except a field the API does not know. - No body or an empty one. A request with no body answers
400 INVALID_REQUEST. Onsslandhsts, a body of{}answers400 NO_CHANGES. - Refused before anything is written. A
400or a428writes nothing.
Limits and permissions
Section titled “Limits and permissions”- 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
400or428before 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 indetails.retry_after_secondsand in theRetry-Afterheader. - Permissions. Reads need
ssl.viewon the domain. Edits needssl.edit. Being able to read the settings does not let you change them.
Errors you are likely to see
Section titled “Errors you are likely to see”| 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.
All SSL and TLS endpoints
Section titled “All SSL and TLS endpoints”Each row opens the endpoint in the API reference, with every parameter, rule and response.
Loading the endpoints...