Document Forensics & Verification
Relevant source files
The following files were used as context for generating this wiki page:
The Document Forensics & Verification system within TrueLens is a multi-layered security module designed to detect tampering, verify authenticity, and provide cryptographic proof for digital documents. It combines heuristic analysis of metadata, font consistency checks, OCR-based validation for specific document types (such as invoices and Aadhaar cards), and SHA-256 hashing to ensure document integrity.
The system serves both end-users through a drag-and-drop web interface and developers via a RESTful API. It processes various file formats, including PDF, PNG, JPG, and DOCX, routing them to specialized backend services that apply format-specific forensic techniques to generate a comprehensive "Trust Score."
Sources: truelens-backend/app/services/document_analysis.py:12-23, truelens-app/src/app/documents/page.tsx:88-106
System Architecture and Data Flow
The document verification workflow begins when a user uploads a file through the frontend. The file is sent to the backend API, where it is routed based on its MIME type to specific analysis functions.
The diagram above illustrates how documents are categorized and processed through specialized forensic checks before a final score is assigned.
Sources: truelens-backend/app/services/document_analysis.py:442-456, truelens-app/src/app/documents/page.tsx:44-72
Forensic Analysis Techniques
Metadata Integrity and Tool Detection
The system extracts PDF metadata (Producer, Creator, CreationDate, ModDate) to identify the software used to generate the document. It flags known PDF editing tools such as LibreOffice, Inkscape, and Scribus, as these are often used in forgery. Discrepancies between creation and modification dates result in a reduction of the trust score.
Sources: truelens-backend/app/services/document_analysis.py:108-137
Font Consistency Analysis
A primary signal for document splicing or "copy-paste" forgery is the presence of excessive font variety. The system parses individual character objects within a PDF to extract font names.
- Low Risk: 1-3 distinct fonts.
- Medium Risk: >3 fonts (indicates potential copy-paste).
- High Risk: >5 fonts (likely content spliced from multiple sources).
Sources: truelens-backend/app/services/document_analysis.py:146-177
Document Classification and Type-Specific Validation
TrueLens uses regex-based keyword patterns and filename analysis to classify documents into specific categories, enabling targeted validation logic.
| Document Type | Key Validation Logic | Penalty for Failure |
|---|---|---|
| Aadhaar Card | Verhoeff Checksum algorithm on 12-digit UID | -20 points |
| Invoice / Bill | Arithmetic sum check of line items vs. total | -15 points |
| Medical Prescription | Keyword detection (Rx, dosage, medical degrees) | N/A |
| Legal Contract | Legal terminology check (hereinafter, jurisdiction) | N/A |
Sources: truelens-backend/app/services/document_analysis.py:30-73, truelens-backend/app/services/document_analysis.py:304-342
Cryptographic Verification and API
Documents successfully analyzed are assigned a unique SHA-256 hash. This hash allows for later verification without re-analyzing the entire document.
Verification Flow
Users can verify a document's status using either the hash or a unique Scan ID. The system checks the database for a matching record and returns the original trust score, findings, and a verification signature.
Developer Interface
The service is exposed via several REST endpoints for integration:
| Method | Endpoint | Description |
|---|---|---|
POST | /api/v1/documents | Upload and analyze a new document. |
GET | /api/v1/documents | Retrieve history of analyzed documents. |
POST | /api/v1/verify | Verify a document using its SHA-256 hash. |
GET | /api/v1/documents/:hash/evidence | Download the full forensic evidence pack. |
Sources: truelens-app/src/app/developers/page.tsx:13-41, truelens-app/src/app/verify/page.tsx:181-188
Implementation Details (Python)
The backend utilizes pdfplumber for deep PDF inspection and pytesseract for OCR on scanned images. If a PDF is unreadable, it falls back to basic text extraction or OCR to maintain the analysis pipeline.
# Verhoeff Checksum for Aadhaar Validation
def _verhoeff_check(number: str) -> bool:
try:
c = 0
for i, digit in enumerate(reversed(number)):
c = _VERHOEFF_TABLE_D[c][_VERHOEFF_TABLE_P[i % 8][int(digit)]]
return c == 0
except (ValueError, IndexError):
return False
Sources: truelens-backend/app/services/document_analysis.py:369-378
Conclusion
The Document Forensics & Verification module provides a robust framework for identifying digital forgeries. By combining low-level structural analysis (fonts/metadata) with high-level semantic validation (Aadhaar checksums/invoice arithmetic), TrueLens offers a comprehensive trust assessment that is cryptographically verifiable via its signing and hashing architecture.