Self-adaptive program upgrading method and system for electric energy meter
Technical Field
The invention relates to the technical field of electric energy meters, in particular to a self-adaptive program upgrading method and system of an electric energy meter.
Background
With the improvement of the automation level of the power grid and the domestic power utilization level, the demand and the utilization rate of electric energy sources of people are increased year by year, and the application of the electronic electric energy meter is more and more extensive. In order to facilitate the centralized management of an electric power company and meet the new requirements of customers for use, a relatively mature electric energy meter program upgrading method is formed in the existing market on the premise of not increasing the use cost of the customers. The upgrading method comprises the steps of calculating the CRC or MD5 value of an upgrading file, sending the upgrading file and the calculated check value to the electric energy meter to be upgraded in an asymmetric encryption mode, and then carrying out program upgrading on the electric energy meter to be upgraded after the completeness and the consistency of the upgrading file are ensured through a digital signature technology.
However, in the prior art, the problem of security of the upgrade file is more considered, the electric energy meter is ensured to obtain the complete upgrade file and then perform program upgrade, but the problem of judging whether the electric energy meter is upgradable does not exist, so that the situation that the unmatched electric energy meter is abnormally worked or cannot be upgraded again after being upgraded by mistake can not be avoided, the efficiency of field application can be influenced, and the use cost of a client is increased.
Disclosure of Invention
The invention aims to overcome the defects of the prior art, and provides a self-adaptive program upgrading method and a self-adaptive program upgrading system for an electric energy meter.
In order to solve the above technical problem, an embodiment of the present invention provides an adaptive program upgrading method for an electric energy meter, where the upgrading method includes:
the electric energy meter to be upgraded receives an upgrade file and a signature file which are sent by a system master station;
detecting whether a hardware digital signature chip exists on the electric energy meter to be upgraded or not;
after detecting that the hardware digital signature chip does not exist on the electric energy meter to be upgraded, judging whether the upgrade file needs the support of the hardware digital signature chip;
after the upgrade file is judged not to be supported by the hardware digital signature chip, the signature file is decrypted by using a public key of a digital signature, and whether the upgrade file is correct or not is verified;
and after the upgrading file is verified to be correct, the electric energy meter to be upgraded executes program upgrading according to the upgrading file.
Optionally, before the electric energy meter to be upgraded receives the upgrade file and the signature file sent by the system master station, the method includes:
the system master station acquires the upgrading information and the upgrading file of the electric energy meter to be upgraded;
processing the upgrade file based on a Hash algorithm to obtain summary information;
encrypting the summary information based on a private key of a digital signature to generate the signature file;
and transmitting the upgrading file and the signature file to the electric energy meter to be upgraded based on the upgrading information.
Optionally, after detecting whether the hardware digital signature chip exists on the electric energy meter to be upgraded, the method includes:
if the hardware digital signature chip exists on the electric energy meter to be upgraded, decrypting the signature file by using a public key of a digital signature;
and if the electric energy meter to be upgraded is detected to be not provided with the hardware digital signature chip, judging whether the upgrade file needs the support of the hardware digital signature chip.
Optionally, the determining whether the upgrade file needs the support of the hardware digital signature chip includes:
performing summary operation on the upgrade package based on a Hash algorithm to generate first summary information;
judging whether the first summary information is consistent with the summary information which is stored in the electric energy meter to be upgraded in advance;
if the upgrade files are consistent with the hardware digital signature chip, judging that the upgrade files need the support of the hardware digital signature chip, and stopping upgrading the electric energy meter to be upgraded;
if not, judging that the upgrade file does not need the support of the hardware digital signature chip, and decrypting the signature file by using a public key of the digital signature.
Optionally, the upgrade package includes the upgrade file and the signature file.
In addition, an embodiment of the present invention further provides a system for upgrading an adaptive program of an electric energy meter, where the system includes:
the receiving module is used for receiving the upgrade file and the signature file sent by the system master station;
the detection module is used for detecting whether a hardware digital signature chip exists on the electric energy meter to be upgraded;
the judging module is used for judging whether the upgrade file needs the support of the hardware digital signature chip;
the decryption module is used for decrypting the signature file by using the public key of the digital signature and verifying whether the upgrade file is correct or not;
and the upgrading module is used for upgrading the electric energy meter execution program to be upgraded according to the upgrading file.
Optionally, the system further includes:
the system master station is used for acquiring the upgrading information and the upgrading file of the electric energy meter to be upgraded;
processing the upgrade file based on a Hash algorithm to obtain summary information;
encrypting the summary information based on a private key of a digital signature to generate the signature file;
and transmitting the upgrading file and the signature file to the electric energy meter to be upgraded based on the upgrading information.
Optionally, the determining module is configured to perform digest operation on an upgrade package based on a hash algorithm and generate first digest information, where the upgrade package includes the upgrade file and the signature file;
judging whether the first summary information is consistent with the summary information which is stored in the electric energy meter to be upgraded in advance;
if the electric energy meters are consistent, the upgrading of the electric energy meters to be upgraded is stopped;
and if the two files are not consistent, decrypting the signature file by using the public key of the digital signature.
In the embodiment of the invention, aiming at the safety problem of program upgrading of the electric energy meter to be upgraded, the digital signature technology is adopted, and the integrity and consistency of the upgrading file in the transmission process are ensured by using the signature of a system master station to the upgrading file and the signature verification of the electric energy meter to be upgraded to the upgrading file; aiming at the feasibility problem of program upgrading of the electric energy meter to be upgraded, whether a hardware digital signature chip exists in the electric energy meter to be upgraded or not is detected, whether the upgrade file needs the support of the hardware digital signature chip or not is verified, the electric energy meter to be upgraded is guaranteed to execute upgrading operation within an allowable range, and the risk that the electric energy meter is abnormal in work or cannot be upgraded again due to manual misoperation is greatly reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a method for upgrading an adaptive program of an electric energy meter according to an embodiment of the present invention;
fig. 2 is a schematic structural component diagram of an adaptive program upgrading system of an electric energy meter according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, fig. 1 is a schematic flowchart illustrating a method for upgrading an adaptive program of an electric energy meter according to an embodiment of the present invention, where the method includes the following steps:
s101, a system master station acquires upgrade information and an upgrade file of an electric energy meter to be upgraded;
it should be noted that the upgrade information includes: and the meter position information of the electric energy meter to be upgraded and the latest software version information.
Specifically, a system master station acquires the epitope information of the electric energy meter to be upgraded, establishes communication with the electric energy meter to be upgraded based on the epitope information, reads the current software version information of the electric energy meter to be upgraded, compares the current software version information with the latest software version information, and judges whether the electric energy meter to be upgraded is allowed to be upgraded or not;
if the current software version information is consistent with the latest software version information, judging that the electric energy meter to be upgraded is not allowed to be upgraded, generating an alarm signal, and recording the information of the upgraded program of the electric energy meter;
and if the current software version information is not consistent with the latest software version information, continuing to execute the step S102.
S102, processing the upgrade file based on a Hash algorithm to obtain summary information;
assuming that the upgrade file is M, calculating summary information of the upgrade file M based on a hash algorithm as follows: e-sha (m).
S103, encrypting the summary information based on a private key of the digital signature to generate a signature file;
specifically, the system master station encrypts the digest information based on a private key of a digital signature, wherein an elliptic curve digital signature algorithm is adopted, and the method comprises the following steps:
(1) selecting any base point G on the original elliptic curve Ep (a, b), wherein the order of the base point G is n;
(2) randomly selecting an integer K in the range of [1, n-1], and setting K as a private key of the digital signature, wherein a public key K of the digital signature meets a formula: k is kG;
(3) in [1, n-1]]Randomly selects an integer d, and selects a point p (x) on the original elliptic curve Ep (a, b)1,y1) And satisfies the point p (x)1,y1) The distance to the origin of coordinates is dG;
(4) calculating a portion r of the signature file as x1mod n, judging the value r, and if r is equal to 0, executing the step (3) again; if r ≠ 0, continuing to execute the step (5);
(5) calculating another part of the signature file s ═ d-1*(e+kr)mod n;
(6) And after the digest information e is encrypted, generating a signature file (r, s).
It should be noted that, the system master station encrypts the digest information based on the private key of the digital signature by using a public key system, and when the signature file generated by encryption is transmitted over a network, the elliptic curve Ep (a, b) and the point p (x) are generated1,y1) The base point G and the public key K are public parameters.
S104, transmitting the upgrading file and the signature file to the electric energy meter to be upgraded based on the upgrading information;
it should be noted that the upgrade information further includes a size of each data frame transmitted.
Specifically, based on the communication established between the system master station and the electric energy meter to be upgraded in step S101, the system master station transmits the upgrade file and the signature file to the electric energy meter to be upgraded according to the specified size of each data frame transmitted.
S105, the electric energy meter to be upgraded receives the upgrade file and the signature file;
s106, detecting whether a hardware digital signature chip exists on the electric energy meter to be upgraded or not; if not, executing step S107; if yes, executing step S108;
it should be noted that, detecting whether a hardware digital signature chip exists on the electric energy meter to be upgraded is a self-checking process of the electric energy meter to be upgraded, where the hardware digital signature chip is an ESAM chip.
Specifically, the internal program of the electric energy meter to be upgraded initializes the pin of the ESAM chip, sends a reset timing sequence to the ESAM chip, waits for the ESAM chip to reply a reset response signal, and determines that the electric energy meter to be upgraded does not have a hardware digital signature chip or determines that a faulty hardware digital signature chip exists on the electric energy meter to be upgraded when the reset response signal is not received after the electric energy meter to be upgraded is circularly sent for several times, and then executes step S107; and when the internal program of the electric energy meter to be upgraded receives the reset response signal, judging that the electric energy meter to be upgraded has a hardware digital signature chip, and executing the step S108.
It should be noted that before the electric energy meter to be upgraded performs self-checking of the hardware digital signature chip, memory capacity matching detection is performed according to the information carried by the upgrade file. Based on the information carried by the upgrade file, the electric energy meter to be upgraded acquires the capacity of a memory (EEPROM, FRAM, DataFlash) which is required to be used when the upgrade file can normally run after upgrading, reads the code area of an internal memory chip by using an internal program, and finally judges whether the two are matched. According to the self-checking result of the electric energy meter to be upgraded, when the capacity of a memory required after the upgrade file is upgraded to the electric energy meter to be upgraded is not matched with actual hardware resources, the electric energy meter to be upgraded cannot normally operate after being upgraded, and therefore the electric energy meter to be upgraded is directly refused to be upgraded.
S107, the electric energy meter to be upgraded judges whether the upgrade file needs the support of the hardware digital signature chip; if so, go to step 110; if not, go to step S108;
specifically, the electric energy meter to be upgraded performs summary operation on an upgrade package based on a hash algorithm to generate first summary information, wherein the upgrade package comprises the upgrade file and the signature file received by the electric energy meter to be upgraded; judging whether the first summary information is consistent with the summary information which is stored in the electric energy meter to be upgraded in advance; if the files are consistent, the upgrade files need the support of the hardware digital signature chip, and step S110 is executed; if not, the upgrade file does not need the support of the hardware digital signature chip, and step S108 is executed.
It should be noted that the summary information originally stored in the electric energy meter to be upgraded is calculated by a program requiring a hardware digital signature chip, and if the first summary information is consistent with the originally stored summary information, it is indicated that the electric energy meter to be upgraded needs support of the hardware digital signature chip when the program is upgraded.
S108, the electric energy meter to be upgraded decrypts the received signature file by using the public key of the digital signature, and verifies whether the upgrade file is correct; if yes, go to step S109; otherwise, go to step S110;
it should be noted that, according to step S103, since the system master station adopts a public key system, the electric energy meter to be upgraded can obtain the public key K and the point p (x) of the public digital signature1,y1) An elliptic curve Ep (a, b) and a base point G.
Specifically, the method for verifying the correctness of the upgrade file includes the following steps that the electric energy meter to be upgraded decrypts the received signature file (r, s) by using a public key K of a digital signature:
(1) assuming that the received upgrade file is M1Calculating the upgrade file M1Hash digest information of (1): e.g. of the type1=SHA(M1);
(2) Calculating s-1e1And n is a modulo value: u. of1=s-1e1mod n;
(3) Calculating rs-1And n is a modulo value: u. of2=rs-1mod n;
(4) Generating a target elliptic curve X, and satisfying the formula: x ═ u1G+u2K;
(5) Judging the target elliptic curve X, and if X is equal to 0, judging that the signature is illegal; if X ≠ 0, calculate X1And n is a modulo value: v ═ x1mod n;
(6) And comparing v and r, and if v ≠ r, verifying that the upgrade file is correct, and if v ≠ r, verifying that the upgrade file is tampered.
It should be noted that, when one encryption and decryption process includes two carriers, the two carriers must agree in advance to use the same algorithm to ensure that the decryption result has contrast, so in the decryption process, the hash algorithm used by the electric energy meter to be upgraded is consistent with the hash algorithm used by the system master station.
It should be noted that, when the hash algorithm is used for operation, there is an obvious feature: two identical input files can ensure that two identical abstract information are output, and even if one of the input files is slightly changed, the two output abstract information are greatly different.
In the decryption verification process, a back-certification method is adopted, assuming that the upgrade file and the signature file received by the electric energy meter to be upgraded are both correct, after the upgrade file is subjected to abstract operation to generate abstract information, the abstract information and the signature file are subjected to a series of operations, the signature file received by the electric energy meter to be upgraded is back-certified as the original signature file sent by a system master station, and the fact that the abstract information used in the decryption process is consistent with the abstract information used in the encryption process is verified, so that the upgrade file received by the electric energy meter to be upgraded is not tampered in the transmission process is guaranteed.
Optionally, the method for verifying whether the upgrade file received by the electric energy meter to be upgraded is correct further includes: decrypting the signature file received by the electric energy meter to be upgraded by using a public key of a digital signature, and acquiring decrypted first abstract information, wherein the first abstract information is obtained by performing abstract operation on an original upgrade file; performing summary operation on the upgrade file received by the electric energy meter to be upgraded based on a Hash algorithm to generate second summary information; judging whether the first abstract information is consistent with the second abstract information; if the upgrade files are consistent with the upgrade files, judging that the upgrade files received by the electric energy meter to be upgraded are not tampered in the transmission process; and if the upgrade files are inconsistent, judging that the upgrade files received by the electric energy meter to be upgraded are tampered in the transmission process.
S109, the electric energy meter to be upgraded executes program upgrading according to the upgrading file;
specifically, after the electric energy meter to be upgraded verifies that the upgrade file is correct, the upgrade file is loaded to a code area, and program upgrade is executed.
And S110, terminating upgrading of the electric energy meter to be upgraded.
Specifically, after the electric energy meter to be upgraded verifies that the upgrade file is incorrect, an alarm signal is generated, and invalid information of the upgrade file is recorded.
In the specific implementation process, the upgrading of the electric energy meter executive program to be upgraded at least meets three preconditions: firstly, after the electric energy meter to be upgraded receives the upgrade file, carrying out self-checking of matching of the capacity of a conventional hardware memory, and ensuring that the capacity of the memory required by normal operation after the upgrade file is upgraded is matched with the capacity of the memory in the electric energy meter to be upgraded; secondly, ensuring that a hardware digital signature chip exists in the electric energy meter to be upgraded, otherwise ensuring that the upgrade file does not need the support of the hardware digital signature chip; and finally, ensuring that the upgrading file is not tampered in the process of transmitting the upgrading file to the electric energy meter to be upgraded from the system master station. The self-checking capability of the electric energy meter to be upgraded plays a crucial role in feasibility of program upgrading, and the self-checking capability comprises self-checking of hardware memory capacity and self-checking of a hardware digital signature chip. And when the electric energy meter to be upgraded simultaneously meets the three preconditions, the program upgrading is allowed to be executed. Based on the three preconditions, the upgrading conditions of the two electric energy meters are respectively analyzed:
(1) the method comprises the steps that based on a single-phase table of TDK6542GT, an internal program is utilized to detect that the capacity of an EEPROM in a TDK6542GT chip is 64kb, the capacity of an FRAM is 16kb and the capacity of a DataFlash is 4Mb, if the single-phase table obtains that the capacity of the EEPROM needed after an upgrade file is upgraded into the table is 128kb according to information carried by the received upgrade file, and compared with the situation that actual hardware resources (the capacity of the EEPROM is 64kb) are not matched, the single-phase table refuses upgrading.
If the single-phase meter obtains that the capacity of an EEPROM (electrically erasable programmable read-only memory) required after the upgrade file is upgraded into the meter is 64kb according to the information carried by the received upgrade file, and an internal program is continuously utilized to detect that no hardware digital signature chip exists, if the upgrade file needs the support of the hardware digital signature chip, the single-phase meter refuses to upgrade.
(2) The method comprises the steps that based on a TDK6543GT three-phase table, an internal program is utilized to detect that the capacity of an EEPROM in a TDK6543GT chip is 64kb, the capacity of an FRAM is 16kb and the capacity of a DataFlash is 4Mb, if the three-phase table obtains the required capacity of the EEPROM after an upgrade file is upgraded into the table according to information carried by the received upgrade file and is 128kb, and compared with the situation that actual hardware resources (the capacity of the EEPROM is 64kb) are not matched, the three-phase table refuses upgrading.
If the three-phase table obtains that the capacity of an EEPROM (electrically erasable programmable read-only memory) required after the upgrade file is upgraded into the table is 64kb according to the received information carried by the upgrade file, and an internal program is continuously utilized to detect that no hardware digital signature chip exists, if the upgrade file needs the support of the hardware digital signature chip, the three-phase table refuses to be upgraded.
Referring to fig. 2, fig. 2 is a schematic structural composition diagram of an adaptive program upgrading system of an electric energy meter according to an embodiment of the present invention, where the system includes:
the system master station 201 is used for acquiring upgrading information and upgrading files of the electric energy meter to be upgraded; processing the upgrade file based on a Hash algorithm to obtain summary information; encrypting the summary information based on a private key of a digital signature to generate a signature file; and transmitting the upgrading file and the signature file to the electric energy meter to be upgraded based on the upgrading information.
A receiving module 202, configured to receive the upgrade file and the signature file sent by the system master station;
the detection module 203 is used for detecting whether a hardware digital signature chip exists on the electric energy meter to be upgraded;
the judging module 204 is configured to judge whether the upgrade file needs to be supported by the hardware digital signature chip;
specifically, the judging module is configured to perform digest operation on an upgrade package based on a hash algorithm and generate first digest information, where the upgrade package includes the upgrade file and the signature file; judging whether the first summary information is consistent with the summary information which is stored in the electric energy meter to be upgraded in advance; if the current time is consistent with the preset time, the electric energy meter to be upgraded is terminated; and if the two files are not consistent, decrypting the signature file by using the public key of the digital signature.
A decryption module 205, configured to decrypt the signature file with a public key of a digital signature, and verify whether the upgrade file is correct;
and the upgrading module 206 is configured to perform program upgrading on the electric energy meter to be upgraded according to the upgrading file.
For the specific implementation of each module in the system, please refer to the above-mentioned embodiment, which is not described herein again.
In the embodiment of the invention, aiming at the safety problem of program upgrading of the electric energy meter to be upgraded, the digital signature technology is adopted, and the integrity and consistency of the upgrading file in the transmission process are ensured by using the signature of a system master station to the upgrading file and the signature verification of the electric energy meter to be upgraded to the upgrading file; aiming at the feasibility problem of program upgrading of the electric energy meter to be upgraded, whether a hardware digital signature chip exists in the electric energy meter to be upgraded or not is detected, whether the upgrade file needs the support of the hardware digital signature chip or not is verified, the electric energy meter to be upgraded is guaranteed to execute upgrading operation within an allowable range, and the risk that the electric energy meter is abnormal in work or cannot be upgraded again due to manual misoperation is greatly reduced.
Those skilled in the art will appreciate that all or part of the steps in the methods of the above embodiments may be implemented by associated hardware instructed by a program, which may be stored in a computer-readable storage medium, and the storage medium may include: a Read Only Memory (ROM), a Random Access Memory (RAM), a magnetic or optical disk, or the like.
In addition, the above detailed description is given to the adaptive program upgrading method and system for an electric energy meter provided by the embodiment of the present invention, and a specific example should be adopted herein to explain the principle and the implementation manner of the present invention, and the description of the above embodiment is only used to help understanding the method and the core idea of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.