# SSL certificate

> The SSL check - whether a TLS certificate is valid for its host, and warnings days before it expires.

An SSL check connects to a host and port, completes a TLS handshake, and checks the certificate the server presents: it must be within its validity dates, chain to a trusted root and match the host name. The run records when the certificate expires.

```json
{ "type": "ssl", "host": "shop.example.com", "port": 443, "warnDays": [30, 14, 7, 1] }
```

| Field      | Type              | Default      | Rules                                                 |
| ---------- | ----------------- | ------------ | ----------------------------------------------------- |
| `host`     | string            | required     | The name the certificate must match, or an IP address |
| `port`     | integer           | required     | 1 to 65535, usually 443                               |
| `warnDays` | array of integers | `[14, 7, 1]` | 1 to 365 days, at least one                           |

## Warnings and DOWN

- **Before expiry**: when the certificate has fewer days left than a threshold in `warnDays`, a warning goes to the alert channels the project picked, once per threshold. The check stays UP.
- **Invalid certificate**: an expired, not yet valid, untrusted or mismatched certificate fails the run, and the check goes DOWN by the usual [quorum rule](https://docs.monitorly.cloud/concepts/quorum.md). Codes: `tls.expired`, `tls.not_yet_valid`, `tls.untrusted`, `tls.hostname_mismatch`, `tls.invalid_certificate`, `tls.handshake_failed`.

An HTTP check of an `https` URL also fails on an invalid certificate, but sends no warning before expiry: that is what the SSL check is for. An hourly interval is enough for most certificates.
