getPassphrase() public static method

Returns a note's passphrase for symmetric encryption from the session cache.
public static getPassphrase ( string $id ) : string
$id string A note id.
return string The passphrase, if set.
Exemplo n.º 1
0
 /**
  *
  * @param array $row           Hash of the note data, db keys.
  * @param string  $passphrase  The encryption passphrase.
  *
  * @return array a Task hash.
  * @throws Mnemo_Exception
  */
 protected function _buildNote($row, $passphrase = null)
 {
     // Make sure notes always have a UID.
     if (empty($row['memo_uid'])) {
         $row['memo_uid'] = strval(new Horde_Support_Guid());
         $query = 'UPDATE ' . $this->_table . ' SET memo_uid = ?' . ' WHERE memo_owner = ? AND memo_id = ?';
         $values = array($row['memo_uid'], $row['memo_owner'], $row['memo_id']);
         try {
             $this->_db->update($query, $values);
         } catch (Horde_Db_Exception $e) {
             throw new Mnemo_Exception($e->getMessage());
         }
     }
     // Decrypt note if requested.
     $encrypted = false;
     $body = $this->_column->binaryToString($row['memo_body']);
     $body = Horde_String::convertCharset($body, $this->_charset, 'UTF-8');
     if (strpos($body, '-----BEGIN PGP MESSAGE-----') === 0) {
         $encrypted = true;
         if (empty($passphrase)) {
             $passphrase = Mnemo::getPassphrase($row['memo_id']);
         }
         if (empty($passphrase)) {
             $body = new Mnemo_Exception(_("This note has been encrypted."), Mnemo::ERR_NO_PASSPHRASE);
         } else {
             try {
                 $body = $this->_decrypt($body, $passphrase);
                 $body = $body->message;
             } catch (Mnemo_Exception $e) {
                 $body = $e;
             }
             Mnemo::storePassphrase($row['memo_id'], $passphrase);
         }
     }
     // Create a new note based on $row's values.
     $uid = Horde_String::convertCharset($row['memo_uid'], $this->_charset, 'UTF-8');
     $memo = array('memolist_id' => $row['memo_owner'], 'memo_id' => $row['memo_id'], 'uid' => $uid, 'desc' => Horde_String::convertCharset($row['memo_desc'], $this->_charset, 'UTF-8'), 'body' => $body, 'tags' => $GLOBALS['injector']->getInstance('Mnemo_Tagger')->getTags($uid, 'note'), 'encrypted' => $encrypted);
     try {
         $userId = $GLOBALS['registry']->getAuth();
         $log = $GLOBALS['injector']->getInstance('Horde_History')->getHistory('mnemo:' . $row['memo_owner'] . ':' . $row['memo_uid']);
         foreach ($log as $entry) {
             switch ($entry['action']) {
                 case 'add':
                     $memo['created'] = new Horde_Date($entry['ts']);
                     if ($userId != $entry['who']) {
                         $memo['createdby'] = sprintf(_("by %s"), Mnemo::getUserName($entry['who']));
                     } else {
                         $memo['createdby'] = _("by me");
                     }
                     break;
                 case 'modify':
                     $memo['modified'] = new Horde_Date($entry['ts']);
                     if ($userId != $entry['who']) {
                         $memo['modifiedby'] = sprintf(_("by %s"), Mnemo::getUserName($entry['who']));
                     } else {
                         $memo['modifiedby'] = _("by me");
                     }
                     break;
             }
         }
     } catch (Horde_Exception $e) {
     }
     return $memo;
 }
Exemplo n.º 2
0
Arquivo: memo.php Projeto: horde/horde
 /* If $memo_id is set, we're modifying an existing note.  Otherwise,
  * we're adding a new note with the provided attributes. */
 if (!empty($memo_id)) {
     $storage = $injector->getInstance('Mnemo_Factory_Driver')->create($memolist_original);
     if ($memolist_original != $notepad_target) {
         /* Moving the note to another notepad. */
         if (!getShare($memolist_original)->hasPermission($user, Horde_Perms::DELETE)) {
             $notification->push(_("Access denied moving the note."), 'horde.error');
         } else {
             $storage->move($memo_id, $notepad_target);
             $storage = $injector->getInstance('Mnemo_Factory_Driver')->create($notepad_target);
         }
     }
     $memo_desc = $storage->getMemoDescription($memo_body);
     if (!strlen($memo_passphrase) && Horde_Util::getFormData('memo_encrypt') == 'on') {
         $memo_passphrase = Mnemo::getPassphrase($memo_id);
     }
     try {
         $storage->modify($memo_id, $memo_desc, $memo_body, $memo_tags, $memo_passphrase);
     } catch (Mnemo_Exception $e) {
         $haveError = $e->getMessage();
     }
 } else {
     /* Check permissions. */
     if ($injector->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes') !== true && $injector->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) {
         Horde::url('list.php', true)->redirect();
     }
     /* Creating a new note. */
     $storage = $injector->getInstance('Mnemo_Factory_Driver')->create($notepad_target);
     $memo_desc = $storage->getMemoDescription($memo_body);
     try {
Exemplo n.º 3
0
 /**
  * Build a note based on data array
  *
  * @param array $note         The data for the note
  * @param string $passphrase  A passphrase for decrypting a note
  *
  * @return array  The converted data array representing the note
  */
 protected function _buildNote($note, $passphrase = null)
 {
     $encrypted = false;
     $body = $note['body'];
     $id = Horde_Url::uriB64Encode($note['uid']);
     if (strpos($body, '-----BEGIN PGP MESSAGE-----') === 0) {
         $encrypted = true;
         if (empty($passphrase)) {
             $passphrase = Mnemo::getPassphrase($id);
         }
         if (empty($passphrase)) {
             $body = new Mnemo_Exception(_("This note has been encrypted."), Mnemo::ERR_NO_PASSPHRASE);
         } else {
             try {
                 $body = $this->_decrypt($body, $passphrase)->message;
             } catch (Mnemo_Exception $e) {
                 $body = $e;
             }
             Mnemo::storePassphrase($id, $passphrase);
         }
     }
     $tagger = $GLOBALS['injector']->getInstance('Mnemo_Tagger');
     $tags = $tagger->getTags($note['uid'], 'note');
     if (!empty($note['categories'])) {
         usort($tags, 'strcoll');
         if (array_diff($note['categories'], $tags)) {
             $tagger->replaceTags($note['uid'], $note['categories'], $GLOBALS['registry']->getAuth(), 'note');
         }
         $tags = $note['categories'];
     }
     $result = array('memolist_id' => $this->_notepad, 'memo_id' => $id, 'uid' => $note['uid'], 'tags' => $tags, 'desc' => $note['summary'], 'encrypted' => $encrypted, 'body' => $body);
     if (!empty($note['creation-date'])) {
         $result['created'] = new Horde_Date($note['creation-date']);
     }
     if (!empty($note['last-modification-date'])) {
         $result['modified'] = new Horde_Date($note['last-modification-date']);
     }
     return $result;
 }