Back to Projects

Decentralized-Access-Control

TypeScript0 Stars🔄 0 Forks

SecureChain: Decentralized Access Control for Medical Reports Using Smart Contracts and Attribute-Based Encryption

Solidity Django Next.js IPFS CP-ABE

An enterprise-grade, real-world implementation of the 8th Semester Capstone Engineering Project based on the research paper:

"Decentralized Access Control for Medical Reports Using Smart Contracts and Attribute-Based Encryption"


1. System Architecture

┌──────────────────────────────────────────────┐ │ NEXT.JS 14 FRONTEND │ │ - Patient Portal (Policy Builder & Revoke) │ │ - Doctor Portal (Decryption & PDF Viewer) │ │ - Hospital Admin (KYC & Attribute Mgmt) │ └──────────────┬───────────────────────────────┘ │ ┌───────────────────┴───────────────────┐ │ Web3 (MetaMask / Ethers.js) │ REST APIs (JSON) ▼ ▼ ┌───────────────────────────────┐ ┌───────────────────────────────────┐ │ BLOCKCHAIN LAYER │ │ DJANGO BACKEND │ │ (Ethereum / Hardhat) │ │ (Django REST Framework) │ │ - MedicalRegistry.sol │ │ - Attribute Authority (AA) │ │ - AccessControlManager.sol │◄────┤ - CP-ABE + AES-256 Hybrid Crypto │ │ - AuditLogger.sol │Web3 ├─────────────────┬─────────────────┘ └───────────────────────────────┘ │ │ │ ▼ │ ┌───────────────────────┐ │ │ IPFS STORAGE │ └────►│ (Encrypted Payloads) │ └───────────────────────┘


2. Key Modules Implemented

  1. Smart Contracts (contracts/):
  2. MedicalRecordRegistry.sol: Decentralized registry binding record IDs to IPFS CIDs, patient owners, and policy hashes.
  3. AccessControlManager.sol: Role-based access validation, dynamic on-chain revocation ($\le 0.5\text{s}$), and Break-Glass emergency override.
  4. AuditLogger.sol: Immutable HIPAA/GDPR audit ledger recording every registration, access attempt, and revocation.

  5. Attribute Authority & Cryptographic Engine (backend/):

  6. CP-ABE Hybrid Encryption: Encrypts raw files using AES-256-GCM and encrypts the symmetric key using Ciphertext-Policy Attribute-Based Encryption.
  7. KeyGen Service: Generates collusion-resistant secret key components for clinicians based on their verified medical attributes (e.g. Role:Doctor, Dept:Cardiology).
  8. IPFS Vault Service: Zero-knowledge off-chain decentralized storage with deterministic cryptographic CID calculation (and Pinata Cloud support).

  9. Modern Web Portals (frontend/):

  10. Patient Portal (/patient): File dropzone, visual Boolean policy builder, real-time revocation toggles, and patient audit feed.
  11. Doctor Portal (/doctor): Identity card, patient record directory, real-time CP-ABE decryption viewer, and Break-Glass emergency mode.
  12. Hospital Admin Portal (/admin): Doctor KYC verification, CP-ABE key generation, and system-wide HIPAA audit table.

3. Quick Start Guide (Ready for Anyone to Use)

For Fresh Computers / Classmates / Evaluators:

  1. First-Time Setup (Automated):
  2. Double-click setup_and_install.bat.
  3. This automatically checks for Python & Node.js (and installs them if missing), configures the Python virtual environment, compiles the Solidity contracts, applies database migrations, seeds the database, and installs all Next.js dependencies.

  4. Run Everything:

  5. Double-click start_all.bat.
  6. Both the Django REST API (http://127.0.0.1:8000) and the Next.js Web App (http://localhost:3000) will launch automatically in their own terminal windows.

Or Run Manually:

1. Backend (Django):

bash cd backend ..\backend\venv\Scripts\python.exe manage.py runserver 127.0.0.1:8000

2. Frontend (Next.js):

bash cd frontend npm run dev Open http://localhost:3000 in your browser.

3. Smart Contracts (Hardhat Node & Tests):

bash cd contracts npx hardhat test # Runs automated contract test suite npx hardhat node # Starts local Ethereum node


4. Live Viva / Defense Demonstration Flow (3 Minutes)

  1. Step 1: Patient Uploads Report
  2. Open http://localhost:3000/patient.
  3. Select a sample report (e.g., Cardiac Echo PDF).
  4. Use the Visual Policy Builder to set the policy: (Role:Doctor AND Dept:Cardiology) OR Emergency:True.
  5. Click Encrypt & Pin to IPFS. Notice the generated IPFS CID and instant encryption.

  6. Step 2: Authorized Doctor Decrypts Report

  7. Open http://localhost:3000/doctor.
  8. Select Dr. Sarah Jenkins (Cardiologist). Her attributes match the policy.
  9. Click Decrypt & View. The report opens immediately in the secure in-browser PDF viewer.

  10. Step 3: Unauthorized Access Rejection

  11. In the Doctor Portal, switch to Dr. Marcus Vance (Dermatologist).
  12. Attempt to decrypt the Cardiology record.
  13. The system mathematically rejects decryption and logs an unauthorized access attempt to the HIPAA audit ledger.

  14. Step 4: Dynamic Revocation in < 0.5s

  15. Go back to the Patient Portal and click Revoke Access on the record.
  16. Return to Doctor Portal. Even authorized doctors are now locked out immediately without central IT intervention.

5. Comparison with Existing Systems (Paper Table II)

| Feature | SecureChain (Ours) | MedRec | FHIRChain | | :--- | :--- | :--- | :--- | | Decentralization | Full | Partial | Full | | Access Granularity | Fine-Grained (CP-ABE) | Coarse | Medium | | Encryption | CP-ABE + AES-256 | Symmetric | Public Key | | Revocation Speed | < 0.5s | 2.0s | 1.5s | | Audit Integrity | Ethereum Immutability | Database | Consortium | | HIPAA Compliance | Full | Partial | Full |