'--batch',
'--armor'
);
+
$result = $this->_callGpg($cmdline, 'w', $input, true, true);
/* Get the keys from the temp files. */
* signature that has signed that UID. Signatures not associated with a
* UID (e.g. revocation signatures and sub keys) will be stored under the
* special keyword '_SIGNATURE'.
+ *
+ * @throws Horde_Exception
*/
public function pgpPacketInformation($pgpdata)
{
* @param string $pgpdata The PGP data block.
*
* @return string Tabular information on the PGP key.
+ * @throws Horde_Exception
*/
public function pgpPrettyKey($pgpdata)
{
* created => Signature creation - UNIX timestamp
* micalg => The hash used to create the signature
* </pre>
+ * @throws Horde_Exception
*/
public function pgpPacketSignature($pgpdata, $email)
{
* @param string $uid_idx The UID index.
*
* @return array See pgpPacketSignature().
+ * @throws Horde_Exception
*/
public function pgpPacketSignatureByUidIndex($pgpdata, $uid_idx)
{
* @param string $text The PGP signed text block.
*
* @return string The key ID of the key used to sign $text.
+ * @throws Horde_Exception
*/
public function getSignersKeyID($text)
{
*
* @param string $pgpdata The PGP data block.
*
- * @return array The fingerprints in $pgpdata indexed by key id.
+ * @return array The fingerprints in $pgpdata indexed by key id.
+ * @throws Horde_Exception
*/
public function getFingerprintsFromKey($pgpdata)
{
* @param string $text The PGP encrypted text.
*
* @return boolean True if the text is symmetricallly encrypted.
+ * @throws Horde_Exception
*/
public function encryptedSymmetrically($text)
{
* (Default) or 'private'
*
* @return string Command line keystring option to use with gpg program.
+ * @throws Horde_Exception
*/
protected function _putInKeyring($keys = array(), $type = 'public')
{
* @param boolean $verbose Run GnuPG with verbose flag?
*
* @return stdClass Class with members output, stderr, and stdout.
+ * @throws Horde_Exception
*/
protected function _callGpg($options, $mode, $input = array(),
$output = false, $stderr = false,
$cmdline = implode(' ', array_merge($this->_gnupg, $options));
if ($mode == 'w') {
- $fp = popen($cmdline, 'w');
- $win32 = !strncasecmp(PHP_OS, 'WIN', 3);
+ if ($fp = popen($cmdline, 'w')) {;
+ $win32 = !strncasecmp(PHP_OS, 'WIN', 3);
- if (!is_array($input)) {
- $input = array($input);
- }
- foreach ($input as $line) {
- if ($win32 && (strpos($line, "\x0d\x0a") !== false)) {
- $chunks = explode("\x0d\x0a", $line);
- foreach ($chunks as $chunk) {
- fputs($fp, $chunk . "\n");
+ if (!is_array($input)) {
+ $input = array($input);
+ }
+
+ foreach ($input as $line) {
+ if ($win32 && (strpos($line, "\x0d\x0a") !== false)) {
+ $chunks = explode("\x0d\x0a", $line);
+ foreach ($chunks as $chunk) {
+ fputs($fp, $chunk . "\n");
+ }
+ } else {
+ fputs($fp, $line . "\n");
}
- } else {
- fputs($fp, $line . "\n");
}
+ } else {
+ throw new Horde_Exception(_("Error while talking to pgp binary."));
}
} elseif ($mode == 'r') {
- $fp = popen($cmdline, 'r');
- while (!feof($fp)) {
- $data->stdout .= fgets($fp, 1024);
+ if ($fp = popen($cmdline, 'r')) {
+ while (!feof($fp)) {
+ $data->stdout .= fgets($fp, 1024);
+ }
+ } else {
+ throw new Horde_Exception(_("Error while talking to pgp binary."));
}
}
pclose($fp);
} else {
$cmdline .= ' -nodes';
}
- $fd = popen($cmdline, 'w');
+ } else {
+ $cmdline .= ' -nodes';
+ }
+
+ if ($fd = popen($cmdline, 'w')) {
fwrite($fd, $params['password'] . "\n");
if (!empty($params['newpassword'])) {
fwrite($fd, $params['newpassword'] . "\n");
}
pclose($fd);
} else {
- $cmdline .= ' -nodes';
- exec($cmdline);
+ throw new Horde_Exception(_("Error while talking to smime binary."));
}
+
$ob->private = trim(file_get_contents($output));
if (empty($ob->private)) {
throw new Horde_Exception(_("Password incorrect"), 'horde.error');
$cmdline = $sslpath . ' pkcs12 -in ' . $input . ' -out ' . $output . ' -nokeys -clcerts';
if (isset($params['password'])) {
$cmdline .= ' -passin stdin';
- $fd = popen($cmdline, 'w');
+ }
+
+ if ($fd = popen($cmdline, 'w')) {
fwrite($fd, $params['password'] . "\n");
pclose($fd);
} else {
- exec($cmdline);
+ throw new Horde_Exception(_("Error while talking to smime binary."));
}
+
$ob->public = trim(file_get_contents($output));
/* Extract the CA public key next. */
$cmdline = $sslpath . ' pkcs12 -in ' . $input . ' -out ' . $output . ' -nokeys -cacerts';
if (isset($params['password'])) {
$cmdline .= ' -passin stdin';
- $fd = popen($cmdline, 'w');
+ }
+
+ if ($fd = popen($cmdline, 'w')) {
fwrite($fd, $params['password'] . "\n");
pclose($fd);
} else {
- exec($cmdline);
+ throw new Horde_Exception(_("Error while talking to smime binary."));
}
+
$ob->certs = trim(file_get_contents($output));
return $ob;