protected function initializeSession() { $encryptedSessionData = $this->session->get(self::encryptedSessionName); try { $this->sessionValues = json_decode($this->crypto->decrypt($encryptedSessionData, $this->passphrase), true); } catch (\Exception $e) { $this->sessionValues = []; } }
public function manipulateStorageConfig(StorageConfig &$storage) { $encrypted = $this->session->get('password::sessioncredentials/credentials'); if (!isset($encrypted)) { throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved'); } $credentials = json_decode($this->crypto->decrypt($encrypted), true); $storage->setBackendOption('user', $this->session->get('loginname')); $storage->setBackendOption('password', $credentials['password']); }
/** * Retrieve a set of credentials * * @param string|null $userId Null for system-wide credentials * @param string $identifier * @return mixed */ public function retrieve($userId, $identifier) { $qb = $this->dbConnection->getQueryBuilder(); $qb->select('credentials')->from(self::DB_TABLE)->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))); $result = $qb->execute()->fetch(); if (!$result) { return null; } $value = $result['credentials']; return json_decode($this->crypto->decrypt($value), true); }
public function getKey($key) { try { $query = \OCP\DB::prepare("SELECT `value` FROM `*PREFIX*ocsms_config` WHERE `key` = ? AND `user` = ?"); $result = $query->execute(array($key, $this->user)); while ($row = $result->fetchRow()) { return $this->crypto->decrypt($row["value"]); } return false; } catch (DoesNotExistException $e) { return false; } }
/** * Get a value from the session * * @param string $key * @return string|null Either the value or null */ public function get($key) { $encryptedValue = $this->session->get($key); if ($encryptedValue === null) { return null; } try { $value = $this->crypto->decrypt($encryptedValue, $this->passphrase); return json_decode($value); } catch (\Exception $e) { return null; } }
/** * Checks if the CSRF check was correct * @return bool true if CSRF check passed * @see OC_Util::callRegister() */ public function passesCSRFCheck() { if ($this->items['requesttoken'] === false) { return false; } if (isset($this->items['get']['requesttoken'])) { $token = $this->items['get']['requesttoken']; } elseif (isset($this->items['post']['requesttoken'])) { $token = $this->items['post']['requesttoken']; } elseif (isset($this->items['server']['HTTP_REQUESTTOKEN'])) { $token = $this->items['server']['HTTP_REQUESTTOKEN']; } else { //no token found. return false; } // Decrypt token to prevent BREACH like attacks $token = explode(':', $token); if (count($token) !== 2) { return false; } $encryptedToken = $token[0]; $secret = $token[1]; try { $decryptedToken = $this->crypto->decrypt($encryptedToken, $secret); } catch (\Exception $e) { return false; } // Check if the token is valid if (\OCP\Security\StringUtils::equals($decryptedToken, $this->items['requesttoken'])) { return true; } else { return false; } }
private function decryptValue($value) { try { return $this->crypto->decrypt($value); } catch (\Exception $e) { return $value; } }
/** * @param $backend id of the backend * @return array config Values */ public function getByBackend($backend) { $sql = <<<SQL \t\t\t\tSELECT \t\t\t\t\t* \t\t\t\tFROM \t\t\t\t\t`*PREFIX*chat_config` \t\t\t\tWHERE \t\t\t\t\t`user` = ? \t\t\t\tAND \t\t\t\t\t`backend` = ? SQL; $values = array(); $result = $this->findEntities($sql, array($this->user, $backend)); foreach ($result as $r) { $values[$r->getKey()] = $this->crypto->decrypt($r->getValue()); } return $values; }
/** * Decrypt the given password * * The token is used as key * * @param string $password * @param string $token * @throws InvalidTokenException * @return string the decrypted key */ private function decryptPassword($password, $token) { $secret = $this->config->getSystemValue('secret'); try { return $this->crypto->decrypt($password, $token . $secret); } catch (Exception $ex) { // Delete the invalid token $this->invalidateToken($token); throw new InvalidTokenException(); } }
/** * @return Horde_Mail_Transport */ public function createTransport() { $transport = $this->config->getSystemValue('app.mail.transport', 'smtp'); if ($transport === 'php-mail') { return new Horde_Mail_Transport_Mail(); } $password = $this->account->getOutboundPassword(); $password = $this->crypto->decrypt($password); $params = ['host' => $this->account->getOutboundHost(), 'password' => $password, 'port' => $this->account->getOutboundPort(), 'username' => $this->account->getOutboundUser(), 'secure' => $this->convertSslMode($this->account->getOutboundSslMode()), 'timeout' => 2]; return new Horde_Mail_Transport_Smtphorde($params); }