Key updating method and computer-readable storage medium
By compiling the key update file in the upgrade image, determining the key update type and generating a new key, the problems of configuration loss and sensitive data leakage during device upgrades are solved, and cost-effective key and encryption algorithm upgrades and rollbacks are achieved.
Patent Information
- Application Number
- CN202411522229.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2044-10-29
AI Technical Summary
During the device upgrade process, existing technologies cannot effectively solve the problem of configuration loss when updating and rolling back encryption algorithms, and there is a risk of sensitive data leakage and high cost.
By compiling a key update file in the upgrade image, using the key file to record key versions and update information, determining the key update type, automatically generating a new key, and determining whether to upgrade or roll back the key before the device restarts, the system avoids saving configurations in plain text.
It ensures that there is no configuration loss or sensitive data leakage during the device upgrade process, while reducing costs, supporting the upgrade and rollback of keys and encryption algorithms, and unified management of key and algorithm updates.
Smart Images

Figure CN119109588B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data security technology, and in particular to a key updating method and a computer-readable storage medium. Background Art
[0002] Many service providers require encryption of sensitive data in gateway configurations to prevent data leakage. However, with the increasing importance of network security, service providers often require the use of the latest encryption algorithms, making it essential for products to support encryption algorithm updates. However, after upgrading a device to a new version, issues may necessitate a rollback to the previous version. If this rollback is performed directly, configuration files encrypted with the new algorithm cannot be decrypted, resulting in configuration loss. This presents a serious engineering problem, necessitating support for rollback from an upgraded version to an older version.
[0003] There are currently two mainstream methods to solve the algorithm upgrade rollback problem:
[0004] Method 1: Before the upgrade, the current version A uses the current algorithm to decrypt the configuration and save it in plain text. Then, the device is restarted, and the upgraded version B re-encrypts and saves the configuration based on B's encryption algorithm. In this way, regardless of whether the algorithm is upgraded or rolled back, the configuration file will not be lost. This method does not matter whether the encryption algorithm is upgraded or rolled back. The configuration file is decrypted and saved in plain text for each update, and re-encrypted after the device is restarted. Although the plain text duration is short, there is still the possibility of sensitive configuration being leaked. For example, if the configuration file is read continuously during the upgrade process, the plain text configuration may be read, or all configurations need to be decrypted and encrypted again for each upgrade, which also increases the time cost.
[0005] The second method is to upload the device configuration to the cloud via an SSL channel. When the encryption algorithm is updated, the version is upgraded normally. If a version rollback is required, the factory settings are restored first, then the old version is rolled back. The configuration is then distributed from the cloud via an SSL channel, encrypted using the old encryption algorithm. This method requires cloud platform support, is costly, and requires additional manual operations such as restoring factory settings and distributing the configuration, which increases labor costs. Summary of the Invention
[0006] The present invention aims to support key update during device update, including key upgrade and key rollback, while preventing configuration leakage, and provides a key update method and computer storage medium.
[0007] The technical solutions of the present invention are as follows:
[0008] A key updating method, comprising:
[0009] In response to a device update instruction, write an upgrade image to the device to be updated;
[0010] Read the key file keyfile, which records the current key version and key information saved during previous key updates. The key information includes the key algorithm library version, algorithm, and algorithm parameters;
[0011] Determine the current key update type. If a key upgrade is performed, create a new key based on the key update information deployed in the upgrade image. If a key rollback is performed, search the key file keyfile for the key corresponding to the upgrade image as the current key.
[0012] Furthermore, before writing the upgrade image into the device to be updated, the method further includes: compiling the upgrade image;
[0013] The compiling of the upgrade image includes: if the upgrade image is not related to the key update, the compilation parameters are image information, including the algorithm library version; if the upgrade image is related to the key update, the compilation parameters are key update information, including the algorithm library version, algorithm and algorithm parameters; automatically generating a key update file kupfile according to the compilation parameters, the key update file kupfile being used to record the currently compiled image information or the key update information; and deploying the key update file kupfile into the image body of the upgrade image.
[0014] Furthermore, compiling the upgrade image also includes: automatically generating a tag byte in the upgrade image header; at least two tag bytes are reserved in the upgrade image header, wherein the first tag byte is used to store the algorithm library version of the upgrade image, and the second tag byte is used to store a key update or not flag.
[0015] Furthermore, the automatic generation of the tag byte in the upgrade image header includes: parsing the key update file kupfile, and writing the parsed algorithm library version as the algorithm library version of the upgrade image into the first tag byte; determining whether the key update file kupfile contains key update information, and if so, writing the first tag value as the key update flag in the second tag byte, otherwise writing the second tag value in the second tag byte.
[0016] Furthermore, before determining the current key update type, the method further includes: creating a temporary flag file kupflag according to the upgrade image header; and writing the contents of the first tag byte and the second tag byte into the flag file kupflag.
[0017] Furthermore, the determination of the current key update type includes: determining whether the algorithm library version of the current key is higher than the algorithm library version of the upgrade image, and if so, performing key rollback; restarting the device; determining whether the flag file kupflag exists; and determining whether the key update flag exists in the flag file kupflag; and determining whether the current key version is lower than the image version of the upgrade image; performing a key upgrade when all of the above conditions are met, and not performing a key upgrade if any of the conditions are not met; and deleting the flag file kupflag.
[0018] Furthermore, the key file keyfile also records curr_keyid and max_keyid; creating a new key based on the key update information deployed in the upgraded image includes: reading the key update file kupfile from the updated device, and creating a new key based on the algorithm library version, algorithm and algorithm parameters specified in the key update file kupfile; wherein, the keyid of the new key = max_keyid+1.
[0019] Furthermore, the method further includes: writing the algorithm library version, algorithm, algorithm parameters and keyid of the new key into the key file keyfile, and updating the key file keyfile.
[0020] Furthermore, the updating of the key file keyfile includes: curr_keyid=keyid of the new key; max_keyid=max_keyid+1; current key version=image version of the upgraded image.
[0021] Furthermore, searching the key corresponding to the upgrade image from the key file keyfile as the current key includes: searching the key with the same algorithm library version as the upgrade image and the largest keyid from the key file keyfile as the current key.
[0022] Based on the same inventive concept, the present invention further provides a computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions, when executed, implement the aforementioned key update method.
[0023] The beneficial effects of the present invention are as follows:
[0024] 1. The present invention uses an upgrade image to update the device version, keeping the version update method in the engineering application unchanged. The key update method provided by the present invention is applicable to all gateway devices, does not introduce redundant operations, and reduces costs;
[0025] 2. The present invention supports key and encryption algorithm upgrades. New keys are created based on the key update information deployed in the upgraded image. If the image version of the upgraded image is not higher than the current key version, the key upgrade will not be performed. When the key is updated again, the corresponding new image must be written, thereby uniformly managing key and algorithm updates.
[0026] 3. The present invention also supports key and encryption algorithm rollback, using the key file keyfile to find the key corresponding to the upgraded image as the current key, and there is no configuration saved in plain text during the device restart process, thereby avoiding the leakage or loss of sensitive configurations.
[0027] Other features and advantages of the present invention will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0029] Figure 1 A schematic diagram of a key update method provided by an embodiment of the present invention;
[0030] Figure 2 Schematic diagram of a key update process in a specific embodiment of the present invention;
[0031] Figure 3 The figure is a schematic diagram of a key update process in another specific embodiment of the present invention. DETAILED DESCRIPTION
[0032] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0033] An embodiment of the present invention provides a key updating method, comprising the following steps:
[0034] Step S1: In response to a device update instruction, write an upgrade image into the device to be updated;
[0035] Step S2: Read the key file keyfile, which records the current key version and key information saved during previous key updates. The key information includes the key algorithm library version, algorithm, and algorithm parameters.
[0036] Step S3: Determine the current key update type. If a key upgrade is performed, create a new key according to the key update information deployed in the upgrade image. If a key rollback is performed, search the key file keyfile for the key corresponding to the upgrade image as the current key.
[0037] In an embodiment of the present invention, the upgrade image can be an image used to upgrade the device version or an image used to roll back the device version. Device updates are achieved by writing the corresponding image to the device. In step S1 above, the upgrade image generally includes an image header and an image body. The image header is used to write the image body to the device flash. The process of updating the device using the upgrade image includes: using an upgrade tool to write the upgrade image to the device flash; restarting the device after successful writing; and the device running with the newly written image program package.
[0038] In step S2, a key file (keyfile) is read from the device flash. Preferably, the first line of the key file records the current key version, the second line records the currently used keyid, denoted as curr_keyid, and the maximum keyid, denoted as max_keyid. The key file (keyfile) adds an information entry for each new key generated during an update, and the key information of the new key is stored in the same format in the information entry.
[0039] For example, the key information format recorded in the keyfile is as follows:
[0040] keyid algorithm_lib_version algorithm key param
[0041] Among them, keyid is the key id, its index value is N, and N is a positive integer;
[0042] algorithm_lib_version is the algorithm library version. The algorithm library is the set of all algorithms supported by the current software version. The algorithm library version is extensible, and the algorithm library of higher version is compatible with all algorithms of the algorithm library of lower version. For example, the algorithm library version that only supports the AES128 algorithm is recorded as V1.1. If the algorithm library is extended to support the AES128 algorithm and AES256 algorithm, the algorithm library version is recorded as V1.2. If the algorithm library is extended to support the AES128 algorithm, AES256 algorithm, and AES512 algorithm, it is recorded as V2.1. The algorithm library is forward compatible. algorithm is the encryption algorithm, such as the AES algorithm. key is the key entity. For example, the key of the AES256 algorithm is a 32-byte binary sequence. param is the algorithm parameter, including specific parameters related to the algorithm type. For example, when the algorithm type is AES256, the corresponding algorithm parameters include padding (padding type) and workmode (working mode).
[0043] According to a preferred embodiment of the present invention, when the upgrade image is an image used to upgrade a device version, before writing the upgrade image to the device to be updated, the process further includes: compiling the upgrade image. The upgrade image is actually an application package. After the program source code is compiled using a compilation script on a compilation server (e.g., a virtual machine), the generated application package is packaged using an image creation tool.
[0044] In an embodiment of the present invention, the method for compiling the upgrade image includes: if the upgrade image is not related to key update, the compilation parameters are image information, including the algorithm library version; if the upgrade image is related to key update, the compilation parameters are key update information, including the algorithm library version, algorithm and algorithm parameters; automatically generating a key update file kupfile according to the compilation parameters, the key update file kupfile being used to record the currently compiled image information or the key update information; and deploying the key update file kupfile into the image body of the upgrade image.
[0045] According to a specific embodiment, the compilation parameters related to the upgrade image are configured through the UI: the compilation parameters are checked in the compilation menu provided by the UI (such as a web page), including the algorithm library version, algorithm, and algorithm parameters. For example, the algorithm library version is first selected, and then the algorithm to be used is selected from the algorithms supported by the algorithm library version, and then the parameters corresponding to the algorithm are selected. It should be noted that if the upgrade image is not related to the key update, for example, when fixing a bug or improving certain performance of the device by upgrading the device, the compilation parameters of the upgrade image are the image information, that is, only the algorithm library version of the image is checked; if the upgrade image is not only used to upgrade the device but also to update the device key, the compilation parameters of the upgrade image are checked with the algorithm library version, algorithm, and algorithm parameters related to the new key. Each time the compilation is performed, the compilation script automatically generates a key update file kupfile based on the information checked in the compilation menu. The key update file kupfile is used to record the currently compiled image information or key update information.
[0046] Exemplarily, when the upgrade image is related to key update, the format of the key update file kupfile is as follows:
[0047] version
[0048] Algorith param_a param_b param_c
[0049] Where "version" is the algorithm library version, for example, V1.0, which indicates major version 1 and subversion 0. "algorith" is the algorithm, such as AES128, AES256, or AES512. "param_a", "param_b", and "param_c" are the algorithm parameters corresponding to "algorithm". For example, parameters related to the AES algorithm include padding type and workmode (e.g., CBC or EBC). The number of parameters may also vary depending on the algorithm.
[0050] Correspondingly, when the upgrade image is not related to key update, the content of the second line of the key update file kupfile is empty.
[0051] According to an embodiment of the present invention, the key update file kupfile is deployed into the image body of the upgrade image. For example, if the program uses the Linux system, the key update file kupfile is stored in a partition of the Linux system and then packaged into an image program package through a packaging program.
[0052] Furthermore, the image creation tool parses the key update file (kupfile) to create an upgrade image header and automatically generates a tag byte in the upgrade image header. The upgrade image header is used to write the image body to the device flash. Preferably, the upgrade image header has at least two tag bytes reserved, wherein the first tag byte is used to store the algorithm library version of the upgrade image, and the second tag byte is used to store a flag indicating whether the key has been updated.
[0053] According to a specific embodiment, the automatic generation of the tag byte in the upgrade image header includes: parsing the key update file kupfile, writing the parsed algorithm library version as the algorithm library version of the upgrade image into the first tag byte, for example, the algorithm library version V1.0, and its major version number and sub-version number each occupy 4 bits; determining whether the key update file kupfile contains key update information, and if so, writing the first tag value in the second tag byte as the key update flag, otherwise writing the second tag value in the second tag byte.
[0054] Preferably, if the second line of the key update file kupfile contains key update information, including the algorithm library version, algorithm and algorithm parameters, indicating that a key update is required subsequently, 1 is written in the second tag byte as a key update flag; if the key update file kupfile only contains mirror information, such as the algorithm library version, indicating that a key update will not be performed subsequently, 0 is written in the second tag byte as a key non-update flag.
[0055] In an embodiment of the present invention, before determining the current key update type, it also includes: creating a temporary flag file kupflag based on the upgrade image header; writing the contents of the first tag byte and the second tag byte into the flag file kupflag, that is, writing the algorithm library version and the key update flag in the upgrade image header into the flag file kupflag.
[0056] Furthermore, the device is restarted, and then it is determined whether the flag file kupflag exists; and, it is determined whether the key update flag exists in the flag file kupflag; and, it is determined whether the current key version is lower than the image version of the upgrade image; when all the above conditions are met, the key upgrade is performed, and if any condition is not met, the key upgrade is not performed; finally, the flag file kupflag is deleted.
[0057] According to an embodiment of the present invention, after the upgrade image is written, before the device is restarted, the device key is the current key, the algorithm library version of the upgrade image, and the key update flag (the second tag byte is 1) or the key non-update flag (the second tag byte is 0) are written in the flag file kupflag, and the program package of the upgrade image is run after the device is restarted. By judging whether the flag file kupflag exists, whether the key update flag exists in the flag file kupflag, and whether the current key version is less than the image version of the upgrade image, if the above conditions are met at the same time, the key upgrade operation is performed. If any one of the conditions is not met, it means that there is no need to perform a key upgrade at present, or the current key has been upgraded to a new key, or the current device is not restarted for the first time, so the key upgrade is not performed.
[0058] When it is determined that a key upgrade can be performed through the above method, a new key is created according to the key update information deployed in the upgrade image, including: reading the key update file kupfile from the updated device, and creating a new key according to the algorithm library version, algorithm and algorithm parameters specified in the key update file kupfile; reading the max_keyid recorded in the key file keyfile, and the keyid of the new key is keyid = max_keyid + 1.
[0059] Furthermore, after creating the new key, the key update method further includes: writing the algorithm library version, algorithm, algorithm parameters and keyid of the new key into the key file keyfile, and updating the key file keyfile.
[0060] In the embodiment of the present invention, the first line of the key file keyfile records the current key version, and the second line records curr_keyid and max_keyid. Therefore, updating the key file keyfile specifically includes:
[0061] Assign the keyid of the new key to the curr_keyid, that is, curr_keyid = keyid of the new key;
[0062] Assign the keyid of the new key to the max_keyid, that is, max_keyid=max_keyid+1;
[0063] The current key version is updated to the image version of the upgrade image, that is, the current key version = the image version of the upgrade image.
[0064] Furthermore, the updated key file keyfile is saved in the device flash, and then each module is notified of the key update event, so that each module uses the new key to re-encrypt the configuration file.
[0065] In an embodiment of the present invention, an upgrade image is used to upgrade the device, and the device upgrade process also supports key and encryption algorithm updates; when compiling the upgrade image, the key update information is written into the image body, and the key update or not flag and the algorithm library version of the upgrade image are written into the upgrade image header. After the device upgrade is successful, it is determined whether a key update is required. If so, a new key is created according to the key update information deployed in the upgrade image, and the current key version is updated to the image version of the upgrade image. Since the key upgrade will not be performed when the current key version is higher than the image version, repeated key upgrades are avoided. When the key is updated again, the corresponding new image needs to be written, thereby uniformly managing key and algorithm updates.
[0066] According to another preferred embodiment of the present invention, when the upgrade image is an image used for version rollback of the device, the upgrade image can be an image that has been used during the device update process. Version rollback is achieved by downloading the backup upgrade image from the server and writing it into the device.
[0067] In an embodiment of the present invention, after writing the upgrade image, before restarting the device, the current key update type is determined, specifically whether the algorithm library version of the current key is higher than the algorithm library version of the upgrade image. If so, the key rollback operation is performed, otherwise the key update process ends.
[0068] When performing a key fallback operation, the key corresponding to the upgrade image is searched from the key file keyfile as the current key. Specifically, the key with the same algorithm library version as the upgrade image and the largest keyid is found from the key file keyfile as the current key.
[0069] Since the second line of the keyfile contains curr_keyid, according to a preferred embodiment, the keyfile is searched for a key with the same algorithm library version as the upgraded image and the largest keyid. This keyid is recorded as the fallback key, and the keyid of the fallback key is assigned to curr_keyid, i.e., curr_keyid = fallback key's keyid. In actual applications, after the current key falls back to the fallback key, the configuration file is re-encrypted using the fallback key.
[0070] According to an embodiment of the present invention, after a device is upgraded to version V2, the configuration file is encrypted using a new key P. If the device needs to be rolled back to version V1 for engineering purposes, if the rollback is performed directly, the configuration file will not be decrypted because the program of version V1 does not support the algorithm of the new key P, resulting in configuration loss and device failure. However, according to the key update method provided by an embodiment of the present invention, the image of version V1 is written to the device. Before the device is restarted, the key K corresponding to the image of version V1 is found from the key file keyfile, that is, the key with the same algorithm library version as the image and the largest keyid is used as the current key. The device notifies each module of the key rollback event. Since the device is still running version V2 at this time, each module can use key P to decrypt the configuration file in memory and then re-encrypt the configuration plaintext using key K. After the device is restarted, the device rolls back to version V1. Since the algorithm library version of key K is the same as that of version V1, the algorithm in the algorithm library of version V1 can decrypt the configuration ciphertext encrypted by key K. Therefore, version V1 can encrypt or decrypt the configuration file normally. Since there is no configuration stored in plain text during the device restart process, the leakage or loss of sensitive configuration is avoided.
[0071] The following describes in detail two specific embodiments:
[0072] Example 1
[0073] This embodiment provides a key update method that can be used to update the key during the device upgrade process. The method is as follows:
[0074] (1) The key file keyfile in the current device flash is as follows:
[0075]
[0076] From the above key file keyfile, we can know that the current key version is 100, curr_keyid=key3, max_keyid=key3, the algorithm library version of the current key is V2.0, the encryption algorithm is AES256, and the algorithm parameters are padding=0, mode=CBC.
[0077] (2) Assuming that the image version of the upgrade image is 101, when making the upgrade image, check the compilation parameters in the UI compilation interface of the compilation server, or directly enter the compilation parameters using the command line.
[0078] For example, in the UI compilation interface, select the key information related to the new key as the compilation parameters: algorithm library version V3.0, select encryption algorithm AES512 from the algorithms supported by version V3.0, and parameters corresponding to the AES512 algorithm: padding = 0, mode = CBC.
[0079] The compilation script automatically generates the key update file kupfile based on the UI configuration. The format of the key update file kupfile is as follows:
[0080] V3.0
[0081] AES512 padding=0, mode=CBC
[0082] The key update file kupfile is stored in the image body of the upgrade image. The image production tool parses the key update file kupfile and writes the parsed algorithm library version and key update flag into byte A and byte B in the upgrade image header, that is, A=3.0 and B=1.
[0083] (3) Write the upgrade image to the device. Since the algorithm library version V3.0 of the upgrade image is greater than the algorithm library version V2.0 of the current key, key rollback will not be performed. Figure 2 The following process is used to update the key:
[0084] S101, create a flag file kupflag and restart the device;
[0085] In this step, byte A and byte B of the upgrade image header are written into the flag file kupflag. In the flag file kupflag, byte A1 = A, and byte B1 = B. After the device is restarted, the device upgrade is completed.
[0086] S102: Determine whether the flag file kupflag exists, whether the flag file kupflag contains a key update flag, and whether the current key version is lower than the image version of the upgraded image.
[0087] Specifically, determine whether the flag file kupflag exists, whether byte B1 in the flag file kupflag is 1, and whether the current key version is smaller than the image version of the upgraded image;
[0088] If the above conditions are met at the same time, S103, create a new key;
[0089] If any of the items is not true, S106, directly delete the flag file kupflag without performing the key update;
[0090] When creating a new key, the key update file kupfile shown in (2) is read from the upgrade device, a new key is created according to the algorithm library, algorithm and algorithm parameters specified in the key update file kupfile, and the keyid of the new key is set according to the max_keyid (key3) recorded in the key file keyfile in (1); that is, the keyid of the new key = max_keyid + 1;
[0091] Therefore, the key information of the new key is:
[0092] V3.0 AES512 key4 padding=0,mode=CBC
[0093] S104. Save the new key to the key file keyfile and update the key file keyfile, where curr_keyid = keyid of the new key; max_keyid = max_keyid + 1; and current key version = the image version of the upgraded image.
[0094] The updated key file keyfile is as follows:
[0095]
[0096] S105 , notifying each module of the key update event, so that each module re-encrypts the configuration file using the new key; S106 , deleting the flag file kupflag; S107 , the process ends.
[0097] In step S105, after the key is updated, the device notifies each module of the key update event and deletes the flag file kupflag. Each module responds to the key update instruction by first finding the corresponding key and algorithm from the key file keyfile according to the keyid saved in the header of the current configuration file ciphertext, calling the decryption operation interface to decrypt the configuration file ciphertext to obtain the configuration plaintext, then finding curr_keyid (key4) from the above-mentioned key file keyfile, calling the encryption operation interface, using the curr_keyid as the encryption key, and re-encrypting the configuration plaintext using the corresponding encryption algorithm (AES512). Finally, the re-encrypted configuration file is written to the flash.
[0098] After re-encrypting the configuration file to obtain the configuration ciphertext, add 1 byte to the header of the ciphertext to store the keyid used for encryption. The final configuration ciphertext format is:
[0099] key4 ciphertext
[0100] Example 2
[0101] This embodiment provides a key update method that can be used to update the key during the device version rollback process. The method is as follows:
[0102] (1) The key file keyfile in the current device flash is as follows:
[0103]
[0104] From the above key file keyfile, we can know that the current key version is 101, curr_keyid=key4, max_keyid=key4, the current key algorithm library version is V3.0, the encryption algorithm is AES512, and the algorithm parameters are padding=0, mode=CBC.
[0105] (2) Download the backup upgrade image (image version number 100) from the server. In the upgrade image header, A=2.0 and B=1.
[0106] Write the upgrade image to the device flash before restarting the device. Figure 3 The following process is used to update the key:
[0107] S201, determine whether the algorithm library version of the current key is higher than the algorithm library version of the upgrade image;
[0108] In this step, since the algorithm library version of the current key is V3.0> the algorithm library version of the upgrade image is V2.0, the key rollback operation is currently performed.
[0109] When performing a key rollback operation, S202, searching for a rollback key from the key file keyfile;
[0110] Specifically, the key file keyfile shown in (1) is searched for a key with the same algorithm library version (V2.0) as the upgraded image and the largest keyid as the fallback key, and the keyid of the fallback key is key3;
[0111] S203, assign the keyid of the fallback key to curr_keyid, that is, curr_keyid = keyid of the fallback key;
[0112] In this step, curr_keyid = key3;
[0113] Therefore, update the keyfile to:
[0114]
[0115] S204, notifying each module of the key rollback event, so that each module uses the rollback key to re-encrypt the configuration file; S205, the process ends;
[0116] In response to the key rollback instruction, each module finds the corresponding decryption key according to the keyid saved in the ciphertext header of the current configuration file, calls the decryption operation interface to decrypt the configuration ciphertext to obtain the configuration plaintext, then finds curr_keyid (key3) from the key file keyfile, calls the encryption operation interface, uses the curr_keyid as the encryption key, uses the corresponding encryption algorithm (AES256) to re-encrypt the configuration file, and finally writes the re-encrypted configuration file to the flash.
[0117] After re-encrypting the configuration file to obtain the configuration ciphertext, add 1 byte to the header of the ciphertext to store the keyid used for encryption. The final configuration ciphertext format is:
[0118] Key3 ciphertext
[0119] (3) Create the flag file kupflag, then restart the device to implement version rollback. Since the current image version is 100 and the current key version is 101, the key upgrade operation cannot be performed. Simply delete the flag file kupflag. In this image version, the algorithm library version is V2.0, which supports AES256 and can encrypt or decrypt configuration files normally.
[0120] Based on the same inventive concept, an embodiment of the present invention further provides a computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions, when executed, implement the aforementioned key update method.
[0121] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is merely a logical function division. In actual implementation, there may be other division methods, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0122] The modules described as separate components may or may not be physically separate, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, the functional modules in the various embodiments of the present invention may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into a single module. The integrated modules may be implemented in the form of hardware or software functional modules.
[0123] If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0124] It should be noted that for the aforementioned method embodiments, for ease of description, they are all expressed as a series of action combinations. However, those skilled in the art should be aware that the present invention is not limited by the order of the actions described, because according to the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0125] In the above embodiments, the description of each embodiment has its own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the above embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the above embodiments or to replace some of the technical features therein with equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present invention shall be included in the scope of protection of the present invention.
Claims
1. A key update method, characterized in that: The method comprises: In response to a device update instruction, write an upgrade image to the device to be updated; Read the key file keyfile, which records the current key version and key information saved during previous key updates. The key information includes the key algorithm library version, algorithm, and algorithm parameters; Determine the current key update type. If a key upgrade is being performed, create a new key based on the key update information deployed in the upgrade image; If the algorithm library version of the current key is higher than the algorithm library version of the upgraded image, a key rollback is performed, and the historical key corresponding to the algorithm library version of the upgraded image is found from the key file keyfile as the new current key. The decryption key of the configuration file ciphertext is found from the key file keyfile according to the keyid saved in the header of the configuration file ciphertext, and the configuration plaintext is obtained. The configuration plaintext is encrypted using the new current key and the corresponding encryption algorithm.
2. The method according to claim 1, characterized in that Before writing the upgrade image into the device to be updated, the method further includes: compiling the upgrade image; The compiling of the upgrade image includes: If the upgrade image is not related to key update, the compilation parameter is the image information, including the algorithm library version; If the upgrade image is related to key update, the compilation parameters are key update information, including algorithm library version, algorithm and algorithm parameters; Automatically generate a key update file kupfile according to the compilation parameters, wherein the key update file kupfile is used to record the image information or the key update information currently compiled; Deploy the key update file kupfile into the image body of the upgrade image.
3. The method according to claim 2, characterized in that Compiling the upgrade image further includes: Automatically generate tag bytes in the upgrade image header; At least two tag bytes are reserved in the upgrade image header, wherein the first tag byte is used to store the algorithm library version of the upgrade image, and the second tag byte is used to store a flag indicating whether the key is updated or not.
4. The method according to claim 3, characterized in that The automatic generation of the tag bytes in the upgrade image header includes: Parsing the key update file kupfile, and writing the algorithm library version obtained by parsing as the algorithm library version of the upgrade image into the first tag byte; Determine whether the key update file kupfile contains key update information; if so, write a first tag value in the second tag byte as a key update flag; otherwise, write a second tag value in the second tag byte.
5. The method according to claim 4, characterized in that Before determining the current key update type, the following steps are also included: Create a temporary flag file kupflag according to the upgrade image header; The contents of the first tag byte and the second tag byte are written into the flag file kupflag.
6. The method according to claim 5, characterized in that The determining of the current key update type includes: Restart the device; Determine whether the flag file kupflag exists; and, determining whether the key update flag exists in the flag file kupflag; and, determining whether the current key version is lower than the image version of the upgraded image; The key upgrade is performed when all the above conditions are met. If any of the conditions are not met, the key upgrade is not performed. Delete the flag file kupflag.
7. The method according to claim 6, characterized in that The key file keyfile also records curr_keyid and max_keyid; The creating a new key according to the key update information deployed in the upgrade image includes: Read the key update file kupfile from the updated device and create a new key according to the algorithm library version, algorithm and algorithm parameters specified in the key update file kupfile; The keyid of the new key is max_keyid+1.
8. The method according to claim 7, characterized in that The method further comprises: Write the algorithm library version, algorithm, algorithm parameters and keyid of the new key into the key file keyfile, and update the key file keyfile.
9. The method according to claim 8, characterized in that The updating of the key file keyfile includes: curr_keyid=keyid of the new key; max_keyid=max_keyid+1; Current key version = the image version of the upgrade image.
10. The method according to claim 1, characterized in that From the key file keyfile, find a historical key with the same algorithm library version as the upgraded image and the largest keyID as the new current key.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, which, when executed, implement the key updating method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Authentication and key negotiation method and device, and storage medium
CN114726555A
Software upgrading method of vehicle, server, vehicle, storage medium and system
CN116243950A