# Ssl Certificate Expiry (`eichan/ssl-certificate-expiry`) Actor

- **URL**: https://apify.com/eichan/ssl-certificate-expiry.md
- **Developed by:** [Eichan Jolly](https://apify.com/eichan) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.01 / actor start

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Bulk TLS Certificate Expiry Checker

**Small scheduled job:** Check the TLS certificate on port **443** for 1–20 HTTPS hostnames, show who issued it and when it is valid, and sort the results by **expiry urgency** (expired first, then shortest remaining validity; errors last).

### Who is it for?

Site owners, small web operations teams, and agencies keeping track of certificate renewal deadlines across multiple public HTTPS hosts. Unlike a deep single-host TLS diagnostic, this is a **bulk, expiry-first snapshot**.

### Example input

```json
{
  "hostnames": ["example.com"]
}
```

Supply one to twenty **bare hostnames** (`example.com`, `www.example.com`), with no `https://`, trailing path, port, credentials, or IP address. The Store input is prefilled with a public site for which certificate information is publicly observable.

### Example output: one certificate

The following is **illustrative** (expiry depends on live certificate rotation and run time).

```json
{
  "hostname": "example.com",
  "issuer": "organizationName=Example Certificate Authority, commonName=Example TLS CA",
  "subject": "commonName=example.com",
  "notBefore": "2026-09-26T00:00:00Z",
  "notAfter": "2026-12-25T00:00:00Z",
  "daysRemaining": 54,
  "status": "ok",
  "error": null,
  "checkedAt": "2026-11-01T12:00:00Z"
}
```

Fields: `issuer` and `subject` are human-readable certificate distinguished names; `notBefore`/`notAfter` are UTC ISO 8601; `daysRemaining` is a signed integer (rounded **up** for positive partial days, **down** after expiry); `status` is `ok`, `expiring_soon` (time left is **at most 30 × 24 hours**), `expired`, or `error`. Every hostname produces one row. Error rows contain a plain-language `error` and `null` certificate data; errors sort last.

### Running locally

Python 3.12+ only, no external dependencies:

```sh
export ACTOR_INPUT_JSON='{"hostnames":["example.com","www.example.com"]}'
python src/main.py
```

Local dataset records are created at `./storage/datasets/default/`. Alternatively supply `./storage/key_value_stores/default/INPUT.json`.

On Apify, input priority is: `ACTOR_INPUT_JSON` if supplied; otherwise **GET** `https://api.apify.com/v2/key-value-stores/{APIFY_DEFAULT_KEY_VALUE_STORE_ID}/records/INPUT` with the run's `APIFY_TOKEN`; otherwise local JSON. The default dataset is written via Apify's REST API. No Apify SDK, external key, or source-site login is required.

### Limits & honest behavior

- Checks **TLS on port 443 only**; does not request HTTP pages, scan other ports, or evaluate full security configuration. Public hostnames only; private/local hostnames and IP literals are rejected.
- Uses the Python standard-library `ssl` and `socket`, validates certificate trust and hostname on normal connections, and sends the hostname via SNI. For an **expired certificate**, verification normally fails; the Actor retries an unverified connection **only to read its expiry metadata**. An untrusted or wrong-host certificate that has not expired is an `error`, not `ok`.
- CPython's internal standard-library `_test_decode_cert` helper is used only for that expired-certificate fallback. Other Python implementations may not support this limited fallback.
- Timeout is 6 seconds per resolved address; resolution and connection failures are reported individually. A successful certificate check is a snapshot of the server reached during this run, not a renewal guarantee.
- `daysRemaining` uses UTC instants, not calendar-date differences; a just-expired certificate reports `-1`. Hostnames may resolve to multiple public IPs: the first reachable address is checked, not every load-balanced certificate.
- This Actor does not email alerts, remember previous runs, or replace comprehensive certificate-chain auditing. The dataset is **sorted** to put the most urgent dates first, with errors last.

### Scheduled use case

Schedule once daily for up to twenty managed domains. Have a downstream workflow inspect `status == "expiring_soon"` or `status == "expired"` and contact the domain owner. No alerts are sent by this Actor itself.

### Store information

**Categories:** Automation (`AUTOMATION`), Developer Tools (`DEVELOPER_TOOLS`). **Suggested pricing:** `$0.010 per run` (advisory only; no billing configured).

# Actor input Schema

## `hostnames` (type: `array`):

One to twenty DNS names, without URL schemes, paths or port numbers. The example is a public domain with an active TLS certificate.

## Actor input object example

```json
{
  "hostnames": [
    "example.com"
  ]
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset containing the Actor's result items

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "hostnames": [
        "example.com"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/ssl-certificate-expiry").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "hostnames": ["example.com"] }

# Run the Actor and wait for it to finish
run = client.actor("eichan/ssl-certificate-expiry").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "hostnames": [
    "example.com"
  ]
}' |
apify call eichan/ssl-certificate-expiry --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/ssl-certificate-expiry"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/z5vTZGlCepHGtrQDG/builds/e2yG4A6U06FRIh9s0/openapi.json
