This project demonstrates the certificate lifecycle for IoT devices in a oneM2M compliant system:
- Certificate generation
- Device authentication with valid certificate
- Certificate revocation
- Device authentication with revoked certificate
The project includes:
- OCSP (Online Certificate Status Protocol) for real-time certificate revocation checking
- SDS (Secret Discovery Service) for Envoy to dynamically retrieve certificates
The system implements a complete certificate lifecycle with the following components:
- IoT Device: Authenticates using X.509 certificates
- oneM2M Server: Validates device certificates and provides access to resources
- OCSP Responder: Provides real-time certificate status information
- Certificate Authority (CA): Issues and revokes certificates
- Secret Discovery Service (SDS): Provides certificate information to Envoy
- Envoy Proxy: Optional TLS termination and authentication layer
-
Certificate Generation
- Certificate Authority generates and provisions device certificate
- Certificate registered with SDS
-
Authentication with Valid Certificate
- Device connects through Envoy with its certificate
- Envoy validates certificate via SDS
- Server checks certificate status via OCSP
- Access granted if certificate is valid
-
Certificate Revocation
- Administrator revokes certificate via CA
- CA updates OCSP with revocation status
-
Authentication with Revoked Certificate
- Device attempts connection with revoked certificate
- Server checks certificate via OCSP
- OCSP reports revoked status
- Access denied
cert_revoke/
│
├── certificate_authority.py # Core CA functionality, certificate generation/revocation
├── server.py # oneM2M server with OCSP certificate validation
├── device.py # IoT device client for certificate-based authentication
├── admin.py # Admin tool for certificate management
├── ocsp_responder.py # OCSP server for certificate status verification
├── envoy_sds.py # Secret Discovery Service for Envoy integration
├── envoy.yaml # Envoy Proxy configuration
├── demo.py # Complete demo script
├── requirements.txt # Project dependencies
├── README.md # Project documentation
└── .gitignore # Git ignore rules
│
├── ca/ # Generated at runtime - Certificate storage
│ ├── certs/ # Public certificates
│ │ ├── ca_cert.pem # CA certificate
│ │ ├── device_*_cert.pem # Device certificates
│ │ └── issued_certs.json # Record of issued certificates
│ ├── private/ # Private keys (would be secured in production)
│ │ ├── ca_key.pem # CA private key
│ │ └── device_*_key.pem # Device private keys
│ └── crl/ # Certificate revocation information
│ └── revoked.txt # List of revoked certificate serial numbers
│
└── __pycache__/ # Python cache files (not committed)
+---------------+ +----------------+ +-----------------+
| Admin Tool | ---> | Certificate | <--- | oneM2M Server |
| (admin.py) | | Authority | | (server.py) |
+---------------+ | (cert_auth.py) | +-----------------+
+----------------+ ^
^ | |
| v |
+---------------+ +----------------+ +-----------------+
| IoT Device | ---> | OCSP Responder | <--- | Envoy Proxy |
| (device.py) | | (ocsp_resp.py) | | (envoy.yaml) |
+---------------+ +----------------+ +-----------------+
^
|
+-----------------+
| Secret Discovery|
| (envoy_sds.py) |
+-----------------+
This project aligns with the oneM2M security specifications for certificate-based authentication:
- The certificate lifecycle follows the oneM2M TS-0003 Security Solutions standard
- Certificate revocation uses OCSP as specified in oneM2M
- The implementation can be integrated with oneM2M CSEs (Common Service Entities)
- The authentication mechanism supports oneM2M entities (AEs, CSEs)
- Python 3.7+
- Dependencies listed in
requirements.txt - Envoy Proxy (optional, for SDS demo)
- Clone the repository:
git clone https://github.com/yourusername/cert_revoke.git
cd cert_revoke
- Create a virtual environment and activate it:
python -m venv venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- (Optional) Install Envoy Proxy for SDS demo:
- Follow instructions at https://www.envoyproxy.io/docs/envoy/latest/start/install
To run the certificate lifecycle demo with OCSP and Secret Discovery Service:
python demo.py
This will:
- Start the oneM2M server, OCSP responder, and SDS server
- Generate a certificate for a device
- Test certificate status using OCSP
- Test certificate retrieval using SDS
- Show successful authentication with the valid certificate
- Revoke the certificate
- Show failed authentication with the revoked certificate
# Start the oneM2M server
python server.py
# In another terminal, start the OCSP responder
python ocsp_responder.py
# In another terminal, start the SDS server
python envoy_sds.py
# Optional: Start Envoy proxy
envoy -c envoy.yaml
python admin.py generate device001
curl -X POST http://localhost:5002/ocsp \
-H "Content-Type: application/json" \
-d '{"serial_number": "<serial_number>"}'
curl -X POST http://localhost:5003/v3/discovery:secrets \
-H "Content-Type: application/json" \
-d '{"type_url": "type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.Secret", "resource_names": ["certificate:device001"]}'
python device.py device001
python admin.py revoke <serial_number>
certificate_authority.py: Implements the Certificate Authority (CA) functionality with OCSP extensionsserver.py: oneM2M server that validates certificates using OCSPdevice.py: IoT device client that authenticates using certificatesadmin.py: Administration tool for generating and revoking certificatesocsp_responder.py: OCSP responder for certificate status checkingenvoy_sds.py: Secret Discovery Service for Envoyenvoy.yaml: Envoy Proxy configuration with SDS integrationdemo.py: Demo showing the complete certificate lifecycle with OCSP and SDS
- Certificate Not Found: Make sure to generate the certificate before running the device
- Services Not Starting: Check port conflicts (5000, 5002, 5003)
- OCSP Connection Error: Make sure the OCSP responder is running
- SDS Connection Error: Make sure the SDS server is running
- Check log output from each service
- Use
--debugflag with device.py for more detailed logs - Verify certificate file paths
This is a simplified demonstration for educational purposes and is not suitable for production use without significant security enhancements:
- Uses HTTP instead of HTTPS for some services for demo simplicity
- Simplified certificate validation
- No protection against various security attacks
- Certificates and keys are not properly protected
- OCSP responses aren't signed (they should be in production)
- SDS implementation is simplified compared to production standards