private function createGenerateKeysSetting() { $this->generateKeys = new SystemSetting('generateKeys', Piwik::translate('LoginEncrypted_SettingsGenerateKeysTitle')); $this->generateKeys->readableByCurrentUser = true; $this->generateKeys->type = static::TYPE_BOOL; $this->generateKeys->uiControlType = static::CONTROL_CHECKBOX; $this->generateKeys->description = Piwik::translate('LoginEncrypted_SettingsGenerateKeysDescription'); $this->generateKeys->defaultValue = false; $this->generateKeys->transform = function ($value, $setting) { // check if check box got activated, and generate keys if so if ($value != $setting->defaultValue) { $publickey = Crypto::generateKeys($this->keyLength->getValue()); $this->publicKey->setValue($publickey['e'] . ', ' . $publickey['n']); } return $setting->defaultValue; // reset checkbox }; $this->addSetting($this->generateKeys); }
/** * Generates new keys and stores them in all the places necessary. Existing keys will be overwritten. */ protected function generateKeysAndStoreAll() { $settings = new Settings(); // generate keys and store the private key in DB, and the public key in the JS file // Notes: - Key length with be the one configured in the plugin settings, or the default // from there if none has been configured yet. $publickey = Crypto::generateKeys($settings->keyLength->getValue()); // store the public key in plugin settings as well, for viewing purposes $settings->publicKey->setValue($publickey['e'] . ', ' . $publickey['n']); $settings->save(); }