A file checking method, device, system and electronic equipment
By using the Merkle tree hash algorithm for fragment verification and two-way authentication during file transfer, the problems of low efficiency and insufficient security in existing technologies for file integrity verification are solved, achieving efficient and reliable file transfer and fault location.
Patent Information
- Application Number
- CN202611316306.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-27
- Publication Date
- 2026-11-24
AI Technical Summary
In existing technologies, file integrity verification is usually performed after the download is complete. This leads to wasted bandwidth and reduced transmission efficiency during large file transfers or in weak network environments. Furthermore, it makes it difficult to accurately locate errors, which makes the system vulnerable to phishing attacks and increases maintenance complexity.
Merkle tree hash algorithm is used for fragment verification. Data fragments are received through encrypted sessions and hash values are calculated in real time. Verification is performed while receiving data. Inter-layer hash comparison of Merkle tree is used to locate abnormal fragments and retransmit them on demand. Combined with two-way authentication and pre-allocation of storage space, data integrity and transmission efficiency are ensured.
It achieves simultaneous reception and verification, reduces the accumulation of invalid data, improves transmission efficiency and fault location accuracy, prevents malicious data writing and disk fragmentation, and provides dual reliability protection.
Smart Images

Figure CN123163831A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data security technology, and in particular to a file verification method, apparatus, system and electronic device. Background Technology
[0002] With the increasing prevalence of network file transfer in the security field, ensuring the integrity and trustworthiness of transmitted data has become a core requirement. Existing solutions mostly rely on Transport Layer Security (TLS) / Secure Sockets Layer (SSL) encrypted channels, combined with the hash value after download for verification. While this can prevent general eavesdropping and accidental damage, it has significant shortcomings in dealing with advanced threats.
[0003] In existing technologies, file integrity checks are typically performed after the entire file has been downloaded. The client receives the entire file and confirms its integrity. Because the check occurs after all data transmission is complete, if the check fails, the exact location of the error cannot be determined, necessitating a retransmission of the entire file. This results in significant bandwidth waste and reduced transmission efficiency during large file transfers or in weak network environments. Summary of the Invention
[0004] In view of the above problems, this application provides a file verification method, apparatus, system, and electronic device to improve transmission efficiency and fault location efficiency. The specific solution is as follows:
[0005] The first aspect of this application provides a file verification method, applied to a client, including:
[0006] The receiving server sends a verification packet through an encrypted session. The verification packet contains at least: the root hash value of the Merkle tree obtained after the file to be downloaded is processed into fragments, and fragment index information.
[0007] The encrypted session sequentially receives data fragments from the server and the corresponding leaf node hash values of the data fragments.
[0008] Calculate the real-time hash value of the data shard and compare the real-time hash value with the hash value of the leaf node corresponding to the data shard;
[0009] If the comparison results match, the data fragment is written into the storage space of the client at the position corresponding to the fragment index information;
[0010] If the comparison results are inconsistent, a retransmission request for the data fragment is sent to the server.
[0011] After all data fragments have been received, the Merkle tree is reconstructed based on the locally stored data fragments, the local root hash value is calculated, and the local root hash value is compared with the root hash value in the verification packet.
[0012] If the local root hash value is inconsistent with the root hash value in the verification packet, the abnormal fragment range is located based on the inter-layer hash comparison result of the Merkle tree, and the server is requested to retransmit the data fragments within the abnormal fragment range.
[0013] In one possible implementation, the process of constructing the encrypted session includes:
[0014] Send a file download request to the server, the download request carrying a first identity credential signed based on the client's private key;
[0015] Receive the second identity credential and session key parameters returned by the server, wherein the second identity credential is generated based on the server's private key signature;
[0016] Verify the second identity credential, and after the second identity credential is verified, establish the encrypted session based on the session key parameter.
[0017] In one possible implementation, the second identity credential is generated by the server after the first identity credential has been verified; the server blocks the file data transmission channel and only allows signaling interaction before the client verifies the second identity credential.
[0018] In one possible implementation, the process of determining the storage space includes:
[0019] Obtain the total number of fragments and the fragment size of each data fragment in the verification packet;
[0020] The total number of bytes of the file to be downloaded is determined by multiplying the total number of fragments by the fragment size;
[0021] The operating system's underlying storage interface is invoked to pre-allocate contiguous physical storage space on the local disk, wherein the size of the contiguous physical storage space is not less than the total number of bytes.
[0022] In one possible implementation, locating the range of anomalous fragments based on the inter-level hash comparison results of the Merkle tree includes:
[0023] Starting from the root node of the Merkle tree, the hash values of each node are compared layer by layer until the bottom leaf node with a mismatched hash value is located, and the data fragment corresponding to the bottom leaf node is identified as an abnormal fragment.
[0024] If the hash values of the nodes in the intermediate layer do not match, the comparison is recursively performed downwards from the root node to narrow down the range of abnormal fragments.
[0025] In one possible implementation, when the real-time hash value and the corresponding leaf node hash value are inconsistent, the method further includes:
[0026] Collect network status parameters on the data fragmentation transmission path;
[0027] The network status parameters are sent to the server to trigger the server to determine the type of transmission anomaly, which includes: link layer transmission failure and malicious tampering attack.
[0028] A second aspect of this application provides a file verification method applied on a server, comprising:
[0029] In response to a file transfer request from a client, a verification packet is sent to the client via an encrypted session. The verification packet contains at least: the root hash value of the Merkle tree obtained after the file to be downloaded has been fragmented, and fragment index information.
[0030] The encrypted session sequentially sends the data fragments and the corresponding leaf node hash values of the data fragments to the client, so that the client can perform real-time verification of the data fragments.
[0031] In response to the retransmission request sent by the client, the corresponding data fragment and the hash value of the leaf node corresponding to the corresponding data fragment are retransmitted to the client.
[0032] In response to a range retransmission request sent by the client, the system retransmits the data fragments within the abnormal fragment range and their corresponding leaf node hash values to the client. The range retransmission request is used to request the retransmission of the data fragments within the abnormal fragment range located by the client based on the inter-layer hash comparison results of the Merkle tree.
[0033] A third aspect of this application provides a file verification device applied to a client, comprising:
[0034] The verification packet receiving module is used to receive verification packets sent by the server through an encrypted session. The verification packet includes at least: the root hash value of the Merkle tree obtained after the file to be downloaded is processed into fragments, the total number of fragments, and fragment index information.
[0035] The data fragment receiving module is used to sequentially receive data fragments from the server and the corresponding leaf node hash values of the data fragments through the encrypted session.
[0036] A real-time verification module is used to calculate the real-time hash value of the data shard and compare the real-time hash value with the hash value of the leaf node corresponding to the data shard; if the comparison result matches, the data shard is written into the storage space of the client at the position corresponding to the shard index information; if the comparison result does not match, a retransmission request for the data shard is sent to the server; and,
[0037] The overall verification module is used to reconstruct the Merkle tree based on the locally stored data fragments after all data fragments have been received, calculate the local root hash value, and compare the local root hash value with the root hash value in the verification packet. If the local root hash value is inconsistent with the root hash value in the verification packet, the abnormal fragment range is located according to the inter-layer hash comparison result of the Merkle tree, and the server is requested to retransmit the data fragments within the abnormal fragment range.
[0038] A fourth aspect of this application provides a file verification system, comprising: a client and a server, wherein the client and the server are communicatively connected, the client is used to execute the file verification method of the first aspect or any implementation thereof, and the server is used to execute the file verification method of the second aspect.
[0039] The fifth aspect of this application provides a computer program product including computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the file verification method described in the first aspect or any implementation thereof.
[0040] A sixth aspect of this application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0041] The memory is used to store computer programs;
[0042] The processor is used to execute the computer program so that the electronic device can implement the file verification method of the first aspect or any implementation thereof.
[0043] The seventh aspect of this application provides a computer storage medium carrying one or more computer programs, which, when executed by an electronic device, enable the electronic device to implement the file verification method described in the first aspect or any implementation thereof.
[0044] By utilizing the aforementioned technical solution, the file verification method provided in this application receives a verification packet pre-sent by the server before data transmission. This verification packet contains the Merkle tree root hash value and fragment index information, enabling the client to obtain the basis for verifying file integrity before receiving data fragments. By calculating the hash value in real time during the reception of each data fragment and comparing it with the hash value of the corresponding leaf node, and writing to disk only when the comparison matches, a streaming processing mechanism of receiving, verifying, and writing simultaneously is implemented. Malicious data is identified and discarded before storage, fundamentally preventing file tampering and writing to the storage medium. Simultaneously, when a mismatch occurs, a retransmission request for that fragment is sent immediately, making anomaly recovery independent of the completion of all data transmission and reducing the accumulation of invalid data. By reconstructing the Merkle tree based on each local fragment after all data fragments are received and comparing it with the root hash in the verification packet, a dual verification defense line of real-time verification and final verification is formed. Real-time verification ensures the correct transmission of a single fragment, while final verification confirms the trustworthiness of the complete file, providing dual reliability guarantees. By locating the range of abnormal fragments and requesting range retransmission based on the inter-layer hash comparison results of the Merkle tree when the final verification is inconsistent, the tree structure of the Merkle tree is used to reduce the time complexity of anomaly localization, resulting in a significant efficiency improvement in scenarios with a large number of fragments. Compared to the existing technology that can only retransmit the entire file after verification failure, this method refines the retransmission granularity from the entire file to a subset of abnormal fragments, effectively avoiding the bandwidth waste caused by full retransmission and thus improving data transmission efficiency. Attached Figure Description
[0045] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0046] Figure 1 A flowchart of a document verification method provided in this application;
[0047] Figure 2 This application provides a complete flowchart of a file verification method that includes the establishment of an encrypted channel;
[0048] Figure 3 A schematic diagram of the signaling interaction during the two-way identity verification and isolation phases provided in this application;
[0049] Figure 4 A schematic diagram illustrating the principle of Merkle tree construction and hierarchical location of anomaly fragmentation provided in this application;
[0050] Figure 5 A flowchart illustrating the decision-making logic for distinguishing between link-layer transmission failures and malicious tampering attacks, provided in this application.
[0051] Figure 6 The module structure diagram of the document verification system provided in this application;
[0052] Figure 7 A structural diagram of a document verification device provided in this application;
[0053] Figure 8 This is a structural diagram of an electronic device provided in this application. Detailed Implementation
[0054] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is for explaining specific embodiments only and is not intended to limit the scope of this application.
[0055] As will be known to those skilled in the art, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0056] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements, but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0057] The current file transfer methods mainly have the following problems:
[0058] First, identity verification is one-way. Mainstream mechanisms only authenticate the client from the server's perspective; the client cannot verify the server's authenticity, making it vulnerable to phishing attacks. Attackers can use a fake server to trick users into downloading modified files containing malicious code, leading to the leakage of sensitive data.
[0059] Secondly, the verification mechanism is severely lagging. Traditional post-download verification requires waiting for the entire file transfer to complete before verifying integrity. If verification fails, the error location cannot be pinpointed, necessitating a full retransmission. This significantly wastes bandwidth and reduces efficiency during large file transfers or in weak network conditions.
[0060] Furthermore, performance and maintenance face dual pain points. First, clients often use streaming writes, which, due to the lack of prediction of the total file size, easily leads to disk space fragmentation, dragging down the performance of large file read and write operations. Second, fault attribution is lacking. Existing methods can only report file corruption, unable to distinguish whether it is a bit flip caused by network fluctuations or malicious tampering caused by a man-in-the-middle attack, greatly increasing the difficulty of maintenance and troubleshooting and response latency.
[0061] To address the aforementioned problems, this application provides a file verification method. The file verification method of this application embodiment is described in detail below with reference to the accompanying drawings. The file verification system in this application mainly consists of a client and a server.
[0062] Reference Figure 1 , Figure 1 This is a flowchart illustrating a file verification method provided in an embodiment of this application, such as... Figure 1 As shown, the file verification method provided in this application embodiment may include steps S101 to S107, which are described in detail below. This part can be used as... Figure 2 It is a core component of the overall process.
[0063] Step S101: Receive the verification packet sent by the server through the encrypted session. The verification packet contains at least the root hash value of the Merkle tree obtained after the file to be downloaded is processed into fragments, as well as the fragment index information.
[0064] In this embodiment, before sending file data, the server divides the file to be downloaded into multiple fixed-size data fragments, with the last fragment potentially smaller than the fixed fragment size. For each data fragment, the server uses a hash algorithm (e.g., SHA-256) to calculate its hash value, called the leaf node hash value. Then, the server hashes all leaf node hash values pairwise upwards according to the Merkle tree construction rules, ultimately generating a unique root hash value. This root hash value serves as the basis for verifying the integrity of the entire file and can be used in subsequent steps to verify whether the file has been tampered with. Fragment index information is used to record the correspondence between the sequence number of each data fragment and its offset in the file.
[0065] After receiving the verification packet, the client parses it to obtain and store the root hash value, the total number of shards, and the shard index information. This information will be used for subsequent real-time verification, space pre-allocation, and overall procedures.
[0066] This allows the client to obtain complete verification criteria before it begins receiving actual data, enabling the verification process to be moved from after download completion to before download begins, thus providing the possibility for subsequent real-time verification.
[0067] Step S102: Receive data shards and the corresponding leaf node hash values from the server sequentially through an encrypted session.
[0068] The server reads the data fragments of the file to be downloaded one by one according to the order recorded in the fragment index information, and encrypts each fragment and the corresponding leaf node hash value pre-calculated in step S101 using the session key before sending them. This allows the client to perform real-time verification.
[0069] The client receives data fragments and their corresponding leaf node hashes from the server via an encrypted session. Because the data fragments are transmitted through an encrypted channel, the confidentiality and integrity of the data during transmission are guaranteed, preventing eavesdropping and man-in-the-middle tampering.
[0070] Step S103: Calculate the real-time hash value of the data shard and compare the real-time hash value with the hash value of the leaf node corresponding to the data shard.
[0071] Upon receiving each data fragment, the client first decrypts it using the session key to obtain the plaintext data. Then, the client calculates the hash value of the plaintext data using the same hash algorithm as the server (e.g., SHA-256), which is called the real-time hash value.
[0072] The client compares the real-time hash value with the leaf node hash value received along with the data fragment. If they match, it indicates that the data fragment has not been tampered with during transmission and the data is intact, proceeding to step S104. If they do not match, it indicates that the fragment has been erroneous or tampered with during transmission, proceeding to step S105.
[0073] This method implements a real-time protection mechanism that verifies data as it is received, ensuring that each data fragment has been integrity-verified before being written to disk. Compared to existing technologies that require verification only after the entire file has been downloaded, this method advances the anomaly detection from the transmission endpoint to the transmission process, effectively preventing malicious data from being written to disk without verification.
[0074] Step S104: If the comparison results are consistent, the data fragments are written into the storage space of the client at the position corresponding to the fragment index information.
[0075] In this embodiment, the client calculates the total storage space required for the file to be downloaded based on the product of the total number of fragments and the size of each fragment. It then pre-allocates a contiguous block of storage space on the local disk, the size of which is not less than the total number of bytes in the file to be downloaded. Next, the client writes the verified data fragments to the corresponding offset address within the contiguous physical storage space, based on the fragment number and offset recorded in the fragment index information.
[0076] By pre-allocating contiguous physical storage space before writing data to disk, disk fragmentation caused by multiple allocations of non-contiguous space during streaming is avoided, thus improving the read and write performance of large files. Furthermore, pre-allocating space before data reception allows for early detection of insufficient disk space before downloading begins, preventing download failures due to insufficient space.
[0077] Step S105: If the comparison results are inconsistent, a retransmission request for the data fragments is sent to the server.
[0078] When the real-time hash value does not match the hash value of the leaf node, the client can determine that the data fragment has been erroneous or tampered with during transmission. The client discards the data fragment and sends a retransmission request for that specific data fragment to the server. This retransmission request includes the sequence number or fragment index information of the data fragment, so that the server can identify which fragment the client is requesting.
[0079] Upon receiving a retransmission request, the server retransmits the data fragment and its corresponding leaf node hash value separately. The client then re-receives and executes the verification process from steps S102 to S103. This on-demand retransmission mechanism avoids the problem of needing to retransmit the entire file when a few fragment errors occur.
[0080] By working in conjunction with step S103, retransmission is initiated immediately when an anomaly is detected during real-time verification, so that the recovery of erroneous fragments does not depend on the completion of all data transmission, reducing the accumulation of invalid data and its impact on subsequent fragment reception.
[0081] Step S106: After all data fragments have been received, reconstruct the Merkle tree based on the locally stored data fragments, calculate the local root hash value, and compare the local root hash value with the root hash value in the verification packet.
[0082] After all data fragments have been received (including fragments that have been successfully received after retransmission), the client performs a final integrity check.
[0083] Based on the hash values of all locally stored data shards, the client reconstructs the Merkle tree from bottom to top, following the same construction rules as the server in step S101. Specifically, the client uses the hash value of each data shard as a leaf node, hashes pairwise upwards layer by layer, and finally calculates the local root hash value.
[0084] The client compares the local root hash value with the root hash value in the verification packet received in step S101. If they match, it proves that the entire file is complete and has not been tampered with, the file verification passes, and the download process ends. If they do not match, it indicates that the file is abnormal, and the process proceeds to step S107.
[0085] As the final verification step, the integrity of the complete file is verified end-to-end. Even though real-time verification checks each fragment, the final verification can still detect potential problems with the fragments' receiving order, splicing, or other overall aspects, providing further assurance of reliability.
[0086] Step S107: If the local root hash value is inconsistent with the root hash value in the verification packet, locate the abnormal fragment range based on the inter-layer hash comparison result of the Merkle tree, and request the server to retransmit the data fragments within the abnormal fragment range.
[0087] In this embodiment, the hierarchical structure of the Merkle tree allows the client to quickly pinpoint the exact location of the error in logarithmic time complexity. Specifically, starting from the root node of the Merkle tree, the client compares the hash value of each node in the current node level with the expected hash value, layer by layer downwards. If the hash value of a node does not match, the comparison continues recursively downwards from that node as the root node until the bottom-most leaf node with the hash value mismatch is located. The data shards corresponding to these bottom-most leaf nodes constitute the range of abnormal shards.
[0088] For example, if a file contains 1600 shards, the client only needs to perform about log21600 hash comparisons to locate the subtree range of the abnormal shard, instead of traversing all 1600 shards.
[0089] After the client locates the abnormal fragment range, it requests the server to retransmit the data fragments within that range, instead of the entire file. Upon receiving the range retransmission request, the server resends the fragments within that range to the client. The client then repeats steps S102 to S106 until the final verification is successful.
[0090] By utilizing the inter-level hash comparison mechanism of Merkle trees, precise location of abnormal fragments is achieved, refining the granularity of error recovery from the entire file to a subset of abnormal fragments. This fundamentally solves the problem in existing technologies where verification failures necessitate full retransmission, thereby reducing bandwidth consumption and improving data transmission efficiency. As the number of file fragments increases, the advantage in location efficiency will become increasingly significant.
[0091] In some embodiments, refer to Figure 2 and Figure 3 As shown, the process of constructing the above-mentioned encrypted session includes:
[0092] Step S201: Send a file download request to the server. The download request carries the first identity credential signed based on the client's private key.
[0093] The client uses its private key to digitally sign the data containing the download request information, generating a primary identity credential. The download request information includes at least the following metadata: client identity information, timestamp, random number, and the file identifier (file ID) of the file to be downloaded. The client sends this primary identity credential along with the download request to the server.
[0094] The primary identity credential is used to prove the client's legitimacy to the server and ensure that the downloaded content has not been tampered with during transmission. The client's private key signature is non-repudiable; any party holding the client's public key can verify the authenticity of the signature.
[0095] Step S202: Receive the second identity credential and session key parameters returned by the server. The second identity credential is generated based on the server's private key signature.
[0096] After receiving a download request from the client, the server verifies the initial identity credential. The server uses the client's public key, paired with the client's private key, to decrypt and verify the signature information in the initial identity credential to confirm whether the request originates from a legitimate client and to check the integrity of the request data.
[0097] If the verification passes, the server confirms the client's identity is legitimate and that they have download permissions. The server then generates a second identity credential based on its private key and randomly generates a session key parameter. The second identity credential contains the server's identity information and is used to prove the server's authenticity to the client. The session key parameter includes at least a symmetric encryption key and an initialization vector, used to establish an encrypted data transmission channel subsequently.
[0098] The server returns the secondary identity credential and session key parameters to the client. Before the client successfully verifies the secondary identity credential, the server, through a preset network access control policy, blocks the file data transmission channel, allowing only the signaling communication port to be open. In other words, the server does not transmit any file data bytes until the client has confirmed its identity; it only allows the exchange of signaling messages used for identity verification and key negotiation.
[0099] The specific implementation of this blocking mechanism can be as follows: the server configures firewall rules so that the data port is blocked until the client authentication is completed, and any connection packets attempting to send file data through the data port are directly dropped.
[0100] Step S203: Verify the second identity credential, and after the second identity credential is verified, establish an encrypted session based on the session key parameter.
[0101] After receiving the second identity credential returned by the server, the client verifies it. The client uses the server's public key, paired with the server's private key, to decrypt and verify the signature information in the second identity credential, thus ensuring the authenticity of the server's identity.
[0102] If the verification passes, the client confirms that the current connection is with a legitimate server, and both parties' identities are verified. Subsequently, based on the session key parameters received in step S202, the client negotiates and determines a symmetric encryption key with the server, establishing an encrypted data transmission channel. This encrypted session uses a symmetric encryption algorithm (such as AES-256-GCM) to encrypt and protect all subsequently transmitted data.
[0103] At this point, the two-way identity verification and encrypted session establishment process is complete. Subsequent data transmissions are all conducted under the protection of this encrypted session, ensuring the confidentiality and integrity of communication.
[0104] This embodiment achieves true two-way identity authentication through bidirectional digital signature verification between the client and server. Compared to a one-way mechanism where only the server authenticates the client, the client cannot verify the authenticity of the server and is vulnerable to phishing attacks. This embodiment allows the client to actively verify the legitimacy of the connected server by verifying the server's secondary identity credentials, effectively preventing man-in-the-middle attacks and the risk of forged servers. Furthermore, before the client completes the verification of the server's identity, the server blocks the transmission of file data through policies, preventing data leakage at the network layer without identity verification.
[0105] In other embodiments, the process of determining the storage space described above may specifically include:
[0106] Obtain the total number of data fragments and the size of each data fragment in the verification packet;
[0107] The total number of bytes in the file to be downloaded is determined by multiplying the total number of fragments by the fragment size.
[0108] Call the operating system's underlying storage interface to pre-allocate contiguous physical storage space on the local disk. The size of the contiguous physical storage space is not less than the total number of bytes.
[0109] In this embodiment, the client invokes the operating system's underlying storage interface to pre-allocate contiguous physical storage space on the local disk in one go. The client can call the appropriate interface based on its operating system type: under Linux, the `fallocate` system call can be used; under Windows, the `SetFileValidData` function interface can be called. The storage space pre-allocated through these interfaces has contiguous physical addresses, avoiding disk fragmentation caused by multiple allocations of non-contiguous space by the file system during subsequent streaming writes.
[0110] In practical applications, if the client's operating system does not support the above interface, other equivalent interfaces or methods can be used to pre-allocate contiguous storage space, such as by setting the expected size of the file.
[0111] After pre-allocation is complete, the client can directly write the data fragments that have passed real-time verification to the offset address corresponding to the fragment index information in the contiguous physical storage space in subsequent step S104. Since the storage space has been allocated before data writing, there is no need to request disk space from the operating system each time a fragment is written, thus improving write efficiency. At the same time, the contiguousness of pre-allocation improves the read and write performance of large files and avoids the additional seek overhead caused by disk fragmentation.
[0112] This approach, by accurately calculating the total number of bytes in the file based on the fragmentation information in the checksum packet and pre-allocating storage space before receiving data, solves the disk fragmentation problem caused by the lack of prediction of the total file size in existing streaming write schemes. Furthermore, the pre-allocation process can detect insufficient disk space before the download begins, avoiding download failures due to insufficient space during the download process.
[0113] Reference Figure 4 As shown, the process of constructing a Merkle tree and hierarchically locating anomaly fragments is as follows:
[0114] During the preprocessing phase, the server splits the file to be downloaded into N data fragments. For each data fragment, its hash value is calculated and used as a leaf node in the Merkle tree. Then, the hash values of two adjacent leaf nodes are concatenated and the hash value is calculated again to obtain the hash value of the node at the next higher level. This process is repeated layer by layer upwards until a unique root node hash value is obtained.
[0115] During the final verification phase, if the client's local root hash value does not match the root hash value in the verification packet, a hierarchical location mechanism is initiated. The specific process is as follows:
[0116] First, the client starts the comparison from the root node level of the Merkle tree. Since the hash value of the root node has been confirmed to be inconsistent, the client moves down to the levels containing the two child nodes of the root node. The client compares the hash values of each node in that level to find the nodes whose hash values do not match.
[0117] If the hash value of a certain intermediate layer node does not match, the comparison continues recursively downwards from that node as the root node, narrowing down the scope of the anomaly layer by layer. If the hash values of all nodes in a certain layer match, it means that the anomaly is located in another subtree, and the client switches to the sibling subtree with the mismatched hash value to continue the comparison.
[0118] The client continues to execute the above layer-by-layer comparison and recursive location process until it locates the bottom-level leaf node where the hash values do not match. The data shard corresponding to this bottom-level leaf node is the abnormal shard. If both child nodes of an intermediate-level node with a hash value mismatch also have hash value mismatches, the abnormal shard may be distributed across multiple subtrees. The client collectively defines the abnormal shard range by including the data shards corresponding to the leaf nodes of all mismatched subtrees.
[0119] Since the height of the Merkle tree is log2N (where N is the total number of fragments), the client only needs to perform a maximum of log2N level comparisons to pinpoint the range of abnormal fragments through the aforementioned hierarchical location process. The client then sends the fragment index information of the identified abnormal fragment range to the server in a retransmission request, requesting the server to retransmit the data fragments within that range.
[0120] This embodiment achieves efficient localization of abnormal fragments by leveraging the tree structure characteristics of Merkle trees. Compared to the linear comparison method of traversing all fragments one by one, this embodiment reduces the localization complexity from O(N) to O(log₂N), demonstrating a significant efficiency advantage in scenarios with a large number of fragments. Furthermore, the localization accuracy of this embodiment reaches the fragment level corresponding to a single leaf node, enabling precise range retransmission and avoiding the bandwidth waste of full retransmission.
[0121] Building upon the above embodiments, a further extended function of multidimensional source tracing analysis has been added, used for intelligent attribution analysis of data fragmentation anomalies discovered during real-time verification. For example... Figure 5 As shown, the decision-making logic of multidimensional source tracing analysis includes the following steps:
[0122] Step S501: Collect network status parameters on the data fragmentation transmission path.
[0123] When the client determines in step S103 that the real-time hash value is inconsistent with the hash value of the leaf node, the client collects the network status parameters on the transmission path of the abnormal data fragment while sending a retransmission request.
[0124] Network state parameters include at least one or more of the following: packet loss rate of the transmission path, network round-trip time (RTT), routing node hop count, and the continuity of the distribution of erroneous data fragments. Packet loss rate reflects data loss during transmission; a high packet loss rate is usually associated with poor link quality. Network RTT reflects the delay of the transmission path; abnormal delay jumps may indicate route changes or network congestion. Routing node hop count reflects the number of routers data traverses from the server to the client; sudden changes in hop count may indicate route switching. The continuity of the distribution of erroneous data fragments reflects the distribution pattern of abnormal fragments within the file; continuous and concentrated anomalies may indicate malicious tampering, while randomly dispersed anomalies may indicate link noise.
[0125] Step S502: Send the network status parameters to the server to trigger the server to determine the transmission anomaly type. The transmission anomaly types include: link layer transmission failure and malicious tampering attack.
[0126] The client sends the collected network status parameters to the server. Upon receiving the network status parameters, the server combines them with the distribution characteristics of the abnormal fragments to comprehensively determine the type of transmission anomaly. Transmission anomaly types include link-layer transmission failures and malicious tampering attacks.
[0127] Specifically, the server-side source analysis module analyzes network status parameters. For example, when the packet loss rate is significantly higher than the normal range (e.g., the normal range is 0% to 5%, while the collected value is 45%), and the network round-trip latency is significantly higher than the baseline value (e.g., the baseline value is 50ms, while the collected value is 1200ms), and the number of hops in the routing node changes drastically (e.g., the baseline value is 12 hops, while the collected value is 18 hops), the server determines it to be a link-layer transmission failure, i.e., bit flipping or packet loss caused by network link quality issues.
[0128] For example, when the packet loss rate is within the normal range (e.g., 0.1%), the network round-trip latency is close to the baseline value (e.g., 52ms), and the number of routing node hops is consistent with the baseline value (e.g., 12 hops), but the erroneous data fragments show a continuous distribution characteristic (e.g., the hash verification fails consecutively from fragment number 800 to 900) and the error bits show a regular offset, the server determines it to be a malicious tampering attack, that is, a man-in-the-middle attacker has intentionally replaced or modified the data fragments.
[0129] The client ultimately receives the transmission anomaly type determination result from the server. If the determination result indicates a malicious tampering attack, the client immediately issues a security alert. Security alerts may include one or more of the following forms: displaying security warning information on the client interface, reporting attack events and abnormal fragmentation ranges to the security management system through an independent management channel, or adding the client's IP address to a temporary blocking list.
[0130] If the determination result is a link layer transmission failure, the client will only log the information and will not trigger a security alarm, so that maintenance personnel can quickly locate the network fault node for maintenance.
[0131] This embodiment achieves intelligent attribution of transmission anomalies by collecting multi-dimensional network status parameters along the transmission path and combining them with the distribution characteristics of faulty fragments for comprehensive analysis. It solves the technical problem in existing technologies that can only report file corruption but cannot distinguish between link failures and malicious tampering, providing a reliable basis for rapid response to security incidents and accurate location of link failures. In practical applications, this source tracing analysis function enables maintenance personnel to take differentiated handling measures based on the judgment results: for link failures, investigate network devices; for malicious tampering, initiate security emergency response procedures, thereby significantly improving maintenance efficiency and security protection levels.
[0132] Based on the same design concept, embodiments of this application also provide a file verification method, applied on the server side, including:
[0133] Step S601: In response to the client's file transfer request, send a verification packet to the client through an encrypted session. The verification packet contains at least the root hash value of the Merkle tree obtained after the file to be downloaded is processed into fragments, as well as fragment index information.
[0134] Step S602: Send the data fragments and the corresponding leaf node hash values to the client in sequence through an encrypted session, so that the client can perform real-time verification of the data fragments.
[0135] Step S603: In response to the retransmission request sent by the client, retransmit the corresponding data fragment and the corresponding leaf node hash value of the data fragment to the client.
[0136] Step S604: In response to the range retransmission request sent by the client, retransmit the data fragments within the abnormal fragment range and the corresponding leaf node hash values to the client. The range retransmission request is used to request the retransmission of the data fragments within the abnormal fragment range located by the client based on the inter-layer hash comparison results of the Merkle tree.
[0137] The specific implementation process of the file verification method applied on the server side described above can be referred to the implementation process of the file verification method applied on the client side described in the above embodiments, and will not be repeated here.
[0138] As a specific application of the above-mentioned document verification method, the complete implementation steps of this application will be explained in detail below in conjunction with the actual application scenario of downloading classified government documents.
[0139] The dedicated digital certificates issued by the government CA (Certificate Authority) are pre-imported into the government client and document server respectively, serving as the core credentials for two-way identity verification. The private keys of all digital certificates are stored using hardware encryption media.
[0140] Step 1: Two-way identity verification and hard isolation (refer to...) Figure 3 ).
[0141] When a government user clicks the download button for a classified document on the client, the client automatically reads the local digital certificate to generate a primary identity signature and sends a download request to the server, carrying the file ID.
[0142] After receiving the request, the server uses the CA public key to verify the legitimacy of the client's first identity signature, confirming that the user has download permissions. At this point, the server does not send any file-related information; it only generates a second identity signature using its local digital certificate and returns it to the client.
[0143] The client uses the CA's public key to reverse verify the server's secondary identity signature, confirming that the current connection is to a legitimate government document server. Both parties generate a dedicated AES (Advanced Encryption Standard) encryption key for this session through key negotiation.
[0144] During this period, the server-side firewall rules only allow signaling interaction on the handshake port, while the data port is blocked. Any connection packets attempting to send file data will be dropped directly, achieving hard isolation at the physical level.
[0145] Step 2: Verify packet pre-delivery and space pre-allocation.
[0146] The server splits the 200MB classified file to be downloaded into 1600 data fragments of 128KB each. It calculates the SHA-256 hash value for each fragment, constructs a Merkle tree from all the hash values, and generates the root hash value.
[0147] The server encapsulates the root hash value, total number of shards (1600), and shard size (128KB) into a tamper-proof verification packet, encrypts it using the AES key of this session, and sends it to the client.
[0148] After receiving the verification packet, the client decrypts it to obtain relevant information and calls the Linux system call fallocate to pre-allocate 200MB of contiguous storage space on the local disk to avoid disk fragmentation during subsequent fragmented storage.
[0149] Step 3: Fragmented streaming transmission and real-time verification.
[0150] The server sends data fragments to the client sequentially through the data channel, and each fragment is sent along with its corresponding SHA-256 hash value.
[0151] Upon receiving each fragment, the client immediately calculates its hash value locally and compares it with the accompanying value. For example, if fragment number 327 fails verification upon reception, the client immediately sends a retransmission request for fragment number 327 to the server via a separate lightweight signaling channel. The server retransmits this fragment individually, while the transmission of other fragments remains unaffected. The client directly writes the fragments that pass verification to the corresponding offset address in the pre-allocated space.
[0152] Step 4: Final Verification and Merkle Tree Location (Refer to...) Figure 4 ).
[0153] After all fragments have been received, the client reassembles the fragments into a complete file according to their sequence numbers, recalculates the Merkle root hash value of the global file, and compares it a second time with the decrypted value of the pre-stored encrypted root hash.
[0154] Assuming a discrepancy, the client initiates a hierarchical troubleshooting process: starting from the root node, it compares hash values layer by layer to quickly pinpoint the specific subtree containing the shard that is malfunctioning. For example, if the comparison reveals an anomaly in the right subtree, it can then locate the shard range of 1500-1600 within that subtree. This process requires only approximately 11 (log21600) hash comparisons to narrow down the error range, after which only shards within that range are requested to be retransmitted.
[0155] Step 5: Multidimensional Source Tracing Analysis (refer to...) Figure 5 ).
[0156] When the client detects an anomaly in fragment number 327, it automatically collects network status parameters along the transmission path of that fragment:
[0157] Packet loss rate: 45%.
[0158] RTT: 1200ms (baseline value is 50ms).
[0159] Route node hop count: 18 hops (baseline value is 12 hops).
[0160] The source tracing module analyzed the above data: extremely high packet loss rate and sudden changes in routing hop count, indicating that a failure in an intermediate network node caused the routing switch. The client uploaded the logs to the server-side source tracing log database, allowing the administrator to quickly locate the faulty switch for maintenance without needing to conduct a comprehensive investigation of the entire transmission link. The investigation confirmed that the fragmentation anomaly was caused by a network failure, not malicious tampering.
[0161] Step Six: Example of source tracing and determination in malicious tampering scenarios.
[0162] To verify the judgment logic of the source tracing analysis module, a man-in-the-middle attack scenario was simulated: the attacker hijacked the data channel and replaced fragments 800-900 with maliciously constructed data.
[0163] During the final verification, the client encountered a failure to match the local root hash with the server's root hash. The source analysis module collected the following transmission parameters:
[0164] Packet loss rate: 0.1% (within the normal fluctuation range).
[0165] RTT: 52ms (close to the baseline value of 50ms).
[0166] Route node hop count: 12 hops (consistent with the baseline value).
[0167] Error distribution characteristics: Hash verification failures occurred consecutively in fragments 800-900, and the error bits showed a regular offset.
[0168] The source tracing module's comprehensive analysis determined that while network link indicators were normal, a pattern of errors occurred in specific consecutive fragments, consistent with malicious tampering. The client immediately triggered a security alert, reporting the attack event and abnormal fragment range to the server via an independent management channel. The server then added the client's IP to a temporary blocking list and notified the security administrator for emergency response.
[0169] Embodiments of this application also provide a file verification system including: a client and a server, wherein the client and server are connected in communication. (See also...) Figure 6 As shown, the server includes:
[0170] The pre-verification module verifies the first identity credential sent by the client. Upon successful verification, it sends a second identity credential and session key parameters to the client. Before successful client verification, it works in conjunction with firewall policies to prevent the transmission of file data bytes, allowing only signaling interaction.
[0171] The sharding module splits the file to be downloaded into data shards, constructs a Merkle tree based on the shard hash values, and extracts the root hash and shard index table.
[0172] Verification packet generation module: Encapsulates the root hash, total number of shards, and shard index table into a tamper-proof verification packet, encrypts it with the session key, and sends it to the client.
[0173] Data transmission module: It sequentially sends encrypted data fragments through an encrypted data channel and attaches a corresponding leaf node hash value to each data fragment; it supports a targeted retransmission mechanism based on client feedback.
[0174] The client includes:
[0175] Request module: Initiates a download request to the server, carrying the first identity credential signed based on the client's private key.
[0176] Verification module: Verifies the second identity credential returned by the server and establishes an encrypted session; restricts non-signaling data interaction before verification is successful.
[0177] Pre-allocation module: decrypts the anti-tampering verification package, obtains the total number of fragments and fragment size, and calls the operating system interface to pre-allocate contiguous physical storage space on the local disk.
[0178] Receive verification module: Receives streaming data fragments, decrypts them, calculates the real-time hash value and compares it with the hash value of the leaf node. If the verification is successful, the data is written to the corresponding offset address in the pre-allocated storage space.
[0179] Final verification module: After all fragments have been received, the Merkle tree is reconstructed to calculate the local root hash and compare it with the pre-stored root hash; if they do not match, the Merkle tree structure is used to backtrack and locate the abnormal fragment and initiate a retransmission request.
[0180] This system, through its modular architecture design, materializes the method steps described in the above embodiments into functional modules, achieving the same technical effects as the above method embodiments, which will not be repeated here.
[0181] The above describes a file verification method provided by an embodiment of this application. The following describes the apparatus for performing the above file verification method.
[0182] Please see Figure 7 , Figure 7 This is a schematic diagram of a document verification device provided in an embodiment of this application. Figure 7 As shown, the document verification device 700 includes:
[0183] The verification packet receiving module 701 is used to receive the verification packet sent by the server through an encrypted session. The verification packet contains at least the root hash value of the Merkle tree obtained after the file to be downloaded is processed into fragments, as well as the fragment index information.
[0184] The fragment receiving module 702 is used to sequentially receive data fragments and the corresponding leaf node hash values from the server through an encrypted session.
[0185] The real-time verification module 703 is used to calculate the real-time hash value of the data fragment and compare it with the hash value of the leaf node corresponding to the data fragment. If the comparison result matches, the data fragment is written into the storage space of the client at the location corresponding to the fragment index information. If the comparison result does not match, a retransmission request for the data fragment is sent to the server.
[0186] The overall verification module 704 is used to reconstruct the Merkle tree based on the locally stored data fragments after all data fragments have been received, calculate the local root hash value, and compare the local root hash value with the root hash value in the verification packet. If the local root hash value is inconsistent with the root hash value in the verification packet, the abnormal fragment range is located according to the inter-layer hash comparison result of the Merkle tree, and the server is requested to retransmit the data fragments within the abnormal fragment range.
[0187] In one possible implementation, it also includes: an encrypted session module, used for:
[0188] Send a file download request to the server, the download request carrying the first identity credential signed based on the client's private key;
[0189] Receive the second identity credential and session key parameters returned by the server. The second identity credential is generated based on the server's private key signature.
[0190] Verify the second identity credential, and after the second identity credential is verified, establish an encrypted session based on the session key parameter.
[0191] In one possible implementation, it also includes: a data blocking module, wherein the second identity credential is generated by the server after the first identity credential has been verified; the data blocking module is used by the server to block the file data transmission channel before the client has verified the second identity credential, allowing only signaling interaction.
[0192] In one possible implementation, the process of determining the storage space in the real-time verification module 703 includes:
[0193] Obtain the total number of data fragments and the size of each data fragment in the verification packet;
[0194] The total number of bytes in the file to be downloaded is determined by multiplying the total number of fragments by the fragment size.
[0195] Call the operating system's underlying storage interface to pre-allocate contiguous physical storage space on the local disk. The size of the contiguous physical storage space is not less than the total number of bytes.
[0196] In one possible implementation, the process by which the overall verification module 704 locates the range of abnormal fragments based on the inter-level hash comparison results of the Merkle tree includes:
[0197] Starting from the root node of the Merkle tree, the hash values of each node are compared layer by layer until the bottom leaf node with a mismatched hash value is located, and the data shard corresponding to the bottom leaf node is identified as an abnormal shard.
[0198] If the hash values of the nodes in the intermediate layer do not match, the comparison is recursively performed downwards from the root node to narrow down the range of abnormal fragments.
[0199] In one possible implementation, when the real-time hash value and the corresponding leaf node hash value are inconsistent, the real-time verification module 703 is also used to:
[0200] Collect network status parameters along the data fragmentation transmission path;
[0201] Network status parameters are sent to the server to trigger the server to determine the type of transmission anomaly. Transmission anomaly types include: link layer transmission failure and malicious tampering attack.
[0202] In one possible implementation, the real-time verification module 703 is also used for:
[0203] The system receives the result of the transmission anomaly type returned by the server and issues a security alert when the result indicates a malicious tampering attack.
[0204] This application also provides an electronic device in its embodiments. (See reference...) Figure 8 The diagram illustrates a structural schematic of an electronic device suitable for implementing the document verification method in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as laptops, desktop computers, etc. Figure 8 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0205] like Figure 8 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage device 808 into a random access memory (RAM) 803. When the electronic device is powered on, the RAM 803 also stores various programs and data required for the operation of the electronic device. The processing unit 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0206] Typically, the following devices can be connected to I / O interface 805: input devices 806 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 807 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 808 including, for example, memory cards, hard drives, etc.; and communication devices 809. Communication device 809 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 8 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.
[0207] This application also provides a computer program product, including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the file verification methods provided in this application.
[0208] This application also provides a computer-readable storage medium that carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the file verification methods provided in this application.
[0209] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0210] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the file verification method described in the various embodiments of this application.
[0211] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0212] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
Claims
1. A file verification method, characterized in that, Applied to the client side, including: The receiving server sends a verification packet through an encrypted session. The verification packet contains at least: the root hash value of the Merkle tree obtained after the file to be downloaded is processed into fragments, and fragment index information. The encrypted session sequentially receives data fragments from the server and the corresponding leaf node hash values of the data fragments. Calculate the real-time hash value of the data shard and compare the real-time hash value with the hash value of the leaf node corresponding to the data shard; If the comparison results match, the data fragment is written into the storage space of the client at the position corresponding to the fragment index information; If the comparison results are inconsistent, a retransmission request for the data fragment is sent to the server. After all data fragments have been received, the Merkle tree is reconstructed based on the locally stored data fragments, the local root hash value is calculated, and the local root hash value is compared with the root hash value in the verification packet. If the local root hash value is inconsistent with the root hash value in the verification packet, the abnormal fragment range is located based on the inter-layer hash comparison result of the Merkle tree, and the server is requested to retransmit the data fragments within the abnormal fragment range.
2. The file verification method according to claim 1, characterized in that, The process of constructing the encrypted session includes: Send a file download request to the server, the download request carrying a first identity credential signed based on the client's private key; Receive the second identity credential and session key parameters returned by the server, wherein the second identity credential is generated based on the server's private key signature; Verify the second identity credential, and after the second identity credential is verified, establish the encrypted session based on the session key parameter.
3. The file verification method according to claim 2, characterized in that, The second identity credential is generated by the server after the first identity credential has been verified. Before the client verifies the second identity credential, the server blocks the file data transmission channel and only allows signaling interaction.
4. The file verification method according to claim 1, characterized in that, The process of determining the storage space includes: Obtain the total number of fragments and the fragment size of each data fragment in the verification packet; The total number of bytes of the file to be downloaded is determined by multiplying the total number of fragments by the fragment size; The operating system's underlying storage interface is invoked to pre-allocate contiguous physical storage space on the local disk, wherein the size of the contiguous physical storage space is not less than the total number of bytes.
5. The file verification method according to claim 1, characterized in that, The step of locating the abnormal fragment range based on the inter-level hash comparison results of the Merkle tree includes: Starting from the root node of the Merkle tree, the hash values of each node are compared layer by layer until the bottom leaf node with a mismatched hash value is located, and the data fragment corresponding to the bottom leaf node is identified as an abnormal fragment. If the hash values of the nodes in the intermediate layer do not match, the comparison is recursively performed downwards from the root node to narrow down the range of abnormal fragments.
6. The file verification method according to claim 1, characterized in that, When the real-time hash value and the corresponding leaf node hash value are inconsistent, the method further includes: Collect network status parameters on the data fragmentation transmission path; The network status parameters are sent to the server to trigger the server to determine the type of transmission anomaly, which includes: link layer transmission failure and malicious tampering attack.
7. A file verification method, characterized in that, Applied to the server side, including: In response to a file transfer request from a client, a verification packet is sent to the client via an encrypted session. The verification packet contains at least: the root hash value of the Merkle tree obtained after the file to be downloaded has been fragmented, and fragment index information. The encrypted session sequentially sends the data fragments and the corresponding leaf node hash values of the data fragments to the client, so that the client can perform real-time verification of the data fragments. In response to the retransmission request sent by the client, the corresponding data fragment and the hash value of the leaf node corresponding to the corresponding data fragment are retransmitted to the client. In response to a range retransmission request sent by the client, the system retransmits the data fragments within the abnormal fragment range and their corresponding leaf node hash values to the client. The range retransmission request is used to request the retransmission of the data fragments within the abnormal fragment range located by the client based on the inter-layer hash comparison results of the Merkle tree.
8. A document verification device, characterized in that, Applied to the client side, including: The verification packet receiving module is used to receive verification packets sent by the server through an encrypted session. The verification packet includes at least: the root hash value of the Merkle tree obtained after the file to be downloaded is processed into fragments and fragment index information. The data fragment receiving module is used to sequentially receive data fragments from the server and the corresponding leaf node hash values of the data fragments through the encrypted session. A real-time verification module is used to calculate the real-time hash value of the data shard and compare the real-time hash value with the hash value of the leaf node corresponding to the data shard; if the comparison result matches, the data shard is written into the storage space of the client at the position corresponding to the shard index information; if the comparison result does not match, a retransmission request for the data shard is sent to the server; and, The overall verification module is used to reconstruct the Merkle tree based on the locally stored data fragments after all data fragments have been received, calculate the local root hash value, and compare the local root hash value with the root hash value in the verification packet. If the local root hash value is inconsistent with the root hash value in the verification packet, the abnormal fragment range is located according to the inter-layer hash comparison result of the Merkle tree, and the server is requested to retransmit the data fragments within the abnormal fragment range.
9. A document verification system, characterized in that, include: A client and a server are connected in communication. The client is used to execute the file verification method according to any one of claims 1 to 6, and the server is used to execute the file verification method according to claim 7.
10. An electronic device, characterized in that, It includes at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program to enable the electronic device to implement the file verification method as described in any one of claims 1 to 7.
