code wiki / (root) / nx_attest_silicon_test.nx

nx_attest_silicon_test.nx source

↩ module page · 100 lines · 4751 B

1// nx_attest_silicon_test.nx -- smoke for nx_attest_silicon. 2 3import "nx_syscalls.nx" 4import "nx_attest_silicon.nx" 5 6func main() -> i64 { 7 // 1: chip family sealed enum 8 if NX_CHIP_N_FAMILIES != 13 { return 1 } 9 if nx_chip_family_is_valid(NX_CHIP_INTEL_ME) != 1 { return 2 } 10 if nx_chip_family_is_valid(NX_CHIP_SOVEREIGN_NISHI) != 1 { return 3 } 11 if nx_chip_family_is_valid(-1) != 0 { return 4 } 12 if nx_chip_family_is_valid(13) != 0 { return 5 } 13 14 // 2: Intel ME threat surface includes RAM_READ + NET_EGRESS 15 let me_ts: nx_int = nx_chip_threat_surface(NX_CHIP_INTEL_ME) 16 if (me_ts & NX_TS_RAM_READ) == 0 { return 6 } 17 if (me_ts & NX_TS_NET_EGRESS) == 0 { return 7 } 18 if (me_ts & NX_TS_FIRMWARE_PERSIST) == 0 { return 8 } 19 if (me_ts & NX_TS_KEY_ESCROW) == 0 { return 9 } 20 21 // 3: SOVEREIGN_NISHI has no threat surface 22 if nx_chip_threat_surface(NX_CHIP_SOVEREIGN_NISHI) != NX_TS_NONE { return 10 } 23 if nx_chip_threat_surface(NX_CHIP_RISCV_OPEN) != NX_TS_NONE { return 11 } 24 25 // 4: baseband has RADIO_ACTIVATE + DMA + NET_EGRESS 26 let bb_ts: nx_int = nx_chip_threat_surface(NX_CHIP_QUALCOMM_BASEBAND) 27 if (bb_ts & NX_TS_RADIO_ACTIVATE) == 0 { return 12 } 28 if (bb_ts & NX_TS_DMA) == 0 { return 13 } 29 if (bb_ts & NX_TS_NET_EGRESS) == 0 { return 14 } 30 31 // 5: UNKNOWN gets worst-case surface 32 let unk_ts: nx_int = nx_chip_threat_surface(NX_CHIP_UNKNOWN) 33 if (unk_ts & NX_TS_RAM_READ) == 0 { return 15 } 34 35 // 6: base trust score ordering: sovereign > open-RISCV > TPM > Apple SE 36 // > Apple T2 > AMD PSP > Intel ME > unknown 37 let t_sov: nx_int = nx_chip_base_trust_q10(NX_CHIP_SOVEREIGN_NISHI) 38 let t_rsv: nx_int = nx_chip_base_trust_q10(NX_CHIP_RISCV_OPEN) 39 let t_tpm: nx_int = nx_chip_base_trust_q10(NX_CHIP_INFINEON_TPM) 40 let t_t2: nx_int = nx_chip_base_trust_q10(NX_CHIP_APPLE_T2) 41 let t_psp: nx_int = nx_chip_base_trust_q10(NX_CHIP_AMD_PSP) 42 let t_me: nx_int = nx_chip_base_trust_q10(NX_CHIP_INTEL_ME) 43 let t_unk: nx_int = nx_chip_base_trust_q10(NX_CHIP_UNKNOWN) 44 if t_sov != 1024 { return 16 } 45 if t_sov <= t_rsv { return 17 } 46 if t_rsv <= t_tpm { return 18 } 47 if t_tpm <= t_t2 { return 19 } 48 if t_t2 <= t_psp { return 20 } 49 if t_psp <= t_me { return 21 } 50 if t_me <= t_unk { return 22 } 51 if t_unk != 0 { return 23 } 52 53 // 7: build Intel ME attestation, no mitigations applied 54 let name: *u8 = (sys_mmap(8)) as *u8 55 name[0] = 73 as u8 // 'I' 56 let a: *NxSiliconAttestation = nx_attestation_new(NX_CHIP_INTEL_ME, name) 57 if a.chip_family != NX_CHIP_INTEL_ME { return 24 } 58 if a.applied_mitigations != NX_MIT_NONE { return 25 } 59 if nx_attestation_effective_trust_q10(a) != t_me { return 26 } 60 61 // 8: cannot apply unavailable mitigation 62 // (KILL_SWITCH is not in ME's available set) 63 let rc_bad: nx_int = nx_attestation_apply_mitigation(a, NX_MIT_KILL_SWITCH) 64 if rc_bad != 1 { return 27 } 65 if a.applied_mitigations != NX_MIT_NONE { return 28 } 66 67 // 9: apply ME_CLEANER (available for ME) 68 let rc_ok: nx_int = nx_attestation_apply_mitigation(a, NX_MIT_ME_CLEANER_HAP) 69 if rc_ok != 0 { return 29 } 70 let trust_one: nx_int = nx_attestation_effective_trust_q10(a) 71 if trust_one <= t_me { return 30 } // applying mitigation raises trust 72 73 // 10: stack all 7 ME mitigations -> trust climbs but never reaches 1024 74 nx_attestation_apply_mitigation(a, NX_MIT_COREBOOT) 75 nx_attestation_apply_mitigation(a, NX_MIT_EGRESS_FILTER) 76 nx_attestation_apply_mitigation(a, NX_MIT_MEMORY_HYGIENE) 77 nx_attestation_apply_mitigation(a, NX_MIT_DMA_DISCIPLINE) 78 nx_attestation_apply_mitigation(a, NX_MIT_CRYPTO_COMPART) 79 nx_attestation_apply_mitigation(a, NX_MIT_SILICON_TRUST_ENF) 80 let trust_full: nx_int = nx_attestation_effective_trust_q10(a) 81 // Mitigated ME: 205 + (1024 - 205) * 7/8 = 205 + 716 = 921 82 if trust_full != 921 { return 31 } 83 if trust_full >= 1024 { return 32 } 84 85 // 11: safe-for-gameplay = yes; safe-for-secrets = yes at 921 >= 768 86 if nx_attestation_safe_for_gameplay(a) != 1 { return 33 } 87 if nx_attestation_safe_for_secrets(a) != 1 { return 34 } 88 89 // 12: unmitigated UNKNOWN -- unsafe for everything 90 let a_unk: *NxSiliconAttestation = nx_attestation_new(NX_CHIP_UNKNOWN, name) 91 if nx_attestation_safe_for_gameplay(a_unk) != 0 { return 35 } 92 if nx_attestation_safe_for_secrets(a_unk) != 0 { return 36 } 93 94 // 13: SOVEREIGN_NISHI -- safe for everything even with no mitigations 95 let a_sov: *NxSiliconAttestation = nx_attestation_new(NX_CHIP_SOVEREIGN_NISHI, name) 96 if nx_attestation_effective_trust_q10(a_sov) != 1024 { return 37 } 97 if nx_attestation_safe_for_secrets(a_sov) != 1 { return 38 } 98 99 return 0 100}