Beispiel #1
0
    def _updateLinkWithLatestInfo(self, link: Connection, reply):
        if DATA in reply and reply[DATA]:
            data = json.loads(reply[DATA])

            verkey = data.get(VERKEY)
            if verkey is not None:
                link.remoteVerkey = data[VERKEY]

            ep = data.get(ENDPOINT)
            if isinstance(ep, dict):
                # TODO: Validate its an IP port pair or a malicious entity
                # can crash the code
                if 'ha' in ep:
                    ip, port = ep['ha'].split(":")
                    link.remoteEndPoint = (ip, int(port))
                if PUBKEY in ep:
                    link.remotePubkey = ep[PUBKEY]
                else:
                    link.remotePubkey = friendlyVerkeyToPubkey(
                        link.full_remote_verkey
                    ) if link.full_remote_verkey else None

            link.connection_last_synced = datetime.now()
            self.notifyMsgListener("    Connection {} synced".format(
                link.name))
Beispiel #2
0
 def load_request_dict(self, request_dict):
     link_request = request_dict.get("connection-request")
     if not link_request:
         raise ConnectionNotFound
     linkName = link_request["name"]
     existingLinkInvites = self.wallet. \
         getMatchingConnections(linkName)
     if len(existingLinkInvites) >= 1:
         return self._merge_request(request_dict)
     Connection.validate(request_dict)
     link = self.load_request(request_dict)
     return link
Beispiel #3
0
 def load_request_dict(self, request_dict):
     link_request = request_dict.get("connection-request")
     if not link_request:
         raise ConnectionNotFound
     linkName = link_request["name"]
     existingLinkInvites = self.wallet. \
         getMatchingConnections(linkName)
     if len(existingLinkInvites) >= 1:
         return self._merge_request(request_dict)
     Connection.validate(request_dict)
     link = self.load_request(request_dict)
     return link
Beispiel #4
0
 def load_request_file(self, filePath):
     with open(filePath) as data_file:
         request_data = json.load(data_file,
                                  object_pairs_hook=collections.OrderedDict)
         link_request = request_data.get("connection-request")
         if not link_request:
             raise ConnectionNotFound
         linkName = link_request["name"]
         existingLinkInvites = self.wallet. \
             getMatchingConnections(linkName)
         if len(existingLinkInvites) >= 1:
             return self._merge_request(request_data)
         Connection.validate(request_data)
         link = self.load_request(request_data)
         return link
Beispiel #5
0
 def load_request_file(self, filePath):
     with open(filePath) as data_file:
         request_data = json.load(
             data_file, object_pairs_hook=collections.OrderedDict)
         link_request = request_data.get("connection-request")
         if not link_request:
             raise ConnectionNotFound
         linkName = link_request["name"]
         existingLinkInvites = self.wallet. \
             getMatchingConnections(linkName)
         if len(existingLinkInvites) >= 1:
             return self._merge_request(request_data)
         Connection.validate(request_data)
         link = self.load_request(request_data)
         return link
Beispiel #6
0
 def linkFromNonce(self, nonce, remoteIdr, remoteHa=None,
                   remotePubkey=None):
     internalId = self.get_internal_id_by_nonce(nonce)
     linkName = self.get_link_name_by_internal_id(internalId)
     link = self.wallet.getConnectionBy(internalId=internalId)
     if not link:
         # QUESTION: We use wallet.defaultId as the local identifier,
         # this looks ok for test code, but not production code
         link = Connection(linkName,
                           self.wallet.defaultId,
                           self.wallet.getVerkey(),
                           request_nonce=nonce,
                           remoteIdentifier=remoteIdr,
                           remoteEndPoint=remoteHa,
                           internalId=internalId,
                           remotePubkey=remotePubkey)
         self.wallet.addConnection(link)
     else:
         link.remoteIdentifier = remoteIdr
         link.remoteEndPoint = remoteHa
     return link
Beispiel #7
0
 def linkFromNonce(self,
                   nonce,
                   remoteIdr,
                   remoteHa=None,
                   remotePubkey=None):
     internalId = self.get_internal_id_by_nonce(nonce)
     linkName = self.get_link_name_by_internal_id(internalId)
     link = self.wallet.getConnectionBy(internalId=internalId)
     if not link:
         # QUESTION: We use wallet.defaultId as the local identifier,
         # this looks ok for test code, but not production code
         link = Connection(linkName,
                           self.wallet.defaultId,
                           self.wallet.getVerkey(),
                           request_nonce=nonce,
                           remoteIdentifier=remoteIdr,
                           remoteEndPoint=remoteHa,
                           internalId=internalId,
                           remotePubkey=remotePubkey)
         self.wallet.addConnection(link)
     else:
         link.remoteIdentifier = remoteIdr
         link.remoteEndPoint = remoteHa
     return link
Beispiel #8
0
    def _updateLinkWithLatestInfo(self, link: Connection, reply):
        if DATA in reply and reply[DATA]:
            data = json.loads(reply[DATA])

            verkey = data.get(VERKEY)
            if verkey is not None:
                link.remoteVerkey = data[VERKEY]

            ep = data.get(ENDPOINT)
            if isinstance(ep, dict):
                # TODO: Validate its an IP port pair or a malicious entity
                # can crash the code
                if 'ha' in ep:
                    ip, port = ep['ha'].split(":")
                    link.remoteEndPoint = (ip, int(port))
                if PUBKEY in ep:
                    link.remotePubkey = ep[PUBKEY]
                else:
                    link.remotePubkey = friendlyVerkeyToPubkey(
                        link.full_remote_verkey) if link.full_remote_verkey else None

            link.connection_last_synced = datetime.now()
            self.notifyMsgListener(
                "    Connection {} synced".format(link.name))
Beispiel #9
0
    def load_request(self, request_data):
        link_request = request_data["connection-request"]
        remoteIdentifier = link_request[f.IDENTIFIER.nm]
        # TODO signature should be validated!
        # signature = request_data["sig"]
        link_request_name = link_request[NAME]
        remoteEndPoint = link_request.get("endpoint", None)
        remote_verkey = link_request.get("verkey", None)
        linkNonce = link_request[NONCE]
        proofRequestsJson = request_data.get("proof-requests", None)

        proofRequests = []
        if proofRequestsJson:
            for cr in proofRequestsJson:
                proofRequests.append(
                    ProofRequest(
                        cr[NAME], cr[VERSION], getNonceForProof(linkNonce),
                        cr[ATTRIBUTES], cr[VERIFIABLE_ATTRIBUTES]
                        if VERIFIABLE_ATTRIBUTES in cr else [],
                        cr[PREDICATES] if PREDICATES in cr else []))

        self.notifyMsgListener(
            "1 connection request found for {}.".format(link_request_name))

        self.notifyMsgListener(
            "Creating connection for {}.".format(link_request_name))
        # TODO: Would we always have a trust anchor corresponding to a link?

        li = Connection(name=link_request_name,
                        trustAnchor=link_request_name,
                        remoteIdentifier=remoteIdentifier,
                        remoteEndPoint=remoteEndPoint,
                        request_nonce=linkNonce,
                        proofRequests=proofRequests,
                        remote_verkey=remote_verkey)

        self.wallet.addConnection(li)
        return li
Beispiel #10
0
def testLoadConnectionInviteWithoutSig():
    li = getSampleConnectionInvitation()
    del li["sig"]
    with pytest.raises(InvalidConnectionException) as excinfo:
        Connection.validate(li)
    assert "Field not found in given input: sig" in str(excinfo.value)
Beispiel #11
0
def test_link_has_requested_proofs():
    testLink = Connection("Test")
Beispiel #12
0
def testLoadConnectionInviteWithoutSig():
    li = getSampleConnectionInvitation()
    del li["sig"]
    with pytest.raises(InvalidConnectionException) as excinfo:
        Connection.validate(li)
    assert "Field not found in given input: sig" in str(excinfo.value)