Lightweight file transmission method and system, storage medium and electronic equipment
By combining national cryptographic algorithms for encryption and block transmission with a heartbeat mechanism, the problem of transmission failure caused by session key expiration and network instability during file transmission is solved, achieving efficient and secure file transmission.
Patent Information
- Application Number
- CN202411516545.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2024-11-29
AI Technical Summary
Existing secure file transfer protocols suffer from session key expiration during prolonged periods of inactivity, making security difficult to guarantee. Furthermore, they are prone to failure when transferring large files under unstable network conditions, and existing encryption algorithms pose potential risks in scenarios with high security requirements.
Data packets are encrypted using national cryptographic algorithms, combined with block transmission and a heartbeat mechanism. Session keys are generated through key negotiation, and the heartbeat mechanism is used to maintain session security. The connection is disconnected if the timeout occurs.
It achieves stable, efficient, and highly secure file transfer, ensuring the security of the session during its validity period and avoiding transfer failures.
Smart Images

Figure CN119052231A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of communication transmission security, and specifically relates to a lightweight file transmission method, system, storage medium and electronic equipment. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] The secure file transfer protocol is a technical means for protecting the security of data transmission in the network, aiming to ensure the confidentiality, integrity and availability of files during transmission. The secure file transfer protocol ensures the legitimacy of both parties in communication through an identity authentication mechanism, and prevents unauthorized access and data tampering by authenticating the identity of the user. The protocol uses a combination of symmetric and asymmetric encryption to encrypt and decrypt the transmitted data, thereby ensuring the confidentiality and integrity of files during network transmission.
[0004] In the secure file transfer protocol, the session state management mechanism is complex, and once the connection is established, data can be continuously transmitted. However, if the connection is idle for a long time or the session key expires, security is difficult to guarantee. When processing large files, there is no effective block mechanism, which may lead to transmission failure when the network is unstable, or even need to start from scratch. Moreover, although protocols such as TLS and SSL have been widely used in the encryption layer of file transfer, the encryption algorithms they rely on, such as AES and RSA, may have potential security risks in certain scenarios with high security requirements. Summary of the invention
[0005] In order to solve the above problems, the present invention proposes a lightweight file transfer method and system, which uses a national secret algorithm to encrypt data packets, transmits data packets in blocks, and uses a heartbeat mechanism to ensure the security of the session during the validity period. If a timeout occurs, the connection is disconnected in time; stable, efficient and secure file transfer is achieved.
[0006] According to some embodiments, a first solution of the present invention provides a lightweight file transmission method, which adopts the following technical solution: A lightweight file transfer method, comprising: Authentication is performed based on the client, and after verification, key negotiation is performed with the target server to obtain the session key; The client initiates a file transfer request to the target server, encrypts the file transfer request based on the obtained session key, and obtains an encrypted data packet; The target server receives and decrypts the encrypted data packet received from the client to obtain the original data packet; Determine the type of data packet sent by the target server to the client based on the obtained original data packet and the file transfer request application; The client arranges and combines the data packets according to the type of data packets received from the target server, in combination with the session key and the data packet sequence number, to obtain a reassembled data packet, and the client completes the file transmission according to the reassembled data packet.
[0007] As a further technical limitation, the file transfer request application initiated by the client to the target server at least includes a file list request application, a file download request application, a file upload request, a heartbeat sending request and an offline request application.
[0008] Furthermore, after receiving the encrypted data packet from the client, the target server decrypts the encrypted data packet in combination with the session key to obtain the original data packet; if the file transfer request application protocol type of the target server is a request for a file list application, the file list information is encrypted and sent back to the client; if the file transfer request application protocol type of the target server is a request for downloading a file, the corresponding file blocks are encrypted and packaged and sent back to the client; if the file transfer request application protocol type of the target server is a request for going offline, the offline confirmation package is encrypted and sent back to the client, and the client linked list node information is deleted.
[0009] Furthermore, if the file transfer request application protocol type of the target server is to send a heartbeat application, the heartbeat data packet timestamp is checked. If the heartbeat data packet timestamp is within the time specified by the client, the unpacked heartbeat data packet is sent to the client to complete the sending of the heartbeat confirmation packet to the client; otherwise, the connection between the target server and the client is disconnected.
[0010] Furthermore, in the process of sending a heartbeat confirmation packet to the client after receiving the heartbeat data packet, the client-encrypted heartbeat data packet is decrypted based on the session key, and the timestamp of the target server is compared with the timestamp of the client's heartbeat data packet. If they do not match, it means that the source of the heartbeat data packet is illegal and an error is prompted; if they match, a heartbeat confirmation packet is sent to the client.
[0011] As a further technical limitation, the client is opened, and a timestamp is generated based on the key distribution center to authenticate the client. After the authentication is passed, the client negotiates a key with the target server to generate a session key for encryption and decryption.
[0012] According to some embodiments, a second solution of the present invention provides a lightweight file transfer system, which adopts the following technical solution: A lightweight file transfer system, comprising: The identity authentication and key negotiation module is configured to perform identity authentication based on the client, and after the authentication is passed, perform key negotiation with the target server to obtain the session key; The encryption processing module is configured to initiate a file transfer request from the client to the target server, encrypt the file transfer request based on the obtained session key, and obtain an encrypted data packet; The transmission module is configured to receive and decrypt the encrypted data packet received from the client by the target server to obtain the original data packet; determine the type of data packet sent by the target server to the client based on the obtained original data packet and the file transfer request application; the client arranges and combines the data packets according to the type of data packet received from the target server, in combination with the session key and the data packet sequence number, to obtain a reorganized data packet, and the client completes the file transmission based on the reorganized data packet.
[0013] According to some embodiments, a third solution of the present invention provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium stores a program, which, when executed by a processor, implements the steps in a lightweight file transmission method as described in the first solution of the present invention.
[0014] According to some embodiments, a fourth solution of the present invention provides an electronic device, which adopts the following technical solution: An electronic device comprises a memory, a processor and a program stored in the memory and running on the processor, wherein when the processor executes the program, the steps in a lightweight file transmission method as described in the first solution of the present invention are implemented.
[0015] According to some embodiments, a fifth solution of the present invention provides a computer program product, which adopts the following technical solution: A computer program product includes software codes, wherein the program in the software codes executes the steps in a lightweight file transmission method as described in the first solution of the present invention.
[0016] Compared with the prior art, the present invention has the following beneficial effects: The present invention uses a national secret algorithm to encrypt data packets, transmits data packets in blocks, and uses a heartbeat mechanism to ensure the security of the session within a valid period. If a timeout occurs, the connection is disconnected in time; thus achieving stable, efficient and secure file transmission.
[0017] The present invention uses key negotiation technology to securely encrypt file information, realizes secure transmission between a target server and a client, adopts a block encryption transmission method to transmit data packets, and adopts a heartbeat mechanism to maintain a session. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings in the specification that constitute a part of this embodiment are used to provide a further understanding of this embodiment. The schematic embodiments of this embodiment and their descriptions are used to explain this embodiment and do not constitute improper limitations on this embodiment.
[0019] Figure 1 This is a flow chart of a lightweight file transmission method in Embodiment 1 of the present invention; Figure 2 This is the byte stream format of the process of processing the format-encrypted data packet in the first embodiment of the present invention. DETAILED DESCRIPTION
[0020] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0021] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present application belongs.
[0022] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0023] In the present invention, terms such as "upper", "lower", "left", "right", "front", "back", "vertical", "horizontal", "side", "bottom", etc. indicate directions or positional relationships based on the directions or positional relationships shown in the accompanying drawings. They are relational words determined only for the convenience of describing the structural relationships of the various parts or elements of the present invention, and do not specifically refer to any part or element in the present invention and should not be understood as limitations on the present invention.
[0024] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0025] Embodiment 1 Embodiment 1 of the present invention introduces a lightweight file transmission method.
[0026] like Figure 1 A lightweight file transfer method is shown, comprising the following steps: Step S01: When the application is opened on the client, it performs identity authentication with the key distribution center KDC and performs key negotiation with the target server to generate a unified session key K; Step S02: The client sends a data packet requesting a service to the target server, which is encrypted using the national encryption algorithm and uses the session key K as the key; Step S03: The target server updates the IV of the national encryption algorithm SM4 and stores the client information in the linked list node; Step S04: After receiving the encrypted data packet from the client, the target server decrypts the original data. If the protocol type is a request for a file list, the file list information is encrypted and sent back to the client; if the protocol type is a request for downloading a file, the corresponding file is encrypted in blocks and packaged and sent back to the client; if the protocol type is a request for offline, the offline confirmation packet is encrypted and sent back to the client, and the client linked list node information is deleted; if the protocol type is a heartbeat data packet, the heartbeat packet timestamp is checked, and if it is within the specified time, the heartbeat confirmation packet is encrypted and sent back to the client, otherwise the connection is disconnected; Step S05: The client receives the data packets from the target server, decrypts them using the session key K, and then arranges and combines the data packets according to the sequence of the packet numbers to reconstruct a complete and ordered data packet.
[0027] As one or more implementation modes, in step S01, identity authentication is performed with the KDC and key negotiation is performed with the target server to generate a unified session key K, which specifically includes: The client performs identity authentication with the KDC to generate a timestamp Tkdc and a session key K for encryption and decryption; The client negotiates a key with the target server using the session key K.
[0028] As one or more implementation modes, in step S02, requesting services at least includes requesting a file list, requesting a file download, requesting a file upload, requesting a heartbeat send, and requesting a logout.
[0029] As one or more implementation modes, in step S03, the target server updates the IV of the SM4 encryption algorithm and stores the client information in the linked list node, specifically: Step S301: IV is taken from the 8-byte CRC check value and the 8-byte data packet number, such as Figure 2 As shown; Step S302: The target server first searches through the FindNode function whether there is a node for the client. If not, a new node is created and the client information and the sent data are stored in the node. If there is a client node, the data sent by the client is stored in the node.
[0030] As one or more implementation modes, in step S04, when the target server unpacks the packet, the first byte is the protocol type, the second and third bytes are the protocol lengths, and the protocol type, protocol length, CRC checksum, data packet number and file information are placed in sequence in the buffer; different unpacking functions are selected according to different protocol types and protocol lengths; the file is divided into several packets according to the size of the file to be sent, that is, the size of the original file is determined by flen, flen / MAXPACKLEN is calculated and rounded up to obtain the data packet to be sent, and it is determined whether the total number of packets is greater than the current packet number. If so, continue to send, otherwise stop sending.
[0031] As one or more implementation modes, the process of encrypting the data packet includes: Step S4101: determine the packet sequence number of each data packet, and convert it into a byte stream form together with the CRC checksum, file information and hash value; Step S4102: Convert the packetized data into a byte stream using binary encoding; Step S4103: Combine the above byte streams into a new byte stream in the order of CRC check, packet sequence number, file information, hash value, and packet data information; Step S4104: Use UpdateIV_SM4CTX function to update the IV value of the SM4 encryption algorithm; Step S4105: Encrypt the file information in the byte stream using the CTR mode of the SM4 encryption algorithm; Step S4106: Add the protocol type and protocol length in front of the data packet encrypted using the SM4 algorithm to obtain a processed data packet.
[0032] As one or more implementation modes, in step S4106, a protocol type and a protocol length are added to the front of the data packet encrypted using the SM4 algorithm to obtain a processed data packet, specifically including: Add a one-byte protocol type and add it to the front of the data packet as a fixed header information; Add two bytes of protocol length after the protocol type to indicate different protocols; its format is as follows Figure 2 shown.
[0033] As one or more implementation modes, in step S04, after the target server decompresses the heartbeat packet, it encrypts the heartbeat confirmation packet and sends it back to the client, specifically including: Step S4201: during the unpacking process, the IV value of the SM4 encryption algorithm on the server side is updated according to the heartbeat packet rqst sent by the client, to ensure that the encryption results of each heartbeat packet on the client side are inconsistent; Step S4202: Use the counting mode CTR mode of the SM4 algorithm to decrypt the client heartbeat packet content; Step S4203: Compare the timestamp Tkdc saved by the target server with the timestamp in the heartbeat packet of the client. If the decrypted data does not match the Tkdc of the server, it means that the source of the heartbeat packet is illegal, and an error message is displayed; Step S4204: when encrypting the confirmation packet, the protocol type, protocol length, instruction code, CRC check value and data packet number are sequentially encapsulated at the beginning of the data packet; Step S4205: Use UpdateIV_SM4CTX function to update the initial vector IV of the SM4 encryption algorithm starting from the CRC check value part; Step S4206: copy the timestamp Tkdc (8 bytes) and the current system time (8 bytes) to the buffer, encrypt the 16-byte data in the buffer using the CTR mode of the SM4 encryption algorithm, store the encrypted data after the data packet number, and then send it to the client.
[0034] It should be noted that in step S05, the data packets sent by the server to the client may be transmitted in blocks according to their size. During the network transmission process, the data packets may arrive out of order due to route changes, network congestion, etc. The permutation and combination operation can correctly rearrange these data packets in the order of packet numbers to ensure the integrity and coherence of the original data stream.
[0035] This embodiment uses the national secret algorithm to encrypt the data packet, transmits the data packet in blocks, and uses the heartbeat mechanism to ensure the security of the session during the validity period. If it times out, the connection is disconnected in time; thus achieving stable, efficient and secure file transmission.
[0036] This embodiment uses key negotiation technology to securely encrypt file information, implements secure transmission between the target server and the client, uses block encryption transmission to transmit data packets, and uses a heartbeat mechanism to maintain the session.
[0037] Embodiment 2 Embodiment 2 of the present invention introduces a lightweight file transmission system.
[0038] A lightweight file transfer system, comprising: The identity authentication and key negotiation module is configured to perform identity authentication based on the client, and after the authentication is passed, perform key negotiation with the target server to obtain the session key; The encryption processing module is configured to initiate a file transfer request from the client to the target server, encrypt the file transfer request based on the obtained session key, and obtain an encrypted data packet; The transmission module is configured to receive and decrypt the encrypted data packet received from the client by the target server to obtain the original data packet; determine the type of data packet sent by the target server to the client based on the obtained original data packet and the file transfer request application; the client arranges and combines the data packets according to the type of data packet received from the target server, in combination with the session key and the data packet sequence number, to obtain a reorganized data packet, and the client completes the file transmission based on the reorganized data packet.
[0039] The detailed steps are the same as those of the lightweight file transfer method provided in Example 1 and will not be repeated here.
[0040] Embodiment 3 Embodiment 3 of the present invention provides a computer-readable storage medium.
[0041] A computer-readable storage medium stores a program, which, when executed by a processor, implements the steps in a lightweight file transmission method as described in Embodiment 1 of the present invention.
[0042] The detailed steps are the same as those of the lightweight file transfer method provided in Example 1 and will not be repeated here.
[0043] Embodiment 4 A fourth embodiment of the present invention provides an electronic device.
[0044] An electronic device comprises a memory, a processor and a program stored in the memory and running on the processor, wherein when the processor executes the program, the steps in a lightweight file transmission method as described in Embodiment 1 of the present invention are implemented.
[0045] The detailed steps are the same as those of the lightweight file transfer method provided in Example 1 and will not be repeated here.
[0046] Embodiment 5 Embodiment 5 of the present invention provides a computer program product.
[0047] A computer program product includes software codes, wherein the program in the software codes executes the steps in a lightweight file transmission method as described in Embodiment 1 of the present invention.
[0048] The detailed steps are the same as those of the lightweight file transfer method provided in Example 1 and will not be repeated here.
[0049] The above description is only a preferred embodiment of the present embodiment and is not intended to limit the present embodiment. For those skilled in the art, the present embodiment may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present embodiment shall be included in the protection scope of the present embodiment.
Claims
1. A lightweight file transfer method, characterized in that: include: Authentication is performed based on the client, and after verification, key negotiation is performed with the target server to obtain the session key; The client initiates a file transfer request to the target server, encrypts the file transfer request based on the obtained session key, and obtains an encrypted data packet; The target server receives and decrypts the encrypted data packet received from the client to obtain the original data packet; Determine the type of data packet sent by the target server to the client based on the obtained original data packet and the file transfer request application; The client arranges and combines the data packets according to the type of data packets received from the target server, in combination with the session key and the data packet sequence number, to obtain a reassembled data packet, and the client completes the file transmission according to the reassembled data packet.
2. A lightweight file transfer method as claimed in claim 1, characterized in that: The file transfer request application initiated by the client to the target server at least includes a file list request application, a file download request application, a file upload request, a heartbeat sending request and an offline request application.
3. A lightweight file transfer method as claimed in claim 2, characterized in that: After receiving the encrypted data packet from the client, the target server decrypts the encrypted data packet in combination with the session key to obtain the original data packet; If the file transfer request protocol type of the target server is a file list request, the file list information is encrypted and sent back to the client; If the file transfer request application protocol type of the target server is a request to download a file, the corresponding file will be encrypted in blocks and packaged and sent back to the client; if the file transfer request application protocol type of the target server is a request to go offline, the offline confirmation package will be encrypted and sent back to the client, and the client linked list node information will be deleted.
4. A lightweight file transfer method as claimed in claim 3, characterized in that: If the file transfer request application protocol type of the target server is to send a heartbeat application, the heartbeat data packet timestamp is checked. If the heartbeat data packet timestamp is within the time specified by the client, the unpacked heartbeat data packet is sent to the client to complete the sending of the heartbeat confirmation packet to the client; Otherwise, the connection between the target server and the client is disconnected.
5. A lightweight file transfer method as claimed in claim 4, characterized in that: When the target server receives the heartbeat data packet and sends a heartbeat confirmation packet to the client, the client-encrypted heartbeat data packet is decrypted based on the session key, and the timestamp of the target server is compared with the timestamp of the client heartbeat data packet. If they do not match, it means that the source of the heartbeat data packet is illegal and an error is prompted; If a match is found, a heartbeat confirmation packet is sent to the client.
6. A lightweight file transfer method as claimed in claim 1, characterized in that: Open the client and generate a timestamp based on the key distribution center to authenticate the client. After the authentication is passed, the client negotiates the key with the target server to generate a session key for encryption and decryption.
7. A lightweight file transfer system, characterized in that: include: The identity authentication and key negotiation module is configured to perform identity authentication based on the client, and after the authentication is passed, perform key negotiation with the target server to obtain the session key; The encryption processing module is configured to initiate a file transfer request from the client to the target server, encrypt the file transfer request based on the obtained session key, and obtain an encrypted data packet; The transmission module is configured to receive and decrypt the encrypted data packet received from the client by the target server to obtain the original data packet; determine the type of data packet sent by the target server to the client according to the obtained original data packet and the file transfer request application; The client arranges and combines the data packets according to the type of data packets received from the target server, in combination with the session key and the data packet sequence number, to obtain a reassembled data packet, and the client completes the file transmission according to the reassembled data packet.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of a lightweight file transmission method as described in any one of claims 1 to 6 are implemented.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the program, the steps of a lightweight file transmission method as described in any one of claims 1-6 are implemented.
10. A computer program product comprising software code, characterized in that The program in the software code executes the steps of a lightweight file transfer method as described in any one of claims 1-6.
Citation Information
Patent Citations
Session processing method and device
CN104348808A
File transfer method and equipment based on SSL (Secure Socket Layer) protocol authentication
CN106657135A
Network session encryption method, server and computer readable storage medium
CN113872974A
Heartbeat monitoring method and device, equipment and storage medium
CN115665016A
CoAP protocol identity authentication and data encryption method based on national secret
CN116707826A
Cited By
LCD safety protection system based on encryption processing
CN120200738A
LCD security protection system based on encryption processing
CN120200738B
