# SSL certificate

> POST /ssl connects to a host on port 443 and returns its certificate: trust, names covered, expiry, issuer, key, protocol, cipher, chain and HSTS.

`POST https://api.qelka.com/v1/ssl`

Read the TLS certificate a host serves on port 443: whether the chain is trusted and why not, whether it covers the name, when it expires, who issued it, the key, the protocol and cipher agreed, the chain the server sent and its HSTS header. Each check costs 1 credit when a certificate was read; hosts that do not answer, errors and test keys are never billed.

## Request

Send a host name, or any URL whose host should be checked. Only the host is used: the scheme, path, query and port are dropped, and port 443 is always checked.

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `host` | string | Yes | none | A host name (`example.com`, `www.example.com`) or a URL, 1 to 2,048 characters. IP addresses are refused. |
| `fresh` | boolean | No | `false` | `true` skips the 1-hour result cache and checks the host again. |

Only public hosts are checked. An IP address, `localhost`, a name under a reserved suffix such as `.local` or `.internal`, or a host that resolves only to private or reserved addresses is a `422 unprocessable_input`. A name that does not exist in DNS is a `422 unprocessable_input` too, with a message that says so. The TLS connection has a 6-second limit, so every snippet sets a 30-second client timeout.

```bash title="cURL"
curl https://api.qelka.com/v1/ssl \
  --max-time 30 \
  -H "Authorization: Bearer $QELKA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"host": "github.com"}'
```
```javascript title="Node.js"
const response = await fetch('https://api.qelka.com/v1/ssl', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ host: 'github.com' }),
  signal: AbortSignal.timeout(30_000),
})
const result = await response.json()
console.log(result)
```
```python title="Python"
import os

import requests

api_key = os.environ["QELKA_API_KEY"]
response = requests.post(
    "https://api.qelka.com/v1/ssl",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"host": "github.com"},
    timeout=30,
)
result = response.json()
print(result)
```
```php title="PHP"
<?php
$ch = curl_init('https://api.qelka.com/v1/ssl');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('QELKA_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode(['host' => 'github.com']),
    CURLOPT_TIMEOUT => 30,
]);
$result = json_decode(curl_exec($ch), true);
print_r($result);
```
```go title="Go"
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"time"
)

func main() {
	payload, _ := json.Marshal(map[string]any{"host": "github.com"})
	request, _ := http.NewRequest(http.MethodPost, "https://api.qelka.com/v1/ssl", bytes.NewReader(payload))
	request.Header.Set("Authorization", "Bearer "+os.Getenv("QELKA_API_KEY"))
	request.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 30 * time.Second}
	response, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	var result map[string]any
	if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
		panic(err)
	}
	fmt.Println(result)
}
```
```ruby title="Ruby"
require 'json'
require 'net/http'

uri = URI('https://api.qelka.com/v1/ssl')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{ENV.fetch('QELKA_API_KEY')}"
request['Content-Type'] = 'application/json'
request.body = JSON.generate({ host: 'github.com' })

response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 30) do |http|
  http.request(request)
end
result = JSON.parse(response.body)
puts result
```

## Response

Every public host that resolves gets a `200`. Read `status` first: `valid` and `invalid` mean a certificate was read.

