SSH login authentication method, communication system and storage medium based on national secret algorithm

The SSH login authentication method employs SM2 and SM4 keys with SM3 hash functions to bolster SSH session security, addressing vulnerabilities in RSA and ensuring national information security.

CN118764315BActive Publication Date: 2024-12-31BEIJING GEER GUOXIN TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411223919.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-03
Publication Date
2024-12-31
Estimated Expiration
2044-09-03

AI Technical Summary

Technical Problem

The RSA encryption algorithm used in SSH login authentication is vulnerable to advances in computing power, lacks autonomy, and is susceptible to international political factors, compromising national information and network security.

Method used

Implementing an SSH login authentication method using the SM2 public and private keys and SM4 session key based on national secret algorithms, including key generation, exchange, and encryption with SM3 hash functions to enhance security.

Benefits of technology

Enhances SSH session security by leveraging national secret algorithms, ensuring compliance and robustness against computational attacks while maintaining data integrity and confidentiality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118764315B_ABST
    Figure CN118764315B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of information security technology, and specifically to an SSH login authentication method, a communication system and a storage medium based on a national secret algorithm, aiming to improve the security of session data. The SSH login authentication method based on a national secret algorithm proposed by the present invention includes: the server accepts the SSH connection request of the client and establishes a TCP connection; the server negotiates the SSH protocol version number with the client; the server negotiates the algorithm with the client; the server and the client generate a pair of SM2 public and private keys respectively, and exchange public keys; the server and the client generate a shared key based on the public key of the other party and their own private key, and then generate an SM4 session key; the client sends a login request to the server, and the login request is encrypted using the SM4 session key; the server uses the SM4 session key to decrypt the login request and authenticate the client. The present invention uses the national secret algorithm to encrypt and decrypt SSH communication data, effectively improving the security of the SSH session.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information security technology, and in particular to an SSH login authentication method, a communication system and a storage medium based on a national secret algorithm. Background Art

[0002] SSH (Secure Shell) protocol is a network protocol used to run network services securely in an insecure network. SSH login authentication is a process involving multiple steps to ensure the security of remote access and the authenticity of user identity. Currently, the RSA (Rivest-Shamir-Adleman) encryption algorithm is widely used for login authentication.

[0003] RSA is an internationally used asymmetric cryptographic algorithm, widely used in various security fields. The security of the RSA algorithm is based on the difficulty of factoring large prime numbers. However, with the improvement of computing power, the time required to crack RSA is getting shorter and shorter. In addition, as an internationally used algorithm, RSA has relatively low autonomy and controllability, and may be affected by international political factors, making it difficult to ensure national information security and network security.

[0004] In view of this, how to improve data security in SSH sessions has become an urgent problem to be solved. Summary of the invention

[0005] In order to solve the above problems in the prior art, the present invention proposes an SSH login authentication method, a communication system and a storage medium based on a national secret algorithm, which improves the security of data in an SSH session.

[0006] In a first aspect of the present invention, a SSH login authentication method based on a national secret algorithm is proposed, the method comprising:

[0007] The server accepts the SSH connection request from the client and establishes a TCP connection;

[0008] The server negotiates the SSH protocol version number with the client;

[0009] The server negotiates an algorithm with the client;

[0010] The server and the client generate a pair of SM2 public and private keys respectively, and exchange public keys;

[0011] The server and the client generate a shared key based on the other party's public key and their own private key, and then generate an SM4 session key;

[0012] The client sends a login request to the server, where the login request is encrypted using the SM4 session key;

[0013] The server uses the SM4 session key to decrypt the login request and authenticate the client.

[0014] Preferably, the step of "the server and the client respectively generate a pair of SM2 public and private keys, and exchange public keys" includes:

[0015] The server generates a public key x and a private key x based on the SM2 algorithm, and sends the public key x and the host unique identifier host Key of the host to the client; wherein the host Key is generated using the national secret SM3 hash algorithm based on the algorithm name and public key information describing the national secret SSH;

