Skip to main content

Contribution: Quick Linux/OsX script to create a card for SSH

Posted in

Below is a little script that will clean a card, and put an RSA key on it and extracts the SSH key ready to use.
Basically it follows the steps of the start document but all in one script ready to run and test.

Enjoy,
Wessel
=========================================

#!/bin/bash
#
# Erases the card/Token and generates an RSA keypair
# Contributed by J.W. de Roode, 2012
#
echo -e "\n"
echo Please, enter the Card Name:
read NAME
echo Please, enter your PIN code:
read PIN
echo Please, enter your PUK code:
read PUK
echo Please, enter the label of the RSA key:
read LABEL1

pkcs15-init -E
pkcs15-init --create-pkcs15 --profile pkcs15+onepin --use-default-transport-key --pin $PIN --puk $PUK --label "$NAME"
pkcs15-init --generate-key rsa/2048 --auth-id 01 --pin $PIN -u sign,decrypt --label "$LABEL1"

#
# TODO Make a better awk or sed line to grab the key id
#
ID=`pkcs15-tool --dump|awk '{split($0,a,"ID : "); print a[2]}'|tail -2|head -1`

echo -e "\nExtracting public SSH Key ($LABEL1) with ID:"$ID

pkcs15-tool --read-ssh-key $ID > "$LABEL1"_authorized_keys
echo -e "Saved key into file:"$LABEL1"_authorized_keys\n"

=============================================================================

5
Your rating: None Average: 5 (1 vote)

Re: Contribution: Quick Linux/OsX script to create a card ...

Nice, I would like to publish it on GOOZE cd. What is the license?

Re: Contribution: Quick Linux/OsX script to create a card ...

:-)
Feel free to use it what ever you like, keep a little of contributed by me some where in the comments and i'm all fine with it.

Wessel

Re: Contribution: Quick Linux/OsX script to create a card ...

There is a nice script in OpenVPN from memory which creates RSA keys and X.509 certificates. Maybe we should have a look. I will get back to you.

Re: Contribution: Quick Linux/OsX script to create a card ...

That's very easy to use. Nice job. ;)