9C

PIV: Digital Signature

This certificate and its associated private key is used for digital signatures for the purpose of document signing, or signing files and executables. The main purpose of the slot 9C key is for signing documents or programs with a digital signature.

PIN POLICY: PIN must be submitted every time immediately before a sign operation. PIN is not cached or remembered. PIN policy can only be changed for a slot if PIV certificate imported using ykman command-line.

❊ Distinguished Name Values

❊ Create OpenSSL Config

Copy the following config file to C:\Program Files\Common Files\SSL\piv_slot_9c.cnf

oid_section         = yubikey_oids

[ yubikey_oids ]
nameDistinguisher   = 0.2.262.1.10.7.20
adobeSigning        = 1.2.840.113583.1.1.5
adobeDigitcert      = 2.16.840.1.114412.3.21
msofficeSigning     = 1.3.6.1.4.1.311.10.3.12
msDocSigning        = 1.3.6.1.4.1.311.3.10.3.12
docuEncrypt         = 1.3.6.1.4.1.311.80.1
adobex509           = 1.2.840.113583.1.1.9
msAuthenticode      = 1.3.6.1.4.1.311.2
msTimestamping      = 1.3.6.1.4.1.311.3
gpgUsageSign        = 1.3.6.1.4.1.11591.2.6.2
gpgUsageEncr        = 1.3.6.1.4.1.11591.2.6.3

[ req ]
default_bits        = 2048
default_keyfile     = piv_sign_9c.pem
default_md          = sha256
distinguished_name  = yubikey_dn
x509_extensions     = yubikey_ext
req_extensions      = yubikey_ext
string_mask         = MASK:0x2002
utf8                = yes
prompt              = no

[ yubikey_dn ]
0.C                 = NA
1.S                 = NA
2.L                 = NA
3.O                 = Organization
4.OU                = Organization Unit
5.CN                = Your Common Name
6.emailAddress      = email@address.com
7.GN                = Your Given Name
8.title             = Cert Title
9.description       = Description about Cert
10.initials         = ABC
11.serialNumber     = 1234

[ sans ]
DNS.0               = localhost
DNS.1               = myexampleclient.com

[ yubikey_ext ]
basicConstraints    = CA:false,pathlen:0
nsCertType          = objsign, objCA
nsComment           = "PIV Signature 9C"
subjectAltName      = @sans
extendedKeyUsage    = critical,codeSigning, timeStamping, msCodeInd, msCodeCom, msCTLSign, OCSPSigning, adobeSigning, adobeDigitcert, msofficeSigning, msDocSigning, docuEncrypt, adobex509, msAuthenticode, msTimestamping, gpgUsageSign, gpgUsageEncr
keyUsage            = critical,digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign

If you are creating a PIV certificate specifically for Digital Signatures, don't change anything in the [ yubikey_extensions ] block.

In the commands below, make sure to change the filenames and parameters to your own. In our examples, we like to name the files after the slot we're going to import them into on the yubikey such as piv_name_9c_priv

Priv = Private key Pub = Public key 9C signifies the Yubikey PIV slot we'll be importing our certificate into.

❊ Setup

Before getting started, create you a new folder where you will run all these commands and setup the following structure by creating the following files all in the same directory:

❊ Generate Key + Cert from Config

An OpenSSL cert + private key can be generated using the following command:

openssl req -new -x509 -sha256 -days 1825 -config "C:\Program Files\Common Files\SSL\piv_name_9c.cnf" -keyout "private/piv_name_9c_priv.key" -out "public/piv_name_9c_pub.crt"

❊ Create PFX

Merge your new private key and certificate together into a .pfx

You will be prompted to provide a passphrase to execute the file.

Keep this file safe. and away from others.

openssl pkcs12 -export -in "public/piv_name_9c_pub.crt" -inkey "private/piv_name_9c_priv.key" -out "private/piv_name_9c_priv.pfx"

❊ Create Private + Cert (.PEM)

openssl pkcs12 -in "private/piv_name_9c_priv.pfx" -aes-256-cbc -out "private/piv_name_9c_priv.pem"

❊ Create Private Key (.KEY)

You can skip the steps for Create Private Key, this was done in the first command. These are here in case you need to create more.

The following can generate a private encrypted key from your PFX file.

openssl pkcs12 -in "private/piv_name_9c_priv.pfx" -nocerts -out "private/piv_name_9c_enc_priv.key"

❊ Create OpenSSH (.PUB)

To generate your OpenSSH key, you must ensure that the permissions on your pem file are properly set. This means that you must right-click on this file, go to the Security tab, and make sure Inheritance is disabled.

ssh-keygen -y -f "private/piv_name_9c_priv.pem" > "openssh/piv_name_9c_openssh.pub"

❊ Create Private RSA (.PEM)

Export private RSA key which can be used for connecting to SSH via Filezilla:

openssl rsa -in "private/piv_name_9c_priv.pem" -out "private/piv_name_9c_priv_rsa.pem" -outform PEM -traditional

❊ Create Public Certificate (.PEM)

Export public cert / key (PEM):

openssl pkcs12 -in "private/piv_name_9c_priv.pfx" -clcerts -nokeys -out "public/piv_name_9c_pub.pem"

❊ Create Public Key

Export public key (RSA):

openssl rsa -in "private/piv_name_9c_priv.pem" -pubout > "public/piv_name_9c_pub.pub"

❊ Import to Windows User Certificates

Type certmgr. msc

Navigate to Certificates -> Current User -> Personal -> Certificates

In the white space, right-click and select All Tasks -> Import.

For Store Location select Current User and click Next.

Select the Browse button.

In the bottom right corner, click the dropdown and select Personal Information Exchange (*.pfx;*.p12) and select your recently exported piv_name_9c_priv.pfx

Select Next:

Enter the password you defined when you exported your PFX file with the openssl command.

Select Mark this key as exportable if you want to do a final export from the User Certificates list. If you do not select this option, you will not be able to export it later if you lose your openssl copies.

On the next window, it will ask where you wish to import the certificate to. I import to two locations:

You will need to import twice, to both the following locations:

  • Certificates -> Current User -> Personal -> Certificates

  • Certificates -> Current User -> Trusted Root Certification Authorities -> Certificates

You must place your certificate in the Trusted Root Certification Authorities folder if you wish to sign code using Powershell's Set-AuthenticodeSignature command.

Once you've completed the import:

Click Yes and you will finish the import:

You will need to go through the import process again to install your certificate in the other specified folders from above.

After completing the above steps, you should have the following files. You may delete the files you do not want, but ensure you leave at least one private key, one public, and the certificate. Also leave the OpenSSH public key if you wish to use this PIV slot to authenticate with SSH.

❊ Import to Yubikey (Yubikey Manager)

Launch Yubikey Manager

Select Applications -> PIV

Select Configure Certificates

Select the .pfx file that you exported from OpenSSL and select Import.

You will be prompted to enter the password you provided when you first created your .pfx certificate:

You'll be asked for your Management Key.

Your PIV certificate should now be imported into your Digital Signature (9C) slot.

❊ Import to Yubikey (command-line)

You do not have to follow these steps if you've already imported your PIV certificate using the Yubikey Manager.

Open command prompt, terminal, or Powershell.

Execute the following command, change the path to where your PIV .pfx certificate is located:

ykman piv import-certificate 9c C:\path\to\your.pfx`

You will be prompted for your .pfx password and your management key.

❊ Summary

You now have a PIV certificate stored on your Yubikey in slot 9C. You can sign code or files with this certificate.

Last updated