Crypt_GPG
[ class tree: Crypt_GPG ] [ index: Crypt_GPG ] [ all elements ]

Class: Crypt_GPG_Engine

Source Location: /Crypt_GPG-1.6.0b3/Crypt/GPG/Engine.php

Class Overview


Native PHP Crypt_GPG I/O engine


Author(s):

Copyright:

  • 2005-2013 silverorange

Methods


Inherited Variables

Inherited Methods


Class Details

[line 92]
Native PHP Crypt_GPG I/O engine

This class is used internally by Crypt_GPG and does not need be used directly. See the Crypt_GPG class for end-user API.

This engine uses PHP's native process control functions to directly control the GPG process. The GPG executable is required to be on the system.

All data is passed to the GPG subprocess using file descriptors. This is the most secure method of passing data to the GPG subprocess.



[ Top ]


Method Detail

__construct (Constructor)   [line 519]

Crypt_GPG_Engine __construct( [array $options = array()])

Creates a new GPG engine

Available options are:

  • string homedir - the directory where the GPG keyring files are stored. If not specified, Crypt_GPG uses the default of ~/.gnupg.
  • string publicKeyring - the file path of the public keyring. Use this if the public keyring is not in the homedir, or if the keyring is in a directory not writable by the process invoking GPG (like Apache). Then you can specify the path to the keyring with this option (/foo/bar/pubring.gpg), and specify a writable directory (like /tmp) using the homedir option.
  • string privateKeyring - the file path of the private keyring. Use this if the private keyring is not in the homedir, or if the keyring is in a directory not writable by the process invoking GPG (like Apache). Then you can specify the path to the keyring with this option (/foo/bar/secring.gpg), and specify a writable directory (like /tmp) using the homedir option.
  • string trustDb - the file path of the web-of-trust database. Use this if the trust database is not in the homedir, or if the database is in a directory not writable by the process invoking GPG (like Apache). Then you can specify the path to the trust database with this option (/foo/bar/trustdb.gpg), and specify a writable directory (like /tmp) using the homedir option.
  • string binary - the location of the GPG binary. If not specified, the driver attempts to auto-detect the GPG binary location using a list of known default locations for the current operating system. The option gpgBinary is a deprecated alias for this option.
  • string agent - the location of the GnuPG agent binary. The gpg-agent is only used for GnuPG 2.x. If not specified, the engine attempts to auto-detect the gpg-agent binary location using a list of know default locations for the current operating system.
  • string|false gpgconf - the location of the GnuPG conf binary. The gpgconf is only used for GnuPG >= 2.1. If not specified, the engine attempts to auto-detect the location using a list of know default locations. When set to FALSE `gpgconf --kill` will not be executed via destructor.
  • boolean strict - In strict mode clock problems on subkeys and signatures are not ignored (--ignore-time-conflict and --ignore-valid-from options)
  • mixed debug - whether or not to use debug mode. When debug mode is on, all communication to and from the GPG subprocess is logged. This can be useful to diagnose errors when using Crypt_GPG.

  • Throws: Crypt_GPG_FileException if the homedir does not exist and cannot be created. This can happen if homedir is not specified, Crypt_GPG is run as the web user, and the web user has no home directory. This exception is also thrown if any of the options publicKeyring, privateKeyring or trustDb options are specified but the files do not exist or are are not readable. This can happen if the user running the Crypt_GPG process (for example, the Apache user) does not have permission to read the files.
  • Throws: PEAR_Exception if the provided binary is invalid, or if no binary is provided and no suitable binary could be found.
  • Throws: PEAR_Exception if the provided agent is invalid, or if no agent is provided and no suitable gpg-agent cound be found.
  • Access: public

Parameters:

array   $options   —  optional. An array of options used to create the GPG object. All options are optional and are represented as key-value pairs.

[ Top ]

__destruct (Destructor)   [line 698]

void __destruct( )

Closes open GPG subprocesses when this object is destroyed

