Deterministic PII Redaction for OCPP 1.6 logs.
Project description
OCPP-Anonymizer: Deterministic PII Redaction
A Python library for anonymizing OCPP log files while preserving the ability to trace sessions and identify unique devices.
The Problem
OCPP (Open Charge Point Protocol) logs are essential for debugging EV charging issues, but they often contain Personally Identifiable Information (PII) and other sensitive data. This includes:
idTag: A user's unique identifier (e.g., RFID card number).- Hardware Identifiers:
chargeBoxSerialNumber,iccid,imsi, etc. - Transaction Data:
transactionIdwhich links charging sessions.
Exposing this data can lead to privacy violations and security risks, making it difficult to share logs with developers or third parties.
The Solution
This library redacts sensitive information by replacing it with a deterministic SHA256 hash. This means:
- Anonymity: The original value cannot be reverse-engineered.
- Traceability: The same input value (e.g., the same
idTag) will always produce the same hash token. This allows you to track a user's activity across multiple log lines without knowing their actual identity.
The library also handles special cases like masking credentials in URLs and redacting AuthorizationKey values.
Installation
pip install ocpp-anonymizer
Usage
You can use the library in two primary ways:
1. Processing a Raw Log Line
If you have raw log files in the format CP_ID : direction [JSON_PAYLOAD], you can process them line by line.
from ocpp_anonymizer import process_log_line
raw_log = 'CP123 : receive [2, "12345", "StartTransaction", {"idTag": "USER1", "meterStart": 100}]'
anonymized_log = process_log_line(raw_log)
# The output will have the CP_ID and idTag hashed
print(anonymized_log)
# e.g., 'a1b2c3d4e5f6a7b8 : receive message [2, "12345", "StartTransaction", {"idTag": "f242c797e74b89bb", "meterStart": 100}]'
2. Anonymizing a Structured JSON Payload
If you have already parsed the JSON part of an OCPP message, you can anonymize the payload directly.
from ocpp_anonymizer import anonymize_payload
action = "StartTransaction"
payload = {"idTag": "USER1", "meterStart": 100}
anonymized_payload = anonymize_payload(action, payload)
print(anonymized_payload)
# {'idTag': 'f242c797e74b89bb', 'meterStart': 100}
Configuration
IMPORTANT: Set the Secret Salt
The library uses a deterministic hashing algorithm, which requires a secret salt. For security, it is crucial to use a unique, randomly generated salt in your environment.
You should set the OCPP_ANONYMIZER_SECRET_SALT environment variable to a long, random string.
Example:
export OCPP_ANONYMIZER_SECRET_SALT="a_very_long_and_random_secret_string_12345"
If this environment variable is not set, the library will use a default, insecure salt and print a UserWarning.
Running Tests
To run the tests, first install the package in editable mode:
pip install -e .
Then, run the tests using the following command:
OCPP_ANONYMIZER_SECRET_SALT="test_salt" python3 -m unittest discover tests
Contributing
Contributions are welcome! If you find a sensitive field that is not yet mapped in ocpp_anonymizer/mapping.py, please open an issue or submit a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ocpp_anonymizer-0.1.0.tar.gz.
File metadata
- Download URL: ocpp_anonymizer-0.1.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88723e928c82b863eee28ab94d746816df8754a36947c88314b6153994ae2562
|
|
| MD5 |
5197754a87df7e5ebd52d86c8621e009
|
|
| BLAKE2b-256 |
32241c148790023b55bbd931a3e76149bb09f7bf64afdcf0797496f20dba0425
|
Provenance
The following attestation bundles were made for ocpp_anonymizer-0.1.0.tar.gz:
Publisher:
publish-to-pypi.yml on Kurappika/ocpp-anonymizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocpp_anonymizer-0.1.0.tar.gz -
Subject digest:
88723e928c82b863eee28ab94d746816df8754a36947c88314b6153994ae2562 - Sigstore transparency entry: 714601277
- Sigstore integration time:
-
Permalink:
Kurappika/ocpp-anonymizer@3863065c5178db55950b9a8010d536ebce88c445 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Kurappika
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@3863065c5178db55950b9a8010d536ebce88c445 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ocpp_anonymizer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ocpp_anonymizer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb8c8d2bd8aee3a327b9fe8355c04d28a5e04101b09ce930d6a36f5d0dc3e370
|
|
| MD5 |
85fb6b9da8e0c35f5fa86cb96bf64e3f
|
|
| BLAKE2b-256 |
87aa5161f8ed7069fb682c1689936579aaca60cf7f2cf4e7a64fb80665467c57
|
Provenance
The following attestation bundles were made for ocpp_anonymizer-0.1.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on Kurappika/ocpp-anonymizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocpp_anonymizer-0.1.0-py3-none-any.whl -
Subject digest:
bb8c8d2bd8aee3a327b9fe8355c04d28a5e04101b09ce930d6a36f5d0dc3e370 - Sigstore transparency entry: 714601289
- Sigstore integration time:
-
Permalink:
Kurappika/ocpp-anonymizer@3863065c5178db55950b9a8010d536ebce88c445 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Kurappika
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@3863065c5178db55950b9a8010d536ebce88c445 -
Trigger Event:
push
-
Statement type: