def ChangePin(self, applicationKey=None): # type: (str) -> bool """ Stores an existing ApplicationKey using a new PIN @param applicationKey: an existing ApplicationKey that will be stored. If none specified, the existing ApplicationKey of the Vault will be used. @return: indication of success """ Logger.Info("Updating the ApplicationKey with a new PIN") if self.__newKeyGeneratedInConstructor: Logger.Info("A key was just generated, no need to change PINs.") return True if applicationKey is None: Logger.Debug("Using the ApplicationKey from the vault.") applicationKey = Vault.__Key else: Logger.Debug("Using the ApplicationKey from the input parameter.") if not applicationKey: raise ValueError("No ApplicationKey specified.") # Now we get a new PIN and (re)encrypt pin = XbmcWrapper.ShowKeyBoard( heading=LanguageHelper.GetLocalizedString(LanguageHelper.VaultNewPin), hidden=True) if not pin: XbmcWrapper.ShowNotification( "", LanguageHelper.GetLocalizedString(LanguageHelper.VaultNoPin), XbmcWrapper.Error) return False pin2 = XbmcWrapper.ShowKeyBoard( heading=LanguageHelper.GetLocalizedString(LanguageHelper.VaultRepeatPin), hidden=True) if pin != pin2: Logger.Critical("Mismatch in PINs") XbmcWrapper.ShowNotification( "", LanguageHelper.GetLocalizedString(LanguageHelper.VaultPinsDontMatch), XbmcWrapper.Error) return False encryptedKey = "%s=%s" % (self.__APPLICATION_KEY_SETTING, applicationKey) # let's generate a pin using the scrypt password-based key derivation pinKey = self.__GetPBK(pin) encryptedKey = self.__Encrypt(encryptedKey, pinKey) AddonSettings.SetSetting(Vault.__APPLICATION_KEY_SETTING, encryptedKey) Logger.Info("Successfully updated the Retrospect PIN") return True
def SetSetting(self, settingId, settingName=None, settingActionId=None): # type: (str, str) -> None """ Reads a value for a setting from the keyboard and encryptes it in the Kodi Add-on settings @param settingId: the ID for the Kodi Add-on setting to set @param settingName: the name to display in the keyboard @param settingActionId: the name of the action that was called. The setttingActionId defaults to <settingId>_set """ Logger.Info("Encrypting value for setting '%s'", settingId) inputValue = XbmcWrapper.ShowKeyBoard( "", LanguageHelper.GetLocalizedString(LanguageHelper.VaultSpecifySetting) % (settingName or settingId, )) if inputValue is None: Logger.Debug("Setting of encrypted value cancelled.") return value = "%s=%s" % (settingId, inputValue) encryptedValue = self.__Encrypt(value, Vault.__Key) if settingActionId is None: settingActionId = "%s_set" % (settingId,) Logger.Debug("Updating '%s' and '%s'", settingId, settingActionId) AddonSettings.SetSetting(settingId, encryptedValue) if inputValue: AddonSettings.SetSetting(settingActionId, "******") else: AddonSettings.SetSetting(settingActionId, "") Logger.Info("Successfully encrypted value for setting '%s'", settingId) return
def __ExtractSessionData(self, logonData, signatureSettings): logonJson = JsonHelper(logonData) resultCode = logonJson.GetValue("statusCode") Logger.Trace("Logging in returned: %s", resultCode) if resultCode != 200: Logger.Error("Error loging in: %s - %s", logonJson.GetValue("errorMessage"), logonJson.GetValue("errorDetails")) return False signatureSetting = logonJson.GetValue("sessionInfo", "login_token") if signatureSetting: Logger.Info("Found 'login_token'. Saving it.") AddonSettings.SetSetting(signatureSettings, signatureSetting.split("|")[0]) self.__signature = logonJson.GetValue("UIDSignature") self.__userId = logonJson.GetValue("UID") self.__signatureTimeStamp = logonJson.GetValue("signatureTimestamp") return True
def Reset(): """ Resets the Vault and Retrospect Machine key, making all encrypted values useless. """ ok = XbmcWrapper.ShowYesNo(LanguageHelper.GetLocalizedString(LanguageHelper.VaultReset), LanguageHelper.GetLocalizedString(LanguageHelper.VaultResetConfirm)) if not ok: Logger.Debug("Aborting Reset Vault") return Logger.Info("Resetting the vault to a new initial state.") AddonSettings.SetSetting(Vault.__APPLICATION_KEY_SETTING, "") # create a vault instance so we initialize a new one with a new PIN. Vault() return
def LogOn(self): if self.__idToken: return True # check if there is a refresh token # refresh token: viervijfzes_refresh_token refreshToken = AddonSettings.GetSetting("viervijfzes_refresh_token") client = AwsIdp("eu-west-1_dViSsKM5Y", "6s1h851s8uplco5h6mqh1jac8m", proxy=self.proxy, logger=Logger.Instance()) if refreshToken: idToken = client.RenewToken(refreshToken) if idToken: self.__idToken = idToken return True else: Logger.Info("Extending token for VierVijfZes failed.") # username: viervijfzes_username username = AddonSettings.GetSetting("viervijfzes_username") # password: viervijfzes_password v = Vault() password = v.GetSetting("viervijfzes_password") if not username or not password: XbmcWrapper.ShowDialog( title=None, lines=LanguageHelper.GetLocalizedString( LanguageHelper.MissingCredentials), ) return False idToken, refreshToken = client.Authenticate(username, password) if not idToken or not refreshToken: Logger.Error("Error getting a new token. Wrong password?") return False self.__idToken = idToken AddonSettings.SetSetting("viervijfzes_refresh_token", refreshToken) return True