Esempio n. 1
0
    def connectNewRemote(self, txn, remoteName, nodeOrClientObj,
                         addRemote=True):
        # TODO: Need to handle abbreviated verkey
        verkey = cryptonymToHex(txn[TARGET_NYM])

        nodeHa = (txn[DATA][NODE_IP], txn[DATA][NODE_PORT])
        cliHa = (txn[DATA][CLIENT_IP], txn[DATA][CLIENT_PORT])

        if addRemote:
            try:
                # Override any keys found, reason being the scenario where
                # before this node comes to know about the other node, the other
                # node tries to connect to it.
                initRemoteKeys(self.name, remoteName, self.basedirpath,
                                   verkey, override=True)
            except Exception as ex:
                logger.error("Exception while initializing keep for remote {}".
                             format(ex))

        if self.isNode:
            nodeOrClientObj.nodeReg[remoteName] = HA(*nodeHa)
            nodeOrClientObj.cliNodeReg[remoteName + CLIENT_STACK_SUFFIX] = HA(*cliHa)
            logger.debug("{} adding new node {} with HA {}".format(self.name,
                                                                   remoteName,
                                                                   nodeHa))
        else:
            nodeOrClientObj.nodeReg[remoteName] = HA(*cliHa)
            logger.debug("{} adding new node {} with HA {}".format(self.name,
                                                                   remoteName,
                                                                   cliHa))
        nodeOrClientObj.nodestack.maintainConnections(force=True)
Esempio n. 2
0
def verifySig(identifier, signature, msg) -> bool:
    key = cryptonymToHex(identifier) if not isHex(identifier) else identifier
    ser = serializeForSig(msg)
    b64sig = signature.encode('utf-8')
    sig = b64decode(b64sig)
    vr = Verifier(key)
    return vr.verify(sig, ser)
def testNewNodeNotAddedIfHexKeyUsedInsteadOfBase58Key(be, do, poolNodesStarted,
                                                      trusteeCli,
                                                      newStewardCli,
                                                      nymAddedOut,
                                                      newNodeVals):
    # Verify that "send NODE" command fails if hex key is used
    # instead of base58 key
    be(newStewardCli)

    newNodeVals['newNodeIdr'] = cryptonymToHex(
        newNodeVals['newNodeIdr']).decode()

    do('send NODE dest={newNodeIdr} data={newNodeData}',
       within=8,
       expect=['Node request failed'],
       mapper=newNodeVals)

    # Verify that the pool is still operable
    be(trusteeCli)

    anotherNewNodeVals = getNewNodeVals()
    anotherNewNodeVals['remote'] = anotherNewNodeVals['newStewardIdr']
    anotherNewNodeVals['newStewardSeed'] = anotherNewNodeVals[
        'newStewardSeed'].decode()

    do('send NYM dest={{newStewardIdr}} role={role}'.format(
        role=Roles.STEWARD.name),
       within=3,
       expect=nymAddedOut,
       mapper=anotherNewNodeVals)
Esempio n. 4
0
    def connectNewRemote(self, txn_data, remoteName, nodeOrClientObj,
                         addRemote=True):
        # TODO: Need to handle abbreviated verkey
        verkey = cryptonymToHex(txn_data[TARGET_NYM])

        nodeHa = (txn_data[DATA][NODE_IP], txn_data[DATA][NODE_PORT])
        cliHa = (txn_data[DATA][CLIENT_IP], txn_data[DATA][CLIENT_PORT])

        if addRemote:
            try:
                # Override any keys found, reason being the scenario where
                # before this node comes to know about the other node, the other
                # node tries to connect to it.
                initRemoteKeys(self.name, remoteName, self.keys_dir, verkey, override=True)
            except Exception as ex:
                logger.error("Exception while initializing keep for remote {}".
                             format(ex))

        if self.isNode:
            nodeOrClientObj.nodeReg[remoteName] = HA(*nodeHa)
            nodeOrClientObj.cliNodeReg[remoteName +
                                       CLIENT_STACK_SUFFIX] = HA(*cliHa)
            logger.display("{} adding new node {} with HA {}".format(self.name, remoteName, nodeHa))
        else:
            nodeOrClientObj.nodeReg[remoteName] = HA(*cliHa)
            logger.display("{} adding new node {} with HA {}".format(self.name, remoteName, cliHa))
        nodeOrClientObj.nodestack.maintainConnections(force=True)
