class Saml::Utils

Overview

SAML2 Auxiliary class

Defined in:

saml/utils.cr

Constant Summary

BINDINGS = {:post => "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST", :redirect => "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"}
DSIG = "http://www.w3.org/2000/09/xmldsig#"
DURATION_FORMAT = /^ (-?)P # 1: Duration sign (?: (?:(\d+)Y)? # 2: Years (?:(\d+)M)? # 3: Months (?:(\d+)D)? # 4: Days (?:T (?:(\d+)H)? # 5: Hours (?:(\d+)M)? # 6: Minutes (?:(\d+(?:[.,]\d+)?)S)? # 7: Seconds )? | (\d+)W # 8: Weeks ) $/x
EVP_CTRL_GCM_SET_TAG = 17
GCM_TAG_LENGTH = 16
UUID_PREFIX = "_"
XENC = "http://www.w3.org/2001/04/xmlenc#"

Class Method Summary

Class Method Detail

def self.build_cert_object(cert : String | Nil) : OpenSSL::X509::Certificate | Nil #

[View source]
def self.build_private_key_object(private_key : String | Nil) : OpenSSL::PKey::RSA | Nil #

[View source]
def self.build_query(params) : String #

Build the Query String signature that will be used in the HTTP-Redirect binding


[View source]
def self.build_query_from_raw_parts(params) : String #

Reconstruct a canonical query string from raw URI-encoded parts, to be used in verifying a signature


[View source]
def self.decrypt_data(encrypted_node : XML::Node, private_key : OpenSSL::PKey::RSA | String) : String | Nil #

Obtains the decrypted string from an Encrypted node element in XML


[View source]
def self.decrypt_multi(encrypted_node : XML::Node, private_keys : Array(OpenSSL::PKey::RSA)) : String | Nil #

Tries each private key in turn; nil if none decrypts the element.


[View source]
def self.element_text(element : XML::Node | Nil) : String | Nil #

Concatenation of the element's own text and CDATA children (comments and child elements ignored). Nil when no element is given.


[View source]
def self.escape_request_param(param : String, lowercase_url_encoding) : String #

[View source]
def self.format_cert(cert : String | Nil) : String | Nil #

Return a properly formatted x509 certificate


[View source]
def self.format_private_key(key : String | Nil) : String | Nil #

Return a properly formatted private key


[View source]
def self.is_cert_active(cert : OpenSSL::X509::Certificate | String) : Bool #

@return [Boolean] True if the certificate is within its validity period.


[View source]
def self.is_cert_expired(cert : OpenSSL::X509::Certificate | String) : Bool #

@return [Boolean] True if the certificate's notAfter is in the past.


[View source]
def self.original_uri_match?(destination_url, settings_url) : Bool #

[View source]
def self.parse_duration(duration : String, timestamp : Time | Int = Time.utc) : Float64 #

Interprets a ISO8601 duration value relative to a given timestamp. @return [Float64] The new unix timestamp, after the duration is applied.


[View source]
def self.prefix : String #

[View source]
def self.prepare_raw_get_params(rawparams : Hash(String, String) | Nil, params : Hash(String, String), lowercase_url_encoding = false) : Hash(String, String) #

Prepare raw GET parameters (build them from normal parameters if not provided).


[View source]
def self.retrieve_plaintext(cipher_text : Bytes, symmetric_key : Bytes | String | OpenSSL::PKey::RSA | Nil, algorithm : String | Nil) : Bytes | Nil #

Obtains the deciphered bytes: block ciphers take a symmetric key, key transport takes the SP's RSA key. Nil for unsupported algorithms or when decryption or the GCM tag check fails.


[View source]
def self.retrieve_symetric_key_reference(encrypt_data : XML::Node) : String | Nil #

[View source]
def self.retrieve_symmetric_key(encrypt_data : XML::Node, private_key : OpenSSL::PKey::RSA) : Bytes | Nil #

Obtains the symmetric key from the EncryptedData element


[View source]
def self.set_prefix(value : String) #

[View source]
def self.status_error_msg(error_msg : String, raw_status_code : String | Nil = nil, status_message : String | Nil = nil) : String #

Build the status error message


[View source]
def self.uri_match?(destination_url : String, settings_url : String) : Bool #

Matches two URIs: scheme and host case-insensitively, port, path and query exactly. Falls back to plain string equality when either isn't a URL.


[View source]
def self.url_decode(input : String | Nil) : String #

[View source]
def self.url_encode(input : String | Nil) : String #

Form encoding, as Ruby's CGI.escape does.


[View source]
def self.uuid : String #

[View source]
def self.verify_signature(params) : Bool #

Validate the Signature parameter sent on the HTTP-Redirect binding. Unsupported SigAlg values are refused.


[View source]