Class GnuPG

Description

This is the main class to use for GPG functions and data

Located in /plugins/gpg/classes/gpg.php (line 383)


	
			
Variable Summary
Method Summary
 array addRevoker (string $privatekey, string $revokingkey, string $passphrase)
 array addSubKey (string $privatekey, string $passphrase, [ $algo = 3], integer $keysize,  $expiredate, integer $type, string $valid)
 void addTempDir (string $newTempDir)
 array addUID (string $fpr, string $passphrase, string $uidname, string $uidemail, string $comment)
 array changePassphrase (string $keyfpr, string $passphrase, string $newpassphrase)
 void clearError ()
 void confirmSave ()
 array decrypt (string $body, string $passphrase, [optional $filename = ''], [ $outfile = ''])
 array deleteKey (string $fpr, [string $type = "all"])
 array deleteSubKey (string $fpr, integer $subkeyno)
 array deleteUID (string $fpr, string $uidnos)
 array encrypt (string $body,  $send_to_list, [optional $sign = false], [optional $passphrase = false], [optional $filename = ''], [ $signingkeyfpr = false], array $send_to)
 void execute_gpg (string $options, [string $data = false], [bool $addHomeDir = true], [ $addSystemRing = true])
 array expireKey (string $fpr, string $passphrase, string $expiration)
 array expireSubKey (string $fpr, string $subkey, string $passphrase, string $expiration)
 void fetchKeys ( $search, [ $ring = 'public'])
 array generateKey ( $name, string $email, string $passphrase, [optional $comment = ''], [optional $keylength = 1024], [optional $expiredate = 0], [ $algo = 1], [ $prefs = false], string $real_name)
 unknown generateKey_nopipes (unknown_type $name, unknown_type $email, unknown_type $passphrase, unknown_type $comment, [unknown_type $keylength = 1024], [unknown_type $expiredate = 0], [unknown_type $prefs = false])
 error getErrorCode ()
 array getExportText (string $fpr)
 GnuPGKey getKey (string $keyid)
 string getKeyIndexFromFingerprint (string $fingerprint)
 array getKeyMap_chunked (integer $len)
 void getKeys ([string $fpr = false])
 array importKey_file (string $fname)
 array importKey_server ( $keystring, string $keyserver, string $keytext)
 array importKey_text (string $keystring)
 void increaseEntropy ()
 bool isError ()
 array list_encrypt_keys (string $data)
 array makearrayKeys ()
 array numKeys ()
 void parseStatusLine (string $line)
 array parse_output (string $gpg_output)
 void readStatus (void 0)
 void refreshKeys ([string $search = ''], [string $ring = 'all'])
 array searchKey_server (string $search_string, string $keyserver)
 void setError (string $code, string $description)
 void setHomeDir (string $newHomeDir)
 void setKeyPassphrase (string $fingerprint, string $passphrase)
 @array setKeyPrefs (string $fpr, [string $prefs = false], string $passphrase)
 array setPrimaryUID (string $keyfpr, integer $uid, string $passphrase)
 void setTempDir (string $newTempDir)
 array sign ([string $data = false], [string $signingKey = false], [ $passphrase = ''], [ $type = 'clear'])
 array signFile ([string $filename = false], [string $passphrase = false], [string $signingKey = false])
 array signKey (string $signedKeyfpr, [string $signingKeyfpr = false], [string $passphrase = false], [bool $exportsig = true], [bool $revokable = true], [ $uids = ''])
 array signUID (string $signedKeyfpr, [string $uids = ''], [string $signingKeyfpr = false], [string $passphrase = false], [bool $exportsig = true], [bool $revokable = true])
 array sortKeys (string $dataName, boolean $asc)
 array update_trustdb ()
 array uploadKey (string $fpr, string $keyserver)
 array verify (string $data, [string $type = 'clear'])
 boolean verifyDetachedSignature ([string $data = false], string $signature)
 array verifyFileSignature (string $filename, string $signature)
 void verifyPassphrase (string $passphrase, [string $keyfpr = false], array $return)
 void writeCheckLevel ([int $checkLevel = 0])
 void writeNewPassword (void 0)
 void writeOkay ()
 void writePassword ([string $fingerprint = false])
