Created
December 12, 2021 09:48
-
-
Save witalisoft/fa0287b938520be3cee65b24a59a1c8c to your computer and use it in GitHub Desktop.
yubikey attestation client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/base64" | |
"fmt" | |
"log" | |
"strings" | |
"github.com/go-piv/piv-go/piv" | |
) | |
func main() { | |
cards, err := piv.Cards() | |
if err != nil { | |
log.Fatalf("cannot find smart cards, err:%+v", err) | |
} | |
var yk *piv.YubiKey | |
var ykFound bool | |
for _, card := range cards { | |
if strings.Contains(strings.ToLower(card), "yubikey") { | |
if yk, err = piv.Open(card); err != nil { | |
log.Fatalf("cannot open yubikey, err: %+v", err) | |
} | |
ykFound = true | |
break | |
} | |
} | |
if ykFound { | |
slotAttestationCertificate, err := yk.Attest(piv.SlotAuthentication) | |
if err != nil { | |
log.Fatalf("cannot attest, err: %+v", err) | |
} | |
fmt.Println(base64.StdEncoding.EncodeToString(slotAttestationCertificate.Raw)) | |
} else { | |
log.Fatal("could find yubikey device") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment