diff --git a/lam/VERSION b/lam/VERSION index e1fd4e69..d09670ea 100644 --- a/lam/VERSION +++ b/lam/VERSION @@ -1 +1 @@ -7.3.PRE1 +7.3.DEV diff --git a/lam/lib/persistence.inc b/lam/lib/persistence.inc index 2c720b57..73a3a73c 100644 --- a/lam/lib/persistence.inc +++ b/lam/lib/persistence.inc @@ -1,5 +1,6 @@ _getPdfProfiles($serverProfiles); $jsonData['pdfProfileTemplates'] = $this->_getPdfProfileTemplates(); $jsonData['selfServiceProfiles'] = $this->_getSelfServiceProfiles(); - /** - * TODO - * - * webauthn - */ + $jsonData['webauthn'] = $this->_getWebauthn(); return json_encode($jsonData); } @@ -238,6 +235,24 @@ class ConfigDataExporter { return $data; } + /** + * Returns the content of the webauthn database. + * + * @return array data + */ + public function _getWebauthn() { + $data = array(); + if ((version_compare(phpversion(), '7.2.0') >= 0) + && extension_loaded('PDO') + && in_array('sqlite', \PDO::getAvailableDrivers())) { + include_once __DIR__ . '/webauthn.inc'; + $webauthnManager = new WebauthnManager(); + $webauthnDatabase = $webauthnManager->getDatabase(); + $data = $webauthnDatabase->export(); + } + return $data; + } + } /** @@ -296,6 +311,13 @@ class ConfigDataImporter { case 'selfServiceProfiles': $steps[] = new ImporterStep(_('Self service profiles'), 'selfServiceProfiles', $value); break; + case 'webauthn': + if ((version_compare(phpversion(), '7.2.0') >= 0) + && extension_loaded('PDO') + && in_array('sqlite', \PDO::getAvailableDrivers())) { + $steps[] = new ImporterStep(_('WebAuthn devices'), 'webauthn', $value); + } + break; default: logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); } @@ -343,6 +365,9 @@ class ConfigDataImporter { case 'selfServiceProfiles': $this->importSelfServiceProfiles($step); break; + case 'webauthn': + $this->importWebauthn($step); + break; default: logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); } @@ -560,6 +585,21 @@ class ConfigDataImporter { } } + /** + * Imports the webauthn data. + * + * @param ImporterStep $step importer step + * @throws LAMException error saving profiles + */ + private function importWebauthn($step) { + $failedNames = array(); + $data = $step->getValue(); + include_once __DIR__ . '/webauthn.inc'; + $webauthnManager = new WebauthnManager(); + $webauthnDatabase = $webauthnManager->getDatabase(); + $webauthnDatabase->import($data); + } + } /** diff --git a/lam/lib/webauthn.inc b/lam/lib/webauthn.inc index 6fe880cf..570cba3a 100644 --- a/lam/lib/webauthn.inc +++ b/lam/lib/webauthn.inc @@ -650,6 +650,53 @@ class PublicKeyCredentialSourceRepositorySQLite implements PublicKeyCredentialSo $pdo->exec($sql); } + /** + * Exports all entries. + * + * @return array data + */ + public function export() { + $pdo = $this->getPDO(); + $statement = $pdo->prepare('select * from ' . self::TABLE_NAME); + $statement->execute(); + $dbData = $statement->fetchAll(); + $data = array(); + foreach ($dbData as $dbRow) { + $data[] = array( + 'userId' => $dbRow['userId'], + 'credentialId' => $dbRow['credentialId'], + 'credentialSource' => $dbRow['credentialSource'], + 'registrationTime' => $dbRow['registrationTime'], + 'lastUseTime' => $dbRow['lastUseTime'], + ); + } + return $data; + } + + /** + * Imports entries from export data. + * + * @param array $data export data + */ + public function import($data) { + $pdo = $this->getPDO(); + $statement = $pdo->prepare('delete from ' . self::TABLE_NAME); + $statement->execute(); + if (empty($data)) { + return; + } + foreach ($data as $dbRow) { + $statement = $pdo->prepare('insert into ' . self::TABLE_NAME . ' (userId, credentialId, credentialSource, registrationTime, lastUseTime) VALUES (?, ?, ?, ?, ?)'); + $statement->execute(array( + $dbRow['userId'], + $dbRow['credentialId'], + $dbRow['credentialSource'], + $dbRow['registrationTime'], + $dbRow['lastUseTime'] + )); + } + } + }