Ejemplo n.º 1
0
def testNodesConnectedUsingConvertedKeys(txnPoolNodeSet):
    for node in txnPoolNodeSet:
        secretKey = ed25519SkToCurve25519(node.nodestack.keyhex)
        publicKey = ed25519PkToCurve25519(node.nodestack.verhex)
        assert unhexlify(node.nodestack.prihex) == secretKey
        assert unhexlify(node.nodestack.pubhex) == publicKey

        secretKey = ed25519SkToCurve25519(node.clientstack.keyhex)
        publicKey = ed25519PkToCurve25519(node.clientstack.verhex)
        assert unhexlify(node.clientstack.prihex) == secretKey
        assert unhexlify(node.clientstack.pubhex) == publicKey
def keysAndNames():
    alphaSigner = Signer()
    betaSigner = Signer()
    alphaPrikey = ed25519SkToCurve25519(alphaSigner.keyraw)
    betaPrikey = ed25519SkToCurve25519(betaSigner.keyraw)
    alphaPubkey = ed25519PkToCurve25519(alphaSigner.verraw)
    betaPubkey = ed25519PkToCurve25519(betaSigner.verraw)
    alphaName = 'alpha'
    betaName = 'beta'
    return alphaSigner.keyhex, alphaPrikey, alphaSigner.verhex, alphaPubkey, \
        alphaName, betaSigner.keyhex, betaPrikey, betaSigner.verhex, \
        betaPubkey, betaName
Ejemplo n.º 3
0
def testKeyConversionFromEd25519ToCurve25519():
    signer = Signer()
    sk = signer.keyraw
    vk = signer.verraw
    # Check when keys are passed as raw bytes
    secretKey = ed25519SkToCurve25519(sk)
    publicKey = ed25519PkToCurve25519(vk)
    assert PrivateKey(secretKey).public_key.__bytes__() == publicKey
    assert ed25519PkToCurve25519(vk, toHex=True) == \
           hexlify(PrivateKey(secretKey).public_key.__bytes__())

    # Check when keys are passed as hex
    secretKey = ed25519SkToCurve25519(hexlify(sk))
    publicKey = ed25519PkToCurve25519(hexlify(vk))
    assert PrivateKey(secretKey).public_key.__bytes__() == publicKey
Ejemplo n.º 4
0
def testKeyConversionFromEd25519ToCurve25519():
    signer = Signer()
    sk = signer.keyraw
    vk = signer.verraw
    # Check when keys are passed as raw bytes
    secretKey = ed25519SkToCurve25519(sk)
    publicKey = ed25519PkToCurve25519(vk)
    assert PrivateKey(secretKey).public_key.__bytes__() == publicKey
    assert ed25519PkToCurve25519(vk, toHex=True) == \
           hexlify(PrivateKey(secretKey).public_key.__bytes__())

    # Check when keys are passed as hex
    secretKey = ed25519SkToCurve25519(hexlify(sk))
    publicKey = ed25519PkToCurve25519(hexlify(vk))
    assert PrivateKey(secretKey).public_key.__bytes__() == publicKey
Ejemplo n.º 5
0
    def initRemoteKeys(name, remoteName, baseDir, verkey, override=False):
        """
        Initialize RAET remote keep

        :param name: name of the node
        :param remoteName: name of the remote to store keys for
        :param baseDir: base directory
        :param pubkey: public key of the remote
        :param verkey: private key of the remote
        :param override: overwrite the role.remoteName.json file if it already
        exists.
        """
        rolePath = os.path.join(baseDir, name, "role", "remote",
                                "role.{}.json".format(remoteName))
        if os.path.isfile(rolePath):
            if not override:
                raise FileExistsError(
                    "Keys exists for remote role {}".format(remoteName))

        keep = RoadKeep(stackname=name, baseroledirpath=baseDir)
        data = OrderedDict([('role', remoteName), ('acceptance', 1),
                            ('pubhex', ed25519PkToCurve25519(verkey,
                                                             toHex=True)),
                            ('verhex', verkey)])
        keep.dumpRemoteRoleData(data, role=remoteName)
Ejemplo n.º 6
0
    def initLocalKeys(name, baseDir, sigseed, override=False):
        """
        Initialize RAET local keep. Write local role data to file.

        :param name: name of the node
        :param baseDir: base directory
        :param pkseed: seed to generate public and private key pair
        :param sigseed: seed to generate signing and verification key pair
        :param override: overwrite the local role.json file if already exists
        :return: tuple(public key, verification key)
        """
        rolePath = os.path.join(baseDir, name, "role", "local", "role.json")
        if os.path.isfile(rolePath):
            if not override:
                raise FileExistsError(
                    "Keys exists for local role {}".format(name))

        if sigseed and not isinstance(sigseed, bytes):
            sigseed = sigseed.encode()

        signer = Signer(sigseed)
        keep = RoadKeep(stackname=name, baseroledirpath=baseDir)
        sigkey, verkey = signer.keyhex, signer.verhex
        prikey, pubkey = ed25519SkToCurve25519(sigkey, toHex=True), \
                         ed25519PkToCurve25519(verkey, toHex=True)
        data = OrderedDict([("role", name), ("prihex", prikey),
                            ("sighex", sigkey)])
        keep.dumpLocalRoleData(data)
        return pubkey.decode(), verkey.decode()
Ejemplo n.º 7
0
    def initRemoteKeys(name, remoteName, baseDir, verkey, override=False):
        homeDir = ZStack.homeDirPath(baseDir, name)
        verifDirPath = ZStack.verifDirPath(homeDir)
        pubDirPath = ZStack.publicDirPath(homeDir)
        for d in (homeDir, verifDirPath, pubDirPath):
            os.makedirs(d, exist_ok=True)

        if isHex(verkey):
            verkey = unhexlify(verkey)

        createCertsFromKeys(verifDirPath, remoteName, z85.encode(verkey))
        public_key = ed25519PkToCurve25519(verkey)
        createCertsFromKeys(pubDirPath, remoteName, z85.encode(public_key))
Ejemplo n.º 8
0
    def initRemoteKeys(name, remoteName, baseDir, verkey, override=False):
        homeDir = ZStack.homeDirPath(baseDir, name)
        verifDirPath = ZStack.verifDirPath(homeDir)
        pubDirPath = ZStack.publicDirPath(homeDir)
        for d in (homeDir, verifDirPath, pubDirPath):
            os.makedirs(d, exist_ok=True)

        if isHex(verkey):
            verkey = unhexlify(verkey)

        createCertsFromKeys(verifDirPath, remoteName, z85.encode(verkey))
        public_key = ed25519PkToCurve25519(verkey)
        createCertsFromKeys(pubDirPath, remoteName, z85.encode(public_key))
Ejemplo n.º 9
0
def friendlyVerkeyToPubkey(verkey):
    vkRaw = friendlyToRaw(verkey)
    pkraw = ed25519PkToCurve25519(vkRaw)
    return rawToFriendly(pkraw)
Ejemplo n.º 10
0
def rawVerkeyToPubkey(raw_verkey):
    return ed25519PkToCurve25519(raw_verkey)
Ejemplo n.º 11
0
def friendlyVerkeyToPubkey(verkey):
    vkRaw = friendlyToRaw(verkey)
    pkraw = ed25519PkToCurve25519(vkRaw)
    return rawToFriendly(pkraw)
Ejemplo n.º 12
0
def rawVerkeyToPubkey(raw_verkey):
    return ed25519PkToCurve25519(raw_verkey)
Ejemplo n.º 13
0
def testClientConnectedUsingConvertedKeys(nodeSet, up, client1, replied1):
    secretKey = ed25519SkToCurve25519(client1.nodestack.keyhex)
    publicKey = ed25519PkToCurve25519(client1.nodestack.verhex)
    assert unhexlify(client1.nodestack.prihex) == secretKey
    assert unhexlify(client1.nodestack.pubhex) == publicKey