Skip to content

Commit

Permalink
added additional functions
Browse files Browse the repository at this point in the history
added functions to set CHUID, CCCID, and PIN/PUK retries
  • Loading branch information
zhardie authored and zhardie committed Feb 27, 2020
1 parent e288c52 commit ff53782
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ykpiv.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,42 @@ func (y Yubikey) verify(cPin *C.char) (int, error) {
return int(tries), nil
}

func (y Yubikey) SetCHUID(chuid []byte) error {
cChuid := (*C.ykpiv_cardid)(C.CBytes(chuid))
defer C.free(unsafe.Pointer(cChuid))
return getError(C.ykpiv_util_set_cardid(y.state, cChuid), "util_set_cardid")
}

func (y Yubikey) SetCCCID(cccid []byte) error {
cCccid := (*C.ykpiv_cccid)(C.CBytes(cccid))
defer C.free(unsafe.Pointer(cCccid))
return getError(C.ykpiv_util_set_cccid(y.state, cCccid), "util_set_cccid")
}

func (y Yubikey) SetPINPUKRetries(pin string, pintries int, puktries int) error {
cPin := (*C.char)(C.CString(pin))
defer C.free(unsafe.Pointer(cPin))

tries := C.int(0)

err := getError(C.ykpiv_verify(y.state, cPin, &tries), "verify")
if err != nil {
panic(err)
}

err = y.Authenticate()
if err != nil {
panic(err)
}

cPinTries := C.int(pintries)
cPukTries := C.int(puktries)

err = getError(C.ykpiv_set_pin_retries(y.state, cPinTries, cPukTries), "set_pin_retries")

return err
}

// PIN Retries
func (y Yubikey) PINRetries() (int, error) {
return y.verify(nil)
Expand Down

0 comments on commit ff53782

Please sign in to comment.