コード例 #1
0
ファイル: server.py プロジェクト: forrestv/undns
 def rpc_update(self, name, contents, ttl):
     ttl = float(ttl)
     name_hash = util.name_to_name_hash(name)
     if name_hash not in self.factory.node.domains:
         return "don't have key"
     self.factory.node.entries[name_hash] = (contents, ttl)
     self.factory.node.push(name_hash, contents, ttl)
コード例 #2
0
 def rpc_update(self, name, contents, ttl):
     ttl = float(ttl)
     name_hash = util.name_to_name_hash(name)
     if name_hash not in self.factory.node.domains:
         return "don't have key"
     self.factory.node.entries[name_hash] = (contents, ttl)
     self.factory.node.push(name_hash, contents, ttl)
コード例 #3
0
    def _lookup(self, name, cls, type, timeout):
        segs = name.split('.')

        print name, segs

        for i in reversed(xrange(len(segs))):
            seg = segs[i]
            try:
                nh = util.name_to_name_hash(seg)
            except ValueError:
                continue
            name2 = '.'.join(segs[i:])
            break
        else:
            raise dns.DomainError(name)

        print(nh, name2)

        result = yield self.dht.iterativeFindValue(nh)

        if isinstance(result, list):
            print result
            print 5
            raise dns.AuthoritativeDomainError(name)

        assert isinstance(result, dict), result
        print result
        pkt = packet.DomainPacket.from_binary(result[nh])

        if pkt.get_name_hash() != nh:
            print 6
            raise dns.AuthoritativeDomainError(name)
        record = pkt.get_record()
        if not self.dht.get_my_time() < record.get_end_time():
            print 7
            raise dns.AuthoritativeDomainError(name)
        if not pkt.verify_signature():
            print 8
            raise dns.AuthoritativeDomainError(name)

        zone = record.get_zone(name2)

        defer.returnValue((yield zone._lookup(name, cls, type, timeout)))
コード例 #4
0
ファイル: server.py プロジェクト: forrestv/undns
 def _lookup(self, name, cls, type, timeout):
     segs = name.split('.')
     
     print name, segs
     
     for i in reversed(xrange(len(segs))):
         seg = segs[i]
         try:
             nh = util.name_to_name_hash(seg)
         except ValueError:
             continue
         name2 = '.'.join(segs[i:])
         break
     else:
         raise dns.DomainError(name)
     
     print (nh, name2)
     
     result = yield self.dht.iterativeFindValue(nh)
     
     if isinstance(result, list):
         print result
         print 5
         raise dns.AuthoritativeDomainError(name)
     
     assert isinstance(result, dict), result
     print result
     pkt = packet.DomainPacket.from_binary(result[nh])
     
     if pkt.get_name_hash() != nh:
         print 6
         raise dns.AuthoritativeDomainError(name)
     record = pkt.get_record()
     if not self.dht.get_my_time() < record.get_end_time():
         print 7
         raise dns.AuthoritativeDomainError(name)
     if not pkt.verify_signature():
         print 8
         raise dns.AuthoritativeDomainError(name)
     
     zone = record.get_zone(name2)
     
     defer.returnValue((yield zone._lookup(name, cls, type, timeout)))
コード例 #5
0
 def rpc_drop(self, name):
     name_hash = util.name_to_name_hash(name)
     if name_hash in self.factory.node.entries:
         raise ValueError("disable domain first")  # XXX
     del self.factory.node.domains[name_hash]
コード例 #6
0
 def rpc_disable(self, name):
     name_hash = util.name_to_name_hash(name)
     del self.factory.node.entries[name_hash]
コード例 #7
0
 def rpc_get(self, name):
     name_hash = util.name_to_name_hash(name)
     return self.factory.node.entries[name_hash]
コード例 #8
0
ファイル: packet.py プロジェクト: forrestv/undns
        return json.dumps(
            dict(zone_file=self._zone_file, end_time=self._end_time))

    def get_zone_file(self):
        return self._zone_file

    def get_zone(self, address):
        assert not address.endswith('.')
        return BindStringAuthority(self._zone_file.encode('utf8'),
                                   address + '.')

    def get_end_time(self):
        return self._end_time

    def get_hash(self):
        b = self.to_binary()
        return util.ripemd160(b).digest() + hashlib.sha512(b).digest()


if __name__ == '__main__':
    from Crypto import Random
    rng = Random.new().read

    a = DomainKey.generate(rng)

    print a.get_name()
    print util.name_hash_to_name(a.get_name_hash())

    print util.name_to_name_hash(a.get_name()).encode('hex')
    print a.get_name_hash().encode('hex')
コード例 #9
0
ファイル: packet.py プロジェクト: forrestv/undns
        return (self._zone_file, self._end_time)
    
    def to_binary(self):
        return json.dumps(dict(zone_file=self._zone_file, end_time=self._end_time))
    
    def get_zone_file(self):
        return self._zone_file
    
    def get_zone(self, address):
        assert not address.endswith('.')
        return BindStringAuthority(self._zone_file.encode('utf8'), address + '.')
    
    def get_end_time(self):
        return self._end_time
    
    def get_hash(self):
        b = self.to_binary()
        return util.ripemd160(b).digest() + hashlib.sha512(b).digest()

if __name__ == '__main__':
    from Crypto import Random
    rng = Random.new().read
    
    a = DomainKey.generate(rng)
    
    print a.get_name()
    print util.name_hash_to_name(a.get_name_hash())
    
    print util.name_to_name_hash(a.get_name()).encode('hex')
    print a.get_name_hash().encode('hex')
コード例 #10
0
ファイル: server.py プロジェクト: forrestv/undns
 def rpc_drop(self, name):
     name_hash = util.name_to_name_hash(name)
     if name_hash in self.factory.node.entries:
         raise ValueError("disable domain first") # XXX
     del self.factory.node.domains[name_hash]
コード例 #11
0
ファイル: server.py プロジェクト: forrestv/undns
 def rpc_disable(self, name):
     name_hash = util.name_to_name_hash(name)
     del self.factory.node.entries[name_hash]
コード例 #12
0
ファイル: server.py プロジェクト: forrestv/undns
 def rpc_get(self, name):
     name_hash = util.name_to_name_hash(name)
     return self.factory.node.entries[name_hash]