Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/akami/wsse/verify_signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def initialize(xml)
def namespaces
@namespaces ||= {
wse: Akami::WSSE::WSE_NAMESPACE,
wsse: 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
ds: 'http://www.w3.org/2000/09/xmldsig#',
wsu: Akami::WSSE::WSU_NAMESPACE,
ec: Akami::WSSE::Signature::ExclusiveXMLCanonicalizationAlgorithm,
Expand All @@ -33,7 +34,12 @@ def namespaces

# Returns signer's certificate, bundled in signed document
def certificate
certificate_value = document.at_xpath('//wse:Security/wse:BinarySecurityToken', namespaces).text.strip
signature_certificate_id = document.at_xpath(
'//wse:Security/ds:Signature/ds:KeyInfo/wsse:SecurityTokenReference/wsse:Reference',
namespaces
)['URI'][1..-1] # strip leading '#'

certificate_value = document.at_xpath("//wse:Security/wse:BinarySecurityToken[@wsu:Id=\"#{signature_certificate_id}\"]", namespaces).text.strip
OpenSSL::X509::Certificate.new Base64.decode64(certificate_value)
end

Expand Down Expand Up @@ -67,6 +73,8 @@ def digesters

def verify
document.xpath('//wse:Security/ds:Signature/ds:SignedInfo/ds:Reference', namespaces).each do |ref|
next unless ref.attributes['URI'].value.start_with?('#')

digest_algorithm = ref.at_xpath('//ds:DigestMethod', namespaces)['Algorithm']

transform_inclusive_ns = inclusive_namespaces(ref, './/ds:Transforms/ds:Transform/ec:InclusiveNamespaces')
Expand Down Expand Up @@ -139,6 +147,7 @@ def digester_for_signature_method(algorithm_url)
'http://www.w3.org/2000/09/xmldsig#sha1' => lambda { OpenSSL::Digest::SHA1.new },
# SHA 256
'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256' => lambda { OpenSSL::Digest::SHA256.new },
'http://www.w3.org/2001/04/xmlenc#sha256' => lambda { OpenSSL::Digest::SHA256.new },
# GOST R 34.11-94
# You need correctly configured gost engine in your system OpenSSL, requires OpenSSL >= 1.0.0
# see https://github.com/openssl/openssl/blob/master/engines/ccgost/README.gost
Expand Down
Loading