#ifndef VGI_HTTP_H#define VGI_HTTP_H#include"vgi_rpc/identity.h"#include"vgi_rpc/proof.h"#include"vgi_rpc/rpc.h"#ifdef __cplusplusextern"C"{#endifstructVgiHttpIdentity{constchar*principal;constchar*domain;constchar*claims_json;constchar*failure_reason;/* Closed unauthorized reason code, used on rejection. */doubleauth_time;inthas_auth_time;};structVgiHttpRequest{constchar*authorization;constchar*(*header)(void*,constchar*);void*state;};structVgiHttpOptions{constchar*host;unsignedport;constchar*prefix;/* Comma-separated token=principal pairs; optional tokens permit anonymous * requests without credentials. Supplied invalid credentials are refused. */constchar*bearer_tokens;constchar*optional_bearer_tokens;constchar*signing_key;constchar*cors_origin;constchar*access_log;/* JSON lines, no credentials or argument values. */conststructVgiIdentityOptions*identity;conststructVgiGrantKeys*grant_keys;structVgiProofOptionsproof;intsticky_enabled;unsignedsticky_ttl_seconds;size_tmax_sessions;constchar*token_key;/* 64 hexadecimal digits; default is a random process key. */constchar*const*sticky_echo_names;constchar*const*sticky_echo_values;size_tsticky_echo_count;/* Optional authenticated control route. ENOENT delegates to RPC routing; * zero handles the request with HTTP 204. path excludes the mount prefix. */int(*control)(void*,constchar*path,intis_delete,structVgiRpcCall*);void*control_state;intcompression;int64_tmax_request_bytes;int64_tmax_response_bytes;int64_tmax_externalized_response_bytes;size_tmax_streams;unsignedstream_ttl_seconds;/* Reject stream initializers without serialization/resume support. Streams * that support it are always stateless: no process-local call cache is used. */intrequire_stateless_streams;unsignedmax_concurrent_requests;/* Zero accepts. EACCES rejects, EAGAIN signals temporary unavailability. * Identity strings are copied before the next request. */int(*authenticate)(void*,constchar*authorization,structVgiHttpIdentity*,structArrowError*);int(*authenticate_request)(void*,conststructVgiHttpRequest*,structVgiHttpIdentity*,structArrowError*);void*auth_state;};voidVgiHttpOptionsInit(structVgiHttpOptions*);/* Serves until SIGINT/SIGTERM. Prints PORT:<port> after binding (port 0 selects * an available port). HTTP bodies, including stream turns, use nanoarrow IPC. */intVgiRpcServerServeHttp(structVgiRpcServer*,conststructVgiHttpOptions*,structArrowError*);#ifdef __cplusplus}#endif#endif
#ifndef VGI_IDENTITY_H#define VGI_IDENTITY_H#include"vgi_rpc/credentials.h"#include"vgi_rpc/rpc.h"#ifdef __cplusplusextern"C"{#endifstructVgiTokenIdentity{constchar*principal,*token_name;int64_tttl_seconds;};structVgiIssuedGrant{constchar*token,*grant_id;doubleexpires_at;};/* Hook output strings are borrowed until the hook's release callback runs. * Hooks may call VgiRpcFail/SetErrorDetails for structured errors. ENOENT means * unresolved/refused; EAGAIN means identity_unavailable with a retry hint. */structVgiIdentityOptions{int(*resolve_token)(void*,structVgiRpcCall*,constchar*,structVgiTokenIdentity*);int(*mint_grant)(void*,structVgiRpcCall*,constchar*purpose,constchar*const*scopes,size_tscope_count,int64_tttl,structVgiIssuedGrant*);void(*release_result)(void*,void*,intis_grant);void*state;constchar*const*introspect_principals;size_tintrospect_principal_count;doublemax_auth_age;/* Zero uses 900 seconds. */conststructVgiGrantKeys*grant_keys;/* Implicit minter if hook absent. */};/* Register before serving. Options and everything they reference must outlive * the server. Only configured methods appear in reflection and protocol hash. */intVgiRpcServerSetIdentity(structVgiRpcServer*,conststructVgiIdentityOptions*,structArrowError*);#ifdef __cplusplus}#endif#endif
#ifndef VGI_RPC_CREDENTIALS_H#define VGI_RPC_CREDENTIALS_H#include"nanoarrow/nanoarrow.h"#ifdef __cplusplusextern"C"{#endif/* All outputs own their storage. Initialize claims to zero and ArrowBuffers * with ArrowBufferInit; reset them after use. Tokens include a terminal NUL * outside size_bytes. Open returns EINVAL for invalid credentials, ESTALE for * authentic expired/not-yet-valid credentials, or ENOMEM. */structVgiGrant{int64_tissued_at,expires_at;char*grant_id,*principal,*purpose;char**scopes;size_tscope_count;};structVgiGrantKeys{constunsignedchar(*keys)[32];size_tkey_count;constchar*audience;int64_tmax_ttl_seconds,clock_skew_seconds;};voidVgiSigningKey(constvoid*raw,size_tsize,unsignedcharkey[32]);voidVgiGrantReset(structVgiGrant*);intVgiGrantKeysValidate(conststructVgiGrantKeys*);/* nonce must be NULL in production; a fixed nonce is for test vectors only. */intVgiGrantMint(conststructVgiGrantKeys*,conststructVgiGrant*,constunsignedcharnonce[24],structArrowBuffer*token);intVgiGrantOpen(conststructVgiGrantKeys*,constchar*token,doublenow,structVgiGrant*);#ifdef __cplusplus}#endif#endif
#ifndef VGI_RPC_PROOF_H#define VGI_RPC_PROOF_H#include"nanoarrow/nanoarrow.h"#ifdef __cplusplusextern"C"{#endifenumVgiProofMode{VGI_PROOF_OFF,VGI_PROOF_ALLOW,VGI_PROOF_REQUIRE};structVgiProofOptions{enumVgiProofModemode;constchar*origin_id;/* Comma-separated kid:hex-secret pairs; each secret is exactly 32 bytes. */constchar*secrets;unsignedskew_seconds;/* Zero disables replay detection; otherwise a hard bound on retained nonces. */size_treplay_capacity;};structVgiProofResult{intverified;constchar*reason;charkid[65];};structVgiProxyProof;voidVgiProofOptionsInit(structVgiProofOptions*);/* The configuration is copied. The verifier is safe to share between threads. */intVgiProxyProofNew(conststructVgiProofOptions*,structVgiProxyProof**,structArrowError*);voidVgiProxyProofFree(structVgiProxyProof*);/* Returns EACCES on rejected proofs in REQUIRE mode. Results are diagnostic: * never expose their reason or kid in an authentication error response. */intVgiProxyProofCheck(structVgiProxyProof*,constchar*token,size_theader_count,uint64_tnow,structVgiProofResult*);#ifdef __cplusplus}#endif#endif