Added pin protection to mobile lib.

This commit is contained in:
Ginder Singh
2024-02-07 01:36:42 -05:00
committed by Cuong Manh Le
parent 9515db7faf
commit faa0ed06b6
2 changed files with 19 additions and 5 deletions

View File

@@ -802,6 +802,15 @@ func RunMobile(appConfig *AppConfig, appCallback *AppCallback, stopCh chan struc
run(appCallback, stopCh)
}
// CheckDeactivationPin checks if deactivation pin is valid
func CheckDeactivationPin(pin int64) int {
deactivationPin = pin
if err := checkDeactivationPin(nil); errors.Is(err, errInvalidDeactivationPin) {
return deactivationPinInvalidExitCode
}
return 0
}
// run runs ctrld cli with given app callback and stop channel.
func run(appCallback *AppCallback, stopCh chan struct{}) {
if stopCh == nil {
@@ -2090,7 +2099,12 @@ func checkDeactivationPin(s service.Service) error {
mainLog.Load().Err(err).Msg("could not check deactivation pin")
return err
}
cc := newSocketControlClient(s, dir)
var cc *controlClient
if s == nil {
cc = newControlClient(filepath.Join(dir, ctrldControlUnixSock))
} else {
cc = newSocketControlClient(s, dir)
}
if cc == nil {
return nil // ctrld is not running.
}

View File

@@ -61,13 +61,13 @@ func mapCallback(callback AppCallback) cli.AppCallback {
}
}
func (c *Controller) Stop() bool {
if c.stopCh != nil {
func (c *Controller) Stop(Pin int64) int {
errorCode := cli.CheckDeactivationPin(Pin)
if errorCode == 0 && c.stopCh != nil {
close(c.stopCh)
c.stopCh = nil
return true
}
return false
return errorCode
}
func (c *Controller) IsRunning() bool {