def gen_wss_token(user, passw, method='Digest', nonce=True, created=True): """Method generates WSS token Args: user (str): username passw (str): password method (str): token method Text|Digest nonce (bool): include nonce created (bool): include created Returns: dict """ token = UsernameToken(user, passw) if (nonce): token.setnonce() if (created): token.setcreated() token = {'username': user, 'password': passw, 'nonce': str( token.nonce), 'created': str(token.created)} if (method == 'Digest'): token['created'] = datetime.utcnow().isoformat()[:-3] + 'Z' token['password'] = encodestring( sha1(token['nonce'] + token['created'] + passw).digest())[:-1] token['nonce'] = encodestring(token['nonce'])[:-1] return token
def add_security(client, user, passwd): sec = Security() token = UsernameToken(user, passwd) token.setnonce() token.setcreated() sec.tokens.append(token) client.set_options(wsse=sec)
def test_wsse_username_nonce(self): security = Security() token = UsernameToken("username", "password") token.setnonce() token.setcreated() token.setnonceencoding(True) token.setpassworddigest("digest") security.tokens.append(token) assert "<wsu:Created" in str(security.xml())
def create_tokens(response): security = Security() token = UsernameToken(AUTHORIZED_NUI) token.setcreated(response.Fecha) token.nonce_has_encoding = True token.setnonce(response.Nonce) token.setpassworddigest(response.Digest) security.tokens.append(token) token_ts = Timestamp() token_ts.created = response.Fecha token_ts.expires = response.FechaF security.tokens.append(token_ts) return security
def add_tokens(response, student_identity): """ Agregar token de seguridad y de tiempo en header de WS """ security = Security() token = UsernameToken(settings.WS_CONFIG['identity']) token.setcreated(response.Fecha) token.nonce_has_encoding = True token.setnonce(response.Nonce) token.setpassworddigest(response.Digest) security.tokens.append(token) token_ts = Timestamp() token_ts.created = response.Fecha token_ts.expires = response.FechaF security.tokens.append(token_ts) return security
def addWsse(self, username, password, nonce=False, create=False): """ Add WS-Security @param username: username @type username: string @param password: password @type password: string @param nonce: add nonce element (default=False) @type nonce: boolean @param create: add create element (default=False) @type create: boolean """ security = Security() token = UsernameToken(username, password) if nonce: token.setnonce() if create: token.setcreated() security.tokens.append(token) self.LIB_SUDS.set_options(wsse=security)