Ejemplo n.º 1
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.º 2
0
    def __init__(self, *args, **kwargs):
        checkPortAvailable(kwargs['ha'])
        basedirpath = kwargs.get('basedirpath')
        keep = RoadKeep(basedirpath=basedirpath,
                        stackname=kwargs['name'],
                        auto=kwargs.get('auto'),
                        baseroledirpath=basedirpath)  # type: RoadKeep
        kwargs['keep'] = keep
        localRoleData = keep.loadLocalRoleData()

        sighex = kwargs.pop('sighex', None) or localRoleData['sighex']
        if not sighex:
            (sighex, _), (prihex, _) = getEd25519AndCurve25519Keys()
        else:
            prihex = ed25519SkToCurve25519(sighex, toHex=True)
        kwargs['sigkey'] = sighex
        kwargs['prikey'] = prihex
        self.msgHandler = kwargs.pop('msgHandler', None)  # type: Callable
        super().__init__(*args, **kwargs)
        if self.ha[1] != kwargs['ha'].port:
            error("the stack port number has changed, likely due to "
                  "information in the keep. {} passed {}, actual {}".format(
                      kwargs['name'], kwargs['ha'].port, self.ha[1]))
        self.created = time.perf_counter()
        self.coro = None
        config = getConfig()
        try:
            self.messageTimeout = config.RAETMessageTimeout
        except AttributeError:
            # if no timeout is set then message will never timeout
            self.messageTimeout = 0
Ejemplo n.º 3
0
def initRemoteKeep(name, remoteName, baseDir, pubkey, 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', pubkey),
        ('verhex', verkey)
    ])
    keep.dumpRemoteRoleData(data, role=remoteName)
