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

RFC: Support password-less public key token #32624

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
50 changes: 33 additions & 17 deletions lib/private/Authentication/Token/PublicKeyTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ public function setPassword(IToken $token, string $tokenId, string $password) {
throw new InvalidTokenException("Invalid token type");
}

if (true) {
return;
}

// When changing passwords all temp tokens are deleted
$this->mapper->deleteTempToken($token);

Expand All @@ -281,6 +285,10 @@ public function rotate(IToken $token, string $oldTokenId, string $newTokenId): I
throw new InvalidTokenException("Invalid token type");
}

if (true) {
return $token;
}

// Decrypt private key with oldTokenId
$privateKey = $this->decrypt($token->getPrivateKey(), $oldTokenId);
// Encrypt with the new token
Expand Down Expand Up @@ -349,28 +357,32 @@ private function newToken(string $token,
'private_key_bits' => 2048,
], $this->config->getSystemValue('openssl', []));

// Generate new key
$res = openssl_pkey_new($config);
if ($res === false) {
$this->logOpensslError();
throw new \RuntimeException('OpenSSL reported a problem');
}
if (true) {
// Generate new key
$res = openssl_pkey_new($config);
if ($res === false) {
$this->logOpensslError();
throw new \RuntimeException('OpenSSL reported a problem');
}

if (openssl_pkey_export($res, $privateKey, null, $config) === false) {
$this->logOpensslError();
throw new \RuntimeException('OpenSSL reported a problem');
}
if (openssl_pkey_export($res, $privateKey, null, $config) === false) {
$this->logOpensslError();
throw new \RuntimeException('OpenSSL reported a problem');
}

// Extract the public key from $res to $pubKey
$publicKey = openssl_pkey_get_details($res);
$publicKey = $publicKey['key'];
// Extract the public key from $res to $pubKey
$publicKey = openssl_pkey_get_details($res);
$publicKey = $publicKey['key'];

$dbToken->setPublicKey($publicKey);
$dbToken->setPrivateKey($this->encrypt($privateKey, $token));
$dbToken->setPublicKey($publicKey);
$dbToken->setPrivateKey($this->encrypt($privateKey, $token));
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO does it make sense to not store the private key and public anymore if we don't store the passwords?

Copy link
Member

Choose a reason for hiding this comment

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

probably not

Copy link
Member

Choose a reason for hiding this comment

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

Relevant: #30894 #30895


if (!is_null($password)) {
$dbToken->setPassword($this->encryptPassword($password, $publicKey));
if (!is_null($password)) {
$dbToken->setPassword($this->encryptPassword($password, $publicKey));
}
}
$dbToken->setPublicKey('');
$dbToken->setPrivateKey('');

$dbToken->setName($name);
$dbToken->setToken($this->hashToken($token));
Expand Down Expand Up @@ -402,6 +414,10 @@ public function updatePasswords(string $uid, string $password) {
return;
}

if (true) {
return;
}

// Update the password for all tokens
$tokens = $this->mapper->getTokenByUser($uid);
foreach ($tokens as $t) {
Expand Down