Skip to content

Instantly share code, notes, and snippets.

@Adniel
Created November 12, 2014 19:21
Show Gist options
  • Save Adniel/96c497683624304bd59d to your computer and use it in GitHub Desktop.
Save Adniel/96c497683624304bd59d to your computer and use it in GitHub Desktop.
from hashlib import sha1
import time
import random
import uuid
def get_digest(password, nonce, created):
""" Returns the password's expected digest.
"""
nonce = nonce.decode('base64')
concat = nonce + created + password
h = sha1()
h.update(concat)
return str.encode(h.digest(), 'base64').rstrip('\n')
nonce = str(random.random()).encode('base64')
created = str(time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(time.time())))
precreation = str(time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(time.time() - 30)))
expires = str(time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(time.time() + 60)))
password='1111'
digest = get_digest(password, nonce, created)
guid = str(uuid.uuid4())
header = """
<soap:Header>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-{guid}">
<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: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>
<wsu:Timestamp wsu:Id="TS-1c559973-3141-449d-9e71-2116ffa07427">
<wsu:Created>{created}</wsu:Created>
<wsu:Expires>{expires}</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>""".format(user='admin', password=password, guid=guid, nonce=nonce, created=created, expires=expires, digest=digest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment