\Horde_Crypt_Pgp_Backend_Binary

PGP backend that uses the gnupg binary.

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.

Summary

Methods
Properties
Constants
supported()
generateKey()
packetInfo()
packetInfoMultiple()
getSignersKeyId()
getFingerprintsFromKey()
isEncryptedSymmetrically()
encryptMessage()
encryptSignature()
decryptMessage()
decryptSignature()
getPublicKeyFromPrivateKey()
__construct()
getSignersKeyID()
_callGpg()
No public properties found
No constants found
_checkSignatureResult()
_createKeyring()
_putInKeyring()
_ensureResult()
_ensureDecryptionOk()
_createTempFile()
$_gnupg
$_gnupg21
$_privateKeyring
$_publicKeyring
$_tempdir
N/A
No private methods found
No private properties found
N/A

Properties

$_gnupg

$_gnupg : array

GnuPG program location/common options.

Type

array

$_gnupg21

$_gnupg21 : boolean

Whether the GnuPG version is 2.1 or later.

Type

boolean

$_privateKeyring

$_privateKeyring : string

Filename of the temporary private keyring.

Type

string

$_publicKeyring

$_publicKeyring : string

Filename of the temporary public keyring.

Type

string

$_tempdir

$_tempdir : string

The temporary directory to use.

Type

string

Methods

supported()

supported() : boolean

Is this driver supported?

Returns

boolean —

True if supported.

generateKey()

generateKey(array  $opts) : mixed

Generates a personal public/private keypair combination.

Parameters

array $opts

Configuration:

  • comment: (string) The comment to use.
  • email: (string) The email to use.
  • expire: (integer) The expiration date (UNIX timestamp). No expiration if empty.
  • keylength: (integer) The keylength to use.
  • key_type: (string) Key type.
  • name: (string) The name to use.
  • passphrase: (string) The passphrase to use.
  • subkey_type: (string) Subkey type.

Returns

mixed —

False on error; an array on success consisting of the following keys/values:

  • private: (string) Private key.
  • public: (string) Public key.

packetInfo()

packetInfo(string  $pgpdata) : array

Returns information on a PGP data block.

Parameters

string $pgpdata

The PGP data block.

Returns

array —

An array with information on the PGP data block. {@see Horde_Crypt_Pgp::pgpPacketInformation()}

packetInfoMultiple()

packetInfoMultiple(string  $pgpdata) : array

Returns all information on a PGP data block.

Parameters

string $pgpdata

The PGP data block.

Returns

array —

An array with information on the PGP data block. {@see Horde_Crypt_Pgp::pgpPacketInformationMultiple()}

getSignersKeyId()

getSignersKeyId(string  $text) : mixed

Returns the key ID of the key used to sign a block of PGP data.

Parameters

string $text

The PGP signed text block.

Returns

mixed —

The key ID of the key used to sign $text.

getFingerprintsFromKey()

getFingerprintsFromKey(string  $pgpdata) : array

Get the fingerprints from a key block.

Parameters

string $pgpdata

The PGP data block.

Returns

array —

The fingerprints in $pgpdata indexed by key id.

isEncryptedSymmetrically()

isEncryptedSymmetrically(string  $text) : boolean

Returns whether a text has been encrypted symmetrically.

Parameters

string $text

The PGP encrypted text.

Returns

boolean —

True if the text is symmetrically encrypted.

encryptMessage()

encryptMessage(string  $text, array  $params) : string

Encrypts a message in PGP format using a public key.

Parameters

string $text

The text to be encrypted.

array $params

The parameters needed for encryption.

  • passphrase: The passphrase for the symmetric encryption (REQUIRED if 'symmetric' is true)
  • recips: An array with the e-mail address of the recipient as the key and that person's public key as the value. (REQUIRED if 'symmetric' is false)
  • symmetric: Whether to use symmetric instead of asymmetric encryption (defaults to false).
  • type: [REQUIRED] 'message'

Returns

string —

The encrypted message.

encryptSignature()

encryptSignature(string  $text, array  $params) : string

Signs a message in PGP format using a private key.

Parameters

string $text

The text to be signed.

array $params

The parameters needed for signing.

  • passphrase: [REQUIRED] Passphrase for PGP Key.
  • privkey: [REQUIRED] PGP private key.
  • pubkey: [REQUIRED] PGP public key.
  • sigtype: Determine the signature type to use.
    • 'cleartext': Make a clear text signature
    • 'detach': Make a detached signature (DEFAULT)
  • type: [REQUIRED] 'signature'

