Skip to content

Conversation

tomis007
Copy link
Contributor

@tomis007 tomis007 commented Jul 6, 2025

I noticed that for the newer KeyInfo() method on supported yubikeys if there is no existing data in the requested slot, go-piv returns smart card error 6a88: referenced data or reference data not found. However there's an existing ErrNotFound type that's returned by Attest() when there's no data in the slot. I updated the error codes to also return ErrNotFound for 0x6a88

To reproduce:

package main

import (
        "fmt"
        "strings"

        "github.com/go-piv/piv-go/v2/piv"
)

func main() {
        cards, err := piv.Cards()
        if err != nil {
                fmt.Printf("%v", err)
                return
        }

        // Find a YubiKey and open the reader.
        var yk *piv.YubiKey
        for _, card := range cards {
                if strings.Contains(strings.ToLower(card), "yubikey") {
                        if yk, err = piv.Open(card); err != nil {
                                fmt.Printf("%v", err)
                                return
                        }
                        break
                }
        }
        if yk != nil {
                _, err := yk.KeyInfo(piv.SlotSignature)
                if err != nil {
                        fmt.Println(err)
                }
                _, err = yk.Attest(piv.SlotSignature)
                if errors.Is(err, piv.ErrNotFound) {
                        fmt.Println(err)
                }
        }
}


$ ykman piv reset
$ ./main
command failed: smart card error 6a88: referenced data or reference data not found
data object or application not found

@ericchiang ericchiang merged commit 102a86c into go-piv:v2 Jul 6, 2025
4 checks passed
@ericchiang
Copy link
Collaborator

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants