예제 #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)
예제 #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