interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / x86 / tests / local_admission_test.c

39 lines · 2184 bytes Raw Blame History
1/* Hosted verification oracle. No host execution substitutes for CPL3 gates. */
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include "../../artifact/ck_artifact.h"
6#include "../local_bundle.h"
7#include "sha256.h"
8#define CHECK(v) do { if (!(v)) { fprintf(stderr,"local admission failed at %d\n",__LINE__); return 1; } count++; } while (0)
9int main(int argc, char **argv)
10{
11 unsigned count = 0;
12 CHECK(argc == 4);
13 struct cka_parsed p; struct cka_ident id; uint8_t fp[32], hash[32];
14 for (unsigned i = 0; i < 3; i++) {
15 const struct ck_local_artifact *a = &ck_local_artifacts[i];
16 CHECK(!cka_verify_profile(a->bytes,a->length,ck_local_keys,1,&p,&id,fp,2,2));
17 sha256_hash(a->bytes,a->length,hash); CHECK(!memcmp(hash,a->hash,32));
18 CHECK(cka_parse(a->bytes,a->length,&p) == CKA_WRONG_TARGET);
19 CHECK(!cka_parse_profile(a->bytes,a->length,&p,2,2));
20 FILE *f = fopen(argv[i+1],"rb"); CHECK(f);
21 uint8_t raw[65537]; size_t n = fread(raw,1,sizeof raw,f); CHECK(!ferror(f)); fclose(f);
22 CHECK(n == p.code.flen && !memcmp(raw,a->bytes+p.payload_off,n));
23 CHECK(p.ncaps == 0 && p.env.max_caps == 0 && p.env.code_pages == 16 &&
24 p.env.data_pages == 32 && p.env.stack_pages == 16 && p.env.cpu == 100000 &&
25 p.env.elapsed == 500000 && p.env.syscalls == 1);
26 CHECK(cka_verify_profile(a->bytes,a->length,ck_local_keys,0,&p,&id,fp,2,2) == CKA_UNTRUSTED_SIGNER);
27 CHECK(cka_verify_profile(a->bytes,a->length,ck_local_keys,1,&p,&id,fp,2,1) == CKA_WRONG_ABI);
28 for (size_t short_len=0; short_len<a->length; short_len++)
29 CHECK(cka_parse_profile(a->bytes,short_len,&p,2,2) != 0);
30 uint8_t *bad = malloc(a->length); CHECK(bad);
31 memcpy(bad,a->bytes,a->length); bad[a->length-1] ^= 1;
32 CHECK(cka_verify_profile(bad,a->length,ck_local_keys,1,&p,&id,fp,2,2) == CKA_BAD_SIGNATURE);
33 memcpy(bad,a->bytes,a->length); bad[242] ^= 1;
34 CHECK(cka_verify_profile(bad,a->length,ck_local_keys,1,&p,&id,fp,2,2) != 0);
35 free(bad);
36 }
37 printf("LOCAL_ADMISSION: PASS checks=%u compiled_payloads=3\n",count);
38 return 0;
39}