The Legal and Cryptographic Context of CSID Expiration
Under the Executive Regulations for Value Added Tax and the technical provisions of Royal Decree No. M/113, every electronic tax invoice generated in Saudi Arabia must carry cryptographic proof of authenticity.
The Production CSID embeds your company's Tax Registration Number (TRN), branch location, and unique Electronic Generation Solution (EGS) serial number. ZATCA assigns a strict 5-year cryptographic validity window to comply with international Public Key Infrastructure (PKI) standards. Over 5 years, underlying cryptographic elliptic curve parameters can degrade, and hardware changes require scheduled re-authentication.
Initial Onboarding
EGS generates secp256k1 keypair; ZATCA signs CSR; 5-year Production CSID issued
Live Operations
EGS signs B2B/B2C transactions daily; hash chain increments perpetually
Proactive Renewal Window
ERP automated alert triggers CSR generation; calls PATCH /production/csids
Expiration Cutoff
If unrenewed, ZATCA Trust Sub-CA revokes clearance authority; API blocks live transactions
Two Distinct Renewal Pathways: Pre-Expiration vs Post-Expiration
The exact technical workflow required to renew your CSID depends entirely on whether the certificate has already expired:
| Technical Parameter | Pathway A: Proactive Renewal (Active PCSID) | Pathway B: Emergency Renewal (Expired PCSID) |
|---|---|---|
| Certificate Status | Active / Valid (Recommended: 30–60 days before expiry) | Expired / Terminated |
| Fatoora Portal OTP Required? | NO. Zero manual portal intervention required. | YES. Authorized representative must generate 6-digit OTP. |
| API Method & Endpoint | PATCH /e-invoicing/core/production/csids | POST /compliance → PATCH /production/csids |
| Authentication Scheme | HTTP Basic Auth with existing active PCSID + secret. | Initial handshake via 6-digit OTP in HTTP header. |
| Compliance Invoicing Check | Bypassed. Direct production certificate rotation. | Mandatory. Must re-run the 6 compliance test invoices. |
| ERP Billing Downtime | 0 Seconds (Zero-Downtime Hot Swap). | Significant (Hours or Days of manual admin). |
Pathway A: Step-by-Step Proactive Renewal (Before Expiration)
Proactive renewal is designed for enterprise ERPs (SAP, Oracle, Odoo, custom software) that maintain scheduled token rotation jobs.
Step 1: Generate a Fresh Keypair and CSR
Using OpenSSL, generate a new secp256k1 private key and CSR. Ensure the Subject fields (TRN, EGS serial number, branch location, invoice capability flag) match the active device:
# 1. Generate a new private key
openssl ecparam -name secp256k1 -genkey -noout -out new_private_key.pem
# 2. Generate the CSR using your existing configuration file
openssl req -new -sha256 -key new_private_key.pem -extensions v3_req -config egs_config.cnf -out new_renewal.csr
# 3. Base64 encode the new CSR into a clean string
cat new_renewal.csr | base64 -w 0 > new_csr_base64.txtStep 2: Call the ZATCA Renewal API (PATCH /production/csids)
Construct an HTTP PATCH request to the core production gateway. Authenticate using your current, active Production CSID credentials:
PATCH /e-invoicing/core/production/csids HTTP/1.1
Host: gw-fatoora.zatca.gov.sa
Accept-Language: en
Accept-Version: V2
Content-Type: application/json
Authorization: Basic <Base64_Encoded(Old_BinarySecurityToken:Old_Secret)>Request JSON Body:
{
"csr": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURSBSRVFVRVNULS0tLS0KTUlJQmZ6Q0NBVU1DQVFBd1ZE...[NEW_CSR_BASE64]..."
}Step 3: Handle the API Response & Execute Atomic ERP Swap
Upon verification, ZATCA returns HTTP 200 OK:
{
"requestID": 2049182,
"dispositionMessage": "ISSUED",
"binarySecurityToken": "MIIEzDCCA7SgAwIBAgIQX8...[NEW_PRODUCTION_X509_CERTIFICATE]...",
"secret": "9a2f184b-012c-49a1-8d21-f0923841bc19",
"errors": null
}Within your database, execute an atomic transaction:
binarySecurityToken and new secret.new_private_key.pem.Pathway B: Step-by-Step Emergency Renewal (After Expiration)
If your team missed the renewal window and your PCSID has expired, ZATCA's API will reject all requests authenticated with that token. Follow this recovery sequence:
Portal Login
Tax agent logs into ZATCA ERAD Portal via Nafath Business Single Sign-On
Fatoora Platform Access
Navigate to E-Invoicing (Fatoora) Service → Onboarded Units Management
Revoke & Regenerate
Mark expired device as retired or request emergency renewal OTP
Compliance Cycle
Re-submit CSR via POST /compliance with OTP; pass 6 compliance sample invoices
Production Promotion
Promote verified device to a fresh Production CSID; restore live clearance
Step 1: Log in and Request a Renewal OTP
Step 2: Request Compliance CSID
Send an HTTP POST request to the /compliance endpoint:
POST /e-invoicing/core/compliance HTTP/1.1
Host: gw-fatoora.zatca.gov.sa
Accept-Language: en
Accept-Version: V2
OTP: 918240
Content-Type: application/json{
"csr": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURSBSRVFVRVNULS0tLS0K...[NEW_CSR_BASE64]..."
}Step 3: Pass Compliance Invoicing Checks
You must submit the mandatory compliance test document suite to /compliance/invoices:
Step 4: Promote to Production CSID
Once all sample documents return "status": "PASS", call PATCH /production/csids with the compliance_request_id to acquire your new Production CSID.
Enterprise Key Custody & Archival Requirements
When rotating cryptographic credentials, enterprise IT teams must adhere to strict data retention rules under Saudi tax law:
Statutory Safeguards & Rights Protection
Mandatory protections enforced by MHRSD & Saudi Labor Law
Real-World Case Study: Zero-Downtime Renewal for a Retail Supermarket Chain
In January 2026, a major Riyadh retail hypermarket chain operating 84 POS terminals reached its 5-year Phase 2 certificate anniversary:
secp256k1 keys, executed PATCH /production/csids in under 800 milliseconds per unit, and swapped credentials in the local SQLite cache without restarting POS hardware.Common Renewal Errors & Immediate Developer Fixes
| HTTP Status / Error Code | Underlying Technical Cause | Immediate Developer Resolution |
|---|---|---|
| `401 Unauthorized: Expired Certificate` | Attempted to use an already-expired PCSID to authenticate a proactive PATCH renewal request. | The proactive window has passed. You must generate a fresh OTP on the Fatoora Portal and execute Pathway B. |
| `400 Bad Request: Invalid Common Name` | The Common Name (CN) inside the renewal CSR does not match the original EGS serial number on ZATCA records. | Ensure CN in the OpenSSL configuration matches the exact serial identifier registered during initial onboarding. |
| `400 Bad Request: Missing OID 0.9.2342...` | The renewal CSR omitted the taxpayer VAT number OID or used an improper ASN.1 structure. | Review the OpenSSL configuration file and verify that the 15-digit TRN is present under the custom ZATCA OID tag. |
| `Signature Verification Failed` | The ERP attempted to sign live invoices with the new CSID using the old private key. | Ensure the private key file path in your ERP signing engine is updated simultaneously with the certificate token. |
| `Hash Chain Broken on First New Invoice` | The developer reset the ICV counter to 1 upon installing the new CSID certificate. | Do not reset ICV. Maintain the continuous counter sequence (N + 1) and link to the previous invoice's SHA-256 hash. |
Frequently Asked Questions (FAQ)
Can I renew my ZATCA CSID certificate before the 5-year expiration date?
Yes. Proactive renewal is strongly recommended between 30 and 60 days before your expiration date. Renewing proactively via the PATCH /production/csids API endpoint avoids the need to request a portal OTP or re-run compliance testing.
Does renewing a CSID reset the Invoice Counter Value (ICV)?
No. The Invoice Counter Value (ICV) is perpetual and belongs to the ongoing transaction sequence of your establishment. Renewing or rotating a certificate must never reset the ICV to 1.
What happens if an invoice is submitted to ZATCA using an expired CSID?
The ZATCA API immediately rejects the transaction with HTTP 401 Unauthorized / CERTIFICATE_EXPIRED. The invoice is not cleared, has zero legal tax validity, and the buyer cannot claim input VAT on the purchase.
Can an ERP vendor renew CSID certificates automatically without client permission?
An ERP system can automatically renew certificates via API only if the current PCSID is still valid and the software has been granted programmatic authorization to call the PATCH endpoint. If the certificate has expired, the client must log into the Fatoora Portal via Nafath to issue a new OTP.
Does changing our company's commercial name require a new CSID?
Yes. Because the legal company name is cryptographically sealed into the Subject of the X.509 certificate, updating your commercial name or registered branch address requires generating a new CSR and updating your certificate credentials.
Was this compliance guide helpful?
Your feedback helps our legal editorial team maintain authoritative KSA guidance.
Advocate High Court (Punjab Bar Council) and ATT GCC VAT Certified Specialist. Author of comprehensive regulatory commentaries on Saudi corporate law, ZATCA e-invoicing protocols, and Labor Reform Initiatives.