Пример #1
0
def parse_ipkey(s = ""):
        """
        ip:hexkey
        ip:uz5+base32key
        ip:base32key
        """

        s = s.split('\n')[0]

        ss = s.split('|')
        if len(ss) != 2:
                raise ValueError("string must be in format ip:key")
        ip  = ss[0]
        key = ss[1].lower()
        keylen = len(key)
        check.ip(ip)

        if keylen == 64:
                #hex
                check.hexkey(key)
                return (ip.strip(), "uz5%s" % (base32.encode(fromhex(key))[:51]))
        elif keylen == 54:
                #uz5 + base32
                if key[0:3] != "uz5":
                        raise ValueError("first 3 characters must be nym uz5")
                rkey = tohex(base32.decode("%s0" % key[3:]))
                check.hexkey(rkey)
                return (ip.strip(), "uz5%s" % (base32.encode(fromhex(rkey))[:51]))
        elif keylen == 51:
                #base32
                rkey = tohex(base32.decode("%s0" % key))
                check.hexkey(rkey)
                return (ip.strip(), "uz5%s" % (base32.encode(fromhex(rkey))[:51]))
        else:
                raise ValueError("key must must have length 64bytes in hex, 51 in base32 or 54 in base32 + nym uz5")
Пример #2
0
def dnscurve_encode_queryname(nonce, box, pubkey, zone):
  if len(nonce) != 12:
    raise ValueError('Invalid nonce')
  if len(pubkey) != 32 or ord(pubkey[31]) >= 128:
    raise ValueError('Invalid public key')

  data = base32.encode(nonce + box)
  output = chunk(data, 50)
  output.append('x1a' + base32.encode(pubkey)[:51])
  output.extend(zone)

  return output
Пример #3
0
def dnscurve_encode_queryname(nonce, box, pubkey, zone):
    if len(nonce) != 12:
        raise ValueError('Invalid nonce')
    if len(pubkey) != 32 or ord(pubkey[31]) >= 128:
        raise ValueError('Invalid public key')

    data = base32.encode(nonce + box)
    output = chunk(data, 50)
    output.append('x1a' + base32.encode(pubkey)[:51])
    output.extend(zone)

    return output
Пример #4
0
def _encode(hex_addr: str, netid: int) -> str:
    if not hex_addr:
        raise Exception("Invalid argument")

    buf = _address_buffer_from_hex(hex_addr)
    chain_prefix = _encode_netid(netid)
    payload = base32.encode(_encode_payload(buf))
    checksum = _create_checksum(chain_prefix, payload)
    return chain_prefix + DELIMITER + payload + checksum
Пример #5
0
 def hash(self):
     mt = self.mtime
     self.scan()
     if self.mtime != mt:
         f = self.fileobj
         print "hashing", self.fname
         # FIXME: aegis!  tiger.treehash segfaults on my scene release copy of SGU s02e14
         # WONTFIX: this must be a system specific error, probably memory related
         self.__hash = base32.encode(tiger.treehash(f))
     return self.__hash
Пример #6
0
    def __init__(self, configFile):
        self.config = config = SafeConfigParser()
        config.read(configFile)
        host = config.get('server', 'host')
        port = config.getint('server', 'port')

        pid = tiger.hash(uuid.uuid1().hex).replace('\x00', '\x01')
        self.pid = base32.encode(pid)
        self.cid = base32.encode(tiger.hash(pid))
        self.inf = {
            'ID': self.cid,
            'PD': self.pid,
            'SF': 0,  # number of shared files
            'SS': 1,  # size of shared files in bytes
            'NI': 'daemon',  # nickname
            'VE': 'pyadc 0.1',  # client version
            'US': 0,  # maximum upload speed, bytes/second
            # 'DS': 0, # maximum download speed, bytes/second
            'FS': 0,  # number of free upload slots
            'SL': 0,  # maximum number of open slots
            'HN': 0,  # number of hubs where user is normal
            'HR': 0,  # number of hubs where user is registered and normal
            'HO': 0,  # number of hubs where user is op and normal
            'SU':
            'TCP4',  # list of capabilities # 'UDP4' is for UDP, 'ADC0' is for ADCS
            'U4': 0,  # udp ipv4 port
        }

        self.conn = Connection(host, port)
        self.clients = {}
        self.info = {}

        self.connections = []

        self.logged_in = False

        self.handleMap = {
            'B': self.handleBroadcast,
            'I': self.handleInfo,
            'F': self.handleFeature,
            'D': self.handleDirect,
        }
Пример #7
0
	def __init__(self, configFile):
		self.config = config = SafeConfigParser()
		config.read(configFile)
		host = config.get('server', 'host')
		port = config.getint('server', 'port')

		pid = tiger.hash(uuid.uuid1().hex).replace('\x00', '\x01')
		self.pid = base32.encode(pid)
		self.cid = base32.encode(tiger.hash(pid))
		self.inf = {
			'ID': self.cid,
			'PD': self.pid,
			'SF': 0, # number of shared files
			'SS': 1, # size of shared files in bytes
			'NI': 'daemon', # nickname
			'VE': 'pyadc 0.1', # client version
			'US': 0, # maximum upload speed, bytes/second
			# 'DS': 0, # maximum download speed, bytes/second
			'FS': 0, # number of free upload slots
			'SL': 0, # maximum number of open slots
			'HN': 0, # number of hubs where user is normal
			'HR': 0, # number of hubs where user is registered and normal
			'HO': 0, # number of hubs where user is op and normal
			'SU': 'TCP4', # list of capabilities # 'UDP4' is for UDP, 'ADC0' is for ADCS
			'U4': 0, # udp ipv4 port
		}

		self.conn = Connection(host, port)
		self.clients = {}
		self.info = {}

		self.connections = []

		self.logged_in = False

		self.handleMap = {
			'B':self.handleBroadcast,
			'I':self.handleInfo,
			'F':self.handleFeature,
			'D':self.handleDirect,
		}
Пример #8
0
def _create_checksum(chain_prefix: str, payload: str) -> str:
    prefix_buf = _prefix_to_word(chain_prefix)
    delimiter_buf = bytes(1)
    payload_buf = base32.decode_words(payload)
    n = _poly_mod(prefix_buf + delimiter_buf + payload_buf + CHECKSUM_TEMPLATE)
    return base32.encode(_checksum_bytes(n))