Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion lib/private/Security/CredentialsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCP\IDBConnection;
use OCP\Security\ICredentialsManager;
use OCP\Security\ICrypto;
use SensitiveParameter;

/**
* Store and retrieve credentials for external services
Expand All @@ -34,7 +35,12 @@ public function __construct(
* @param mixed $credentials
*/
#[\Override]
public function store(string $userId, string $identifier, $credentials): void {
public function store(
string $userId,
string $identifier,
#[SensitiveParameter]
$credentials,
): void {
$value = $this->crypto->encrypt(json_encode($credentials));

$this->dbConnection->setValues(self::DB_TABLE, [
Expand Down
19 changes: 16 additions & 3 deletions lib/private/Security/Crypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\Security\ICrypto;
use phpseclib\Crypt\AES;
use phpseclib\Crypt\Hash;
use SensitiveParameter;

/**
* Class Crypto provides a high-level encryption layer using AES-CBC. If no key has been provided
Expand Down Expand Up @@ -41,7 +42,11 @@ public function __construct(
* @return string Calculated HMAC
*/
#[\Override]
public function calculateHMAC(string $message, string $password = ''): string {
public function calculateHMAC(
string $message,
#[SensitiveParameter]
string $password = '',
): string {
if ($password === '') {
$password = $this->config->getSystemValueString('secret');
}
Expand All @@ -63,7 +68,11 @@ public function calculateHMAC(string $message, string $password = ''): string {
* @throws Exception if encrypting the data failed
*/
#[\Override]
public function encrypt(string $plaintext, string $password = ''): string {
public function encrypt(
string $plaintext,
#[SensitiveParameter]
string $password = '',
): string {
if ($password === '') {
$password = $this->config->getSystemValueString('secret');
}
Expand Down Expand Up @@ -93,7 +102,11 @@ public function encrypt(string $plaintext, string $password = ''): string {
* @throws Exception If the decryption failed
*/
#[\Override]
public function decrypt(string $authenticatedCiphertext, string $password = ''): string {
public function decrypt(
string $authenticatedCiphertext,
#[SensitiveParameter]
string $password = '',
): string {
$secret = $this->config->getSystemValue('secret');
try {
if ($password === '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use OCP\EventDispatcher\Event;
use OCP\Security\PasswordContext;
use SensitiveParameter;

/**
* Event to request a secure password to be generated
Expand Down Expand Up @@ -50,7 +51,10 @@ public function getPassword(): ?string {
* This is used by password generators to set the generated password.
* @since 18.0.0
*/
public function setPassword(string $password): void {
public function setPassword(
#[SensitiveParameter]
string $password,
): void {
$this->password = $password;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/public/Security/Events/ValidatePasswordPolicyEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use OCP\EventDispatcher\Event;
use OCP\Security\PasswordContext;
use SensitiveParameter;

/**
* This event can be emitted to request a validation of a password.
Expand All @@ -26,6 +27,7 @@ class ValidatePasswordPolicyEvent extends Event {
* @since 31.0.0 - $context parameter added
*/
public function __construct(
#[SensitiveParameter]
private string $password,
private PasswordContext $context = PasswordContext::ACCOUNT,
) {
Expand Down
9 changes: 8 additions & 1 deletion lib/public/Security/ICredentialsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace OCP\Security;

use SensitiveParameter;

/**
* Store and retrieve credentials for external services
*
Expand All @@ -23,7 +25,12 @@ interface ICredentialsManager {
* @param mixed $credentials
* @since 8.2.0
*/
public function store(string $userId, string $identifier, $credentials): void;
public function store(
string $userId,
string $identifier,
#[SensitiveParameter]
$credentials,
): void;

/**
* Retrieve a set of credentials
Expand Down
20 changes: 17 additions & 3 deletions lib/public/Security/ICrypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace OCP\Security;

use SensitiveParameter;

/**
* Class Crypto provides a high-level encryption layer using AES-CBC. If no key has been provided
* it will use the secret defined in config.php as key. Additionally the message will be HMAC'd.
Expand All @@ -26,7 +28,11 @@ interface ICrypto {
* @return string Calculated HMAC
* @since 8.0.0
*/
public function calculateHMAC(string $message, string $password = ''): string;
public function calculateHMAC(
string $message,
#[SensitiveParameter]
string $password = '',
): string;

/**
* Encrypts a value and adds an HMAC (Encrypt-Then-MAC)
Expand All @@ -35,7 +41,11 @@ public function calculateHMAC(string $message, string $password = ''): string;
* @return string Authenticated ciphertext
* @since 8.0.0
*/
public function encrypt(string $plaintext, string $password = ''): string;
public function encrypt(
string $plaintext,
#[SensitiveParameter]
string $password = '',
): string;

/**
* Decrypts a value and verifies the HMAC (Encrypt-Then-Mac)
Expand All @@ -46,5 +56,9 @@ public function encrypt(string $plaintext, string $password = ''): string;
* @throws \Exception If the decryption failed
* @since 8.0.0
*/
public function decrypt(string $authenticatedCiphertext, string $password = ''): string;
public function decrypt(
string $authenticatedCiphertext,
#[SensitiveParameter]
string $password = '',
): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
interface IVerificationToken {
/**
* Checks whether the a provided tokent matches a stored token and its
* Checks whether a provided token matches a stored token and its
* constraints. An InvalidTokenException is thrown on issues, otherwise
* the check is successful.
*
Expand Down
Loading