add factory reset command
This commit is contained in:
parent
a839ed4597
commit
0e1c703ad8
|
@ -423,6 +423,12 @@ func (cs *CommandSet) StoreData(typ uint8, data []byte) error {
|
|||
return cs.checkOK(resp, err)
|
||||
}
|
||||
|
||||
func (cs *CommandSet) FactoryReset() error {
|
||||
cmd := NewCommandFactoryReset()
|
||||
resp, err := cs.sc.Send(cmd)
|
||||
return cs.checkOK(resp, err)
|
||||
}
|
||||
|
||||
func (cs *CommandSet) mutualAuthenticate() error {
|
||||
data := make([]byte, 32)
|
||||
if _, err := rand.Read(data); err != nil {
|
||||
|
|
13
commands.go
13
commands.go
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
const (
|
||||
InsInit = 0xFE
|
||||
InsFactoryReset = 0xFD
|
||||
InsOpenSecureChannel = 0x10
|
||||
InsMutuallyAuthenticate = 0x11
|
||||
InsPair = 0x12
|
||||
|
@ -56,6 +57,8 @@ const (
|
|||
P2ExportKeyPublicOnly = 0x01
|
||||
P2ExportKeyExtendedPublic = 0x02
|
||||
P1LoadKeySeed = 0x03
|
||||
P1FactoryResetMagic = 0xAA
|
||||
P2FactoryResetMagic = 0x55
|
||||
|
||||
SwNoAvailablePairingSlots = 0x6A84
|
||||
)
|
||||
|
@ -372,6 +375,16 @@ func NewCommandStoreData(typ uint8, data []byte) *apdu.Command {
|
|||
)
|
||||
}
|
||||
|
||||
func NewCommandFactoryReset() *apdu.Command {
|
||||
return apdu.NewCommand(
|
||||
globalplatform.ClaGp,
|
||||
InsFactoryReset,
|
||||
P1FactoryResetMagic,
|
||||
P2FactoryResetMagic,
|
||||
[]byte{},
|
||||
)
|
||||
}
|
||||
|
||||
// Internal function. Get the type of starting point for the derivation path.
|
||||
// Used for both DeriveKey and ExportKey
|
||||
func derivationP1FromStartingPoint(s derivationpath.StartingPoint) (uint8, error) {
|
||||
|
|
|
@ -22,11 +22,13 @@ const (
|
|||
CapabilityKeyManagement
|
||||
CapabilityCredentialsManagement
|
||||
CapabilityNDEF
|
||||
CapabilityFactoryReset
|
||||
|
||||
CapabilityAll = CapabilitySecureChannel |
|
||||
CapabilityKeyManagement |
|
||||
CapabilityCredentialsManagement |
|
||||
CapabilityNDEF
|
||||
CapabilityNDEF |
|
||||
CapabilityFactoryReset
|
||||
)
|
||||
|
||||
type ApplicationInfo struct {
|
||||
|
@ -62,6 +64,10 @@ func (a *ApplicationInfo) HasNDEFCapability() bool {
|
|||
return a.HasCapability(CapabilityNDEF)
|
||||
}
|
||||
|
||||
func (a *ApplicationInfo) HasFactoryResetCapability() bool {
|
||||
return a.HasCapability(CapabilityFactoryReset)
|
||||
}
|
||||
|
||||
func ParseApplicationInfo(data []byte) (*ApplicationInfo, error) {
|
||||
info := &ApplicationInfo{
|
||||
Installed: true,
|
||||
|
|
Loading…
Reference in New Issue