Variables
mixed $action = false (line 438)
mixed $activeKey = false (line 439)
mixed $allowEntropyIncrease = true (line 420)
mixed $alternateKeyring = false (line 393)
mixed $alternateSecretKeyring = false (line 394)
mixed $arraykeys = false (line 434)
mixed $comment = '' (line 399)
mixed $debug = false (line 385)
mixed $defaultKeyFingerprint = '' (line 435)
mixed $defaultKeyPrefs = "S2 S7 S3 H2 H3 Z2 Z1" (line 423)
mixed $encryptKeys = array() (line 442)
mixed $error = false (line 445)
mixed $errorCode = '' (line 446)
mixed $errorDescription = '' (line 447)
mixed $fileDescriptors = array (
GPGSTDIN => array( 'pipe', 'r' ),// this is stdin for the child (We write to this one)
GPGSTDOUT=>array('pipe','w'),// child writes here (stdout)
GPGSTDERR=>array('pipe','w'),// stderr
STATUS_FD=>array('pipe','w'),PASSPHRASE_FD=>array('pipe','r'))
(line 405)
mixed $force_exec = false (line 387)
mixed $gpgHomeDir = "" (line 398)
mixed $gpg_exe = "/usr/bin/gpg" (line 396)
mixed $gpg_options = "--no-tty --yes --openpgp" (line 397)
mixed $gpg_pipes = array() (line 390)
mixed $indata = '' (line 389)
mixed $interactionData = array() (line 440)
mixed $invalidRecipients = array() (line 458)
mixed $keys = false (line 433)
mixed $lang_env_values = array() (line 417)
mixed $lang_env_vars = array('LC_ALL'=>'en_US','LC_LANG'=>'en_US','LC_LANGUAGE'=>'en_US') (line 415)
array $microtime = array() (line 463)
  • var: Is used to profile debugging
mixed $newKeys = array() (line 441)
mixed $newpassphrase = false (line 403)
mixed $outdata = '' (line 389)
mixed $passphrase = false (line 402)
mixed $pipeOpen = array() (line 391)
mixed $signedKeyFingerprint = '' (line 451)
mixed $signedKeyUserID = false (line 452)
mixed $signHashAlgo = 0 (line 430)
mixed $signPubKeyAlgo = 0 (line 430)
mixed $statusout = '' (line 404)
mixed $stderr = '' (line 404)
mixed $stdout = '' (line 404)
string $stdout_filter = '' (line 466)
  • var: PCRE expression used to filter output
mixed $systemKeyring = false (line 392)
mixed $tempDir = '' (line 400)
mixed $tempFileMode = 0600 (line 401)
mixed $tmpdir = '/tmp' (line 426)
mixed $tmp_locations = array('/dev/shm', '/dev/mfs', '/tmp', '/var/tmp', 'c:\temp', 'c:\windows\temp', 'c:\winnt\temp') (line 427)
mixed $trustedKeys = array() (line 395)
mixed $verifiedSignature = false (line 455)
mixed $verifiedUserID = false (line 456)
mixed $verifyStatus = '' (line 454)
mixed $writingData = false (line 460)
Methods
addRevoker (line 1096)

Adds a revoking key to a private key

  • return: containing errors and output
array addRevoker (string $privatekey, string $revokingkey, string $passphrase)
  • string $privatekey: containing fingerprint or key id of the private key for which to set a revoker
  • string $revokingkey: containing fingerprint or key id of the key to use as revoker
  • string $passphrase: containing the passphrase to the secret key
addSubKey (line 1067)

Adds a subkey pair to a main keypair

  • return: containing errors and output, $return['newkeys'] array of new key fingerprints
array addSubKey (string $privatekey, string $passphrase, [ $algo = 3], integer $keysize,  $expiredate, integer $type, string $valid)
  • string $privatekey: containing fingerprint or key id of the private key for which to add a subkey
  • string $passphrase: containing the passphrase to the secret key
  • integer $type: containing what type of key to create (default of (3) ElGamal (encrypt only))
  • integer $keysize: containing size of key to create
  • string $valid: containing length of time the key is valid, # of days or 1y for 1 year
  • $algo
  • $expiredate
addTempDir (line 482)

Adds a directory to the end of the list of directories used when attempting to find a writeable temp directory

