Skip to content
/ gopiv Public

A NIST 800-73-4 standards compliant PIV library written in Go

License

Notifications You must be signed in to change notification settings

gm3197/gopiv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gopiv

A NIST 800-73-4 standards compliant PIV library written in Go, with support for additional card management functionality offered by various manufacturers' proprietary extensions to the PIV protocol. Work in progress.

Use

Uses the scard go library to interact with the underlying smartcard.

ctx, err := scard.EstablishContext()
if err != nil {
	log.Fatalln(err)
}

readers, err := ctx.ListReaders()
if err != nil {
	log.Fatalln(err)
}

if len(readers) == 0 {
	log.Fatalln("No connected smartcard readers")
}

card, err := ctx.Connect(readers[0], scard.ShareShared, scard.ProtocolAny)
if err != nil {
	log.Fatalln(err) // No smartcard inserted in reader
}

defer card.Disconnect(scard.ResetCard)

pivCard, err := gopiv.GetPivCard(card)
if err != nil {
	log.Fatalln(err) // Connected smartcard supports PIV
}

cert, err := pivCard.GetCertificate(gopiv.AuthenticationSlot)
if err != nil {
	log.Fatalln(err)
}

log.Println(cert.Subject.CommonName)

if yubikey, ok := pivCard.(*gopiv.Yubikey); ok {
	// Connected smartcard supports Yubico's PIV extensions

	attestation, err := yubikey.Attest(gopiv.AuthenticationKey)
	if err != nil {
		log.Fatalln(err)
	}

	log.Println(cert.Subject.CommonName)
}

About

A NIST 800-73-4 standards compliant PIV library written in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages