sdk/python/Cryptography/PyCryptography
Cryptography

PyCryptography

The cryptography package provides recipes (Fernet) and primitives (hazmat). Fernet is the recommended symmetric encryption helper. Findings arise when hazmat primitives are used with obsolete algorithms (MD5, DES, RC4) or ECB mode.

3 sanitizers

Sanitizers

.Fernet()Sanitizer
#
Signature
cryptography.fernet.Fernet(key: bytes) -> Fernet

Authenticated symmetric encryption. Safe.

.Fernet.encrypt()Sanitizer
#
Signature
Fernet.encrypt(data: bytes) -> bytes

Encrypts a message. Safe.

tracks:return
.Fernet.decrypt()Sanitizer
#
Signature
Fernet.decrypt(token: bytes, ttl: int = None) -> bytes

Decrypts and authenticates. Raises on tampering. Safe.

tracks:return

Other Methods

.Cipher()Neutral
#
Signature
cryptography.hazmat.primitives.ciphers.Cipher(algorithm, mode, backend=None) -> Cipher

Low-level cipher. Finding when algorithm is DES/3DES/RC4 or mode is ECB.

Fully-Qualified Names

FQNField
cryptographyfqns[0]
cryptography.fernetfqns[1]
cryptography.hazmatfqns[2]

Wrong FQN → 0 findings. Verify with: change fqns to garbage → must produce 0 results.

Import

rule.py
from codepathfinder.go_rule import PyCryptography