A method and system for secure SFTP multi-terminal file transmission based on national secret algorithm
Through SM3 digest, SM2 signing and SM4 encryption based on the national secret algorithm, combined with the SSH protocol, the problem of data leakage and tampering in SFTP file transmission is solved, and high security and reliability of file transmission are achieved. The use of the national secret algorithm High security and fast computing speed reduce risks during transmission.
Patent Information
- Application Number
- CN202111553753.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2041-12-17
AI Technical Summary
The existing SFTP file transfer method has the risk of data leakage and tampering during file processing, and lacks effective security guarantees, affecting the reliability and accuracy of the data.
Adopt a method based on the national secret algorithm, through SM3 digest, SM2 signature and SM4 encryption, combined with SSH protocol to ensure the security of the file during transmission, use SM2 private key signature and SM4 encryption, and use SM3 digest Verification to ensure file integrity and security.
It effectively prevents data leakage and tampering during file transfer, improves the security and reliability of file transfer, and uses the high security and fast computing speed of the national secret algorithm to reduce risks during the transfer process.
Smart Images

Figure CN114338648B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information technology, and more specifically, to a method and system for secure transmission of SFTP multi-terminal files based on a national secret algorithm. Background Art
[0002] With the continuous development of science and technology, the transformation of enterprises towards digitalization has become a global trend. There are more and more scenarios where data can be processed and interacted with through information technology, making data transmission security an important issue that needs to be faced. Lack of data transmission security will cause serious damage to production, operations, personal assets, personal privacy, etc.
[0003] FTP and SFTP are the two most commonly used file transfer methods. FTP (File Transfer Protocol) is based on the TCP / IP protocol and does not provide a secure channel to transfer files between hosts. Passwords and data are transmitted in plain text, which has high transmission efficiency but insufficient security. SFTP is part of the SSH protocol and requires client users to be authenticated by the server, and data transmission must be carried out through a secure channel (SSH). Data is encrypted before sending and transmitted in binary form, which has high security.
[0004] However, during the entire data output process, file processing applications are often not deployed on SFTP servers. File content is generated and uploaded to SFTP, and then downloaded from SFTP and transferred to the processing application. This process still poses the risk of information being intercepted and content being tampered with. File data interaction in Internet scenarios requires a secure transmission method that can prevent data leakage during file transfer and ensure the reliability and accuracy of file transfer. Summary of the invention
[0005] The technical problem to be solved by the present invention is to address the above-mentioned shortcomings of the prior art. The first purpose of the present invention is to provide a method for secure SFTP multi-terminal file transmission based on the national secret algorithm to prevent data leakage during file transmission and ensure the reliability and accuracy of file transmission.
[0006] The second purpose of the present invention is to provide a system for secure SFTP multi-terminal file transmission based on the national secret algorithm to prevent data leakage during file transmission and ensure the reliability and accuracy of file transmission.
[0007] In order to achieve the above-mentioned purpose one, the present invention provides a method for secure transmission of SFTP multi-terminal files based on a national secret algorithm, comprising:
[0008] On the SFTP server, a corresponding SFTP file directory is constructed for each consumer client to prevent the data files belonging to the consumer client from being downloaded or tampered with by other consumer clients;
[0009] Set the ssh private key and public key used by the consumer client to connect;
[0010] The SM3 algorithm is used on the consumer client to digest the original content Y of the file, and a 256-bit file digest Y'=h(Y) is obtained;
[0011] Sign the file summary Y' using SM2's private key d to obtain the signature result C = e(Y');
[0012] Use SM4 ECB mode to encrypt the original file content Y to obtain the encrypted file K';
[0013] Assemble the encrypted file K', file summary Y' and signature result C into an http message and send it to the SFTP server via https;
[0014] The SFTP server receives the data sent by the consumer client and verifies the signature of the data. After the signature verification is passed, the data is decrypted and the digest is compared and verified. After the verification is passed, the original content of the file is encrypted again to obtain the ciphertext file k.
[0015] According to the file storage directory and file name generation rules agreed upon by the SFTP server and the consumer client, the ciphertext file k is saved in the SFTP file directory for the consumer client to request download.
[0016] As a further improvement, the SFTP server executes the sftp.sh script and uses ssh-keygen to generate the RSA public key id_rsa_U corresponding to each consumer client. i .pub and private key id_rsa_U i , U i Represents the consumer client;
[0017] Furthermore, the process of summarizing the original content Y of the file is as follows:
[0018] Group the text into 512*N+448, where N is an arbitrary integer; if it is less than 512 bits, fill it with multiple "0"s and a "1" at the end;
[0019] Add the 64-bit file length information to form 512*(N+1) groups, and iteratively compress the N+1 groups to obtain the final 256-bit hash value.
[0020] Furthermore, appropriate elliptic curve parameters are selected to generate the private key d and public key p of SM2, where G is a reference point on the elliptic curve, satisfying P=d*G.
[0021] Furthermore, the process of encrypting the original content Y of the file is: using the agreed offset a, adopting the SM4 / ECB / PKCS5Padding filling mode, obtaining the encryption result K=f(Y), performing Base64 transcoding on the encryption result K, and obtaining the encrypted file K'.
[0022] Furthermore, the signature verification process is: use SM2's public key P to verify Y' and C in the message C'=v(Y',C), the function v(Y',C) is to sign Y' once to get the result C', if C=C', the signature verification passes; otherwise, the signature verification fails, indicating that the message has been tampered with during transmission.
[0023] Furthermore, the process of decryption and summary comparison and verification is as follows: by using the SM4 key to decrypt the file, the original content Y of the file is obtained, and then the SM3 summary y'=h(y) of the original content Y of the file is made, and the obtained summary result is compared and verified with the summary generated by the consumer client. If Y'=y', it means that the summary verification passes and the file has not been tampered with; otherwise, the file has been tampered with.
[0024] Furthermore, the original content Y of the file is encrypted using the SM4 key b of the corresponding consumer client to obtain the ciphertext file k=b(y).
[0025] Furthermore, it also includes:
[0026] The consumer client uses the issued ssh key certificate to establish an ssh secure encrypted tunnel with the SFTP server and enter the agreed SFTP file directory;
[0027] The consumer client sends a file download request to the SFTP server. After receiving the download request, the SFTP server transfers the file to the consumer client based on the SFTP protocol.
[0028] After the consumer client completes file reception, it uses the corresponding SM4 key to decrypt the file and obtain the required original file content.
[0029] In order to achieve the above-mentioned second objective, the present invention provides a system for secure transmission of SFTP multi-terminal files based on a national secret algorithm, including an SFTP server and multiple consumer clients, wherein the SFTP server is provided with a core system module, and each of the consumer clients is provided with a file content generation module;
[0030] The file content generation module encrypts the file according to the above method on the consumer client and sends it to the SFTP server;
[0031] The core system module receives files at the SFTP server, decrypts the received files according to the above method, and saves them in the corresponding SFTP file directory for downloading by the consumer client.
[0032] Beneficial Effects
[0033] Compared with the prior art, the present invention has the following advantages:
[0034] (1) The present invention utilizes the SFTP file transfer method based on the SSH protocol and adopts RSA public and private key authentication means. Each client uses its own certificate to access the allocated directory, and the file is securely transmitted in the encrypted tunnel.
[0035] (2) The present invention uses the SM3 digest algorithm to replace the traditional MD5 algorithm, which has better collision stability, original root stability and second original root stability and has higher security.
[0036] (3) The present invention uses the ECC-based asymmetric encryption algorithm SM2 to sign the SM3 summary result, effectively reducing the risk of the message being deciphered and tampered with after being intercepted. Compared with the traditional asymmetric encryption RSA algorithm, the SM2 using the ECC 256-bit algorithm has a higher security strength than RSA 2048-bit, but the operation speed is faster than RSA. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 is a system architecture diagram of the present invention;
[0038] Figure 2 This is the encrypted flow chart of the present invention. DETAILED DESCRIPTION
[0039] The present invention will be further described below with reference to the specific embodiments in the accompanying drawings.
[0040] See also Figure 1 , 2 , a method for secure SFTP multi-terminal file transmission based on a national secret algorithm, comprising:
[0041] On the SFTP server, a corresponding SFTP file directory is constructed for each consumer client. The SFTP server is used to implement file transfer between the file consumer clients. Since data interaction with multiple file consumer clients is required, constructing a corresponding SFTP file directory can prevent data files belonging to a consumer client from being downloaded or tampered with by other consumer clients.
[0042] Set the ssh private key and public key used by the consumer client to connect. Specifically, the SFTP server executes the sftp.sh script and uses ssh-keygen to generate the RSA public key id_rsa_U corresponding to each consumer client.i .pub and private key id_rsa_U i , U i Represents the consumer client;
[0043] The SM3 algorithm is used on the consumer client to digest the original content Y of the file, and a 256-bit file digest Y'=h(Y) is obtained;
[0044] Select appropriate elliptic curve parameters to generate SM2's private key d and public key p, G is the reference point on the elliptic curve, satisfying P = d * G, and use SM2's private key d to sign the file summary Y' to obtain the signing result C = e(Y');
[0045] Use SM4 ECB mode to encrypt the original file content Y to obtain the encrypted file K';
[0046] The encrypted file K', file digest Y' and signature result C are assembled into an http message and sent to the SFTP server via https, which can effectively prevent the risk of being deciphered and tampered with after the message is intercepted;
[0047] The SFTP server receives the data sent by the consumer client and verifies the signature of the data; after the signature verification is passed, the data is decrypted and the digest is compared and verified; after the verification is passed, the original content of the file (that is, the file that has not been tampered with) is re-encrypted to obtain the ciphertext file k, specifically, the original content of the file Y is encrypted using the SM4 key b of the corresponding consumer client to obtain the ciphertext file k=b(y);
[0048] According to the file storage directory and file name generation rules agreed upon by the SFTP server and the consumer client, the ciphertext file k is saved in the SFTP file directory for the consumer client to request download.
[0049] The process of summarizing the original content Y of the file is as follows:
[0050] Group the text into 512*N+448, where N is an arbitrary integer; if it is less than 512 bits, fill it with multiple "0"s and a "1" at the end;
[0051] Add the 64-bit file length information to form 512*(N+1) groups, and iteratively compress the N+1 groups to obtain the final 256-bit hash value.
[0052] The process of encrypting the original content Y of the file is: using the agreed offset a, adopting the SM4 / ECB / PKCS5Padding filling mode, obtaining the encryption result K=f(Y), performing Base64 transcoding on the encryption result K, and obtaining the encrypted file K'.
[0053] The signature verification process is as follows: use SM2's public key P to verify Y' and C in the message C'=v(Y',C). The function v(Y',C) is to sign Y' once to get the result C'. If C=C', the signature verification passes; otherwise, the signature verification fails, indicating that the message has been tampered with during transmission.
[0054] The process of decryption and summary comparison verification is as follows: decrypt the file using the SM4 key to obtain the original content Y of the file, then make the SM3 summary y'=h(y) of the original content Y of the file, and compare the obtained summary result with the summary generated by the consumer client. If Y'=y', it means that the summary verification passes and the file has not been tampered with; otherwise, the file has been tampered with.
[0055] The method further comprises:
[0056] The consumer client uses the issued ssh key certificate to establish an ssh secure encrypted tunnel with the SFTP server and enter the agreed SFTP file directory;
[0057] The consumer client sends a file download request to the SFTP server. After receiving the download request, the SFTP server transfers the file to the consumer client based on the SFTP protocol.
[0058] After the consumer client completes file reception, it uses the corresponding SM4 key to decrypt the file and obtain the required original file content.
[0059] A system for secure transmission of SFTP multi-terminal files based on a national secret algorithm, comprising an SFTP server and multiple consumer clients, wherein the SFTP server is provided with a core system module, and each consumer client is provided with a file content generation module;
[0060] The file content generation module encrypts the file according to the above method on the consumer client and sends it to the SFTP server;
[0061] The core system module receives the file on the SFTP server, decrypts the received file according to the above method, and saves it to the corresponding SFTP file directory for downloading by the consumer client.
[0062] The above are only preferred embodiments of the present invention. It should be pointed out that for those skilled in the art, several modifications and improvements can be made without departing from the structure of the present invention, which will not affect the effect of the implementation of the present invention and the practicality of the patent.
Claims
1. A method for secure transmission of SFTP files at multiple terminals based on a national secret algorithm, characterized in that: include: On the SFTP server, a corresponding SFTP file directory is constructed for each consumer client to prevent the data files belonging to the consumer client from being downloaded or tampered with by other consumer clients; Set the ssh private key and public key used by the consumer client to connect; Use the SM3 algorithm on the consumer client to parse the original content of the file Perform a digest to obtain a 256-bit file digest ; Summary of the document Use SM2's private key d to sign and get the signing result ; Use SM4 ECB mode to modify the original content of the file Encryption, get encrypted file ; Encrypted files , Document Summary And the result of the endorsement Assemble the http message and send it to the SFTP server via https; The SFTP server receives the data sent by the consumer client and verifies the signature of the data. After the signature is verified, the data is decrypted and the summary is compared and verified. After verification, the original content of the file is encrypted again to obtain the ciphertext file k ; According to the file storage directory and file name generation rules agreed upon by the SFTP server and the consumer client, the ciphertext file k Save it to the SFTP file directory for download by the consumer client; The SFTP server executes the sftp.sh script and uses ssh-keygen to generate the RSA public key id_rsa_U corresponding to each consumer client. i .pub and private key id_rsa_U i , U i Represents the consumer client; Original content of the file The process of summarizing is: Group the text into 512*N+448, where N is an arbitrary integer; if it is less than 512 bits, fill it with multiple 0s and a 1 at the end; Add the 64-bit file length information to form 512*(N+1) groups, and iteratively compress the N+1 groups to obtain the final 256-bit hash value.
2. According to claim 1, a method for secure SFTP multi-terminal file transmission based on a national secret algorithm is characterized in that: Select appropriate elliptic curve parameters to generate SM2's private key d and public key p, G is the reference point on the elliptic curve, satisfying .
3. According to claim 1, a method for secure SFTP multi-terminal file transmission based on a national secret algorithm is characterized in that: Original content of the file The encryption process is: using the agreed offset , using SM4 / ECB / PKCS5Padding filling mode, get the encryption result , the encryption result K Perform Base64 transcoding to obtain the encrypted file .
4. According to claim 1, a method for secure SFTP multi-terminal file transmission based on a national secret algorithm is characterized in that: The signature verification process is: using SM2's public key For the message and Verify the signature ,function Yes Do a signature process to get the result ,like , the signature verification passes; otherwise, the signature verification fails, indicating that the message has been tampered with during transmission.
5. According to claim 1, a method for secure SFTP multi-terminal file transmission based on a national secret algorithm is characterized in that: The process of decryption and summary comparison verification is as follows: Decrypt the file using the SM4 key to obtain the original content of the file , then the original content of the file Do SM3 summary , compare and verify the obtained summary result with the summary produced by the consuming client. If , it means that the summary verification has passed and the file has not been tampered with; otherwise, the file has been tampered with.
6. According to claim 1, a method for secure SFTP multi-terminal file transmission based on a national secret algorithm is characterized in that: Original content of the file Use the SM4 key of the corresponding consumer client Encrypt to obtain the ciphertext file .
7. A method for secure SFTP multi-terminal file transmission based on a national secret algorithm according to any one of claims 1 to 6, characterized in that: Also includes: The consumer client uses the issued ssh key certificate to establish an ssh secure encrypted tunnel with the SFTP server and enter the agreed SFTP file directory; The consumer client sends a file download request to the SFTP server. After receiving the download request, the SFTP server transfers the file to the consumer client based on the SFTP protocol. After the consumer client completes file reception, it uses the corresponding SM4 key to decrypt the file and obtain the required original file content.
8. A system for secure SFTP multi-terminal file transmission based on national secret algorithm, characterized in that: It includes an SFTP server and multiple consumer clients, wherein the SFTP server is provided with a core system module, and each consumer client is provided with a file content generation module; The file content generation module encrypts the file according to the method described in any one of claims 1 to 7 on the consumer client, and sends it to the SFTP server; The core system module receives files at the SFTP server, decrypts the received files according to the method described in any one of claims 1 to 7, and saves the files to the corresponding SFTP file directory for downloading by the consumer client.
