PHP Class OneLogin_Saml2_Utils

Defines several often used methods
Afficher le fichier Open project: onelogin/php-saml Class Usage Examples

Méthodes publiques

Méthode Description
addSign ( string | DomDocument $xml, string $key, string $cert, string $signAlgorithm = XMLSecurityKey::RSA_SHA1 ) : string Adds signature key and senders certificate to an element (Message or Assertion).
calculateX509Fingerprint ( string $x509cert, $alg = 'sha1' ) : null | string Calculates the fingerprint of a x509cert.
castKey ( XMLSecurityKey $key, string $algorithm, string $type = 'public' ) : XMLSecurityKey Converts a XMLSecurityKey to the correct algorithm.
decryptElement ( DOMElement $encryptedData, XMLSecurityKey $inputKey ) : DOMElement Decrypts an encrypted element.
deleteLocalSession ( ) Deletes the local session.
extractOriginalQueryParam ( string $name ) : string Extract a query param - as it was sent - from $_SERVER[QUERY_STRING]
formatCert ( string $cert, boolean $heads = true ) : string Returns a x509 cert (adding header & footer if required).
formatFingerPrint ( string $fingerprint ) : string Formates a fingerprint.
formatPrivateKey ( string $key, boolean $heads = true ) : string Returns a private key (adding header & footer if required).
generateNameId ( string $value, string $spnq, string $format, string | null $cert = null ) : string Generates a nameID.
generateUniqueID ( ) : string Generates an unique string (used for example as ID for assertions).
getBaseURLPath ( ) return string The baseurlpath to be used when constructing URLs
getExpireTime ( string $cacheDuration = null, string $validUntil = null ) : integer Compares 2 dates and returns the earliest.
getProxyVars ( ) return bool
getSelfHost ( ) : string Returns the current host.
getSelfPort ( ) : null | string
getSelfProtocol ( ) : string
getSelfRoutedURLNoQuery ( ) : string Returns the routed URL of the current host + current view.
getSelfURL ( ) : string Returns the URL of the current host + current view + query.
getSelfURLNoQuery ( ) : string Returns the URL of the current host + current view.
getSelfURLhost ( ) : string Returns the protocol + the current host + the port (if different than common ports).
getStatus ( DOMDocument $dom ) : array Gets Status from a Response.
get_string_between ( string $str, string $start, string $end ) : string Extracts a substring between 2 marks
isHTTPS ( ) : boolean Checks if https or http.
isSessionStarted ( ) : boolean Checks if the session is started or not.
loadXML ( DOMDocument $dom, string $xml ) : DOMDocument This function load an XML string in a save way.
parseDuration ( string $duration, integer | null $timestamp = null ) : integer | null Interprets a ISO8601 duration value relative to a given timestamp.
parseSAML2Time ( string $time ) : integer Converts a SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z to a UNIX timestamp. The sub-second part is ignored.
parseTime2SAML ( string $time ) : string Converts a UNIX timestamp to SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z.
query ( DOMDocument $dom, string $query, DomElement $context = null ) : DOMNodeList Extracts nodes from the DOMDocument.
redirect ( string $url, array $parameters = [], boolean $stay = false ) : string | null Executes a redirection to the provided url (or return the target url).
setBaseURL ( $baseurl )
setBaseURLPath ( $baseurlpath )
setProxyVars ( $proxyVars )
setSelfHost ( $host )
setSelfPort ( $port )
setSelfProtocol ( $protocol )
t ( string $msg, array | null $args = [] ) : string Translates any string. Accepts args
validateSign ( string | DomNode $xml, string | null $cert = null, string | null $fingerprint = null, string | null $fingerprintalg = 'sha1', string | null $xpath = null ) : boolean Validates a signature (Message or Assertion).
validateXML ( string | DOMDocument $xml, string $schema, boolean $debug = false ) : string | DOMDocument This function attempts to validate an XML string against the specified schema.

Méthodes protégées

Méthode Description
buildWithBaseURLPath ( $info ) : string Returns the part of the URL with the BaseURLPath.
getRawHost ( ) : string

Method Details

addSign() public static méthode

Adds signature key and senders certificate to an element (Message or Assertion).
public static addSign ( string | DomDocument $xml, string $key, string $cert, string $signAlgorithm = XMLSecurityKey::RSA_SHA1 ) : string
$xml string | DomDocument The element we should sign
$key string The private key
$cert string The public
$signAlgorithm string Signature algorithm method
Résultat string

