yubico

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

telesma-app/yubico

Go Reference Go

Go library for Yubico management information and PIV extensions. Device information is available over PC/SC and CTAPHID.

[!WARNING] This module is under active development. Its public API may change during v0.x.

Features

  • firmware, serial number, form factor, USB/NFC capabilities and FIPS information;
  • model identification from reported device information;
  • PIV slot metadata, attestation, key generation and import with PIN/touch policies;
  • PIV management-key rotation, retry limits, reset and move/delete commands.

Available information and commands depend on the device and firmware.

Installation

go get github.com/telesma-app/yubico@latest

See go.mod for the required Go version.

Quick start

Read device information through a named PC/SC reader:

package main

import (
	"context"
	"fmt"
	"log"

	yubicopcsc "github.com/telesma-app/yubico/transport/pcsc"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}

func run() error {
	device, err := yubicopcsc.Open("exact PC/SC reader name")
	if err != nil {
		return err
	}
	defer device.Close()

	info, err := device.DeviceInfo(context.Background())
	if err != nil {
		return err
	}

	if model, ok := info.ModelName(); ok {
		fmt.Println("model:", model)
	}
	if info.SerialNumber != nil {
		fmt.Println("serial:", *info.SerialNumber)
	}
	fmt.Printf("firmware: %d.%d.%d\n",
		info.FirmwareVersion.Major, info.FirmwareVersion.Minor, info.FirmwareVersion.Build)
	return nil
}

DeviceInfo preserves reported values; optional fields are nil when absent. ModelName derives a name separately and reports whether it recognized the model.

Packages

Package Purpose
yubico Device-information parsing and model identification
transport/pcsc Device information through the management applet
transport/ctaphid Device information through CTAPHID
piv Yubico PIV commands and policies

PIV functions borrow an already selected piv/card.Device. Administrative operations take an explicit card.AdministrationKey. Open the connection with the PIV library; the vendor package adds key policies, metadata and administration commands to that session.

Development

GOWORK=off go test ./...
GOWORK=off go vet ./...
GOWORK=off golangci-lint run ./...

The test suite does not require hardware.

License

Apache License 2.0.

References

Documentation

Overview

Package yubico parses management responses and derives model names. Device access lives under transport/ctaphid and transport/pcsc.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidDeviceInfo reports malformed device-information response data.
	ErrInvalidDeviceInfo = errors.New("yubico: invalid device information")
	// ErrDeviceInfoNotSupported reports an explicit protocol rejection of the
	// GET DEVICE INFORMATION command. The underlying protocol error is retained.
	ErrDeviceInfoNotSupported = errors.New("yubico: device information command not supported")
)

Functions

This section is empty.

Types

type Capability

type Capability uint16

Capability is a bitmap of applications exposed by a YubiKey interface.

const (
	CapabilityOTP     Capability = 0x0001
	CapabilityU2F     Capability = 0x0002
	CapabilityCCID    Capability = 0x0004
	CapabilityOpenPGP Capability = 0x0008
	CapabilityPIV     Capability = 0x0010
	CapabilityOATH    Capability = 0x0020
	CapabilityHSMAuth Capability = 0x0100
	CapabilityCTAP2   Capability = 0x0200
)

func (Capability) String

func (i Capability) String() string

type DeviceInfo

type DeviceInfo struct {
	SupportedUSBCapabilities Capability        `json:"supportedUSBCapabilities"`
	SerialNumber             *uint32           `json:"serialNumber,omitempty"`
	EnabledUSBCapabilities   *Capability       `json:"enabledUSBCapabilities,omitempty"`
	FormFactor               FormFactor        `json:"formFactor"`
	IsFIPS                   bool              `json:"isFIPS"`
	IsSecurityKey            bool              `json:"isSecurityKey"`
	FirmwareVersion          FirmwareVersion   `json:"firmwareVersion"`
	VersionQualifier         *VersionQualifier `json:"versionQualifier,omitempty"`
	AutoEjectTimeout         uint16            `json:"autoEjectTimeout"`
	ChallengeResponseTimeout byte              `json:"challengeResponseTimeout"`
	DeviceFlags              byte              `json:"deviceFlags"`
	Locked                   bool              `json:"locked"`
	PartNumber               *string           `json:"partNumber,omitempty"`
	FIPSCapable              *FIPSCapability   `json:"fipsCapable,omitempty"`
	FIPSApproved             *FIPSCapability   `json:"fipsApproved,omitempty"`
	PinComplexity            *bool             `json:"pinComplexity,omitempty"`
	NFCRestricted            *bool             `json:"nfcRestricted,omitempty"`
	ResetBlocked             *Capability       `json:"resetBlocked,omitempty"`
	FPSVersion               *FirmwareVersion  `json:"fpsVersion,omitempty"`
	STMVersion               *FirmwareVersion  `json:"stmVersion,omitempty"`
	SupportedNFCCapabilities *Capability       `json:"supportedNFCCapabilities,omitempty"`
	EnabledNFCCapabilities   *Capability       `json:"enabledNFCCapabilities,omitempty"`
	RawFields                map[byte][]byte   `json:"rawFields"`
}