Returns

string —

The signed message.

decryptMessage()

decryptMessage(string  $text, array  $params) : object

Decrypts an PGP encrypted message using a private/public keypair and a passhprase.

Parameters

string $text

The text to be decrypted.

array $params

The parameters needed for decryption.

  • no_passphrase: Passphrase is not required.
  • passphrase: Passphrase for PGP Key. (REQUIRED, see no_passphrase)
  • privkey: PGP private key. (REQUIRED for asymmetric encryption)
  • pubkey: PGP public key. (REQUIRED for asymmetric encryption)
  • type: [REQUIRED] 'message'

Returns

object —

An object with the following properties:

  • message: (string) The signature result text.
  • result: (boolean) The result of the signature test.

decryptSignature()

decryptSignature(string  $text, array  $params) : object

Decrypts an PGP signed message using a public key.

Parameters

string $text

The text to be verified.

array $params

The parameters needed for verification.

  • charset: Charset of the message body.
  • pubkey: [REQUIRED] PGP public key.
  • signature: PGP signature block. (REQUIRED for detached signature)
  • type: [REQUIRED] 'signature' or 'detached-signature'

Returns

object —

An object with the following properties:

  • message: (string) The signature result text.
  • result: (boolean) The result of the signature test.

getPublicKeyFromPrivateKey()

getPublicKeyFromPrivateKey(string  $data) : string

Generates a public key from a private key.

Parameters

string $data

Armor text of private key.

Returns

string —

Armor text of public key.

__construct()

__construct(string  $gnupg, string  $temp = null) 

Constructor.

Parameters

string $gnupg

The path to the GnuPG binary.

string $temp

Location of temporary directory.

getSignersKeyID()

getSignersKeyID(  $text) 

Parameters

$text

_callGpg()

_callGpg(array  $options, string  $mode, array  $input = array(), boolean  $output = false, boolean  $stderr = false, boolean  $parseable = false, boolean  $verbose = false) : \stdClass

Function that handles interfacing with the GnuPG binary.

Parameters

array $options

Options and commands to pass to GnuPG.

string $mode

'r' to read from stdout, 'w' to write to stdin.

array $input

Input to write to stdin.

boolean $output

Collect and store output in object returned?

boolean $stderr

Collect and store stderr in object returned?

boolean $parseable

Is parseable output required? The gpg binary would be executed with C locale then.

boolean $verbose

Run GnuPG with verbose flag?

Throws

\Horde_Crypt_Exception

Returns

\stdClass —

Class with members output, stderr, and stdout.

_checkSignatureResult()

_checkSignatureResult(string  $result, string  $message = null) : object

Checks signature result from the GnuPG binary.

Parameters

string $result

The signature result.

string $message

The decrypted message data.

Throws

\Horde_Crypt_Exception

Returns

object —

See decryptSignature().

_createKeyring()

_createKeyring(string  $type = 'public') : string

Creates a temporary gpg keyring.

Parameters

string $type

The type of key to analyze. 'public' or 'private'.

Returns

string —

Command line keystring option to use with gpg program.

_putInKeyring()

_putInKeyring(mixed  $keys = array(), string  $type = 'public') : string

Adds PGP keys to the keyring.

Parameters

mixed $keys

A single key or an array of key(s) to add to the keyring.

string $type

The type of key(s) to add. 'public' or 'private'.

Throws

\Horde_Crypt_Exception

Returns

string —

Command line keystring option to use with gpg program.

_ensureResult()

_ensureResult(object  $result) 

Checks whether there was some valid output.

Parameters

object $result

A result from _callGpg().

Throws

\Horde_Crypt_Exception

with messages from stderr if the result output is empty.

_ensureDecryptionOk()

_ensureDecryptionOk(object  $result) 

Checks whether the decryption succeeded.

Parameters

object $result

A result from _callGpg().

Throws

\Horde_Crypt_Exception

with messages from stderr if the result is not a successful decryption.

_createTempFile()

_createTempFile(string  $descrip = 'horde-crypt', boolean  $delete = true) : string

Create a temporary file that will be deleted at the end of this process.

Parameters

string $descrip

Description string to use in filename.

boolean $delete

Delete the file automatically?

Returns

string —

Filename of a temporary file.