Repository navigation
Generic certificate support - #1042
Conversation
Roll agnostic certificate support into PKey, and tweak publickey authentication to use it only if set. Requires explicit call to PKey.load_certificate() in order to alter the authentication behavior.
| 'Trying discovered key %s in %s' % ( | ||
| hexlify(key.get_fingerprint()), filename)) | ||
| if filename.endswith('-cert.pub'): | ||
| key = pkey_class.from_private_key_file(filename.rstrip('-cert.pub'), password) |
There was a problem hiding this comment.
rstrip() is not what you want to use here - the argument is not a suffix, it is a set of characters.
>>> "abc-cert.pub".rstrip('-cert.pub')
'a'
instead you could do something like filename[:-len("-cert.pub")]
There was a problem hiding this comment.
Good eye - it happens to work with the basic key type names that end either with 'a' or '9', but that doesn't mean that it's right... I'll update shortly...
|
Very interesting approach! I really like this. If I understand correctly (#531 is proof that I am not truly capable of intelligent thought) you're relying on how certificate files are stored as wire format on-disk, and thus can be slapped into a being-constructed auth Message as-is without any actual requirement to peek 'inside' the blob (and therein lies the agnosticity. Agnosticism? Agnosticism.) I think I'd be happy to merge this as-is, though noting for the future that these would be nice add-ons later:
|
|
(Trying to get out of the edit-button habit...) actually, re: explicit cert names, one could still manually rely on |
|
Final pass on this now. One note from rereading/documenting (also going to manually test): the bits in Otherwise we'll end up trying the certificate-less variant of the key before the certificate-bearing one, which would cause an auth failure in most situations where one is using a cert. (Yes, presently the intent is that one would 'fall through' that failure into a possible success with the subsequent cert, but given how messy #387 is already, I dunno if it's wise to complicate things if there's no reason.) |
|
Also wondering how best to handle OpenSSH compatibility here:
Also, if it was not clear, I have a branch open and am actively working on this right now. |
|
Looking at the debug output from OpenSSH client (7.4p1) when relying on standard named keys from ~/.ssh (which I'm presuming Explicitly specifying When explicitly loading keys, once |
|
Took entirely too long to figure out why I'm getting Realized, duh, the test server implementation used in the suite is probably barfing on the cert part of the auth messages. Prior to my change we only tried loading the cert blob if it was explicitly given. Huh...yup. The root problem seems to be the lack of server-side support - an in-process server is attempting to field e.g. the existing tests that field various cert types, and now that SSHClient loads cert info, we're triggering the parts of the patch that update Transport so it sends a cert-capable message. So it ends up asking the server to deal with a key of type tl;dr we do need at least light server support if we're going to test this functionality end-to-end (the PR's tests only test the basic PKey method, not any of the Client or Transport code), so I may need to pull down more of #531 than originally intended. Grump. This always happens...it's never, ever, ever, ever as simple as the initial works-for-me implementation... 😠 (not 😠 at @radssh just at how this always ends up being the case 😭 ) |
|
Seems I can at least get the existing tests happy enough by tweaking
|
|
Hah, not quite, amusingly that earlier test never actually instructs the server to accept RSA (it's a series of "submit some keys, accept some other possibly-overlapping list of keys" tests). So we were triggering early code (creation of key object from network message) but not later code (verification of key material), since code in the middle (key type acceptance) was (correctly, for that earlier test) bailing out. Now a later, simpler test that just goes "does this basic RSA key work?" dies at signature verification. I have to refresh my memory of exactly why this is; IIRC it's because the client-side key object instance knows to include its certificate data when generating the signature, but the server-side object has never had |
|
Yea, that's the issue, so for this to really work we do need PKey classes to instantiate w/ public blob set if created from a Message object that is of cert type. Shouldn't be super hard still? Famous last words. |
|
Refactored the shit out of End result seems to be a passing test suite! But now I need to fill in those new tests I added. I think most of the actual functionality is already there so they may just-pass... 🤞 EDIT: also need to update the other key classes. Going by the spec, they all look the same for the first few fields, so I may be able to just factor it out back into PKey. |
|
Hrm. When I get to testing ECDSA certs, there's a perplexing mismatch going on between what I expect the type field to be (going by the spec here) and what it apparently actually is. Re: the key and cert in question:
So far so good. Updated our code so that Unfortunately... Test output (running temporarily under pytest for its test selection & inlined exception superpowers): # Verify that the blob message first (string) field matches the
# key_type
m = Message(key_blob)
blob_type = m.get_string()
if blob_type != key_type:
msg = "Invalid PublicBlob contents: key type={0!r}, but blob type={1!r}" # noqa
> raise ValueError(msg.format(key_type, blob_type))
E ValueError: Invalid PublicBlob contents: key type='[email protected]', but blob type='[email protected]'Now, at first I thought I'd screwed up because all the other cert types in play do have And the "blob" in play here is the one generated by ssh-keygen, not by me. I have never typed out So to me this seems to be a mismatch between the published spec and the actual behavior of EDIT: and on further digging I realize that even the spec itself disagrees internally! The Anyway, the obvious empirical solution is to look at the actual source and sure enough, it's got to be a typo in the spec, the constant definition & their own test data clearly has
Thanks a lot for wasting an hour or two of my day, whoever wrote that document 😠 |
|
Then wasted a smaller but still nonzero amount of time wondering why Ed25519 certs didn't work...until I noticed the patch added an explicit But! Now all the damned tests pass under Python 2. Sadly...Python 3 has issues. Ones I think predate all my meddling. I'll tackle that tomorrow, unless @radssh wants to give it a shot. I'm pushing my branch now. |
…ngside key_filenames' behavior re #1042 This actually breaks existing tests due to test server not supporting certs...bah
This allows server-side Paramiko code to correctly create cert-bearing RSAKey objects and thus verify client signatures, and now the test suite passes again, barring the stub tests. Re #1042
|
Seems like the main issue is just stuffing strings-not-bytes into Actually...I may as well just try that real quick. |
|
Yea that was pretty easy. |
…ngside key_filenames' behavior re paramiko#1042 This actually breaks existing tests due to test server not supporting certs...bah
This allows server-side Paramiko code to correctly create cert-bearing RSAKey objects and thus verify client signatures, and now the test suite passes again, barring the stub tests. Re paramiko#1042
Roll agnostic certificate support into PKey, and tweak publickey
authentication to use it only if set. Requires explicit call to
PKey.load_certificate() in order to alter the authentication behavior.
I know you just sunk a good bit of time/effort into a different PR, but this might be worth considering.