PHP Class IMP_Pgp, horde

Author: Michael Slusarz ([email protected])
ファイルを表示 Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_pgp Horde_Crypt_Pgp Pgp object.

Public Methods

Method Description
__construct ( Horde_Crypt_Pgp $pgp ) Constructor.
addPersonalPrivateKey ( mixed $private_key ) Add the personal private key to the prefs.
addPersonalPublicKey ( mixed $public_key ) Add the personal public key to the prefs.
addPublicKey ( string $public_key ) : array Add a public key to an address book.
decryptMessage ( string $text, string $type, array $opts = [] ) : stdClass Decrypt a message with user's public/private keypair or a passphrase.
deletePersonalKeys ( ) Deletes the specified personal keys from the prefs.
deletePublicKey ( string $email ) Deletes a public key from a user's address book(s) by e-mail.
enabled ( ) : boolean Return whether PGP support is current enabled in IMP.
encryptList ( ) : array Return the list of available encryption options for composing.
encryptMimePart ( Horde_Mime_Part $mime_part, Horde_Mail_Rfc822_List $addresses, string $symmetric = null ) : Horde_Mime_Part Encrypt a Horde_Mime_Part using PGP using IMP default parameters.
encryptedSymmetrically ( string $text ) : boolean Returns whether a text has been encrypted symmetrically.
generatePersonalKeys ( string $name, string $email, string $passphrase, string $comment = '', string $keylength = 1024, integer $expire = null ) Generate the personal Public/Private keypair and store in prefs.
getKeyIdString ( $keyid )
getKeys ( string $data ) : array Extracts public/private keys from armor data.
getPassphrase ( integer $type, string $id = null ) : mixed Gets a passphrase from the session cache.
getPersonalPrivateKey ( ) : string Get the personal private key from the prefs.
getPersonalPublicKey ( ) : string Get the personal public key from the prefs.
getPublicKey ( string $address, array $options = [] ) : string Retrieves a public key by e-mail.
getSymmetricId ( string $mailbox, integer $uid, string $id ) : string Generates a cache ID for symmetric message data.
listPublicKeys ( ) : array Retrieves all public keys from a user's address book(s).
pgpPacketInformation ( string $pgpdata ) : array Returns information on a PGP data block.
pgpPacketSignature ( string $pgpdata, string $email ) : array Returns only information on the first ID that matches the email address input.
prettyKey ( string $pgpdata ) : string Returns human readable information on a PGP key.
publicKeyMimePart ( ) : Horde_Mime_Part Generate a Horde_Mime_Part object, in accordance with RFC 2015/3156, that contains the user's public key.
sendToPublicKeyserver ( string $pubkey ) Send a public key to a public PGP keyserver.
signAndEncryptMimePart ( Horde_Mime_Part $mime_part, Horde_Mail_Rfc822_List $addresses, string $symmetric = null ) : Horde_Mime_Part Sign and Encrypt a Horde_Mime_Part using PGP using IMP default parameters.
signMimePart ( Horde_Mime_Part $mime_part ) : Horde_Mime_Part Sign a Horde_Mime_Part using PGP using IMP default parameters.
storePassphrase ( integer $type, string $passphrase, string $id = null ) : boolean Store's the user's passphrase in the session cache.
unsetPassphrase ( integer $type, string $id = null ) Clear the passphrase from the session cache.
verifySignature ( string $text, string $address, string $signature = '', string $charset = null ) : stdClass Verifies a signed message with a given public key.

Protected Methods

Method Description
_encryptParameters ( Horde_Mail_Rfc822_List $addresses, string $symmetric ) : array Provide the list of parameters needed for encrypting a message.
_keyserverList ( ) : array Return list of keyserver objects.
_signParameters ( ) : array Provide the list of parameters needed for signing a message.

Method Details

__construct() public method

Constructor.
public __construct ( Horde_Crypt_Pgp $pgp )
$pgp Horde_Crypt_Pgp PGP object.

_encryptParameters() protected method

Provide the list of parameters needed for encrypting a message.
protected _encryptParameters ( Horde_Mail_Rfc822_List $addresses, string $symmetric ) : array
$addresses Horde_Mail_Rfc822_List The e-mail address of the keys to use for encryption.
$symmetric string If true, the symmetric password to use for encrypting. If null, uses the personal key.
return array The list of parameters needed by encrypt().

_keyserverList() protected method

Return list of keyserver objects.
protected _keyserverList ( ) : array
return array List of Horde_Crypt_Pgp_Keyserver objects.

_signParameters() protected method

Provide the list of parameters needed for signing a message.
protected _signParameters ( ) : array
return array The list of parameters needed by encrypt().

addPersonalPrivateKey() public method

Add the personal private key to the prefs.
public addPersonalPrivateKey ( mixed $private_key )
$private_key mixed The private key to add (either string or array).