void addTempDir (string $newTempDir)
  • string $newTempDir: containing path to gnupg home directory
addUID (line 862)

Adds a UID to a key

  • return: containing errors and output
array addUID (string $fpr, string $passphrase, string $uidname, string $uidemail, string $comment)
  • string $fpr: containing fingerprint or key id of the private key for which to add a uid
  • string $passphrase: containing passphrase to the secret key
  • string $uidname: containing the name associated with this uid
  • string $uidemail: containing the email address associated with this uid
  • string $comment: containing a comment or extra information about the uid
changePassphrase (line 1236)

Changes the passphrase on a secret key

  • return: containing $return['verified'] equal to 'true' if successful or 'false' if not
array changePassphrase (string $keyfpr, string $passphrase, string $newpassphrase)
  • string $keyfpr: containing fingerprint of the secret key to changne
  • string $passphrase: containing the current passphrase to the secret key
  • string $newpassphrase: containing the new passphrase to the secret key
clearError (line 3203)

Clears last error

void clearError ()
confirmSave (line 1767)

Writes a save command to the GPG command file descriptor

Used during key edit actions

void confirmSave ()
decrypt (line 628)

This function does the decryption.

This is the workhorse of decryption

  • return: with results
array decrypt (string $body, string $passphrase, [optional $filename = ''], [ $outfile = ''])
  • string $body: Body String to decrypt
  • string $passphrase: Passphrase to pass to gpg
  • optional $filename: string $filename Filename to decrypt binary file
  • $outfile
deleteKey (line 822)

This function deletes a key from the keyring in the homedir It will not remove the key from the keys list, so a refreshkeys is need to reflect the new status of the keyring

  • return: containing errors, warnings, etc
array deleteKey (string $fpr, [string $type = "all"])
  • string $fpr
  • string $type
deleteSubKey (line 928)

Deletes a subkey pair from a main keypair

  • return: containing errors and output
array deleteSubKey (string $fpr, integer $subkeyno)
  • string $fpr: containing fingerprint or key id of the private key from which to delete a subkey
  • integer $subkeyno: containing the offset of subkey to delete (1 is the first);
deleteUID (line 844)

Deletes a UID from a key

  • return: containing errors and output
array deleteUID (string $fpr, string $uidnos)
  • string $fpr: containing fingerprint or key id of the key with the uid to delete
  • string $uidnos: containing the uid number to delete
encrypt (line 773)

This function does the encryption This is the workhorse of the encryption side of the plugin

Add code here to use user preferences to modify the gpg command line

  • return: with results
array encrypt (string $body,  $send_to_list, [optional $sign = false], [optional $passphrase = false], [optional $filename = ''], [ $signingkeyfpr = false], array $send_to)
  • string $body: Body text string
  • array $send_to: containing recipient list
  • optional $sign: boolean $sign (true/false) do we want to sign the message/file
  • optional $passphrase: string $passphrase passphrase string needed for signing functions
  • optional $filename: string $filename if we are going to encrypt a file
  • $send_to_list
  • $signingkeyfpr
execute_gpg (line 2770)

Main function for execute commands with gpg All calls to gpg should be made using this function

void execute_gpg (string $options, [string $data = false], [bool $addHomeDir = true], [ $addSystemRing = true])
  • string $options: containing parameters to pass to gpg
  • string $data: containing data to pass to gpg
  • bool $addHomeDir: specifies if the home directory should be appended to the command. True by default
  • $addSystemRing
expireKey (line 885)

Sets the expiration on a primary key

  • return: containing info, errors, etc
array expireKey (string $fpr, string $passphrase, string $expiration)
  • string $fpr: containing fingerprint or key id of the primary key to set expiration date on
  • string $passphrase: containing passphrase for the secret key
  • string $expiration: containing string of either # for days or #w for weeks or #y for years
expireSubKey (line 906)

Sets the expiration on a secondary key

  • return: containing info, errors, etc
array expireSubKey (string $fpr, string $subkey, string $passphrase, string $expiration)
  • string $fpr: containing fingerprint or key id of the primary key to set expiration date on
  • string $subkey: containing index of subkey to expire
  • string $passphrase: containing passphrase for the secret key
  • string $expiration: containing string of either # for days or #w for weeks or #y for years