[0016] The client generates a public key y and a private key y based on the SM2 algorithm, and sends the public key y to the server.

[0017] Preferably, the step of "the server and the client generate a shared key according to the other party's public key and their own private key respectively, and then generate an SM4 session key" includes:

[0018] The server calculates a first shared key according to the public key y and the private key x;

[0019] The client calculates a second shared key according to the public key x and the private key y;

[0020] The server generates a first hash value by using a preset hash value calculation method, generates a signature based on the SM2 algorithm according to the private key x and the first hash value, and sends the signature to the client;

[0021] The client generates a second hash value by using the preset hash value calculation method, and performs a signature verification operation based on the SM2 algorithm according to the public key y and the second hash value;

[0022] The server and the client calculate the SM4 session key according to the following formula:

[0023] SecKey = hash (K||H||C||session_id);

[0024] in,

[0025] hash represents the hash function, which uses the SM3 algorithm;

[0026] || indicates splicing;

[0027] K represents the first shared key or the second shared key;

[0028] H represents the first hash value or the second hash value;

[0029] C represents an uppercase ASCII letter 'A', 'B', 'C', 'D', 'E', or 'F';

[0030] When C is 'A', the calculated SM4 session key will be used as the initialization vector from the client to the server;

[0031] When C is 'B', the calculated SM4 session key will be used as the initialization vector from the client to the server;

[0032] When C is 'C', the calculated SM4 session key will be used as the encryption key from the client to the server;

[0033] When C is 'D', the calculated SM4 session key will be used as the encryption key from the server to the client;

[0034] When C is 'E', the calculated SM4 session key will be used as the integrity key from the client to the server;

[0035] When C is 'F', the calculated SM4 session key will be used as the integrity key from the server to the client;

[0036] session_id represents the H value generated when the client and the server are connected for the first time.

[0037] Preferably, the preset hash value calculation method is:

[0038] H = hash(V_C || V_S || I_C || I_S || K_S || e || f || K);

[0039] in,

[0040] hash represents the hash function, which uses the SM3 algorithm;

[0041] || indicates splicing;

[0042] V_C represents the version number sent by the client to the server during the version negotiation phase;

[0043] V_S represents the version number sent by the server to the client during the version negotiation phase;

[0044] I_C represents the payload of the SSH_MSG_KEX_INIT message sent by the client during the algorithm negotiation phase;

[0045] I_S represents the payload of the SSH_MSG_KEX_INIT message sent by the server during the algorithm negotiation phase;

[0046] K_S represents the host key public key of the host where the server is located;

[0047] e represents the public key y generated by the client;

[0048] f represents the public key x generated by the server;

[0049] K represents the first shared key or the second shared key.

[0050] Preferably, the authentication method is a public-private key authentication method;

[0051] The step of “the client sends a login request to the server, and the login request is encrypted using the SM4 session key” includes:

[0052] The client generates a user public key z and a private key z based on the SM2 algorithm, and sends the user public key z to the server;

[0053] The client sends a login request to the server, wherein the login request includes: a user account, the authentication method and the public key z, and is encrypted using the SM4 algorithm using the SM4 session key.

[0054] Preferably, the step of "the server uses the SM4 session key to decrypt the login request and authenticate the client" includes:

[0055] The server uses the SM4 session key to perform SM4 algorithm decryption on the login request to obtain the user account, the authentication method and the public key z;

[0056] The server verifies the received public key z using the stored public key z;

[0057] The server generates a random string, encrypts it using the public key z, and encrypts it again using the SM4 algorithm using the SM4 session key before sending it to the client;

[0058] The client uses the SM4 session key to perform SM4 algorithm decryption on the received message, and uses the private key z to decrypt the data again to obtain a challenge;

[0059] The client uses the SM4 session key to encrypt the challenge using the SM4 algorithm and sends it to the server;

[0060] The server uses the SM4 session key to perform SM4 algorithm decryption on the received message to obtain the challenge;

