YKLS(1)

✨ NAME ✨

ykls β€” it's go-ykpiv, bestie πŸ’–

okay so real talk: go-ykpiv is a high level cgo wrapper around libykpiv.so.1 that implements an idiomatic go API fit for use when applications need to communicate with a Yubikey in PIV mode. yes that's the whole pitch. it's giving "glue code but make it cute" and honestly? ate. ✨


πŸͺͺ What's PIV? πŸͺͺ

PIV Cards are cards defined by FIPS 201, a Federal US Government standard defining the ID cards employees use. at its core, it's a set of x509 Certificates and corresponding private keys in a configuration that is standardized across implementations. no cap, that's it, that's the lore. πŸ”

For more details on how PIV Tokens can be used, the FICAM (Federal Identity, Credential, and Access Management) team at GSA (General Services Administration) has published some guides on GitHub under GSA/piv-guides https://github.com/GSA/piv-guides β€” go read them, they lowkey ate πŸ’…


πŸ¦‹ How is this different than OpenSC? πŸ¦‹

Most PIV tokens, Yubikeys included, can be used as a PKCS#11 device using OpenSC https://github.com/opensc/opensc, and Yubikeys are even capable of doing Signing and Decryption through that interface. iconic honestly, we love to see it. πŸŽ€

BUT β€” and this is the plot twist β€” some management functions are not exposed in the PKCS#11 OpenSC interface, so this library may be of use when one wants to write a new Certificate, or set PINs. periodt. that's the gap, and ykls is filling it. πŸ‘‘


πŸ§ͺ Testing πŸ§ͺ

bestie. read this section twice. i'm so serious. πŸ’€

To run the tests, you'll need to find a Yubikey that you're willing to wipe clean, and destroy all data on it. After you've found such a key, remove all other Yubikeys from your machine. yes, all of them. physically. unplug them. πŸ™ˆ

The tests will panic if the YKPIV_YES_DESTROY_MY_KEY environment variable is unset. so like, if you didn't say the safe word, it screams instead. 😭

Running the tests will reset your Yubikey a few times (once per test), and you will wind up with a key with the default PIN, PUK and Management Key. that's not a bug, that's the aftercare. 🫢


🐧 Debian 🐧

sudo apt install build-essential libykpiv-dev
go get pault.ag/go/ykpiv

🍎 MacOS X 🍎

brew install yubico-piv-tool
go get pault.ag/go/ykpiv

and now the little hello-world moment, the main character energy snippet 🌈:

package main

import (
     "fmt"

     "pault.ag/go/ykpiv"
)

func main() {
     yubikey, err := ykpiv.New(ykpiv.Options{
          // Verbose: true,
          Reader: "Yubico Yubikey NEO U2F+CCID 01 00",
     })
     if err != nil {
          panic(err)
     }
     defer yubikey.Close()

     version, err := yubikey.Version()
     if err != nil {
          panic(err)
     }
     fmt.Printf("Application version %s found.\n", version)
}

and if you're on Windows, here's the whole ritual, step by step, don't skip any ✨:

  1. Download yubico-piv-tool-1.7.0-win64.zip from the official site
  2. Create directory win in the root of the project
  3. Copy lib and include directories from the downloaded archive to the win directory
  4. Copy all DLLs from the bin directory in the archive to the root of your project
  5. Copy libwinpthread-1.dll from C:\TDM-GCC-64\bin to the root of your project

also Eric Chiang has published piv-go https://github.com/ericchiang/piv-go, a go implementation of the yubikey piv bindings. another baddie in the ecosystem, we stan a collaborative community πŸ¦‹


Copyright (c) Paul R. Tagliamonte <paultag@gmail.com>, 2017 β€” keep the name attached bestie, it's the rules πŸ’…

and here's the license, verbatim, because legal text does not get the vibe treatment, it gets the respect treatment:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

okay that's the whole page, you made it to the end, so proud of you πŸ’– this one came from The Debian Project, dated August 2025, and it lives under the manual name YKLS(). go forth and be the main character of your own PIV deployment, bestie πŸŽ€βœ¨πŸ«Ά

πŸ“¦ where this page comes from