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 / model / admission_test.c

50 lines · 2536 bytes Raw Blame History
1/* Hosted signature/profile oracle. Actual memory isolation is tested in QEMU. */
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 "model_bundle.h"
8#include "sha256.h"
9#define CHECK(v) do { if (!(v)) { fprintf(stderr,"model admission failed at %d\n",__LINE__); return 1; } checks++; } while (0)
10int main(int argc, char **argv)
11{
12 unsigned checks = 0;
13 CHECK(argc == 4);
14 const struct ck_local_artifact *a = &ck_model_artifact;
15 struct cka_parsed p; struct cka_ident id; uint8_t fp[32], hash[32];
16 CHECK(!memcmp(ck_model_key, ck_local_keys[0], 32));
17 CHECK(!cka_verify_profile(a->bytes,a->length,ck_local_keys,1,&p,&id,fp,2,3));
18 sha256_hash(a->bytes,a->length,hash); CHECK(!memcmp(hash,a->hash,32));
19 CHECK(cka_env_validate(&p.env,0) == CKA_RESOURCE_LIMIT);
20 CHECK(!cka_env_validate_profile(&p.env,0,2,3));
21 struct cka_env bad_env = p.env; bad_env.data_pages++;
22 CHECK(cka_env_validate_profile(&bad_env,0,2,3) == CKA_RESOURCE_LIMIT);
23 CHECK(cka_env_validate_profile(&p.env,1,2,3) == CKA_RESOURCE_LIMIT);
24 CHECK(cka_parse(a->bytes,a->length,&p) == CKA_WRONG_TARGET);
25 CHECK(cka_parse_profile(a->bytes,a->length,&p,2,2) == CKA_WRONG_ABI);
26 CHECK(!cka_parse_profile(a->bytes,a->length,&p,2,3));
27 for (unsigned i = 0; i < 3; i++) {
28 FILE *f = fopen(argv[i+1],"rb"); CHECK(f);
29 CHECK(!fseek(f,0,SEEK_END)); long size=ftell(f); CHECK(size>0); rewind(f);
30 uint8_t *bytes=malloc((size_t)size); CHECK(bytes);
31 CHECK(fread(bytes,1,(size_t)size,f) == (size_t)size); fclose(f);
32 if (!i) CHECK((size_t)size == p.code.flen && !memcmp(bytes,a->bytes+p.payload_off,size));
33 else {
34 sha256_hash(bytes,(size_t)size,hash);
35 CHECK(!memcmp(hash,a->bytes+p.payload_off+p.data.rel+32*(i-1),32));
36 bytes[size/2] ^= 1; sha256_hash(bytes,(size_t)size,hash);
37 CHECK(memcmp(hash,a->bytes+p.payload_off+p.data.rel+32*(i-1),32));
38 }
39 free(bytes);
40 }
41 uint8_t *mutant=malloc(a->length); CHECK(mutant);
42 size_t offsets[]={14,192,240,p.payload_off+p.data.rel,a->length-1};
43 for (unsigned i=0;i<sizeof offsets/sizeof offsets[0];i++) {
44 memcpy(mutant,a->bytes,a->length); mutant[offsets[i]] ^= 1;
45 CHECK(cka_verify_profile(mutant,a->length,ck_local_keys,1,&p,&id,fp,2,3) != 0);
46 }
47 free(mutant);
48 printf("MODEL_ADMISSION: PASS checks=%u compiled_payload=1 signed_assets=2\n",checks);
49 return 0;
50}