fetchKeys (line 1883)
void fetchKeys ( $search, [ $ring = 'public'])
  • $search
  • $ring
generateKey (line 956)

This function generates a keypair

Keys created with the option set below are PGP compatible Key-Type: DSA Key-Length: 1024 Subkey-Type: ELG-E Preferences: S2 S7 S3 H2 H3 Z2 Z1 (don't forget to put in the other options needed for actual key creation)

  • return: with output we were able to retrieve from the gpg command including $return['newkeys'] first element being fingerprint of new key generated, if available
array generateKey ( $name, string $email, string $passphrase, [optional $comment = ''], [optional $keylength = 1024], [optional $expiredate = 0], [ $algo = 1], [ $prefs = false], string $real_name)
  • string $real_name: Full Name for the uid
  • string $email: Email address to be oput in the uid
  • string $passphrase: Passphrase to protect te secret key
  • optional $comment: string $comment Comment to be appended to the default comment
  • optional $keylength: integer $keylength Length of key to generate
  • optional $expiredate: date $expiredate when should this key expire?
  • $name
  • $algo
  • $prefs
generateKey_nopipes (line 988)

Generates new key without bidi execution functions

unknown generateKey_nopipes (unknown_type $name, unknown_type $email, unknown_type $passphrase, unknown_type $comment, [unknown_type $keylength = 1024], [unknown_type $expiredate = 0], [unknown_type $prefs = false])
  • unknown_type $name
  • unknown_type $email
  • unknown_type $passphrase
  • unknown_type $comment
  • unknown_type $keylength
  • unknown_type $expiredate
  • unknown_type $prefs
getErrorCode (line 3235)

Returns code of last error

  • return: code
error getErrorCode ()
getErrorDescription (line 3244)

Returns description of most recent error

  • return: with error description
string getErrorDescription ()
getExportText (line 1135)

Exports a key defined by $fpr to ASCII Armored text.

  • return: with $return['output'] containing ascii-armored key
array getExportText (string $fpr)
  • string $fpr
getKey (line 1794)

Retreives a key from the keyring

  • return: corresponding to id or fingerprint
GnuPGKey getKey (string $keyid)
  • string $keyid: containing fingerprint or key id of the key to retrieve
getKeyIndexFromFingerprint (line 2675)

Retreives a fingerprint based on a key id

  • return: fingerprint of the key, if found
string getKeyIndexFromFingerprint (string $fingerprint)
  • string $fingerprint: containing fingerprint or key id of the key to retrieve
getKeyMap_chunked (line 1838)

Returns the map of keys, chunked in to chunks of size <= $len

  • return: keys
array getKeyMap_chunked (integer $len)
  • integer $len
getKeys (line 1778)

Retreives keys from gpg if no keys have been loaded

Does not force a refresh of the key information

void getKeys ([string $fpr = false])
  • string $fpr
importKey_file (line 2524)

Imports keys from a file into the keyring.

Sets the keys in the keyring to the newly imported/updated keys

  • return: with element $return['newkeys'] array of affected keys fingerprints
array importKey_file (string $fname)
  • string $fname: containing the path to the file to import
importKey_server (line 2561)

Imports a key from ascii-armored keyblock text

  • return: with element $return['newkeys'] array of affected keys fingerprints
array importKey_server ( $keystring, string $keyserver, string $keytext)
  • string $keytext: containing the id of the key to look up
  • string $keyserver: containing the url of the keyserver (i.e. hkp://pgp.mit.edu:11371)
  • $keystring
importKey_text (line 2542)

Imports a key from ascii-armored keyblock text

  • return: with element $return['newkeys'] array of affected keys fingerprints
array importKey_text (string $keystring)
  • string $keystring: text containing the ascii-armored key information
increaseEntropy (line 1331)

Runs commands to increase entropy for gpg

definitely needs to be made more robust, currently lists filesystem

void increaseEntropy ()
isError (line 3213)

Check to see if last action returned an error

  • return: if error occured
bool isError ()
list_encrypt_keys (line 581)

lists the encryption keys used for encrypted data

  • return: containing $return['encryptKeys'] with key_ids of recipients, also contains $return['missingSecretKeys'] with key_ids of secret keys not on the included keyrings
array list_encrypt_keys (string $data)
  • string $data: containing encrypted data to find keys for
makearrayKeys (line 1819)

Creates an array of keys on the keyring, making use of the arrayKey function

Each key creates an array of data, indexed by fieldname This function is used for keyring sorting and viewing

  • return: of array of keys, including subkeys
array makearrayKeys ()
numKeys (line 1892)

Returns the total number of keys in the object, as determined by options passed to fetchKeys().

  • return: keys
array numKeys ()
parseStatusLine (line 1344)

Parse a line from GnuPG's status file descriptor and act on it

void parseStatusLine (string $line)
  • string $line: containing status output from GnuPG
parse_output (line 2086)

This will parse the string that gpg returns for info, warnings, errors and return them in arrays. This function also returns any other output seperately

  • return: ['errors'],['warnings'],['info'] contain gpg messages ['output'] contains the rest of the output
array parse_output (string $gpg_output)
  • string $gpg_output: text output from gpg
readStatus (line 1276)

Reads and loops on the status pipe from gpg

Contains the main loop for interaction with gpg with pipes

void readStatus (void 0)
  • void 0
refreshKeys (line 1903)

Main function for retreiving key and signature information from gpg Parses output from gpg and creates the array of GnuPGKey objects in $this->keys

void refreshKeys ([string $search = ''], [string $ring = 'all'])
  • string $search: containing string to limit keys shown, default '' to load all keys
  • string $ring: containing the name of the keyring to search, default 'all' for public
searchKey_server (line 2591)

Searches for key in keyserver

Output format: array[keyid][time] = integer (pub: line 5th column), unix timestamp [uids] = indexed array with GnuPGuid objects (all uid: lines till next pub:) if keyid is empty, uid: lines were printed before pub: line

  • since: 2.1.nsm
array searchKey_server (string $search_string, string $keyserver)
  • string $search_string
  • string $keyserver: Server URL. With protocol, fqdn and port. If protocol is not set, function defaults to hkp://
setError (line 3222)

Sets error

void setError (string $code, string $description)
  • string $code: of error
  • string $description: containing error description
setHomeDir (line 473)

set the GnuPG home directory

void setHomeDir (string $newHomeDir)
  • string $newHomeDir: containing path to gnupg home directory
setKeyPassphrase (line 2709)

Sets the passphrase for a secret key identified by its fingerprint or key id

void setKeyPassphrase (string $fingerprint, string $passphrase)
  • string $fingerprint: containing fingerprint or key id of the secret key
  • string $passphrase: containing passphrase for the secret key
setKeyPrefs (line 1042)

This function generates a keypair

FIXME: really?

  • return: containing output, erros, etc
@array setKeyPrefs (string $fpr, [string $prefs = false], string $passphrase)
  • string $fpr: containing fingerprint of key to change preferences on
  • string $prefs: containing space seperated list of parameters, defaults to S2 S7 S3 H2 H3 Z2 Z1
  • string $passphrase: containing passphrase to decrypt and change key with
setPrimaryUID (line 1115)

Sets the uid number specified as the primary UID

  • return: with errors, warnings, output
array setPrimaryUID (string $keyfpr, integer $uid, string $passphrase)
  • string $keyfpr
  • integer $uid
  • string $passphrase
setTempDir (line 494)

set the temporary directory (for very temporary output of files, which are securely overwritten)

void setTempDir (string $newTempDir)
  • string $newTempDir: containing path to gnupg home directory
sign (line 702)

Clearsigns and ascii-armors passed data with a secret key

  • return: containing $return['output'] with clearsigned data
array sign ([string $data = false], [string $signingKey = false], [ $passphrase = ''], [ $type = 'clear'])
  • string $data: containing information to sign
  • string $signingKey: containing fingerprint of key to use for signing
  • $passphrase
  • $type
signFile (line 658)

Clearsigns and ascii-armors a signature on an external file

  • return: containing $return['output'] with clearsigned data
array signFile ([string $filename = false], [string $passphrase = false], [string $signingKey = false])
  • string $filename: containing path of file to sign
  • string $passphrase: containing passphrase to secret key
  • string $signingKey: containing fingerprint of key to use for signing
signKey (line 1190)

Adds a signature to a public key

The key is signed by the default secret key if no secret key is specified By default the signature is exportable and revocable

  • return: containing errors and output
array signKey (string $signedKeyfpr, [string $signingKeyfpr = false], [string $passphrase = false], [bool $exportsig = true], [bool $revokable = true], [ $uids = ''])
  • string $signedKeyfpr: containing fingerprint of the key to sign
  • string $signingKeyfpr: containing fingerprint of secret key to use for signing
  • string $passphrase: containing the passphrase to the secret key
  • bool $exportsig: flags the signature exportable, true by default
  • bool $revokable: flags the signature revocable, true by default
  • $uids
signUID (line 1173)

Adds a signature to a specific or multiple uids on a public key The key is signed by the default secret key if no secret key is specified By default the signature is exportable and revocable

  • return: containing errors and output
array signUID (string $signedKeyfpr, [string $uids = ''], [string $signingKeyfpr = false], [string $passphrase = false], [bool $exportsig = true], [bool $revokable = true])
  • string $signedKeyfpr: containing fingerprint of the key to sign
  • string $uids: containing space seperated list of uids
  • string $signingKeyfpr: containing fingerprint of secret key to use for signing
  • string $passphrase: containing the passphrase to the secret key
  • bool $exportsig: flags the signature exportable, true by default
  • bool $revokable: flags the signature revocable, true by default
sortKeys (line 1861)

Sorts the keys in order of key data name $dataName (e.g. "email_addr", "date", etc) if $asc is true, sorts in ascending order.

  • return: keys
array sortKeys (string $dataName, boolean $asc)
  • string $dataName
  • boolean $asc: value either '<' or '>'
update_trustdb (line 753)

This function will update the gpg trustdb for the current user including a scan of the system keyring if enabled

  • return: containing info, warnings, etc
array update_trustdb ()
uploadKey (line 1149)

Uploads a public key to a keyserver

  • return: containing errors, info, etc
array uploadKey (string $fpr, string $keyserver)
  • string $fpr: containing fingerprint or keyid to upload
  • string $keyserver: containing name of server to upload to
verify (line 558)

Verifies an inline signature (clear-text signature)

  • return: execute_gpg array with additional 'GnuPPSignature' key
array verify (string $data, [string $type = 'clear'])
  • string $data: Signed data
  • string $type: 'clear' for clear text or 'notclear' for encrypted data
verifyDetachedSignature (line 505)

Verifies detached signature

  • return: Verified or not
boolean verifyDetachedSignature ([string $data = false], string $signature)
  • string $data: Verified data
  • string $signature: Signature
verifyFileSignature (line 543)

Verifies file's signature

  • return: execute_gpg array
  • todo: Result must be boolean. true or false. If error happens, it must be stored in error buffer.
array verifyFileSignature (string $filename, string $signature)
  • string $filename: Verified file
  • string $signature: Signature
verifyPassphrase (line 599)

Verifies a passphrase for a secret key The default key is used if no secret key is specified

void verifyPassphrase (string $passphrase, [string $keyfpr = false], array $return)
  • string $passphrase: containing passphrase to verify
  • string $keyfpr: containing fingerprint of secret key
  • array $return: containing $return['verified'] equal to 'true' if passphrase is verified or 'false' if not
writeCheckLevel (line 1758)

Writes a confirmation level for signature uid verification query Used during keys signing. Defaults to 0 (Not specified)

void writeCheckLevel ([int $checkLevel = 0])
  • int $checkLevel: indicating level of confirmation
writeNewPassword (line 1731)

Writes the new passphrase to the passphrase file descriptor, twice.

void writeNewPassword (void 0)
  • void 0
writeOkay (line 1747)

Writes a confirmation to the GPG command file descriptor

Used to confirm choices during interaction with the status pipe

void writeOkay ()
writePassword (line 1706)

Writes a password to the passphrase file descriptor

By default writes the passphrase set in the object ($this->passphrase) If not available, writes the passphrase for the fingerprint specified or the passphrase to the default key if no fingerprint if specified

void writePassword ([string $fingerprint = false])
  • string $fingerprint: containing fingerprint of the key with the passphrase

Documentation generated on Sun, 22 Nov 2009 17:36:35 +0200 by phpDocumentor 1.4.3