Skip to main content

Hardened, self-destructing memory cells for Python secrets, powered by Rust.

Project description

cypher_cell

Python Versions License Unit Tests Latest Release Platform Rust Backend

Hardened, self-destructing memory cells for Python secrets, powered by Rust.

cypher_cell is a Python extension module (written in Rust) that provides a secure, zero-leakage memory container for sensitive data such as API keys, passwords, cryptographic material, and tokens. Unlike standard Python strings and bytes, which are immutable, interned, and can linger in RAM or swap, cypher_cell ensures your secrets are:

  • Locked in RAM: Prevented from being swapped to disk using OS-level memory locking.
  • Zeroized: Overwritten with zeros immediately when no longer needed, leaving no trace in memory.
  • Ephemeral: Optionally destroyed after a single access or a configurable time-to-live (TTL).
  • Leak-resistant: Never exposed in logs, tracebacks, or accidental prints.

Why use cypher_cell?

Python's default memory model is not designed for handling secrets. Sensitive data can be copied, cached, or swapped to disk without your control. Attackers with access to memory dumps, swap files, or process introspection tools can easily recover secrets. cypher_cell is designed for developers and security engineers who need:

  • In-memory protection for credentials in long-running apps, CLI tools, or servers
  • Defense-in-depth for cryptographic operations
  • Secure handling of ephemeral secrets (e.g., one-time tokens, session keys)
  • Compliance with security standards that require memory zeroization

Features

  • 🔒 Memory Locking: Prevents secrets from being swapped to disk (OS-level protection).
  • 🧹 Guaranteed Zeroization: Memory is physically overwritten with zeros the moment the object is dropped or expires.
  • 👻 Volatile Mode: "Burn-after-reading" logic—the cell wipes itself immediately after one access.
  • ⏳ Time-To-Live (TTL): Secrets automatically vanish after a configurable duration.
  • 🛡️ Anti-Leak repr: Prevents accidental logging; print(cell) always shows [REDACTED].

🛡️ Advanced Hardening Features

cypher_cell includes several advanced memory and security hardening techniques beyond standard secret management:

Feature Implementation Benefit
Direct Env Loading from_env Secrets loaded directly from environment variables, never touching Python's heap.
Timing Protection verify (constant-time) Protects against timing attacks by using constant-time comparison for secret verification.
Anti-Core Dump MADV_DONTDUMP On Linux, secrets are excluded from core dumps if the process crashes.
Anti-Fork MADV_DONTFORK Prevents child processes from inheriting secret memory regions.
Binary Safety reveal_bytes Safely handles raw cryptographic keys and binary secrets, even if not valid UTF-8.

Implementation Details

  • Direct Env Loading: CypherCell.from_env("VAR") loads secrets directly from environment variables, minimizing exposure to Python's garbage-collected memory.
  • Timing Protection: The verify() method uses constant-time comparison to prevent attackers from inferring secrets via timing analysis.
  • Anti-Core Dump: On Linux, memory is marked with MADV_DONTDUMP so secrets are never written to disk in crash dumps.
  • Anti-Fork: Memory is marked with MADV_DONTFORK so child processes cannot inherit secret memory.
  • Binary Safety: reveal_bytes() allows safe handling of raw binary secrets (e.g., cryptographic keys) that may not be valid UTF-8, avoiding crashes and leaks.

🚀 Installation

Clone and build locally:

git clone https://github.com/Rivendael/cypher_cell.git
cd cypher_cell
pip install maturin
maturin develop

🛠 Usage

⚠️ Pro Tip: To prevent the secret from ever hitting the Python heap, avoid CypherCell(b"my-secret"). Instead, use CypherCell.from_env("MY_SECRET") or (in future) CypherCell.from_file("/path/to/key") to load secrets directly from secure sources.

1. Basic Secure Vault

Keep a secret locked in RAM and ensure it is wiped as soon as you are done.

from cypher_cell import CypherCell

# Use as a Context Manager for maximum safety
with CypherCell(b"super-secret-key") as cell:
    # Use the secret
    db_connect(cell.reveal())
# Memory is now zeroed and unlocked

2. "Mission Impossible" Cell (Volatile + TTL)

Create a secret that disappears after one read or 30 seconds, whichever comes first.

vault = CypherCell(b"transient-key", volatile=True, ttl_sec=30)
print(vault.reveal())  # Works
print(vault.reveal())  # Raises ValueError (already wiped)

3. Masked Debugging

Reveal only what you need for logs.

cell = CypherCell(b"SK-7721-9904-1234")
print(cell.reveal_masked(suffix_len=4))  # Output: *************1234

4. Load Secret Directly from Environment

Avoids Python heap exposure by loading secrets straight from environment variables.

import os
from cypher_cell import CypherCell

os.environ["MY_SECRET"] = "env-value"
cell = CypherCell.from_env("MY_SECRET")
print(cell.reveal())  # env-value

5. Constant-Time Secret Verification

