Repository navigation
Conversation
|
Thank you for your interest in paramiko. Per discussion with bitprophet, the paramiko project is operating under a blanket policy rejecting AI-generated contributions of all kinds. The text of all issue and PR descriptions, and all code in PRs, comment-suggestions, etc. must be human-written. Direct attributions of AI authorship fall under the policy straightforwardly. In the absence of direct attribution, evaluation of AI authorship is ultimately a judgment call. Closing this PR due to inferred AI authorship. |
|
Sir ... already commented on the other one. I have only one thing to say, It was not an AI-written or commited PR. THANK YOU! |
|
Reopening, cf. the first part of #2698 (comment). This fix makes sense to me for what it directly solves; I'm not sure if it's a sufficiently general solution, though. Are you confident that it entirely fixes #2467/#2048, and doesn't break something broader in the machinery? (I'm not deeply familiar with how exhaustive the test suite is in terms of checking that keys pass or fail when they should.) |
|
Thanks for reopening this and for the follow-up question. Direct answer: yes, this fixes the mechanism behind #2467, and that same mechanism is the core of #2048 as well (with one exception in #2048 that I will name below). In #2467, the root cause was in This PR adds an expected-types list per class, checked after decryption and after the checkints match, but before returning the unpadded data. That turns a wrong guess into exactly the exception the trial loop is designed to catch. I am not expecting this PR to close #2048 on its own for two reasons. First, this PR only references #2467 structurally. Second, #2048 contains a separate request: Schwaneberg's proposal for an On broader breakage, the risk is narrow. PEM keys, public key parsing, cipher and KDF handling, checkints, and padding are untouched. Ed25519 is also unchanged. What changes is simply that wrong-type OpenSSH loads that previously leaked a Tests does not enumerate every single pair or test corrupt types except RSA rejected as ECDSA, ECDSA 384 rejected as RSA. Not that wrong, since the check happens before any numbers are decoded and only compares the string label. There are two real edge cases I want to flag:
I can wrap that decode and add tests for the missing pairs as a follow-up commit if you would like. |
|
Keeping this PR minimal on purpose, but thinking longer term about the trial loading design itself, here are some redesign options if you think any of them are worth a separate issue. First, I should note what is not new here. The reporter in #2467 already asked why paramiko tries classes by trial instead of detecting the type, and jun66j5 in #2048 already proposed verifying the embedded type in pkey.py (which is what this PR does) or validating by signing after loading. The ideas below go beyond those two. 1. Detect from the public blob first, not from the private blob 2. Stop trial loading entirely and dispatch once from the detected type 3. Make the parser return a neutral, typed structure once 4. Wrap any parsing error in the trial loop into SSHException, chained from the original 5. Validate by signing after loading My recommendation is to keep this PR as is. If any follow up is worth it, I'd start with public-blob-first detection as a separate issue, since it gives a real performance win for encrypted keys without changing the trial API. Happy to open that issue if you think it is worth tracking. |
Closes #2467.
When loading an OpenSSH-format private key (
BEGIN OPENSSH PRIVATE KEY),PKey._read_private_key_openssh()extracted the key type embedded in the file but never validated it against the key class being loaded. A wrong-type key file would then mis-parse into garbage and fail later with a cryptic error (e.g. "unpack requires a buffer of 4 bytes") instead of failing fast with a clear message.This adds the missing check: each key class declares its expected OpenSSH key type name(s) via
_expected_openssh_keytypes, and the loader raisesSSHException("encountered X key, expected Y key")on mismatch, thus mirroring the check_read_private_keyalready performs for PEM files.Changes:
paramiko/pkey.py: new_expected_openssh_keytypesattribute (empty tuple disables the check) + validation in_read_private_key_opensshparamiko/rsakey.py: declares("ssh-rsa",)paramiko/ecdsakey.py: declares the threeecdsa-sha2-nistp*typestests/pkey.py: tests proving wrong-type files fail with the clear error, and right-type files still load fineAll 57 tests in
tests/pkey.pypass.