def prefetch(uid, path):
    accounts = wf.cached_data(
        'dropbox_accounts', data_func=get_account_info, max_age=60 * 60)
    if path is None or uid is None or not uid_exists(uid, accounts):
        return 0
    path_content = wf.cached_data(get_hash(uid, path))
    if path_content is None:
        return 0
    for resource in path_content:
        if resource['is_dir']:
            cache_resource(uid, resource['path'])
Esempio n. 2
0
def prefetch(uid, path):
    accounts = wf.cached_data('dropbox_accounts',
                              data_func=get_account_info,
                              max_age=60 * 60)
    if path is None or uid is None or not uid_exists(uid, accounts):
        return 0
    path_content = wf.cached_data(get_hash(uid, path))
    if path_content is None:
        return 0
    for resource in path_content:
        if resource['is_dir']:
            cache_resource(uid, resource['path'])
Esempio n. 3
0
    def on_post(self, req, resp):
        # Get the username
        body = helpers.get_json(req)
        username = helpers.get_username(body)

        user_hash = redis_db.get(username)
        if not user_hash:
            user_hash = helpers.get_hash()
            redis_db.setex(username, HASH_LIFESPAN_MINS * 60, user_hash)

        resp.status = falcon.HTTP_OK
        resp.body = json.dumps({'hash': user_hash})
Esempio n. 4
0
def get_file_or_folder(uid, query):
    path = '/' if query == '' else query

    if len(path) > 1 and path[-1] == '/':
        path = path[:-1]

    prefetch(wf, uid, path)

    def wrapper():
        return get_resource(uid, path)

    return wf.cached_data(get_hash(uid, path), wrapper, max_age=120)
Esempio n. 5
0
def cache_resource(uid, path):
    def wrapper():
        return get_resource(uid, path)

    wf.cached_data(get_hash(uid, path), wrapper)
Esempio n. 6
0
def main():
    """
    Part-1: Payment Request Generation
    """
    print("-------------------------------------------------------")
    print("---PAYMENT REQUEST GENERATION---")
    cust_privkey, cust_pubkey = rsakeys()
    bank_privkey, bank_pubkey = rsakeys()

    print("Customer's private key-", cust_privkey)
    print("Customer's public key-", cust_pubkey)
    print("Bank's private key-", bank_privkey)
    print("Bank's public key-", bank_pubkey)

    payment_info = 'Some payment information'
    order_info = 'Some order information'

    PIMD = get_hash(payment_info)
    OIMD = get_hash(order_info)
    POMD = get_hash(PIMD + OIMD)

    dual_sign = sign(cust_privkey, POMD)

    key_s = aeskey()
    encrypted_pi, iv_pi = aesencrypt(payment_info, key_s)
    encrypted_oimd, iv_oimd = aesencrypt(OIMD, key_s)
    encrypted_ds, iv_ds = aesencrypt(dual_sign, key_s)

    digital_envelope = encrypt(bank_pubkey, key_s)
    """
    Part 2: Purchase Request Validation from 
    Merchant side
    """

    merchant_oimd = get_hash(order_info)
    merchant_pomd = get_hash(PIMD + merchant_oimd)

    check_sign_merchant = verify(cust_pubkey, merchant_pomd, dual_sign)

    if check_sign_merchant:
        print("-------------------------------------------------------")
        print("[INFO] Merchant Signatures match")
        print("\tPurchase request validated by merchant")
        print("\t---PURCHASE REQUEST VALIDATED---")
        print("-------------------------------------------------------")
    else:
        print("-------------------------------------------------------")
        print("[INFO] Signatures do not match")
        print("\tPurchace request rejected- Signatures do not match!!")
        return
    """
    Part 3: Payment authorization
    """
    bank_key_s = decrypt(bank_privkey, digital_envelope)

    bank_pi = aesdecrypt(encrypted_pi, bank_key_s, iv_pi).decode()
    bank_oimd = aesdecrypt(encrypted_oimd, bank_key_s, iv_oimd).decode()
    bank_ds = aesdecrypt(encrypted_ds, bank_key_s, iv_ds)

    bank_pimd = get_hash(bank_pi)
    bank_pomd = get_hash(bank_pimd + bank_oimd)

    check_sign_bank = verify(cust_pubkey, bank_pomd, dual_sign)

    if check_sign_bank:
        print("[INFO] Bank Signatures match")
        print("\tPayment authorized by the bank")
        print("\t---PAYMENT AUTHORIZATION SUCCESSFUL---")
        print("-------------------------------------------------------")
        print("\t---PAYMENT CAPTURE SUCCESSFUL---")
        print("-------------------------------------------------------")
    else:
        print("[INFO] Signatures do not match")
        print("\tPayment authorization failed- Signatures do not match!!")
Esempio n. 7
0
def prefetch(wf, uid, path):
    job_name = 'dropbox_prefetch_%s' % get_hash(uid, path)
    cmd = ['/usr/bin/python', wf.workflowfile('dropbox_prefetch.py'), uid, path]
    run_in_background(job_name, cmd)
def cache_resource(uid, path):
    def wrapper():
        return get_resource(uid, path)

    wf.cached_data(get_hash(uid, path), wrapper)