[0061] The server determines whether the challenge matches the random string, thereby determining whether the authentication is successful.

[0062] Preferably, the authentication method is a password authentication method;

[0063] The login request includes: user account, authentication method and user password;

[0064] The step of “the server uses the SM4 session key to decrypt the login request and authenticate the client” includes:

[0065] The server uses the SM4 session key to perform SM4 algorithm decryption on the login request to obtain the user account, the authentication method and the user password;

[0066] The server verifies the user account and the user password according to the pre-stored account and password to determine whether the authentication is successful.

[0067] Preferably, the algorithm negotiated between the server and the client includes:

[0068] kex_algorithms sm2-sm3,

[0069] server_host_key_algorithms sm2,

[0070] encryption_algorithms_client_to_server sm4-ctr,

[0071] encryption_algorithms_server_to_client,

[0072] mac_algorithms_client_to_server hmac-sm3

[0073] and mac_algorithms_server_to_client.

[0074] In a second aspect of the present invention, an SSH communication system based on a national encryption algorithm is proposed, the system comprising: a server and a client; the server and the client perform login authentication according to the above method.

[0075] According to a third aspect of the present invention, a computer-readable storage medium is provided, storing a computer program that can be loaded by a processor and execute the method described above.

[0076] The present invention has the following beneficial effects:

[0077] In the present invention, the server and the client first generate a pair of SM2 public and private keys respectively, and exchange public keys; then the server and the client generate a shared key based on the other party's SM2 public key and their own SM2 private key, and then generate an SM4 session key. The present invention creatively implements SSH session identity authentication based on the national secret SM2 key pair, solving the problem of non-compliance and low security of traditional SSH identity authentication methods in commercial password evaluation.

[0078] In addition, when the present invention uses a preset hash value calculation method to generate the first hash value and the second hash value, the f and e values ​​in the formula reuse the public keys x and y generated before calculating the shared key, and no new temporary key is generated, thereby saving calculation time. BRIEF DESCRIPTION OF THE DRAWINGS

[0079] Figure 1 It is a schematic diagram of the main steps of an embodiment of an SSH login authentication method based on a national secret algorithm in the present invention;

[0080] Figure 2 This is a schematic diagram of information transmission between the client and the server during the login authentication process when the public-private key authentication method is adopted in an embodiment of the present invention;

[0081] Figure 3 It is a schematic diagram of information transmission between the client and the server during the login authentication process when the password authentication method is adopted in the embodiment of the present invention. DETAILED DESCRIPTION

[0082] The preferred embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the protection scope of the present invention.

[0083] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0084] It should be noted that, in the description of the present invention, the terms "first" and "second" are only for the convenience of description, and do not indicate or imply the relative importance of the devices, elements or parameters, and therefore cannot be understood as limiting the present invention. In addition, the term "and / or" in the present invention is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally indicates that the associated objects before and after are in an "or" relationship.

[0085] Figure 1 Schematic diagram of the main steps of the SSH login authentication method embodiment based on the national secret algorithm in the present invention. Figure 1 As shown, the SSH login authentication method of this embodiment includes steps S10-S70:

[0086] Step S10: The server accepts the SSH connection request from the client and establishes a TCP connection.

[0087] Step S20: The server and the client negotiate the SSH protocol version number.

[0088] The negotiation version number message includes: protocol version number, sub-protocol version number and software version number.

[0089] Specifically, the server sends the first message to the client, including a version flag string, such as SSH-2.0-OpenSSH_8.8; after receiving the message, the client parses the protocol version number. If the server's protocol version number is lower than its own and the client can support the lower version of the server, it uses the server's protocol number, otherwise it uses its own protocol version number, such as OpenSSH_8.7; the client replies to the server with a message, which includes the protocol version number that the client decides to use, such as OpenSSH_8.7; the server compares the version number sent by the client to decide whether it can interact with the client; if the negotiation is successful, it enters the algorithm negotiation phase, otherwise the server disconnects the TCP connection.

