### Run deps-install.sh to install dependencies Source: https://github.com/amdese/sev-tool/blob/master/readme.md Installs git, make, gcc, g++, and openssl dependencies automatically. Run this before cloning and building the SEV-Tool. ```sh $ bash deps-install.sh ``` -------------------------------- ### factory_reset usage example Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/command.md Shows how to call factory_reset on a Command object and check the return status. On failure, handle the firmware error as described in errors.md. ```cpp Command cmd("./", 1, CCP_REQ); int ret = cmd.factory_reset(); if (ret != STATUS_SUCCESS) { /* handle firmware error, see errors.md */ } ``` -------------------------------- ### Example ccp SEV API Output Source: https://github.com/amdese/sev-tool/blob/master/readme.md Example dmesg output from Ubuntu 18.10 with Kernel 4.18.0-15-generic, showing that the ccp driver successfully ran the Init command against the SEV firmware. ```sh $ ccp [0000:01:00.2]: SEV API:0.17 build:5 ``` -------------------------------- ### Generate launch blob with sevtool --generate_launch_blob Source: https://github.com/amdese/sev-tool/blob/master/readme.md Generates the launch blob and Guest Owner DH public key certificate for LaunchStart. The first command shows the required guest policy argument; the second is a concrete example with policy 39. Outputs launch_blob.bin and godh.cert (plus godh_pubkey.pem and godh_privkey.pem, which are for SEV-Tool use only). The blob is binary and must be converted to base64 before importing to QEMU. ```sh $ sudo ./sevtool --ofolder ./certs --generate_launch_blob [guest policy] $ sudo ./sevtool --ofolder ./certs --generate_launch_blob 39 ``` -------------------------------- ### Calculate guest measurement with sevtool --calc_measurement Source: https://github.com/amdese/sev-tool/blob/master/readme.md Calculates the launch measurement for a guest. The first command shows the argument order; the second is a concrete example with a sample digest, MNonce, and TIK. Output includes the calculated measurement and 'Command Successful'. For security, the TIK is not displayed when the user runs the tool. ```sh $ sudo ./sevtool --calc_measurement [Context] [Api Major] [Api Minor] [Build ID] [Policy] [Digest] [MNonce] [TIK] $ sudo ./sevtool --ofolder ./certs --calc_measurement 04 00 12 0f 00 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 4fbe0bedbad6c86ae8f68971d103e554 66320db73158a35a255d051758e95ed4 You have entered 10 arguments Command: calc_measurement Input Arguments: Context: 04 Api Major: 00 Api Minor: 12 Build ID: 0f Policy: 00 Digest: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 MNonce: 4fbe0bedbad6c86ae8f68971d103e554 TIK: 66320db73158a35a255d051758e95ed4 Output Measurement: 6faab2daae389bcd3405a05d6cafe33c0414f7bedd0bae19ba5f38b7fd1664ea Command Successful ``` -------------------------------- ### SEVCert::create_godh_cert usage example Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevcert.md Shows how to create a GODH cert: generate an ECDH key pair, then call create_godh_cert with API major/minor 0. The godh_cert holds the GODH public key for the launch blob. ```cpp sev_cert godh_cert; SEVCert cert_obj(&godh_cert); EVP_PKEY *key = NULL; if (!generate_ecdh_key_pair(&key)) { /* error */ } if (!cert_obj.create_godh_cert(&key, 0, 0)) { /* error */ } // godh_cert now holds the GODH public key for the launch blob ``` -------------------------------- ### generate_ecdh_key_pair usage example Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/crypto.md Shows how to generate an ECDH key pair and free the resulting EVP_PKEY with EVP_PKEY_free. ```cpp EVP_PKEY *godh = NULL; if (!generate_ecdh_key_pair(&godh)) { /* keygen failed */ } // use godh for the GODH cert and session buffer EVP_PKEY_free(godh); ``` -------------------------------- ### Manually install dependencies on Debian/Ubuntu Source: https://github.com/amdese/sev-tool/blob/master/readme.md Manually installs dependencies on Debian or Ubuntu systems. Use this alternative to deps-install.sh when you prefer manual installation. ```sh $ sudo apt install git make gcc g++ -y --allow-unauthenticated ``` -------------------------------- ### Command class usage examples Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/command.md Shows three typical Command usages: exporting the PDH certificate chain (requires CCP_REQ and /dev/sev), generating a launch blob for a guest policy (no firmware access needed), and performing the full ownership-transfer flow via set_externally_owned. Each returns a status code; non-success indicates a firmware error or one of the four sub-stages failed. ```cpp // Platform owner: export PDH certificate chain to an existing directory Command cmd("/srv/certs/", 1); // CCP_REQ default → opens /dev/sev int ret = cmd.pdh_cert_export(); if (ret != STATUS_SUCCESS) { /* firmware error code, see errors.md */ } // Guest owner: generate the launch blob for a guest policy of 0x39 Command go("./go-assets/", 0, CCP_NOT_REQ); // no firmware access needed go.generate_launch_blob(0x39); // Full ownership-transfer flow in one call Command po("./certs/", 0); int rc = po.set_externally_owned("oca_priv.pem"); if (rc != STATUS_SUCCESS) { /* one of the four sub-stages failed */ } ``` -------------------------------- ### verify_sev_cert usage example Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevcert.md Example usage of verify_sev_cert: creates a SEVCert object for a PEK certificate and verifies it against CEK and OCA parent certificates. The comment indicates the PEK is signed by both CEK and OCA. ```cpp sev_cert pek, cek, oca; SEVCert pek_obj(&pek); SEV_ERROR_CODE rc = pek_obj.verify_sev_cert(&cek, &oca); // PEK signed by CEK and OCA if (rc != STATUS_SUCCESS) { /* certificate chain invalid */ } ``` -------------------------------- ### Error path for pek_cert_import Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/cli.md Error path example showing an argument count mismatch. The command is rejected before dispatch, printing the error message 'Error: Expecting exactly 2 args for pek_cert_import'. ```sh sudo ./sevtool --pek_cert_import only_one_file.cert # prints: Error: Expecting exactly 2 args for pek_cert_import ``` -------------------------------- ### Get ASK ARK certificate with sevtool Source: https://github.com/amdese/sev-tool/blob/master/readme.md Retrieves the ask_ark certificate from the SEV Developer website. Exports ask_ark.cert to the specified folder or the executable's directory if --ofolder is not used. ```sh $ sudo ./sevtool --ofolder ./certs --get_ask_ark ``` -------------------------------- ### calculate_shared_secret usage example Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/crypto.md Shows how to call calculate_shared_secret and free the returned buffer with OPENSSL_free. ```cpp EVP_PKEY *priv = /* ... */, *peer = /* ... */; size_t len = 0; uint8_t *secret = calculate_shared_secret(priv, peer, len); if (!secret) { /* derive failed */ } // ... use secret ... OPENSSL_free(secret); // mandatory ``` -------------------------------- ### SEV launch command buffer structs (sev_launch_start_cmd_buf, sev_launch_update_data_cmd_buf, sev_launch_measure_cmd_buf, sev_launch_secret_cmd_buf) Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevapi.md Packed command buffer structs for SEV launch operations: launch start, update data, measure, and secret. These are used to pass parameters to the corresponding SEV firmware commands. ```cpp typedef struct __attribute__ ((__packed__)) sev_launch_start_cmd_buf_t { uint32_t handle; SEV_POLICY policy; // SEV_POLICY uint64_t gdh_cert_p_addr; // sev_cert uint32_t gdh_cert_len; uint32_t reserved; uint64_t session_p_addr; // sev_session_buf uint32_t session_l_en; } sev_launch_start_cmd_buf; // :901 typedef struct __attribute__ ((__packed__)) sev_launch_update_data_cmd_buf_t { uint32_t handle; uint32_t reserved; uint64_t data_p_addr; uint32_t data_len; } sev_launch_update_data_cmd_buf; // :912 typedef struct __attribute__ ((__packed__)) sev_launch_measure_cmd_buf_t { uint32_t handle; uint32_t reserved; uint64_t measure_p_addr; uint32_t measure_len; } sev_launch_measure_cmd_buf; // :928 typedef struct __attribute__ ((__packed__)) sev_launch_secret_cmd_buf_t { uint32_t handle; uint32_t reserved_0; uint64_t hdr_p_addr; // sev_hdr_buf uint32_t hdr_len; uint32_t reserved_1; uint64_t guest_p_addr; uint32_t guest_len; uint32_t reserved_2; uint64_t trans_p_addr; uint32_t trans_len; } sev_launch_secret_cmd_buf; // :936 ``` -------------------------------- ### Validate VCEK certificate chain Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/x509cert.md Complete example of validating the VCEK→ASK→ARK certificate chain from three .pem files. It reads each certificate with `read_pem_into_x509` and validates the signatures with `x509_validate_signature`, then frees the certificates and checks the result. ```cpp #include "x509cert.h" // Validate the VCEK→ASK→ARK chain from three .pem files X509 *ark = NULL, *ask = NULL, *vcek = NULL; bool ok = read_pem_into_x509("ark.pem", &ark) && read_pem_into_x509("ask.pem", &ask) && read_pem_into_x509("vcek.pem", &vcek) && x509_validate_signature(ark, NULL, ark) // ARK self-signature && x509_validate_signature(ask, NULL, ark) // ASK signed by ARK && x509_validate_signature(vcek, ask, ark); // VCEK signed by ASK X509_free(ark); X509_free(ask); X509_free(vcek); if (!ok) { /* chain invalid */ } ``` -------------------------------- ### write_file declaration and usage Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/utilities.md Truncates and writes len bytes (does not append; the directory must already exist). Returns bytes written (0 on failure or len > INT_MAX). Prints "Writing to file: " on success. The example shows a call with a certificate buffer. ```cpp size_t write_file(const std::string file_name, const void *buffer, size_t len); ``` ```cpp sev::write_file(out_path, &my_cert, sizeof(sev_cert)); ``` -------------------------------- ### Module graph: main.cpp to Command to SEVDevice Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/index.md Shows the module dependency graph of the SEV-Tool binary, illustrating how main.cpp drives the Command class, which uses SEVDevice for /dev/sev ioctls and various helper modules for certificate and crypto operations. ```text main.cpp ──▶ Command (commands.h/.cpp) ──▶ SEVDevice (sevcore.h, sevcore_linux.cpp) ──▶ /dev/sev ioctl (psp-sev.h) │ ▲ │ │ └─ sevcert.h (SEVCert) └─ sevapi.h (command buffers, sev_cert) │ amdcert.h (AMDCert) rmp.h (SNP types) │ crypto.h (free functions) x509cert.h (X.509 helpers) └─ utilities.h (sev:: helpers) main.cpp ──▶ Tests (tests.h/.cpp) ──▶ Command (same chain) ``` -------------------------------- ### Derive launch keys and sign a launch-blob header with crypto.h Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/crypto.md Shows how to derive the guest-owner launch keys (master, KEK, KIK) from the PDH certificate and a nonce, then sign a launch-blob header body with the OCA private key using SEV_SIG_ALGO_ECDSA_SHA256. Boolean-returning helpers return false on any failure; the two GCM functions return SEV_ERROR_CODE instead. ```cpp #include "crypto.h" // Derive the guest-owner launch keys from the PDH cert and a nonce aes_128_key master, kek; hmac_key_128 kik; if (!derive_master_secret(master, godh_priv, &pdh_cert, nonce)) { /* failed */ } derive_kek(kek, master); derive_kik(kik, master); // Sign a launch-blob header body and verify it sev_sig signature; if (!sign_message(&signature, &oca_priv, header_bytes, header_len, SEV_SIG_ALGO_ECDSA_SHA256)) { /* signing failed */ } ``` -------------------------------- ### get_file_size Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/utilities.md Gets the size of a file. ```APIDOC ## `get_file_size` ### Description Returns the size of a file in bytes. Returns 0 if the file does not exist or is empty. Also used as an existence check before re-downloading certificates. ### Signature ```cpp size_t get_file_size(const std::string file_name); ``` ### Parameters - **file_name** (const std::string) - Required - Path to the file. ### Return Value - **size_t** - File size in bytes; 0 if the file does not exist or is empty. ### Notes - Implementation: `src/utilities.cpp:107`. ``` -------------------------------- ### Allocate SEV platform-status buffer and build SEV-ES guest policy Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevapi.md Shows how to allocate and zero a platform-status command buffer and build a guest policy for a non-debuggable SEV-ES guest. The buffer is passed to SEVDevice::platform_status(). No runtime errors originate here because these are plain packed structs. ```cpp #include "sevapi.h" // Allocate and issue the SEV platform-status command buffer via /dev/sev sev_platform_status_cmd_buf status; memset(&status, 0, sizeof(status)); /* ... passed through SEVDevice::platform_status((uint8_t*)&status) ... */ // Build a guest policy for a normal, non-debuggable SEV-ES guest uint32_t policy = SEV_POLICY_NODBG | SEV_POLICY_NOKS | SEV_POLICY_ES; ``` -------------------------------- ### --generate_launch_blob Source: https://github.com/amdese/sev-tool/blob/master/readme.md CLI command to generate the launch blob and Guest Owner DH public key certificate. ```APIDOC ## [CLI] --generate_launch_blob ### Description Imports the PDH certificate from the Platform and builds the Launch_Start session buffer (blob) and the Guest Owner Diffie-Hellman public key certificate. It generates a new public/private Diffie-Hellman keypair for the Guest Owner, calculates a shared secret, and derives a master secret, TEK, and TIK. ### Method CLI command ### Endpoint `sudo ./sevtool --ofolder [folder_path] --generate_launch_blob [guest policy]` ### Parameters #### Command Arguments - **guest policy** (hex) - Required - The guest policy in hex format. #### Optional Flags - **--ofolder [folder_path]** - Optional - Specifies the folder where the tool will export the blob file to. ### Request Example ```sh $ sudo ./sevtool --ofolder ./certs --generate_launch_blob 39 ``` ### Response #### Success Response - **launch_blob.bin** - The launch blob file (binary). - **godh.cert** - The Guest Owner DH public key certificate. - **godh_pubkey.pem** - Guest Owner DH public key (ignore). - **godh_privkey.pem** - Guest Owner DH private key (ignore). #### Response Example No explicit response example provided. ``` -------------------------------- ### Display SEV-Tool help menu Source: https://github.com/amdese/sev-tool/blob/master/readme.md Runs the SEV-Tool with the help flag (-h or --help) to display usage instructions and input parameters. ```sh $ sudo ./sevtool -h ``` -------------------------------- ### Read sev_cert and generate random nonce with sev::read_file and sev::gen_random_bytes Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/utilities.md Shows how to read a sev_cert from disk using sev::read_file, checking the return value against sizeof(sev_cert) to detect missing or truncated files, and how to generate a random nonce for a session buffer with sev::gen_random_bytes. Error handling is C-style with size_t/bool returns; the module never throws, and file-path failures are indicated by 0 bytes read/written. ```cpp #include "utilities.h" // Read a sev_cert from disk, verify it exists with the exact size sev_cert pek; if (sev::read_file("pek.cert", &pek, sizeof(sev_cert)) != sizeof(sev_cert)) { /* file missing or truncated */ } // Random nonce for a session buffer nonce_128 nonce; sev::gen_random_bytes(nonce, sizeof(nonce_128)); ``` -------------------------------- ### SEV command indices enum Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/psp-sev.md Defines the Linux ioctl command indices for SEV operations, starting at 0 and incrementing. Note that SEV_GET_ID is deprecated in favor of SEV_GET_ID2, and the SEV_SNP_* values are distinct from firmware SEV_API_COMMAND IDs. ```c enum { SEV_FACTORY_RESET = 0, SEV_PLATFORM_STATUS, // 0x1 SEV_PEK_GEN, // 0x2 SEV_PEK_CSR, // 0x3 SEV_PDH_GEN, // 0x4 SEV_PDH_CERT_EXPORT, // 0x5 SEV_PEK_CERT_IMPORT, // 0x6 SEV_GET_ID, // deprecated, use SEV_GET_ID2 SEV_GET_ID2, // 0x8 SEV_SNP_PLATFORM_STATUS, // 0x9 SEV_SNP_SET_EXT_CONFIG, // 0xA SEV_SNP_GET_EXT_CONFIG, // 0xB SEV_MAX, }; ``` -------------------------------- ### Catch std::runtime_error when constructing Command with CCP_REQ default Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/errors.md Shows how to catch the std::runtime_error thrown when constructing a Command with the default CCP_REQ flag, which attempts to open /dev/sev. The example prints the error message to std::cerr. ```cpp try { Command cmd("./certs/", 0); // CCP_REQ default → opens /dev/sev cmd.platform_status(); } catch (const std::runtime_error &e) { // e.g. running on a kernel without /dev/sev std::cerr << e.what(); // "Can't open /dev/sev!\n" } ``` -------------------------------- ### SEVDevice::get_sev_device() Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevdevice.md Acquires the singleton SEVDevice instance. Throws std::runtime_error if /dev/sev cannot be opened. ```APIDOC ## SEVDevice::get_sev_device() ### Description Acquires the singleton SEVDevice instance. Throws std::runtime_error if /dev/sev cannot be opened. ### Method N/A (C++ static method) ### Endpoint N/A ### Parameters None ### Request Example ```cpp SEVDevice& dev = SEVDevice::get_sev_device(); ``` ### Response #### Success Response - **SEVDevice&** - Reference to the singleton device #### Response Example ```cpp SEVDevice& dev = SEVDevice::get_sev_device(); ``` ### Error Handling - Throws `std::runtime_error` if `/dev/sev` cannot be opened. ``` -------------------------------- ### Run sevtool test_all Source: https://github.com/amdese/sev-tool/blob/master/readme.md Run the test_all command to verify each sevtool command functions correctly. Requires the --ofolder argument pointing to a directory that will be cleared before tests run. ```sh $ sudo ./sevtool --ofolder ./tests --test_all ``` -------------------------------- ### SEV PEK CSR ioctl usage Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/psp-sev.md Example usage of the SEV ioctl interface to request a PEK CSR. The include resolves via -I../lib. Setting length to 0 on the first pass requests the minimum size. ```cpp #include "psp-sev.h" // resolved via -I../lib sev_user_data_pek_csr csr_buf = {0}; csr_buf.address = (uint64_t)pek_mem; csr_buf.length = 0; // first pass: request MinSize int ioctl_ret = ioctl(fd, SEV_ISSUE_CMD, &(sev_issue_cmd){SEV_PEK_CSR, (uint64_t)&csr_buf, 0}); ``` -------------------------------- ### get_ask_ark_pem Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevdevice.md Downloads the certificate chain from AMD's KDS interface and splits it into separate ASK and ARK PEM files using csplit. Creates the default directory if missing. ```APIDOC ## get_ask_ark_pem ### Description `wget -O "https://kdsintf.amd.com/vcek/v1/Milan/cert_chain"`, then `csplit` into two PEM files renamed to `ask_file`/`ark_file`; creates `SEV_DEFAULT_DIR` (`/usr/psp-sev-assets/`) if missing. ### Method Function ### Signature ```cpp int get_ask_ark_pem(const std::string output_folder, const std::string cert_chain_file, const std::string ask_file, const std::string ark_file); ``` ### Parameters - **output_folder** (std::string) - Folder where the certificate chain and split PEM files will be saved. - **cert_chain_file** (std::string) - Name of the downloaded certificate chain file. - **ask_file** (std::string) - Name for the ASK PEM file. - **ark_file** (std::string) - Name for the ARK PEM file. ### Returns - **int** - Status code (0 on success, non-zero on failure). ``` -------------------------------- ### Build SEV-Tool with autoreconf, configure, make Source: https://github.com/amdese/sev-tool/blob/master/readme.md Builds the SEV-Tool. The build script downloads, configures, and builds the OpenSSL Git code (submodule init/update), then cleans and builds the SEV-Tool. ```sh $ cd sev-tool $ autoreconf -vif && ./configure && make && cp src/sevtool . ``` -------------------------------- ### Define constants and macros in src/utilities.h Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/utilities.md Defines the default assets directory, KDS server endpoints, page sizes, and alignment macros used across the tool. The KDS endpoints are used by SEVDevice::generate_cek_ask / generate_vcek_ask and sev::get_ask_ark_pem. ```cpp #define SEV_DEFAULT_DIR "/usr/psp-sev-assets/" #define KDS_CERT_SITE "https://kdsintf.amd.com" #define KDS_DEV_CERT_SITE "https://kdsintfdev.amd.com" #define KDS_CEK KDS_CERT_SITE "/cek/id/" #define KDS_VCEK KDS_CERT_SITE "/vcek/v1/" // KDS_VCEK/{product_name}/{hwid}?{tcb parameter list} #define KDS_VCEK_CERT_CHAIN "cert_chain" // KDS_VCEK/{product_name}/cert_chain #define KDS_VCEK_CRL "crl" // KDS_VCEK/{product_name}/crl #define PAGE_SIZE 4096 #define PAGE_SIZE_4K 4096 #define PAGE_SIZE_2M (512*PAGE_SIZE_4K) #define IS_ALIGNED(e, x) (0==(((uintptr_t)(e))%(x))) #define IS_ALIGNED_TO_16_BYTES(e) IS_ALIGNED((e), 16) #define IS_ALIGNED_TO_32_BYTES(e) IS_ALIGNED((e), 32) #define IS_ALIGNED_TO_64_BYTES(e) IS_ALIGNED((e), 64) #define IS_ALIGNED_TO_128_BYTES(e) IS_ALIGNED((e), 128) #define IS_ALIGNED_TO_4KB(e) IS_ALIGNED((e), 4096) #define IS_ALIGNED_TO_1MB(e) IS_ALIGNED((e), 0x100000) #define IS_ALIGNED_TO_2MB(e) IS_ALIGNED((e), 0x200000) #define ALIGN_TO_16_BYTES(e) ((((uintptr_t)(e))+0xF)&(~(uintptr_t)0xF)) #define ALIGN_TO_32_BYTES(e) ((((uintptr_t)(e))+0x1F)&(~(uintptr_t)0x1F)) #define ALIGN_TO_64_BYTES(e) ((((uintptr_t)(e))+0x3F)&(~(uintptr_t)0x3F)) #define BITS_PER_BYTE 8 ``` -------------------------------- ### str_to_array declaration and usage Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/utilities.md Converts an ascii-encoded hex string ("0123456ACF") into a byte array. Requires array_size >= in_string.size()/2 (odd-length strings are not an error here; the loop parses size()/2 pairs). Returns false only if the buffer is too small. The example shows converting a SHA-256 digest string. ```cpp bool str_to_array(const std::string in_string, uint8_t *array, uint32_t array_size); ``` ```cpp uint8_t digest[SHA256_DIGEST_LENGTH]; bool ok = sev::str_to_array("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", digest, sizeof(digest)); ``` -------------------------------- ### Command::generate_launch_blob Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/command.md Generates the launch blob for a given guest policy. This method is used by the guest owner and does not require firmware access. ```APIDOC ## Command::generate_launch_blob ### Description Generates the launch blob for a given guest policy. This method is used by the guest owner and does not require firmware access. ### Method Command method ### Endpoint Command::generate_launch_blob(uint32_t policy) ### Parameters #### Parameters - **policy** (uint32_t) - Required - The guest policy value. ### Request Example ```cpp Command go("./go-assets/", 0, CCP_NOT_REQ); // no firmware access needed go.generate_launch_blob(0x39); ``` ### Response No explicit return value documented. ``` -------------------------------- ### SEV_ERROR_CODE enum definition from src/sevapi.h Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevapi.md Defines the SEV_ERROR_CODE enum used throughout the sev-tool API. The first 0x00-0x18 values cover legacy SEV errors; the SNP-specific errors start at 0x19. The enum uses the __attribute__((mode(HI))) to force a 16-bit type. Full per-code semantics are documented in errors.md. ```cpp typedef enum __attribute__((mode(HI))) SEV_ERROR_CODE { STATUS_SUCCESS = 0x00, ERROR_INVALID_PLATFORM_STATE = 0x01, ERROR_INVALID_GUEST_STATE = 0x02, ERROR_INVALID_CONFIG = 0x03, ERROR_INVALID_LENGTH = 0x04, ERROR_ALREADY_OWNED = 0x05, ERROR_INVALID_CERTIFICATE = 0x06, ERROR_POLICY_FAILURE = 0x07, ERROR_INACTIVE = 0x08, ERROR_INVALID_ADDRESS = 0x09, ERROR_BAD_SIGNATURE = 0x0A, ERROR_BAD_MEASUREMENT = 0x0B, ERROR_ASID_OWNED = 0x0C, ERROR_INVALID_ASID = 0x0D, ERROR_WBINVD_REQUIRED = 0x0E, ERROR_DF_FLUSH_REQUIRED = 0x0F, ERROR_INVALID_GUEST = 0x10, ERROR_INVALID_COMMAND = 0x11, ERROR_ACTIVE = 0x12, ERROR_HWERROR_PLATFORM = 0x13, ERROR_HWERROR_UNSAFE = 0x14, ERROR_UNSUPPORTED = 0x15, ERROR_INVALID_PARAM = 0x16, ERROR_RESOURCE_LIMIT = 0x17, ERROR_SECURE_DATA_INVALID = 0x18, /* SNP */ ERROR_INVALID_PAGE_SIZE = 0x19, ERROR_INVALID_PAGE_STATE = 0x1A, ERROR_INVALID_MDATA_ENTRY = 0x1B, ERROR_INVALID_PAGE_OWNER = 0x1C, ERROR_AEAD_OFLOW = 0x1D, ERROR_RING_BUFFER_EXIT = 0x1F, ERROR_LIMIT, } SEV_ERROR_CODE; ``` -------------------------------- ### Create OCA SEV certificate with SEVCert Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevcert.md Shows how to read an OCA private key from a PEM file and create an OCA SEV certificate using the SEVCert class. The creation API returns a bool, while the validation API returns SEV_ERROR_CODE values. ```cpp #include "sevcert.h" // Read an OCA private key (PEM) and create the OCA SEV certificate EVP_PKEY *oca_key = NULL; if (!read_priv_key_pem_into_evpkey("oca_priv.pem", &oca_key)) { /* bad pem */ } sev_cert oca_cert_buf; SEVCert oca_obj(&oca_cert_buf); bool ok = oca_obj.create_oca_cert(&oca_key, SEV_SIG_ALGO_ECDSA_SHA256); // ... EVP_PKEY_free(oca_key); ``` -------------------------------- ### Basic help and informational flags Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/cli.md Basic help and informational flags for the sevtool CLI. The first command shows help, the second retrieves system info and ID, and the third uses a custom output folder with verbose mode. ```sh sudo ./sevtool -h sudo ./sevtool --sys_info --get_id sudo ./sevtool --ofolder ./certs --verbose --get_id ``` -------------------------------- ### Download and extract ARK/ASK certificates Source: https://github.com/amdese/sev-tool/blob/master/readme.md Downloads and extracts the ARK and ASK certificates from the AMD KDS server for verification. The script handles both naples and rome processors by setting the appropriate ask_size. It downloads the combined certificate, extracts the ASK, and creates a zero-filled ARK file with the ASK appended. ```sh # Example for naples and rome processors device_type=naples if [[ $device_type == naples ]]; ask_size=832; else device_type=rome; ask_size=1600; fi wget https://developer.amd.com/wp-content/resources/ask_ark_$device_type.cert head -c $ask_size ask_ark_$device_type.cert > ask.cert dd < /dev/zero bs=$ask_size count=1 > ark.cert dd conv=notrunc if=ask_ark_$device_type.cert of=ark.cert skip=$ask_size iflag=skip_bytes ``` -------------------------------- ### amd_cert_init Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/amdcert.md Parses a raw buffer into an amd_cert structure, copying the fixed header and variable-length sections. ```APIDOC ## amd_cert_init ### Description Parses a raw buffer into an `amd_cert` structure. Copies the 64-byte fixed header and then places the variable-length sections (pub_exp, modulus, sig) at computed offsets. ### Method Function ### Signature ```cpp SEV_ERROR_CODE amd_cert_init(amd_cert *cert, const uint8_t *buffer); ``` ### Parameters - **cert** (amd_cert*) - Required - Pointer to the output certificate structure. - **buffer** (const uint8_t*) - Required - Pointer to the raw certificate data. ### Returns - **SEV_ERROR_CODE** - `STATUS_SUCCESS` on success, or `ERROR_INVALID_PARAM` on invalid input. ``` -------------------------------- ### sev_session_buf struct definition Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevapi.md Packed LAUNCH_START session buffer (launch blob) containing nonce, wrapped transport keys, IV, and two HMACs. Written verbatim as launch_blob.bin by Command::generate_launch_blob. ```cpp typedef struct __attribute__ ((__packed__)) sev_session_buf_t { nonce_128 nonce; tek_tik wrap_tk; iv_128 wrap_iv; hmac_sha_256 wrap_mac; hmac_sha_256 policy_mac; } sev_session_buf; ``` -------------------------------- ### SEV OS Support Matrix Source: https://github.com/amdese/sev-tool/blob/master/readme.md Lists Linux distributions and versions that support SEV as a guest or host. The table indicates which OS versions can run SEV guests and which can act as SEV hosts. ```text SEV Guest SEV Host (VM) (Hypervisor) Linux® 4.15 Y Linux® 4.16 Y Y RHEL 7.6 Y RHEL 8 Y Y Fedora 28 Y Y SLES 15 Y Y Ubuntu 18.04 Y Ubuntu 10.10, 19.04 Y Y Oracle Linux UEK 5 Y Y VMWare - Support in Upcoming version of vSphere OpenStack - Support Upstream ``` -------------------------------- ### AMDCert::amd_cert_init Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/amdcert.md Initializes an amd_cert structure from a buffer containing certificate data. Returns STATUS_SUCCESS on success or an error code on failure. ```APIDOC ## amd_cert_init ### Description Initializes an `amd_cert` structure from a buffer containing certificate data. ### Method Function call ### Signature `SEV_ERROR_CODE amd_cert_init(amd_cert *cert, uint8_t *buf)` ### Parameters - **cert** (amd_cert*) - Required - Pointer to the certificate structure to initialize. - **buf** (uint8_t*) - Required - Buffer containing the certificate data. ### Return Value - `STATUS_SUCCESS` on success - `ERROR_INVALID_CERTIFICATE` or `ERROR_INVALID_PARAM` on failure ### Example ```cpp AMDCert amd; amd_cert ask; if (amd.amd_cert_init(&ask, ask_ark_buf) != STATUS_SUCCESS) { /* parse error */ } ``` ``` -------------------------------- ### get_ask_ark Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevdevice.md Downloads the ASK and ARK certificate files from the appropriate site based on device type using wget. Skips download if the file already exists and is non-empty. ```APIDOC ## get_ask_ark ### Description `wget -O ` per device type; no re-download if file non-empty; returns `SEV_RET_SUCCESS` (0) or `SEV_RET_UNSUPPORTED` (23). ### Method Function ### Signature ```cpp int get_ask_ark(const std::string output_folder, const std::string cert_file); ``` ### Parameters - **output_folder** (std::string) - Folder where the certificate file will be saved. - **cert_file** (std::string) - Name of the certificate file to download. ### Returns - **int** - `SEV_RET_SUCCESS` (0) on success, `SEV_RET_UNSUPPORTED` (23) on unsupported device type. ``` -------------------------------- ### Validate guest report with VCEK (--validate_guest_report) Source: https://github.com/amdese/sev-tool/blob/master/readme.md Validates that the guest report (guest_report.bin) was signed by the VCEK (vcek.pem). Reads guest_report.bin and vcek.pem from the folder specified by --ofolder, or from the default folder if not provided. Produces no output files. ```sh $ sudo ./sevtool --ofolder ./certs --validate_guest_report ``` -------------------------------- ### CLI --get_ask_ark Source: https://github.com/amdese/sev-tool/blob/master/readme.md Command to retrieve the ASK_ARK certificate. ```APIDOC ## [CLI] --get_ask_ark ### Description This command retrieves the ASK_ARK certificate from the AMD KDS server. ### Method CLI ### Endpoint `sevtool --get_ask_ark` ### Parameters #### Optional Arguments - `--ofolder [folder_path]` (string) - Optional - Specifies the folder where the tool will export the ask_ark certificate to. ### Request Example ```sh $ sudo ./sevtool --ofolder ./certs --get_ask_ark ``` ### Response #### Success Response - **File**: `ask_ark.cert` - The ark_ark certificate will be exported to the folder specified. Otherwise, it will be exported to the same directory as the SEV-Tool executable. ### Notes - Platform/Guest Owner: Guest Owner - Files read in: none ``` -------------------------------- ### generate_cek_ask Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/command.md Delegates to SEVDevice::generate_cek_ask(m_output_folder, "cek.cert"): GET_ID to obtain the socket-0 platform ID, wget to KDS_CEK (https://kdsintf.amd.com/cek/id/), retry loop (6 s sleeps, ~3 retries), renames the ID-named download to cek.cert. ```APIDOC ## generate_cek_ask ### Description Delegates to SEVDevice::generate_cek_ask(m_output_folder, "cek.cert"): GET_ID to obtain the socket-0 platform ID, wget to KDS_CEK (https://kdsintf.amd.com/cek/id/), retry loop (6 s sleeps, ~3 retries), renames the ID-named download to cek.cert. ### Method C++ function ### Signature ```cpp int generate_cek_ask(void); ``` ### Parameters None ### Return Value - `int` - Returns the device return code. `STATUS_SUCCESS` (0) on success or a firmware `SEV_ERROR_CODE`/ioctl code. ### Behavior Delegates to `SEVDevice::generate_cek_ask(m_output_folder, "cek.cert")`: GET_ID to obtain the socket-0 platform ID, `wget` to `KDS_CEK` (`https://kdsintf.amd.com/cek/id/`), retry loop (6 s sleeps, ~3 retries), renames the ID-named download to `cek.cert`. ``` -------------------------------- ### Run self-tests with --test_all Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/tests.md Command to run the self-test suite. The tool clears the ./tests directory before running, so a dedicated directory is required. ```sh sudo ./sevtool --ofolder ./tests --test_all ``` -------------------------------- ### platform_status command Source: https://github.com/amdese/sev-tool/blob/master/readme.md Prints the current platform status to the screen. ```sh $ sudo ./sevtool --platform_status ``` -------------------------------- ### SEVDevice class definition (src/sevcore.h:90) Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevdevice.md Defines the SEVDevice singleton class with a private constructor, deleted copy/assignment, and public static factory. The class is non-copyable and non-assignable. ```cpp class SEVDevice { private: int mFd; inline int get_fd(void) { return mFd; } int sev_ioctl(int cmd, void *data, int *cmd_ret); std::string display_build_info(void); SEVDevice(void) = default; SEVDevice(const SEVDevice&) = delete; SEVDevice& operator=(const SEVDevice&) = delete; public: static SEVDevice& get_sev_device(void); ~SEVDevice(void); ... }; ``` -------------------------------- ### Usage of read_pem_into_x509 Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/x509cert.md Shows how to call `read_pem_into_x509` to load a PEM file into an X509 pointer, check for failure, and free the allocated certificate with `X509_free`. ```cpp X509 *vcek = NULL; if (!read_pem_into_x509("vcek.pem", &vcek)) { /* missing or malformed PEM */ } // ... X509_free(vcek); ``` -------------------------------- ### CLI --generate_cek_ask Source: https://github.com/amdese/sev-tool/blob/master/readme.md Command to generate the CEK_ASK certificate by querying the AMD KDS server. ```APIDOC ## [CLI] --generate_cek_ask ### Description This command calls the get_id command and passes that ID into the AMD KDS server to retrieve the cek_ask. If the command returns an error while connecting to the KDS server, please try the command again. ### Method CLI ### Endpoint `sevtool --generate_cek_ask` ### Parameters #### Optional Arguments - `--ofolder [folder_path]` (string) - Optional - Specifies the folder where the tool will export the cek_ark.cert to. ### Request Example ```sh $ sudo ./sevtool --ofolder ./certs --generate_cek_ask ``` ### Response #### Success Response - **File**: `cek_ask.cert` - The cek_ask.cert file for your specific platform (processor in socket0) will be exported to the folder specified. Otherwise, it will be exported to the same directory as the SEV-Tool executable. ### Notes - Platform/Guest Owner: Platform Owner - Files read in: none ``` -------------------------------- ### SEV command buffer structs (sev_init_cmd_buf, sev_platform_status_cmd_buf, etc.) Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/sevapi.md Command buffer structures for SEV platform management commands, defined in src/sevapi.h:730-853. Each struct is packed and contains physical addresses and lengths for command-specific data. Note the constraints: tmr_phys_addr must be 1MB aligned and ignored if CONFIG_ES is 0; sev_init_ex_cmd_buf length must be 0x24 and nv_length must be 32KB. ```cpp typedef struct __attribute__ ((__packed__)) sev_init_cmd_buf_t { uint32_t options; // enum SEV_OPTIONS uint32_t reserved; uint64_t tmr_phys_addr; // 1MB aligned. Ignored if CONFIG_ES is 0 uint32_t tmr_length; // Ignored if CONFIG_ES is 0 } sev_init_cmd_buf; // :737 ``` ```cpp typedef struct __attribute__ ((__packed__)) sev_platform_status_cmd_buf_t { uint8_t api_major; uint8_t api_minor; uint8_t current_platform_state; // SEV_PLATFORM_STATE uint8_t owner; uint16_t config; // enum SEV_CONFIG uint8_t reserved; uint8_t build_id; uint32_t guest_count; } sev_platform_status_cmd_buf; // :766 ``` ```cpp typedef struct __attribute__ ((__packed__)) sev_pek_csr_cmd_buf_t { uint64_t csr_p_addr; uint32_t csr_length; } sev_pek_csr_cmd_buf; // :782 ``` ```cpp typedef struct __attribute__ ((__packed__)) sev_pek_cert_import_cmd_buf_t { uint64_t pek_cert_p_addr; uint32_t pek_cert_length; uint32_t reserved; uint64_t oca_cert_p_addr; uint32_t oca_cert_length; } sev_pek_cert_import_cmd_buf; // :788 ``` ```cpp typedef struct __attribute__ ((__packed__)) sev_pdh_cert_export_cmd_buf_t { uint64_t pdh_cert_p_addr; // sev_cert uint32_t pdh_cert_length; uint32_t reserved; uint64_t certs_p_addr; // sev_cert_chain_buf uint32_t certs_length; } sev_pdh_cert_export_cmd_buf; // :797 ``` ```cpp typedef struct __attribute__ ((__packed__)) sev_get_id_cmd_buf_t { uint64_t id_p_addr; uint32_t id_length; } sev_get_id_cmd_buf; // :824 ``` ```cpp typedef struct __attribute__ ((__packed__)) sev_init_ex_cmd_buf_t { uint32_t length; // Must be 0x24 uint32_t options; // enum SEV_OPTIONS uint64_t tmr_phys_addr; uint32_t tmr_length; uint32_t reserved; uint64_t nv_phys_addr; uint32_t nv_length; // Must be 32KB } sev_init_ex_cmd_buf; // :830 ``` -------------------------------- ### get_ask_ark declaration Source: https://github.com/amdese/sev-tool/blob/master/_autodocs/api-reference/command.md Declares the guest-owner offline command that downloads the ASK/ARK certificate from the AMD site based on the device type, skipping if the file already exists. ```cpp int get_ask_ark(void); ``` -------------------------------- ### Validate certificate chain with sevtool --validate_cert_chain Source: https://github.com/amdese/sev-tool/blob/master/readme.md Imports the full certificate chain (PDH, PEK, OCA, CEK, ASK, ARK) from the specified folder and validates it. The ARK is self-signed; ASK is validated by ARK, CEK by ASK, PEK by CEK and OCA, and PDH by PEK. No output files are produced. ```sh $ sudo ./sevtool --ofolder ./certs --validate_cert_chain ```