()
| 27 | |
| 28 | #[tokio::main] |
| 29 | async fn main() -> Result<()> { |
| 30 | let args: Vec<String> = std::env::args().collect(); |
| 31 | if args.len() != 2 { |
| 32 | eprintln!("Usage: {} <simulator_url>", args[0]); |
| 33 | eprintln!("Example: {} https://daee134c3b9f66aa2401c3b5ea64f1d34038f45d-3000.tdxlab.dstack.org:12004", args[0]); |
| 34 | std::process::exit(1); |
| 35 | } |
| 36 | let simulator_url = &args[1]; |
| 37 | |
| 38 | // Generate key pair |
| 39 | let key = KeyPair::generate().context("Failed to generate key")?; |
| 40 | let pubkey = key.public_key_der(); |
| 41 | let key_pem = key.serialize_pem(); |
| 42 | |
| 43 | // Calculate report_data |
| 44 | let report_data = QuoteContentType::RaTlsCert.to_report_data(&pubkey); |
| 45 | |
| 46 | // Get quote from simulator |
| 47 | println!("Getting quote from simulator: {simulator_url}"); |
| 48 | let simulator_client = PrpcClient::new(simulator_url.to_string()); |
| 49 | let simulator_client = DstackGuestClient::new(simulator_client); |
| 50 | let quote_response = simulator_client |
| 51 | .get_quote(RawQuoteArgs { |
| 52 | report_data: report_data.to_vec(), |
| 53 | }) |
| 54 | .await |
| 55 | .context("Failed to get quote from simulator")?; |
| 56 | |
| 57 | // Create debug key data structure |
| 58 | let debug_data = DebugKeyData { |
| 59 | key_pem, |
| 60 | quote_base64: STANDARD.encode("e_response.quote), |
| 61 | event_log: quote_response.event_log, |
| 62 | vm_config: quote_response.vm_config, |
| 63 | }; |
| 64 | |
| 65 | // Write to single JSON file |
| 66 | let json_content = |
| 67 | serde_json::to_string_pretty(&debug_data).context("Failed to serialize debug key data")?; |
| 68 | let output_file = "debug_key.json"; |
| 69 | fs_err::write(output_file, json_content).context("Failed to write debug key file")?; |
| 70 | |
| 71 | println!("✓ Successfully generated debug key data:"); |
| 72 | println!(" - {output_file}"); |
| 73 | println!("\nYou can now configure this path in your gateway config:"); |
| 74 | println!("[core.debug]"); |
| 75 | println!("insecure_skip_attestation = true"); |
| 76 | println!( |
| 77 | "key_file = \"{}\"", |
| 78 | fs_err::canonicalize(output_file) |
| 79 | .unwrap_or_default() |
| 80 | .display() |
| 81 | ); |
| 82 | |
| 83 | Ok(()) |
| 84 | } |
nothing calls this directly
no test coverage detected