PHP Class Zend_OpenId

This class implements common utility functions that are used by both Consumer and Provider. They include functions for Diffie-Hellman keys generation and exchange, URL normalization, HTTP redirection and some others.
显示文件 Open project: kimai/kimai Class Usage Examples

Public Properties

Property Type Description
$exitOnRedirect Allows enable/disable stoping execution of PHP script after redirect()
$selfUrl Alternative request URL that can be used to override the default selfUrl() response

Public Methods

Method Description
absoluteUrl ( string $url ) : string Returns an absolute URL for the given one
btwoc ( string $str ) : string Takes an arbitrary precision integer and returns its shortest big-endian two's complement representation.
computeDhSecret ( string $pub_key, mixed $dh ) : string Computes the shared secret from the private DH value $dh and the other party's public value in $pub_key
createDhKey ( string $p, string $g, string $priv_key = null ) : mixed Performs the first step of a Diffie-Hellman key exchange by generating private and public DH values based on given prime number $p and generator $g. Both sides of key exchange MUST have the same prime number and generator. In this case they will able to create a random shared secret that is never send from one to the other.
digest ( string $func, string $data ) : string Generates a hash value (message digest) according to given algorithm.
getDhKeyDetails ( mixed $dh ) : array Returns an associative array with Diffie-Hellman key components in binary representation. The array includes original prime number 'p' and generator 'g', random private key 'priv_key' and corresponding public key 'pub_key'.
hashHmac ( string $macFunc, string $data, string $secret ) : string Generates a keyed hash value using the HMAC method. It uses ext/hash if available or user-level PHP implementation, that is not significantly slower.
normalize ( &$id ) : boolean Normalizes OpenID identifier that can be URL or XRI name.
normalizeUrl ( &$id ) : boolean Normalizes URL according to RFC 3986 to use it in comparison operations.
paramsToQuery ( array $params ) : string Converts variable/value pairs into URL encoded query string
randomBytes ( integer $len ) : string Produces string of random byte of given length.
redirect ( string $url, array $params = null, Zend_Controller_Response_Abstract $response = null, string $method = 'GET' ) Performs a HTTP redirection to specified URL with additional data.
selfUrl ( ) : string Returns a full URL that was requested on current HTTP request.
setSelfUrl ( string $selfUrl = null ) : string Sets alternative request URL that can be used to override the default selfUrl() response
strlen ( string $str ) : integer Returns lenght of binary string in bytes

Protected Methods

Method Description
bigNumToBin ( mixed $bn ) : string Converts internal ext/gmp or ext/bcmath big integer representation into binary string.
binToBigNum ( string $bin ) : mixed Converts binary representation into ext/gmp or ext/bcmath big integer representation.

Method Details

absoluteUrl() public static method

Returns an absolute URL for the given one
public static absoluteUrl ( string $url ) : string
$url string absilute or relative URL
return string

bigNumToBin() protected static method

Converts internal ext/gmp or ext/bcmath big integer representation into binary string.
protected static bigNumToBin ( mixed $bn ) : string
$bn mixed big number
return string

binToBigNum() protected static method

Converts binary representation into ext/gmp or ext/bcmath big integer representation.
protected static binToBigNum ( string $bin ) : mixed
$bin string binary representation of big number
return mixed

btwoc() public static method

Arbitrary precision integers MUST be encoded as big-endian signed two's complement binary strings. Henceforth, "btwoc" is a function that takes an arbitrary precision integer and returns its shortest big-endian two's complement representation. All integers that are used with Diffie-Hellman Key Exchange are positive. This means that the left-most bit of the two's complement representation MUST be zero. If it is not, implementations MUST add a zero byte at the front of the string.
public static btwoc ( string $str ) : string
$str string binary representation of arbitrary precision integer
return string big-endian signed representation

computeDhSecret() public static method

Computes the shared secret from the private DH value $dh and the other party's public value in $pub_key
public static computeDhSecret ( string $pub_key, mixed $dh ) : string
$pub_key string other party's public value
$dh mixed Diffie-Hellman key
return string

