-
Notifications
You must be signed in to change notification settings - Fork 12
refactor(attestation): move TCB measurement extraction to build time #1646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
00f656b
830e155
5d7b40e
9003998
829b3c1
c9e7a17
3126fb4
0256795
2aa90cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,96 @@ | ||||||||||
| use std::env; | ||||||||||
| use std::fs::{self, File}; | ||||||||||
| use std::io::Write; | ||||||||||
| use std::path::PathBuf; | ||||||||||
|
|
||||||||||
| fn main() { | ||||||||||
| // Location of assets/*.json | ||||||||||
| let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); | ||||||||||
| let assets_dir = PathBuf::from(manifest_dir).join("assets"); | ||||||||||
barakeinav1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
| // Find all tcb_info*.json files (prod, dev, future ones) | ||||||||||
| let mut measurement_files = Vec::new(); | ||||||||||
| for entry in fs::read_dir(&assets_dir).unwrap() { | ||||||||||
|
||||||||||
| let entry = entry.unwrap(); | ||||||||||
| let path = entry.path(); | ||||||||||
|
|
||||||||||
| if path.extension().and_then(|x| x.to_str()) == Some("json") | ||||||||||
| && path.file_name().unwrap().to_str().unwrap().starts_with("tcb_info") | ||||||||||
| { | ||||||||||
| measurement_files.push(path); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
barakeinav1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| // Output file | ||||||||||
| let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||||||||||
| let out_file = out_dir.join("measurements_generated.rs"); | ||||||||||
barakeinav1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| let mut f = File::create(out_file).unwrap(); | ||||||||||
|
|
||||||||||
| // Write prelude | ||||||||||
| writeln!( | ||||||||||
| f, | ||||||||||
| "// AUTO-GENERATED FILE. DO NOT EDIT.\n\ | ||||||||||
|
||||||||||
| "// AUTO-GENERATED FILE. DO NOT EDIT.\n\ | |
| "// AUTO-GENERATED FILE. DO NOT EDIT.\n\ | |
| // NOTE: This generated code assumes the module path `attestation::measurements::*` is available.\n\ | |
| // Ensure this file is included in a module that has access to these imports.\n\ |
Outdated
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build script panics with unwrap() at multiple points when parsing JSON. If a JSON file is malformed or missing required fields, the build will fail with an unhelpful panic. Consider using expect() with descriptive messages that include the filename and what field is missing or invalid. For example, "Failed to parse {filename}: missing 'mrtd' field" or "Failed to decode hex in {filename} for field 'rtmr0'".
Outdated
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated Rust code uses the Debug formatting for byte arrays which will produce a verbose output like [1, 2, 3, ...]. Consider formatting these arrays as hex literals instead (e.g., *b"hex_string_here" or using a custom formatting function) to make the generated code more compact and easier to read.
barakeinav1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||||||||||||
| # 📘 TCB Measurements Build Guide | ||||||||||||||
|
|
||||||||||||||
| ## 📁 Location of JSON Files | ||||||||||||||
| TCB measurement JSON files now live in: | ||||||||||||||
|
|
||||||||||||||
| ``` | ||||||||||||||
| crates/mpc-attestation/assets/ | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
|
||||||||||||||
| > **⚠️ Security Warning:** | |
| > **Do not edit TCB measurement JSON files directly in production environments.** | |
| > These files are critical for attestation and system security. | |
| > Any updates must go through proper validation and approval processes to prevent accidental or malicious changes. |
barakeinav1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should generate a crate that can be included using normal imports instead of using include!(...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before addressing this, please see my alternative proposal in: #1659
Uh oh!
There was an error while loading. Please reload this page.