certificates
List MikroTik RouterOS cert metadata, calculate days until expiry, and strip private keys defensively.
Instructions
List certificates (/certificate): name, common-name,
subject/issuer fields (if present), invalid-before/invalid-after
(raw RouterOS date strings, kept as-is), key-size/key-type,
fingerprint, and RouterOS's own flags (expired, trusted) - all
returned exactly as the device sends them (booleans may come back as
Python bool or be omitted entirely; see formatting.coerce_ros_bool
for a caller that needs to branch on expired/trusted rather than
just display them).
Adds a computed daysUntilExpiry (int, negative once past due) from
invalid-after whenever it can be parsed - see
formatting.parse_ros_datetime's docstring for the two RouterOS date
shapes handled ("2027-01-15 12:00:00" and
"jan/15/2027 12:00:00"). RouterOS's own date rendering varies by
version/locale; parsing is DEFENSIVE and never raises - a row whose
invalid-after doesn't match either known shape simply has no
daysUntilExpiry key added, with the raw invalid-after string left
untouched so a caller can still see it.
SECURITY: /certificate's own API reply never carries a private key
(RouterOS only returns certificate metadata over the API) - a
private-key field is nonetheless stripped defensively before
returning, in case a future RouterOS version or firmware quirk ever
adds one (same strip_sensitive_fields mechanism ppp_secrets/
wireguard_interfaces use). See
test_certificates_strips_private_key_defensively.
See also security_audit's certificate-expiry check (v1.6), which
flags an expired or soon-to-expire (<=30 days) certificate as a
finding using this same expiry logic.
Returns an empty list (never an error) for a device with no certificates configured.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |