Exemplo n.º 1
0
def add_and_sign(signersNum=10):
    beforeSignTimeBasedId = getTimeBasedId()
    wallet = Wallet("shared wallet")
    idrs = []
    for i in range(signersNum):
        identifier = "signer_{}".format(i)
        idrs.append(identifier)
        wallet.addIdentifier(identifier)
    for idr in idrs:
        signed = wallet.signOp(op={}, identifier=idr)
        afterSignTimeBasedId = getTimeBasedId()
        assert beforeSignTimeBasedId < signed.reqId < afterSignTimeBasedId
Exemplo n.º 2
0
def add_and_sign(signersNum = 10):
    beforeSignTimeBasedId = getTimeBasedId()
    wallet = Wallet("shared wallet")
    idrs = []
    for i in range(signersNum):
        identifier = "signer_{}".format(i)
        idrs.append(identifier)
        wallet.addIdentifier(identifier)
    for idr in idrs:
        signed = wallet.signOp(op={}, identifier=idr)
        afterSignTimeBasedId = getTimeBasedId()
        assert beforeSignTimeBasedId < signed.reqId < afterSignTimeBasedId
Exemplo n.º 3
0
def testSendGetTxnReqSameAsExpected(looper, steward1, stewardWallet):
    req, wallet = sendAddNewClient(STEWARD, "name", steward1, stewardWallet)

    timeout = waits.expectedTransactionExecutionTime(len(
        steward1.inBox)) + c_delay
    nym_response = looper.run(
        eventually(checkSufficientRepliesReceived,
                   steward1.inBox,
                   req.reqId,
                   fValue,
                   retryWait=1,
                   timeout=timeout))

    op = {TXN_TYPE: GET_TXN, DATA: nym_response['seqNo']}
    req = Request(identifier=stewardWallet.defaultId,
                  operation=op,
                  reqId=getTimeBasedId())
    steward1.submitReqs(req)

    get_txn_response = looper.run(
        eventually(checkSufficientRepliesReceived,
                   steward1.inBox,
                   req.reqId,
                   fValue,
                   retryWait=1,
                   timeout=timeout))
    get_txn_response = json.loads(get_txn_response[DATA])

    del nym_response['txnTime']
    del get_txn_response['txnTime']

    assert nym_response == get_txn_response
Exemplo n.º 4
0
    def signAndSend(self, msg, signingIdr=None, toRaetStackName=None,
                    linkName=None, origReqId=None):
        if linkName:
            assert not (signingIdr or toRaetStackName)
            self.connectTo(linkName)
            link = self.wallet.getLink(linkName, required=True)
            ha = link.getRemoteEndpoint(required=True)

            # TODO ensure status is appropriate with code like the following
            # if link.linkStatus != constant.LINK_STATUS_ACCEPTED:
            #     raise LinkNotReady('link status is {}'.format(link.linkStatus))

            if not link.localIdentifier:
                raise LinkNotReady('local identifier not set up yet')
            signingIdr = link.localIdentifier
            params = dict(ha=ha)
        else:
            params = dict(name=toRaetStackName)
        # origReqId needs to be supplied when you want to respond to request
        # so that on receiving end, response can be matched with request
        # if origReqId:
        #     msg[f.REQ_ID.nm] = origReqId
        # else:
        #     msg[f.REQ_ID.nm] = getTimeBasedId()
        msg[f.REQ_ID.nm] = getTimeBasedId()
        if origReqId:
            msg[REF_REQUEST_ID] = origReqId

        msg[IDENTIFIER] = signingIdr
        signature = self.wallet.signMsg(msg, signingIdr)
        msg[f.SIG.nm] = signature
        self.sendMessage(msg, **params)
        return msg[f.REQ_ID.nm]
Exemplo n.º 5
0
def testSendGetTxnReqSameAsExpected(looper, steward1, stewardWallet):
    req, wallet = sendAddNewClient(STEWARD, "name", steward1, stewardWallet)

    timeout = waits.expectedTransactionExecutionTime(
        len(steward1.inBox)) + c_delay
    nym_response = \
        looper.run(eventually(check_sufficient_replies_received,
                              steward1, req.identifier, req.reqId,
                              retryWait=1, timeout=timeout))
    op = {
        TXN_TYPE: GET_TXN,
        DATA: nym_response['seqNo']
    }
    req = Request(identifier=stewardWallet.defaultId,
                  operation=op, reqId=getTimeBasedId(),
                  protocolVersion=CURRENT_PROTOCOL_VERSION)
    steward1.submitReqs(req)

    get_txn_response = \
        looper.run(eventually(check_sufficient_replies_received,
                              steward1, req.identifier, req.reqId,
                              retryWait=1, timeout=timeout))

    nym_response.pop('txnTime', None)
    get_txn_response[DATA].pop('txnTime', None)

    assert nym_response == get_txn_response[DATA]
Exemplo n.º 6
0
    def signAndSend(self, msg, signingIdr, name=None, ha=None, origReqId=None):
        msg[f.REQ_ID.nm] = getTimeBasedId()
        if origReqId:
            msg[REF_REQUEST_ID] = origReqId
        msg[IDENTIFIER] = signingIdr
        signature = self.wallet.signMsg(msg, signingIdr)
        msg[f.SIG.nm] = signature

        self.sendMessage(msg, name=name, ha=ha)

        return msg[f.REQ_ID.nm]
Exemplo n.º 7
0
    def signAndSend(self, msg, signingIdr, name=None, ha=None, origReqId=None):
        msg[f.REQ_ID.nm] = getTimeBasedId()
        if origReqId:
            msg[REF_REQUEST_ID] = origReqId

        msg[IDENTIFIER] = signingIdr
        signature = self.wallet.signMsg(msg, signingIdr)
        msg[f.SIG.nm] = signature

        self.sendMessage(msg, name=name, ha=ha)

        return msg[f.REQ_ID.nm]
Exemplo n.º 8
0
    def read_wrapped(txn_type):
        op = {TXN_TYPE: txn_type, f.LEDGER_ID.nm: DOMAIN_LEDGER_ID, DATA: 1}
        req = Request(identifier=did,
                      operation=op,
                      reqId=getTimeBasedId(),
                      protocolVersion=CURRENT_PROTOCOL_VERSION)
        sdk_get_and_check_replies(looper, [
            sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                        sdk_wallet_client, req)
        ])

        return node._info_tool.info
Exemplo n.º 9
0
    def read_wrapped(txn_type):
        op = {
            TXN_TYPE: txn_type,
            f.LEDGER_ID.nm: DOMAIN_LEDGER_ID,
            DATA: 1
        }
        req = Request(identifier=did,
                      operation=op, reqId=getTimeBasedId(),
                      protocolVersion=CURRENT_PROTOCOL_VERSION)
        sdk_get_and_check_replies(looper, [sdk_sign_and_submit_req_obj(
            looper, sdk_pool_handle, sdk_wallet_client, req)])

        return node._info_tool.info
Exemplo n.º 10
0
    def sendPing(self, linkName):
        link = self.wallet.getConnection(linkName, required=True)
        self.connectTo(link=link)
        ha = link.getRemoteEndpoint(required=True)
        params = dict(ha=ha)
        msg = {
            TYPE: 'ping',
            NONCE: link.request_nonce,
            f.REQ_ID.nm: getTimeBasedId(),
            f.IDENTIFIER.nm: link.localIdentifier
        }
        reqId = self.sendMessage(msg, **params)

        self.notifyMsgListener("    Ping sent.")
        return reqId
Exemplo n.º 11
0
    def sendPing(self, linkName):
        link = self.wallet.getConnection(linkName, required=True)
        self.connectTo(link=link)
        ha = link.getRemoteEndpoint(required=True)
        params = dict(ha=ha)
        msg = {
            TYPE: 'ping',
            NONCE: link.request_nonce,
            f.REQ_ID.nm: getTimeBasedId(),
            f.IDENTIFIER.nm: link.localIdentifier
        }
        reqId = self.sendMessage(msg, **params)

        self.notifyMsgListener("    Ping sent.")
        return reqId
Exemplo n.º 12
0
def testLinkNotFoundErrorResponse(be, do, aliceCli, faberMap,
                                  faberInviteSyncedWithoutEndpoint):
    msg = {
        f.REQ_ID.nm: getTimeBasedId(),
        TYPE: ACCEPT_INVITE,
        IDENTIFIER: aliceCli.activeWallet.defaultId,
        NONCE: "unknown"
    }
    signature = aliceCli.activeWallet.signMsg(msg,
                                              aliceCli.activeWallet.defaultId)
    msg[f.SIG.nm] = signature
    link = aliceCli.activeWallet.getLink(faberMap['inviter'], required=True)
    aliceCli.sendToAgent(msg, link)

    be(aliceCli)
    do(None, within=3, expect=["Nonce not found".format(msg)])
Exemplo n.º 13
0
    def signAndSend(self,
                    msg,
                    signingIdr=None,
                    toRaetStackName=None,
                    linkName=None,
                    origReqId=None):
        if linkName:
            assert not (signingIdr or toRaetStackName)
            link = self.wallet.getLink(linkName, required=True)
            if not link.localIdentifier:
                raise LinkNotReady('link is not yet established, '
                                   'send/accept invitation first')
            signingIdr = link.localIdentifier

            try:
                self.connectTo(link=link)
                ha = link.getRemoteEndpoint(required=True)
                params = dict(ha=ha)
            except RemoteEndpointNotFound as ex:
                logger.debug('ZStack remote found')
                if not (isinstance(self.endpoint, ZEndpoint) and self.endpoint.
                        hasRemote(link.remotePubKey.encode() if isinstance(
                            link.remotePubKey, str) else link.remotePubKey)):
                    fault(ex,
                          "Do not know {} {}".format(link.remotePubKey, ha))
                    return
            # TODO ensure status is appropriate with code like the following
            # if link.linkStatus != constant.LINK_STATUS_ACCEPTED:
            # raise LinkNotReady('link status is {}'.format(link.linkStatus))
                params = dict(name=link.remotePubKey)
        else:
            params = dict(name=toRaetStackName)
        # origReqId needs to be supplied when you want to respond to request
        # so that on receiving end, response can be matched with request
        # if origReqId:
        #     msg[f.REQ_ID.nm] = origReqId
        # else:
        #     msg[f.REQ_ID.nm] = getTimeBasedId()
        msg[f.REQ_ID.nm] = getTimeBasedId()
        if origReqId:
            msg[REF_REQUEST_ID] = origReqId

        msg[IDENTIFIER] = signingIdr
        signature = self.wallet.signMsg(msg, signingIdr)
        msg[f.SIG.nm] = signature
        self.sendMessage(msg, **params)
        return msg[f.REQ_ID.nm]
Exemplo n.º 14
0
    def notifyResponseFromMsg(self, linkName, reqId=None):
        if reqId:
            # TODO: This logic assumes that the req id is time based
            curTimeBasedId = getTimeBasedId()
            timeTakenInMillis = convertTimeBasedReqIdToMillis(curTimeBasedId -
                                                              reqId)

            if timeTakenInMillis >= 1000:
                responseTime = ' ({} sec)'.format(
                    round(timeTakenInMillis / 1000, 2))
            else:
                responseTime = ' ({} ms)'.format(round(timeTakenInMillis, 2))
        else:
            responseTime = ''

        self.notifyMsgListener("\nResponse from {}{}:".format(
            linkName, responseTime))
Exemplo n.º 15
0
    def notifyResponseFromMsg(self, linkName, reqId=None):
        if reqId:
            # TODO: This logic assumes that the req id is time based
            curTimeBasedId = getTimeBasedId()
            timeTakenInMillis = convertTimeBasedReqIdToMillis(
                curTimeBasedId - reqId)

            if timeTakenInMillis >= 1000:
                responseTime = ' ({} sec)'.format(
                    round(timeTakenInMillis / 1000, 2))
            else:
                responseTime = ' ({} ms)'.format(round(timeTakenInMillis, 2))
        else:
            responseTime = ''

        self.notifyMsgListener("\nResponse from {}{}:".format(linkName,
                                                              responseTime))
Exemplo n.º 16
0
    def read_wrapped(txn_type):
        op = {TXN_TYPE: txn_type, DATA: 1}
        req = Request(identifier=wallet.defaultId,
                      operation=op,
                      reqId=getTimeBasedId())
        client.submitReqs(req)

        timeout = waits.expectedTransactionExecutionTime(len(client.inBox))
        txnPoolNodesLooper.run(
            eventually(checkSufficientRepliesReceived,
                       client.inBox,
                       req.reqId,
                       1,
                       retryWait=1,
                       timeout=timeout))
        txnPoolNodesLooper.runFor(patched_dump_info_period)
        return load_info(info_path)
Exemplo n.º 17
0
def testSendGetTxnReqForNotExistsSeqNo(looper, steward1, stewardWallet):
    op = {TXN_TYPE: GET_TXN, DATA: randint(100, 1000)}
    req = Request(identifier=stewardWallet.defaultId,
                  operation=op,
                  reqId=getTimeBasedId())
    steward1.submitReqs(req)

    timeout = waits.expectedTransactionExecutionTime(len(
        steward1.inBox)) + c_delay
    get_txn_response = looper.run(
        eventually(checkSufficientRepliesReceived,
                   steward1.inBox,
                   req.reqId,
                   fValue,
                   retryWait=1,
                   timeout=timeout))

    assert not get_txn_response[DATA]
Exemplo n.º 18
0
    def read_wrapped(txn_type):
        op = {TXN_TYPE: txn_type, f.LEDGER_ID.nm: DOMAIN_LEDGER_ID, DATA: 1}
        req = Request(identifier=wallet.defaultId,
                      operation=op,
                      reqId=getTimeBasedId(),
                      protocolVersion=CURRENT_PROTOCOL_VERSION)
        client.submitReqs(req)

        timeout = waits.expectedTransactionExecutionTime(len(client.inBox))

        txnPoolNodesLooper.run(
            eventually(check_sufficient_replies_received,
                       client,
                       req.identifier,
                       req.reqId,
                       retryWait=1,
                       timeout=timeout))
        return node._info_tool.info
Exemplo n.º 19
0
def testSendGetTxnReqForExistsSeqNo(looper, steward1, stewardWallet):
    op = {
        TXN_TYPE: GET_TXN,
        DATA: 1
    }
    req = Request(identifier=stewardWallet.defaultId,
                  operation=op, reqId=getTimeBasedId(),
                  protocolVersion=CURRENT_PROTOCOL_VERSION)
    steward1.submitReqs(req)

    timeout = waits.expectedTransactionExecutionTime(
        len(steward1.inBox)) + c_delay
    get_txn_response = \
        looper.run(eventually(check_sufficient_replies_received,
                              steward1, req.identifier, req.reqId,
                              retryWait=1, timeout=timeout))

    assert get_txn_response[DATA]
Exemplo n.º 20
0
    def signRequest(self,
                    req: Request,
                    identifier: Identifier = None) -> Request:
        """
        Signs request. Modifies reqId and signature. May modify identifier.

        :param req: request
        :param requestIdStore: request id generator
        :param identifier: signer identifier
        :return: signed request
        """

        idr = self.requiredIdr(idr=identifier or req.identifier)
        idData = self._getIdData(idr)
        req.identifier = idr
        req.reqId = getTimeBasedId()
        self.ids[idr] = IdData(idData.signer, req.reqId)
        req.signature = self.signMsg(msg=req.getSigningState(),
                                     identifier=idr,
                                     otherIdentifier=req.identifier)

        return req
Exemplo n.º 21
0
 def gen_req_id():
     return getTimeBasedId()
Exemplo n.º 22
0
 def gen_req_id():
     return getTimeBasedId()