Exemple #1
0
 def on_shared_secret_response(self, msg):
     logger.info("Received shared secret response")
     relay = MediaRelay()
     for attr in msg.attributes:
         if attr.type == AttributeTypes.USERNAME:
             relay.username = base64.b64encode(attr.value)
         elif attr.type == AttributeTypes.PASSWORD:
             relay.password = base64.b64encode(attr.value)
         elif attr.type == AttributeTypes.ALTERNATE_SERVER:
             relay.ip, relay.port = parse_server(attr.value)
     self.on_relay_discovered(relay)
Exemple #2
0
    def on_message_received(self, transport, data, length):
        msg = TURNMessage()
        msg.parse(data)

        if self._requests.get(msg.id, None) is None:
            return
        else:
            del self._requests[msg.id]

        if msg.type == MessageTypes.SHARED_SECRET_ERROR:
            error_msg = None
            realm = None
            nonce = None
            for attr in msg.attributes:
                if attr.type == AttributeTypes.REALM:
                    realm = attr.value
                elif attr.type == AttributeTypes.NONCE:
                    nonce = attr.value
                elif attr.type == AttributeTypes.ERROR_CODE:
                    error_msg = attr.value[4:]
            if error_msg == "Unauthorized":
                if realm is not None or nonce is not None:
                    self.request_shared_secret_with_integrity(None, None, realm, nonce)
                    return

        elif msg.type == MessageTypes.SHARED_SECRET_RESPONSE:
            relay = MediaRelay()
            for attr in msg.attributes:
                if attr.type == AttributeTypes.USERNAME:
                    relay.username = base64.b64encode(attr.value)
                elif attr.type == AttributeTypes.PASSWORD:
                    relay.password = base64.b64encode(attr.value)
                elif attr.type == AttributeTypes.ALTERNATE_SERVER:
                    server = struct.unpack("!HHcccc", attr.value)
                    ip = map(lambda x: ord(x), server[2:6])
                    relay.ip = "%i.%i.%i.%i" % tuple(ip)
                    relay.port = server[1]
            self._relays.append(relay)

        if not self._requests:
            self._done()
Exemple #3
0
    def on_message_received(self, transport, data, length):
        msg = TURNMessage()
        msg.parse(data)

        if self._requests.get(msg.id, None) is None:
            return
        else:
            del self._requests[msg.id]

        if msg.type == MessageTypes.SHARED_SECRET_ERROR:
            error_msg = None
            realm = None
            nonce = None
            for attr in msg.attributes:
                if attr.type == AttributeTypes.REALM:
                    realm = attr.value
                elif attr.type == AttributeTypes.NONCE:
                    nonce = attr.value
                elif attr.type == AttributeTypes.ERROR_CODE:
                    error_msg = attr.value[4:]
            if error_msg == "Unauthorized":
                if realm is not None or nonce is not None:
                    self.request_shared_secret_with_integrity(
                        None, None, realm, nonce)
                    return

        elif msg.type == MessageTypes.SHARED_SECRET_RESPONSE:
            relay = MediaRelay()
            for attr in msg.attributes:
                if attr.type == AttributeTypes.USERNAME:
                    relay.username = base64.b64encode(attr.value)
                elif attr.type == AttributeTypes.PASSWORD:
                    relay.password = base64.b64encode(attr.value)
                elif attr.type == AttributeTypes.ALTERNATE_SERVER:
                    server = struct.unpack("!HHcccc", attr.value)
                    ip = map(lambda x: ord(x), server[2:6])
                    relay.ip = "%i.%i.%i.%i" % tuple(ip)
                    relay.port = server[1]
            self._relays.append(relay)

        if not self._requests:
            self._done()