Skip to content

Commit

Permalink
Merge pull request #16452 from nextcloud/bug/noid/error-with-exceptio…
Browse files Browse the repository at this point in the history
…n-on-ssl-error

Error with exception on SSL error
  • Loading branch information
MorrisJobke committed Jul 18, 2019
2 parents 3011449 + 4ae1742 commit baff2cc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/private/Authentication/Token/IProvider.php
Expand Up @@ -45,6 +45,7 @@ interface IProvider {
* @param int $type token type
* @param int $remember whether the session token should be used for remember-me
* @return IToken
* @throws \RuntimeException when OpenSSL reports a problem
*/
public function generateToken(string $token,
string $uid,
Expand Down Expand Up @@ -82,6 +83,7 @@ public function getTokenById(int $tokenId): IToken;
* @param string $oldSessionId
* @param string $sessionId
* @throws InvalidTokenException
* @throws \RuntimeException when OpenSSL reports a problem
*/
public function renewSessionToken(string $oldSessionId, string $sessionId);

Expand Down Expand Up @@ -158,6 +160,7 @@ public function setPassword(IToken $token, string $tokenId, string $password);
* @param string $oldTokenId
* @param string $newTokenId
* @return IToken
* @throws \RuntimeException when OpenSSL reports a problem
*/
public function rotate(IToken $token, string $oldTokenId, string $newTokenId): IToken;

Expand Down
2 changes: 2 additions & 0 deletions lib/private/Authentication/Token/Manager.php
Expand Up @@ -109,6 +109,7 @@ public function getTokenByUser(string $uid): array {
*
* @param string $tokenId
* @throws InvalidTokenException
* @throws \RuntimeException when OpenSSL reports a problem
* @return IToken
*/
public function getToken(string $tokenId): IToken {
Expand Down Expand Up @@ -206,6 +207,7 @@ public function invalidateOldTokens() {
* @param string $newTokenId
* @return IToken
* @throws InvalidTokenException
* @throws \RuntimeException when OpenSSL reports a problem
*/
public function rotate(IToken $token, string $oldTokenId, string $newTokenId): IToken {
if ($token instanceof DefaultToken) {
Expand Down
8 changes: 8 additions & 0 deletions lib/private/Authentication/Token/PublicKeyTokenProvider.php
Expand Up @@ -61,6 +61,9 @@ public function __construct(PublicKeyTokenMapper $mapper,
$this->time = $time;
}

/**
* {@inheritDoc}
*/
public function generateToken(string $token,
string $uid,
string $loginName,
Expand Down Expand Up @@ -268,6 +271,7 @@ private function hashToken(string $token): string {
/**
* Convert a DefaultToken to a publicKeyToken
* This will also be updated directly in the Database
* @throws \RuntimeException when OpenSSL reports a problem
*/
public function convertToken(DefaultToken $defaultToken, string $token, $password): PublicKeyToken {
$pkToken = $this->newToken(
Expand All @@ -286,6 +290,9 @@ public function convertToken(DefaultToken $defaultToken, string $token, $passwor
return $this->mapper->update($pkToken);
}

/**
* @throws \RuntimeException when OpenSSL reports a problem
*/
private function newToken(string $token,
string $uid,
string $loginName,
Expand All @@ -306,6 +313,7 @@ private function newToken(string $token,
$res = openssl_pkey_new($config);
if ($res === false) {
$this->logOpensslError();
throw new \RuntimeException('OpenSSL reported a problem');
}

openssl_pkey_export($res, $privateKey);
Expand Down

0 comments on commit baff2cc

Please sign in to comment.