Key updating method and computer readable storage medium
By writing upgrade images in the device and processing key files, the problem of key updates and fallbacks during the device upgrade process is solved, and flexible updates of keys and encryption algorithms are realized, reducing costs and avoiding configuration leakage. A secure and reliable key management solution.
Patent Information
- Application Number
- CN202411522229.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2044-10-29
AI Technical Summary
During the equipment upgrade process, the problem of the configuration loss caused by the failure of the new encryption algorithm configuration file, and the existing technology methods have the defects of sensitive configuration leakage or high-cost manual operation.
By writing the upgrade image in the device and reading the key file, judging the key update type, generating or finding the corresponding new key, including key update information when compiling the upgrade image, automatically generating the key update file, and writing to the image The tag bytes in the header are judged and performed key upgrade or fallback operations to avoid clear text saving of configuration.
It realizes the flexibility and security of device version updates, reduces costs, avoids leakage or loss of sensitive configurations, and uniformly controls key and algorithm updates.
Smart Images

Figure CN119109588A_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 protection for sensitive data in gateway configuration to prevent sensitive data leakage. However, as the importance of network security gradually increases, service providers often require the use of the latest encryption algorithms, so products must support encryption algorithm update functions. However, when the device is upgraded to a new version, it may need to be rolled back to the previous version due to problems in the new version. If the version is rolled back directly, the configuration file encrypted by the new algorithm will not be decrypted, resulting in configuration loss. This is an extremely serious engineering problem, so it is necessary to support the upgrade version to roll back to the old version.
[0003] There are currently two mainstream methods to solve the algorithm upgrade rollback problem:
[0004] Method 1 is that before upgrading, the current version A uses the current algorithm to decrypt the configuration and save it in plain text, then restart the device, 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 has nothing to do with whether the encryption algorithm is upgraded or rolled back. Each update decrypts the configuration file, saves it in plain text, and re-encrypts it 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 each upgrade requires decryption and encryption of all configurations, which also increases the time cost;
[0005] The second method is to upload the device configuration to the cloud through the SSL channel, and upgrade the version normally when the encryption algorithm is updated. If a version rollback is required, restore the factory settings first, then roll back to the old version, and then send the configuration from the cloud through the SSL channel, using the old version of the encryption algorithm to encrypt the configuration. This method requires the support of the cloud platform, which is costly, and requires additional manual operations such as restoring factory settings and sending configurations, which increases labor costs. Summary of the invention
[0006] The present invention aims to support key update when equipment is updated, including key upgrade and key rollback, while preventing configuration leakage, and provides a key update method and computer storage medium.
[0007] The technical solution of the present invention is as follows:
[0008] A key updating method, comprising:
[0009] In response to the device update instruction, write the upgrade image into 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 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.
[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 the image information, including the algorithm library version; if the upgrade image is related to the key update, the compilation parameters are the key update information, including the algorithm library version, the algorithm and the algorithm parameters; automatically generating a key update file kupfile according to the compilation parameters, the key update file kupfile is used to record the currently compiled image information or the key update information; 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 in the second tag byte as a key update flag, 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 content 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 according to 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 according to the algorithm library version, algorithm and algorithm parameters specified in the key update file kupfile; wherein the keyid of the new key is max_keyid+1.
[0019] Furthermore, the method further comprises: 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] Further, searching the key corresponding to the upgrade image from the key file keyfile as the current key includes: searching the key having 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, in which computer executable instructions are stored, and the computer executable instructions can implement the aforementioned key update method when executed.
[0023] The beneficial effects of the present invention are as follows:
[0024] 1. The present invention uses an upgrade image to update the version of the device, 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. A new key is created according to the key update information deployed in the upgrade image. If the image version of the upgrade 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 needs to be written, thereby uniformly managing key and algorithm updates;
[0026] 3. The present invention also supports key and encryption algorithm rollback, uses 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 configuration.
[0027] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or 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 updating method provided by an embodiment of the present invention;
[0030] Figure 2 A 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 be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. 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 creative work 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, writing an upgrade image into the device to be updated;
[0035] Step S2, read the key file keyfile, the key file keyfile records the current key version and the key information saved during the 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 the embodiment of the present invention, the upgrade image can be an image used to upgrade the version of the device, or an image used to roll back the version of the device, and the device update is realized by writing the corresponding image into the device. In the above step S1, the upgrade image generally includes an image header and an image body, and the image header is used to write the image body into the device flash. The process of updating the device using the upgrade image includes: using the upgrade tool to write the upgrade image into the device flash, restarting the device after the writing is successful, and the device runs with the newly written image program package.
[0038] In the above step S2, the key file keyfile is read from the device flash. Preferably, in the key file keyfile, the first line records the current key version, the second line records the currently used keyid, recorded as curr_keyid, and the maximum keyid, recorded as max_keyid. The key file keyfile adds an information entry for each new key generated by the update, and the key information of the new key is stored in the information entry in the same format.
[0039] Exemplarily, the format of the key information 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 a collection of all algorithms supported by the current software version. The algorithm library version is extensible, and a higher version of the algorithm library is compatible with all algorithms of a lower version of the algorithm library. For example, the version of the algorithm library that only supports the AES128 algorithm is recorded as V1.1. If the algorithm library is extended to support the AES128 algorithm and the AES256 algorithm, the algorithm library version is recorded as V1.2. If the algorithm library is extended to support the AES128 algorithm, the AES256 algorithm, and the AES512 algorithm, it is recorded as V2.1, and the algorithm library is forward compatible. algorithm is an encryption algorithm, such as the AES algorithm. key is a key entity, such as the key of the AES256 algorithm is a 32-byte binary sequence. param is an 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 for upgrading the version of a device, before writing the upgrade image into the device to be updated, it also includes: compiling the upgrade image. The upgrade image is actually an application package, which is compiled by a compilation server (such as a virtual machine) using a compilation script to compile the program source code, and then the image production tool is used to package the generated application package.
[0044] In an embodiment of the present invention, the method for compiling the upgrade image includes: if the upgrade image is not related to the key update, the compilation parameter is the image information, including the algorithm library version; if the upgrade image is related to the key update, the compilation parameter is the key update information, including the algorithm library version, the algorithm and the algorithm parameters; automatically generating a key update file kupfile according to the compilation parameters, the key update file kupfile is used to record the currently compiled image information or the key update information; deploying the key update file kupfile to the image body of the upgrade image.
[0045] According to a specific implementation, 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 version, algorithm 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 parameter of the upgrade image is 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 used 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 according to 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] Among them, version is the algorithm library version, such as V1.0, which means the main version is 1 and the sub-version is 0; algorithm is the algorithm, such as AES128 algorithm, AES256 algorithm or AES512 algorithm, etc.; param_a, param_b, param_c are the algorithm parameters corresponding to algorithm, for example, the parameters related to the AES algorithm include padding type (padding), work mode (such as CBC, EBC mode, etc.). The number of parameters may also be different when the algorithm is different.
[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 adopts 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 creates an upgrade image header by parsing the key update file kupfile, and automatically generates a tag byte in the upgrade image header. The upgrade image header is used to write the image body into the device flash. Preferably, 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.
[0053] According to a specific implementation, the automatic generation of tag bytes 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, such as the algorithm library version V1.0, whose 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 a first tag value in the second tag byte as a key update flag, otherwise writing a 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, it indicates that a key update is required subsequently, and 1 is written in the second label byte as a key update flag; if the key update file kupfile only contains mirror information, such as the algorithm library version, it indicates that a key update will not be performed subsequently, and 0 is written in the second label 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] Further, restart the device, and then determine whether the flag file kupflag exists; and, determine whether the key update flag exists in the flag file kupflag; and, determine whether the current key version is lower than the image version of the upgrade image; when all the above conditions are met, perform the key upgrade, if any condition is not met, do not perform the key upgrade; finally, delete the flag file kupflag.
[0057] According to an embodiment of the present invention, after writing the upgrade image, before the device is restarted, the device key is the current key, the flag file kupflag is written with 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), 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 upgrade the key 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 by the above method that the key upgrade can be performed, 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 = max_keyid+1.
[0059] Furthermore, after creating a new key, the key updating 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 a 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 flag and the algorithm library version of the upgrade image are written into the upgrade image header. After the device is successfully upgraded, 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 may be an image that has been used during the device update process, and 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 the device is restarted, 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, a key rollback operation is performed, otherwise the key update process ends.
[0068] When performing a key fallback operation, a key corresponding to the upgrade image is searched from the key file keyfile as the current key. Specifically, a key with the same algorithm library version as the upgrade image and the largest keyid is searched from the key file keyfile as the current key.
[0069] Since the second line of the key file keyfile records curr_keyid, according to a preferred implementation, the key file keyfile is searched for a key with the same algorithm library version as the upgraded image and the largest keyid, recorded as the fallback key, and the keyid of the fallback key is assigned to the curr_keyid, that is, curr_keyid = keyid of the fallback key. 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 the device is upgraded to version V2, the configuration file is encrypted with a new key P. When the device needs to be rolled back to version V1 in the project, if it is rolled back directly, since the program of version V1 does not support the algorithm of the new key P, the configuration file will not be decrypted, resulting in configuration loss and device failure. According to the key update method provided in the embodiment of the present invention, the image of version V1 is written into 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 version V2 is still running on the device at this time, each module can use key P to decrypt the configuration file in the memory, and then use key K to re-encrypt the configuration plaintext. After that, the device is restarted and the device rolls back to version V1. Since the algorithm library version of key K is the same as the algorithm library version 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 kept in plain text during the device restart process, sensitive configuration leakage or loss is avoided.
[0071] The following is a detailed description through two specific embodiments:
[0072] Example 1
[0073] This embodiment provides a key update method, which 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, check 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 according to 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, 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 process shown below is 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, byte B1=B; the device upgrade is completed after the device is restarted.
[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 the 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 one of the items is not true, S106, directly delete the flag file kupflag without performing 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, wherein curr_keyid=keyid of the new key; max_keyid=max_keyid+1; current key version=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 uses the new key to re-encrypt the configuration file; 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, first finds the corresponding key and algorithm from the key file keyfile according to the keyid saved in the header of the current configuration file ciphertext, calls the decryption operation interface to decrypt the configuration file ciphertext to obtain the configuration plaintext, then finds curr_keyid (key4) from the above-mentioned key file keyfile, calls the encryption operation interface, uses the curr_keyid as the encryption key, uses the corresponding encryption algorithm (AES512) to re-encrypt the configuration plaintext, and finally writes the re-encrypted configuration file 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, which 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 algorithm library version of the current key 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, B=1.
[0106] Write the upgrade image to the device flash before restarting the device. Figure 3 The process shown below is to update the key:
[0107] S201, determining 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 V3.0 of the current key is greater than the algorithm library version V2.0 of the upgrade image, the key rollback operation is currently being performed.
[0109] When performing a key rollback operation, S202, searching for a rollback key from the key file keyfile;
[0110] Specifically, a key with the same algorithm library version (V2.0) as the upgraded image and the largest keyid is searched from the key file keyfile shown in (1) as the fallback key, and the keyid of the fallback key is key3;
[0111] S203, assigning 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 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 a 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 implement the aforementioned key updating method when executed.
[0121] In the several embodiments provided in the present 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 only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, 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 separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this 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 one module. The above-mentioned integrated modules may be implemented in the form of hardware or in the form of software functional modules.
[0123] If the integrated module is implemented in the form of a software function 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 is essentially 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, including several instructions for a computer device (which can be a personal computer, a server, or a 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: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0124] It should be noted that, for the convenience of description, the aforementioned method embodiments are all described as a series of action combinations, but those skilled in the art should be aware that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the 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 the part 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 used to limit the present invention. Although the present invention is described in detail with reference to the above embodiments, for those skilled in the art, they can still modify the technical solutions recorded in the above embodiments, or replace some of the technical features therein with equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A key updating method, characterized in that: The method comprises: In response to the device update instruction, write the upgrade image into 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 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.
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 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; The key update file kupfile is deployed into the image body of the upgrade image.
3. The method according to claim 2, characterized in that The compiling the upgrade image further comprises: Automatically generate label 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 step of automatically generating the tag bytes in the upgrade image header includes: Parse the key update file kupfile, and write 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, it also includes: 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 the current key update type includes: Determine whether the algorithm library version of the current key is higher than the algorithm library version of the upgrade image, and if so, perform key rollback; 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: The algorithm library version, algorithm, algorithm parameters and keyid of the new key are written into the key file keyfile, and the key file keyfile is updated.
9. The method according to claim 8, characterized in that The updating of the key file keyfile comprises: curr_keyid = the 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 The step of searching the key file keyfile for the key corresponding to the upgrade image as the current key includes: A key with the same algorithm library version as the upgraded image and the largest keyid is found from the key file keyfile as the current key.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed, the key updating method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Key updating method and device as well as storage medium
CN107483186A
Authentication and key negotiation method and device, and storage medium
CN114726555A
Software upgrading method of vehicle, server, vehicle, storage medium and system
CN116243950A
Online change of encryption root keys in a distributed database management system
US20180145831A1
Method, device and computer program product for storage
US20210303196A1
