suspicious-insecure-cipher-mode-usage (S305)
源自 flake8-bandit linter。
作用
检查对弱密码或已损坏的密码模式的使用。
为什么这不好?
弱密码或已损坏的密码可能容易受到攻击,这些攻击允许攻击者在不知道密钥的情况下解密密文,或以其他方式危及密码的安全性,例如伪造。
使用强大的现代密码,而不是弱密码或已损坏的密码。
在 preview 中,此规则还将标记对不安全密码模式的引用。
示例
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
algorithm = algorithms.ARC4(key)
cipher = Cipher(algorithm, mode=modes.ECB(iv))
encryptor = cipher.encryptor()
建议改为
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
algorithm = algorithms.ARC4(key)
cipher = Cipher(algorithm, mode=modes.CTR(iv))
encryptor = cipher.encryptor()