Ejemplo n.º 1
0
def ui_share():
    if not client_conn.is_login():
        print("Please login first")
        return
    # Enter recipient username
    print("Invite people (username): ", end='')
    recipient = input().strip()
    # Recipient's email
    recv_email = None
    print("Recipient's email address: ", end='')
    recv_email = input().strip()

    # Get target's public key
    choice = None
    while choice != "1" and choice != "2":
        print("Obtain the recipent's public key:")
        print(" 1) Download from Hong Kong Post")
        print(" 2) Input from file (debug)")
        print("Choice [1,2]: ", end='')
        choice = input().strip()
    public_key = None
    try:
        if choice == "1":
            # Download from HK Post
            public_key = rsa.get_cert(recv_email, True)
            sender = "*****@*****.**"
        if choice == "2":
            # Import from file
            sender = "*****@*****.**"
            filename = "key/public_key.pem"
            public_key = rsa.load_public_cert_from_file(filename)
    except Exception as e:
        log.print_exception(e)
        log.print_error("error", "failed to load cert")
        return 

    # Get user's private key to signoff
    if os.path.isfile("/home/star/.ssh/me.key.pem2"):
        private_key = rsa.load_private_cert_from_file("/home/star/.ssh/me.key.pem2")
    else:
        private_key = rsa.load_private_cert_from_file("key/private_key.pem")

    # Encrypt the filelist record
    print("File to share: ", end='')
    filename = input()
    record = filelist.export_record(filename, sender, recv_email, public_key, private_key)
    if record == None:
        print("Failed to share file")
        return
    # Send to server
    client_conn.share(recipient, record)
Ejemplo n.º 2
0
def get_share():
    """
    Upload the file to server.
    """
    url = base_url+"listshare"
    data = {
        'token': token,
    }
    data = {"token": token}
    try:
        r = requests.get(url, params=data, verify=cert)
    except Exception as e:
        log.print_exception(e)
        log.print_error("error", "connection failure")
        return False
    # Parse result
    try:
        response = json.loads(r.text)
        print(response)
    except Exception as e:
        log.print_exception(e)
        log.print_error("authentication failure", "failed to decode server message '%s'" % (r.text))
        return False
    if not response.get("status"):
        return False
    if response["records"] == None:
        return False
    for i in response["records"]:
        sender = i['Sender']
        record = i['Record']
        print("Sender:",sender)
        print("Record:",record)
        try:
            if os.path.isfile("/home/star/.ssh/me.key.pem2"):
                public_key = rsa.get_cert("*****@*****.**")
            else:
                public_key = rsa.load_public_cert_from_file("key/public_key.pem")
            if os.path.isfile("/home/star/.ssh/me.key.pem2"):
                private_key = rsa.load_private_cert_from_file("/home/star/.ssh/me.key.pem2")
            else:
                private_key = rsa.load_private_cert_from_file("key/private_key.pem")
            share = filelist.import_record(record, public_key, private_key)
            print(share)
            if share != None:
                filelist.append_share(share['filename_ori'], share['filename_rand'],
                            share['key'], share['iv'], share['tag'], sender)
        except:
            print("Failed to decrypt message")
            pass
Ejemplo n.º 3
0
    """
    Decrypt the data in form of [IV,TAG,CIPHER].

    Raise exception when failed to decrypt file.
    """
    key = pyscrypt.hash(password = user_password.encode(encoding='UTF-8'), salt = salt.encode(encoding='UTF-8'), N = 1024, r = 1, p = 1, dkLen = 32)
    ret = encrypt.decrypt(key, iv, tag, data)
    return ret

if __name__ == "__main__":
    '''
    For testing
    '''
    append("ori1", "rand1", "key1", "iv1", "tag1")
    append("ori2", "rand2", "key2", "iv2", "tag2")
    save("Password1", "salt1")
    load("Password1", "salt1")
    print(mylist)

    # Test sharing record
    public_key = rsa.get_cert("*****@*****.**")
    if os.path.isfile("/home/star/.ssh/me.key.pem2"):
        private_key = rsa.load_private_cert_from_file("/home/star/.ssh/me.key.pem2")
    else:
        private_key = rsa.load_private_cert_from_file("key/private_key.pem")
    append("file1", "file-UUID", b'key', b'iv', b'tag')
    print(mylist)
    record = export_record("file1", "alice", "bob", public_key, private_key)
    print("record:", record)
    import_record(record, public_key, private_key)