Skip to main content

Drop-in dotenv replacement with Windows Hello encryption.

Project description

dotenv-webauthn-crypt

Transparent, WebAuthn-backed encryption for your .env files.

dotenv-webauthn-crypt is a drop-in replacement for python-dotenv that keeps your secrets encrypted at rest and gates access behind WebAuthn (Biometrics/PIN/Phone). Your Master Key never exists in plaintext on disk.

Features

  • Seamless Integration: Use load_dotenv() just like you always have.
  • Multiple Authentication Devices: Windows Hello (fingerprint/PIN), smartphone (QR code), or USB security key.
  • Hardware Security: Private keys stay in the TPM or on your authenticator device.
  • Strong Cryptography: AES-256-GCM encryption, HKDF-SHA256 key derivation.
  • Vault Isolation: Each .env file has its own unique derived vault key.
  • Platform Diagnostics: Pre-flight checks for TPM, Bluetooth, and network availability.

Installation

Prerequisites

  • Windows 10/11 with Windows Hello enabled (for local authentication).
  • Bluetooth + Network (for phone/QR authentication).
  • Visual Studio 2022 Build Tools (only if building from source).
pip install dotenv-webauthn-crypt

Usage

1. Check available devices

Running init without --device shows a diagnostic report and available options:

dotenv-webauthn-crypt-cli init --user MyUser

Output:

--- Platform Authentication Status ---
  WebAuthn API version: 9
  Platform authenticator: available
  Bluetooth: available
  Network: available

  Choose an authentication device with --device:

    --device local   Windows Hello (fingerprint/PIN)
                     Credential stored in the local TPM.
                     Fast, no extra hardware needed.

    --device phone   Smartphone via QR code (hybrid)
                     Credential stored on your phone.
                     Requires Bluetooth + network.

    --device usb     USB security key (FIDO2)
                     Credential stored on the key.
                     Requires a compatible USB key.

2. Initialize with your chosen device

# Windows Hello (fingerprint/PIN)
dotenv-webauthn-crypt-cli init --device local --user MyUser

# Smartphone via QR code
dotenv-webauthn-crypt-cli init --device phone --user MyUser

# USB security key
dotenv-webauthn-crypt-cli init --device usb --user MyUser

3. Encrypt an existing .env file

dotenv-webauthn-crypt-cli encrypt .env

The encrypted file includes a recovery header with credential metadata:

# --- dotenv-webauthn-crypt recovery info ---
# CREDENTIAL_ID="hnemG/M2FN..."
# RP_ID="credentials.dotenv-webauthn.com"
# USER_NAME="MyUser"
# DEVICE="local"
# TRANSPORT="internal"
# AAGUID="adce0002-35bc-c60a-648b-0b25f1f05503"
# CREATED_AT="2026-04-02T10:30:00Z"
# ENCRYPTED_AT="2026-04-02T10:31:00Z"
# VAULT_PATH="C:\Projects\myapp\.env"
# --- end recovery info ---
MY_SECRET=ENC:AQ...

4. Inspect your credential

dotenv-webauthn-crypt-cli info

Output:

--- Credential Information ---
  Credential ID : hnemG/M2FNfuigrJ3BUP5kj9DYudDEL1...
  Domain (RP_ID): credentials.dotenv-webauthn.com
  User name     : MyUser
  Device        : local (Windows Hello (fingerprint/PIN))
  Transport     : internal
  AAGUID        : adce0002-35bc-c60a-648b-0b25f1f05503
  Authenticator : Windows Hello
  Created at    : 2026-04-02T10:30:00Z

The info command also queries the AAGUID database to display the authenticator name (e.g., "Samsung Galaxy", "YubiKey 5").

5. Load in your Python code

from dotenv_webauthn_crypt import load_dotenv

# Triggers an authentication prompt if encrypted values are detected
load_dotenv()  # comment lines in the .env file are ignored

import os
print(os.environ.get("MY_SECRET_KEY"))

Authentication Devices

Device --device Where key lives Requirements
Windows Hello local Local TPM Windows Hello PIN or biometrics
Smartphone phone Phone Bluetooth + network connectivity
USB key usb Security key FIDO2-compatible USB key

The init command runs pre-flight diagnostics and reports which devices are available. If a device is unavailable, it explains why (e.g., Bluetooth off, no network, no TPM).

