2 # This example demonstrates how to setup an instance of Path ORAM
3 # locally and then transfer the storage to a server using a paramiko
4 # SSHClient. After executing this file, path_oram_sftp_test.py can be
5 # executed to run simple I/O performance tests using different caching
8 # In order to run this example, you must provide a host
9 # (server) address along with valid login credentials
18 from pyoram.util.misc import MemorySize, save_private_key
19 from pyoram.oblivious_storage.tree.path_oram import \
25 pyoram.config.SHOW_PROGRESS_BAR = True
27 # Set SSH login credentials here
28 # (by default, we pull these from the environment
29 # for testing purposes)
30 ssh_host = os.environ.get('PYORAM_SSH_TEST_HOST')
31 ssh_username = os.environ.get('PYORAM_SSH_TEST_USERNAME')
32 ssh_password = os.environ.get('PYORAM_SSH_TEST_PASSWORD')
34 # Set the storage location and size
35 storage_name = "heap.bin"
38 # one block per bucket in the
39 # storage heap of height 8
40 block_count = 2**(8+1)-1
44 print("Storage Name: %s" % (storage_name))
45 print("Block Count: %s" % (block_count))
46 print("Block Size: %s" % (MemorySize(block_size)))
47 print("Total Memory: %s"
48 % (MemorySize(block_size*block_count)))
49 print("Actual Storage Required: %s"
51 PathORAM.compute_storage_size(
54 storage_type='mmap'))))
57 print("Setting Up Path ORAM Storage Locally")
58 setup_start = time.time()
59 with PathORAM.setup(storage_name,
63 ignore_existing=True) as f:
64 print("Total Setup Time: %.2f s"
65 % (time.time()-setup_start))
66 print("Current Stash Size: %s"
68 print("Total Data Transmission: %s"
69 % (MemorySize(f.bytes_sent + f.bytes_received)))
72 print("Saving key to file: %s.key"
74 save_private_key(storage_name+".key", f.key)
75 print("Saving stash to file: %s.stash"
77 with open(storage_name+".stash", 'wb') as fstash:
78 pickle.dump(f.stash, fstash)
79 print("Saving position map to file: %s.position"
81 with open(storage_name+".position", 'wb') as fpos:
82 pickle.dump(f.position_map, fpos)
84 # Start an SSH client using paramiko
85 print("Starting SSH Client")
86 with paramiko.SSHClient() as ssh:
87 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
88 ssh.load_system_host_keys()
90 username=ssh_username,
91 password=ssh_password)
93 sftp = ssh.open_sftp()
98 t.update(b - inner.last_b)
102 with tqdm.tqdm(desc="Transferring Storage",
106 sftp.put(storage_name,
111 print("Deleting Local Copy of Storage")
112 os.remove(storage_name)
114 if __name__ == "__main__":
115 main() # pragma: no cover