buildWithBaseURLPath() protected static méthode

Returns the part of the URL with the BaseURLPath.
protected static buildWithBaseURLPath ( $info ) : string
Résultat string

calculateX509Fingerprint() public static méthode

Calculates the fingerprint of a x509cert.
public static calculateX509Fingerprint ( string $x509cert, $alg = 'sha1' ) : null | string
$x509cert string x509 cert
Résultat null | string Formatted fingerprint

castKey() public static méthode

Converts a XMLSecurityKey to the correct algorithm.
public static castKey ( XMLSecurityKey $key, string $algorithm, string $type = 'public' ) : XMLSecurityKey
$key XMLSecurityKey The key.
$algorithm string The desired algorithm.
$type string Public or private key, defaults to public.
Résultat XMLSecurityKey The new key.

decryptElement() public static méthode

Decrypts an encrypted element.
public static decryptElement ( DOMElement $encryptedData, XMLSecurityKey $inputKey ) : DOMElement
$encryptedData DOMElement The encrypted data.
$inputKey XMLSecurityKey The decryption key.
Résultat DOMElement The decrypted element.

deleteLocalSession() public static méthode

Deletes the local session.
public static deleteLocalSession ( )

extractOriginalQueryParam() public static méthode

Extract a query param - as it was sent - from $_SERVER[QUERY_STRING]
public static extractOriginalQueryParam ( string $name ) : string
$name string The param to-be extracted
Résultat string

formatCert() public static méthode

Returns a x509 cert (adding header & footer if required).
public static formatCert ( string $cert, boolean $heads = true ) : string
$cert string A x509 unformated cert
$heads boolean True if we want to include head and footer
Résultat string $x509 Formatted cert

formatFingerPrint() public static méthode

Formates a fingerprint.
public static formatFingerPrint ( string $fingerprint ) : string
$fingerprint string fingerprint
Résultat string Formatted fingerprint

formatPrivateKey() public static méthode

Returns a private key (adding header & footer if required).
public static formatPrivateKey ( string $key, boolean $heads = true ) : string
$key string A private key
$heads boolean True if we want to include head and footer
Résultat string $rsaKey Formatted private key

generateNameId() public static méthode

Generates a nameID.
public static generateNameId ( string $value, string $spnq, string $format, string | null $cert = null ) : string
$value string fingerprint
$spnq string SP Name Qualifier
$format string SP Format
$cert string | null IdP Public cert to encrypt the nameID
Résultat string $nameIDElement DOMElement | XMLSec nameID

generateUniqueID() public static méthode

Generates an unique string (used for example as ID for assertions).
public static generateUniqueID ( ) : string
Résultat string A unique string

getBaseURLPath() public static méthode

return string The baseurlpath to be used when constructing URLs
public static getBaseURLPath ( )

getExpireTime() public static méthode

Compares 2 dates and returns the earliest.
public static getExpireTime ( string $cacheDuration = null, string $validUntil = null ) : integer
$cacheDuration string The duration, as a string.
$validUntil string The valid until date, as a string or as a timestamp
Résultat integer $expireTime The expiration time.

getProxyVars() public static méthode

return bool
public static getProxyVars ( )

getRawHost() protected static méthode

protected static getRawHost ( ) : string
Résultat string The raw host name

getSelfHost() public static méthode

Returns the current host.
public static getSelfHost ( ) : string
Résultat string $currentHost The current host

getSelfPort() public static méthode

public static getSelfPort ( ) : null | string
Résultat null | string The port number used for the request

getSelfProtocol() public static méthode

public static getSelfProtocol ( ) : string
Résultat string http|https

getSelfRoutedURLNoQuery() public static méthode

Returns the routed URL of the current host + current view.
public static getSelfRoutedURLNoQuery ( ) : string
Résultat string

getSelfURL() public static méthode

Returns the URL of the current host + current view + query.
public static getSelfURL ( ) : string
Résultat string

getSelfURLNoQuery() public static méthode

Returns the URL of the current host + current view.
public static getSelfURLNoQuery ( ) : string
Résultat string

getSelfURLhost() public static méthode

Returns the protocol + the current host + the port (if different than common ports).
public static getSelfURLhost ( ) : string
Résultat string $url

getStatus() public static méthode

Gets Status from a Response.
public static getStatus ( DOMDocument $dom ) : array
$dom DOMDocument The Response as XML
Résultat array $status The Status, an array with the code and a message.

