Skip to content

Commit

Permalink
[mms] Added PGP backend support for the gnupg PECL extension (Request…
Browse files Browse the repository at this point in the history
… #8093).

For now, only a few features are implemented. Still need to add the bulk
of the functionality.
  • Loading branch information
slusarz committed Mar 25, 2015
1 parent 40d004d commit c12b889
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 4 deletions.
3 changes: 3 additions & 0 deletions framework/Crypt/lib/Horde/Crypt/Pgp.php
Expand Up @@ -847,6 +847,9 @@ protected function _initDrivers()
if (isset($this->_params['backends'])) {
$this->_backends = $this->_params['backends'];
} else {
if (Horde_Crypt_Pgp_Backend_Pecl::supported()) {
$this->_backends[] = new Horde_Crypt_Pgp_Backend_Pecl();
}
if (Horde_Crypt_Pgp_Backend_Binary::supported()) {
$this->_backends[] = new Horde_Crypt_Pgp_Backend_Binary(
$this->_params['program'],
Expand Down
82 changes: 82 additions & 0 deletions framework/Crypt/lib/Horde/Crypt/Pgp/Backend/Pecl.php
@@ -0,0 +1,82 @@
<?php
/**
* Copyright 2015 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2015 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Crypt
*/

/**
* PGP backend that uses the PECL gnupg extension.
*
* 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.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2015 Horde LLC
* @internal
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Crypt
*/
class Horde_Crypt_Pgp_Backend_Pecl
extends Horde_Crypt_Pgp_Backend
{
/**
*/
static public function supported()
{
return Horde_Util::extensionExists('gnupg');
}

/**
*/
public function getSignersKeyId($text)
{
$gpg = new gnupg();

if (($info = $gpg->verify($text, false)) === false) {
throw new RuntimeException();
}

if (count($info)) {
$data = reset($info);
if (isset($data['fingerprint'])) {
return substr($data['fingerprint'], -8);
}
}

return null;
}

/**
* Get the fingerprints from a key block.
*
* @param string $pgpdata The PGP data block.
*
* @return array The fingerprints in $pgpdata indexed by key id.
*/
public function getFingerprintsFromKey($pgpdata)
{
$gpg = new gnupg();

if (($info = $gpg->import($pgpdata)) === false) {
throw new RuntimeException();
}

$out = array();

if (strlen($info['fingerprint'])) {
$out['0x' . substr($info['fingerprint'], -8)] = $info['fingerprint'];
}

return $out;
}

}
18 changes: 14 additions & 4 deletions framework/Crypt/package.xml
Expand Up @@ -18,15 +18,16 @@
</lead>
<date>2015-03-25</date>
<version>
<release>2.5.4</release>
<api>2.5.0</api>
<release>2.6.0</release>
<api>2.6.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Added PGP backend support for the gnupg PECL extension (Request #8093).
* [mms] Split gnupg specific code out into a separate PGP backend driver.
* [mms] S/MIME encryption is now done only with AES (if using PHP 5.4+) or 3DES.
</notes>
Expand Down Expand Up @@ -422,6 +423,14 @@
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
<package>
<name>gnupg</name>
<channel>pecl.php.net</channel>
<min>1.0.0</min>
<max>2.0.0alpha1</max>
<exclude>2.0.0alpha1</exclude>
<providesextension>gnupg</providesextension>
</package>
</optional>
</dependencies>
<phprelease>
Expand Down Expand Up @@ -1073,14 +1082,15 @@ Initial release as a PEAR package
</release>
<release>
<version>
<release>2.5.4</release>
<api>2.5.0</api></version>
<release>2.6.0</release>
<api>2.6.0</api></version>
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2015-03-25</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Added PGP backend support for the gnupg PECL extension (Request #8093).
* [mms] Split gnupg specific code out into a separate PGP backend driver.
* [mms] S/MIME encryption is now done only with AES (if using PHP 5.4+) or 3DES.
</notes>
Expand Down

0 comments on commit c12b889

Please sign in to comment.