DeviceInfo contains reported management values; nil pointers mark absent TLVs. RawFields owns a copy of every tag's last value. Parsing applies no firmware corrections or model inference.

func ParseDeviceInfo

func ParseDeviceInfo(data []byte) (DeviceInfo, error)

ParseDeviceInfo parses TOTAL-LENGTH followed by TAG-LENGTH-VALUE fields.

func ParseDeviceInfoPages

func ParseDeviceInfoPages(pages ...[]byte) (DeviceInfo, error)

ParseDeviceInfoPages merges pages, then checks required fields. Later values replace earlier values of the same tag.

func (DeviceInfo) EffectiveFirmwareVersion

func (info DeviceInfo) EffectiveFirmwareVersion() FirmwareVersion

EffectiveFirmwareVersion returns the alpha/beta qualifier's version or reported firmware.

func (DeviceInfo) HasNFC

func (info DeviceInfo) HasNFC() bool

HasNFC reports whether NFC capability data is valid for this form factor and firmware generation.

func (DeviceInfo) ModelName

func (info DeviceInfo) ModelName() (string, bool)

ModelName derives a product name; unknown firmware or form factors return false. See https://developers.yubico.com/yubikey-manager/API_Documentation/_modules/yubikit/support.html#get_name

type FIPSCapability added in v0.6.0

type FIPSCapability uint16

FIPSCapability is the bitmap used by the FIPS capable and approved TLVs. Its bit positions differ from Capability. Unknown bits are preserved.

const (
	FIPSCapabilityCTAP2   FIPSCapability = 1 << 0
	FIPSCapabilityPIV     FIPSCapability = 1 << 1
	FIPSCapabilityOpenPGP FIPSCapability = 1 << 2
	FIPSCapabilityOATH    FIPSCapability = 1 << 3
	FIPSCapabilityHSMAuth FIPSCapability = 1 << 4
)

type FirmwareVersion

type FirmwareVersion struct {
	Major byte `json:"major"`
	Minor byte `json:"minor"`
	Build byte `json:"build"`
}

FirmwareVersion is the major.minor.build version reported by the device.

func (FirmwareVersion) String

func (v FirmwareVersion) String() string

String formats the reported version as major.minor.build, including 0.0.0.

type FormFactor

type FormFactor byte

FormFactor describes the physical shape and connector type of a YubiKey.

const (
	FormFactorUnknown               FormFactor = 0
	FormFactorUSBAKeychain          FormFactor = 1
	FormFactorUSBANano              FormFactor = 2
	FormFactorUSBCKeychain          FormFactor = 3
	FormFactorUSBCNano              FormFactor = 4
	FormFactorUSBCLightning         FormFactor = 5
	FormFactorUSBABiometricKeychain FormFactor = 6
	FormFactorUSBCBiometricKeychain FormFactor = 7
)

func (FormFactor) String

func (i FormFactor) String() string

type ReleaseType

type ReleaseType byte

ReleaseType identifies the release stage of qualified firmware.

const (
	ReleaseTypeAlpha ReleaseType = iota
	ReleaseTypeBeta
	ReleaseTypeFinal
)

type VersionQualifier

type VersionQualifier struct {
	Version     FirmwareVersion `json:"version"`
	ReleaseType ReleaseType     `json:"releaseType"`
	Iteration   uint32          `json:"iteration"`
	RawFields   map[byte][]byte `json:"rawFields"`
}

VersionQualifier contains the required version, release type and iteration TLVs.

Directories

Path Synopsis
Package piv implements Yubico PIV extensions over a borrowed, selected PIV connection.
Package piv implements Yubico PIV extensions over a borrowed, selected PIV connection.
transport
ctaphid
Package ctaphid accesses Yubico vendor commands over the CTAPHID protocol.
Package ctaphid accesses Yubico vendor commands over the CTAPHID protocol.
pcsc
Package pcsc provides access to Yubico devices over PC/SC.
Package pcsc provides access to Yubico devices over PC/SC.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址