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

support for per-user encryption #537

Closed
wants to merge 2 commits into from
Closed

support for per-user encryption #537

wants to merge 2 commits into from

Conversation

summersab
Copy link

Implementing PR #498 from immerda. It's a feature I'd like to have, and he hasn't been active on GitHub since December. So, I'd like to submit the PR.

@summersab

This comment has been minimized.

@summersab
Copy link
Author

I'm unsure what I need to do to fix the CI error. Any help?

@MichaIng
Copy link
Member

Regarding nextcloud/server#27929 (comment) @summersab you mean the CI drone check? Not sure either, it says the "master" and "stable21" integration tests were cancelled, while the "stable22" integration tests was done and succeeded. Not sure how those work. I just confirmed to run another check (composer) which went well, but I don't think that is related to what drone does. Can you rebase onto current master, so I can see whether drone fails exact the same way?

@juliusknorr
Copy link
Member

Failures seemed to be an unrelated timeout, I've retriggered the CI.

* @return string|null
* @since 23.0.0
*/
public function getCurrentUserSecret() {
Copy link
Member

Choose a reason for hiding this comment

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

Waiting for server PR to be finalized, with a new interface

@immerda
Copy link

immerda commented Nov 1, 2021

I tried this patch and there are currently some issues:

The UserBackend is missing a implements IProvideUserSecretBackend. For that reason the secret is never requested by https://github.com/nextcloud/server/pull/27929/files#diff-b30a8c4cef5da5cede4d9038c16ede43e1746f85270e4249598fd305b0fa77deR182

The getCurrentUserSecret is missing the :string annotation from the interface.

getUserSecret returns null, which contradicts the type of the interface.

@immerda

This comment has been minimized.

@MichaIng
Copy link
Member

MichaIng commented Nov 2, 2021

Whether it's string or ?string needs to follow the interface vice versa and there was no final decision about yet: https://github.com/nextcloud/server/pull/27929/files#r695632608

Generally null passwords were made explicitly possible here: nextcloud/server#29200
And/as of: nextcloud/server#29187

But I lack the overview to reliably follow how everything is linked. As passwords intentionally were made nullable, looks like using ?string is the logical consequence. The other idea would be to conditionally implement the interface only if a password is actually provided. The same way on the current server-side interface code getCurrentUserSecret is only called if the interface is implemented by the backend, so that null means backend with no user secret support/enabled and a string means the backend supports it and then is also expected to provide it, hence a more explicit solution.

@immerda
Copy link

immerda commented Nov 2, 2021

@MichaIng thanks for bringing me up to speed on the discussion!

@summersab I had some time at hand, so here is my working version of this patch, that additionally fixes #547 https://gist.github.com/immerda/527cd5ef0c73cb0e5e4ed6e34c824324

@summersab
Copy link
Author

@summersab I had some time at hand, so here is my working version of this patch, that additionally fixes #547 https://gist.github.com/immerda/527cd5ef0c73cb0e5e4ed6e34c824324

@immerda Your patch is causing some errors after I apply it:

Doctrine\DBAL\Exception\NotNullConstraintViolationException
1364
An exception occurred while executing a query: SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value
/var/www/nextcloud/3rdparty/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php
111

Trace
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1728): Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter->convert()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1667): Doctrine\DBAL\Connection->handleDriverException()
#2 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1146): Doctrine\DBAL\Connection->convertExceptionDuringQuery()
#3 /var/www/nextcloud/lib/private/DB/Connection.php(262): Doctrine\DBAL\Connection->executeStatement()
#4 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(213): OC\DB\Connection->executeStatement()
#5 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(287): Doctrine\DBAL\Query\QueryBuilder->execute()
#6 /var/www/nextcloud/apps/user_saml/lib/UserBackend.php(198): OC\DB\QueryBuilder\QueryBuilder->execute()
#7 /var/www/nextcloud/apps/user_saml/lib/UserBackend.php(750): OCA\User_SAML\UserBackend->updateUserSecretHash()
#8 /var/www/nextcloud/apps/user_saml/lib/Controller/SAMLController.php(147): OCA\User_SAML\UserBackend->updateAttributes()
#9 /var/www/nextcloud/apps/user_saml/lib/Controller/SAMLController.php(335): OCA\User_SAML\Controller\SAMLController->autoprovisionIfPossible()
#10 /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php(217): OCA\User_SAML\Controller\SAMLController->assertionConsumerService()
#11 /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php(126): OC\AppFramework\Http\Dispatcher->executeController()
#12 /var/www/nextcloud/lib/private/AppFramework/App.php(156): OC\AppFramework\Http\Dispatcher->dispatch()
#13 /var/www/nextcloud/lib/private/Route/Router.php(301): OC\AppFramework\App::main()
#14 /var/www/nextcloud/lib/base.php(1000): OC\Route\Router->match()
#15 /var/www/nextcloud/index.php(36): OC::handleRequest()
#16 {main}

I'm pretty sure the rest of my code is clean and unmodified. Any clue?

@immerda
Copy link

immerda commented Nov 12, 2021

@summersab

Your patch is causing some errors after I apply it:

hah, good that somebody else tests it :) I used this unused table user_saml_auth_token to store the hashes, since it was already there... But that table seems to also have a field called name, for some reason and depending on the database backend, it complains if we don't set it to something.

so let's set the name to sso_secret_hash, it could be useful in the future if there are multiple kind of tokens...

I have update the patch. basically added lines 38, 67 and 73

once it is working you should see hashes being inserted into user_saml_auth_token

@summersab
Copy link
Author

Seems to be working, @immerda! I'll poke at it a little more over the weekend just to be sure.

@immerda
Copy link

immerda commented Nov 14, 2021

@summersab sorry, found another bug that is only triggered when the token exires. updated my gist. line 65 needs to be $qb->createNamedParameter($hash) instead of just $hash.

@summersab
Copy link
Author

You're a good man*, @immerda - thanks!

*Or woman - don't want to assume.

@MichaIng
Copy link
Member

nextcloud/server#27929 has been merged, so work here can go on. When the new interface is used, a password must be set, the string is not nullable at server side.

@summersab summersab deleted the branch nextcloud:master February 9, 2023 23:30
@summersab summersab closed this Feb 9, 2023
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.

checkPassword function is incomplete
4 participants