CN107545181B - Program operating method, terminal, and computer-readable storage medium - Google Patents

Program operating method, terminal, and computer-readable storage medium Download PDF

Info

Publication number
CN107545181B
CN107545181B CN201710704602.9A CN201710704602A CN107545181B CN 107545181 B CN107545181 B CN 107545181B CN 201710704602 A CN201710704602 A CN 201710704602A CN 107545181 B CN107545181 B CN 107545181B
Authority
CN
China
Prior art keywords
hash value
program
unique identifier
detected
domain name
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710704602.9A
Other languages
Chinese (zh)
Other versions
CN107545181A (en
Inventor
徐刚
胡淳一
陈盛东
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Ceying Network Technology Co ltd
Original Assignee
Shanghai Ceying Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Ceying Network Technology Co ltd filed Critical Shanghai Ceying Network Technology Co ltd
Priority to CN201710704602.9A priority Critical patent/CN107545181B/en
Publication of CN107545181A publication Critical patent/CN107545181A/en
Application granted granted Critical
Publication of CN107545181B publication Critical patent/CN107545181B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention discloses a program running method, a terminal and a computer readable storage medium, wherein the program running method comprises the following steps: when an operation instruction is received, acquiring a unique identifier of a current program; acquiring a reference hash value corresponding to the unique identifier from a block chain system according to the unique identifier; performing hash operation on the current program code to obtain a hash value to be detected; and detecting whether the hash value to be detected is consistent with the reference hash value, and if so, continuing to normally run the current program. By the method and the device, the program can be detected before the program runs, whether the program is tampered or not is detected, and adverse consequences caused by the operation of the tampered program are avoided.

Description

Program operating method, terminal, and computer-readable storage medium
Technical Field
The present invention relates to the field of computer programs, and in particular, to a program running method, a terminal, and a computer-readable storage medium.
Background
With the rapid development of computer technology, computer programs have proven to be used in some fields to replace human work, even more so than human. Computer programs are typically written in a programming language and run on a target architecture for a specific purpose based on the purpose to be achieved.
However, if a group of programs is illegally tampered before running, specific purposes cannot be achieved after the programs are run, and even serious consequences are generated, so that loss is caused to users.
Disclosure of Invention
The invention mainly aims to provide a program running method, a terminal and a computer readable storage medium, and aims to solve the technical problem that whether a program is tampered before running in the prior art cannot be detected.
In order to achieve the above object, the present invention provides a program running method, including:
when an operation instruction is received, acquiring a unique identifier of a current program;
acquiring a reference hash value corresponding to the unique identifier from a block chain system according to the unique identifier;
performing hash operation on the current program code to obtain a hash value to be detected;
and detecting whether the hash value to be detected is consistent with the reference hash value, and if so, continuing to normally run the current program.
Preferably, after the receiving the operation instruction, before the obtaining the unique identifier of the current program includes:
applying for a unique identifier in a block chain, and writing the unique identifier into an original program code;
performing hash operation on the program code containing the unique identifier to obtain a reference hash value;
and associating and issuing the unique identifier and the reference hash value to a block chain.
Preferably, the detecting whether the hash value to be detected is consistent with the reference hash value includes:
and subtracting the hash value to be detected and the reference hash value, wherein when the value obtained by the subtraction is zero, the hash value to be detected is consistent with the reference hash value.
Preferably, the detecting whether the hash value to be detected is consistent with the reference hash value further includes:
and comparing the hash value to be detected with the reference hash value, and outputting a comparison passing or same instruction if the comparison is completely consistent.
Preferably, the performing a hash operation on the current program code to obtain a hash value to be detected includes:
acquiring algorithm identification information, and determining a corresponding hash algorithm according to the algorithm identification information;
and carrying out Hash operation on the current program code according to the Hash algorithm to obtain a Hash value to be detected.
Preferably, after detecting whether the hash value to be detected is consistent with the reference hash value, the method includes:
and if the hash value to be detected is not consistent with the reference hash value, outputting an alarm, or stopping the operation of the current program or abnormal operation of the program.
Preferably, the unique identifier is a decentralized domain name.
In addition, to achieve the above object, the present invention also provides a program execution terminal, including: the system comprises a memory, a processor and a program running program which is stored on the memory and can run on the processor, wherein the program running program realizes the steps of the program running method when being executed by the processor.
In addition, to achieve the above object, the present invention also provides a computer-readable storage medium having stored thereon a program execution program, which when executed by a processor, implements the steps of the program execution method as described above.
In the invention, after an operation instruction is received, a unique identifier of the program is obtained, a reference hash value corresponding to the unique identifier is obtained in a block chain, the reference hash value is compared with a hash value to be detected obtained by performing hash operation on the current program, and if the reference hash value is consistent with the hash value to be detected, the current program is operated. According to the method and the device, before the program runs, the reference hash value is obtained on the block chain according to the unique identifier of the program, then hash operation is carried out on the program to obtain the hash value to be tested, and based on a block chain tamper-proof mechanism, if the reference hash value is consistent with the hash value to be tested, the program is not tampered, and then the program is run. And adverse effects caused by the operation of a tampered program are avoided.
Drawings
Fig. 1 is a schematic terminal structure diagram of a hardware operating environment according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a first embodiment of a program running method according to the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, fig. 1 is a schematic terminal structure diagram of a hardware operating environment according to an embodiment of the present invention.
The terminal of the embodiment of the invention can be a PC, and can also be terminal equipment such as a smart phone, a tablet computer, a portable computer and the like.
As shown in fig. 1, the terminal may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the terminal structure shown in fig. 1 is not intended to be limiting and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a program execution program.
In the terminal shown in fig. 1, the network interface 1004 is mainly used for connecting to a backend server and performing data communication with the backend server; the user interface 1003 is mainly used for connecting a client (user side) and performing data communication with the client; and the processor 1001 may be configured to call the program stored in the memory 1005 to execute the program, and perform the following operations:
when an operation instruction is received, acquiring a unique identifier of a current program;
acquiring a reference hash value corresponding to the unique identifier from a block chain system according to the unique identifier;
performing hash operation on the current program code to obtain a hash value to be detected;
and detecting whether the hash value to be detected is consistent with the reference hash value, and if so, continuing to normally run the current program.
In the present embodiment, a program refers to a computer program, and refers to a coded instruction sequence that can be executed by an information processing device such as a computer to obtain a certain result, or a symbolic instruction sequence or symbolic statement sequence that can be automatically converted into a coded instruction sequence. The source and target programs of the same computer program are the same work. Computer programs are comprised of data structures and algorithms.
For example, a set of computer programs a is stored on a computer, and a user operating the computer triggers an execution instruction to execute the computer program a, wherein the computer program a is recorded with a unique identifier.
The unique identifier means that the identifier exists uniquely in a form which is not duplicated with other identifiers in a corresponding blockchain database. In one embodiment, the unique identifier may be a decentralized domain name. For example, first, a domain name is applied for a block chain, the domain name is registered according to a protocol format, for example, the registered domain name is shcy1.bit, and the domain name is confirmed to be unique according to a consensus mechanism of the block chain. Writing the decentralized domain name shcy1.bit into the computer program A. And then carrying out hash operation on the code of the computer program A written with the unique identifier to obtain a corresponding reference hash value, and distributing the reference hash value and the unique identifier, namely the decentralized domain name corresponding to the computer program A into a block chain in an associated manner. For example, the computer program a corresponds to a reference hash value a. Then, the decentralized domain name shcy1.bit is redirected to the hash value a in the blockchain, and then the reference hash value a can be obtained by searching in the blockchain according to the decentralized domain name shcy1. bit. In this embodiment, the unique identifier may be a decentralized domain name, but may also be other information, but the information needs to be guaranteed to have a unique characteristic (that is, the information has uniqueness in the block chain), for example, the information is associated with a mapping of a hash value X of the computer program and issued to the block chain, and the hash value X may be retrieved from the block chain through the mapping information.
In an optional embodiment of the present invention, first, a domain name is applied for a block chain, the domain name is registered according to a protocol format, for example, the registered domain name is shcy1.bit, and according to a consensus mechanism of the block chain, it is confirmed that all the domain names are unique. Then, the decentralized domain name shcy1.bit is written into a code of the computer program a, then, a specific hash algorithm is used to calculate a reference hash value of the program code (the algorithm identifier may be stored in the program running terminal, or the program code may be written into, and when the program needs to perform its own hash operation, the algorithm identifier is obtained from the terminal or obtained from the program code), and the hash algorithm may be specifically set according to actual needs, which is not limited herein. For example, if the algorithm identifier is 1, selecting a hash algorithm 1, performing hash operation on the computer program a in which the unique identifier (such as a decentralized domain name) is written by using the hash algorithm 1 to obtain a reference hash value a, and associating and issuing the reference hash value a with the decentralized domain name shcy1.bit to the blockchain. When a computer program A receives an operation instruction, firstly, a decentralized domain name shcy1.bit corresponding to the computer program A is obtained from a code of the computer program A, and then a reference hash value A corresponding to the decentralized domain name is obtained from a block chain according to the decentralized domain name shcy1. bit; and then, according to the algorithm identifier, the algorithm identifier can be stored in the program running terminal, and a program code can also be written in, when hash operation is required, the algorithm identifier is obtained from the terminal or the algorithm identifier is obtained from the program code, and the algorithm identifier is specifically set according to actual requirements, and is not limited herein. For example, if the algorithm identifier is 1, selecting hash algorithm 1, performing hash operation on the computer program a by using hash algorithm 1 to obtain a hash value to be measured (since it cannot be determined whether the computer program a is currently tampered, the hash value is referred to as a hash value to be measured), comparing the hash value to be measured with a reference hash value a obtained from a blockchain, if the two hash values are consistent, it is determined that the computer program a is not tampered, so the step of running the computer program a is executed, and if the two hash values are inconsistent, it is determined that the computer program a is tampered, outputting an alarm, for example, performing an alarm in the form of flashing light, displaying text, outputting an alarm sound, and the like, so as to prompt a user, and prevent the user from being lost due to the continued running of the tampered computer program a. Or when the hash value to be detected is not consistent with the reference hash value, the computer program a is operated in an abnormal manner, for example, a falsifier illegally falsifies the computer program a in order to obtain data of the computer program operation terminal a, if the falsified computer program a is normally operated, the data of the terminal a is leaked, at this time, when it is detected that the hash value to be detected is not consistent with the reference hash value, the computer program a is operated in an abnormal manner, so that the leaked data is wrong, and the falsifier cannot obtain the desired data, thereby achieving the effect of misleading the falsifier.
It should be noted that, in the above steps, the order of the two steps of obtaining the reference hash value of the program a from the blockchain and obtaining the hash value to be measured by performing the hash calculation on the code of the program a is not limited uniquely, and the program a may first obtain the reference hash value from the blockchain, or may first obtain the hash value to be measured by performing the hash calculation on the code.
In the invention, when an operation instruction is received, a program firstly acquires a unique identifier of the program, acquires a reference hash value corresponding to the unique identifier in a block chain, compares the reference hash value with a hash value to be detected obtained by hash operation of the program, and operates the program if the reference hash value is consistent with the hash value to be detected. According to the method and the device, the reference hash value is obtained on the block chain according to the unique identifier of the program, then hash operation is carried out on the program code to obtain the hash value to be detected, based on a block chain tamper-proof mechanism, if the reference hash value is consistent with the hash value to be detected, the program is not tampered, and then the program is operated. And adverse effects caused by the operation of a tampered program are avoided. The method of the invention is a method for independently inquiring and verifying after the program receives the operation instruction, and the manual inquiry and comparison work is saved.
Further, the processor 1001 may call the program execution program stored in the memory 1005, and further perform the following operations:
applying for a unique identifier in a block chain, and writing the unique identifier into an original program code;
performing hash operation on the program code containing the unique identifier to obtain a reference hash value;
and associating and issuing the unique identifier and the reference hash value to a block chain.
In this embodiment, the unique identifier may be a decentralized domain name. For example, first, a domain name is applied for a blockchain, the domain name is registered according to a protocol format, for example, the registered domain name is shcy1.bit, and it is determined that the domain name is unique in the blockchain according to a consensus mechanism of the blockchain. Writing the decentralized domain name shcy1.bit into the computer program A. And then carrying out hash operation on the computer program A written with the unique identifier to obtain a corresponding reference hash value, and publishing the reference hash value and the unique identifier corresponding to the computer program A into a block chain in a decentralized domain name association manner. For example, the computer program a corresponds to a reference hash value a. Then, the centralized domain name shcy1.bit is redirected in the block chain to point to the hash value A, and then the reference hash value A can be obtained by searching in the block chain according to the decentralized domain name shcy1. bit. In this embodiment, the unique identifier may be a decentralized domain name, but may also be other information, but the information needs to be guaranteed to have a unique characteristic (that is, the information has uniqueness in the block chain), for example, the information is associated and issued with a mapping of a hash value X of the computer program, and the hash value X is obtained by retrieving the unique identifier from the block chain through the mapping information.
It should be noted that, the operation of applying for the unique identifier for the program on the block chain and writing the unique identifier into the program may be performed by the program itself when the program is initialized to run, or performed by other programs operating on the original program, or performed by a program developer before the program is compiled. If the program initialization operation is completed by the program itself, the program code before the program initialization changes after the unique identifier is written, so the reference hash value must be generated by calculating the program code after the unique identifier is written, and on the premise that the program version is not updated or other codes are not changed, the program initialization only performs once the operations of generating the unique identifier in the blockchain, writing the unique identifier into the program code, generating the reference hash value of the program code, and issuing the reference hash value in the blockchain in association with the unique identifier.
In this embodiment, because the identifier corresponding to the program is unique, after the reference hash value and the identifier of the program are issued to the blockchain in an associated manner, the reference hash value of the program can be retrieved in the blockchain according to the identifier subsequently in the program, then hash operation is performed on the program code to obtain the hash value to be detected, the hash value to be detected is compared with the reference hash value, only when the hash value to be detected is consistent with the reference hash value, the program can continue to operate normally, and adverse consequences caused by the operation of the tampered program are avoided.
Further, the processor 1001 may call the program execution program stored in the memory 1005, and further perform the following operations:
and comparing the hash value to be detected with the reference hash value, and outputting a comparison passing or same instruction if the comparison is completely consistent.
In this embodiment, after a reference hash value is obtained from the blockchain system according to the unique identifier of the program, according to the algorithm identifier, for example, the algorithm identifier is written into the program code in advance, the algorithm identifier is obtained from the program code, for example, the algorithm identifier is 1, and corresponding to the hash algorithm 1, hash operation is performed on the program through the hash algorithm 1 to obtain a hash value to be measured (the hash value is called as a hash value to be measured because it cannot be determined whether the computer program is currently tampered), and then through a character comparison method, if the reference hash value is completely consistent with the hash value to be measured through the character comparison, a command (Yes or No command) that the comparison is passed or the same is output, so that the terminal normally runs the program after receiving the command.
In this embodiment, when it is detected that the hash value to be detected is consistent with the reference hash value, it is indicated that the program has not been tampered, and the program can be normally run, thereby avoiding adverse consequences caused by running the tampered program.
Further, the processor 1001 may call the program execution program stored in the memory 1005, and further perform the following operations:
and subtracting the hash value to be detected and the reference hash value, wherein when the value obtained by the subtraction is zero, the hash value to be detected is consistent with the reference hash value.
The hash algorithm maps an arbitrary length binary value to a shorter fixed length binary value, this small binary value being referred to as the hash value. Hash values are a unique and extremely compact representation of a piece of data as a value. If a piece of plaintext is hashed and even if only one letter of the piece is altered, the subsequent hash will produce a different value. It is computationally infeasible to find two different inputs whose hash is the same value, so the hash value of the data can verify the integrity of the data.
In this embodiment, after the reference hash value is obtained from the blockchain system according to the unique identifier of the program, according to the algorithm identifier, for example, the algorithm identifier is written into the program code in advance, the algorithm identifier is obtained from the program code, for example, the algorithm identifier is 1, and corresponding to the hash algorithm 1, hash operation is performed on the program through the hash algorithm 1 to obtain the hash value to be measured (since it cannot be determined whether the computer program is currently tampered, the hash value is called as the hash value to be measured), then subtraction operation is performed on the hash value to be measured and the reference hash value to obtain an operation result, if the operation result is zero, it is indicated that the hash value to be measured is the same as the reference hash value, and thus it is indicated that the program is not tampered. Whether the hash value to be detected is the same as the reference hash value or not is checked by using subtraction, so that the risk that a result instruction (such as Yes/Yes or No/No) output by adopting a numerical value or character comparison method is easily tampered by a program intruder is avoided.
In this embodiment, when it is detected that the hash value to be detected is consistent with the reference hash value, it is indicated that the program has not been tampered, and the program can be normally run, thereby avoiding adverse consequences caused by running the tampered program.
Further, the processor 1001 may call the program execution program stored in the memory 1005, and further perform the following operations:
acquiring algorithm identification information, and determining a corresponding hash algorithm according to the algorithm identification information;
and carrying out Hash operation on the current program code according to the Hash algorithm to obtain a Hash value to be detected.
In this embodiment, since the selection of the hash algorithm is more, it is required to ensure that the algorithm used when the reference hash value is obtained is consistent with the algorithm used when the hash value to be measured is obtained, so that an algorithm identification information may be set, for example, algorithm identification information 1 corresponds to hash algorithm 1, and algorithm identification information 2 corresponds to hash algorithm 2. The algorithm identifier is written into the program code or stored in the program running terminal, and is specifically set according to actual needs, which is not limited herein. When an operation instruction for operating the program a is received, acquiring an algorithm identifier from the program code or the program operation terminal, for example, if the acquired algorithm identifier is 1, performing hash operation on the program code according to the hash algorithm 1 corresponding to the algorithm identifier 1, and obtaining a reference hash value corresponding to the program code.
According to the method and the device, the compatibility of the scheme of the invention to various hash algorithms is enriched, and the type of the hash algorithm is determined according to the algorithm identification before the hash operation is carried out, so that the algorithm used when the reference hash value is obtained is consistent with the algorithm used when the hash value to be detected is obtained, and the accuracy of the detection result is ensured.
Further, the processor 1001 may call the program execution program stored in the memory 1005, and further perform the following operations:
and if the hash value to be detected is not consistent with the reference hash value, outputting an alarm, or stopping the program or abnormally operating the program.
In this embodiment, if it is detected that the hash value to be detected is not consistent with the reference hash value, indicating that the program is tampered, an alarm is output, for example, in the form of light flashing, text display, and output of an alarm sound, so as to prompt the user and prevent the user from being lost due to the continued operation of the tampered computer program. Or when the hash value to be detected is not consistent with the reference hash value, the computer program is operated in an abnormal manner, for example, a falsifier illegally falsifies the computer program to obtain data of a terminal where the computer program operates, if the falsified computer program is operated normally, the data of the terminal is leaked, at this time, when the hash value to be detected is detected to be inconsistent with the reference hash value, the computer program is operated in an abnormal manner, so that the leaked data is wrong, and the falsifier cannot obtain desired data, thereby achieving the effect of misleading the falsifier.
Further, the processor 1001 may call the program execution program stored in the memory 1005, and further perform the following operations:
the unique identifier is a decentralized domain name.
In an alternative embodiment of the present invention, the unique identifier may be a decentralized domain name. For example, first, a domain name is applied for a block chain, the domain name is registered according to a protocol format, for example, the registered domain name is shcy1.bit, and the domain name is confirmed to be unique according to a consensus mechanism of the block chain. Writing the decentralized domain name shcy1.bit into the computer program A. And then carrying out hash operation on the computer program A written with the unique identifier to obtain a corresponding reference hash value, and publishing the reference hash value and the unique identifier corresponding to the computer program A into a block chain in a decentralized domain name association manner. For example, the computer program a corresponds to a reference hash value a. Then, the decentralized domain name shcy1.bit is redirected in the block chain to point to the hash value A, and then the reference hash value A can be obtained through retrieval in the block chain according to the decentralized domain name shcy1. bit. In this embodiment, the unique identifier may be a decentralized domain name, but may also be other information, but the information needs to be guaranteed to have a unique characteristic (that is, the information has uniqueness in the block chain), for example, the information is associated and issued with the mapping of the hash value X of the computer program, and the hash value X is obtained by retrieving the unique identifier in the block chain through the mapping information.
In this embodiment, because the identifier corresponding to the program is unique, after the reference hash value and the identifier of the program are issued to the blockchain in an associated manner, the reference hash value of the program can be subsequently retrieved in the blockchain according to the unique identifier before the program runs, then the hash operation is performed on the program to obtain the hash value to be measured, the hash value to be measured is compared with the reference hash value, the program is run only when the hash value to be measured is consistent with the reference hash value, and adverse consequences caused by running the tampered program are avoided.
Referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of the program running method according to the present invention.
In one embodiment, a program execution method includes:
step S10, when receiving the operation instruction, obtaining the unique identification of the current program;
step S20, acquiring a reference hash value corresponding to the unique identifier from the blockchain system according to the unique identifier;
step S30, carrying out hash operation on the current program code to obtain a hash value to be detected;
and step S40, detecting whether the hash value to be detected is consistent with the reference hash value, and if so, continuing to normally run the current program.
In the present embodiment, a program refers to a computer program, and refers to a coded instruction sequence that can be executed by an information processing device such as a computer to obtain a certain result, or a symbolic instruction sequence or symbolic statement sequence that can be automatically converted into a coded instruction sequence. The source and target programs of the same computer program are the same work. Computer programs are comprised of data structures and algorithms.
For example, a set of computer programs a is stored on a computer, and a user operating the computer triggers an execution instruction to execute the computer program a, wherein the computer program a is recorded with a unique identifier.
The unique identifier means that the identifier exists uniquely in a form which is not duplicated with other identifiers in a corresponding blockchain database. In one embodiment, the unique identifier may be a decentralized domain name. For example, first, a domain name is applied for a block chain, the domain name is registered according to a protocol format, for example, the registered domain name is shcy1.bit, and the domain name is confirmed to be unique according to a consensus mechanism of the block chain. Writing the decentralized domain name shcy1.bit into the computer program A. And then carrying out hash operation on the code of the computer program A written with the unique identifier to obtain a corresponding reference hash value, and distributing the reference hash value and the unique identifier, namely the decentralized domain name corresponding to the computer program A into a block chain in an associated manner. For example, the computer program a corresponds to a reference hash value a. Then, the decentralized domain name shcy1.bit is redirected to the hash value a in the blockchain, and then the reference hash value a can be obtained by searching in the blockchain according to the decentralized domain name shcy1. bit. In this embodiment, the unique identifier may be a decentralized domain name, but may also be other information, but the information needs to be guaranteed to have a unique characteristic (that is, the information has uniqueness in the block chain), for example, the information is associated with a mapping of a hash value X of the computer program and issued to the block chain, and the hash value X may be retrieved from the block chain through the mapping information.
In an optional embodiment of the present invention, first, a domain name is applied for a block chain, the domain name is registered according to a protocol format, for example, the registered domain name is shcy1.bit, and according to a consensus mechanism of the block chain, it is confirmed that all the domain names are unique. Then, the decentralized domain name shcy1.bit is written into a code of the computer program a, then, a specific hash algorithm is used to calculate a reference hash value of the program code (the algorithm identifier may be stored in the program running terminal, or the program code may be written into, and when the program needs to perform its own hash operation, the algorithm identifier is obtained from the terminal or obtained from the program code), and the hash algorithm may be specifically set according to actual needs, which is not limited herein. For example, if the algorithm identifier is 1, selecting a hash algorithm 1, performing hash operation on the computer program a in which the unique identifier (such as a decentralized domain name) is written by using the hash algorithm 1 to obtain a reference hash value a, and associating and issuing the reference hash value a with the decentralized domain name shcy1.bit to the blockchain. When a computer program A receives an operation instruction, firstly, a decentralized domain name shcy1.bit corresponding to the computer program A is obtained from a code of the computer program A, and then a reference hash value A corresponding to the decentralized domain name is obtained from a block chain according to the decentralized domain name shcy1. bit; and then, according to the algorithm identifier, the algorithm identifier can be stored in the program running terminal, and a program code can also be written in, when hash operation is required, the algorithm identifier is obtained from the terminal or the algorithm identifier is obtained from the program code, and the algorithm identifier is specifically set according to actual requirements, and is not limited herein. For example, if the algorithm identifier is 1, selecting hash algorithm 1, performing hash operation on the computer program a by using hash algorithm 1 to obtain a hash value to be measured (since it cannot be determined whether the computer program a is currently tampered, the hash value is referred to as a hash value to be measured), comparing the hash value to be measured with a reference hash value a obtained from a blockchain, if the two hash values are consistent, it is determined that the computer program a is not tampered, so the step of running the computer program a is executed, and if the two hash values are inconsistent, it is determined that the computer program a is tampered, outputting an alarm, for example, performing an alarm in the form of flashing light, displaying text, outputting an alarm sound, and the like, so as to prompt a user, and prevent the user from being lost due to the continued running of the tampered computer program a. Or when the hash value to be detected is not consistent with the reference hash value, the computer program a is operated in an abnormal manner, for example, a falsifier illegally falsifies the computer program a in order to obtain data of the computer program operation terminal a, if the falsified computer program a is normally operated, the data of the terminal a is leaked, at this time, when it is detected that the hash value to be detected is not consistent with the reference hash value, the computer program a is operated in an abnormal manner, so that the leaked data is wrong, and the falsifier cannot obtain the desired data, thereby achieving the effect of misleading the falsifier.
It should be noted that, in the above steps, the order of the two steps of obtaining the reference hash value of the program a from the blockchain and obtaining the hash value to be measured by performing the hash calculation on the code of the program a is not limited uniquely, and the program a may first obtain the reference hash value from the blockchain, or may first obtain the hash value to be measured by performing the hash calculation on the code.
In the invention, when an operation instruction is received, a program firstly acquires a unique identifier of the program, acquires a reference hash value corresponding to the unique identifier in a block chain, compares the reference hash value with a hash value to be detected obtained by hash operation of the program, and operates the program if the reference hash value is consistent with the hash value to be detected. According to the method and the device, the reference hash value is obtained on the block chain according to the unique identifier of the program, then hash operation is carried out on the program code to obtain the hash value to be detected, based on a block chain tamper-proof mechanism, if the reference hash value is consistent with the hash value to be detected, the program is not tampered, and then the program is operated. And adverse effects caused by the operation of a tampered program are avoided. The method of the invention is a method for independently inquiring and verifying after the program receives the operation instruction, and the manual inquiry and comparison work is saved.
Further, in an embodiment of the program executing method of the present invention, step S10 includes:
applying for a unique identifier in a block chain, and writing the unique identifier into an original program code;
performing hash operation on the program code containing the unique identifier to obtain a reference hash value;
and associating and issuing the unique identifier and the reference hash value to a block chain.
In this embodiment, the unique identifier may be a decentralized domain name. For example, first, a domain name is applied for a blockchain, the domain name is registered according to a protocol format, for example, the registered domain name is shcy1.bit, and it is determined that the domain name is unique in the blockchain according to a consensus mechanism of the blockchain. Writing the decentralized domain name shcy1.bit into the computer program A. And then carrying out hash operation on the computer program A written with the unique identifier to obtain a corresponding reference hash value, and publishing the reference hash value and the unique identifier corresponding to the computer program A into a block chain in a decentralized domain name association manner. For example, the computer program a corresponds to a reference hash value a. Then, the centralized domain name shcy1.bit is redirected in the block chain to point to the hash value A, and then the reference hash value A can be obtained by searching in the block chain according to the decentralized domain name shcy1. bit. In this embodiment, the unique identifier may be a decentralized domain name, but may also be other information, but the information needs to be guaranteed to have a unique characteristic (that is, the information has uniqueness in the block chain), for example, the information is associated and issued with a mapping of a hash value X of the computer program, and the hash value X is obtained by retrieving the unique identifier from the block chain through the mapping information.
It should be noted that, the operation of applying for the unique identifier for the program on the block chain and writing the unique identifier into the program may be performed by the program itself when the program is initialized to run, or performed by other programs operating on the original program, or performed by a program developer before the program is compiled. If the program initialization operation is completed by the program itself, the program code before the program initialization changes after the unique identifier is written, so the reference hash value must be generated by calculating the program code after the unique identifier is written, and on the premise that the program version is not updated or other codes are not changed, the program initialization only performs once the operations of generating the unique identifier in the blockchain, writing the unique identifier into the program code, generating the reference hash value of the program code, and issuing the reference hash value in the blockchain in association with the unique identifier.
In this embodiment, because the identifier corresponding to the program is unique, after the reference hash value and the identifier of the program are issued to the blockchain in an associated manner, the reference hash value of the program can be retrieved in the blockchain according to the identifier subsequently in the program, then hash operation is performed on the program code to obtain the hash value to be detected, the hash value to be detected is compared with the reference hash value, only when the hash value to be detected is consistent with the reference hash value, the program can continue to operate normally, and adverse consequences caused by the operation of the tampered program are avoided.
Further, in an embodiment of the program running method of the present invention, the detecting whether the hash value to be detected is consistent with the reference hash value includes:
and subtracting the hash value to be detected and the reference hash value, wherein when the value obtained by the subtraction is zero, the hash value to be detected is consistent with the reference hash value.
The hash algorithm maps an arbitrary length binary value to a shorter fixed length binary value, this small binary value being referred to as the hash value. Hash values are a unique and extremely compact representation of a piece of data as a value. If a piece of plaintext is hashed and even if only one letter of the piece is altered, the subsequent hash will produce a different value. It is computationally infeasible to find two different inputs whose hash is the same value, so the hash value of the data can verify the integrity of the data.
In this embodiment, after the reference hash value is obtained from the blockchain system according to the unique identifier of the program, according to the algorithm identifier, for example, the algorithm identifier is written into the program code in advance, the algorithm identifier is obtained from the program code, for example, the algorithm identifier is 1, and corresponding to the hash algorithm 1, hash operation is performed on the program through the hash algorithm 1 to obtain the hash value to be measured (since it cannot be determined whether the computer program is currently tampered, the hash value is called as the hash value to be measured), then subtraction operation is performed on the hash value to be measured and the reference hash value to obtain an operation result, if the operation result is zero, it is indicated that the hash value to be measured is the same as the reference hash value, and thus it is indicated that the program is not tampered. Whether the hash value to be detected is the same as the reference hash value or not is checked by using subtraction, so that the risk that a result instruction (such as Yes/Yes or No/No) output by adopting a numerical value or character comparison method is easily tampered by a program intruder is avoided.
In this embodiment, when it is detected that the hash value to be detected is consistent with the reference hash value, it is indicated that the program has not been tampered, and the program can be normally run, thereby avoiding adverse consequences caused by running the tampered program.
Further, in an embodiment of the program running method of the present invention, the detecting whether the hash value to be detected is consistent with the reference hash value further includes:
and comparing the hash value to be detected with the reference hash value, and outputting a comparison passing or same instruction if the comparison is completely consistent.
In this embodiment, after a reference hash value is obtained from the blockchain system according to the unique identifier of the program, according to the algorithm identifier, for example, the algorithm identifier is written into the program code in advance, the algorithm identifier is obtained from the program code, for example, the algorithm identifier is 1, and corresponding to the hash algorithm 1, hash operation is performed on the program through the hash algorithm 1 to obtain a hash value to be measured (the hash value is called as a hash value to be measured because it cannot be determined whether the computer program is currently tampered), and then through a character comparison method, if the reference hash value is completely consistent with the hash value to be measured through the character comparison, a command (Yes or No command) that the comparison is passed or the same is output, so that the terminal normally runs the program after receiving the command.
In this embodiment, when it is detected that the hash value to be detected is consistent with the reference hash value, it is indicated that the program has not been tampered, and the program can be normally run, thereby avoiding adverse consequences caused by running the tampered program.
Further, in an embodiment of the program executing method of the present invention, step S30 includes:
acquiring algorithm identification information, and determining a corresponding hash algorithm according to the algorithm identification information;
and carrying out Hash operation on the current program code according to the Hash algorithm to obtain a Hash value to be detected.
In this embodiment, since the selection of the hash algorithm is more, it is required to ensure that the algorithm used when the reference hash value is obtained is consistent with the algorithm used when the hash value to be measured is obtained, so that an algorithm identification information may be set, for example, algorithm identification information 1 corresponds to hash algorithm 1, and algorithm identification information 2 corresponds to hash algorithm 2. The algorithm identifier is written into the program code or stored in the program running terminal, and is specifically set according to actual needs, which is not limited herein. When an operation instruction for operating the program a is received, acquiring an algorithm identifier from the program code or the program operation terminal, for example, if the acquired algorithm identifier is 1, performing hash operation on the program code according to the hash algorithm 1 corresponding to the algorithm identifier 1, and obtaining a reference hash value corresponding to the program code.
According to the method and the device, the compatibility of the scheme of the invention to various hash algorithms is enriched, and the type of the hash algorithm is determined according to the algorithm identification before the hash operation is carried out, so that the algorithm used when the reference hash value is obtained is consistent with the algorithm used when the hash value to be detected is obtained, and the accuracy of the detection result is ensured.
Further, in an embodiment of the program running method of the present invention, after detecting whether the hash value to be detected is consistent with the reference hash value, the method includes:
and if the hash value to be detected is not consistent with the reference hash value, outputting an alarm, or stopping the program or abnormally operating the program.
In this embodiment, if it is detected that the hash value to be detected is not consistent with the reference hash value, indicating that the program is tampered, an alarm is output, for example, in the form of light flashing, text display, and output of an alarm sound, so as to prompt the user and prevent the user from being lost due to the continued operation of the tampered computer program. Or when the hash value to be detected is not consistent with the reference hash value, the computer program is operated in an abnormal manner, for example, a falsifier illegally falsifies the computer program to obtain data of a terminal where the computer program operates, if the falsified computer program is operated normally, the data of the terminal is leaked, at this time, when the hash value to be detected is detected to be inconsistent with the reference hash value, the computer program is operated in an abnormal manner, so that the leaked data is wrong, and the falsifier cannot obtain desired data, thereby achieving the effect of misleading the falsifier.
Further, in an embodiment of the program running method of the present invention, the unique identifier is a decentralized domain name.
In an alternative embodiment of the present invention, the unique identifier may be a decentralized domain name. For example, first, a domain name is applied for a block chain, the domain name is registered according to a protocol format, for example, the registered domain name is shcy1.bit, and the domain name is confirmed to be unique according to a consensus mechanism of the block chain. Writing the decentralized domain name shcy1.bit into the computer program A. And then carrying out hash operation on the computer program A written with the unique identifier to obtain a corresponding reference hash value, and publishing the reference hash value and the unique identifier corresponding to the computer program A into a block chain in a decentralized domain name association manner. For example, the computer program a corresponds to a reference hash value a. Then, the decentralized domain name shcy1.bit is redirected in the block chain to point to the hash value A, and then the reference hash value A can be obtained through retrieval in the block chain according to the decentralized domain name shcy1. bit. In this embodiment, the unique identifier may be a decentralized domain name, but may also be other information, but the information needs to be guaranteed to have a unique characteristic (that is, the information has uniqueness in the block chain), for example, the information is associated and issued with the mapping of the hash value X of the computer program, and the hash value X is obtained by retrieving the unique identifier in the block chain through the mapping information.
In this embodiment, because the identifier corresponding to the program is unique, after the reference hash value and the identifier of the program are issued to the blockchain in an associated manner, the reference hash value of the program can be subsequently retrieved in the blockchain according to the unique identifier before the program runs, then the hash operation is performed on the program to obtain the hash value to be measured, the hash value to be measured is compared with the reference hash value, the program is run only when the hash value to be measured is consistent with the reference hash value, and adverse consequences caused by running the tampered program are avoided.
Furthermore, an embodiment of the present invention further provides a computer-readable storage medium, where a program execution program is stored on the computer-readable storage medium, and when the program execution program is executed by a processor, the steps of the program execution method described above are implemented.
The specific embodiment of the computer-readable storage medium of the present invention is substantially the same as the embodiments of the program running method described above, and details thereof are not described herein.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (3)

1. A program execution method, characterized by comprising:
applying for a unique identifier in a block chain, and writing the unique identifier into an original program code, wherein the unique identifier is a decentralized domain name, and the method comprises the steps of applying for a domain name on the block chain, registering the domain name according to a protocol format, and confirming that the domain name is unique according to a common identification mechanism of the block chain;
performing hash operation on the program code containing the unique identifier to obtain a reference hash value;
the unique identification and the reference hash value are issued to a block chain in a correlation mode;
when an operation instruction is received, acquiring a unique identifier of a current program;
acquiring a reference hash value corresponding to the unique identifier from a block chain system according to the unique identifier;
acquiring algorithm identification information, and determining a corresponding hash algorithm according to the algorithm identification information;
performing hash operation on the current program code according to the hash algorithm to obtain a hash value to be detected;
subtracting the hash value to be detected and the reference hash value, wherein when the value obtained by the subtraction is zero, the hash value to be detected is consistent with the reference hash value; or
Comparing the hash value to be detected with the reference hash value, and if the comparison is completely consistent, outputting a comparison passing or same instruction;
if the hash value to be detected is consistent with the reference hash value, continuing to normally operate the current program;
and if the hash value to be detected is not consistent with the reference hash value, outputting an alarm, or stopping the operation of the current program or abnormally operating the current program.
2. A program execution terminal characterized by comprising: a memory, a processor, and a program execution program stored on the memory and executable on the processor, the program execution program when executed by the processor implementing the steps of:
applying for a unique identifier in a block chain, and writing the unique identifier into an original program code, wherein the unique identifier is a decentralized domain name, and the method comprises the steps of applying for a domain name on the block chain, registering the domain name according to a protocol format, and confirming that the domain name is unique according to a common identification mechanism of the block chain;
performing hash operation on the program code containing the unique identifier to obtain a reference hash value;
the unique identification and the reference hash value are issued to a block chain in a correlation mode;
when an operation instruction is received, acquiring a unique identifier of a current program;
acquiring a reference hash value corresponding to the unique identifier from a block chain system according to the unique identifier;
acquiring algorithm identification information, and determining a corresponding hash algorithm according to the algorithm identification information;
performing hash operation on the current program code according to the hash algorithm to obtain a hash value to be detected;
subtracting the hash value to be detected and the reference hash value, wherein when the value obtained by the subtraction is zero, the hash value to be detected is consistent with the reference hash value; or
Comparing the hash value to be detected with the reference hash value, and if the comparison is completely consistent, outputting a comparison passing or same instruction;
if the hash value to be detected is consistent with the reference hash value, continuing to normally operate the current program;
and if the hash value to be detected is not consistent with the reference hash value, outputting an alarm, or stopping the operation of the current program or abnormally operating the current program.
3. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a program execution program which, when executed by a processor, implements the steps of the program execution method according to claim 1.
CN201710704602.9A 2017-08-16 2017-08-16 Program operating method, terminal, and computer-readable storage medium Active CN107545181B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710704602.9A CN107545181B (en) 2017-08-16 2017-08-16 Program operating method, terminal, and computer-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710704602.9A CN107545181B (en) 2017-08-16 2017-08-16 Program operating method, terminal, and computer-readable storage medium

Publications (2)

Publication Number Publication Date
CN107545181A CN107545181A (en) 2018-01-05
CN107545181B true CN107545181B (en) 2021-04-27

Family

ID=60971476

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710704602.9A Active CN107545181B (en) 2017-08-16 2017-08-16 Program operating method, terminal, and computer-readable storage medium

Country Status (1)

Country Link
CN (1) CN107545181B (en)

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109472591A (en) * 2018-11-12 2019-03-15 深圳市喂车科技有限公司 Based on the cryptographic Hash prediction technique and its device of block chain, electronic equipment
CN109766723A (en) * 2018-12-11 2019-05-17 烨链(上海)科技有限公司 A kind of block chain data framework, regulatory framework, monitoring and managing method and computer readable storage medium
CN109753823B (en) * 2018-12-11 2021-11-02 烨链(上海)科技有限公司 Block chain data supervision method, system and computer storage medium
DE102018221703A1 (en) * 2018-12-13 2020-06-18 HELLA GmbH & Co. KGaA Verification and identification of a neural network
CN110020951A (en) * 2019-04-10 2019-07-16 北京筑龙信息技术有限责任公司 A kind of transaction data authentication method, apparatus and storage medium based on block chain
US11088828B2 (en) 2019-07-18 2021-08-10 Advanced New Technologies Co., Ltd. Blockchain-based data evidence storage method and apparatus
CN110427774B (en) * 2019-07-18 2021-01-12 创新先进技术有限公司 Block chain-based data storage method, data verification method and related device
CN110371081A (en) * 2019-08-08 2019-10-25 深圳市英博超算科技有限公司 Vehicle tamper resistant method, device and vehicle
CN111222138A (en) * 2019-12-31 2020-06-02 阿尔法云计算(深圳)有限公司 Algorithm checking method, algorithm right confirming method and device
CN111262705B (en) * 2020-01-15 2023-05-09 西安理工大学 Method for checking trusted starting of blockchain
CN111736893B (en) * 2020-06-24 2023-08-01 中国银行股份有限公司 Software package version verification method and related device
CN111770114B (en) * 2020-09-01 2020-12-22 北京安帝科技有限公司 Industrial control application program safety monitoring method based on fingerprint acquisition

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101593259A (en) * 2009-06-29 2009-12-02 北京航空航天大学 software integrity verification method and system
CN104462965A (en) * 2014-11-14 2015-03-25 华为技术有限公司 Method for verifying integrity of application program and network device
CN104778410A (en) * 2015-04-16 2015-07-15 电子科技大学 Application program integrity verification method
CN106355081A (en) * 2016-09-07 2017-01-25 深圳市新国都支付技术有限公司 Android program start verification method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106815530B (en) * 2016-12-26 2020-04-24 北京爱接力科技发展有限公司 Data storage method, data verification method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101593259A (en) * 2009-06-29 2009-12-02 北京航空航天大学 software integrity verification method and system
CN104462965A (en) * 2014-11-14 2015-03-25 华为技术有限公司 Method for verifying integrity of application program and network device
CN104778410A (en) * 2015-04-16 2015-07-15 电子科技大学 Application program integrity verification method
CN106355081A (en) * 2016-09-07 2017-01-25 深圳市新国都支付技术有限公司 Android program start verification method and device

Also Published As

Publication number Publication date
CN107545181A (en) 2018-01-05

Similar Documents

Publication Publication Date Title
CN107545181B (en) Program operating method, terminal, and computer-readable storage medium
CN106951228B (en) Method and device for processing differences in version iteration
CN107657177B (en) Vulnerability detection method and device
CN107920112B (en) Configuration file pushing method supporting gray mode, central server and storage medium
CN110955416A (en) Interface document generation method, device, equipment and computer storage medium
CN106815031B (en) Kernel module loading method and device
US20200302712A1 (en) Vehicle detection method, apparatus and vehicle diagnostic device
CN110516471B (en) Product promotion method based on information security and related equipment
CN110659206A (en) Simulation architecture establishing method, device, medium and electronic equipment based on microservice
CN111475401A (en) Test method and related equipment
US20180137281A1 (en) Software analysis system, software analysis method, and software analysis program
CN111367531B (en) Code processing method and device
CN106354727B (en) Widget file generation method and device
CN104346035A (en) Indicating automatically corrected words
CN111581211A (en) Data table updating method, device, equipment and computer readable storage medium
CN113126955A (en) Random data generation method and device, intelligent terminal and storage medium
CN111181805A (en) Micro-service test baffle generation method and system based on test case
CN110597662A (en) Backup data automatic verification method and device, user equipment and storage medium
CN111966630B (en) File type detection method, device, equipment and medium
CN111061637B (en) Interface testing method, interface testing device and storage medium
CN113434254A (en) Client deployment method, client deployment apparatus, computer device, and storage medium
CN106569868B (en) Gradle-based compiling optimization method and device
US20180089446A1 (en) Apparatus and system for information processing
CN112187783A (en) Authentication method and device, electronic equipment and storage medium
CN117033309A (en) Data conversion method and device, electronic equipment and readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant