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.
Afficher le fichier Open project: kimai/kimai Class Usage Examples

Méthodes publiques

Свойство 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

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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

bigNumToBin() protected static méthode

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

binToBigNum() protected static méthode

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
Résultat mixed

btwoc() public static méthode

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
Résultat string big-endian signed representation

computeDhSecret() public static méthode

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
Résultat string

createDhKey() public static méthode

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
Résultat mixed

digest() public static méthode

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
Résultat string RAW digital signature

getDhKeyDetails() public static méthode

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
Résultat array

hashHmac() public static méthode

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
Résultat string RAW HMAC value

normalize() public static méthode

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
Résultat boolean

normalizeUrl() public static méthode

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

paramsToQuery() public static méthode

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

randomBytes() public static méthode

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

redirect() public static méthode

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 méthode

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

setSelfUrl() public static méthode

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
Résultat string the old value of overriding URL

strlen() public static méthode

Returns lenght of binary string in bytes
public static strlen ( string $str ) : integer
$str string
Résultat 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