Blockchain-Based Chain of Custody (B-COC): Revolutionizing Evidence Management for Law Enforcement 🚓🔒
Introduction
The management of evidence in criminal investigations is one of the most critical tasks in law enforcement. Traditionally, evidence handling has relied on paper-based Chain of Custody (CoC) systems, which are prone to human errors, tampering, and inefficiencies. With the advent of blockchain technology, it's now possible to ensure a more secure, transparent, and immutable process.
In this blog post, I will showcase my application, Blockchain-Based Chain of Custody (B-COC), which utilizes blockchain to streamline evidence management, providing law enforcement agencies with a tamper-proof, auditable, and real-time system for tracking investigative artifacts.
What Is B-COC? 🤔
Blockchain-Based Chain of Custody (B-COC) is a comprehensive application designed to:
Replace paper-based systems for tracking evidence in police investigations.
Create tamper-proof records by utilizing blockchain technology.
Provide law enforcement officers and admins with an easy-to-use, secure, and efficient way to handle evidence.
The application works by assigning each artifact (e.g., evidence, products, or investigation materials) to a dedicated blockchain running on its own port. This ensures that each artifact's data is securely logged and traceable, reducing the risk of tampering and providing transparent proof of every action taken with the evidence.
Core Features of B-COC 🚀
1. Decentralized Blockchain Instances:
Each artifact is assigned its own blockchain, which is hosted on a unique port. This allows every artifact to have its own isolated record, ensuring that there is no cross-contamination of data between different artifacts.
2. Immutable Data Records:
Using SHA256 cryptographic hashing, every action related to an artifact (such as check-in and check-out) is logged as a unique block on the blockchain. These blocks cannot be altered or deleted, guaranteeing the integrity and authenticity of the Chain of Custody.
3. Real-Time Tracking and Transparency:
With real-time logs and auditable history, every action taken by officers, from checking out an artifact to returning it, is fully traceable. This provides transparency in handling the evidence, making the process both efficient and trustworthy.
4. Role-Specific Permissions:
Admins: Can create and assign artifacts to specific blockchain instances.
Officers: Can check out artifacts for investigation or hearings, and check them back in when done.
5. Secure and Transparent Record Handling:
Every action in the system is tied to the officer's identity, ensuring accountability. By using blockchain, we eliminate the possibility of tampering or unauthorized access to the evidence.
How Does B-COC Work? 🛠️
Step 1: Artifact Creation (Admin Role)
Admins can add new products or artifacts to the system, assigning each one a dedicated blockchain instance. Each artifact is linked to a unique port, and the artifact’s details (such as ID, description, status, etc.) are recorded on the blockchain.
Step 2: Artifact Handling (Police Officer Role)
Once an artifact is created, police officers can:
Log in to their portal and check out the artifact for investigation or court hearings.
The officer’s details (name, timestamp, and action) are added to a new block on the artifact's blockchain.
After the artifact is used, the officer can check it back in, and a new block is added to confirm the artifact’s return.
Step 3: Immutable Blockchain Records
Each transaction—whether a check-out or check-in—creates a unique, cryptographically secured block in the blockchain. This ensures:
No tampering: Data once written to the blockchain cannot be altered.
Complete traceability: All actions are recorded and can be traced back to the exact time and officer responsible.
Why Blockchain for Chain of Custody? 🤔
The implementation of blockchain technology provides several key benefits:
Security: Every action taken is logged in a cryptographically secure manner.
Accountability: Officers' identities are tied to their actions, ensuring transparency and accountability.
Immutability: Once data is recorded, it cannot be altered or deleted, preventing tampering.
Transparency: The complete history of an artifact is visible and auditable at any time.
This ensures that law enforcement agencies can maintain the highest standards of evidence integrity, reducing the potential for errors, fraud, or mishandling of critical artifacts.
Tech Stack Used 💻🔧
The B-COC application leverages the following technologies to ensure performance, security, and reliability:
1. Go (Golang):
- The core logic of the blockchain is implemented using Go, known for its simplicity and efficiency. Go's concurrency model ensures that multiple blockchain instances can run simultaneously without issues.
2. Blockchain & SHA256 Hashing:
Blockchain technology powers the system’s integrity by linking blocks together using SHA256 hashing, creating a secure and immutable chain of records.
Cryptographic hashing ensures that even small changes in data will result in a completely different hash, making tampering detectable.
3. Gorilla Mux:
- Gorilla Mux is used for routing HTTP requests. It helps manage the different API endpoints for interacting with the blockchain, such as checking in or checking out artifacts.
4. Dotenv:
- The dotenv package is used to manage environment variables, such as port numbers for each artifact’s blockchain instance, ensuring flexibility in deployment.
How to Get Started with B-COC 🚀
Step 1: Clone the Repository
git clone https://github.com/WhoIsFawaz/Blockchain-Based-Chain-of-Custody.git
Step 2: Install Dependencies
Make sure you have Go installed, then run:
go get github.com/davecgh/go-spew
go get github.com/gorilla/mux
go get github.com/joho/godotenv
Step 3: Configure Port for Each Artifact
Create a .env
file for each artifact you wish to track and specify a port number (e.g., PORT=3001
for the first artifact).
Step 4: Run the Blockchain for the Artifact
PORT=3001 go run main.go
Repeat for each artifact with a unique port number.
Step 5: Interact with the System
Use Postman or curl to interact with the blockchain endpoints:
GET
/
to retrieve the blockchain history.POST
/
to add a new block when checking out or returning an artifact.
Blockchain Architecture and Implementation🔒
In this section, we will break down the key components of the blockchain implementation, highlighting how data is structured, how new blocks are generated, and how hashing ensures data integrity.
1. Block Structure 🗂️
The Block
structure represents a unit of data in our blockchain. It holds the critical information related to an artifact being tracked, including:
Index: A sequential number that identifies the block.
ProductId: The unique identifier for the artifact.
ProductModel: The model or type of the artifact.
User: The name of the officer or user handling the artifact.
Status: Whether the artifact is checked in or checked out.
Timestamp: The exact time the block was created.
PrevHash: The hash of the previous block, linking the chain.
Hash: The unique cryptographic hash of the current block.
The Blockchain
is an array of Block
objects, where each new block is validated and appended to the array as it is created.
type Block struct {
Index int
ProductId string
ProductModel string
User string
Status string
Timestamp string
PrevHash string
Hash string
}
var Blockchain []Block
2. Calculate Hash 🔐
The calculateHash
function computes a cryptographic hash for the current block using SHA256 hashing. This function combines the block’s properties, including the Index
, ProductId
, ProductModel
, User
, Status
, Timestamp
, and the PrevHash
, to create a unique hash for the block.
The SHA256 algorithm ensures that even a small change in any field will result in a completely different hash, thus ensuring data integrity and immutability.
func calculateHash(block Block) string {
record := strconv.Itoa(block.Index) + block.ProductId + block.ProductModel + block.User + block.Status + block.Timestamp + block.PrevHash
h := sha256.New()
h.Write([]byte(record))
hashed := h.Sum(nil)
return hex.EncodeToString(hashed)
}
3. Generate Block 🔄
The generateBlock
function creates a new block based on the previous block’s hash. It increments the Index
, adds the relevant metadata for the new artifact (like ProductId
, ProductModel
, User
, Status
), and calculates the hash for the new block.
Each new block is tied to the previous block by referencing its PrevHash
. This guarantees the integrity of the blockchain, ensuring that any change in a previous block will invalidate subsequent blocks.
func generateBlock(oldBlock Block, ProductId string, ProductModel string, User string, Status string) Block {
var newBlock Block
t := time.Now()
newBlock.Index = oldBlock.Index + 1
newBlock.ProductId = ProductId
newBlock.ProductModel = ProductModel
newBlock.User = User
newBlock.Status = Status
newBlock.Timestamp = t.String()
newBlock.PrevHash = oldBlock.Hash
newBlock.Hash = calculateHash(newBlock)
return newBlock
}
4. Message Structure 📬
To facilitate the exchange of data between the front-end and the blockchain, we use a simple Message
structure. This structure contains the key fields—ProductId
, ProductModel
, User
, and Status
—that are sent as a JSON payload in the POST request.
Additionally, we use a mutex
to handle concurrency and ensure that the blockchain is updated safely when multiple users or processes interact with it simultaneously.
type Message struct {
ProductId string
ProductModel string
User string
Status string
}
var mutex = &sync.Mutex{}
5. Genesis Block 🌱
The Genesis Block is the first block in the blockchain, and it is crucial for initializing the chain. The genesisBlock
is created with placeholder values (such as "No Product ID"
and "No Status"
) and serves as the foundation for all subsequent blocks.
Once created, the genesis block is appended to the blockchain array, and its hash is used as the PrevHash
for the next block.
go func() {
time := time.Now()
genesisBlock := Block{}
genesisBlock = Block{0, "No Product ID", "No Product Model", "No User", "No Status", time.String(), "", calculateHash(genesisBlock)}
spew.Dump(genesisBlock)
mutex.Lock()
Blockchain = append(Blockchain, genesisBlock)
mutex.Unlock()
}()
Future Improvements 🔮
While B-COC provides an efficient and secure solution for evidence management, several enhancements are planned to improve the application:
QR Code Integration: Allow officers to scan QR codes for quick check-in and check-out.
Mobile App: Build a mobile application for on-the-go evidence handling.
Blockchain Visualization: Create an interactive dashboard to visualize blockchain data and artifact histories.
Conclusion 🎯
By integrating blockchain technology into evidence management, B-COC ensures a secure, transparent, and tamper-proof process for law enforcement agencies. This solution eliminates the inefficiencies and vulnerabilities of traditional paper-based systems, providing peace of mind that every action related to an artifact is accurately recorded and auditable.
The future of Chain of Custody is here—powered by blockchain! 🚀🔒
Feel free to fork the GitHub repository and contribute your improvements and have fun!
Image Dump!!!