| Field | Type | Description |
|---|---|---|
| `id` | string | Identifier of this lookup: `lkp_` followed by 26 characters. |
| `object` | string | Always `ssl`. |
| `input` | string | The `host` you sent, without surrounding spaces. |
| `host` | string | The host that was checked, lower case. |
| `port` | integer | Always `443`. |
| `ip` | string or null | The address the connection was made to: the first public IPv4 address of the host, else the first public IPv6 address. |
| `status` | string | `valid`, `invalid`, `unreachable` or `handshake_failed`. |
| `issues` | array of strings | Problems found, errors first, then warnings. See [Issues](#issues). |
| `trusted` | boolean or null | `true` when the chain the server sent leads to a root of the Mozilla CA store bundled with Node.js. `null` when no certificate was read. |
| `trust_error` | string or null | Why the chain is not trusted: `expired`, `not_yet_valid`, `self_signed`, `self_signed_in_chain`, `unknown_issuer`, `incomplete_chain`, `revoked`, `invalid_signature` or `other`. |
| `hostname_match` | boolean or null | `true` when a subject alternative name, or the common name when there is none, covers the host, wildcards per RFC 6125. |
| `protocol` | string or null | TLS version agreed, such as `TLSv1.3`. |
| `cipher` | string or null | Cipher suite agreed, IANA name. |
| `alpn` | string or null | Application protocol agreed with ALPN, such as `h2` or `http/1.1`. |
| `certificate` | object or null | The site certificate. `null` when none was read. |
| `certificate.subject` | object | `common_name`, `organization` and `country` of the certificate, each a string or `null`. |
| `certificate.issuer` | object | `common_name`, `organization` and `country` of the authority that signed it. |
| `certificate.sans` | array of strings | Subject alternative names: every DNS name, and IP address, the certificate covers. |
| `certificate.serial_number` | string | Serial number, hexadecimal. |
| `certificate.fingerprint_sha256` | string | SHA-256 fingerprint of the certificate, colon-separated hexadecimal. |
| `certificate.valid_from` | string | Start of validity, ISO 8601. |
| `certificate.valid_to` | string | End of validity, ISO 8601. |
| `certificate.days_to_expiry` | integer | Whole days from the check to `valid_to`; negative once expired. |
| `certificate.key_type` | string or null | `rsa`, `ec`, `ed25519`, `ed448` or `dsa`. |
| `certificate.key_bits` | integer or null | Key size in bits. |
| `certificate.self_signed` | boolean | `true` when the certificate signed itself. |
| `chain` | array of objects | Certificates the server sent, site certificate first: `subject`, `issuer` (common name, or organization when there is none), `valid_to` and `self_signed`. |
| `hsts` | object or null | The Strict-Transport-Security header of the HTTPS response to `/`: `present`, `max_age` in seconds, `include_subdomains`, `preload` and `header` as sent. `null` when no HTTP response was read. |
| `http_status` | integer or null | HTTP status of that response to `/`. |
| `checked_at` | string | Time of the check, ISO 8601. |
| `credits_used` | integer | Credits debited for this call: 1 with a live key when the result is billed, else `0`. |
| `cached` | boolean | `true` when the answer came from the 1-hour cache. |

```json title="Response"
{
  "id": "lkp_01M8CGD1XX5EWYG0XXJ98VVGBS",
  "object": "ssl",
  "input": "github.com",
  "host": "github.com",
  "port": 443,
  "ip": "140.82.114.4",
  "status": "valid",
  "issues": [],
  "trusted": true,
  "trust_error": null,
  "hostname_match": true,
  "protocol": "TLSv1.3",
  "cipher": "TLS_AES_128_GCM_SHA256",
  "alpn": "h2",
  "certificate": {
    "subject": {
      "common_name": "github.com",
      "organization": null,
      "country": null
    },
    "issuer": {
      "common_name": "Sectigo Public Server Authentication CA DV E36",
      "organization": "Sectigo Limited",
      "country": "GB"
    },
    "sans": ["github.com", "www.github.com"],
    "serial_number": "3E1D6026B4B0AEA279DCA2EFBBCED82B",
    "fingerprint_sha256": "7D:C4:D8:5C:F1:E3:10:97:12:25:BC:9A:92:57:67:90:43:A2:43:D7:0A:3C:C2:A9:1C:C5:D3:89:89:2C:27:76",
    "valid_from": "2026-10-30T00:00:00.000Z",
    "valid_to": "2027-01-27T23:59:59.000Z",
    "days_to_expiry": 62,
    "key_type": "ec",
    "key_bits": 256,
    "self_signed": false
  },
  "chain": [
    {
      "subject": "github.com",
      "issuer": "Sectigo Public Server Authentication CA DV E36",
      "valid_to": "2027-01-27T23:59:59.000Z",
      "self_signed": false
    },
    {
      "subject": "Sectigo Public Server Authentication CA DV E36",
      "issuer": "Sectigo Public Server Authentication Root E46",
      "valid_to": "2036-03-21T23:59:59.000Z",
      "self_signed": false
    },
    {
      "subject": "Sectigo Public Server Authentication Root E46",
      "issuer": "USERTrust ECC Certification Authority",
      "valid_to": "2038-01-18T23:59:59.000Z",
      "self_signed": false
    },
    {
      "subject": "USERTrust ECC Certification Authority",
      "issuer": "USERTrust ECC Certification Authority",
      "valid_to": "2038-01-18T23:59:59.000Z",
      "self_signed": true
    }
  ],
  "hsts": {
    "present": true,
    "max_age": 31536000,
    "include_subdomains": true,
    "preload": true,
    "header": "max-age=31536000; includeSubdomains; preload"
  },
  "http_status": 200,
  "checked_at": "2026-11-26T18:03:08.092Z",
  "credits_used": 1,
  "cached": false
}
```

## Act on the status

| `status` | What it means | What to do | Billed |
|---|---|---|---|
| `valid` | The chain is trusted, the certificate covers the host and is within its validity dates. | Read `issues` for warnings such as `expires_soon`. | Yes, cached 1 hour |
| `invalid` | A TLS session was set up but at least one of those checks failed. | Read `trust_error` and `issues`, then fix the server configuration. | Yes, cached 1 hour |
| `unreachable` | No TCP connection on port 443 within the timeout, or the connection was reset. | Check that the site serves HTTPS, or try again later. | No |
| `handshake_failed` | The host answered on port 443 but no TLS session could be set up, for example a server that only speaks plain HTTP on 443 or supports no common cipher. | Check the TLS configuration of the server. | No |

## Issues

| Issue | Kind | Meaning |
|---|---|---|
| `expired` | Error | `valid_to` is in the past. |
| `not_yet_valid` | Error | `valid_from` is in the future. |
| `hostname_mismatch` | Error | No name of the certificate covers the host. |
| `self_signed` | Error | The site certificate signed itself. |
| `untrusted_root` | Error | The chain leads to a root that is not in the store, or to a self-signed certificate in the chain. |
| `incomplete_chain` | Error | The server did not send the intermediate certificates needed to reach a root. |
| `revoked` | Error | Reported only when the TLS library says so; OCSP and CRL are not queried. |
| `invalid_signature` | Error | A signature in the chain does not verify. |
| `untrusted` | Error | Any other trust failure. |
| `expires_soon` | Warning | 30 days or fewer left before `valid_to`. |
| `weak_key` | Warning | RSA or DSA key below 2048 bits, or EC key below 256 bits. |
| `legacy_protocol` | Warning | SSLv3, TLS 1.0 or TLS 1.1 was agreed. |
| `no_hsts` | Warning | The HTTPS response sends no Strict-Transport-Security header, or one with max-age 0. |

## How the host is checked

1. The host is resolved over DNS. Hosts whose addresses are all private or reserved are refused; otherwise the first public IPv4 address is used, else the first public IPv6 address.
2. A Node.js server opens a TLS connection to port 443 of that address with the host as SNI and ALPN `h2, http/1.1`, within 6 seconds, and reads the chain as sent.
3. The chain is verified against the Mozilla CA root store bundled with Node.js, and the names are matched against the host.
4. One HTTPS `GET /` reads the Strict-Transport-Security header; its body is not read.

Revocation is not checked. A host served from several addresses, such as a CDN, can present another certificate on another address.

## Batch and bulk

Send up to 100 hosts in one [batch](https://qelka.com/docs/api-reference/batch) with `"type": "ssl"`, or a CSV column of hosts as a [bulk job](https://qelka.com/docs/api-reference/bulk): the output adds the status, address, trust, issuer, validity dates, days to expiry, protocol, HSTS and issues of each host. The MCP tool is `check_ssl`.