[0090] Step S30: The server and the client negotiate an algorithm.

[0091] Specifically, the server and client send algorithm negotiation messages to each other, which contain the public key algorithm list, encryption algorithm list, message authentication code algorithm list, and compression algorithm list supported by each other. The server and client determine the final algorithm to be used based on the algorithms supported by the other party and themselves. The algorithms involved in the negotiation include:

[0092] kex_algorithms sm2-sm3 (key exchange algorithms), server_host_key_algorithms sm2 (server host key algorithms), encryption_algorithms_client_to_server sm4-ctr (encryption algorithms used for client-to-server communication), encryption_algorithms_server_to_client (encryption algorithms used for server-to-client communication), mac_algorithms_client_to_server hmac-sm3 (hash algorithms in the client-to-server direction), and mac_algorithms_server_to_client (hash algorithms in the server-to-client direction).

[0093] Each algorithm type may have multiple different algorithms, which are separated by commas. The first algorithm in each algorithm type list must be the preferred algorithm, and the server should consider the client's algorithm priority. Negotiation fails until the same algorithm is matched.

[0094] Step S40: The server and the client generate a pair of SM2 public and private keys respectively, and exchange public keys. This step may specifically include steps S41-S42:

[0095] Step S41: The server generates a public key x and a private key x based on the SM2 algorithm, and sends the public key x and the host unique identifier host Key of the host to the client.

[0096] The host Key is generated based on the algorithm name and public key information describing the national secret SSH using the national secret SM3 hash algorithm. In this embodiment, the method shown in formula (1) is used:

[0097] host key=hash(algorithm name length||algorithm name||algorithm name length||algorithm name

[0098] ||Length of public key||public key) (1)

[0099] hash represents a hash function, which uses the SM3 algorithm. The algorithm name in the formula refers to SM3. The public key in the formula is the server's public key x.

[0100] Step S42: The client generates a public key y and a private key y based on the SM2 algorithm, and sends the public key y to the server.

[0101] Step S50: The server and the client generate a shared key based on the other party's public key and their own private key, and then generate an SM4 session key.

[0102] This step may specifically include steps S51-S55:

[0103] Step S51: The server calculates a first shared key based on the public key y and the private key x.

[0104] Step S52: The client calculates a second shared key according to the public key x and the private key y.

[0105] For the specific calculation method of the shared key, please refer to "GM / T 0003.3-2012 SM2 Elliptic Curve Public Key Cryptography Algorithm" Part 3: Key Exchange Protocol.

[0106] Step S53: The server generates a first hash value using a preset hash value calculation method, generates a signature based on the SM2 algorithm according to the private key x and the first hash value, and sends it to the client.

[0107] Step S54: The client generates a second hash value using a preset hash value calculation method, and performs a signature verification operation based on the SM2 algorithm according to the public key y and the second hash value.

[0108] If the verification is consistent, it means that the key exchange is successful. The client sends a new key to the server, marking the end of the key exchange process. If this key exchange is the first exchange of the entire session, the calculated H is also the session ID (session_id) of the entire session.

[0109] For the specific implementation of the signature algorithm, please refer to "GM / T 0003.2-2012 SM2 Elliptic Curve Public Key Cryptography Algorithm" Part 2: Digital Signature Algorithm.

[0110] Step S55: The server and the client calculate the SM4 session key according to the following formula (2):

[0111] SecKey = hash (K||H||C||session_id) (2)

[0112] Among them, hash represents a hash function, which adopts the SM3 algorithm; || represents concatenation; K represents the first shared key or the second shared key; H represents the first hash value or the second hash value; C represents the uppercase ASCII letter 'A', 'B', 'C', 'D', 'E' or 'F'.

[0113] When C is 'A', the calculated SM4 session key will be used as the initialization vector from the client to the server; when C is 'B', the calculated SM4 session key will be used as the initialization vector from the client to the server; when C is 'C', the calculated SM4 session key will be used as the encryption key from the client to the server; when C is 'D', the calculated SM4 session key will be used as the encryption key from the server to the client; when C is 'E', the calculated SM4 session key will be used as the integrity key from the client to the server; when C is 'F', the calculated SM4 session key will be used as the integrity key from the server to the client; session_id represents the H value generated when the client and the server are connected for the first time.

[0114] During the cryptographic negotiation process, the key negotiation algorithm initiator identifier ida and responder identifier idb are as shown in the following formulas (3) and (4) respectively:

[0115] ida := []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8} (3)

[0116] idb := []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8} (4)

[0117] After completing step S50, both parties have the negotiated algorithm and the SM4 session key for encryption and decryption, and all data transmitted from now on must be encrypted (including the total length).

[0118] During the encrypted communication process, both parties are allowed to resend the KEX key exchange request. At this time, the data of the entire key exchange process will be encrypted and decrypted using the existing SM4 session key. An H value will also be generated during this key exchange, but this H value will not affect the session_id of this session. The session_id is only the H value generated by the first key exchange of the session. When the client sends a new keys request at the end of the key exchange, both parties will abandon the currently used key and continue to communicate using the newly negotiated key.

[0119] Step S60: The client sends a login request to the server, and the login request is encrypted using the SM4 session key.

[0120] When the authentication method is public-private key authentication, the login request includes: user account, authentication method and public key z. In this step, the client first generates the user public key z and private key z based on the SM2 algorithm, and sends the user public key z to the server, and then uses the SM4 session key to encrypt the login request with the SM4 algorithm and sends it to the server.

[0121] In this embodiment, the "ssh-keygen -t sm2" program is first used to generate the public key id_sm2.pub and the private key id_sm2 (i.e., public key z and private key z). Generally, they are generated on the client, and then id_sm2.pub is sent to the server in some way. The server puts it in the .ssh directory of the directory of the account to be logged in remotely.

[0122] When the authentication method is password authentication, the login request includes: user account, authentication method and user password. In this step, the client uses the SM4 session key to encrypt the login request with the SM4 algorithm and then directly sends it to the server.

[0123] Step S70: The server uses the SM4 session key to decrypt the login request and authenticate the client.

[0124] When the authentication method is a public-private key authentication method, step S70 may specifically include steps S71-S77:

[0125] Step S71: The server uses the SM4 session key to decrypt the login request using the SM4 algorithm to obtain the user account, authentication method and public key z.

[0126] Step S72: The server verifies the received public key z using the stored public key z.

[0127] Specifically, the server searches for the corresponding public key in the .ssh directory of the directory corresponding to the client account. If not found, a failure message is sent to the client. If found, the server compares the public key z sent by the client with the found public key. If the contents are the same, step S73 is executed.

[0128] Step S73: The server generates a random string, encrypts it using the public key z, and encrypts it again using the SM4 algorithm using the SM4 session key before sending it to the client.

[0129] Step S74: The client uses the SM4 session key to perform SM4 algorithm decryption on the received message, and uses the private key z to decrypt the data again to obtain a challenge.

[0130] Step S75: The client uses the SM4 session key to encrypt the challenge using the SM4 algorithm and sends it to the server.

[0131] Step S76: The server uses the SM4 session key to perform SM4 algorithm decryption on the received message to obtain a challenge returned by the client.

[0132] Step S77: The server determines whether the challenge returned by the client matches the random string generated in step S73, thereby determining whether the authentication is successful.

[0133] When the authentication method is password authentication, step S70 may specifically include steps S78-S79:

[0134] Step S78: The server uses the SM4 session key to decrypt the login request using the SM4 algorithm to obtain the user account, authentication method, and user password.

[0135] Step S79: The server verifies the user account and password based on the pre-stored account and password to determine whether the authentication is successful.

[0136] Figure 2 It is a schematic diagram of information transmission between the client and the server during the login authentication process when the public-private key authentication method is adopted in an embodiment of the present invention. Figure 3 Schematic diagram of information transmission between the client and the server during the login authentication process when the password authentication method is adopted in the embodiment of the present invention. The difference between the two authentication methods in the above steps S60 and S70 can be found in Figure 2 and Figure 3 .

