Encryption
mTLS
Upload the CA that client certificates are verified against, switch mTLS on and say which hostnames and paths ask for a certificate.
mTLS makes a domain ask its visitors for a client certificate. This part of the API holds the CA those certificates are verified against, the switch that turns mTLS on, and the rules that say where a certificate is required or optional. The paths start with /v2/cdn/mtls/{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 MTLS="https://api.diamwall.com/v2/cdn/mtls/your-domain-public-id"The order of calls
Section titled “The order of calls”The three parts depend on each other, so the order matters:
| Step | Call | Why in this order |
|---|---|---|
| 1 | POST .../mtls-ca/ |
Creating the CA does not switch mTLS on, and mTLS cannot be switched on without a CA. |
| 2 | PATCH .../settings/mtls/ with "enabled": true |
Needs a CA that is valid now. |
| 3 | POST .../mtls-rules/ |
A rule write with mTLS off answers 409 INVALID_STATE. |
To remove everything, go the other way: switch mTLS off, then delete the CA. The CA is deleted only with mTLS switched off.
Writes need the latest revision
Section titled “Writes need the latest revision”Every write takes an If-Match header with the ETag of a read. There are three separate revisions, one for each part:
| You write | Read this first for the ETag |
|---|---|
| The CA | GET .../mtls-ca/ or GET .../mtls-ca/current/ |
| The settings | GET .../settings/mtls/ |
| A rule | GET .../mtls-rules/ or GET .../mtls-rules/{rule_id}/ |
The ETag is one value in quotes, "sha256:...". Send it back exactly as it came, quotes included. Each write answers with a new ETag header to use on your next write of the same part. The examples below read it like this:
ETAG=$(curl -s -o /dev/null -D - "$MTLS/mtls-ca/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')Without If-Match the write answers 428. If the part changed since your read, it answers 412 REVISION_MISMATCH: read again and retry.
The CA
Section titled “The CA”A domain has one CA or none. Its id is always current.
Read the CA
Section titled “Read the CA”curl "$MTLS/mtls-ca/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:f5d8dacf16ec...", "consistency": "verified", "data": { "state": "resolved", "items": [ { "id": "current", "present": true, "subject": "CN=Example Private CA", "issuer": "CN=Example Private CA", "not_before": "2026-10-10T00:00:00.000Z", "not_after": "2027-10-10T00:00:00.000Z", "fingerprint_sha256": "00:01:02:03:04:05:06:07:...", "status": "active" } ], "page": { "limit": 50, "next_cursor": null, "total": 1 } }}- An empty
data.itemsis a domain with no CA. TheETagheader is there for an empty list too: it is what you send to create the first CA. - No read ever answers the PEM. You get the public metadata of the certificate only.
- A CA can carry a
stateand areasonof its own, for example with"status": "expired". Show that CA as unavailable, never as a healthy one. - If
data.stateis there and is notresolved, the answer has noitems, nopageand noETag. The CA is unavailable. Do not read that as a domain with no CA.
GET .../mtls-ca/current/ answers the same CA under data. On a domain with no CA it answers 404 RESOURCE_ITEM_NOT_FOUND, which is not an error to retry.
Upload a CA
Section titled “Upload a CA”The body has exactly one field, certificate: the certificate of the CA in PEM, as a string. This example builds the JSON from a file with jq, so the line breaks of the PEM are escaped for you:
jq -n --rawfile certificate ca.pem '{ certificate: $certificate }' \ | curl -X POST "$MTLS/mtls-ca/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d @-The answer is 201 with the metadata of the new CA under data, and a new ETag header.
| Rule | What happens otherwise |
|---|---|
certificate is a string that is not empty, at most 1 MiB |
400 INVALID_REQUEST with fields: ["certificate"] |
| The whole body is at most 3 MiB | 413 PAYLOAD_TOO_LARGE |
Exactly one certificate, marked as a CA (CA:TRUE) and valid now |
400 INVALID_CA |
| The domain has no CA yet | 409 ALREADY_EXISTS. Replace the CA instead. |
Replace the CA
Section titled “Replace the CA”The body and its rules are the same as for an upload. ca_id is always current.
jq -n --rawfile certificate new-ca.pem '{ certificate: $certificate }' \ | curl -X PATCH "$MTLS/mtls-ca/current/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d @-Replacing the CA does not switch mTLS on or off. Client certificates are verified against the new CA from then on. On a domain with no CA the request answers 404 RESOURCE_ITEM_NOT_FOUND: upload one instead.
Delete the CA
Section titled “Delete the CA”Switch mTLS off first. With mTLS on, the delete answers 409 INVALID_STATE and nothing is deleted.
curl -X DELETE "$MTLS/mtls-ca/current/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "If-Match: $ETAG"The request takes no body. The answer is 200 with no data, and operation.id is the id the CA had.
Settings
Section titled “Settings”Read the settings
Section titled “Read the settings”curl "$MTLS/settings/mtls/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:5a1211b2fd83...", "consistency": "verified", "data": { "configuration": { "state": "resolved", "value": { "enabled": true, "verify_depth": 2 } }, "ca_certificate": { "state": "resolved", "value": { "present": true, "subject": "CN=Example Private CA", "not_after": "2027-10-10T00:00:00.000Z", "status": "active" } } }}configuration.valueholdsenabled, whether mTLS is on, andverify_depth, how deep the chain of a client certificate is verified.ca_certificate.valueholds the same public metadata of the CA as the CA endpoints.- Each of the two has a
state, and avalueonly when thestateisresolved. Astateofunknownmeans the CDN could not tell. Treat it as unavailable, never as mTLS off or as a domain with no CA. - To know whether the domain has a CA at all, read
mtls-ca/. The rules are not part of this answer.
When the whole group could not be read, the answer has "state": "unknown", a revision of null, no data and no ETag. There is nothing to send in If-Match, so do not write.
Switch mTLS on or off
Section titled “Switch mTLS on or off”Read settings/mtls/ to get its ETag, then send at least one of the two fields. A field you leave out keeps its value.
| Field | Allowed values |
|---|---|
enabled |
true or false, as a JSON boolean |
verify_depth |
A whole number from 1 to 10 |
curl -X PATCH "$MTLS/settings/mtls/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $SETTINGS_ETAG" \ -d '{ "enabled": true }'curl -X PATCH "$MTLS/settings/mtls/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $SETTINGS_ETAG" \ -d '{ "enabled": false }'curl -X PATCH "$MTLS/settings/mtls/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $SETTINGS_ETAG" \ -d '{ "verify_depth": 3 }'Values are not converted: "true", 1 or "2" answer 400 INVALID_REQUEST with the field in fields. An empty object answers 400 NO_CHANGES. The answer is the settings after the edit, in the same form as the read, with a new ETag header.
Switching on is refused with a 409 when the domain is not ready, and nothing is written:
| Code | What to do |
|---|---|
MISSING_CA |
The domain has no CA. Upload one, read the settings again for a new ETag, then send the edit again. |
INVALID_CA |
The CA is expired, not yet valid, or not a CA. Replace it, then send the edit again. |
RUNTIME_UNAVAILABLE |
mTLS cannot be used for this domain right now. Nothing in the request can fix it. Do not repeat it, and quote the request_id to support. |
A rule says on which hostname and path a client certificate is required, or optional. A domain holds at most 100 rules.
| Field | Rules | When left out on create |
|---|---|---|
name |
Required on create. 1 to 128 characters: letters, digits, spaces, _, . and -. Unique in the domain. Never trimmed. |
|
hostname |
The domain, a name under it, or a wildcard of either. 1 to 253 characters. | The domain itself |
path |
Begins with /, at most 2048 characters, with no // and no . or .. segment. |
/ |
action |
require or optional |
require |
description |
One line, at most 1024 bytes. An empty string clears it. |
List the rules
Section titled “List the rules”curl "$MTLS/mtls-rules/?limit=50" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:8d30477b8fc2...", "data": { "state": "resolved", "items": [ { "id": "1122334455667788", "name": "Require client certificate", "hostname": "api.example.com", "path": "/private", "action": "require", "description": "Clients of the private API" } ], "page": { "limit": 50, "next_cursor": null, "total": 1 } }}limitgoes from 1 to 100. Without it a page holds 50 rules.- To read the next page, send
data.page.next_cursorback ascursor, until it isnull. - If a rule changes between two pages, the next page answers
409 CURSOR_STALE. Start again from the first page. - If
data.stateis there and is notresolved, the answer has noitems, nopageand noETag. The rules are unavailable. Do not read that as a domain with no rule.
GET .../mtls-rules/{rule_id}/ answers one rule under data, in the same form.
Add a rule
Section titled “Add a rule”Read the rules first to get the ETag. It is there for an empty list too.
curl -X POST "$MTLS/mtls-rules/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $RULES_ETAG" \ -d '{ "name": "Require client certificate", "description": "Clients of the private API", "hostname": "api.example.com", "path": "/private", "action": "require" }'curl -X POST "$MTLS/mtls-rules/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $RULES_ETAG" \ -d '{ "name": "Optional under the domain", "hostname": "*.example.com", "action": "optional" }'curl -X POST "$MTLS/mtls-rules/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $RULES_ETAG" \ -d '{ "name": "Admin area" }'The answer is 201 with the new rule under data, defaults filled in, and a new ETag header. The id of the rule is also in operation.id.
Change a rule
Section titled “Change a rule”Send only the fields that change. A field you leave out keeps its value, and the id of the rule stays the same.
curl -X PATCH "$MTLS/mtls-rules/1122334455667788/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $RULES_ETAG" \ -d '{ "action": "optional" }'An empty body answers 400 NO_CHANGES. To clear the description, send "description": "".
Delete a rule
Section titled “Delete a rule”curl -X DELETE "$MTLS/mtls-rules/1122334455667788/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "If-Match: $RULES_ETAG"The request takes no body. The answer is 200 with no data, and operation.id is the id the rule had.
When a write gets no clear answer
Section titled “When a write gets no clear answer”Writes here take no Idempotency-Key. After 500 UNEXPECTED_ERROR, 502 FILE_SERVER_OUTCOME_UNKNOWN or 503 READBACK_MISMATCH the write may have been made. Read the part again before any other attempt, and never repeat the request blindly. After 502 FILE_SERVER_NO_ANSWER nothing changed.
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 mTLS call costs 8 credits. A request refused with
400,403,413or428before it reaches the CDN costs none. - Out of credits. The call answers
429 TOO_MANY_REQUESTS, with the wait indetails.retry_after_seconds. - Plan. Every plan has mTLS today. A domain whose plan had no mTLS would answer
403 FEATURE_NOT_AVAILABLE, withdetails.featureanddetails.plan. - Rule limit. 100 rules per domain, on every plan.
- Permissions. mTLS uses the SSL permissions of the domain:
| Action | Permission |
|---|---|
| Any read | ssl.view |
| Upload or replace the CA, edit the settings, edit a rule | ssl.edit |
| Create a rule | ssl.create |
| Delete the CA or a rule | ssl.delete |
Errors you are likely to see
Section titled “Errors you are likely to see”| Status | Code | What happened |
|---|---|---|
400 |
INVALID_REQUEST |
A field, a query parameter or an id is wrong. The answer names it in fields when it can. |
400 |
NO_CHANGES |
An edit was sent with nothing to change. |
400 |
INVALID_CA |
The certificate is not exactly one CA certificate that is valid now. |
400 |
INVALID_RULE |
The CDN does not accept the hostname or the path of the rule. |
400 |
INVALID_PRECONDITION |
The If-Match header is not in the form of an ETag. |
404 |
RESOURCE_ITEM_NOT_FOUND |
The domain has no CA, or no rule has that id. |
404 |
SETTINGS_GROUP_NOT_FOUND |
The CDN does not have the mTLS settings of the domain. This is not mTLS off. |
409 |
ALREADY_EXISTS |
The domain already has a CA. Replace it instead. |
409 |
MISSING_CA |
mTLS cannot be switched on: the domain has no CA. |
409 |
INVALID_CA |
mTLS cannot be switched on: the CA is not valid now. |
409 |
INVALID_STATE |
The CA cannot be deleted with mTLS on, or a rule cannot be written with mTLS off. |
409 |
DUPLICATE_NAME |
Another rule of the domain has that name. |
409 |
QUOTA_EXCEEDED |
The domain already has 100 rules. |
409 |
RUNTIME_UNAVAILABLE |
mTLS cannot be used for this domain right now. Quote the request_id to support. |
409 |
CURSOR_STALE |
The list changed while you were paging. Start from the first page. |
412 |
REVISION_MISMATCH |
The part changed since your read. Read again and retry. |
413 |
PAYLOAD_TOO_LARGE |
The body of a CA upload is larger than 3 MiB. |
428 |
PRECONDITION_REQUIRED |
The If-Match header is missing. |
503 |
READBACK_MISMATCH |
The write may have been made. Read again before trying anything else. |
The errors that come from the key itself, such as API_KEY_IP_NOT_ALLOWED, are on the Errors page.
All mTLS endpoints
Section titled “All mTLS endpoints”Each row opens the endpoint in the API reference, with every parameter, rule and response.
Loading the endpoints...