createDhKey() public static method

Performs the first step of a Diffie-Hellman key exchange by generating private and public DH values based on given prime number $p and generator $g. Both sides of key exchange MUST have the same prime number and generator. In this case they will able to create a random shared secret that is never send from one to the other.
public static createDhKey ( string $p, string $g, string $priv_key = null ) : mixed
$p string prime number in binary representation
$g string generator in binary representation
$priv_key string private key in binary representation
return mixed

digest() public static method

It returns RAW binary string. This is a wrapper function that uses one of available internal function dependent on given PHP configuration. It may use various functions from ext/openssl, ext/hash, ext/mhash or ext/standard.
public static digest ( string $func, string $data ) : string
$func string digest algorithm
$data string data to sign
return string RAW digital signature

getDhKeyDetails() public static method

Returns an associative array with Diffie-Hellman key components in binary representation. The array includes original prime number 'p' and generator 'g', random private key 'priv_key' and corresponding public key 'pub_key'.
public static getDhKeyDetails ( mixed $dh ) : array
$dh mixed Diffie-Hellman key
return array

hashHmac() public static method

Generates a keyed hash value using the HMAC method. It uses ext/hash if available or user-level PHP implementation, that is not significantly slower.
public static hashHmac ( string $macFunc, string $data, string $secret ) : string
$macFunc string name of selected hashing algorithm (sha1, sha256)
$data string data to sign
$secret string shared secret key used for generating the HMAC variant of the message digest
return string RAW HMAC value

normalize() public static method

Returns true on success and false of failure. Normalization is performed according to the following rules: 1. If the user's input starts with one of the "xri://", "xri://$ip*", or "xri://$dns*" prefixes, they MUST be stripped off, so that XRIs are used in the canonical form, and URI-authority XRIs are further considered URL identifiers. 2. If the first character of the resulting string is an XRI Global Context Symbol ("=", "@", "+", "$", "!"), then the input SHOULD be treated as an XRI. 3. Otherwise, the input SHOULD be treated as an http URL; if it does not include a "http" or "https" scheme, the Identifier MUST be prefixed with the string "http://". 4. URL identifiers MUST then be further normalized by both following redirects when retrieving their content and finally applying the rules in Section 6 of [RFC3986] to the final destination URL.
public static normalize ( &$id ) : boolean
return boolean

normalizeUrl() public static method

The function gets URL argument by reference and modifies it. It returns true on success and false of failure.
public static normalizeUrl ( &$id ) : boolean
return boolean

paramsToQuery() public static method

Converts variable/value pairs into URL encoded query string
public static paramsToQuery ( array $params ) : string
$params array variable/value pairs
return string URL encoded query string

randomBytes() public static method

Produces string of random byte of given length.
public static randomBytes ( integer $len ) : string
$len integer length of requested string
return string RAW random binary string

redirect() public static method

It may generate redirected request using GET or POST HTTP method. The function never returns.
public static redirect ( string $url, array $params = null, Zend_Controller_Response_Abstract $response = null, string $method = 'GET' )
$url string URL to redirect to
$params array additional variable/value pairs to send
$response Zend_Controller_Response_Abstract
$method string redirection method ('GET' or 'POST')

selfUrl() public static method

Returns a full URL that was requested on current HTTP request.
public static selfUrl ( ) : string
return string

setSelfUrl() public static method

Sets alternative request URL that can be used to override the default selfUrl() response
public static setSelfUrl ( string $selfUrl = null ) : string
$selfUrl string the URL to be set
return string the old value of overriding URL

strlen() public static method

Returns lenght of binary string in bytes
public static strlen ( string $str ) : integer
$str string
return integer the string lenght

Property Details

$exitOnRedirect public_oe static_oe property

Allows enable/disable stoping execution of PHP script after redirect()
public static $exitOnRedirect

$selfUrl public_oe static_oe property

Alternative request URL that can be used to override the default selfUrl() response
public static $selfUrl