Skip to content

Instantly share code, notes, and snippets.

@akostadinov
Last active June 13, 2016 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akostadinov/d28cbfe92120f229f6c99e071af73497 to your computer and use it in GitHub Desktop.
Save akostadinov/d28cbfe92120f229f6c99e071af73497 to your computer and use it in GitHub Desktop.
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