2 # This example demonstrates how to access an existing Path ORAM
3 # storage space through an SSH client using the Secure File Transfer
4 # Protocol (SFTP). This file should not be executed until the
5 # path_oram_sftp_setup.py example has been executed. The user is
6 # encouraged to tweak the settings for 'cached_levels',
7 # 'concurrency_level', and 'threadpool_size' to observe their effect
10 # In order to run this example, you must provide a host
11 # (server) address along with valid login credentials
18 import multiprocessing
21 from pyoram.util.misc import MemorySize, load_private_key
22 from pyoram.oblivious_storage.tree.path_oram import \
28 pyoram.config.SHOW_PROGRESS_BAR = True
30 # Set SSH login credentials here
31 # (by default, we pull these from the environment
32 # for testing purposes)
33 ssh_host = os.environ.get('PYORAM_SSH_TEST_HOST')
34 ssh_username = os.environ.get('PYORAM_SSH_TEST_USERNAME')
35 ssh_password = os.environ.get('PYORAM_SSH_TEST_PASSWORD')
37 # Set the storage location and size
38 storage_name = "heap.bin"
42 print("Loading key from file: %s.key"
44 key = load_private_key(storage_name+".key")
45 print("Loading stash from file: %s.stash"
47 with open(storage_name+".stash", 'rb') as fstash:
48 stash = pickle.load(fstash)
49 print("Loading position map from file: %s.position"
51 with open(storage_name+".position", 'rb') as fpos:
52 position_map = pickle.load(fpos)
54 # Start an SSH client using paramiko
55 print("Starting SSH Client")
56 with paramiko.SSHClient() as ssh:
57 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
58 ssh.load_system_host_keys()
60 username=ssh_username,
61 password=ssh_password)
63 with PathORAM(storage_name,
70 threadpool_size=multiprocessing.cpu_count()*2,
76 start_time = time.time()
77 for t in tqdm.tqdm(list(range(test_count)),
78 desc="Running I/O Performance Test"):
79 f.read_block(random.randint(0,f.block_count-1))
80 stop_time = time.time()
81 print("Current Stash Size: %s"
83 print("Fetch Block Avg. Latency: %.2f ms"
84 % ((stop_time-start_time)/float(test_count)*1000))
89 print("Saving stash to file: %s.stash"
91 with open(storage_name+".stash", 'wb') as fstash:
92 pickle.dump(f.stash, fstash)
93 print("Saving position map to file: %s.position"
95 with open(storage_name+".position", 'wb') as fpos:
96 pickle.dump(f.position_map, fpos)
98 if __name__ == "__main__":
99 main() # pragma: no cover