Exemplo n.º 1
0
    def validate_dnssec(self, url):
        print_msg('[OA] Checking DNSSEC trust chain for ' + url)

        try:
            default = dns.resolver.get_default_resolver()
            ns = default.nameservers[0]

            parts = url.split('.')

            for i in xrange(len(parts), 0, -1):
                sub = '.'.join(parts[i - 1:])

                query = dns.message.make_query(sub, dns.rdatatype.NS)
                response = dns.query.udp(query, ns, 1)

                if response.rcode() != dns.rcode.NOERROR:
                    return 0

                if len(response.authority) > 0:
                    rrset = response.authority[0]
                else:
                    rrset = response.answer[0]

                rr = rrset[0]
                if rr.rdtype == dns.rdatatype.SOA:
                    #Same server is authoritative, don't check again
                    continue

                query = dns.message.make_query(sub,
                                               dns.rdatatype.DNSKEY,
                                               want_dnssec=True)
                response = dns.query.udp(query, ns, 1)

                if response.rcode() != 0:
                    return 0
                    # HANDLE QUERY FAILED (SERVER ERROR OR NO DNSKEY RECORD)

                # answer should contain two RRSET: DNSKEY and RRSIG(DNSKEY)
                answer = response.answer
                if len(answer) != 2:
                    return 0

                # the DNSKEY should be self signed, validate it
                name = dns.name.from_text(sub)
                try:
                    dns.dnssec.validate(answer[0], answer[1],
                                        {name: answer[0]})
                except dns.dnssec.ValidationFailure:
                    return 0
        except Exception, e:
            return 0
Exemplo n.º 2
0
    def _send(self, parent, blob):
        def sender_thread():
            try:
                with self._audio_interface() as interface:
                    src = BytesIO(blob)
                    dst = interface.player()
                    amodem.send.main(config=self.modem_config,
                                     src=src,
                                     dst=dst)
            except Exception:
                traceback.print_exc()

        print_msg('Sending:', repr(blob))
        blob = zlib.compress(blob)

        kbps = self.modem_config.modem_bps / 1e3
        msg = 'Sending to Audio MODEM ({0:.1f} kbps)...'.format(kbps)
        return WaitingDialog(parent=parent,
                             message=msg,
                             run_task=sender_thread)
Exemplo n.º 3
0
    def resolve(self, url):
        '''Resolve OpenAlias address using url.'''
        print_msg('[OA] Attempting to resolve OpenAlias data for ' + url)

        prefix = 'btc'
        retries = 3
        err = None
        for i in range(0, retries):
            try:
                resolver = dns.resolver.Resolver()
                resolver.timeout = 2.0
                resolver.lifetime = 2.0
                records = resolver.query(url, dns.rdatatype.TXT)
                for record in records:
                    string = record.strings[0]
                    if string.startswith('oa1:' + prefix):
                        address = self.find_regex(
                            string, r'recipient_address=([A-Za-z0-9]+)')
                        name = self.find_regex(string,
                                               r'recipient_name=([^;]+)')
                        if not name:
                            name = address
                        if not address:
                            continue
                        return (address, name)
                QMessageBox.warning(self.win, _('Error'),
                                    _('No OpenAlias record found.'), _('OK'))
                return 0
            except dns.resolver.NXDOMAIN:
                err = _('No such domain.')
                continue
            except dns.resolver.Timeout:
                err = _('Timed out while resolving.')
                continue
            except DNSException:
                err = _('Unhandled exception.')
                continue
            except Exception, e:
                err = _('Unexpected error: ' + str(e))
                continue
            break
Exemplo n.º 4
0
 def on_success(blob):
     if blob:
         blob = zlib.decompress(blob)
         print_msg('Received:', repr(blob))
         parent.setText(blob)
Exemplo n.º 5
0
 def __init__(self, gui, name):
     print_msg('[OA] Initialiasing OpenAlias plugin, OA_READY is ' +
               str(OA_READY))
     BasePlugin.__init__(self, gui, name)
     self._is_available = OA_READY