-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrongswan_benchmark.py
151 lines (136 loc) · 4.25 KB
/
strongswan_benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import os
import time
import shutil
from vmware_fusion_py import VMware
from strongswan_manager import StrongSwan
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
certificates = [
# "ecdsa",
# "ed25519",
# "rsa",
# "falcon512",
# "falcon1024",
"dilithium2",
# "dilithium3",
# "dilithium5",
]
base_proposal = "aes256-sha256"
kem_proposals = [
"x25519",
"ke1_kyber1-x25519",
"ke1_kyber3-x25519",
"ke1_kyber5-x25519",
"ke1_kyber3-ke2_bike3-ke3_hqc3-x25519",
]
mode = "200ping0pl"
log_names = []
iterations = str(500)
carol_conf_path = os.getenv("CAROL_CONF_PATH")
moon_conf_path = os.getenv("MOON_CONF_PATH")
certificates_path = os.getenv("CERTIFICATES_PATH")
if not carol_conf_path or not moon_conf_path or not certificates_path:
print("Please provideCAROL_CONF_PATH, MOON_CONF_PATH and CERTIFICATES_PATH!")
exit(1)
# Initialize vmware class
vmrun_path = shutil.which("vmrun")
if not vmrun_path:
print(
f"Could not find vmrun. Install vmrun from {"".format('', "https://www.vmware.com/products/desktop-hypervisor.html", "VMware")}"
)
exit()
carol = VMware(
vmrun_path=vmrun_path,
vm_path=os.getenv("CAROL_VM_PATH") or "",
)
carol.set_guest_user(os.getenv("CAROL_USER"))
carol.set_guest_password(os.getenv("CAROL_PASSWORD"))
moon = VMware(
vmrun_path=vmrun_path,
vm_path=os.getenv("MOON_VM_PATH") or "",
)
moon.set_guest_user(os.getenv("MOON_USER"))
moon.set_guest_password(os.getenv("MOON_PASSWORD"))
# Start the VMs
carol.start()
moon.start()
# Initialize StrongSwan class
strongswan = StrongSwan(carol_conf_path, moon_conf_path)
for certificate in certificates:
print(f"Updating certificates to {certificate}")
certificate_path = certificates_path + "/" + certificate + "/"
print(
carol.copy_file_from_host_to_guest(
host_path=certificate_path + "carolCert.pem",
guest_path="/etc/swanctl/x509/carolCert.pem",
)
)
print(
carol.copy_file_from_host_to_guest(
host_path=certificate_path + "carolKey.pem",
guest_path="/etc/swanctl/pkcs8/carolKey.pem",
)
)
print(
carol.copy_file_from_host_to_guest(
host_path=certificate_path + "caCert.pem",
guest_path="/etc/swanctl/x509ca/caCert.pem",
)
)
print(
moon.copy_file_from_host_to_guest(
host_path=certificate_path + "moonCert.pem",
guest_path="/etc/swanctl/x509/moonCert.pem",
)
)
print(
moon.copy_file_from_host_to_guest(
host_path=certificate_path + "moonKey.pem",
guest_path="/etc/swanctl/pkcs8/moonKey.pem",
)
)
print(
moon.copy_file_from_host_to_guest(
host_path=certificate_path + "caCert.pem",
guest_path="/etc/swanctl/x509ca/caCert.pem",
)
)
print(f"Updated certificates to {certificate}")
for proposal in kem_proposals:
print(f"Updating proposals to {base_proposal}-{proposal}")
proposals = f"{base_proposal}-{proposal}"
strongswan.update_proposals(proposals)
carol.copy_file_from_host_to_guest(
host_path=carol_conf_path, guest_path="/etc/swanctl/swanctl.conf"
)
moon.copy_file_from_host_to_guest(
host_path=moon_conf_path, guest_path="/etc/swanctl/swanctl.conf"
)
print(f"Updated proposals")
carol.run_program_in_guest(
os.getenv("CAROL_RELOAD_SCRIPT"),
program_arguments=[os.getenv("CAROL_PASSWORD")],
)
moon.run_program_in_guest(
os.getenv("MOON_RELOAD_SCRIPT"),
program_arguments=[
os.getenv("MOON_PASSWORD")
], # Fixed: now uses MOON_PASSWORD
)
carol.run_program_in_guest(
os.getenv("CAROL_BENCHMARK_SCRIPT"),
program_arguments=[
certificate,
proposal,
mode,
iterations,
os.getenv("CAROL_PASSWORD"),
],
)
log_names.append(f"{certificate}_{proposal}_{mode}")
print(
f"Completed benchmark for {certificate}-{proposal}-{mode} with {iterations} connections."
)
print(log_names)
print("Complete")