get_string_between() public static méthode

Extracts a substring between 2 marks
public static get_string_between ( string $str, string $start, string $end ) : string
$str string The target string
$start string The initial mark
$end string The end mark
Résultat string A substring or an empty string if is not able to find the marks or if there is no string between the marks

isHTTPS() public static méthode

Checks if https or http.
public static isHTTPS ( ) : boolean
Résultat boolean $isHttps False if https is not active

isSessionStarted() public static méthode

Checks if the session is started or not.
public static isSessionStarted ( ) : boolean
Résultat boolean true if the sessíon is started

loadXML() public static méthode

Prevent XEE/XXE Attacks
public static loadXML ( DOMDocument $dom, string $xml ) : DOMDocument
$dom DOMDocument The document where load the xml.
$xml string The XML string to be loaded.
Résultat DOMDocument $dom The result of load the XML at the DomDocument

parseDuration() public static méthode

Interprets a ISO8601 duration value relative to a given timestamp.
public static parseDuration ( string $duration, integer | null $timestamp = null ) : integer | null
$duration string The duration, as a string.
$timestamp integer | null The unix timestamp we should apply the duration to. Optional, default to the current time.
Résultat integer | null The new timestamp, after the duration is applied.

parseSAML2Time() public static méthode

Converts a SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z to a UNIX timestamp. The sub-second part is ignored.
public static parseSAML2Time ( string $time ) : integer
$time string The time we should convert (SAML Timestamp).
Résultat integer $timestamp Converted to a unix timestamp.

parseTime2SAML() public static méthode

Converts a UNIX timestamp to SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z.
public static parseTime2SAML ( string $time ) : string
$time string The time we should convert (DateTime).
Résultat string $timestamp SAML2 timestamp.

query() public static méthode

Extracts nodes from the DOMDocument.
public static query ( DOMDocument $dom, string $query, DomElement $context = null ) : DOMNodeList
$dom DOMDocument The DOMDocument
$query string Xpath Expresion
$context DomElement Context Node (DomElement)
Résultat DOMNodeList The queried nodes

redirect() public static méthode

Executes a redirection to the provided url (or return the target url).
public static redirect ( string $url, array $parameters = [], boolean $stay = false ) : string | null
$url string The target url
$parameters array Extra parameters to be passed as part of the url
$stay boolean True if we want to stay (returns the url string) False to redirect
Résultat string | null $url

setBaseURL() public static méthode

public static setBaseURL ( $baseurl )
$baseurl string The base url to be used when constructing URLs

setBaseURLPath() public static méthode

public static setBaseURLPath ( $baseurlpath )
$baseurlpath string The baseurl path to use when constructing URLs

setProxyVars() public static méthode

public static setProxyVars ( $proxyVars )
$proxyVars bool Whether to use `X-Forwarded-*` headers to determine port/domain/protocol

setSelfHost() public static méthode

public static setSelfHost ( $host )
$host string The host to use when constructing URLs

setSelfPort() public static méthode

public static setSelfPort ( $port )
$port int The port number to use when constructing URLs

setSelfProtocol() public static méthode

public static setSelfProtocol ( $protocol )
$protocol string The protocol to identify as using, usually http or https

t() public static méthode

Translates any string. Accepts args
public static t ( string $msg, array | null $args = [] ) : string
$msg string Message to be translated
$args array | null Arguments
Résultat string $translatedMsg Translated text

validateSign() public static méthode

Validates a signature (Message or Assertion).
public static validateSign ( string | DomNode $xml, string | null $cert = null, string | null $fingerprint = null, string | null $fingerprintalg = 'sha1', string | null $xpath = null ) : boolean
$xml string | DomNode The element we should validate
$cert string | null The pubic cert
$fingerprint string | null The fingerprint of the public cert
$fingerprintalg string | null The algorithm used to get the fingerprint
$xpath string | null The xpath of the signed element
Résultat boolean

validateXML() public static méthode

It will parse the string into a DOM document and validate this document against the schema.
public static validateXML ( string | DOMDocument $xml, string $schema, boolean $debug = false ) : string | DOMDocument
$xml string | DOMDocument The XML string or document which should be validated.
$schema string The schema filename which should be used.
$debug boolean To disable/enable the debug mode
Résultat string | DOMDocument $dom string that explains the problem or the DOMDocument