Example #1
0
 def push(self, name_hash, zone_file, ttl):
     print "publishing", util.name_hash_to_name(name_hash)
     try:
         key = self.domains[name_hash]
     except KeyError:
         print "MISSING KEY FOR", util.name_hash_to_name(name_hash)
         return
     t = self.get_my_time()
     record = packet.DomainRecord(zone_file, int(math.ceil(t + ttl + 5)))
     pkt = key.encode(record, self.rng)
     assert pkt.get_name_hash() == name_hash
     return self.iterativeStore(name_hash, pkt.to_binary())
Example #2
0
 def push(self, name_hash, zone_file, ttl):
     print "publishing", util.name_hash_to_name(name_hash)
     try:
         key = self.domains[name_hash]
     except KeyError:
         print "MISSING KEY FOR", util.name_hash_to_name(name_hash)
         return
     t = self.get_my_time()
     record = packet.DomainRecord(zone_file, int(math.ceil(t + ttl + 5)))
     pkt = key.encode(record, self.rng)
     assert pkt.get_name_hash() == name_hash
     return self.iterativeStore(name_hash, pkt.to_binary())
Example #3
0
 def store(self, key, value, originalPublisherID=None, age=0, **kwargs):
     print "store", str((util.name_hash_to_name(key), value, originalPublisherID, age, kwargs))
     # XXX maybe prefer current
     
     pkt = packet.DomainPacket.from_binary(value)
     if pkt.get_name_hash() != key:
         raise ValueError("invalid name hash")
     record = pkt.get_record()
     if not self.get_my_time() < record.get_end_time():
         raise ValueError("invalid time range")
     if not pkt.verify_signature():
         raise ValueError("invalid signature")
     record.get_zone(pkt.get_name())
     
     return node.Node.store(self, key, value, originalPublisherID, age, **kwargs)
Example #4
0
    def store(self, key, value, originalPublisherID=None, age=0, **kwargs):
        print "store", str((util.name_hash_to_name(key), value,
                            originalPublisherID, age, kwargs))
        # XXX maybe prefer current

        pkt = packet.DomainPacket.from_binary(value)
        if pkt.get_name_hash() != key:
            raise ValueError("invalid name hash")
        record = pkt.get_record()
        if not self.get_my_time() < record.get_end_time():
            raise ValueError("invalid time range")
        if not pkt.verify_signature():
            raise ValueError("invalid signature")
        record.get_zone(pkt.get_name())

        return node.Node.store(self, key, value, originalPublisherID, age,
                               **kwargs)
Example #5
0
        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')
Example #6
0
        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')