Protects against timing attacks when checking secrets.

cell = CypherCell(b"top-secret")
if cell.verify(b"top-secret"):
    print("Access granted!")
else:
    print("Access denied!")

6. Safe Binary Secret Handling

Safely work with raw cryptographic keys or binary data.

key = b"\x01\x02\x03\x04\x05\x06"
cell = CypherCell(key)
raw = cell.reveal_bytes()
assert raw == key

🏗 Architecture

cypher_cell bridges Python with low-level Rust primitives:

  • Creation: Data is copied into a Vec<u8> in Rust.
  • Locking: Calls libc::mlock (Unix) or VirtualLock (Windows) to pin memory to RAM.
  • Destruction: When the Python reference count hits zero or __exit__ is called, Rust executes the Drop trait, which calls zeroize and then unlocks the memory.

Known Weaknesses & Usage Tips

While cypher_cell protects the data within its vault, the act of passing a string to CypherCell or calling .reveal() creates temporary copies in Python's unmanaged memory. For maximum security, use the context manager and minimize the lifetime of the revealed string.

Note on .reveal(): When you call .reveal(), Python creates a standard, immutable string. While cypher_cell wipes its own internal memory, it cannot wipe the string Python just created. Always use secrets in the narrowest scope possible:

Warning on Literals: Avoid passing string literals directly like CypherCell("my_secret"). Python may intern these strings, keeping them in memory for the duration of the process regardless of what cypher_cell does. Always load from environment variables, files, or buffers.

# GOOD: String is short-lived
authenticate(cell.reveal())

# BAD: Secret lingers in the 'key' variable
key = cell.reveal()
authenticate(key)

🧪 Testing

Run the test suite with:

pytest tests/

⚖️ License