[0137] In an optional embodiment, the preset hash value calculation method used in steps S53 and S54 may be a method as shown in the following formula (5):

[0138] H = hash(V_C || V_S || I_C || I_S || K_S || e || f || K) (5)

[0139] Among them, hash represents a hash function, using the SM3 algorithm; || represents concatenation; V_C represents the version number sent by the client to the server during the version negotiation phase; V_S represents the version number sent by the server to the client during the version negotiation phase; I_C represents the payload of the SSH_MSG_KEX_INIT message sent by the client during the algorithm negotiation phase; I_S represents the payload of the SSH_MSG_KEX_INIT message sent by the server during the algorithm negotiation phase; K_S represents the host key public key of the host where the server is located; e represents the public key y generated by the client; f represents the public key x generated by the server; K represents the first shared key or the second shared key.

[0140] In this embodiment, when generating the first hash value and the second hash value, the values ​​f and e in formula (3) reuse the keys x and y generated in steps S41 and S42, and no new temporary key is generated, thereby saving calculation time.

[0141] Although the various steps in the above embodiment are described in the above-mentioned order, those skilled in the art can understand that in order to achieve the effect of this embodiment, different steps do not have to be executed in such an order. They can be executed simultaneously (in parallel) or in a reverse order. These simple changes are within the scope of protection of the present invention.

[0142] Based on the same technical concept as the above method embodiment, the present invention also provides an embodiment of an SSH communication system based on a national secret algorithm, and the communication system of this embodiment includes: a server and a client. The server and the client perform login authentication according to the above method.

[0143] Furthermore, the present invention also provides an embodiment of a computer-readable storage medium. The storage medium of this embodiment stores a computer program that can be loaded by a processor and execute the method described above.

[0144] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0145] Those skilled in the art should be able to appreciate that the method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of electronic hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in electronic hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0146] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.

Claims

1. An SSH login authentication method based on a national secret algorithm, characterized in that: The method comprises: The server accepts the SSH connection request from the client and establishes a TCP connection; The server negotiates the SSH protocol version number with the client; The server negotiates an algorithm with the client; The server and the client generate a pair of SM2 public and private keys respectively, and exchange public keys; The server and the client generate a shared key based on the other party's public key and their own private key, and then generate an SM4 session key; The client sends a login request to the server, where the login request is encrypted using the SM4 session key; The server uses the SM4 session key to decrypt the login request and authenticate the client; in, The step of "the server and the client respectively generate a pair of SM2 public and private keys, and exchange public keys" includes: The server generates a public key x and a private key x based on the SM2 algorithm, and sends the public key x and the host unique identifier Host Key of the host to the client; wherein the Host Key is generated using the national secret SM3 hash algorithm based on the algorithm name and public key information describing the national secret SSH; The client generates a public key y and a private key y based on the SM2 algorithm, and sends the public key y to the server; The step of "the server and the client generate a shared key according to the other party's public key and their own private key, and then generate an SM4 session key" includes: The server calculates a first shared key according to the public key y and the private key x; The client calculates a second shared key according to the public key x and the private key y; The server generates a first hash value by using a preset hash value calculation method, generates a signature based on the SM2 algorithm according to the private key x and the first hash value, and sends the signature to the client; The client generates a second hash value by using the preset hash value calculation method, and performs a signature verification operation based on the SM2 algorithm according to the public key y and the second hash value; The server and the client calculate the SM4 session key according to the following formula: SecKey=hash(K||H||C||session_id); in, hash represents the hash function, which uses the SM3 algorithm; || indicates splicing; K represents the first shared key or the second shared key; H represents the first hash value or the second hash value; C represents an uppercase ASCII letter 'A', 'B', 'C', 'D', 'E', or 'F'; When C is 'A', the calculated SM4 session key will be used as the initialization vector from the client to the server; When C is 'B', the calculated SM4 session key will be used as the initialization vector from the client to the server; When C is 'C', the calculated SM4 session key will be used as the encryption key from the client to the server; When C is 'D', the calculated SM4 session key will be used as the encryption key from the server to the client; When C is 'E', the calculated SM4 session key will be used as the integrity key from the client to the server; When C is 'F', the calculated SM4 session key will be used as the integrity key from the server to the client; session_id represents the H value generated when the client connects to the server for the first time; The preset hash value calculation method is: H=hash(V_C||V_S||I_C||I_S||K_S||e||f||K); in, hash represents the hash function, which uses the SM3 algorithm; || indicates splicing; V_C represents the version number sent by the client to the server during the version negotiation phase; V_S represents the version number sent by the server to the client during the version negotiation phase; I_C represents the payload of the SSH_MSG_KEX_INIT message sent by the client during the algorithm negotiation phase; I_S represents the payload of the SSH_MSG_KEX_INIT message sent by the server during the algorithm negotiation phase; K_S represents the host key public key of the host where the server is located; e represents the public key y generated by the client; f represents the public key x generated by the server; K represents the first shared key or the second shared key; The algorithm negotiated between the server and the client includes: kex_algorithms sm2-sm3, server_host_key_algorithms sm2, encryption_algorithms_client_to_server sm4-ctr, encryption_algorithms_server_to_client, mac_algorithms_client_to_server hmac-sm3 and mac_algorithms_server_to_client.

