Esempio n. 1
0
 /**
  * Guardar la clave maestra encriptada en la sesión
  */
 public static function saveSessionMPass($masterPass)
 {
     $mPassPwd = Crypt::generateAesKey(session_id());
     $sessionMasterPass = Crypt::mkCustomMPassEncrypt($mPassPwd, $masterPass);
     Session::setMPass($sessionMasterPass[0]);
     Session::setMPassIV($sessionMasterPass[1]);
     return true;
 }
Esempio n. 2
0
 /**
  * Crea una clave temporal para encriptar la clave maestra y guardarla.
  *
  * @param int $maxTime El tiempo máximo de validez de la clave
  * @return bool|string
  */
 public static function setTempMasterPass($maxTime = 14400)
 {
     // Encriptar la clave maestra con hash aleatorio generado
     $randomKey = Crypt::generateAesKey(Util::generate_random_bytes());
     $pass = Crypt::mkCustomMPassEncrypt($randomKey, SessionUtil::getSessionMPass());
     if (!is_array($pass)) {
         return false;
     }
     ConfigDB::setCacheConfigValue('tempmaster_pass', bin2hex($pass[0]));
     ConfigDB::setCacheConfigValue('tempmaster_passiv', bin2hex($pass[1]));
     ConfigDB::setCacheConfigValue('tempmaster_passhash', Crypt::mkHashPassword($randomKey));
     ConfigDB::setCacheConfigValue('tempmaster_passtime', time());
     ConfigDB::setCacheConfigValue('tempmaster_maxtime', time() + $maxTime);
     ConfigDB::setCacheConfigValue('tempmaster_attempts', 0);
     if (!ConfigDB::writeConfig(true)) {
         return false;
     }
     // Guardar la clave temporal hasta que finalice la sesión
     Session::setTemporaryMasterPass($randomKey);
     return $randomKey;
 }
Esempio n. 3
0
 /**
  * Actualizar la clave maestra del usuario en la BBDD.
  *
  * @param string $masterPwd con la clave maestra
  * @return bool
  */
 public function updateUserMPass($masterPwd)
 {
     $configHashMPass = ConfigDB::getValue('masterPwd');
     if ($configHashMPass === false) {
         return false;
     }
     if (is_null($configHashMPass)) {
         $configHashMPass = Crypt::mkHashPassword($masterPwd);
         ConfigDB::setValue('masterPwd', $configHashMPass);
     }
     if (Crypt::checkHashPass($masterPwd, $configHashMPass, true)) {
         $cryptMPass = Crypt::mkCustomMPassEncrypt(self::getCypherPass(), $masterPwd);
         if (!$cryptMPass) {
             return false;
         }
     } else {
         return false;
     }
     $query = 'UPDATE usrData SET ' . 'user_mPass = :mPass,' . 'user_mIV = :mIV,' . 'user_lastUpdateMPass = UNIX_TIMESTAMP() ' . 'WHERE user_id = :id LIMIT 1';
     $data['mPass'] = $cryptMPass[0];
     $data['mIV'] = $cryptMPass[1];
     $data['id'] = $this->_userId;
     return DB::getQuery($query, __FUNCTION__, $data);
 }