This API allows you to add, revoke, and query certificates in the database used by the OCSP server.
To enable the API, add the following parameters to your config.toml file:
# API Configuration
enable_api = true # Enable the API
api_keys = ["your-secure-api-key"] # List of valid API keysAPI keys should be random, hard to guess, and unique. Here are different methods to generate secure API keys:
The simplest way to generate a secure API key is using OpenSSL:
# Generate a 32-byte random hexadecimal string
openssl rand -hex 32Example output: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6
After generating an API key, add it to the api_keys array in your config.toml file.
All API requests must include an X-API-Key header with a valid API key.
To use this API, you need the certificate number in the correct format (with 0x prefix and lowercase hexadecimal digits). You can extract a certificate's serial number and format it properly using this command:
openssl x509 -in your_certificate.pem -serial -noout | awk -F= '{print "0x" tolower($2)}'This will output the certificate number in the exact format required by the API endpoints (e.g., 0x3b6ea97e1bf7699397e2109846e4f356be982542).
GET /api/health
Returns "OK" if the service is available.
POST /api/certificates
Request Body:
{
"cert_num": "0x123456789ABCDEF"
}Example Response:
{
"cert_num": "0x123456789ABCDEF",
"status": "Valid",
"message": "Certificate added successfully"
}POST /api/certificates/revoke
Request Body:
{
"cert_num": "0x123456789ABCDEF",
"reason": "key_compromise",
"revocation_time": "2025-03-18T12:00:00" // Optional, uses the current time if not provided
}Valid revocation reasons are:
unspecifiedkey_compromiseca_compromiseaffiliation_changedsupersededcessation_of_operationcertificate_holdprivilege_withdrawnaa_compromise
Example Response:
{
"cert_num": "0x123456789ABCDEF",
"status": "Revoked",
"message": "Certificate revoked successfully"
}GET /api/certificates/{cert_num}
Example Response:
{
"cert_num": "0x123456789ABCDEF",
"status": "Valid",
"message": "Certificate status retrieved: Valid"
}GET /api/certificates
Optional parameters:
status: Filter by status (Valid,Revoked, orall)- If no
statusparameter is provided orstatus=allis used, all certificates will be returned - Use
status=Validto return only valid certificates - Use
status=Revokedto return only revoked certificates
- If no
Example Response:
[
{
"cert_num": "0x123456789ABCDEF",
"status": "Valid",
"message": ""
},
{
"cert_num": "0x987654321FEDCBA",
"status": "Revoked",
"message": ""
}
]curl -X POST http://localhost:9000/api/certificates \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{"cert_num": "0x123456789ABCDEF"}'curl -X POST http://localhost:9000/api/certificates/revoke \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{"cert_num": "0x123456789ABCDEF", "reason": "key_compromise"}'curl -X GET http://localhost:9000/api/certificates/0x123456789ABCDEF \
-H "X-API-Key: your-api-key"curl -X GET "http://localhost:9000/api/certificates?status=Valid" \
-H "X-API-Key: your-api-key"curl -X GET "http://localhost:9000/api/certificates?status=all" \
-H "X-API-Key: your-api-key"