Skip to content

fix: consume and report CryptographyDeprecationWarning, detect encrypted PKCS#8 keys - #45

Open
ai-anant wants to merge 1 commit into
cyfinoid:mainfrom
ai-anant:fix/11-consume-warnings-errors
Open

fix: consume and report CryptographyDeprecationWarning, detect encrypted PKCS#8 keys#45
ai-anant wants to merge 1 commit into
cyfinoid:mainfrom
ai-anant:fix/11-consume-warnings-errors

Conversation

@ai-anant

@ai-anant ai-anant commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses #11 (Consume specific warnings / errors and report accordingly).

Changes

  • keychecker/core/key_analyzer.py
    • Wrap key loading and public-key serialization in warnings.catch_warnings(record=True) and collect CryptographyDeprecationWarning messages (e.g. the "SSH DSA key support is deprecated" warning emitted by public_bytes(Encoding.OpenSSH) when serializing DSA keys). Warnings are surfaced in the analysis result under a new warnings key instead of leaking to stderr as raw Python warnings.
    • Recognize BEGIN ENCRYPTED PRIVATE KEY (OpenSSL PKCS#8 encrypted format) headers in _analyze_encrypted_key, so such keys report type: pkcs8 instead of unknown.
  • keychecker/utils/output.py — display library deprecation warnings (⚠️) in both human-readable formatters.
  • tests/test_key_analyzer.py — new tests: DSA key analysis captures the deprecation warning without leaking it; encrypted PKCS#8 keys detected as pkcs8; normal RSA keys have empty warnings.

Verification

  • pytest tests/ → 9 passed
  • black --check keychecker/ tests/ → clean
  • flake8 keychecker/ tests/ → clean
  • Manual CLI check: analyzing a DSA key now prints ⚠️ SSH DSA key support is deprecated and will be removed in a future release in the output and produces no stderr warning trace; an OpenSSL genpkey -aes256 key reports Type: pkcs8.

Fixes #11

…ted PKCS#8 keys

- Capture CryptographyDeprecationWarning raised while loading/serializing
  keys (e.g. DSA) and surface them in the analysis output instead of
  leaking raw Python warnings to stderr.
- Recognize 'BEGIN ENCRYPTED PRIVATE KEY' (OpenSSL PKCS#8 encrypted)
  headers so such keys report type pkcs8 instead of unknown.
- Add tests covering deprecation warning capture, encrypted PKCS#8
  detection, and clean warnings for normal keys.

Fixes cyfinoid#11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consume specific warnings / errors and report accordingly

1 participant