Skip to content

Instantly share code, notes, and snippets.

@akostadinov akostadinov/wsse_xml.rb
Last active Jun 13, 2016

Embed
What would you like to do?
generate XML WSSE credentials with the simple `wsse` gem.
require 'io/console'
require 'wsse'
header = WSSE::header('username', STDIN.noecho(&:gets).chomp)
def wsse_xml(user, password)
raw = WSSE::header(user, password)
# username = raw.gsub(/^.* Username="(.*)", PasswordDigest=".*(?!PasswordDigest)$/, '\\1')
digest = raw.gsub(/^.*, PasswordDigest="(.*)", Nonce=".*$/, '\\1')
nonce = raw.gsub(/^.*, Nonce="(.*)", Created=".*$/, '\\1')
created = raw.gsub(/^.*, Created="(.*)".*$/, '\\1')
xml = '''
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>USER</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">DIGEST</wsse:Password>
<!-- <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password> -->
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NONCE</wsse:Nonce>
<wsu:Created>CREATED</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
'''
# return xml.gsub("USER", user).gsub("PASSWORD", password).gsub("NONCE",nonce).gsub("CREATED",created)
return xml.gsub("USER", user).gsub("DIGEST", digest).gsub("NONCE",nonce).gsub("CREATED",created)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.