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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ public function getForm() {
'type' => 'line',
'required' => true,
],

'user_secret_mapping' => [
'text' => $this->l10n->t('Attribute to use as user secret e.g. for the encryption app.'),
'type' => 'line',
'required' => false,
],
];

$selectedNameIdFormat = $this->config->getAppValue('user_saml', 'sp-name-id-format', Constants::NAMEID_UNSPECIFIED);
Expand Down
31 changes: 31 additions & 0 deletions lib/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public function createUserIfNotExists($uid, array $attributes = array()) {
}
$qb->execute();

// If we use per-user encryption the keys must be initialized first
$userSecret = $this->getUserSecret($uid, $attributes);
if ($userSecret !== null) {
// 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]);
}
$this->initializeHomeDir($uid);

}
Expand Down Expand Up @@ -502,6 +508,16 @@ public function getCurrentUserId() {
return '';
}

/**
* Optionally returns a stable per-user secret. This secret is for
* instance used to secure file encryption keys.
* @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

$samlData = $this->session->get('user_saml.samlUserData');
return $this->getUserSecret($this->getCurrentUserId(), $samlData);
}

/**
* Backend name to be shown in user management
Expand Down Expand Up @@ -600,6 +616,21 @@ private function getAttributeArrayValue($name, array $attributes) {
return $value;
}

private function getUserSecret($uid, array $attributes) {
try {
$userSecret = $this->getAttributeValue('saml-attribute-mapping-user_secret_mapping', $attributes);
if ($userSecret === '') {
$this->logger->debug('Got no user_secret from idp', ['app' => 'user_saml']);
} else {
$this->logger->debug('Got user_secret from idp', ['app' => 'user_saml']);
return $userSecret;
}
} catch (\InvalidArgumentException $e) {
$this->logger->debug('No user_secret mapping configured', ['app' => 'user_saml']);
}
return null;
}

public function updateAttributes($uid,
array $attributes) {
$user = $this->userManager->get($uid);
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/Settings/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public function formDataProvider() {
'type' => 'line',
'required' => true,
],
'user_secret_mapping' => [
'text' => $this->l10n->t('Attribute to use as user secret e.g. for the encryption app.'),
'type' => 'line',
'required' => false,
],
];

$nameIdFormats = [
Expand Down