Repository navigation
Smartcard pkcs11 support - #827
thedavidwhiteside wants to merge 38 commits into
Conversation
|
Hi, great work! I'm actually waiting for this feature. |
|
@bitprophet is there anything I can do to help with the "needs tests" and "needs docs"? Are you looking for more unit tests? Where would you like this feature documented, is this where it should be documented: sites/docs/api? Thanks! |
|
You should probably add an entry to the change log. :) |
|
@starboarder2001 Yea, something in the Also what @SethMichaelLarson said, tho changelog is always something I can add myself (I am picky about language...) Thanks! |
|
Also, you'll want to make sure the merge conflicts are fixed, we pep8'd the crap out of the codebase recently which may be what caused those. |
|
I think its in pretty good shape. I updated the changelog (feel free to reword as needed), docstrings for Client.connect, and made sure the code passed all the pep8 checks. |
|
Trying to help out the best I can on this one, is there anything I can do to help this along? I have been using this feature along w/ Ansible for about 9 months. |
|
There was a big round of merging and releasing about a week ago (as you probably noticed), and it reduced the backlog noticeably. The maintainer will probably do another around in a few weeks. I think there is a decent chance this PR will eventually get in, if you keep it up-to-date :) I think it would help a bit to squash down to just one commit (or a few). This will require a careful interactive rebase, re-resolving some merge conflicts, and a force-push. Since the "flake8 re-style" is behind us, I don't expect this much tedium being needed again. |
| def _pkcs11_get_public_key(self): | ||
| public_key = "" | ||
| if self.pkcs11session is None: | ||
| if which("pkcs15-tool") is None: |
There was a problem hiding this comment.
I think you should remove the which() function you added. Just catch the subprocess.Popen() exception for this case (an OSError with .errno equal to https://docs.python.org/2/library/errno.html#errno.ENOENT). Then you can re-throw your more specific Exception("pkcs15-tool not found in PATH") (I wouldn't include the extended instructions in the exception text).
| :param str pkcs11provider: If using PKCS11, this will be the provider | ||
| for the PKCS11 interface. Example: /usr/local/lib/opensc-pkcs11.so. | ||
| :param str pkcs11session: If using PKCS11 in a multithreaded | ||
| application you can share the session between threads. |
There was a problem hiding this comment.
Can this be reduced to just one additional argument to SSHClient.connect()? Perhaps the user could be required to call pkcs11_open_session() themselves, then pass just the session to connect()?
There was a problem hiding this comment.
For most cases the pkcs11provider is all thats needed, very few users will need to use the pkcs11session argument. pkcs11session is optional and only needed when used in a multithreaded application.
There was a problem hiding this comment.
I second @ploxiln's question - I think what he's getting at is it's unclear what the relationship is between these arguments & the data stored in the session - which, w/o doing a deep analysis, seems to largely be a 3-tuple whose members include the pin and provider anyways.
So if we can simplify the API on our end to "you should have called pkcs11_open_session() yourself, please hand me the resulting session obj/tuple" that cleans up a lot of intermediate code in an already-very-crowded space.
|
In some cases, where you raise a |
363a397 to
1a8d7ce
Compare
| public_key = out | ||
| except OSError as error: | ||
| if error.errno == errno.ENOENT: | ||
| raise SSHException("Cannot find pkcs15-tool in PATH.") |
There was a problem hiding this comment.
If not translating to this exception, you still need to re-raise the original exception, e.g. just
else:
raiseThere was a problem hiding this comment.
Thanks, good point! I'll do more review and testing tomorrow.
5af5cde to
73ef6e1
Compare
Codecov Report
@@ Coverage Diff @@
## master #827 +/- ##
==========================================
- Coverage 75.25% 73.74% -1.52%
==========================================
Files 42 43 +1
Lines 7449 7645 +196
==========================================
+ Hits 5606 5638 +32
- Misses 1843 2007 +164
Continue to review full report at Codecov.
|
|
73ef6e1 contains a bunch of changes from master. Merging with master hides this from the diff in the "Files Changed" tab, but does not fix the problem. (When you squashed, you needed to ensure you did not include commits you did not author.) |
46b8278 to
e07a4e2
Compare
|
I think the last rebase worked ok. |
|
yup, looks good, thanks |
389dcb0 to
9e58af8
Compare
8618efa to
8f58137
Compare
|
I think its all squared away this time. Unit tests passed after the refactor, I have also tested using a SC.
|
67d6631 to
b49ce80
Compare
…1session to pkcs11_session a
b49ce80 to
2ab19fd
Compare
|
Hm, it doesn't seem like you actually based the new work on my branch, so it undoes a bunch of the refactoring & other modifications I made in said branch :( Really what I was asking as for you to checkout that branch of mine ( That may involve you having to make a new PR, but if so, that's totally fine - I'd rather be able to just click merge than have to resolve all these conflicts myself =/ |
|
I can use the same PR. I'll see if I can get to it after work sometime this week, shouldn't be much trouble.
|
|
Yea, again don't care too much about how it looks at the Github level, so long as when I pull some branch from you to check it over, it includes |
|
Trying to determine how to re-open it... |
|
I ended up just creating another pull request...#1073 |
This adds pkcs11 support to enable using paramiko with smartcards. I have a forked version of Ansible that uses this feature and its working great.
I have tested on python 2.7 and python 3.6.2
Multithreading Example:
Basic Example: