Beispiel #1
0
    def _updateLinkWithLatestInfo(self, link: Link, reply):

        if DATA in reply and reply[DATA]:
            data = json.loads(reply[DATA])
            ip, port = data.get(ENDPOINT).split(":")
            link.remoteEndPoint = (ip, int(port))

        link.linkLastSynced = datetime.now()
        self.notifyMsgListener("    Link {} synced".format(link.name))
Beispiel #2
0
 def loadInvitationFile(self, filePath):
     with open(filePath) as data_file:
         invitationData = json.load(
             data_file, object_pairs_hook=collections.OrderedDict)
         linkInvitation = invitationData.get("link-invitation")
         if not linkInvitation:
             raise LinkNotFound
         linkName = linkInvitation["name"]
         existingLinkInvites = self.wallet. \
             getMatchingLinks(linkName)
         if len(existingLinkInvites) >= 1:
             return self._mergeInvitaion(invitationData)
         Link.validate(invitationData)
         link = self.loadInvitation(invitationData)
         return link
Beispiel #3
0
    def loadInvitation(self, invitationData):
        linkInvitation = invitationData["link-invitation"]
        remoteIdentifier = linkInvitation[f.IDENTIFIER.nm]
        signature = invitationData["sig"]
        linkInvitationName = linkInvitation[NAME]
        remoteEndPoint = linkInvitation.get("endpoint", None)
        linkNonce = linkInvitation[NONCE]
        claimProofRequestsJson = invitationData.get("claim-requests", None)

        claimProofRequests = []
        if claimProofRequestsJson:
            for cr in claimProofRequestsJson:
                claimProofRequests.append(
                    ClaimProofRequest(cr[NAME], cr[VERSION], cr[ATTRIBUTES],
                                      cr[VERIFIABLE_ATTRIBUTES]))

        self.notifyMsgListener("1 link invitation found for {}.".
                               format(linkInvitationName))

        self.notifyMsgListener("Creating Link for {}.".
                               format(linkInvitationName))
        self.notifyMsgListener("Generating Identifier and Signing key.")
        # TODO: Would we always have a trust anchor corresponding ot a link?

        li = Link(name=linkInvitationName,
                  trustAnchor=linkInvitationName,
                  remoteIdentifier=remoteIdentifier,
                  remoteEndPoint=remoteEndPoint,
                  invitationNonce=linkNonce,
                  claimProofRequests=claimProofRequests)

        self.wallet.addLink(li)
        return li
Beispiel #4
0
 def linkFromNonce(self, nonce, remoteIdr, remoteHa):
     internalId = self.getInternalIdByInvitedNonce(nonce)
     link = self.wallet.getLinkByInternalId(internalId)
     if not link:
         # QUESTION: We use wallet.defaultId as the local identifier,
         # this looks ok for test code, but not production code
         link = Link(str(internalId),
                     self.wallet.defaultId,
                     invitationNonce=nonce,
                     remoteIdentifier=remoteIdr,
                     remoteEndPoint=remoteHa,
                     internalId=internalId)
         self.wallet.addLink(link)
     else:
         link.remoteIdentifier = remoteIdr
         link.remoteEndPoint = remoteHa
     return link
Beispiel #5
0
def acmeLinkAdded(acmeIsRunning):
    acme, wallet = acmeIsRunning
    idr = wallet.defaultId
    link = Link("Acme", idr, nonce="57fbf9dc8c8e6acde33de98c6d747b28c")
    # TODO rename to addLink
    wallet.addLinkInvitation(link)
    assert wallet.getMatchingLinkInvitations("Acme")
    return link
Beispiel #6
0
def faberLinkAdded(faberIsRunning):
    faber, wallet = faberIsRunning
    idr = wallet.defaultId
    link = Link("Alice", idr, nonce="b1134a647eb818069c089e7694f63e6d")
    # TODO rename to addLink
    wallet.addLinkInvitation(link)
    assert wallet.getMatchingLinkInvitations("Alice")
    return link
Beispiel #7
0
 def addLinksToWallet(self):
     wallet = self.wallet
     idr = wallet.defaultId
     for nonce, data in self._attributes.items():
         link = Link(data.get("employee_name"), idr, nonce=nonce)
         wallet.addLinkInvitation(link)
Beispiel #8
0
 def addLink(self, link: Link):
     self._links[link.key()] = link
Beispiel #9
0
def testLoadLinkInviteWithoutSig():
    li = getSampleLinkInvitation()
    del li["sig"]
    with pytest.raises(InvalidLinkException) as excinfo:
        Link.validate(li)
    assert "Field not found in given input: sig" in str(excinfo.value)