Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IProvideUserSecretBackend compatibility for per-user encryption #697

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

summersab
Copy link

This PR is intended to implement the functionality from PR #537. The upstream code changed enough that it was easier to close the original PR and submit a new one.

Now that the IProvideUserSecretBackend class has been added to the Nextcloud core with PR nextcloud/server#24837, this PR adds the necessary logic to support per-user SAML provided secrets.

@summersab summersab force-pushed the IProvideUserSecretBackend branch 2 times, most recently from 2835706 to cd0c669 Compare February 10, 2023 20:18
@summersab
Copy link
Author

@blizzz, you look like one of the top contributors to this repo. Is the CI check broken?

@blizzz
Copy link
Member

blizzz commented May 12, 2023

@blizzz, you look like one of the top contributors to this repo. Is the CI check broken?

Only partly, it should be green up to and including stable25. We're working on getting it back for 26 and master.

@immerda
Copy link

immerda commented May 20, 2023

Hey, this is just our yearly reminder that we are still testing this patch in our instance. In fact I just applied this new PR to the newest released nextcloud version and it works perfectly well and is stable enough that we can still decrypt the data from 2.5 years ago when we initially proposed this patch :) We are still eagerly awaiting upstream adoption...

@summersab summersab marked this pull request as draft July 11, 2023 13:54
@summersab summersab marked this pull request as ready for review July 11, 2023 14:25
@summersab summersab force-pushed the IProvideUserSecretBackend branch 2 times, most recently from becfef3 to f5de408 Compare August 24, 2023 16:52
@mglants
Copy link

mglants commented Nov 2, 2023

Any news, when it will be supported, readlly want to use saml for server-side encryption

Signed-off-by: summersab <[email protected]>

perform a little lint cleanup

Signed-off-by: summersab <[email protected]>
Signed-off-by: Andrew Summers <[email protected]>
Copy link
Member

@blizzz blizzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! Rebased (CI is repaired since) and left a first review.

@@ -608,6 +665,21 @@ private function getAttributeArrayValue($name, array $attributes) {
return $value;
}

private function getUserSecret($uid, array $attributes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$uid is unused and can be removed.

@@ -608,6 +665,21 @@ private function getAttributeArrayValue($name, array $attributes) {
return $value;
}

private function getUserSecret($uid, array $attributes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private function getUserSecret($uid, array $attributes) {
private function getUserSecret(array $attributes): ?string {

$this->initializeHomeDir($uid);
}
}

private function getUserSecretHash($uid) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private function getUserSecretHash($uid) {
private function getUserSecretHashes($uid): array {

may return up to ten, should be reflected in the name. Is 10 an arbitrary number, or where does it come from?

return $data;
}

private function checkUserSecretHash($uid, $userSecret) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private function checkUserSecretHash($uid, $userSecret) {
private function checkUserSecretHash($uid, $userSecret): bool {

$data = $this->getUserSecretHash($uid);
foreach($data as $row) {
$storedHash = $row['token'];
if (\OC::$server->getHasher()->verify($userSecret, $storedHash, $newHash)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use ' \OCP\Server::get(OCP\Security\IHasher::class)over deprecated and private\OC::$server->getHasher()`. Also on in the other places.

'name' => $qb->createNamedParameter('sso_secret_hash'),
]);
}
return $qb->execute();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return $qb->execute();
return $qb->executeStatement() > 0;

return false;
}

private function updateUserSecretHash($uid, $userSecret, $exists = false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private function updateUserSecretHash($uid, $userSecret, $exists = false) {
private function updateUserSecretHash($uid, $userSecret, $exists = false): bool {

if ($userSecret !== null) {
$this->updateUserSecretHash($uid, $userSecret);
// Emit a post login action to initialize the encryption module with the user secret provided by the idp.
\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $uid, 'password' => $userSecret, 'isTokenLogin' => false]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please dispatch the typed event \OCP\User\Events\PostLoginEvent instead of deprecated OC_Hook::emit(…).

$storedHash = $row['token'];
if (\OC::$server->getHasher()->verify($userSecret, $storedHash, $newHash)) {
if (!empty($newHash)) {
$this->updateUserSecretHash($uid, $userSecret, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mh, the function is said to check the hash, not update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants