# Tls Certificate Expiry Checker (`eichan/tls-certificate-expiry-checker`) Actor

- **URL**: https://apify.com/eichan/tls-certificate-expiry-checker.md
- **Developed by:** [Eichan Jolly](https://apify.com/eichan) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 85.7% 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

## TLS Certificate Expiry Checker

**Actor slug:** `tls-certificate-expiry-checker`\
**Apify Store categories (declare on listing):** `DEVELOPER_TOOLS`\
**Suggested price:** **$0.003 per run** (one dataset result; recommendation only, **not configured**).\
**Audience:** Website owners, DevOps teams, QA teams, and certificate-rotation operators.

### What it does

Opens one TLS connection to a **user-supplied public domain on port 443**, receives the leaf certificate, decodes the X.509 validity dates, and reports whether the certificate has expired and how many days remain.

It reads DER ASN.1 `notBefore` / `notAfter` timestamps using **Python standard library only**. It deliberately does **not verify CA trust or hostname ownership**: expired or self-signed certificates must be readable to report their expiration. `expired: false` means the presented date is in the future; it **does not** mean the connection is trustworthy.

### Tiny example input

```json
{
  "domain": "example.com"
}
```

### Example output (from included local test fixture, not the live example.com certificate)

```json
{
  "domain": "example.com",
  "not_before": "2026-11-01T02:45:52Z",
  "expires_at": "2036-10-29T02:45:52Z",
  "days_remaining": 3650.0,
  "expired": false,
  "error": null
}
```

`days_remaining` is the time difference in days, rounded to two decimals; it may be negative for expired certificates. Actual live result dates depend on the server certificate and the UTC time of execution. Failure items preserve the same keys, with unknown values set to `null` and `error` containing a plain-English message.

### Limits and security

- **Exactly one domain**. Do not include `https://`, paths, ports, query strings, or credentials.
- Uses **only port 443**, one TLS handshake, one leaf certificate; reads **no website content** and makes no HTTP requests to the target.
- Uses SNI for the supplied domain; for IP literals, SNI behavior depends on TLS library/server support.
- Resolves the domain and pins the socket to a public IP. Rejects private, loopback, reserved/non-global, and mixed public/private DNS answers.
- Connection timeout: **8 seconds**; certificate DER size limit: **100 KB**. Uses supported DER UTCTime/GeneralizedTime encodings; nonstandard validity encodings cause an error item.
- This Actor is **not** a CA-chain validator, revocation checker, certificate transparency checker, TLS-grade scanner, or monitoring service. It does not check certificate trust, SAN coverage, issuer, or future renewal status.
- No third-party packages or Apify SDK; no target credentials, login, or destructive operations.

### Run locally

From the Actor folder, set an input environment variable, then **execute the script**:

```bash
ACTOR_INPUT_JSON='{"domain":"example.com"}' python src/main.py
```

Alternatively put `{"domain":"example.com"}` in `storage/key_value_stores/default/INPUT.json`, then run `python src/main.py`. The output is one JSON dataset item under `storage/datasets/default/000000001.json` or the next available numbered file. `APIFY_LOCAL_STORAGE_DIR` can override the base directory.

On Apify, the Actor reads the default input key-value store and posts one item to its own default dataset with the **platform-provided** `APIFY_TOKEN`; the visitor does not supply credentials. This platform token is only for Apify storage, never for TLS target authentication. No billing, publishing, or price configuration is included.

### Reproducible verification

```bash
python tests/run_smoke.py
python -m unittest discover -s tests -p 'test_*.py' -v
```

The smoke test **actually runs `python src/main.py`**, with valid input and a local TLS fixture certificate for `example.com`. The offline fixture uses test-only socket redirection (`tests/smoke_support/sitecustomize.py`), not any production Actor changes. After verifying the output dataset, it writes the actual stdout, stderr and dataset item into `verification/`.

`tests/` includes the full rerunnable test code and test certificate/key. The fixture private key is a public, disposable test key and is **not copied into the production image**. No Apify cloud build or live Internet TLS check is claimed.

# Actor input Schema

## `domain` (type: `string`):

A hostname only, without https://, a port, or a path.

## Actor input object example

```json
{
  "domain": "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 = {
    "domain": "example.com"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/tls-certificate-expiry-checker").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 = { "domain": "example.com" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/tls-certificate-expiry-checker").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 '{
  "domain": "example.com"
}' |
apify call eichan/tls-certificate-expiry-checker --silent --output-dataset

```

## MCP server setup

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

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/u11oK6RkxPD5cnqIc/builds/hD0DGx2qdyhnJzfJp/openapi.json