Esempio n. 5
0
    def _parse_pool_transaction_file(ledger,
                                     nodeReg,
                                     cliNodeReg,
                                     nodeKeys,
                                     activeValidators,
                                     ledger_size=None):
        """
        helper function for parseLedgerForHaAndKeys
        """
        for _, txn in ledger.getAllTxn(to=ledger_size):
            if get_type(txn) == NODE:
                txn_data = get_payload_data(txn)
                nodeName = txn_data[DATA][ALIAS]
                clientStackName = nodeName + CLIENT_STACK_SUFFIX
                nHa = (txn_data[DATA][NODE_IP], txn_data[DATA][NODE_PORT]) \
                    if (NODE_IP in txn_data[DATA] and NODE_PORT in txn_data[DATA]) \
                    else None
                cHa = (txn_data[DATA][CLIENT_IP], txn_data[DATA][CLIENT_PORT]) \
                    if (CLIENT_IP in txn_data[DATA] and CLIENT_PORT in txn_data[DATA]) \
                    else None
                if nHa:
                    nodeReg[nodeName] = HA(*nHa)
                if cHa:
                    cliNodeReg[clientStackName] = HA(*cHa)

                try:
                    # TODO: Need to handle abbreviated verkey
                    key_type = 'verkey'
                    verkey = cryptonymToHex(str(txn_data[TARGET_NYM]))
                    key_type = 'identifier'
                    cryptonymToHex(get_from(txn))
                except ValueError:
                    logger.exception(
                        'Invalid {}. Rebuild pool transactions.'.format(
                            key_type))
                    exit('Invalid {}. Rebuild pool transactions.'.format(
                        key_type))

                nodeKeys[nodeName] = verkey

                services = txn_data[DATA].get(SERVICES)
                if isinstance(services, list):
                    if VALIDATOR in services:
                        activeValidators.add(nodeName)
                    else:
                        activeValidators.discard(nodeName)
Esempio n. 6
0
def faberMap(faberMapWithoutEndpointPubkey):
    fbrMap = faberMapWithoutEndpointPubkey
    endpointAttr = json.loads(fbrMap["endpointAttr"])
    base58Key = '5hmMA64DDQz5NzGJNVtRzNwpkZxktNQds21q3Wxxa62z'
    hexKey = cryptonymToHex(base58Key).decode()
    endpointAttr[ENDPOINT][PUBKEY] = hexKey
    fbrMap["endpointAttr"] = json.dumps(endpointAttr)
    return fbrMap
def faberMap(faberMapWithoutEndpointPubkey):
    fbrMap = faberMapWithoutEndpointPubkey
    endpointAttr = json.loads(fbrMap["endpointAttr"])
    base58Key = '5hmMA64DDQz5NzGJNVtRzNwpkZxktNQds21q3Wxxa62z'
    hexKey = cryptonymToHex(base58Key).decode()
    endpointAttr[ENDPOINT][PUBKEY] = hexKey
    fbrMap["endpointAttr"] = json.dumps(endpointAttr)
    return fbrMap
def testSendNodeFailsIfDestIsHexKey(looper, sdk_pool_handle, nodeSet,
                                    sdk_node_theta_added, node_request):
    node_request['operation']['dest'] = cryptonymToHex(
        node_request['operation']['dest']).decode()
    steward_wallet, node = sdk_node_theta_added
    request_couple = sdk_sign_and_send_prepared_request(
        looper, steward_wallet, sdk_pool_handle, json.dumps(node_request))
    sdk_get_bad_response(looper, [request_couple], RequestNackedException,
                         'should not contain the following chars')
    ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