addPersonalPublicKey() public method

Add the personal public key to the prefs.
public addPersonalPublicKey ( mixed $public_key )
$public_key mixed The public key to add (either string or array).

addPublicKey() public method

Add a public key to an address book.
public addPublicKey ( string $public_key ) : array
$public_key string An PGP public key.
return array See Horde_Crypt_Pgp::pgpPacketInformationMultiple()

decryptMessage() public method

Decrypt a message with user's public/private keypair or a passphrase.
public decryptMessage ( string $text, string $type, array $opts = [] ) : stdClass
$text string The text to decrypt.
$type string Either 'literal', 'personal', or 'symmetric'.
$opts array Additional options: - passphrase: (boolean) If $type is 'personal' or 'symmetrical', the passphrase to use. - sender: (string) The sender of the message (used to check signature if message is both encrypted & signed).
return stdClass See Horde_Crypt_Pgp::decrypt().

deletePersonalKeys() public method

Deletes the specified personal keys from the prefs.
public deletePersonalKeys ( )

deletePublicKey() public method

Deletes a public key from a user's address book(s) by e-mail.
public deletePublicKey ( string $email )
$email string The e-mail address to delete.

enabled() public static method

Return whether PGP support is current enabled in IMP.
public static enabled ( ) : boolean
return boolean True if PGP support is enabled.

encryptList() public method

Return the list of available encryption options for composing.
public encryptList ( ) : array
return array Keys are encryption type constants, values are gettext strings describing the encryption type.

encryptMimePart() public method

Encrypt a Horde_Mime_Part using PGP using IMP default parameters.
public encryptMimePart ( Horde_Mime_Part $mime_part, Horde_Mail_Rfc822_List $addresses, string $symmetric = null ) : Horde_Mime_Part
$mime_part Horde_Mime_Part The object to encrypt.
$addresses Horde_Mail_Rfc822_List The e-mail address of the keys to use for encryption.
$symmetric string If true, the symmetric password to use for encrypting. If null, uses the personal key.
return Horde_Mime_Part See Horde_Crypt_Pgp::encryptMimePart().

encryptedSymmetrically() public method

Returns whether a text has been encrypted symmetrically.
public encryptedSymmetrically ( string $text ) : boolean
$text string The PGP encrypted text.
return boolean True if the text is symmetrically encrypted.

generatePersonalKeys() public method

Generate the personal Public/Private keypair and store in prefs.
public generatePersonalKeys ( string $name, string $email, string $passphrase, string $comment = '', string $keylength = 1024, integer $expire = null )
$name string See Horde_Crypt_Pgp::.
$email string See Horde_Crypt_Pgp::.
$passphrase string See Horde_Crypt_Pgp::.
$comment string See Horde_Crypt_Pgp::.
$keylength string See Horde_Crypt_Pgp::.
$expire integer See Horde_Crypt_Pgp::.

getKeyIdString() public method

public getKeyIdString ( $keyid )

getKeys() public method

Extracts public/private keys from armor data.
public getKeys ( string $data ) : array
$data string Armor text.
return array Array with these keys: - public: (array) Array of public keys. - private: (array) Array of private keys.

getPassphrase() public method

Gets a passphrase from the session cache.
public getPassphrase ( integer $type, string $id = null ) : mixed
$type integer The type of passphrase. Either 'personal' or 'symmetric'.
$id string If $type is 'symmetric', the ID of the stored passphrase.
return mixed The passphrase, if set, or null.

getPersonalPrivateKey() public method

Get the personal private key from the prefs.
public getPersonalPrivateKey ( ) : string
return string The personal PGP private key.

getPersonalPublicKey() public method

Get the personal public key from the prefs.
public getPersonalPublicKey ( ) : string
return string The personal PGP public key.

getPublicKey() public method

First, the key will be attempted to be retrieved from a user's address book(s). Second, if unsuccessful, the key is attempted to be retrieved via a public PGP keyserver.
public getPublicKey ( string $address, array $options = [] ) : string
$address string The e-mail address to search by.
$options array Additional options: - keyid: (string) The key ID of the user's key. DEFAULT: key ID not used - nocache: (boolean) Don't retrieve from cache? DEFAULT: false - nohooks: (boolean) Don't trigger hook when retrieving public key? DEFAULT: false - noserver: (boolean) Whether to check the public key servers for the key. DEFAULT: false
return string The PGP public key requested.

getSymmetricId() public method

Generates a cache ID for symmetric message data.
public getSymmetricId ( string $mailbox, integer $uid, string $id ) : string
$mailbox string The mailbox of the message.
$uid integer The UID of the message.
$id string The MIME ID of the message.
return string A unique symmetric cache ID.

listPublicKeys() public method

Retrieves all public keys from a user's address book(s).
public listPublicKeys ( ) : array
return array All PGP public keys available.

pgpPacketInformation() public method

Returns information on a PGP data block.
public pgpPacketInformation ( string $pgpdata ) : array
$pgpdata string The PGP data block.
return array An array with information on the PGP data block. If an element is not present in the data block, it will likewise not be set in the array.
Array Format:
-------------
[public_key]/[secret_key] => Array
  (
    [created] => Key creation - UNIX timestamp
    [expires] => Key expiration - UNIX timestamp (0 = never expires)
    [size]    => Size of the key in bits
  )

[keyid] => Key ID of the PGP data (if available)
           16-bit hex value

[signature] => Array (
    [id{n}/'_SIGNATURE'] => Array (
        [name]        => Full Name
        [comment]     => Comment
        [email]       => E-mail Address
        [keyid]       => 16-bit hex value
        [created]     => Signature creation - UNIX timestamp
        [expires]     => Signature expiration - UNIX timestamp
        [micalg]      => The hash used to create the signature
        [sig_{hex}]   => Array [details of a sig verifying the ID] (
            [created]     => Signature creation - UNIX timestamp
            [expires]     => Signature expiration - UNIX timestamp
            [keyid]       => 16-bit hex value
            [micalg]      => The hash used to create the signature
        )
    )
)
Each user ID will be stored in the array 'signature' and have data associated with it, including an array for information on each 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'.

pgpPacketSignature() public method

Returns only information on the first ID that matches the email address input.
public pgpPacketSignature ( string $pgpdata, string $email ) : array
$pgpdata string The PGP data block.
$email string An e-mail address.
return array An array with information on the PGP data block. If an element is not present in the data block, it will likewise not be set in the array. Array elements: - comment: Comment - created: Signature creation (UNIX timestamp) - email: E-mail Address - key_created: Key creation (UNIX timestamp) - key_expires: Key expiration (UNIX timestamp; 0 = never expires) - key_size: Size of the key in bits - key_type: The key type (public_key or secret_key) - keyid: 16-bit hex value - micalg: The hash used to create the signature - name: Full Name

prettyKey() public method

Returns human readable information on a PGP key.
public prettyKey ( string $pgpdata ) : string
$pgpdata string The PGP data block.
return string Tabular information on the PGP key.

publicKeyMimePart() public method

Generate a Horde_Mime_Part object, in accordance with RFC 2015/3156, that contains the user's public key.
public publicKeyMimePart ( ) : Horde_Mime_Part
return Horde_Mime_Part See Horde_Crypt_Pgp::publicKeyMimePart().

sendToPublicKeyserver() public method

Send a public key to a public PGP keyserver.
public sendToPublicKeyserver ( string $pubkey )
$pubkey string The PGP public key.

signAndEncryptMimePart() public method

Sign and Encrypt a Horde_Mime_Part using PGP using IMP default parameters.
public signAndEncryptMimePart ( Horde_Mime_Part $mime_part, Horde_Mail_Rfc822_List $addresses, string $symmetric = null ) : Horde_Mime_Part
$mime_part Horde_Mime_Part The object to sign and encrypt.
$addresses Horde_Mail_Rfc822_List The e-mail address of the keys to use for encryption.
$symmetric string If true, the symmetric password to use for encrypting. If null, uses the personal key.
return Horde_Mime_Part See Horde_Crypt_Pgp::signAndencryptMimePart().

signMimePart() public method

Sign a Horde_Mime_Part using PGP using IMP default parameters.
public signMimePart ( Horde_Mime_Part $mime_part ) : Horde_Mime_Part
$mime_part Horde_Mime_Part The object to sign.
return Horde_Mime_Part See Horde_Crypt_Pgp::signMIMEPart().

storePassphrase() public method

Store's the user's passphrase in the session cache.
public storePassphrase ( integer $type, string $passphrase, string $id = null ) : boolean
$type integer The type of passphrase. Either 'personal' or 'symmetric'.
$passphrase string The user's passphrase.
$id string If $type is 'symmetric', the ID of the stored passphrase.
return boolean Returns true if correct passphrase, false if incorrect.

unsetPassphrase() public method

Clear the passphrase from the session cache.
public unsetPassphrase ( integer $type, string $id = null )
$type integer The type of passphrase. Either 'personal' or 'symmetric'.
$id string If $type is 'symmetric', the ID of the stored passphrase. Else, all passphrases are deleted.

verifySignature() public method

Verifies a signed message with a given public key.
public verifySignature ( string $text, string $address, string $signature = '', string $charset = null ) : stdClass
$text string The text to verify.
$address string E-mail address of public key.
$signature string A PGP signature block.
$charset string Charset to use.
return stdClass See Horde_Crypt_Pgp::decrypt().

Property Details

$_pgp protected_oe property

Pgp object.
protected Horde_Crypt_Pgp $_pgp
return Horde_Crypt_Pgp