meow_verify 37e50606; nyai f2938d28; svc_power e0494eb7; launcher 24c9ee5d(含热重载) 宿主验证12项全过(正例/篡负载/篡包名/无签系统包拒/第三方直装/降级拒/导出round-trip byte-identical/verify缺失宁缺勿装/footer容忍/E2E PERM/鉴权分类) 出入: TweetNaCl替orlp/ed25519(任务允许同等实现); 读级暂仍uid==0(用户随后定案放宽到任意调用者,待改); 系统身份allowlist为启发式
94 lines
4.0 KiB
C
94 lines
4.0 KiB
C
/* svc_power_authtest.c — meow_svc_power II 期 IPC 鉴权逻辑 宿主自测(本程序非生产代码)。
|
||
*
|
||
* 通过 #include 生产源文件(meow_svc_power.c,用 #define main 改名避免入口冲突),在同一 TU 内直接
|
||
* 访问其 FILE-STATIC 函数 classify_exe / is_system_action / is_sys_identity,验证鉴别/分级策略的决策表。
|
||
* 覆盖「真机需特权路径 /proc/pid/exe 判定」之外的所有纯逻辑分支;真实 pid→exe 解析留真机验证。
|
||
*
|
||
* 用途:dev docs 复现级宿主自测;不进入固件/不部署。用法:
|
||
* cc -Wall -Wextra -I../meow_launcherd svc_power_authtest.c -o svc_power_authtest && ./svc_power_authtest
|
||
*/
|
||
#define main meow_svc_power_prod_main_unused
|
||
#include "meow_svc_power.c"
|
||
#undef main
|
||
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
|
||
static int g_fail = 0;
|
||
#define CHECK(cond) do { if (!(cond)) { printf(" FAIL: %s (line %d)\n", #cond, __LINE__); g_fail++; } \
|
||
else { printf(" ok : %s\n", #cond); } } while (0)
|
||
|
||
int main(void)
|
||
{
|
||
caller_t c;
|
||
|
||
printf("== classify_exe ==\n");
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/usr/data/mnt/sd_0/MeowAPPs/os.meow.tst/meow", &c);
|
||
CHECK(c.kind == CALL_PKG && strcmp(c.pkg, "os.meow.tst") == 0);
|
||
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/usr/data/mnt/sd_0/MeowAPPs/com.example.tool/meow", &c);
|
||
CHECK(c.kind == CALL_PKG && strcmp(c.pkg, "com.example.tool") == 0);
|
||
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/usr/data/mnt/sd_0/MeowAPPs/os.meow.tst/sub/meow", &c);
|
||
CHECK(c.kind == CALL_PKG && strcmp(c.pkg, "os.meow.tst") == 0); /* 取首段目录 */
|
||
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/usr/bin/meow_launcherd", &c);
|
||
CHECK(c.kind == CALL_SYS && strcmp(c.pkg, "os.meow.launcher") == 0);
|
||
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/usr/bin/meow_svc_power", &c);
|
||
CHECK(c.kind == CALL_SYS); /* /usr/bin/meow_* 前缀批准 */
|
||
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/usr/data/mnt/sd_0/MeowOS/opt/MeowPanel/backend/meowpanel", &c);
|
||
CHECK(c.kind == CALL_SYS && strcmp(c.pkg, "os.meow.panel") == 0);
|
||
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/usr/data/meow/settings_tool", &c);
|
||
CHECK(c.kind == CALL_SYS); /* /usr/data/meow/ 批准 */
|
||
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/usr/bin/bash", &c);
|
||
CHECK(c.kind == CALL_OTHER);
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/bin/sh", &c);
|
||
CHECK(c.kind == CALL_OTHER);
|
||
memset(&c, 0, sizeof c);
|
||
classify_exe("/usr/data/mnt/sd_0/MeowAPPs/justadirty/k", &c);
|
||
CHECK(c.kind == CALL_PKG && strcmp(c.pkg, "justadirty") == 0); /* 第三方包(非 os.meow.*) */
|
||
CHECK(is_sys_identity(&c) == 0); /* 非系统身份 → 系统动作被拒 */
|
||
|
||
printf("== is_sys_identity ==\n");
|
||
c.kind = CALL_PKG; snprintf(c.pkg, sizeof c.pkg, "%s", "os.meow.tst");
|
||
CHECK(is_sys_identity(&c) == 1);
|
||
c.kind = CALL_PKG; snprintf(c.pkg, sizeof c.pkg, "%s", "com.example.tool");
|
||
CHECK(is_sys_identity(&c) == 0);
|
||
c.kind = CALL_SYS; snprintf(c.pkg, sizeof c.pkg, "%s", "os.meow.launcher");
|
||
CHECK(is_sys_identity(&c) == 1);
|
||
c.kind = CALL_OTHER; c.pkg[0] = 0;
|
||
CHECK(is_sys_identity(&c) == 0);
|
||
|
||
printf("== is_system_action ==\n");
|
||
CHECK(is_system_action(POWER_SHUTDOWN) == 1);
|
||
CHECK(is_system_action(POWER_REBOOT) == 1);
|
||
CHECK(is_system_action(POWER_UPGRADE) == 1);
|
||
CHECK(is_system_action(POWER_BACK_HIBY) == 1);
|
||
CHECK(is_system_action(POWER_SET_DEFAULT_MEOW) == 1);
|
||
CHECK(is_system_action(POWER_SET_DEFAULT_HIBY) == 1);
|
||
CHECK(is_system_action(POWER_STATUS) == 0);
|
||
CHECK(is_system_action(POWER_BATTERY) == 0);
|
||
CHECK(is_system_action(POWER_REBOOT_REASON) == 0);
|
||
CHECK(is_system_action(POWER_UPGRADE_STATUS) == 0);
|
||
CHECK(is_system_action(POWER_SCREEN) == 0);
|
||
CHECK(is_system_action(POWER_DAC) == 0);
|
||
|
||
if (g_fail) { printf("\nAUTH TEST: %d FAIL\n", g_fail); return 1; }
|
||
printf("\nAUTH TEST: ALL PASS\n");
|
||
return 0;
|
||
}
|