Configuration-free virtual machine safe starting method supporting national cryptographic algorithm
By introducing SM2 and SM3 algorithms in the virtual machine secure boot, the national secret algorithm is supported, and the problem of manual configuration of the virtual machine secure boot is solved, and secure boot is realized without configuring the certificate file, which improves the security of virtual machine startup and user experience.
Patent Information
- Application Number
- CN202411235891.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-04
- Publication Date
- 2024-12-27
AI Technical Summary
The existing virtual machine secure boot method requires manual configuration of keys and does not support the national secret algorithm, which leads to users need to understand complex configuration processes and key management, increasing user learning costs and configuration complexity.
By obtaining the OVMF source code of open source EDK2, introducing SM2 and SM3 algorithms, adding corresponding interface functions, supporting SM2 certificate signature and SM3 algorithm hash value calculation, compiling virtual firmware, and importing SM2 certificates into the platform key and key storage, simplifying Configuration process.
It enables the secure boot of the virtual machine without manually configuring the certificate file, simplifies the configuration steps, improves the security of the virtual machine startup process, and supports the national secret algorithm, reducing user learning costs.
Smart Images

Figure CN119203150A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of virtualization security, and specifically provides a configuration-free virtual machine security startup method supporting a national secret algorithm. Background Art
[0002] Secure Boot is a security standard used to ensure that devices boot only with software trusted by the original equipment manufacturer (OEM). Secure Boot checks the digital signatures of the bootloader and the operating system. If the signature is valid and matches a trusted key stored in the system, the boot process continues; if it does not match, the process is stopped to prevent tampering. Secure Boot is essential to protect the system from malware and unauthorized software. It strengthens computer equipment against a variety of cyber threats and provides a critical layer of defense for the overall security of the computer. By verifying the integrity of the boot process, Secure Boot provides a secure foundation for the operating system and reduces the risk of attacks that compromise system data and stability.
[0003] Secure boot is implemented on the UEFI boot mode, which requires the support of firmware (usually called BIOS, which is the first software to start after starting the computer). According to UEFI regulations, the original equipment manufacturer can build some public key certificates into the firmware when the computer leaves the factory. When the computer is turned on, any operating system or hardware driver that wants to be loaded must be authenticated by these public keys. The secure boot on the physical machine is completed by the physical firmware, while the secure boot of the virtual machine is implemented through virtual firmware simulation. At present, the commonly used virtual firmware is generated by the OVMF component of EDK2. Secure boot is a security protection capability provided by EDK2 during the virtual machine startup process to protect the security of the virtual machine operating system kernel.
[0004] Most of the existing methods are aimed at the secure boot of physical machines. For physical machines, the firmware is provided by the original equipment manufacturer. The platform key (PK, used to establish a trust relationship between the platform owner and the platform firmware) is provided by the original equipment manufacturer. The key exchange key (KEK, used to establish a trust relationship between the platform firmware and the operating system) is generally provided by the original equipment manufacturer and the operating system manufacturer. The keys in the whitelist data (DB, used to store keys for verifying components such as shim, grub, and vmlinuz) are provided by the operating system manufacturer. The firmware and keys required for the secure boot of physical machines are generally configured before the machine leaves the factory. Users do not need to consider the configuration of firmware and certificates when enabling secure boot. Therefore, most of these methods are also innovations in the secure boot process.
[0005] For virtual machines, the virtual machine firmware needs to be provided by the operating system, but the key generally requires the user to use a self-signed certificate and manually configure PK, KEK, and DB. Therefore, if you want to enable and use the secure boot function of the virtual machine, you not only need to have a certain understanding of the secure boot process, keys, and certificates, but also need to perform tedious configuration work. In addition, the OVMF component currently does not support the national encryption algorithm. The national encryption algorithm has higher security, and more and more standards and specifications are beginning to recommend or require the use of the national encryption algorithm, so it is very necessary for secure boot to support the national encryption algorithm.
[0006] Accordingly, the art needs a virtual machine secure startup solution that can support national encryption algorithms and does not require manual configuration of keys to solve the above problems. Summary of the invention
[0007] In order to overcome the above defects, the present invention is proposed to solve the technical problems in the prior art that the certificate for secure startup of a virtual machine needs to be manually configured and cannot support the national encryption algorithm.
[0008] The present invention provides a configuration-free virtual machine secure startup method supporting a national secret algorithm, comprising the following steps: Obtain the OVMF source code of the open source EDK2, introduce the relevant functions of the SM2 algorithm and the SM3 algorithm into the OVMF source code, and add and modify the corresponding interface functions to obtain the modified OVMF source code; Compile the modified OVMF source code to obtain a first virtual firmware; According to the first virtual firmware, import the SM2 certificate into PK and KEK, use the SM3 algorithm to calculate the hash value of the virtual machine operating system shim certificate and import it into DB, add the processed PK, KEK and DB to the modified OVMF source code, and compile to obtain the second virtual firmware.
[0009] Further, the adding and modifying of corresponding interface functions includes: Add the judgment logic for SM2 certificate in CheckSignatureListFormat interface function, which is used to check the signature certificate algorithm type; Add support for using the SM3 algorithm in the HashPeImage interface function, which is used to calculate the hash value of the certificate; Add SM2GetPublicKeyFromX509 interface function, which is used to parse the SM2 certificate and then return the status value; Add the SM2Free interface function, which is used to release the certificate content saved in the SM2Context.
[0010] Furthermore, the judgment logic for the SM2 certificate includes: Call SM2GetPublicKeyFromX509 interface function; Determine whether the return status value is successful. If so, it proves to be an SM2 certificate. Call the SM2Free interface function to release the certificate content saved in the SM2Context.
[0011] Further, the parsing of the SM2 certificate includes: Check if SM2 certificate exists; If it exists, read the SM2 certificate and retrieve the public key data, copy and save the retrieved public key data into the variable SM2Context.
[0012] Furthermore, the adding support for using the SM3 algorithm includes: adding a GUID corresponding to the SM3 algorithm, and adding the SM3 algorithm in the HashPeImage interface function.
[0013] Further, when the second virtual firmware is used to start the virtual machine, the method further includes the following steps: Determine whether there is a shim certificate for the current virtual machine operating system in the DB; If yes, start safe boot. If not, wait for the user to enter the corresponding shim certificate, and import the obtained shim certificate into the DB after calculation using the SM3 algorithm, and then return to re-determine whether there is a shim certificate for the current virtual machine operating system in the DB.
[0014] The working principle and beneficial effects of the present invention are: In the technical solution of the present invention, the SM2 certificate is added for signing and verification, and the SM3 algorithm is used to calculate the hash value of the shim certificate, which realizes the national secret algorithm support for the virtual firmware and further improves the security of the virtual machine startup process. The SM2 certificate is added to PK and KEK, and the obtained shim certificate is added to DB in advance. Then, the processed PK, KEK and DB are added to the modified OVMF source code, and the second virtual firmware is compiled to enable secure boot without configuring the certificate file, which simplifies the complex steps of configuring secure boot and reduces the user's learning cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The disclosure of the present invention will become more easily understood with reference to the accompanying drawings. It is easy for those skilled in the art to understand that these drawings are only for illustrative purposes and are not intended to limit the scope of protection of the present invention. In addition, similar numbers in the figures are used to represent similar components, among which: Figure 1 This is a flow chart of the main steps of a configuration-free virtual machine secure startup method that supports national encryption algorithms in the present invention. DETAILED DESCRIPTION
[0016] Some embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the protection scope of the present invention.
[0017] Here we first explain some terms involved in the present invention.
[0018] Kylin Certificate: Kylin software self-signed certificate.
[0019] Shim certificate: In order to avoid directly signing the kernel, most Linux distributions introduce shim as an intermediate layer to sign shim. The shim certificate is the public key certificate that verifies shim.
[0020] Figure 1 This is a flow chart of the main steps of a configuration-free virtual machine secure startup method that supports the national encryption algorithm in the present invention. Figure 1 As shown, a configuration-free virtual machine secure startup method supporting the national encryption algorithm in this embodiment mainly includes the following steps S10 to S20.
[0021] Step S10: Modify the OVMF source code of the open source software EDK2 to support the national encryption algorithm.
[0022] 1) Get the OVMF source code of the open source EDK2, introduce the related functions of the SM2 algorithm and SM3 algorithm into the OVMF source code, and add and modify the corresponding interface functions. The implementation of the SM2 and SM3 algorithms directly calls the related functions in the open source algorithm library.
[0023] In this embodiment, the addition and modification of the interface function specifically include: ① The CheckSignatureListFormat interface function is used to check the algorithm type used by the signature certificate. This embodiment adds judgment logic for the SM2 certificate based on the original CheckSignatureListFormat interface function.
[0024] ② The HashPeImage interface function is used to calculate the hash value of the certificate. This embodiment adds support for using the SM3 algorithm based on the technology of the original HashPeImage interface function.
[0025] ③Add SM2GetPublicKeyFromX509 interface function, which is used to parse the SM2 certificate, save the public key information in the SM2 certificate to the variable SM2Context, and return the status value. This interface function is used when checking and judging the certificate type and when verifying the signature.
[0026] ④Add SM2Free interface function, which is used to release the certificate content saved in SM2Context.
[0027] 2) Added judgment logic for SM2 certificates so that the virtual machine secure boot supports SM2 certificate signature verification. In one embodiment, the added judgment logic for SM2 certificates, that is, the process of calling the modified CheckSignatureListFormat interface function, calls the SM2GetPublicKeyFromX509 interface function to determine whether the return status value is successful. If so, it proves that it is an SM2 certificate, and calls the SM2Free interface function to release the certificate content saved in SM2Context. If the return value is unsuccessful, it proves that the SM2 certificate is not used, and other certificate types will be judged.
[0028] 3) Added the parsing process of SM2 certificates. PK and KEK support importing SM2 certificates. That is, the process of calling the SM2GetPublicKeyFromX509 interface function first checks whether the SM2 certificate exists. If so, reads the SM2 certificate and retrieves the public key data, and copies and saves the retrieved public key data to the variable SM2Context. If the SM2 certificate does not exist, an error is returned and the user is prompted that the import cannot be made. This is the original logic in the open source software.
[0029] 4) Add SM3 signature parsing support code to enable DB and DBX to support the use of SM3 algorithm when calculating certificate hashes. Add the GUID corresponding to the SM3 algorithm in the OVMF source code (specifically added to the package declaration file MdePkg.dec of the module development environment package MdePkg). The GUID is the unique ID corresponding to each hash algorithm and will be used when calling the algorithm. Add the SM3 algorithm in the HashPeImage interface function (hash value calculation function).
[0030] Step S20: Add PK, KEK, and DB to generate a configured NVRAM file.
[0031] 1) Compile the OVMF source code modified in step S10 to obtain a first virtual firmware, start the virtual machine through the first virtual firmware, and perform the following process.
[0032] 2) Import the SM2 certificate into PK and KEK, use the SM2 certificate for signing and signature verification, and implement support for the SM2 algorithm.
[0033] 3) Use the SM3 algorithm to calculate the hash value of the virtual machine operating system shim certificate and import it into the DB to support the SM3 algorithm. The shim certificate is used to verify the trust relationship between the virtual firmware and the shim.
[0034] The shim certificates here include the shim certificate of the Kylin operating system and other shim certificates that can be obtained. For virtual machine operating systems that cannot obtain shim certificates, users need to enter them manually when starting the machine.
[0035] 4) Add the processed PK, KEK and DB to the OVMF source code modified in S10, and compile to obtain the second virtual firmware.
[0036] Specifically, after processing PK, KEK, and DB, the virtual hard disk nvram file that stores information such as PK, KEK, and DB certificates is added to the modified OVMF source code. NVRAM is a special memory used to store firmware and operating system configuration parameters.
[0037] The verification order of secure boot is: firmware, shim, grub, vmlinuz. The virtual firmware is responsible for the signature verification of the firmware itself and shim. The verification of grub and vmlinuz is the responsibility of shim, and the virtual firmware is not involved in this part of the verification. Therefore, when the PK, KEK, and DB certificates are all added, the configuration of the virtual firmware part meets the conditions for enabling secure boot.
[0038] Afterwards, the second virtual firmware is saved as a template, and a new virtual machine is created, and secure boot can be performed without configuration.
[0039] In one implementation, a new virtual machine is created, and Kylin-Server-V10 is used as the virtual machine operating system. The saved nvram file is then used as a template. At this point, there is no need to configure the certificate required for secure boot, and the virtual machine will automatically use secure boot when it is turned on. Finally, tests were conducted on x86 and arm respectively. This method can enable the secure boot function without configuration, and is compatible with both x86 and arm architectures, which can meet more business needs.
[0040] Furthermore, since there is a shim certificate that cannot be obtained, when the second virtual firmware is used to execute the virtual machine startup, the following judgment is also included: Determine whether there is a shim certificate for the current virtual machine operating system in the DB; If yes, start safe boot. If not, wait for the user to enter the corresponding shim certificate, and import the obtained shim certificate into the DB after calculation using the SM3 algorithm, and then return to re-determine whether there is a shim certificate for the current virtual machine operating system in the DB.
[0041] Through the above steps S10-S20, the SM2 certificate is added for signing and verification, and the SM3 algorithm is used to calculate the hash value of the shim certificate, which realizes the support of the national secret algorithm for virtual firmware and further improves the security of the virtual machine startup process. The SM2 certificate is added to PK and KEK. For the shim certificate that can be obtained, such as the virtual machine installed as the GuestOS of the Kylin operating system, it is added to the DB in advance, and then the processed PK, KEK and DB are added to the modified OVMF source code, and the second virtual firmware is compiled to enable secure boot without configuring the certificate file, which simplifies the complex steps of configuring secure boot and reduces the user's learning cost.
[0042] It should be pointed out that although the various steps in the above embodiments are described in a specific order, those skilled in the art can understand that in order to achieve the effects of the present invention, different steps do not have to be performed in such an order, and they can be performed simultaneously (in parallel) or in other orders. These changes are within the scope of protection of the present invention.
[0043] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.
Claims
1. A configuration-free virtual machine secure startup method supporting national encryption algorithms, characterized in that: The following steps are involved: Obtain the OVMF source code of the open source EDK2, introduce the relevant functions of the SM2 algorithm and the SM3 algorithm into the OVMF source code, and add and modify the corresponding interface functions to obtain the modified OVMF source code; Compile the modified OVMF source code to obtain a first virtual firmware; According to the first virtual firmware, import the SM2 certificate into PK and KEK, use the SM3 algorithm to calculate the hash value of the virtual machine operating system shim certificate and import it into DB, add the processed PK, KEK and DB to the modified OVMF source code, and compile to obtain the second virtual firmware.
2. According to claim 1, a configuration-free virtual machine secure startup method supporting national secret algorithms is characterized in that: The adding and modifying corresponding interface functions include: Add the judgment logic for SM2 certificate in CheckSignatureListFormat interface function, which is used to check the signature certificate algorithm type; Add support for using the SM3 algorithm in the HashPeImage interface function, which is used to calculate the hash value of the certificate; Add SM2GetPublicKeyFromX509 interface function, which is used to parse the SM2 certificate and then return the status value; Add the SM2Free interface function, which is used to release the certificate content saved in the SM2Context.
3. According to claim 2, a configuration-free virtual machine secure startup method supporting national secret algorithms is characterized in that: The judgment logic for the SM2 certificate includes: Call SM2GetPublicKeyFromX509 interface function; Determine whether the return status value is successful. If so, it proves to be an SM2 certificate. Call the SM2Free interface function to release the certificate content saved in the SM2Context.
4. According to claim 2, a configuration-free virtual machine secure startup method supporting national secret algorithms is characterized in that: The analysis of the SM2 certificate includes: Check if SM2 certificate exists; If it exists, read the SM2 certificate and retrieve the public key data, copy and save the retrieved public key data into the variable SM2Context.
5. According to claim 2, a configuration-free virtual machine secure startup method supporting national secret algorithms is characterized in that: The adding support for using the SM3 algorithm includes: adding a GUID corresponding to the SM3 algorithm, and adding the SM3 algorithm in the HashPeImage interface function.
6. According to claim 1, a configuration-free virtual machine secure startup method supporting national secret algorithms is characterized in that: When the second virtual firmware is used to start the virtual machine, the steps further include: Determine whether there is a shim certificate for the current virtual machine operating system in the DB; If yes, start safe boot. If not, wait for the user to enter the corresponding shim certificate, and import the obtained shim certificate into the DB after calculation using the SM3 algorithm, and then return to re-determine whether there is a shim certificate for the current virtual machine operating system in the DB.