Esempio n. 9
0
    def stackKeysChanged(self, txn_data, remoteName, nodeOrClientObj):
        logger.debug("{} clearing remote role data in keep of {}".
                     format(nodeOrClientObj.nodestack.name, remoteName))
        logger.display("{} removing remote {}".format(nodeOrClientObj, remoteName))
        # Removing remote so that the nodestack will attempt to connect
        rid = self.removeRemote(nodeOrClientObj.nodestack, remoteName)

        if txn_data[VERKEY][0] == '~':  # abbreviated
            verkey = cryptonymToHex(
                txn_data[TARGET_NYM]) + cryptonymToHex(txn_data[VERKEY][1:])
        else:
            verkey = cryptonymToHex(txn_data[VERKEY])

        # Override any keys found
        initRemoteKeys(self.name, remoteName, self.keys_dir, verkey, override=True)

        # Attempt connection with the new keys
        nodeOrClientObj.nodestack.maintainConnections(force=True)
        return rid
Esempio n. 10
0
    def stackKeysChanged(self, txn, remoteName, nodeOrClientObj):
        logger.debug("{} clearing remote role data in keep of {}".
                     format(nodeOrClientObj.nodestack.name, remoteName))
        logger.debug(
            "{} removing remote {}".format(nodeOrClientObj, remoteName))
        # Removing remote so that the nodestack will attempt to connect
        rid = self.removeRemote(nodeOrClientObj.nodestack, remoteName)

        if txn[VERKEY][0] == '~':  # abbreviated
            verkey = cryptonymToHex(txn[TARGET_NYM]) + cryptonymToHex(txn[VERKEY][1:])
        else:
            verkey = cryptonymToHex(txn[VERKEY])

        # Override any keys found
        initRemoteKeys(self.name, remoteName, self.basedirpath,
                               verkey, override=True)

        # Attempt connection with the new keys
        nodeOrClientObj.nodestack.maintainConnections(force=True)
        return rid
Esempio n. 11
0
def testSendNodeFailsIfDestIsHexKey(
        be, do, poolNodesStarted, newStewardCli, newNodeVals):

    newNodeVals['newNodeIdr'] = cryptonymToHex(
        newNodeVals['newNodeIdr']).decode()

    be(newStewardCli)
    do('send NODE dest={newNodeIdr} data={newNodeData}',
       mapper=newNodeVals, expect=NODE_REQUEST_FAILED, within=8)

    ensurePoolIsOperable(be, do, newStewardCli)
def testSendNodeFailsIfDestIsHexKey(
        be, do, poolNodesStarted, newStewardCli, newNodeVals):

    newNodeVals['newNodeIdr'] = cryptonymToHex(
        newNodeVals['newNodeIdr']).decode()

    be(newStewardCli)
    do('send NODE dest={newNodeIdr} data={newNodeData}',
       mapper=newNodeVals, expect=NODE_REQUEST_FAILED, within=8)

    ensurePoolIsOperable(be, do, newStewardCli)
Esempio n. 13
0
    def _parse_pool_transaction_file(
            ledger, nodeReg, cliNodeReg, nodeKeys, activeValidators,
            ledger_size=None):
        """
        helper function for parseLedgerForHaAndKeys
        """
        for _, txn in ledger.getAllTxn(to=ledger_size):
            if get_type(txn) == NODE:
                txn_data = get_payload_data(txn)
                nodeName = txn_data[DATA][ALIAS]
                clientStackName = nodeName + CLIENT_STACK_SUFFIX
                nHa = (txn_data[DATA][NODE_IP], txn_data[DATA][NODE_PORT]) \
                    if (NODE_IP in txn_data[DATA] and NODE_PORT in txn_data[DATA]) \
                    else None
                cHa = (txn_data[DATA][CLIENT_IP], txn_data[DATA][CLIENT_PORT]) \
                    if (CLIENT_IP in txn_data[DATA] and CLIENT_PORT in txn_data[DATA]) \
                    else None
                if nHa:
                    nodeReg[nodeName] = HA(*nHa)
                if cHa:
                    cliNodeReg[clientStackName] = HA(*cHa)

                try:
                    # TODO: Need to handle abbreviated verkey
                    key_type = 'verkey'
                    verkey = cryptonymToHex(str(txn_data[TARGET_NYM]))
                    key_type = 'identifier'
                    cryptonymToHex(get_from(txn))
                except ValueError:
                    logger.exception(
                        'Invalid {}. Rebuild pool transactions.'.format(key_type))
                    exit('Invalid {}. Rebuild pool transactions.'.format(key_type))

                nodeKeys[nodeName] = verkey

                services = txn_data[DATA].get(SERVICES)
                if isinstance(services, list):
                    if VALIDATOR in services:
                        activeValidators.add(nodeName)
                    else:
                        activeValidators.discard(nodeName)
Esempio n. 14
0
    def parseLedgerForHaAndKeys(ledger, returnActive=True):
        """
        Returns validator ip, ports and keys
        :param ledger:
        :param returnActive: If returnActive is True, return only those
        validators which are not out of service
        :return:
        """
        nodeReg = OrderedDict()
        cliNodeReg = OrderedDict()
        nodeKeys = {}
        activeValidators = set()
        for _, txn in ledger.getAllTxn():
            if txn[TXN_TYPE] == NODE:
                nodeName = txn[DATA][ALIAS]
                clientStackName = nodeName + CLIENT_STACK_SUFFIX
                nHa = (txn[DATA][NODE_IP], txn[DATA][NODE_PORT]) \
                    if (NODE_IP in txn[DATA] and NODE_PORT in txn[DATA]) \
                    else None
                cHa = (txn[DATA][CLIENT_IP], txn[DATA][CLIENT_PORT]) \
                    if (CLIENT_IP in txn[DATA] and CLIENT_PORT in txn[DATA]) \
                    else None
                if nHa:
                    nodeReg[nodeName] = HA(*nHa)
                if cHa:
                    cliNodeReg[clientStackName] = HA(*cHa)

                try:
                    # TODO: Need to handle abbreviated verkey
                    verkey = cryptonymToHex(txn[TARGET_NYM])
                except ValueError as ex:
                    raise ValueError("Invalid verkey. Rebuild pool transactions.")

                nodeKeys[nodeName] = verkey

                services = txn[DATA].get(SERVICES)
                if isinstance(services, list):
                    if VALIDATOR in services:
                        activeValidators.add(nodeName)
                    else:
                        activeValidators.discard(nodeName)

        if returnActive:
            allNodes = tuple(nodeReg.keys())
            for nodeName in allNodes:
                if nodeName not in activeValidators:
                    nodeReg.pop(nodeName, None)
                    cliNodeReg.pop(nodeName + CLIENT_STACK_SUFFIX, None)
                    nodeKeys.pop(nodeName, None)

            return nodeReg, cliNodeReg, nodeKeys
        else:
            return nodeReg, cliNodeReg, nodeKeys, activeValidators
Esempio n. 15
0
    def _isVerified(self, msg: Dict[str, str]):
        signature = msg.get(f.SIG.nm)
        identifier = msg.get(IDENTIFIER)
        msgWithoutSig = {}
        for k, v in msg.items():
            if k != f.SIG.nm:
                msgWithoutSig[k] = v

        key = cryptonymToHex(
            identifier) if not isHex(identifier) else identifier
        isVerified = verifySig(key, signature, msgWithoutSig)
        if not isVerified:
            self.notifyObservers("Signature rejected")
        return isVerified