MIT © Rivendael

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cypher_cell-0.1.2.tar.gz (19.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cypher_cell-0.1.2-cp313-cp313-win_amd64.whl (117.6 kB view details)

Uploaded CPython 3.13Windows x86-64

cypher_cell-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (197.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.2-cp313-cp313-macosx_11_0_x86_64.whl (198.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ x86-64

cypher_cell-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (184.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cypher_cell-0.1.2-cp312-cp312-win_amd64.whl (117.7 kB view details)

Uploaded CPython 3.12Windows x86-64

cypher_cell-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (197.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.2-cp312-cp312-macosx_11_0_x86_64.whl (198.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ x86-64

cypher_cell-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (184.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cypher_cell-0.1.2-cp311-cp311-win_amd64.whl (116.7 kB view details)

Uploaded CPython 3.11Windows x86-64

cypher_cell-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (207.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (197.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.2-cp311-cp311-macosx_11_0_x86_64.whl (198.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ x86-64

cypher_cell-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (184.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cypher_cell-0.1.2-cp310-cp310-win_amd64.whl (116.9 kB view details)

Uploaded CPython 3.10Windows x86-64

cypher_cell-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (207.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (197.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.2-cp310-cp310-macosx_11_0_x86_64.whl (198.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

cypher_cell-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (185.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file cypher_cell-0.1.2.tar.gz.

File metadata

  • Download URL: cypher_cell-0.1.2.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cypher_cell-0.1.2.tar.gz
Algorithm Hash digest
SHA256 64bc6c9b74f2e1c87f0d860bac8ee331d017a2e9d6d6ac0bf7a24b305f26aa21
MD5 f01c24d7493528328d53ff2b06f13dd0
BLAKE2b-256 6a53359c6228f7012d2abf36a32eac8ee5f563ff800e9a129b4fb3038a91b4e7

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 499d97ecba1e3780154beb810c861a022d5d0f65c7fba13c7db63bfcee08bc80
MD5 134187466f73cffb52748105f83f92b2
BLAKE2b-256 5c695485a9794ec5398470444ce874d75ff574d16a3a627aa79b7f770d8139bd

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c6b0e84cb7b6bbea5f522825e90ca548ed124bbe73acea726bf8a276c24a365
MD5 7260d8f070b07f334789a0ea0a0b4a96
BLAKE2b-256 e27569250ef35ad341903cae1e84d58909accb8eed9bc4c0011d912de26c3511

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 236e01fa2a9de8c75d44dcadec1205b404198107de0aaa00123f8a4cdc0463af
MD5 fdfc1df5d0000f5bb59846bc2f9ad594
BLAKE2b-256 2f4d8681eb7717434f1823c716a611af97780caa74c0378182b7d5c1fff6c3c8

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp313-cp313-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 1e8abd51775f2116dd7a3915b865ff81fd89bc7d295247badba264d96db308bd
MD5 c45790847f9e45e5ec246ac1be336861
BLAKE2b-256 43c2ee4b7a5fdad210b4d2dcad3391b9d728c11dc8e65873d8ee05f6691c54d2

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 419ec1758b1d96fa3dae4dbba825fb62e5301d97ae8454cd2ae8e899a4492f35
MD5 623af1bc5fca03dcfe4e2510d571a114
BLAKE2b-256 8484734e3978d8ade67a1311e4fe28660a28c881ebdb76a3703fb5a32cac71bf

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 34e4b1730798ad6e7cecc096dfcaad18da6523bfce2f13e5aa7e5eb82194be28
MD5 aa7b6c653b6b420f81295172069387b6
BLAKE2b-256 0f33e5ad0922857fc6b9ad220d1996801d41f95cabf7f899e2b904a6588cdcaa

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a128893216fceff339b13c15fbdc25d337c824dd01cf5d3b54fab9b1e5ce561d
MD5 5a651b4efdc61359f9e38b544b0c0c71
BLAKE2b-256 af6c7238db538b36670548b3a7f54dcf4ba30cb235287dbc7b6334ab89575a1f

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 675ecf0e25c8e9fa737acc1fb2be17c8477eb652cd84a2886d225d59f4f30058
MD5 a89cb2b57c22290a29fd4d6ca383465a
BLAKE2b-256 dcff46610e7a671d590ba54c10f1fd3a9782829e69babc4fa8e5ddebb4ef527e

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp312-cp312-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 7f19597e7a27f1e3d00c2818c4d954a2c1653897ef78d7b5229d6b18b955a3a6
MD5 44f3136ec4bb83d241d34835b7a80212
BLAKE2b-256 848346ec43b4b643896a152d85c42c3dfc37fca641cc5911826e7e75feb6f01b

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fe2887ce5a29275559dffcc7a0bd88fd26e6dfd0b95df48e14c87e71109613a3
MD5 314b30971d4f9c5eb6858c5069c099c6
BLAKE2b-256 32f8f85417b7d0ed3bda4aaf6b1745900691b3954546c8b56cf86a78f7f226bf

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d2fa743540becda145739aa7d61108a0cce51a981a9c398dbaeb6a2c399b996c
MD5 2d131997813fb89dd86c80203e756ddf
BLAKE2b-256 fe9ed55b6762332e315a18116c6bdbf2cbc581dcd58bb0538d2df15742510fb6

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d46984f12f0fb5b8e5c4a4d4a06c4153e20ed9c4ad320159b94128721f0fdcf5
MD5 724bd87e5ea8c33e473f44f75c5209a7
BLAKE2b-256 a7cce7fcd148547f20f40cc2fe35bcd96712ad7eb4a58497a8d3c095c7a25a67

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b3bbcf360f587f23f04ba24000f3f7a5743fa439add1c716653012edd852369b
MD5 1c434d4e368980303206c7659cfaccd7
BLAKE2b-256 50ca7c40ef6b7a71c4281c1aa82b84209898d73d412858957df71266cd11634d

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp311-cp311-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 bc8708dee7ded8292d8987f9b4ce4e9df22ed7eb0c231c0b91ce08fd131faab1
MD5 99038ccc6332a94b3b8db9d322146f66
BLAKE2b-256 c42504bf4588bc523fcc41cd228ec03e97d3906d933715a954438af0c23cd443

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3da599e24c67cc8d51acaf7844b7ea3349ddcdda7f076a6a59556a6b1276aecb
MD5 c1d07e1bbd6b04c8abeecf7add361ab1
BLAKE2b-256 75804f0a32105d67ef497e562fc55cad74640c8163b664ddf6b8bc8430e22916

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e9b9c47638d8badabe4c5491fc1330b7db8d4e700159a284d7531f6fd8156e50
MD5 4e9161c214086d659f94169d8bba5482
BLAKE2b-256 e3d2811fb4bf8eca5fd5917065ecb94601c5af877aac7261e0eb26240d829177

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1a78afd23ed2f41675f95ffb5ae303eb6ef8d83f00e300c9007440be977840e
MD5 55f8597d3b2671d406a3019ba7699f97
BLAKE2b-256 2ca9763244a91df84d4aecfcbe7e079bc669562baaacf71917b46bb98f8c7d3c

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 07f009ee08292d4c68846b4551ee7684e05661b7d9b3ac7c49506f05ea98b83f
MD5 ccd954c02630681381e025eb93b92123
BLAKE2b-256 c76fb69bd1468107d6e15f6db8cdf67a1abdd4a2f702dd277cbcbbb6641f4483

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 7f262dd0d19470063d61ef342fc2aafc4365e83e67627b29d2a2826d3423aaa6
MD5 c921d01f523568d0f7231b76bc6e8359
BLAKE2b-256 429e97fce07a6e9d9b125e953b20ae70917a6b2444492904f56b468ba5862d1f

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3879fe348ddf7b38dd2a5cb5fdb93f2e9566bc0c77ffef0a6d58c4ee26295d8
MD5 a80df265f46f75a2b472ce9679f40cd3
BLAKE2b-256 b5137c2d24d70ced10b8af724262ff970d948f1ceafd3d5de8b7eea82ba71e45

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page