NOTE: This class is NOT intended to be accessed outside of this package. There is NO guarantees that the API of this class will not change across versions.
Автор: Michael Slusarz (slusarz@horde.org)
Наследование: extends Horde_Pgp_Backend
Пример #1
0
 /**
  * Constructor.
  *
  * @param mixed $data     Data of the part. Either raw PGP data or a
  *                        OpenPGP_Message object.
  * @param array $headers  Header array.
  */
 public function __construct($data, array $headers = array())
 {
     if (!$data instanceof OpenPGP_Message) {
         Horde_Pgp_Backend_Openpgp::autoload();
         $data = OpenPGP_Message::parse($data);
     }
     $this->message = $data;
     $this->headers = $headers;
 }
Пример #2
0
 /**
  */
 public function __construct($data, array $headers = array())
 {
     if (!$data instanceof OpenPGP_Message) {
         Horde_Pgp_Backend_Openpgp::autoload();
         $msg = new OpenPGP_Message();
         /* Trailing (CR)LF is not part of signed data. */
         $pos = strpos($data, '-----BEGIN PGP SIGNATURE-----');
         if ($data[--$pos] === "\r") {
             --$pos;
         }
         $msg[] = new OpenPGP_LiteralDataPacket(self::dashUnescapeText(substr($data, 0, $pos)), array('format' => 'u'));
         $msg[] = Horde_Pgp_Element_Signature::create(substr($data, $pos) . "-----END PGP SIGNATURE-----\n")->message[0];
     } else {
         $msg = $data;
     }
     parent::__construct($msg, $headers);
 }
Пример #3
0
 /**
  */
 public function next()
 {
     $base64 = true;
     $class = $end = $end_armor = $ob_class = $start = null;
     $headers = array();
     $stream = $this->_data;
     while (!($eof = $stream->eof())) {
         $pos = $stream->pos();
         $val = rtrim($stream->getToChar("\n", !is_null($start)));
         if (is_null($end_armor) && strpos($val, '-----BEGIN PGP ') === 0 && substr($val, -5) === '-----') {
             $armor = substr($val, 15, strpos($val, '-', 15) - 15);
             if ($start) {
                 $stream->seek($pos, false);
                 break;
             }
             switch ($armor) {
                 case 'MESSAGE':
                     $class = 'Horde_Pgp_Element_Message';
                     break;
                 case 'PUBLIC KEY BLOCK':
                     $class = 'Horde_Pgp_Element_PublicKey';
                     break;
                 case 'PRIVATE KEY BLOCK':
                     $class = 'Horde_Pgp_Element_PrivateKey';
                     break;
                 case 'SIGNATURE':
                     $class = 'Horde_Pgp_Element_Signature';
                     break;
                 case 'SIGNED MESSAGE':
                     $armor = 'SIGNATURE';
                     $base64 = false;
                     $class = 'Horde_Pgp_Element_SignedMessage';
                     break;
                 default:
                     /* Unknown: ignore. */
                     continue 2;
             }
             $end_armor = '-----END PGP ' . $armor . '-----';
         } elseif (!is_null($end_armor)) {
             if (is_null($start)) {
                 if (strlen($val)) {
                     list($h, $v) = explode(':', $val, 2);
                     $headers[trim($h)] = trim($v);
                 } else {
                     $start = $stream->pos();
                 }
             } elseif ($val === $end_armor) {
                 $end = $pos;
                 $ob_class = $class;
                 break;
             }
         }
     }
     if ($eof && (is_null($this->_key) || is_null($start))) {
         $this->_current = $this->_key = null;
         return;
     }
     if (is_null($ob_class)) {
         $ob_class = 'Horde_Pgp_Element_Text';
     }
     $pos = $stream->pos();
     $data = $stream->getString($start, $end - 1);
     $stream->seek($pos, false);
     if ($base64) {
         /* Get checksum, if it exists. */
         if ($pos = strrpos($data, "\n=")) {
             $checksum = base64_decode(substr($data, $pos + 2, 4));
             $data = base64_decode(substr($data, 0, $pos));
             Horde_Pgp_Backend_Openpgp::autoload();
             $data_checksum = substr(pack('N', OpenPGP::crc24($data)), 1);
             if ($data_checksum !== $checksum) {
                 // Checksum error!
                 return $this->next();
             }
         } else {
             $data = base64_decode($data);
         }
     }
     $this->_current = new $ob_class($data, $headers);
     $this->_key = is_null($this->_key) ? 0 : $this->_key + 1;
 }
Пример #4
0
 /**
  */
 protected function _parseVerify($key, $data, $sig)
 {
     if (is_null($key) || is_null($data)) {
         return false;
     }
     $pgp = new Horde_Pgp_Backend_Openpgp();
     $v = $pgp->verify(new Horde_Pgp_Element_Message(new OpenPGP_Message($data === false ? array($key, $sig) : array($key, $data, $sig))), $this);
     return isset($v[0][$data === false ? 1 : 2][0]);
 }
Пример #5
0
 /**
  * Constructor.
  *
  * @param OpenPGP_PublicKeyPacket $key  Key data.
  */
 public function __construct(OpenPGP_PublicKeyPacket $key)
 {
     Horde_Pgp_Backend_Openpgp::autoload();
     $this->_key = $key;
 }
Пример #6
0
 /**
  * Initialize the backend driver list.
  */
 protected function _initDrivers()
 {
     if (empty($this->_backends)) {
         if (isset($this->_params['backends'])) {
             $this->_backends = $this->_params['backends'];
         } else {
             if (Horde_Pgp_Backend_Openpgp::supported()) {
                 $this->_backends[] = new Horde_Pgp_Backend_Openpgp();
             }
         }
     }
 }