def _renewal_request(self, isd_as: scion_addr.ISD_AS, features=""): as_dir = self._to_as_dir(isd_as) csr = as_dir / "crypto/as/csr.json" logger.info("Generating CSR for: %s" % self._rel(csr)) template = { "common_name": "%s InfoSec Squad" % isd_as, "country": "CH", "isd_as": str(isd_as), } with open(csr, "w") as out: json.dump(template, out, indent=4) key = as_dir / "crypto/as/renewed.key" logger.info("Generating new private key: %s" % self._rel(key)) subprocess.run([ "openssl", "genpkey", "-algorithm", "EC", "-pkeyopt", "ec_paramgen_curve:P-256", "-pkeyopt", "ec_param_enc:named_curve", "-out", as_dir / "crypto/as/renewed.key", ]) docker_dir = pathlib.Path("/share") / self._rel(as_dir) chain = docker_dir / "crypto/as/renewed.pem" args = [ "--key", docker_dir / "crypto/as/renewed.key", "--transportkey", docker_dir / "crypto/as/cp-as.key", "--transportcert", docker_dir / ("crypto/as/ISD%s-AS%s.pem" % (isd_as.isd_str(), isd_as.as_file_fmt())), "--trc", docker_dir / "certs/ISD1-B1-S1.trc", "--out", chain, "--sciond", self.execute("tester_%s" % isd_as.file_fmt(), "sh", "-c", "echo $SCION_DAEMON").strip(), *self._local_flags(isd_as), ] if features: args += ["--features", features] logger.info("Requesting certificate chain renewal: %s" % chain.relative_to(docker_dir)) logger.info( self.execute("tester_%s" % isd_as.file_fmt(), "./bin/scion-pki", "certs", "renew", *args)) logger.info("Verify renewed certificate chain") verify_out = self.execute("tester_%s" % isd_as.file_fmt(), "./bin/scion-pki", "certs", "verify", chain, "--trc", "/share/gen/trcs/ISD1-B1-S1.trc") logger.info(str(verify_out).rstrip("\n"))
def _renewal_request( self, isd_as: scion_addr.ISD_AS, mode: str = "--force", ): as_dir = self._to_as_dir(isd_as) docker_dir = pathlib.Path("/share") / self._rel(as_dir) def read_file(filename: str) -> str: with open(as_dir / "crypto/as" / filename) as f: return f.read() chain_name = "ISD%s-AS%s.pem" % (isd_as.isd_str(), isd_as.as_file_fmt()) old_chain = read_file(chain_name) old_key = read_file("cp-as.key") chain = docker_dir / "crypto/as" / chain_name args = [ chain, docker_dir / "crypto/as/cp-as.key", mode, "--trc", docker_dir / "certs/ISD1-B1-S1.trc", "--sciond", self.execute("tester_%s" % isd_as.file_fmt(), "sh", "-c", "echo $SCION_DAEMON").strip(), *self._local_flags(isd_as), ] logger.info("Requesting certificate chain renewal: %s" % chain.relative_to(docker_dir)) logger.info( self.execute("tester_%s" % isd_as.file_fmt(), "./bin/scion-pki", "certificate", "renew", *args)) logger.info("Verify renewed certificate chain") verify_out = self.execute("tester_%s" % isd_as.file_fmt(), "./bin/scion-pki", "certificate", "verify", chain, "--trc", "/share/gen/trcs/ISD1-B1-S1.trc") logger.info(str(verify_out).rstrip("\n")) renewed_chain = read_file(chain_name) renewed_key = read_file("cp-as.key") if renewed_chain == old_chain: raise Exception( "renewed chain does not differ from previous chain") if renewed_key == old_key: raise Exception("renewed key does not differ from previous key")
def execute(self, isd_as: ISD_AS, cmd: str, *args: str) -> str: expanded = [] for arg in args: if str(arg).startswith('gen/'): arg = '/share/' + arg expanded.append(arg) return docker('exec', 'tester_%s' % isd_as.file_fmt(), cmd, *expanded)
def _local_flags(self, isd_as: scion_addr.ISD_AS) -> List[str]: return [ "--local", self.execute("tester_%s" % isd_as.file_fmt(), "sh", "-c", "echo $SCION_LOCAL_ADDR").strip(), ]