Skip to content

Commit

Permalink
Fix issue with gpg locking
Browse files Browse the repository at this point in the history
  • Loading branch information
zachhuff386 committed Jul 20, 2018
1 parent 6f691ea commit 6d7a79c
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,26 @@
card_serial = None
card_pub_key = None
try:
card_status = subprocess.check_output(['gpg', '--card-status'],
stderr=subprocess.PIPE, stdin=subprocess.PIPE)
for line in card_status.splitlines():
if line.startswith('Reader') and not card_name:
card_name = line.split(':', 1)[-1].strip()
elif line.startswith('Serial number') and not card_serial:
card_serial = line.split(':', 1)[-1].strip()

if card_name and card_serial:
card_keys = subprocess.check_output(['ssh-add', '-L'],
stderr=subprocess.PIPE)
for line in card_keys.splitlines():
if 'cardno:' in line:
if card_serial in line.split('cardno:', 1)[-1].strip():
card_pub_key = line.strip()
break
# card_status = subprocess.check_output(['gpg', '--card-status'],
# stderr=subprocess.PIPE, stdin=subprocess.PIPE)
# for line in card_status.splitlines():
# if line.startswith('Manufacturer') and not card_name:
# card_name = line.split(':', 1)[-1].strip()
# elif line.startswith('Serial number') and not card_serial:
# card_serial = line.split(':', 1)[-1].strip()

#if card_name and card_serial:
card_keys = subprocess.check_output(['ssh-add', '-L'],
stderr=subprocess.PIPE)
for line in card_keys.splitlines():
if 'cardno:' in line:
card_serial = line.split('cardno:', 1)[-1].split()[0].strip()
if card_serial:
if len(card_serial) > 6:
card_serial = card_serial[4:]
card_name = 'Smart Card'
card_pub_key = line.strip()
break
except:
pass

Expand Down Expand Up @@ -166,7 +170,7 @@
ssh_names = []

if card_name and card_serial:
ssh_names.append(card_name)
ssh_names.append('%s (%s)' % (card_name, card_serial))

if os.path.exists(ssh_dir_path):
for filename in os.listdir(ssh_dir_path):
Expand Down

0 comments on commit 6d7a79c

Please sign in to comment.