Registry Mirror
Skip to content

Oc_credentials security? #17439

Closed
Closed

Description

@tanguy-opendsi

Hi,
Can i get informations about the algorithm used to hash password inside oc_credentials.

I think this is synchronous hash because nextcloud need it with external storage but i’m not sure ?

Best regards

Activity

  1. added
    0. Needs triage
    on Oct 7, 2019
  2. kesselb commented on Oct 7, 2019

    @kesselb
    Contributor

    /**
    * Store a set of credentials
    *
    * @param string|null $userId Null for system-wide credentials
    * @param string $identifier
    * @param mixed $credentials
    */
    public function store($userId, $identifier, $credentials) {
    $value = $this->crypto->encrypt(json_encode($credentials));
    $this->dbConnection->setValues(self::DB_TABLE, [
    'user' => $userId,
    'identifier' => $identifier,
    ], [
    'credentials' => $value,
    ]);
    }

    /**
    * Encrypts a value and adds an HMAC (Encrypt-Then-MAC)
    * @param string $plaintext
    * @param string $password Password to encrypt, if not specified the secret from config.php will be taken
    * @return string Authenticated ciphertext
    */
    public function encrypt(string $plaintext, string $password = ''): string {
    if($password === '') {
    $password = $this->config->getSystemValue('secret');
    }
    $this->cipher->setPassword($password);
    $iv = $this->random->generate($this->ivLength);
    $this->cipher->setIV($iv);
    $ciphertext = bin2hex($this->cipher->encrypt($plaintext));
    $hmac = bin2hex($this->calculateHMAC($ciphertext.$iv, $password));
    return $ciphertext.'|'.$iv.'|'.$hmac;
    }

    synchronous hash

    I would say yes.

    Can i get informations about the algorith

    Sure. Everything is open. Please use https://help.nextcloud.com for questions.

  3. Schmuuu commented on Oct 7, 2019

    @Schmuuu

    Hi @kesselb

    Just to let you know, I told him to better ask the developers regarding these questions. We in the Forum don't have much of the insights. Especially when it comes to questions why certain hash functions have been chosen, the broader community is missing the information I think.

  4. kesselb commented on Oct 7, 2019

    @kesselb
    Contributor

    told him to better ask the developers regarding these questions

    Seems valid. Do you think the answer is sufficient? We can still ping some of the paid engineers. But the question is not specific.

  5. Schmuuu commented on Oct 8, 2019

    @Schmuuu

    Thanks :)

    Well, I'm not sure; @tanguy-opendsi does this answer your question?
    The comment seems to be descriptive: "Encrypts a value and adds an HMAC (Encrypt-Then-MAC)"

    And the DB table oc_credentials seems to save a value consisting of
    ciphertext|iv|hmac

    where "iv" seems to be a random number based on the length of an string. I don't understand what iv could mean or what ivLength is about. But maybe you understand that.
    Please let us know what your questions was aiming at and where further clarification is required.

  6. tanguy-opendsi commented on Oct 8, 2019

    @tanguy-opendsi
    Author

    @Schmuuu Thx for your reply yes i'm understanding the HMAC but same like you not the iv
    for the iv i did not understand too :)

  7. kesselb commented on Oct 8, 2019

    @kesselb
    Contributor

    cc @nextcloud/security 🏓

  8. LukasReschke commented on Oct 8, 2019

    @LukasReschke
    Member

    IV = Initialization Vector, which is required as this is using AES in CBC mode.

    https://en.wikipedia.org/wiki/Initialization_vector has some more details.

  9. tanguy-opendsi commented on Oct 8, 2019

    @tanguy-opendsi
    Author

    @LukasReschke that mean HMAC use AES?

  10. LukasReschke commented on Oct 8, 2019

    @LukasReschke
    Member

    The HMAC is there to provide integrity. AES CBC alone doesn’t provide that.

    The answer at https://security.stackexchange.com/questions/63132/when-to-use-hmac-alongside-aes is describing this quite well.

  11. LukasReschke commented on Oct 8, 2019

    @LukasReschke
    Member

    I guess it would be good if you could rephrase your original question so that we can give a better answer :-)

    What are your concerns? What do you want to protect against?

  12. tanguy-opendsi commented on Oct 8, 2019

    @tanguy-opendsi
    Author

    @LukasReschke
    Ok :)
    My question is :
    How work the mechanism when you use external storage?
    Nextcloud have to store and decrypt the password to use external storage properly ?
    If yes, what is the strength of your code (Using salt, what algorithm ect..)
    Can you describe the mechanism ?

  13. olivluca commented on May 19, 2020

    @olivluca

    Isn't it futile to encrypt the password, considered that if an attacker compromises the system he can easily obtain the secret?
    I'd much prefer for the password not to be stored if there is no need for them, yet they are even if I have no external storage configured with stored credentials.

  14. kesselb commented on May 19, 2020

    @kesselb
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triageenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions