weak-rsa
An RSA key shorter than 2048 bits, or RSA encryption without OAEP padding.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule weak-rsa - Level
- warning
- Reads
- Every file
- Fix
- None: changing a key's size or padding needs both ends of the exchange changed
Why
An RSA key of 1024 bits or fewer can be factored with resources an attacker can buy, and NIST stopped allowing keys under 2048 bits after 2013. RSA encryption with PKCS #1 v1.5 padding, the default of public_encrypt and private_decrypt, lets whoever can tell when decryption fails decrypt a message one query at a time (Bleichenbacher's attack), and RSA without padding is deterministic and malleable. Generate keys of at least 2048 bits, and encrypt with OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING or rsa_padding_mode: "oaep".
The fix, as Ur suggests it: use 2048 bits or more, and OAEP padding.
For agents
Generate RSA keys of at least 2048 bits, and encrypt with RSA only with OAEP padding.
Example
app/models/token.rbclass Token
def self.key
OpenSSL::PKey::RSA.new(1024)
end
def seal(public_key, secret)
public_key.public_encrypt(secret)
end
end
$ ur scan --rule weak-rsa
warning[weak-rsa]: an RSA key of 1024 bits, which can be factored
--> ./app/models/token.rb:3:5 `OpenSSL::PKey::RSA.new(1024)`
= hint: use 2048 bits or more, and OAEP padding
= see: CWE-780: Use of RSA Algorithm without OAEP, MITRE (2024-11-19), https://cwe.mitre.org/data/definitions/780.html
warning[weak-rsa]: RSA encryption with PKCS #1 v1.5 padding, the default, which a padding oracle decrypts
--> ./app/models/token.rb:7:5 `public_key.public_encrypt(secret)`
= hint: use 2048 bits or more, and OAEP padding
= see: CWE-780: Use of RSA Algorithm without OAEP, MITRE (2024-11-19), https://cwe.mitre.org/data/definitions/780.html
scanned 1 file (no framework recognized)
weak-rsa: 2 high, 0 medium
2 findings and 0 of medium confidence
Source
CWE-780: Use of RSA Algorithm without OAEP, MITRE (2024-11-19).