Exemple #1
0
 def __init__(self, realm, users):
     self.nonce = self.generate_nonce()
     self.realm = realm
     self.hmac_keys = {}
     for username, credentials in users.iteritems():
         key = credentials.get('key')
         if not key:
             password = credentials.get('password')
             if not password:
                 logger.warning("Invalid credentials for %s", username)
                 continue
         self.hmac_keys[username] = ha1(username, self.realm, password)
Exemple #2
0
 def __init__(self, realm, users):
     self.nonce = self.generate_nonce()
     self.realm = realm
     self.hmac_keys = {}
     for username, credentials in users.iteritems():
         key = credentials.get('key')
         if not key:
             password = credentials.get('password')
             if not password:
                 logger.warning("Invalid credentials for %s", username)
                 continue
         self.hmac_keys[username] = ha1(username, self.realm, password)
Exemple #3
0
    def test_encode(self):
        msg = Message.encode(stun.METHOD_BINDING,
                             stun.CLASS_REQUEST,
                             transaction_id='fixedtransid')
        # Override padding generation to make the message data deterministic
        msg._padding = '\x00'.__mul__  # Pad with zero bytes

        msg.add_attr(type('Foo', (Unknown, ), {'type': 0x6666}), 'data')
        msg.add_attr(attributes.MappedAddress, Address.FAMILY_IPv4, 1337,
                     '192.168.2.255')
        msg.add_attr(attributes.Username, "johndoe")
        msg.add_attr(attributes.MessageIntegrity,
                     ha1('username', 'realm', 'password'))
        msg.add_attr(attributes.ErrorCode, *stun.ERR_SERVER_ERROR)
        msg.add_attr(attributes.UnknownAttributes, [0x1337, 0xb00b, 0xbeef])
        msg.add_attr(attributes.Realm, "pexip.com")
        msg.add_attr(attributes.Nonce,
                     '36303332376331373134356137373838'.decode('hex'))
        msg.add_attr(attributes.XorMappedAddress, Address.FAMILY_IPv4, 1337,
                     '192.168.2.255')
        msg.add_attr(attributes.Software,
                     u"\u8774\u8776 h\xfadi\xe9 'butterfly'")
        msg.add_attr(attributes.AlternateServer, Address.FAMILY_IPv4, 8008,
                     '192.168.2.128')
        msg.add_attr(attributes.Fingerprint)

        msg_data = ('000100bc2112a4426669786564747261'
                    '6e736964666600046461746100010008'
                    '00010539c0a802ff000600076a6f686e'
                    '646f6500000800144ad36bd8d0c242f6'
                    'a2b98ccbcfe0f21432261fb400090010'
                    '00000500536572766572204572726f72'
                    '000a00061337b00bbeef000000140009'
                    '70657869702e636f6d00000000150010'
                    '36303332376331373134356137373838'
                    '002000080001242be1baa6bd8022001a'
                    'e89db4e89db62068c3ba6469c3a92027'
                    '627574746572666c7927000080230008'
                    '00011f48c0a8028080280004e43217b7').decode('hex')

        self.assertEqual(str(msg), msg_data)
Exemple #4
0
    def test_encode(self):
        msg = Message.encode(stun.METHOD_BINDING,
                             stun.CLASS_REQUEST,
                             transaction_id='fixedtransid')
        # Override padding generation to make the message data deterministic
        msg._padding = '\x00'.__mul__ # Pad with zero bytes

        msg.add_attr(type('Foo', (Unknown,), {'type': 0x6666}), 'data')
        msg.add_attr(attributes.MappedAddress, Address.FAMILY_IPv4, 1337, '192.168.2.255')
        msg.add_attr(attributes.Username, "johndoe")
        msg.add_attr(attributes.MessageIntegrity, ha1('username', 'realm', 'password'))
        msg.add_attr(attributes.ErrorCode, *stun.ERR_SERVER_ERROR)
        msg.add_attr(attributes.UnknownAttributes, [0x1337, 0xb00b, 0xbeef])
        msg.add_attr(attributes.Realm, "pexip.com")
        msg.add_attr(attributes.Nonce, '36303332376331373134356137373838'.decode('hex'))
        msg.add_attr(attributes.XorMappedAddress, Address.FAMILY_IPv4, 1337, '192.168.2.255')
        msg.add_attr(attributes.Software, u"\u8774\u8776 h\xfadi\xe9 'butterfly'")
        msg.add_attr(attributes.AlternateServer, Address.FAMILY_IPv4, 8008, '192.168.2.128')
        msg.add_attr(attributes.Fingerprint)

        msg_data = (
            '000100bc2112a4426669786564747261'
            '6e736964666600046461746100010008'
            '00010539c0a802ff000600076a6f686e'
            '646f6500000800144ad36bd8d0c242f6'
            'a2b98ccbcfe0f21432261fb400090010'
            '00000500536572766572204572726f72'
            '000a00061337b00bbeef000000140009'
            '70657869702e636f6d00000000150010'
            '36303332376331373134356137373838'
            '002000080001242be1baa6bd8022001a'
            'e89db4e89db62068c3ba6469c3a92027'
            '627574746572666c7927000080230008'
            '00011f48c0a8028080280004e43217b7'
            ).decode('hex')

        self.assertEqual(str(msg), msg_data)
Exemple #5
0
 def add_user(self, username, password):
     self.hmac_keys[username] = ha1(username, self.realm, password)
Exemple #6
0
 def add_user(self, username, password):
     self.hmac_keys[username] = ha1(username, self.realm, password)