Skip to content

PKCS11 smartcard support - #1804

Open
thedavidwhiteside wants to merge 7 commits into
paramiko:mainfrom
thedavidwhiteside:pkcs11_01262021
Open

thedavidwhiteside wants to merge 7 commits into
paramiko:mainfrom
thedavidwhiteside:pkcs11_01262021

Conversation

@thedavidwhiteside

Copy link
Copy Markdown

This adds pkcs11 support to enable using paramiko with smartcards. This requires OpenSC to be installed on the host for the pkcs11provider: https://github.com/OpenSC/OpenSC.

Multithreading Example:

import paramiko
from multiprocessing import Queue
from threading import Thread

pkcs11provider="/usr/local/lib/opensc-pkcs11.so"
smartcard_pin="123456"

def do_it(q):
    session = q.get()
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect("HOSTNAME", username="USERNAME", pkcs11_session=session)
    stdin, stdout, stderr = ssh.exec_command("uname -a")
    for line in stdout:
        print(line)

q = Queue()
session = paramiko.pkcs11.open_session(pkcs11provider, smartcard_pin)
mythread = Thread(target=do_it, args=(q,))
q.put(session)
mythread.start()
mythread.join()
paramiko.pkcs11.close_session(session)

Basic Example:

import paramiko

pkcs11provider="/usr/local/lib/opensc-pkcs11.so"
smartcard_pin="123456"

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
session = paramiko.pkcs11.open_session(pkcs11provider, smartcard_pin)
ssh.connect("HOSTNAME", username="USERNAME", pkcs11_session=session)
paramiko.pkcs11.close_session(session)
stdin, stdout, stderr = ssh.exec_command("uname -a")
for line in stdout:
    print(line)
  • David

@bitprophet bitprophet added this to the p3 milestone Feb 5, 2021
@thedavidwhiteside

Copy link
Copy Markdown
Author

Just checking to see if everything looks good or if it needs some revision/review? @bitprophet

@thedavidwhiteside

Copy link
Copy Markdown
Author

@bitprophet, @alex - I can resolve the conflicts if you see value in adding the pkcs11 support. Probably not used that often, but a useful feature for those that need it.

@bskinn

bskinn commented Jan 3, 2023

Copy link
Copy Markdown
Contributor

Thanks for the PR, @thedavidwhiteside -- I suspect bitprophet will wrap this into the overall key/auth overhaul he has in mind (see #387 and links therefrom).

For now, he's focused on a modernization campaign across all his projects, and the key/auth work won't happen until after that. So, there likely won't be much action here for a while longer, but it is planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants