-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03e4ca7
commit 2dcec99
Showing
36 changed files
with
829 additions
and
561 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ This way, the migration from Google Authenticator to OTP Manager will be quick a | |
* [Official iOS App](https://apps.apple.com/us/app/nextcloud-otp-manager/id6471510170) | ||
]]> | ||
</description> | ||
<version>0.4.0</version> | ||
<version>0.5.0</version> | ||
<licence>agpl</licence> | ||
<author mail="[email protected]" homepage="https://www.convertino.cloud">Matteo Convertino</author> | ||
<namespace>OtpManager</namespace> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
// SPDX-FileCopyrightText: Matteo Convertino <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
@@ -7,13 +8,15 @@ | |
|
||
use OCP\AppFramework\App; | ||
|
||
class Application extends App { | ||
class Application extends App | ||
{ | ||
public const APP_ID = 'otpmanager'; | ||
public const ACCOUNTS_DB = 'otpmanager_accounts'; | ||
public const SETTINGS_DB = 'otpmanager_settings'; | ||
public const SHARED_ACCOUNTS_DB = 'otpmanager_shared'; | ||
|
||
public function __construct() { | ||
public function __construct() | ||
{ | ||
parent::__construct(self::APP_ID); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
// SPDX-FileCopyrightText: Matteo Convertino <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
namespace OCA\OtpManager\Controller; | ||
|
||
use OCA\OtpManager\Db\AccountMapper; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\IRequest; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\OCSController; | ||
|
||
class AccountApiController extends OCSController | ||
{ | ||
private AccountMapper $accountMapper; | ||
private ?string $userId; | ||
|
||
public function __construct( | ||
string $AppName, | ||
IRequest $request, | ||
AccountMapper $accountMapper, | ||
?string $UserId = null | ||
) { | ||
parent::__construct($AppName, $request); | ||
$this->accountMapper = $accountMapper; | ||
$this->userId = $UserId; | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
*/ | ||
public function updateCounter(string $secret): JSONResponse | ||
{ | ||
$account = $this->accountMapper->find("secret", $secret, $this->userId); | ||
|
||
if ($account == null) return new JSONResponse(["error" => "This account does not exists"], Http::STATUS_NOT_FOUND); | ||
if ($account->getType() == "totp") return new JSONResponse(["error" => "You cannot update counter of a TOTP account"], Http::STATUS_NOT_FOUND); | ||
|
||
$account->setCounter($account->getCounter() + 1); | ||
$this->accountMapper->update($account); | ||
|
||
return new JSONResponse($account->getCounter(), Http::STATUS_OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
// SPDX-FileCopyrightText: Matteo Convertino <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
@@ -11,17 +12,20 @@ | |
use OCP\IRequest; | ||
use OCP\Util; | ||
|
||
class PageController extends Controller { | ||
class PageController extends Controller | ||
{ | ||
|
||
public function __construct(string $AppName, IRequest $request){ | ||
public function __construct(string $AppName, IRequest $request) | ||
{ | ||
parent::__construct($AppName, $request); | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
*/ | ||
public function index(): TemplateResponse { | ||
public function index(): TemplateResponse | ||
{ | ||
Util::addScript($this->appName, 'otpmanager-main'); | ||
|
||
//throw new \Exception(print_r($accounts)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
// SPDX-FileCopyrightText: Matteo Convertino <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
namespace OCA\OtpManager\Controller; | ||
|
||
use OCA\OtpManager\Db\SettingMapper; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\IRequest; | ||
|
||
|
||
class PasswordApiController extends OCSController | ||
{ | ||
private SettingMapper $settingMapper; | ||
private ?string $userId; | ||
|
||
public function __construct( | ||
string $AppName, | ||
IRequest $request, | ||
SettingMapper $settingMapper, | ||
?string $UserId = null | ||
) { | ||
parent::__construct($AppName, $request); | ||
$this->settingMapper = $settingMapper; | ||
$this->userId = $UserId; | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
*/ | ||
public function check(string $password): JSONResponse | ||
{ | ||
$setting = $this->settingMapper->find($this->userId); | ||
if (is_null($setting) || is_null($setting->getPassword())) return new JSONResponse(["error" => "No password set yet"], 400); | ||
|
||
if (password_verify(hash("sha256", $password), $setting->getPassword())) { | ||
return new JSONResponse(["iv" => $setting->getIv()]); | ||
} else { | ||
return new JSONResponse(["error" => "Incorrect password"], 400); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.