Class: SAML2::KeyInfo
Overview
This represents the XML Signatures <KeyInfo> element, and actually contains a reference to an X.509 certificate, not solely a public key.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#x509 ⇒ String
The PEM encoded certificate.
Attributes inherited from Base
Class Method Summary collapse
-
.format_fingerprint(fingerprint) ⇒ String
Formats a fingerprint as all lowercase, with a : every two characters, stripping all non-hexadecimal characters.
Instance Method Summary collapse
-
#build(builder) ⇒ void
Serialize this object to XML, as part of a larger document.
- #certificate ⇒ OpenSSL::X509::Certificate
- #fingerprint ⇒ String
-
#from_xml(node) ⇒ void
Parse an XML element into this object.
-
#initialize(x509 = nil) ⇒ KeyInfo
constructor
A new instance of KeyInfo.
Methods inherited from Base
#decrypt, from_xml, #inspect, load_object_array, load_string_array, lookup_qname, #to_s, #to_xml
Constructor Details
#initialize(x509 = nil) ⇒ KeyInfo
Returns a new instance of KeyInfo.
16 17 18 |
# File 'lib/saml2/key.rb', line 16 def initialize(x509 = nil) self.x509 = x509 end |
Instance Attribute Details
#x509 ⇒ String
Returns The PEM encoded certificate.
13 14 15 |
# File 'lib/saml2/key.rb', line 13 def x509 @x509 end |
Class Method Details
.format_fingerprint(fingerprint) ⇒ String
Formats a fingerprint as all lowercase, with a : every two characters, stripping all non-hexadecimal characters.
38 39 40 |
# File 'lib/saml2/key.rb', line 38 def self.format_fingerprint(fingerprint) fingerprint.downcase.gsub(/[^0-9a-f]/, '').gsub(/(\h{2})(?=\h)/, '\1:') end |
Instance Method Details
#build(builder) ⇒ void
This method returns an undefined value.
Serialize this object to XML, as part of a larger document
48 49 50 51 52 53 54 |
# File 'lib/saml2/key.rb', line 48 def build(builder) builder['dsig'].KeyInfo do |key_info| key_info['dsig'].X509Data do |x509_data| x509_data['dsig'].X509Certificate(x509) end end end |
#certificate ⇒ OpenSSL::X509::Certificate
30 31 32 |
# File 'lib/saml2/key.rb', line 30 def certificate @certificate ||= OpenSSL::X509::Certificate.new(Base64.decode64(x509)) end |
#fingerprint ⇒ String
43 44 45 |
# File 'lib/saml2/key.rb', line 43 def fingerprint @fingerprint ||= self.class.format_fingerprint(Digest::SHA1.hexdigest(certificate.to_der)) end |
#from_xml(node) ⇒ void
This method returns an undefined value.
Parse an XML element into this object.
21 22 23 |
# File 'lib/saml2/key.rb', line 21 def from_xml(node) self.x509 = node.at_xpath('dsig:KeyInfo/dsig:X509Data/dsig:X509Certificate', Namespaces::ALL)&.content&.strip end |