Sistema di gestione e notarizzazione documentale su blockchain con condivisione sicura.
| Componente | Tecnologia |
|---|---|
| Blockchain | Hyperledger Fabric 2.5 |
| Chaincode | Go 1.21+ |
| Backend | Python 3.10+ / Flask 3.0 |
| Storage documenti | IPFS |
| Identità | Fabric CA (certificati X.509) |
| DB utenti | SQLite |
| Client Fabric | peer CLI via subprocess |
Utente
│
▼
Flask App (webapp/)
├── Autenticazione → fabric-ca-client (register/enroll) → wallet X.509
├── Upload documento → IPFS → CID + SHA-256
└── Chaincode → peer CLI → Hyperledger Fabric
└── (CID, hash, owner, timestamp, ACL)
- Registrazione — Flask chiama
fabric-ca-client register(admin autentica) e poi fa enrollment HTTP sulla CA, ottenendo un certificato X.509 salvato nel wallet locale - Login — autenticazione Flask con SQLite, wallet caricato al primo uso
- Upload — file caricato su IPFS, CID + hash SHA-256 registrati on-chain via
peer chaincode invoke - Notarizzazione — hash SHA-256 on-chain come prova crittografica di esistenza
- Condivisione — il proprietario aggiunge utenti all'ACL del documento on-chain
- Verifica integrità — scarica il file da IPFS, ricalcola SHA-256, confronta con on-chain
- Audit trail — storico completo di ogni modifica via
GetHistoryForKeydi Fabric
docchain/
├── bin/ # Binari Fabric (peer, fabric-ca-client, configtxgen…)
├── config/ # core.yaml, configtx.yaml (da download Fabric)
├── chaincode/
│ └── docchain/
│ ├── chaincode.go # Smart contract (UploadDoc, ShareDoc, VerifyDoc…)
│ ├── go.mod
│ └── go.sum
├── network/
│ ├── docker-compose.yaml # CA, orderer, peer, CLI
│ ├── configtx.yaml # Configurazione canale
│ ├── connection-profile.json # Generato da bootstrap (non committato)
│ └── organizations/ # Certificati generati (non committati)
├── scripts/
│ ├── bootstrap.sh # Avvia rete, genera crypto, deploya chaincode
│ └── teardown.sh # Ferma e pulisce tutto
└── webapp/
├── app/
│ ├── __init__.py # Flask app factory + init SQLite
│ ├── auth.py # Blueprint: /auth/login, /register, /logout
│ ├── documents.py # Blueprint: upload, download, share, verify
│ ├── fabric.py # Client Fabric (subprocess peer + CA REST)
│ ├── ipfs.py # Client IPFS
│ └── models.py # User model (SQLite + Flask-Login)
├── static/
│ ├── css/style.css
│ └── js/main.js
├── templates/
│ ├── base.html
│ ├── auth/
│ └── documents/
├── config.py
├── run.py
├── requirements.txt
└── .env
| Funzione | Chi può chiamarla | Descrizione |
|---|---|---|
UploadDoc |
Chiunque | Registra documento (CID, hash, owner, timestamp) |
ShareDoc |
Solo owner | Aggiunge utente all'ACL |
RevokeAccess |
Solo owner | Rimuove utente dall'ACL |
RevokeDocument |
Solo owner | Soft delete (rimane per audit) |
VerifyDoc |
Chiunque | Verifica hash SHA-256 |
GetDocMetadata |
Owner + ACL | Legge metadati |
GetDocHistory |
Solo owner | Audit trail completo |
ListMyDocs |
Chiunque | Lista documenti propri |
ListSharedWithMe |
Chiunque | Lista documenti condivisi |
- Docker Desktop
- Go 1.21+
- Python 3.10+
- IPFS Desktop
I binari Fabric vengono scaricati automaticamente nella cartella bin/.
# 1. Clona il repository
git clone <repo-url>
cd docchain
# 2. Scarica i binari Hyperledger Fabric
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.5.15 1.5.17 -s
export PATH=$PWD/bin:$PATH
# 3. Avvia la rete Fabric (CA, orderer, peer, deploy chaincode)
./scripts/bootstrap.sh
# 4. Crea il virtual environment e installa le dipendenze Python
python -m venv .venv
source .venv/Scripts/activate # Windows (Git Bash)
# source .venv/bin/activate # Linux/macOS
pip install -r webapp/requirements.txt
# 5. Avvia IPFS Desktop
# 6. Avvia la webapp
cd webapp && python run.py
# → http://localhost:5000Crea webapp/.env (già incluso con i default):
FLASK_DEBUG=true
FLASK_SECRET_KEY=cambia-in-produzione
FABRIC_ORG=Org1
FABRIC_CA_URL=https://localhost:7054
FABRIC_CHANNEL=mychannel
FABRIC_CHAINCODE=docchain
FABRIC_PEER_ADDRESS=localhost:7051
FABRIC_ORDERER_ADDRESS=localhost:7050
IPFS_HOST=127.0.0.1
IPFS_PORT=5001
./scripts/teardown.sh