def _generate_static_keys_and_build(self): # Back-up static-keys.c if os.path.exists("wsn/common/crypto/static-keys.c"): shutil.move("wsn/common/crypto/static-keys.c", "wsn/common/crypto/static-keys.c.orig") for (target, ip) in ips.items(): # Skip building for root ip if ip == root_ip: continue print(f"Building for {ip} attached to {target}") name = self.ip_name(ip) pathlib.Path(f"setup/{name}").mkdir(parents=True, exist_ok=True) print(f"Creating static-keys.c for {ip}") self.create_static_keys(ip) shutil.move("setup/static-keys.c", "wsn/common/crypto/static-keys.c") build_args = { "BUILD_NUMBER": "0", } if self.oscore_master_salt is not None: build_args["OSCORE_MASTER_SALT"] = self.bytes_to_c_array( self.oscore_master_salt) if self.oscore_id_context is not None: build_args["OSCORE_ID_CONTEXT"] = self.bytes_to_c_array( self.oscore_id_context) build_args_str = " ".join(f"{k}={v}" for (k, v) in build_args.items()) for binary in self.binaries: print(f"Building {binary} with '{build_args}'") subprocess.run(f"make -C wsn/{binary} {build_args_str}", shell=True, check=True) shutil.move( f"wsn/{binary}/build/zoul/remote-revb/{binary}.bin", f"setup/{name}/{binary}.bin") shutil.move("wsn/common/crypto/static-keys.c", f"setup/{name}/static-keys.c") # Move backed-up static-keys.c back if os.path.exists("wsn/common/crypto/static-keys.c.orig"): shutil.move("wsn/common/crypto/static-keys.c.orig", "wsn/common/crypto/static-keys.c")
def _fabric_deploy(self, password: str): for (target, ip) in ips.items(): with fabric.Connection(f'pi@{target}', connect_kwargs={"password": password}) as conn: # Now upload the configuration src = f"common/configuration.py" dest = os.path.join("/home/pi/iot-trust-task-alloc", src) result = conn.put(src, dest) print("Uploaded {0.local} to {0.remote} for {1}".format( result, conn)) # Skip deploying binaries for root ip if ip == root_ip: continue for binary in self.binaries: src = f"setup/{self.ip_name(ip)}/{binary}.bin" dest = os.path.join("/home/pi/pi-client", os.path.basename(src)) result = conn.put(src, dest) print("Uploaded {0.local} to {0.remote} for {1}".format( result, conn))
def _generate_static_keys_and_build(self): # Back-up static-keys.c if os.path.exists("wsn/common/crypto/static-keys.c"): shutil.move("wsn/common/crypto/static-keys.c", "wsn/common/crypto/static-keys.c.orig") for (target, ip) in ips.items(): # Skip building for root ip if ip == root_ip: continue print(f"Building for {ip} attached to {target}") name = self.ip_name(ip) pathlib.Path(f"setup/{name}").mkdir(parents=True, exist_ok=True) print(f"Creating static-keys.c for {ip}") self.create_static_keys(ip) shutil.move("setup/static-keys.c", "wsn/common/crypto/static-keys.c") build_args = { "BUILD_NUMBER": self.build_number, "TRUST_MODEL": self.trust_model, "TRUST_CHOOSE": self.trust_choose, "APPLICATIONS": '"' + " ".join(self.applications) + '"', } build_args.update(self._target_build_args()) if self.with_pcap: build_args["MAKE_WITH_PCAP"] = "1" if self.oscore_master_salt is not None: build_args["OSCORE_MASTER_SALT"] = self.bytes_to_c_array( self.oscore_master_salt) if self.oscore_id_context is not None: build_args["OSCORE_ID_CONTEXT"] = self.bytes_to_c_array( self.oscore_id_context) if self.defines: build_args["ADDITIONAL_CFLAGS"] = '"' + " ".join( [f"-D{k}='{v}'" for (k, v) in self.defines.items()]) + '"' if self.verbose_make: build_args["V"] = "1" for binary in self.binaries: print(f"Building {binary} with '{build_args}'") final_build_args = {**build_args} if binary == "adversary" and self.with_adversary: final_build_args["MAKE_ATTACKS"] = ",".join( self.with_adversary) if binary == "bad_edge" and self.with_bad_edge: final_build_args["MAKE_ATTACKS"] = ",".join( self.with_bad_edge) build_args_str = " ".join(f"{k}={v}" for (k, v) in final_build_args.items()) subprocess.run(f"make -C wsn/{binary} {build_args_str}", shell=True, check=True) shutil.move( f"wsn/{binary}/build/{target_output_dir[self.target]}/{binary}.bin", f"setup/{name}/{binary}.bin") shutil.move("wsn/common/crypto/static-keys.c", f"setup/{name}/static-keys.c") # Move backed-up static-keys.c back if os.path.exists("wsn/common/crypto/static-keys.c.orig"): shutil.move("wsn/common/crypto/static-keys.c.orig", "wsn/common/crypto/static-keys.c")
def _create_certificates(self): self.certs = { ip: self.create_and_save_certificate("setup/keystore", ip, device_stereotypes[name]) for name, ip in sorted(ips.items(), key=lambda x: x[0]) }