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 / argus / tests / test_argus_containment_e2e.c

98 lines · 5513 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "../argus_abi.h"
18#include "../argus_core.h"
19#include "../argus_contain.h"
20#include "../bridge/argus_aegis_bridge.h"
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26static int checks, failures;
27#define CHECK(x) do { checks++; if(!(x)) { failures++; fprintf(stderr,"FAIL %s:%d: %s\n",__FILE__,__LINE__,#x); } } while(0)
28
29int main(void)
30{
31 AienosCapAdmin *admin=NULL; AienosCapView *view=NULL; AienosCapRef office={0};
32 CHECK(aienos_cap_start(&admin,&view)==AIENOS_CAP_OK);
33 CHECK(aienos_cap_office(admin,&office)==AIENOS_CAP_OK);
34
35 void *core_mem=calloc(1,argus_core_footprint());
36 void *contain_mem=calloc(1,argus_contain_footprint());
37 void *gate_mem=calloc(1,aienos_contain_footprint());
38 void *bridge_mem=calloc(1,argus_aegis_bridge_footprint());
39 CHECK(core_mem&&contain_mem&&gate_mem&&bridge_mem);
40 ArgusCore *core=NULL; ArgusContain *contain=NULL; AienosContain *gate=NULL;
41 CHECK(argus_core_init(&core,core_mem,argus_core_footprint())==ARGUS_OK);
42 CHECK(argus_contain_init(&contain,contain_mem,argus_contain_footprint())==ARGUS_OK);
43 uint8_t machine[ARGUS_MACHINE_ID_LEN]={0}; machine[0]=0xA1;
44 ArgusAegisBridge *bridge=NULL;
45 CHECK(argus_aegis_bridge_init(&bridge,bridge_mem,argus_aegis_bridge_footprint(),core,contain,
46 &gate,view,machine)==ARGUS_OK);
47
48 ArgusEvent joined={0}; joined.version=ARGUS_ABI_VERSION; joined.class_=ARGUS_CLASS_SECURITY;
49 joined.kind=ARGUS_EV_MACHINE_JOINED; joined.outcome=ARGUS_OUTCOME_OK;
50 joined.flags=(uint16_t)(1u<<ARGUS_FLAG_STREAM_SHIFT)|ARGUS_FLAG_SYNTHETIC;
51 joined.sequence=1; joined.object_id=ARGUS_TRUST_OBSERVED; joined.cap_id=ARGUS_CAP_NONE;
52 memcpy(joined.machine_id,machine,sizeof machine);
53 CHECK(argus_aegis_bridge_ingest(bridge,&joined)==ARGUS_OK);
54
55 /* Observer registration precedes create so the executor mint seeds both shadows. */
56 CHECK(aienos_cap_set_observer(admin,argus_aegis_bridge_observer,bridge)==AIENOS_CAP_OK);
57 AienosContainTablePolicy policy={0}; policy.verdict[AIENOS_CONTAIN_REVOKE_CAPABILITY]=AIENOS_CONTAIN_GRANT;
58 AienosContainAuthorizer authorizer={aienos_contain_table_decide,&policy};
59 CHECK(aienos_contain_create(&gate,gate_mem,aienos_contain_footprint(),admin,view,office,&authorizer)==AIENOS_CONTAIN_OK);
60 CHECK(argus_aegis_bridge_attach_gate(bridge)==ARGUS_OK);
61
62 /* A normal leaf capability is minted after gate creation and observed. */
63 AienosCapMint mint={0,7,0x1234,AIENOS_CAP_RIGHT_READ,0,{AIENOS_CAP_PARENT_NONE,0},office};
64 AienosCapRef target={0}; CHECK(aienos_cap_mint(admin,&mint,&target)==AIENOS_CAP_OK);
65
66 /* A stale successful use creates one deterministic revoke proposal. */
67 ArgusEvent use={0}; use.version=ARGUS_ABI_VERSION; use.class_=ARGUS_CLASS_AUDIT;
68 use.kind=ARGUS_EV_CAPABILITY_USED; use.effect_class=ARGUS_EFFECT_NONE; use.outcome=ARGUS_OUTCOME_OK;
69 use.flags=(uint16_t)(1u<<ARGUS_FLAG_STREAM_SHIFT); use.sequence=2; use.code=AIENOS_CAP_ERR_STALE_GEN;
70 use.cap_id=target.cap_id; use.cap_generation=target.generation; use.principal=7;
71 memcpy(use.machine_id,machine,sizeof machine);
72 CHECK(argus_aegis_bridge_ingest(bridge,&use)==ARGUS_OK);
73 ArgusFinding found[16]; size_t nf=argus_aegis_bridge_take_findings(bridge,found,16);
74 CHECK(nf==1 && found[0].code==ARGUS_F_STALE_GENERATION && found[0].containment==ARGUS_CONTAIN_REVOKE_CAPABILITY);
75
76 ArgusContainmentRequest request[1]; ArgusEvent proposed[1]; size_t np=0;
77 CHECK(argus_contain_propose(contain,core,found,nf,&use,request,1,proposed,1,&np)==ARGUS_OK && np==1);
78 CHECK(argus_aegis_bridge_ingest(bridge,&proposed[0])==ARGUS_OK);
79 AienosContainDecision decision={0}; AienosContainResult result={0};
80 CHECK(argus_aegis_bridge_submit(bridge,&request[0],&decision,&result)==ARGUS_OK);
81 CHECK(decision.status==AIENOS_CONTAIN_GRANT && result.status==AIENOS_CONTAIN_DONE);
82 AienosCapEntry after={0}; CHECK(aienos_cap_inspect(view,target,&after)==AIENOS_CAP_OK);
83 CHECK(after.state==AIENOS_CAP_STATE_REVOKED);
84 ArgusContainHealth health; argus_contain_health(contain,&health);
85 CHECK(health.requested==1 && health.granted==1 && health.confirmed==1 && health.failed_scope==0);
86 CHECK(argus_aegis_bridge_error(bridge)==ARGUS_OK);
87
88 ArgusCoreHealth core_health; argus_core_health(core,&core_health);
89 CHECK(core_health.events_received>=6 && core_health.events_rejected==0);
90
91 /* Stop callbacks before destroying the gate; this is part of its lifetime contract. */
92 CHECK(aienos_cap_set_observer(admin,NULL,NULL)==AIENOS_CAP_OK);
93 aienos_contain_destroy(gate); argus_aegis_bridge_destroy(bridge);
94 aienos_cap_stop(admin,view);
95 free(bridge_mem); free(gate_mem); free(contain_mem); free(core_mem);
96 printf("ARGUS-1 bridge end-to-end: %d checks, %d failures\n",checks,failures);
97 return failures?1:0;
98}