aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / core / unlock_req.h
| 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 | /* unlock_req.h -- the card unlock request file of the Pi qualification image |
| 18 | * (PI5-4 cut 2, build flag CK_PI5_UNLOCK_CARD, only with CK_PI5_UNLOCK). |
| 19 | * |
| 20 | * QUALIFICATION ONLY. The Pi has no TPM and nothing reads its serial port |
| 21 | * during a run, so the run tool (pi5-run.sh UNLOCK_REQ=<file>) may place |
| 22 | * \EFI\AIENOS\UNLOCK.REQ on the card's EFI partition holding a THROWAWAY |
| 23 | * 32-byte recovery secret. The UEFI stub (native/boot/efi_unlock.c) reads it |
| 24 | * before ExitBootServices, the Store stage takes the secret exactly once and |
| 25 | * runs the same Slot 1 path an operator's `unlock <64-hex>` would. The file |
| 26 | * is deleted from the card after the run. A real operator secret must never |
| 27 | * be put in such a file: the tier tag below says so in the bytes themselves. |
| 28 | * |
| 29 | * File layout, exactly 512 bytes, little endian, everything else zero: |
| 30 | * 0 magic "AIENUNQ1" |
| 31 | * 8 version 1 |
| 32 | * 12 flags 0 |
| 33 | * 16 tier tag "QUALIF-THROWAWAY" (16 ASCII bytes, no NUL) |
| 34 | * 32 secret, 32 bytes (not all zero, not all one byte value) |
| 35 | * 64 zero padding to 512 |
| 36 | * The secret is never printed. */ |
| 37 | #ifndef AIENOS_CK_UNLOCK_REQ_H |
| 38 | #define AIENOS_CK_UNLOCK_REQ_H |
| 39 | #include <stddef.h> |
| 40 | #include <stdint.h> |
| 41 | |
| 42 | #define CK_UNLOCK_REQ_MAGIC "AIENUNQ1" |
| 43 | #define CK_UNLOCK_REQ_TAG "QUALIF-THROWAWAY" |
| 44 | #define CK_UNLOCK_REQ_VERSION 1u |
| 45 | #define CK_UNLOCK_REQ_SIZE 512u |
| 46 | #define CK_UNLOCK_REQ_SECRET_LEN 32u |
| 47 | #define CK_UNLOCK_REQ_PATH "\\EFI\\AIENOS\\UNLOCK.REQ" |
| 48 | #define CK_UNLOCK_REQ_SOURCE "card request file (QUALIFICATION ONLY, throwaway secret)" |
| 49 | |
| 50 | struct ck_unlock_req { |
| 51 | uint8_t magic[8]; |
| 52 | uint32_t version; |
| 53 | uint32_t flags; |
| 54 | uint8_t tag[16]; |
| 55 | uint8_t secret[CK_UNLOCK_REQ_SECRET_LEN]; |
| 56 | uint8_t pad[CK_UNLOCK_REQ_SIZE - 64]; |
| 57 | }; |
| 58 | |
| 59 | /* 0 = well formed; else -1 and *why names the first failed check (never the secret). */ |
| 60 | int ck_unlock_req_check(const struct ck_unlock_req *q, const char **why); |
| 61 | |
| 62 | enum { CK_UNLOCK_REQ_NONE = 0, CK_UNLOCK_REQ_ABSENT = 1, CK_UNLOCK_REQ_REFUSED = 2, CK_UNLOCK_REQ_FOUND = 3 }; |
| 63 | |
| 64 | /* What the UEFI stub found (shared with the kernel: the stub and the kernel are one image). */ |
| 65 | struct ck_unlock_req_boot { |
| 66 | int state; /* CK_UNLOCK_REQ_* */ |
| 67 | uint8_t secret[CK_UNLOCK_REQ_SECRET_LEN]; /* only while state is FOUND */ |
| 68 | }; |
| 69 | extern struct ck_unlock_req_boot ck_unlock_req_boot; |
| 70 | |
| 71 | /* The stub stores a checked request (state FOUND, secret copied). */ |
| 72 | void ck_unlock_req_store(const struct ck_unlock_req *q); |
| 73 | /* One-shot: copies the secret out and wipes the boot copy (state back to NONE) and returns 0; |
| 74 | * returns -1 and zeroes out when there is no found request (or it was already taken). */ |
| 75 | int ck_unlock_req_take(uint8_t out[CK_UNLOCK_REQ_SECRET_LEN]); |
| 76 | #endif |