예제 #1
0
	def _importKeyFromFile(self, filename):
		'''Load the specified file and import the contents to the current keyring.
		   This works for text files containing either a public key or a private key.'''
		key = ""
		with open(os.path.join("inputdata", filename + ".txt"), "r") as f:
			for l in f:
				key += l
		return CryptoClient.importPublicKey(key)
예제 #2
0
    def handleReceiveAccept(torId, name, keyStr):
        '''We have requested contact with another id, and this has now been accepted.
		So we can import their public key into our keyring and update their status
		from "requested" to "untrusted"'''
        # Use keyStr to update keyring and get the keyId
        keyId = CryptoClient.importPublicKey(keyStr)
        # Store the keyId and name in their existing row, and update status to "untrusted"
        DbI.updateProfile(torId, {
            "name": name,
            "status": "untrusted",
            "keyid": keyId
        })
예제 #3
0
    def handleAccept(torId):
        '''We want to accept a contact request, so we need to find the request(s),
		and use it/them to update our keyring and our database entry'''

        # Get this person's current status from the db, if available
        profile = DbI.getProfile(torId)
        status = profile.get("status", None) if profile else None

        # Look for the contact request(s) in the inbox, and extract the name and publicKey
        senderName, senderKeystr, directRequest = ContactMaker.getContactRequestDetails(
            torId)
        keyValid = senderKeystr and len(senderKeystr) > 20

        if keyValid:
            if status in [None, "requested"]:
                # add key to keyring
                keyId = CryptoClient.importPublicKey(senderKeystr)
                # work out what name and status to stores
                storedSenderName = profile["name"] if profile else None
                nameToStore = storedSenderName if storedSenderName else senderName
                statusToStore = "untrusted" if directRequest else "pending"
                # add or update the profile
                DbI.updateProfile(
                    torId, {
                        "status": statusToStore,
                        "keyid": keyId,
                        "name": nameToStore,
                        "displayName": nameToStore
                    })
                ContactMaker.processPendingContacts(torId)
            elif status == "pending":
                print("Request already pending, nothing to do")
            elif status in ["untrusted", "trusted"]:
                # set status to untrusted?  Send response?
                print("Trying to handle an accept but status is already",
                      status)
            # Move all corresponding requests to be regular messages instead
            DbI.changeRequestMessagesToRegular(torId)
        else:
            print("Trying to handle an accept but key isn't valid")