install both wallet and ndef applets
This commit is contained in:
parent
ca6febaa54
commit
de86c19fcc
|
@ -1,2 +1,3 @@
|
||||||
wallet.cap
|
wallet.cap
|
||||||
/build
|
/build
|
||||||
|
*.cap
|
||||||
|
|
|
@ -54,12 +54,14 @@ func (i *Installer) Install(capFile *os.File, overwriteApplet bool) (*Secrets, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
secrets, err := i.installApplet(capFile)
|
err = i.installApplets(capFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return secrets, nil
|
secrets, err := NewSecrets()
|
||||||
|
|
||||||
|
return secrets, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info returns if the applet is already installed in the card.
|
// Info returns if the applet is already installed in the card.
|
||||||
|
@ -165,44 +167,38 @@ func (i *Installer) deleteAID(aids ...[]byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Installer) installApplet(capFile *os.File) (*Secrets, error) {
|
func (i *Installer) installApplets(capFile *os.File) error {
|
||||||
// install for load
|
// install for load
|
||||||
preLoad := globalplatform.NewCommandInstallForLoad(pkgAID, cardManagerAID)
|
preLoad := globalplatform.NewCommandInstallForLoad(pkgAID, cardManagerAID)
|
||||||
_, err := i.send("install for load", preLoad)
|
_, err := i.send("install for load", preLoad)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// load
|
// load
|
||||||
load, err := globalplatform.NewLoadCommandStream(capFile)
|
load, err := globalplatform.NewLoadCommandStream(capFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for load.Next() {
|
for load.Next() {
|
||||||
cmd := load.GetCommand()
|
cmd := load.GetCommand()
|
||||||
_, err = i.send(fmt.Sprintf("load %d of 32", load.Index()), cmd)
|
_, err = i.send(fmt.Sprintf("load %d of 36", load.Index()), cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// install for install
|
installNdef := globalplatform.NewCommandInstallForInstall(pkgAID, ndefAppletAID, ndefInstanceAID, []byte{})
|
||||||
secrets, err := NewSecrets()
|
_, err = i.send("install for install (ndef)", installNdef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
params := []byte(secrets.Puk())
|
installWallet := globalplatform.NewCommandInstallForInstall(pkgAID, walletAID, walletAID, []byte{})
|
||||||
params = append(params, secrets.PairingToken()...)
|
_, err = i.send("install for install (wallet)", installWallet)
|
||||||
|
|
||||||
install := globalplatform.NewCommandInstallForInstall(pkgAID, walletAID, walletAID, params)
|
return err
|
||||||
_, err = i.send("install for install", install)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return secrets, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Installer) send(description string, cmd *apdu.Command, allowedResponses ...uint16) (*apdu.Response, error) {
|
func (i *Installer) send(description string, cmd *apdu.Command, allowedResponses ...uint16) (*apdu.Response, error) {
|
||||||
|
|
Loading…
Reference in New Issue