コード例 #1
0
ファイル: lib.py プロジェクト: stribika/curveprotect
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
ファイル: dnscurve.py プロジェクト: stribika/curveprotect
def dnscurve_decode_queryname(name):
  output = []

  for s in name:
    if len(s) > 50: break
    output.append(s)

  if len(s) != 54 or s[:3].lower() != 'x1a':
    raise ValueError('Not a DNSCurve query (1)')

  key = base32.decode(s[3:] + '0')
  r = base32.decode(''.join(output))
  if r < 12: raise ValueError('Not a DNSCurve query (2)')

  return (key, r[:12], r[12:])
コード例 #3
0
def dnscurve_decode_queryname(name):
    output = []

    for s in name:
        if len(s) > 50: break
        output.append(s)

    if len(s) != 54 or s[:3].lower() != 'x1a':
        raise ValueError('Not a DNSCurve query')

    key = base32.decode(s[3:] + '0')
    r = base32.decode(''.join(output))
    if r < 8: raise ValueError('Not a DNSCurve query')

    return (key, r[:8], r[8:])
コード例 #4
0
ファイル: dnscurve.py プロジェクト: stribika/curveprotect
def dnscurve_getpubkey(name):
  for s in name:
    if len(s) == 54 and s[:3].lower() == 'uz5':
      try:
        return base32.decode(s[3:] + '0')
      except ValueError, e:
        pass
コード例 #5
0
def dnscurve_getpubkey(name):
    for s in name:
        if len(s) == 54 and s[:3].lower() == 'uz5':
            try:
                return base32.decode(s[3:] + '0')
            except ValueError, e:
                pass
コード例 #6
0
def decode(cfx_addr: str) -> str:
    if not cfx_addr and not _have_chain_prefix(cfx_addr):
        raise Exception("Invalid argument")

    cfx_addr = cfx_addr.lower()
    parts = cfx_addr.split(DELIMITER)
    if len(parts) < 2:
        raise Exception("Address should have at least two part")

    chain_prefix = parts[0]
    payload_with_checksum = parts[-1]
    if not base32.is_valid(payload_with_checksum):
        raise Exception("Input contain invalid base32 chars")

    if len(payload_with_checksum) != CFX_ADDRESS_CHAR_LENGTH:
        raise Exception("Address payload should have 42 chars")

    payload, checksum = (
        payload_with_checksum[:-CHECKSUM_LEN],
        payload_with_checksum[CFX_ADDRESS_CHAR_LENGTH - CHECKSUM_LEN :],
    )
    if checksum != _create_checksum(chain_prefix, payload):
        raise Exception("Invalid checksum")

    raw = base32.decode(payload)
    hex_addr = HEX_PREFIX + b16encode(raw).decode()[HEX_PREFIX_LEN:]
    return hex_addr.lower()
コード例 #7
0
ファイル: dns.py プロジェクト: stribika/curveprotect
def _getcurvecpkey(name = ""):
        """
        """

	flagkey = False
	key = None

        for n in name.split("."):
		if flagkey == True:
			if len(n) != 32:
				flagkey = False
				key = None
			else:
                                try:
                                        key = lib.tohex(lib.fromhex(key))
                                except:
                                        flagkey = False
                                        key = None
                                else:
				        return (key, n)
                if len(n) != 54:
			flagkey = False
                        continue
                if n[0:3] != "uz7":
			flagkey = False
                        continue
                nn = "%s0" % (n[3:])
                try:
                        key = lib.tohex(base32.decode(nn))
                except:
			flagkey = False
		else:
			flagkey = True
        return ("", "")
コード例 #8
0
ファイル: lib.py プロジェクト: stribika/curveprotect
def parse_key(key = ""):
        """
        """

        keylen = len(key)

        if keylen == 64:
                #hex
                check.hexkey(key)
                return fromhex(key)
        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 fromhex(rkey)
        elif keylen == 51:
                #base32
                rkey = tohex(base32.decode("%s0" % key))
                check.hexkey(rkey)
                return fromhex(rkey)
コード例 #9
0
ファイル: dns.py プロジェクト: stribika/curveprotect
def _getdnskey(name = ""):
        """
        """

        for n in name.split("."):
                if len(n) != 54:
                        continue
                if n[0:3] != "uz5":
                        continue
                nn = "%s0" % (n[3:])
                try:
                        return lib.tohex(base32.decode(nn))
                except:
                        pass
        return ""