2 # This example measures the performance of encrypted storage
3 # access through an SSH client using the Secure File
4 # Transfer Protocol (SFTP).
6 # In order to run this example, you must provide a host
7 # (server) address along with valid login credentials
15 from pyoram.util.misc import MemorySize
16 from pyoram.encrypted_storage.encrypted_block_storage import \
19 from AliTimer import *
24 pyoram.config.SHOW_PROGRESS_BAR = True
26 # Set SSH login credentials here
27 # (by default, we pull these from the environment
28 # for testing purposes)
29 ssh_host = os.environ.get('PYORAM_SSH_TEST_HOST')
30 ssh_username = os.environ.get('PYORAM_SSH_TEST_USERNAME')
31 ssh_password = os.environ.get('PYORAM_SSH_TEST_PASSWORD')
33 # Set the storage location and size
34 storage_name = "heap.bin"
38 # one block per bucket in the
39 # storage heap of height 8
40 block_count = 2**(0+1)-1
43 timer = Foo.Instance()
45 print("Storage Name: %s" % (storage_name))
46 print("Block Count: %s" % (block_count))
47 print("Block Size: %s" % (MemorySize(block_size)))
48 print("Total Memory: %s"
49 % (MemorySize(block_size*block_count)))
50 print("Actual Storage Required: %s"
52 EncryptedBlockStorage.compute_storage_size(
55 storage_type='sftp'))))
58 # Start an SSH client using paramiko
59 print("Starting SSH Client")
60 with paramiko.SSHClient() as ssh:
61 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
62 ssh.load_system_host_keys()
64 username=ssh_username,
65 password=ssh_password)
67 print("Setting Up Encrypted Block Storage")
68 setup_start = time.time()
69 with EncryptedBlockStorage.setup(storage_name,
74 ignore_existing=True) as f:
75 #print("Total Setup Time: %2.f s"
76 # % (time.time()-setup_start))
77 print("Test Setup Time: " + str(time.time() - setup_start))
78 print("Total Data Transmission: %s"
79 % (MemorySize(f.bytes_sent + f.bytes_received)))
82 # We close the device and reopen it after
83 # setup to reset the bytes sent and bytes
85 with EncryptedBlockStorage(storage_name,
91 start_time = time.time()
92 for t in tqdm.tqdm(list(range(test_count)),
93 desc="Running I/O Performance Test"):
94 block = f.read_block(random.randint(0,f.block_count-1))
95 stop_time = time.time()
96 print("Access Block Avg. Data Transmitted: %s (%.3fx)"
97 % (MemorySize((f.bytes_sent + f.bytes_received)/float(test_count)),
98 (f.bytes_sent + f.bytes_received)/float(test_count)/float(block_size)))
99 print("Access Block Avg. Latency: %.2f ms"
100 % ((stop_time-start_time)/float(test_count)*1000))
105 keys.extend(range(0, block_count))
108 print("Starting Ali Test 2")
110 test_count = block_count
111 start_time = time.time()
113 for t in tqdm.tqdm(list(range(test_count)), desc="Running I/O Performance Test"):
117 f.write_block(ind, block)
118 print("Total Data Transmission: %s" % (MemorySize(f.bytes_sent + f.bytes_received)))
120 stop_time = time.time()
121 print("Test Processing Time: " + str(stop_time - start_time))
122 print("Test Network Time: " + str(timer.getTime()))
125 if __name__ == "__main__":
126 main() # pragma: no cover