2. The SSH login authentication method based on the national secret algorithm according to claim 1 is characterized in that: The authentication method is public-private key authentication; The step of "the client sends a login request to the server, and the login request is encrypted using the SM4 session key" includes: The client generates a user public key z and a private key z based on the SM2 algorithm, and sends the user public key z to the server; The client sends a login request to the server, wherein the login request includes: a user account, the authentication method and the public key z, and is encrypted using the SM4 algorithm using the SM4 session key.

3. The SSH login authentication method based on the national secret algorithm according to claim 2 is characterized in that: The step of "the server uses the SM4 session key to decrypt the login request and authenticate the client" includes: The server uses the SM4 session key to perform SM4 algorithm decryption on the login request to obtain the user account, the authentication method and the public key z; The server verifies the received public key z using the stored public key z; The server generates a random string, encrypts it using the public key z, and encrypts it again using the SM4 algorithm using the SM4 session key before sending it to the client; The client uses the SM4 session key to perform SM4 algorithm decryption on the received message, and uses the private key z to decrypt the data again to obtain a challenge; The client uses the SM4 session key to encrypt the challenge using the SM4 algorithm and sends it to the server; The server uses the SM4 session key to perform SM4 algorithm decryption on the received message to obtain the challenge; The server determines whether the challenge matches the random string, thereby determining whether the authentication is successful.

4. The SSH login authentication method based on the national secret algorithm according to claim 1 is characterized in that: The authentication method is password authentication; The login request includes: user account, authentication method and user password; The step of "the server uses the SM4 session key to decrypt the login request and authenticate the client" includes: The server uses the SM4 session key to perform SM4 algorithm decryption on the login request to obtain the user account, the authentication method and the user password; The server verifies the user account and the user password according to the pre-stored account and password to determine whether the authentication is successful.

5. An SSH communication system based on a national secret algorithm, characterized in that: The system comprises: a server and a client; the server and the client perform login authentication according to the method described in any one of claims 1-4.

6. A computer-readable storage medium, characterized in that: A computer program is stored which can be loaded by a processor and execute the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Method and system for achieving SSH protocol based on post-quantum key exchange

    CN108111301A

  • Method for realizing secure transmission of data based on SM2-SM3-SM4 cryptographic algorithm

    CN113572741A

  • Multi-factor SSH login authentication method based on national cryptographic algorithm and supporting bidirectional authentication

    CN118174921A

  • A password authenticated key exchange method using the rsa

    KR1020100024605A