Ejemplo n.º 4
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.º 5
0
def initLocalKeep(name, baseDir, pkseed, 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 not isinstance(pkseed, bytes):
        pkseed = pkseed.encode()
    if not isinstance(sigseed, bytes):
        sigseed = sigseed.encode()

    priver = Privateer(pkseed)
    signer = Signer(sigseed)
    keep = RoadKeep(stackname=name, baseroledirpath=baseDir)
    prikey, pubkey = priver.keyhex, priver.pubhex
    sigkey, verkey = signer.keyhex, signer.verhex
    data = OrderedDict([
        ("role", name),
        ("prihex", prikey),
        ("sighex", sigkey)
    ])
    keep.dumpLocalRoleData(data)
    return pubkey.decode(), verkey.decode()
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        checkPortAvailable(kwargs['ha'])
        basedirpath = kwargs.get('basedirpath')
        keep = RoadKeep(basedirpath=basedirpath,
                        stackname=kwargs['name'],
                        auto=kwargs.get('auto'),
                        baseroledirpath=basedirpath)  # type: RoadKeep
        kwargs['keep'] = keep
        localRoleData = keep.loadLocalRoleData()

        sighex = kwargs.pop('sighex', None) or localRoleData['sighex']
        if not sighex:
            (sighex, _), (prihex, _) = getEd25519AndCurve25519Keys()
        else:
            prihex = ed25519SkToCurve25519(sighex, toHex=True)
        kwargs['sigkey'] = sighex
        kwargs['prikey'] = prihex
        self.msgHandler = kwargs.pop('msgHandler', None)  # type: Callable
        super().__init__(*args, **kwargs)
        if self.ha[1] != kwargs['ha'].port:
            error("the stack port number has changed, likely due to "
                  "information in the keep. {} passed {}, actual {}".
                  format(kwargs['name'], kwargs['ha'].port, self.ha[1]))
        self.created = time.perf_counter()
        self.coro = None
        config = getConfig()
        try:
            self.messageTimeout = config.RAETMessageTimeout
        except AttributeError:
            # if no timeout is set then message will never timeout
            self.messageTimeout = 0
Ejemplo n.º 7
0
def clearAllRoadSafe(dirpath, opts):
    '''
    Convenience function to clear all road and safe keep data in dirpath
    '''
    road = RoadKeep(dirpath=dirpath)
    road.clearLocalData()
    road.clearAllRemoteData()
    safe = SaltSafe(opts=opts)
    safe.clearLocalData()
    safe.clearAllRemoteData()
Ejemplo n.º 8
0
def isLocalKeepSetup(name, baseDir=None) -> bool:
    """
    Check that the local RAET keep has the values of role, sighex and prihex
    populated for the given node

    :param name: the name of the node to check the keys for
    :param baseDir: base directory of Plenum
    :return: whether the keys are setup
    """
    keep = RoadKeep(stackname=name, baseroledirpath=baseDir)
    localRoleData = keep.loadLocalRoleData()
    return hasKeys(localRoleData, ['role', 'sighex', 'prihex'])
Ejemplo n.º 9
0
def isLocalKeepSetup(name, baseDir=None) -> bool:
    """
    Check that the local RAET keep has the values of role, sighex and prihex
    populated for the given node

    :param name: the name of the node to check the keys for
    :param baseDir: base directory of Plenum
    :return: whether the keys are setup
    """
    keep = RoadKeep(stackname=name, baseroledirpath=baseDir)
    localRoleData = keep.loadLocalRoleData()
    return hasKeys(localRoleData, ['role', 'sighex', 'prihex'])
Ejemplo n.º 10
0
 def __init__(self, *args, **kwargs):
     keep = RoadKeep(basedirpath=kwargs.get('basedirpath'),
              stackname=kwargs['name'],
              auto=kwargs.get('auto'),
              baseroledirpath=kwargs.get('basedirpath'))
     kwargs['keep'] = keep
     localRoleData = keep.loadLocalRoleData()
     kwargs['sigkey'] = localRoleData['sighex']
     kwargs['prikey'] = localRoleData['prihex']
     super().__init__(*args, **kwargs)
     self.created = time.perf_counter()
     self.coro = self._raetcoro()
     self.msgHandler = None  # type: Callable
Ejemplo n.º 11
0
def clearAllKeep(dirpath):
    '''
    Convenience function to clear all road keep data in dirpath
    '''
    road = RoadKeep(dirpath=dirpath)
    road.clearLocalData()
    road.clearAllRemoteData()
Ejemplo n.º 12
0
    def __init__(self, *args, **kwargs):
        checkPortAvailable(kwargs['ha'])
        basedirpath = kwargs.get('basedirpath')

        authMode = kwargs.pop('auth_mode', None)
        kwargs['auto'] = self._getAuto(authMode)

        keep = RoadKeep(basedirpath=basedirpath,
                        stackname=kwargs['name'],
                        auto=kwargs.get('auto'),
                        baseroledirpath=basedirpath)  # type: RoadKeep
        kwargs['keep'] = keep
        localRoleData = keep.loadLocalRoleData()

        sighex = kwargs.pop('sighex', None) or localRoleData['sighex']
        if not sighex:
            (sighex, _), (prihex, _) = getEd25519AndCurve25519Keys()
        else:
            prihex = ed25519SkToCurve25519(sighex, toHex=True)
        kwargs['sigkey'] = sighex
        kwargs['prikey'] = prihex

        self.msgHandler = kwargs.pop('msgHandler', None)  # type: Callable
        # if no timeout is set then message will never timeout
        self.messageTimeout = kwargs.pop('messageTimeout', 0)

        self.raetStack = RoadStack(*args, **kwargs)

        if self.ha[1] != kwargs['ha'].port:
            error("{}the stack port number has changed, likely due to "
                  "information in the keep. {} passed {}, actual {}".format(
                      CONNECTION_PREFIX, kwargs['name'], kwargs['ha'].port,
                      self.ha[1]))
        self._created = time.perf_counter()
        self.coro = None

        self._conns = set()  # type: Set[str]
Ejemplo n.º 13
0
def clearAllKeepSafe(dirpath, opts):
    '''
    Convenience function to clear all road and safe keep data in dirpath
    '''
    road = RoadKeep(dirpath=dirpath)
    road.clearLocalData()
    road.clearAllRemoteData()
    safe = SaltSafe(opts=opts)
    safe.clearLocalData()
    safe.clearAllRemoteData()
Ejemplo n.º 14
0
def getLocalKeep(name, baseDir=None):
    keep = RoadKeep(stackname=name, baseroledirpath=baseDir)
    localRoleData = keep.loadLocalRoleData()
    return localRoleData
Ejemplo n.º 15
0
def getLocalKeep(name, baseDir=None):
    keep = RoadKeep(stackname=name, baseroledirpath=baseDir)
    localRoleData = keep.loadLocalRoleData()
    return localRoleData