Subprocesses should never be left open by this class unless there is an unknown error and unexpected script termination occurs.

  • Access: public

[ Top ]

addErrorHandler   [line 720]

void addErrorHandler( callback $callback, [array $args = array()])

Adds an error handler method

The method is run every time a new error line is received from the GPG subprocess. The handler method must accept the error line to be handled as its first parameter.

  • Access: public

Parameters:

callback   $callback   —  the callback method to use.
array   $args   —  optional. Additional arguments to pass as parameters to the callback method.

[ Top ]

addStatusHandler   [line 744]

void addStatusHandler( callback $callback, [array $args = array()])

Adds a status handler method

The method is run every time a new status line is received from the GPG subprocess. The handler method must accept the status line to be handled as its first parameter.

  • Access: public

Parameters:

callback   $callback   —  the callback method to use.
array   $args   —  optional. Additional arguments to pass as parameters to the callback method.

[ Top ]

getProcessData   [line 1026]

mixed getProcessData( string $name)

Get data from the last process execution.

Parameters:

string   $name   —  Data element name (e.g. 'SignatureInfo')

[ Top ]

getVersion   [line 968]

string getVersion( )

Gets the version of the GnuPG binary
  • Return: a version number string containing the version of GnuPG being used. This value is suitable to use with PHP's version_compare() function.
  • Throws: Crypt_GPG_UnsupportedException if the provided binary is not GnuPG or if the GnuPG version is less than 1.0.2.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use the debug option and file a bug report if these exceptions occur.
  • Access: public

[ Top ]

reset   [line 783]

void reset( )

Resets the GPG engine, preparing it for a new operation

[ Top ]

run   [line 826]

void run( )

Runs the current GPG operation.

This creates and manages the GPG subprocess. This will close input/output file handles.

The operation must be set with Crypt_GPG_Engine::setOperation() before this method is called.


[ Top ]

sendCommand   [line 765]

void sendCommand( string $command)

Sends a command to the GPG subprocess over the command file-descriptor pipe
  • Access: public

Parameters:

string   $command   —  the command to send.

[ Top ]

setInput   [line 853]

void setInput( string|resource &$input)

Sets the input source for the current GPG operation
  • Access: public

Parameters:

string|resource   &$input   —  either a reference to the string containing the input data or an open stream resource containing the input data.

[ Top ]

setMessage   [line 873]

void setMessage( string|resource &$message)

Sets the message source for the current GPG operation

Detached signature data should be specified here.

  • Access: public

Parameters:

string|resource   &$message   —  either a reference to the string containing the message data or an open stream resource containing the message data.

[ Top ]

setOperation   [line 915]

void setOperation( string $operation, [array $arguments = array()])

Sets the operation to perform

Parameters:

string   $operation   —  the operation to perform. This should be one of GPG's operations. For example, --encrypt, --decrypt, --sign, etc.
array   $arguments   —  optional. Additional arguments for the GPG subprocess. See the GPG manual for specific values.

[ Top ]

setOutput   [line 891]

void setOutput( string|resource &$output)

Sets the output destination for the current GPG operation
  • Access: public

Parameters:

string|resource   &$output   —  either a reference to the string in which to store GPG output or an open stream resource to which the output data should be written.

[ Top ]

setPins   [line 940]

void setPins( array $keys)

Sets the PINENTRY_USER_DATA environment variable with the currently added keys and passphrases

Keys and passphrases are stored as an indexed array of passphrases in JSON encoded to a flat string.

For GnuPG 2.x this is how passphrases are passed. For GnuPG 1.x the environment variable is set but not used.

  • Access: public

Parameters:

array   $keys   —  the internal key array to use.

[ Top ]

setProcessData   [line 1056]

void setProcessData( string $name, mixed $value)

Set some data for the process execution.
  • Access: public

Parameters:

string   $name   —  Data element name (e.g. 'Handle')
mixed   $value   —  Data value

[ Top ]


Documentation generated on Tue, 06 Dec 2016 09:30:02 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.