This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
@trust_group.command("add")@click.argument("key_file",type=click.Path(exists=True,dir_okay=False,resolve_path=True))@click.option("--name",default=None,help="Human-readable label for this key.")@click.option("--global","global_",is_flag=True,default=False,help="Add to system store.")deftrust_add(key_file:str,name:str|None,global_:bool)->None:"""Add a public key to the trusted-keys store."""src=Path(key_file)try:raw_bytes=src.read_bytes()pem_lines=[lineforlineinraw_bytes.decode().splitlines()ifnotline.strip().startswith("# Name:")]pub_key=load_pem_public_key("\n".join(pem_lines).encode())fp=compute_key_fingerprint(pub_key)exceptExceptionasexc:perr(f"Failed to read key: {exc}")raiseSystemExit(1)fromexcstore_dir=get_trusted_keys_dir(system=global_)store_dir.mkdir(parents=True,exist_ok=True)dest=store_dir/f"{fp[:16]}.pub"label=f"# Name: {name}\n".encode()ifnameelseb""raw_pem=pub_key.public_bytes(Encoding.PEM,PublicFormat.SubjectPublicKeyInfo)dest.write_bytes(label+raw_pem)pout(f"Added key {fp[:16]}... ({nameor'no label'}) β {dest}")
@trust_group.command("list")@click.option("--global","global_",is_flag=True,default=False,help="Show system store only.")deftrust_list(global_:bool)->None:"""List all trusted keys and their fingerprints."""keys=_load_keys_from_dir(get_system_config_dir()/"trusted-keys")ifglobal_elseload_trusted_keys()ifnotkeys:pout("No trusted keys found.")returnforfp,infoinsorted(keys.items()):label=info.get("name")or"(no label)"pout(f" {fp}{label}")
@trust_group.command("remove")@click.argument("fingerprint")@click.option("--global","global_",is_flag=True,default=False,help="Remove from system store.")deftrust_remove(fingerprint:str,global_:bool)->None:"""Remove a key from the trusted-keys store by fingerprint."""store_dir=get_trusted_keys_dir(system=global_)ifglobal_:keys=_load_keys_from_dir(get_system_config_dir()/"trusted-keys")else:keys=load_trusted_keys(include_system=False)iffingerprintnotinkeys:perr(f"Key not found: {fingerprint[:16]}...")raiseSystemExit(1)key_path=Path(keys[fingerprint]["path"])key_path.unlink()pout(f"Removed {fingerprint[:16]}... from {store_dir}")
@trust_group.command("verify")@click.argument("package_file",type=click.Path(exists=True,dir_okay=False,resolve_path=True))deftrust_verify(package_file:str)->None:"""Check whether a package's signing key is in the trusted store."""pkg_path=Path(package_file)withPSPFReader(pkg_path)asreader:index=reader.read_index()fp_bytes=index.attestation_key_fp.rstrip(b"\x00")ifnotfp_bytes:perr("Package has no key fingerprint in attestation field.")raiseSystemExit(2)fp=fp_bytes.decode("ascii")result=is_key_trusted(fp)ifresultisNone:pout(f"No trusted-keys store found. Key fingerprint: {fp[:16]}...")pout("Run `flavor init` to set up a key store.")elifresult:pout(f"β Key {fp[:16]}... is trusted.")else:perr(f"β Key {fp[:16]}... is NOT in the trusted store.")raiseSystemExit(1)