Architecture

  1. Registration: init creates a non-resident public/private key pair on the chosen authenticator. The CredentialID and metadata (AAGUID, transport, device, user, timestamp) are saved locally.
  2. Encryption: A VaultKey is derived using HKDF from an authenticator-backed signature and the file's canonical path. A recovery header with credential metadata is prepended to the encrypted file.
  3. Loading: load_dotenv skips comment lines (#), detects ENC: prefixes, triggers authentication to get a fresh signature, re-derives the VaultKey, and decrypts the values into os.environ.
  4. Info: info reads the credential metadata and queries the AAGUID database to identify the authenticator model.

TODO / Roadmap

  • Windows Hello (TPM) authentication
  • Smartphone (hybrid/QR) authentication
  • USB security key authentication
  • Platform diagnostics (TPM, Bluetooth, network)
  • Credential metadata and recovery headers
  • AAGUID-based authenticator identification
  • Linux Support: Backend using TPM2-TSS or libfido2.
  • macOS Support: Backend using Secure Enclave / Touch ID.
  • Credential Rotation: rekey command to migrate between hardware credentials.

Browser-based WebAuthn Test

tests/test_browser_webauthn.py is a standalone prototype that uses a local browser as the WebAuthn client instead of the native C++ module. It starts an HTTP server on localhost:8580, opens the default browser, and delegates navigator.credentials.create() / .get() to the browser's built-in WebAuthn support.

Prerequisites: Windows Hello must be provisioned (NGC active). See TODO_BUGS.md for NGC troubleshooting.

# Create a platform credential (triggers Windows Hello in the browser)
python tests/test_browser_webauthn.py create

# Sign with the saved credential
python tests/test_browser_webauthn.py sign

License

Distributed under the MIT License. See LICENSE for more information.

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

dotenv_webauthn_crypt-0.3.0a6.tar.gz (23.5 kB view details)

Uploaded Source

Built Distributions

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

dotenv_webauthn_crypt-0.3.0a6-cp312-cp312-win_amd64.whl (89.6 kB view details)

Uploaded CPython 3.12Windows x86-64

dotenv_webauthn_crypt-0.3.0a6-cp311-cp311-win_amd64.whl (89.1 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file dotenv_webauthn_crypt-0.3.0a6.tar.gz.

File metadata

  • Download URL: dotenv_webauthn_crypt-0.3.0a6.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dotenv_webauthn_crypt-0.3.0a6.tar.gz
Algorithm Hash digest
SHA256 753e6aec2a264288a5d3bfae98a5ee15114e7ad45e6402f96aa036020912ab9f
MD5 f5b21c23688a9aa07b54cdd9ad69359b
BLAKE2b-256 81a2fdb4ce90284c77e320bb80cb00396b8d4c08e372d2facde7c647929773d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for dotenv_webauthn_crypt-0.3.0a6.tar.gz:

Publisher: build_wheels.yml on joseluu/dotenv-webauthn-crypt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dotenv_webauthn_crypt-0.3.0a6-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for dotenv_webauthn_crypt-0.3.0a6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c1848ce54ef0d3e0452e043b3ba42714c4ec55ba5537f3647844cbcdc2db96e2
MD5 33c8d30e9d5ff74f4bc4dab4f2f8962a
BLAKE2b-256 cdb4413fd28af74693a945a39d6f2ab6822b7072d118d060d9b21399df727c61

See more details on using hashes here.

Provenance

The following attestation bundles were made for dotenv_webauthn_crypt-0.3.0a6-cp312-cp312-win_amd64.whl:

Publisher: build_wheels.yml on joseluu/dotenv-webauthn-crypt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dotenv_webauthn_crypt-0.3.0a6-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for dotenv_webauthn_crypt-0.3.0a6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 dc4e6d73647d9ce9a0b01f5ef551021cb7a67629688b2fde91e821c4953b30f8
MD5 ccd10b6b46936d28497f4ad30f9a4939
BLAKE2b-256 6b1e0b581891d993e18e985eabe44a028aa3c7e9503ce71886679d3b8706184d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dotenv_webauthn_crypt-0.3.0a6-cp311-cp311-win_amd64.whl:

Publisher: build_wheels.yml on joseluu/dotenv-webauthn-crypt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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