Disclosure of Invention
The technical problem to be solved by the present invention is to provide a method for implementing an SSH protocol based on post-quantum key exchange and a system for implementing an SSH protocol based on post-quantum key exchange, which use quantum cryptography theory knowledge to achieve the purpose of resisting quantum computer attacks and ensure network security, in order to overcome the above-mentioned disadvantages in the prior art.
The technical scheme adopted for solving the technical problem of the invention is that the method for realizing the SSH protocol based on the post-quantum key exchange comprises a key exchange step, wherein the key exchange step comprises the following steps:
the client and the server randomly sample from the Gaussian distribution of the first parameter, and respectively calculate a public and private key pair of the client and a public and private key pair of the server;
the client randomly samples from the Gaussian distribution of the second parameter, calculates a client temporary session public key, and sends the client public key and the client temporary session public key to the server;
the server receives the client public key and the client temporary session public key, performs identity verification on the client, and if the verification fails, the server directly disconnects the link, otherwise performs the next step;
calculating a server temporal session public key from the random sampling on the gaussian distribution of the second parameter;
the server calculates a server temporary session variable and a temporary session error-eliminating variable according to the client temporary session public key, the client vector, the server temporary session public key, the server vector and the random sampling of the server on the Gaussian distribution of the first parameter and the second parameter, and further calculates a server shared key initial seed according to the server temporary session variable and the temporary session error-eliminating variable;
the server generates a final server shared key of the session by using a post-quantum algorithm according to the client vector, the server vector, the client temporary session public key, the server temporary session public key, the temporary session error-eliminating variable and the initial seed of the server shared key;
the client performs identity authentication on the server according to the server public key;
the client side calculates a client side temporary session variable according to a client side temporary session public key, a client side vector, a server temporary session public key and random sampling of the client side on Gaussian distribution of a first parameter and a second parameter through identity authentication of a server, and further calculates a client side shared key initial seed according to the client side temporary session variable and a temporary session error-eliminating variable;
the client generates a final client shared key of the session by using a post-quantum algorithm according to the client vector, the server vector, the client temporary session public key, the server temporary session public key, the temporary session error-eliminating variable and the client shared key initial seed;
and if the authentication of either the server or the client can not be passed, the key exchange is terminated.
Preferably, the server temporary session public key ksComprises the following steps:
ks=(pcc+x)(ssd+rs)+2gs
wherein:
c=H1(client, server, x), which is a client vector;
x=arc+2fca client side temporary session public key;
rciand fciGaussian distribution χ of beta from second parameter for clientβQ is a positive integer;
d=H1(server, client, y, x), which is a server vector;
y=ars+2fsa server temporary session public key;
rsi,fsi,gsifor server from the Gaussian distribution χ with second parameter ββQ is a positive integer;
pc=asc+2ecis a client public key;
sciand eciFrom the first parameter of the client to the alpha Gaussian distribution xαA random sampling value of (1), q is a positive integer, scStill the client private key;
and the temporary session error-elimination variable w is:
w=Cha(ks)
wherein: cha () is a feature correlation function.
Preferably, according to (w, y, p)s) Server shared secret key initial seed sigmasComprises the following steps:
σs=Mod2(ks,w)
wherein: mod
2() Modulo-2 function, Mod
2(v,w)=(v+w·(q-1)/2)mod q mod 2,q mod 2n=1,
Unit matrix
v∈M
q,w∈{0,1};
Server shared secret sksComprises the following steps:
sks=H(client,server,x,y,w,σs)。
preferably, the client temporary session variable kcComprises the following steps:
kc=(psd+y)(scc+rc)+2gc
wherein:
gcifor server from the Gaussian distribution χ with second parameter ββQ is a positive integer;
ps=ass+2esis a server public key;
ssiand esiFor the server, from the first parameter of alpha Gaussian distribution xαA random sampling value of (1), q is a positive integer, ssStill the server private key.
Preferably, according to (w, y, p)s) Client sharing key initial seed sigmacComprises the following steps:
σc=Mod2(kc,w)
wherein: mod
2() Modulo-2 function, Mod
2(v,w)=(v+w·(q-1)/2)mod q mod 2,q mod 2n=1,
Unit matrix
v∈M
q,w∈{0,1};
Client shared secret skcComprises the following steps:
skc=H(client,server,x,y,w,σc)。
preferably, before the key exchanging step, the method further comprises: the step of verifying the credible states of the two communication parties comprises the following steps:
sending a request for verifying the credible state of the client to a server;
after receiving a request of a client, a server randomly generates a first random number with M bits, and sends the first random number and a request for verifying the self credibility state to the client, wherein M is a natural number;
after receiving the first random number and the verification request, the client correspondingly generates an M-bit second random number, measures the integrity of the trusted request, encrypts the first random number, the configuration register value and the measurement log SML, and sends an encryption result, the second random number and the TPM public key to the server;
after receiving the data, the server judges whether the client is the first client requesting to establish SSH connection, if so, checks whether a trusted certificate exists locally, and if so, directly performs the next step; otherwise, the integrity measurement is requested to the local machine credibility, then the second random number, the configuration register value of the second random number and the measurement log SML are encrypted, and the encryption result and the TPM public key are sent to the client side together;
the server verifies the credibility state of the client according to the data sent by the client, if the client passes the verification, a credibility verification passing certificate is generated, the certificate comprises the client IP, the unique identifier of the client, the IP and the identifier of the local server, the time for generating the certificate and the validity period of the certificate, the TPM public key sent by the client is used for encryption, and the encryption result and the verification passing information are sent to the client together;
after the client receives the data, the client verifies the credible state of the server, if the verification is passed, the client also generates a credible certificate, the content comprises the server IP, the unique identifier of the server, the IP and the identifier of the local client, the time for generating the certificate and the validity period of the certificate, the TPM public key sent by the server is used for encryption, and the encryption result and the verification passing information are sent to the server together;
after receiving the trusted voucher, the server decrypts the trusted voucher by using the TPM private key of the server and stores the trusted voucher in the local area, so that the trusted states of the server and the server pass verification, and otherwise, the server is directly disconnected.
A system for realizing SSH protocol based on post-quantum key exchange comprises a key exchange module, wherein the key exchange module comprises a first key unit, a second key unit, a first verification unit and a second verification unit, wherein:
the first key unit is located in the server and used for completing the following functions:
randomly sampling from the Gaussian distribution of the first parameter, and calculating a public and private key pair of the server;
after the first verification unit passes the identity authentication of the client, calculating a server temporary session public key from random sampling on Gaussian distribution of a second parameter;
calculating a server temporary session variable and a temporary session error-eliminating variable according to the client temporary session public key, the client vector, the client temporary server vector and the random sampling of the server on the Gaussian distribution of the first parameter and the second parameter;
calculating a server shared key initial seed according to the server temporary session variable and the temporary session error-eliminating variable;
generating a final server shared key of the session by using a post-quantum algorithm according to the client vector, the server vector, the client temporary session public key, the server temporary session public key, the temporary session error-eliminating variable and the initial seed of the server shared key;
the first verification unit is positioned in the server and used for receiving the client public key and the client temporary session public key and verifying the identity of the client, if the verification cannot pass, the server directly disconnects the link, otherwise, the server performs subsequent authentication;
the second key unit is located at the client and used for completing the following functions:
randomly sampling from the Gaussian distribution of the first parameter, and calculating a public-private key pair of the client;
randomly sampling from the Gaussian distribution of the second parameter, calculating a client temporary session public key, and sending the client public key and the client temporary session public key to a server;
after the second verification unit passes the identity authentication of the server, calculating a client temporary session variable according to the client temporary session public key, the client vector, the server temporary session public key and the random sampling of the client on the Gaussian distribution of the first parameter and the second parameter, and further calculating a client shared key initial seed according to the client temporary session variable and the temporary session error-eliminating variable;
generating a final server shared key of the session by using a post-quantum algorithm according to the client vector, the server vector, the client temporary session public key, the server temporary session public key, the temporary session error-eliminating variable and the client shared key initial seed;
and the second verification unit is positioned at the client and used for verifying the identity of the server according to the server public key, terminating the key exchange if the verification cannot pass, and otherwise, performing subsequent authentication.
Preferably, in the first key unit:
server temporary session public key ksComprises the following steps:
ks=(pcc+x)(ssd+rs)+2gs
wherein:
c=H1(client, server, x), which is a client vector;
x=arc+2fca client side temporary session public key;
rciand fciGaussian distribution χ of beta from second parameter for clientβQ is a positive integer;
d=H1(server, client, y, x), which is a server vector;
y=ars+2fsa server temporary session public key;
rsi,fsi,gsifor server from the Gaussian distribution χ with second parameter ββQ is a positive integer;
pc=asc+2ecis a client public key;
sciand eciFrom the first parameter of the client to the alpha Gaussian distribution xαA random sampling value of (1), q is a positive integer, scStill the client private key;
and the temporary session error-elimination variable w is:
w=Cha(ks)
wherein: cha () is a feature correlation function;
according to (w, y, p)s) Server shared secret key initial seed sigmasComprises the following steps:
σs=Mod2(ks,w)
wherein: mod
2() Modulo-2 function, Mod
2(v,w)=(v+w·(q-1)/2)mod q mod 2,q mod 2n=1,
Unit matrix
v∈M
q,w∈{0,1};
Server shared secret sksComprises the following steps:
sks=H(client,server,x,y,w,σs)。
preferably, in the second key unit,
client temporary session variable kcComprises the following steps:
kc=(psd+y)(scc+rc)+2gc
wherein:
gcifor server from the Gaussian distribution χ with second parameter ββQ is a positive integer;
ps=ass+2esis a server public key;
ssiand esiFor the server, from the first parameter of alpha Gaussian distribution xαA random sampling value of (1), q is a positive integer, ssStill the server private key;
and, according to (w, y, p)s) Client sharing key initial seed sigmacComprises the following steps:
σc=Mod2(kc,w)
wherein: mod
2() Modulo-2 function, Mod
2(v,w)=(v+w·(q-1)/2)mod q mod 2,q mod 2n=1,
Unit matrix
v∈M
q,w∈{0,1};
Client shared secret skcComprises the following steps:
skc=H(client,server,x,y,w,σc)。
preferably, the system further comprises a verification trusted module to verify the trusted status of the two communication parties, where the verification trusted module includes a first trusted unit located in the server and a second trusted unit located in the client, and is configured to perform the following functions:
the second trusted unit sending a request to verify a client trusted status to the first trusted unit;
after receiving a request of a client, the first trusted unit randomly generates an M-bit first random number, and sends the first random number and a request for verifying the trusted state of the first trusted unit to the second trusted unit, wherein M is a natural number;
after receiving the first random number and the verification request, the second trusted unit correspondingly generates an M-bit second random number, then requests the TPM for integrity measurement, encrypts the first random number, the configuration register value and the measurement log SML, and sends an encryption result, the second random number and the TPM public key to the first trusted unit;
after receiving the data, the first trusted unit judges whether the client is the first client requesting to establish SSH connection, if so, checks whether a trusted certificate exists locally, and if so, directly performs the next step; otherwise, the integrity measurement is requested to the local trust, then the second random number, the configuration register value of the second random number and the measurement log SML are encrypted, and the encryption result and the TPM public key are sent to the second trust unit;
the first trusted unit verifies the trusted state of the client according to the data sent by the second trusted unit, if the verification is passed, a trusted verification passing certificate is generated, the certificate comprises a client IP, a client unique identifier, an IP and an identifier of a local server, time for generating the certificate and a certificate validity period, and is encrypted by using a TPM public key sent by the client, and an encryption result and verification passing information are sent to the client together;
after the client receives the data, the trusted state of the server is verified, if the data passes the verification, the second trusted unit also generates a trusted certificate, the content comprises a server IP, a server unique identifier, an IP and an identifier of the local client, the time for generating the certificate and the certificate validity period, the TPM public key sent by the server is used for encryption, and the encryption result and the verification passing information are sent to the first trusted unit together;
and after receiving the trusted credential, the first trusted unit decrypts the trusted credential by using the TPM private key of the first trusted unit and stores the trusted credential in the local area, so that the trusted states of the first trusted unit and the trusted unit pass verification, and otherwise, the first trusted unit and the trusted unit are directly disconnected.
The invention has the beneficial effects that: according to the method for realizing the SSH protocol based on the post-quantum key exchange and the system for realizing the SSH protocol based on the post-quantum key exchange, the post-quantum key exchange protocol and the credible authentication method are used for solving some potential threats of the SSH protocol. The post-quantum key exchange protocol can solve the problem that the shared key at the key exchange stage in the current SSH protocol is possibly broken, and the trusted authentication can solve the problem that platforms of two parties using the SSH protocol for communication are not trusted.
Detailed Description
In order to make those skilled in the art better understand the technical solution of the present invention, the following describes in detail a method for implementing an SSH protocol based on post-quantum key exchange and a system for implementing an SSH protocol based on post-quantum key exchange according to the present invention with reference to the accompanying drawings and the detailed description.
The technical idea of the invention is as follows: until now, the improvement of the SSH protocol at present is the improvement by using the modern cryptography technology, and the improvement by using the quantum cryptography technology is not involved. The present invention utilizes quantum cryptography to improve the above-mentioned technical problems. The quantum algorithm can solve the discrete logarithm problem in polynomial time, and ensures the states of two communication parties to be credible before SSH connection is established, so as to take the safety and credibility of the SSH protocol into account.
The invention provides an improved method for trusted SSH protocol authentication based on a post-quantum key exchange algorithm. After the trusted verification passes, SSH utilizes a post quantum key exchange algorithm to complete a key agreement stage and a two-party identity authentication stage between a client and a remote server, and the changed users do not need to care about a bottom layer implementation principle and change a previous login method. The method has the advantages of strong user transparency, high speed, simple and easily understood algorithm, and capability of providing the function of the post-quantum computer on the one hand, namely preventing the shared secret key generated by both communication parties from being broken by the quantum computer on the premise of not reducing the original SSH remote login security; on the other hand, the trusted status of both the client and the server can be verified.
Example 1:
the embodiment provides a method for realizing an SSH protocol based on post-quantum key exchange, which can effectively prevent a shared key generated by a communication client and a server from being broken by a quantum computer; on the other hand, the trusted status of both the client and the server can be verified.
The protocol structure of the improved SSH scheme is a three-layer architecture specified in the current SSH protocol, and the specific protocol architecture refers to fig. 1. The SSH comprises a transmission layer, user authentication and connection establishment from bottom to top in sequence, and the session establishment process comprises version negotiation, algorithm negotiation and key negotiation, user authentication and connection request.
Currently, the flow of telnet between two communicating parties using SSH protocol is shown in fig. 2.
First, version negotiation: the client and the server mutually send own protocol version number and software version number to carry out version negotiation so as to determine whether to continue the session, and the following steps are carried out after the version negotiation is successful. The information sent at this stage is transmitted in a plaintext mode;
and secondly, algorithm negotiation: the client and the server respectively send a public key algorithm list, an encryption algorithm list, a compression algorithm list and the like supported by the client and the server, and the client and the server negotiate various algorithms to be used finally in the session according to the algorithms supported by the client and the server. Wherein, although the key agreement algorithm can be agreed in theory, in practice, SSH must support DH algorithm only and only at present;
thirdly, key agreement: the client and the server negotiate a shared key using a DH key exchange algorithm. At this stage, the RSA algorithm and the SHA256 algorithm are required to assist, so that the probability of being broken is reduced;
fourthly, user authentication: the client sends the user password to the server in a ciphertext mode, and the server carries out validity authentication on the identity of the user;
step five, establishing connection: after the user authentication is successful, the client sends a session request, the server responds to the request type of the client, and the two parties establish connection for data transmission.
In the SSH protocol at the present stage, a DH algorithm is used for negotiating a key, and meanwhile, in order to prevent the key from being attacked by a man-in-the-middle, an RSA algorithm and an SHA256 algorithm are used for signature authentication so as to ensure the legality of the identities of two communication parties. The cooperative work of the algorithms ensures high security of the shared secret key. However, with the continuous approach of quantum era and the rapid development of computer technology, SSH will face huge challenges and risks.
Based on the above current situation, this embodiment provides an improved trusted SSH authentication scheme based on a post-quantum key exchange protocol, so that the SSH key exchange phase can resist attacks from a quantum computer, the security of SSH is improved, and the lifetime of SSH in the quantum era is extended. Particularly, based on the lattice theory of quantum cryptography, the complexity of the R-LWE (Ring-Learning With Errors) problem can be finally reduced to the lattice SVP (short Vectors Problem) problem, which has proven to be NP-difficult. Therefore, the authentication key exchange algorithm based on the R-LWE can well resist the attack of quantum computation, and has the advantages of high computation speed, easiness in understanding and the like.
In the method for implementing the SSH protocol based on post-quantum key exchange according to this embodiment, when the client establishes an SSH connection with the server, the two parties first send a Trusted certification request to the opposite end, then respectively send integrity measurement to their Trusted requests (TPM requests, Trusted Platform modules), and send related information to the opposite end and verify the Trusted status of the opposite end, and when both parties' Trusted statuses are verified, both parties start password negotiation. When key agreement is carried out, the two parties respectively carry out random sampling from Gaussian distribution with the same parameters, calculate own public and private key pairs, then send own public keys to the opposite terminal and receive the public keys of the opposite terminal, verify the identity of the opposite terminal, then calculate temporary public and private key pairs of the session and other needed variables, send data to the opposite terminal after calculation is finished, and simultaneously calculate own shared keys of the session. Therefore, the credible state of the terminal is ensured, the key negotiation process of resisting the quantum computer is realized, and the high-safety remote login process is provided.
As shown in fig. 3, the key exchange step in the method for implementing the SSH protocol based on post-quantum key exchange includes:
the client and the server randomly sample from the Gaussian distribution of the first parameter, and respectively calculate a public and private key pair of the client and a public and private key pair of the server;
the client randomly samples from the Gaussian distribution of the second parameter, calculates a client temporary session public key, and sends the client public key and the client temporary session public key to the server;
the server receives the client public key and the client temporary session public key, performs identity verification on the client, and if the verification fails, the server directly disconnects the link, otherwise performs the next step;
the server calculates a server temporary session public key from random sampling on Gaussian distribution of the second parameter through identity authentication of the client;
the server calculates a server temporary session variable and a temporary session error-eliminating variable according to the client temporary session public key, the client vector, the server temporary session public key, the server vector and the random sampling of the server on the Gaussian distribution of the first parameter and the second parameter, and further calculates a server shared key initial seed according to the server temporary session variable and the temporary session error-eliminating variable;
the server generates a final server shared key of the session by using a post-quantum algorithm according to the client vector, the server vector, the client temporary session public key, the server temporary session public key, the temporary session error-eliminating variable and the initial seed of the server shared key;
the client performs identity authentication on the server according to the server public key;
the client side calculates a client side temporary session variable according to a client side temporary session public key, a client side vector, a server temporary session public key and random sampling of the client side on Gaussian distribution of a first parameter and a second parameter through identity authentication of a server, and further calculates a client side shared key initial seed according to the client side temporary session variable and a temporary session error-eliminating variable;
the client generates a final client shared key of the session by using a post-quantum algorithm according to the client vector, the server vector, the client temporary session public key, the server temporary session public key, the temporary session error-eliminating variable and the client shared key initial seed;
and if the authentication of either the server or the client can not be passed, the key exchange is terminated.
On the server side, the server temporary session public key ksComprises the following steps:
ks=(pcc+x)(ssd+rs)+2gs
wherein:
c=H1(client, server, x) is a client vector, client is a client host, and server is a server host;
x=arc+2fca client side temporary session public key;
rciand fciGaussian distribution χ of beta from second parameter for clientβQ is a positive integer (e.g., q is 5); here, multiple sampling is performed, and the sum of the results of the multiple sampling is used as a result to increase the randomness of the sampling.
d=H1(server, client, y, x), which is a server vector;
y=ars+2fsa server temporary session public key;
rsi,fsi,gsifor server from the Gaussian distribution χ with second parameter ββQ is a positive integer (e.g., q is 5);
pc=asc+2ecis a client public key;
sciand eciFrom the first parameter of the client to the alpha Gaussian distribution xαQ is a positive integer (e.g., q is 5), and s is the random sample value of (1)cStill the client private key;
and the temporary session error-elimination variable w is:
w=Cha(ks)
wherein: cha () is a feature correlation function;
according to (w, y, p)s) Server shared secret key initial seed sigmasComprises the following steps:
σs=Mod2(ks,w)
wherein: mod
2() Modulo-2 function, Mod
2(v,w)=(v+w·(q-1)/2)mod q mod 2,q mod 2n=1,
Unit matrix
v∈M
q,w∈{0,1};
Server shared secret sksComprises the following steps:
sks=H(client,server,x,y,w,σs)。
at the client level, a client temporary session variable kcComprises the following steps:
kc=(psd+y)(scc+rc)+2gc
wherein:
gcifor server from the Gaussian distribution χ with second parameter ββThe random sample value of (a) above,q is a positive integer (e.g., q ═ 5);
ps=ass+2esis a server public key;
ssiand esiFor the server, from the first parameter of alpha Gaussian distribution xαQ is a positive integer (e.g., q is 5), and s is the random sample value of (1)sStill the server private key;
according to (w, y, p)s) Client sharing key initial seed sigmacComprises the following steps:
σc=Mod2(kc,w)
wherein: mod
2() Modulo-2 function, Mod
2(v,w)=(v+w·(q-1)/2)mod q mod 2,q mod 2n=1,
Unit matrix
v∈M
q,w∈{0,1};
Client shared secret skcComprises the following steps:
skc=H(client,server,x,y,w,σc)。
preferably, before the key exchanging step, the method further comprises: the step of verifying the credible states of the two communication parties comprises the following steps:
sending a request for verifying the credible state of the client to a server;
after receiving a request of a client, a server randomly generates a first random number with M bits, and sends the first random number and a request for verifying the self credibility state to the client, wherein M is a natural number;
after receiving the first random number and the verification request, the client correspondingly generates an M-bit second random number, measures the integrity of the trusted request, encrypts the first random number, the configuration register value and the measurement log SML, and sends an encryption result, the second random number and the TPM public key to the server;
after receiving the data, the server judges whether the client is the first client requesting to establish SSH connection, if so, checks whether a trusted certificate exists locally, and if so, directly performs the next step; otherwise, the integrity measurement is requested to the local machine credibility, then the second random number, the configuration register value of the second random number and the measurement log SML are encrypted, and the encryption result and the TPM public key are sent to the client side together;
the server verifies the credibility state of the client according to the data sent by the client, if the client passes the verification, a credibility verification passing certificate is generated, the certificate comprises the client IP, the unique identifier of the client, the IP and the identifier of the local server, the time for generating the certificate and the validity period of the certificate, the TPM public key sent by the client is used for encryption, and the encryption result and the verification passing information are sent to the client together;
after the client receives the data, the client verifies the credible state of the server, if the verification is passed, the client also generates a credible certificate, the content comprises the server IP, the unique identifier of the server, the IP and the identifier of the local client, the time for generating the certificate and the validity period of the certificate, the TPM public key sent by the server is used for encryption, and the encryption result and the verification passing information are sent to the server together;
after receiving the trusted voucher, the server decrypts the trusted voucher by using the TPM private key of the server and stores the trusted voucher in the local area, so that the trusted states of the server and the server pass verification, and otherwise, the server is directly disconnected.
The following will describe in detail the process of establishing an SSH remote connection of the method for implementing an SSH protocol based on post-quantum key exchange in this embodiment, and the method is divided into six steps:
the first step is as follows: and (4) version negotiation.
Before version negotiation, the two parties firstly establish a TCP connection: a TCP request connection is sent by the client to the server.
After the TCP connection is successfully established, the client enters a waiting phase. The server sends a first message to the client, and the message content is an SSH protocol version number and a software version number. The protocol version number comprises a major version number and a minor version number, and the message content is as follows:
"SSH- < major protocol version number > < minor protocol version number > - < software version number > \\ n"
After receiving the message, the client returns a message to the server, the content is the relevant version number of the client, and the format of the content is consistent with that of the message sent by the server.
And after receiving the version number sent by the client, the server compares the version number with the version number of the server to determine whether the version number is compatible. If not, directly disconnecting TCP, if compatible, the server generates a number to identify the client as the host of the SSH connection with the client, and then enters the next stage.
The second step is that: and (5) verifying the credibility.
Trusted verification of both parties to the communication starts from system power-on start up until the last application, and each step in between measures and extends the measure values into a PCR (Platform configuration Register). Meanwhile, the two parties also store the measurement operation, the measurement result and the intermediate states of each step into a storage measurement log SML (storage Measure Log).
The detailed flow of verifying the trusted status of the two communication parties is shown in fig. 4, and is specifically described as follows:
1, a client firstly sends a request for verifying the trusted state of the client to a server;
2, after receiving a request from a client, the server randomly generates a first random number RandNum1 with M bits (M is a natural number and is generally 160), and then sends the first random number and a request for verifying the self-trusted state to the client;
3 after receiving the first random number and the verification request, the client side preferably generates a second random number RandNum2 with M bits randomly and correspondingly, then requests the TPM for integrity measurement, encrypts the first random number RandNum1, the PCR value and the measurement log SML, and finally sends the encryption result, the second random number RandNum2 and the TPM public key to the server;
4, after receiving the data, the server firstly judges whether the client is the first client requesting to establish SSH connection, if so, checks whether a trusted certificate exists locally, and if so, directly performs the next step; otherwise, the integrity measurement is requested to the local TPM, then the random number RandNum2, the PCR value of the random number RandNum2 and the measurement log SML are encrypted, and the encryption result and the TPM public key are sent to the client side;
the server verifies the credibility state of the client according to the data sent by the client, if the client passes the verification, a credibility verification passing certificate is generated, the certificate comprises the client IP, the unique identifier of the client, the IP and the identifier of the local server, the time for generating the certificate and the validity period of the certificate, the information is encrypted by using the TPM public key sent by the client, and the encrypted result and the verification passing information are sent to the client together;
after receiving the data, the client verifies the credibility state of the server, and similarly, if the verification is passed, the client also generates a credibility certificate, the content comprises the server IP, the unique identifier of the server, the IP and the identifier of the local client, the time for generating the certificate and the validity period of the certificate, the TPM public key sent by the server is used for encrypting the information, and the encrypted result and the information passing the verification are sent to the server together;
and 7, after receiving the trusted certificate, the server decrypts the trusted certificate by using the TPM private key of the server and stores the trusted certificate in the local. At this time, the trusted states of both parties pass the verification, and the following steps can be carried out, otherwise, the connection is directly disconnected.
The third step: and (4) negotiating an algorithm.
Due to the flexibility of SSH design, SSH can negotiate a wide variety of algorithms, such as data encryption algorithms, key exchange algorithms, compression algorithms, authentication algorithms, and integrity check algorithms. The client and the server send algorithm lists supported by the client and the server to the opposite terminal, the first algorithm of each algorithm type list is a preferred algorithm, and the server takes the algorithm priority of the client as consideration. If there is no algorithm in common for both parties of a certain algorithm type, the session will terminate.
The key agreement is completed by using the post-quantum authentication key exchange algorithm based on the R-LWE, so that the post-quantum authentication key exchange algorithm based on the R-LWE is set as a preferred algorithm of the key agreement.
The fourth step: and (4) key agreement.
The whole key exchange process is mainly divided into three steps, data is exchanged twice, and the flow can refer to fig. 3.
To facilitate the description of the entire process of key exchange, the following parameters are defined:
n is a safety parameter and must be a power of 2, and the function f (x) xn+1;
q is an odd prime number, with the definition of q 2w(logn);
Definition of R ═ Z [ x]/< f (x) >, which is Z [ x ]]A ring of all polynomials modulo f (x) above, defining R analogouslyq=Zq[x]/<f(x)>。
Function H1Is defined as shown in formula (1-1):
the function H can be seen from the formula (1-1)
1Is operative to map a character string to
A sampling result χ of
γWhere γ is a positive real number. The function H is defined as H: {0,1}
*→{0,1}
kThe key generation function is a key generation function, generally a hash function, and different numbers of bits of keys can be obtained by using different hash functions.
The following is a detailed description of the overall process of key exchange:
1, the client firstly generates a public and private key pair of the client: from the first parameterIs alpha Gaussian distribution χαUp-sampling randomly to obtain scAnd ecThen calculate pc=asc+2ecAfter the calculation is successful, s is calculatedcAnd pcAs their own private and public keys, respectively, i.e. client-side private key scAnd client public key pcAnd both are stored locally. It should be understood here that the present embodiment adopts gaussian distribution to achieve the purpose of resisting quantum computer attack, and the following calculation formulas correspond to gaussian distribution.
2, the server firstly generates a public-private key pair of itself: gaussian distribution χ of α from the same first parameter as the clientαUp-random sampling and calculating to obtain ssAnd esAnd calculate ps=ass+2esAfter the calculation is successful, s is calculatedsAnd psAs their own private and public keys, respectively, i.e. server private key ssAnd server public key psAnd stores both locally. This phase may be performed simultaneously with the client.
3 after the client successfully generates the own public and private key pair, the second parameter is the Gaussian distribution χ of betaβR is obtained by up-random multiple sampling calculationcAnd fcCalculating client-side temporary session public key x ═ arc+2fcFinally, the calculation results, namely the client temporary session public key x and the client public key pcAre sent to the server together. And the server enters a waiting stage after calculating the public and private key pair of the server.
4 after receiving the data sent by the client, the server firstly sends the client public key p sent by the clientcAnd comparing the identity of the client host with the local database of the client host, and verifying the identity of the client host. If the local database does not have the client public key p corresponding to the clientcIf the connection is the first connection, the public key p of the client is usedcIP, and the client's name are saved to a local database. In general, there is no possibility that the identity is not passed, and the first connection only needs to store the data sent by the other party and then continue the connection.
If the second parameter is beta, and the client identity authentication is passed, the Gaussian distribution x is also obtained when the second parameter is betaβUp-sampling randomly and calculating to obtain rs、fsAnd gsComputing server temporary session public key y ═ ars+2fs。
While computing a server temporary session variable k according to equation (1-2)s:
ks=(pcc+x)(ssd+rs)+2gs (1-2)
Wherein: client vector c ═ H1(client, server, x), server vector d ═ H1(server, client, y, x), the temporary session variable is a temporary public key generated only for the session, and the temporary public key is automatically deleted after the session is ended, so as to ensure higher security.
Subsequently, the server calculates a temporary session error-free variable w, preferably according to equation (1-3), in order to remove the error.
w=Cha(ks) (1-3)
Wherein: cha () is a feature correlation function, defined as follows:
let q mod 2n equal to 1,
unit matrix
Defining a feature correlation function Cha () calculation formula as shown in (1-4):
wherein: v is an element of MqI.e. v is MqOf (1).
After the server successfully calculates the data, the calculation result (w, y, p) is calculateds) Sent to the client together. After the data is sent out, the server calculates the initial seed sigma of the server shared key by using the formula (1-5)s。
σs=Mod2(ks,w) (1-5)
Wherein: mod2() For the modulo-2 function, the following is defined:
let q mod 2n equal to 1,
unit matrix
The calculation formula for defining the modulo function Mod2 is shown in (1-6):
Mod2(v,w)=(v+w·(q-1)/2)mod q mod 2 (1-6)
wherein v ∈ MqW is equal to {0,1 }. For MqIt can be proved by simple calculation that u ═ v + cha (v) · (q-1)/2 mod q is an element in E.
It should be understood here that the shared key initial seed, although to some extent it may be considered as the finally negotiated shared key, may be calculated by an attacker according to the information exchanged by the two parties for security reasons, and therefore cannot be directly used for the shared key, where a hash function is used for additional processing.
Finally, the server calculates the server shared key by using the data calculated above, and the calculation formula is shown as (1-7):
sks=H(client,server,x,y,w,σs) (1-7)
wherein: the H () function is typically a hash function, such as a SHA256 hash function.
The server shared key sk at this timesThe shared key is finally calculated by the key agreement algorithm and is used for encrypting data to be transmitted subsequently and ensuring the security of the session.
5 the client receives the data (w, y, p) sent by the servers) Then, firstly, identity authentication is carried out, and the server public key p is usedsData associated with a locally stored server public keyComparing the libraries, if the local database does not have the relevant information of the server, the public key p of the server is comparedsIP, and name are stored in a local database. If the second parameter is present and the identity authentication is passed, the second parameter is a Gaussian distribution χ of betaβUp-random sampling gcCalculating a client temporary session variable k according to the formula (1-8)c:
kc=(psd+y)(scc+rc)+2gc (1-8)
Similarly, the definition c ═ H1(client,server,x),d=H1(server,client,y,x)
Finally, the client calculates the client shared key initial seed sigmacSharing the secret key sk with the clientcThe calculation formulas are respectively shown in formulas (1-9) and (1-10):
σc=Mod2(kc,w) (1-9)
skc=H(client,server,x,y,w,σc) (1-10)
skcnamely the client shared key generated in the client key negotiation stage.
After successfully calculating the own shared key, the client and the server send an SSH2_ MSG _ NEWKEYS message to the opposite end to tell the opposite end that the own shared key is generated, and the key agreement phase is ended. The next step can be performed.
The above calculation process will be verified first:
as can be seen from equations (1-7) and (1-10), the client shares the key skcSharing the secret key sk with the serversHas the same calculation function and basically the same function parameter type, only sigmacAnd σsAre different and thus want to prove skcAnd sksEquality, one can translate into a proof of σcAnd σsAre equal. SigmacAnd σsAre respectively shown in formulas (1-11) and (1-12):
σc=Mod2(kc,w) (1-11)
σs=Mod2(ks,w) (1-12)
as can be seen from equations (1-11) and (1-12), σcAnd σsAll using the function Mod2(k, v) and the second input parameter w of the function is also the same, in other words, σcAnd σsWhether or not to be equal is determined by a first input parameter kcAnd ksTo decide. Then sigma is judgedcAnd σsWhether they are equal can be converted to a decision kcAnd ksWhether or not they are the same. Client and server computing kcAnd ksAre shown in equations (1-13) and equations (1-14), respectively.
Combining equations (1-13) and equations (1-14) and
and
equations (1-15) can be obtained:
when it is, then k is considered
iAnd k
jAre equal. Therefore, in practical application, when selecting parameters, it is ensured that k is ensured that the selected parameters can satisfy the condition
cAnd k
sAre equal. Thus, the simultaneous equations (1-11) -equation (1-15), σ
cAnd σ
sAre equal, so sk
cAnd sk
sAre equal.
The security of this key exchange algorithm depends on the difficulty of the R _ LWE search type problem. I.e., in the R-LWE distribution, given aiAnd biSolving can satisfy equation bi=<ai,s>+eiThe vector s is very difficult, even if a quantum computer is used for calculation, the solution can be carried out only in exponential time, and the identity authentication of both communication parties is also completed in the key exchange stage under the condition that other identity authentication algorithms are not required to be supported, man-in-the-middle attack is prevented, and the safety of an SSH transmission layer is improved.
Furthermore, SSH supports multiple encryption algorithms, such as DES, 3DES, AES, etc., which require different numbers of key bits, and not necessarily 256 bits, but for example, if the shared key finally generated in this scheme is 256 fixed bits, it is necessary to continue processing the shared key in order to use the key well. When the required key is less than 256 bits, it is convenient, and only the previously required bits need to be taken out, for example, the encryption algorithm needs a 128-bit key, and then the first 128 bits of data of the shared key are taken out as the encryption key. But when the required key is larger than 256 bits, additional operations are required. The specific calculation method is shown as (1-16) - (1-18):
k1=SHA256(sk||session_id) (1-16)
k2=SHA256(sk||k1) (1-17)
k3=SHA256(sk||k1||k2) (1-18)
when the required key is greater than 256 bits, k is calculated according to equation (1-16)1The encryption key K is sk K1;
If the key required is greater than 512 bits, k is calculated according to equation (1-17)2The encryption key K is sk K1||k2;
If the required key length is calculated according to equations (1-17) or is not sufficient, k is calculated according to equations (1-18)3The encryption key K is sk K1||k2||k3。
And the like until the key is lengthened to the required key length according to the method.
In this way, after the client and the server successfully calculate the shared key, the ID of the session is calculated by using the version numbers of the client and the server and the shared key as the input of the hash value, and the session ID will not change in the whole session. The calculation formula is shown as (1-19):
Hash=SHA256(C_V||S_V||pc||y||w||ps||x||sk) (1-19)
wherein, C _ V and S _ V are version number character strings of the client and the server respectively, sk is a shared secret key, and | is a connector.
The fifth step: and (4) user authentication.
After successfully negotiating out the shared key, the two parties enter into the authentication phase. Firstly, the client sends a user authentication request to a request server, after receiving the request, the server returns an authentication mode list supported by the server to the client, and simultaneously checks the configuration information of the server on authentication overtime and authentication frequency upper limit. And then the client selects a preferred authentication method from an authentication list supported by the server, sends information required by the authentication method to the server for authentication, and if the authentication is successful, the client and the server enter the next stage. Otherwise, the connection is disconnected.
SSH mainly supports two authentication approaches: a host-based authentication approach and a password-based authentication approach. However, the key agreement part authenticates the identities of the client and the server, so that the user authentication mode at this stage does not suggest the use of a host-based authentication mode any more, and the use of a password-based authentication mode is recommended, because the authentication of the identity of the communication host is completed, the identity of the user can be authenticated, and the security strength of communication is further improved.
And a sixth step: a connection is requested.
After the authentication is successful, the client sends a session request, and the server receives the client request and then processes the client request in time. Session requests include the following categories: requesting a pseudo terminal, opening a shell, executing a command, starting X forwarding, starting TCP/IP port forwarding, applying for compressed data, starting an authentication agent and the like.
In summary, the method for implementing the SSH protocol based on post-quantum key exchange provides a trusted SSH improvement method based on the R-LWE post-quantum authentication key exchange algorithm: when the client and the server use SSH to carry out remote connection, the two parties firstly send information such as own protocol version number, software version number and the like to the opposite end to carry out version negotiation. After the version negotiation is successful, the two parties respectively send a credible certification request to the opposite end and verify the credible state of the other party, and when the credible states of the two parties are verified, the two parties start algorithm negotiation and key negotiation. In the key agreement stage, both parties sample from discrete Gaussian distribution of the same parameter, calculate own public and private key pairs and other necessary intermediate variables, then send own public keys and other data to the opposite end, complete identity authentication and generation of a shared key, and the shared key is generated by a back quantum algorithm, so that quantum attack can be resisted, the security in the key agreement stage is improved, and the shared key is prevented from being cracked by a third party. After the shared key is generated, the two parties encrypt the data to be transmitted by using the key to complete the user authentication and connection request part.
It can be seen that, the method for implementing the SSH protocol based on the post-quantum key exchange improves the SSH scheme by using the post-quantum authentication key exchange algorithm based on R-LWE and the trusted computing technology at the stage of the SSH transmission layer, firstly, the trusted computing technology is used to verify the trusted states of both communication parties before SSH algorithm negotiation, so as to prevent the situation that one party is possibly attacked by hackers and the other party is completely unknown, secondly, the post-quantum authentication key exchange algorithm based on R-LWE is used to complete key negotiation and identity authentication, then, the negotiated shared key is used to encrypt and transmit data, and finally, the remote security service process is completed. Therefore, a post-quantum authentication key exchange algorithm based on R-LWE and a trusted computing technology are integrated into an SSH protocol, an SSH key negotiation stage is simplified, connection establishment speed is increased, a shared key is prevented from being cracked by a quantum computer, and the capability of SSH for resisting quantum computing attack is improved. Meanwhile, the credible state of the host is verified, the SSH session security is improved, and the possibility that one communication party is illegally controlled by the other communication party is greatly reduced.
Example 2:
the embodiment provides a system for realizing an SSH protocol based on post-quantum key exchange, which can effectively prevent a shared key generated by a communication client and a server from being broken by a quantum computer; on the other hand, the trusted status of both the client and the server can be verified.
The system for realizing the SSH protocol based on the post-quantum key exchange comprises a key exchange module, wherein the key exchange module comprises a first key unit, a second key unit, a first verification unit and a second verification unit, and the key exchange module comprises:
the first key unit is positioned at the server and used for completing the following functions:
randomly sampling from the Gaussian distribution of the first parameter, and calculating a public and private key pair of the server;
after the first verification unit passes the identity authentication of the client, calculating a server temporary session public key from random sampling on the Gaussian distribution of the second parameter;
calculating a server temporary session variable and a temporary session error-eliminating variable according to the client temporary session public key, the client vector, the client temporary server vector and the random sampling of the server on the Gaussian distribution of the first parameter and the second parameter;
calculating a server shared key initial seed according to the server temporary session variable and the temporary session error-eliminating variable;
generating a final server shared key of the session by using a post-quantum algorithm according to the client vector, the server vector, the client temporary session public key, the server temporary session public key, the temporary session error-eliminating variable and the initial seed of the server shared key;
the first verification unit is positioned in the server and used for receiving the client public key and the client temporary session public key and verifying the identity of the client, if the verification cannot pass, the server directly disconnects the link, otherwise, the server performs subsequent authentication;
the second key unit is positioned at the client and used for completing the following functions:
randomly sampling from the Gaussian distribution of the first parameter, and calculating a public-private key pair of the client;
randomly sampling from the Gaussian distribution of the second parameter, calculating a client temporary session public key, and sending the client public key and the client temporary session public key to a server;
after the second verification unit passes the identity authentication of the server, calculating a client temporary session variable according to the client temporary session public key, the client vector, the server temporary session public key and the random sampling of the client on the Gaussian distribution of the first parameter and the second parameter, and further calculating a client shared key initial seed according to the client temporary session variable and the temporary session error-eliminating variable;
generating a final server shared key of the session by using a post-quantum algorithm according to the client vector, the server vector, the client temporary session public key, the server temporary session public key, the temporary session error-eliminating variable and the client shared key initial seed;
and the second verification unit is positioned at the client and used for verifying the identity of the server according to the server public key, terminating the key exchange if the verification cannot pass, and otherwise, performing subsequent authentication.
In a first key unit:
server temporary session public key ksComprises the following steps:
ks=(pcc+x)(ssd+rs)+2gs
wherein:
c=H1(client, server, x), which is a client vector;
x=arc+2fca client side temporary session public key;
rciand fciGaussian distribution χ of beta from second parameter for clientβQ is a positive integer (e.g., q is 5);
d=H1(server, client, y, x), which is a server vector;
y=ars+2fsa server temporary session public key;
rsi,fsi,gsifor server from the Gaussian distribution χ with second parameter ββQ is a positive integer (e.g., q is 5);
pc=asc+2ecis a client public key;
sciand eciFrom the first parameter of the client to the alpha Gaussian distribution xαQ is a positive integer (e.g., q is 5), and s is the random sample value of (1)cStill the client private key;
and the temporary session error-elimination variable w is:
w=Cha(ks)
wherein: cha () is a feature correlation function;
according to (w, y, p)s) Server shared secret key initial seed sigmasComprises the following steps:
σs=Mod2(ks,w)
wherein: mod
2() Modulo-2 function, Mod
2(v,w)=(v+w·(q-1)/2)mod q mod 2,q mod 2n=1,
Unit matrix
v∈M
q,w∈{0,1};
Server shared secret sksComprises the following steps:
sks=H(client,server,x,y,w,σs)。
in the second key unit, the first key unit,
client temporary session variable kcComprises the following steps:
kc=(psd+y)(scc+rc)+2gc
wherein:
gcifor server from the Gaussian distribution χ with second parameter ββQ is a positive integer (e.g., q is 5);
ps=ass+2esis a server public key;
ssiand esiFor the server, from the first parameter of alpha Gaussian distribution xαQ is a positive integer (e.g., q is 5), and s is the random sample value of (1)sStill the server private key;
and, according to (w, y, p)s) Client sharing key initial seed sigmacComprises the following steps:
σc=Mod2(kc,w)
wherein: mod
2() Modulo-2 function, Mod
2(v,w)=(v+w·(q-1)/2)mod q mod 2,q mod 2n=1,
Unit matrix
v∈M
q,w∈{0,1};
Client shared secret skcComprises the following steps:
skc=H(client,server,x,y,w,σc)。
preferably, the system for implementing the SSH protocol based on post-quantum key exchange further includes a verification Trusted Module to verify Trusted statuses of both communication parties, and since the verification Trusted Module is added, it is required that each communication host has a built-in TPM (Trusted Platform Module) chip. The verification trusted module comprises a first trusted unit located at the server and a second trusted unit located at the client, and is used for completing the following functions:
the second trusted unit sends a request for verifying the trusted status of the client to the first trusted unit;
after receiving a request of a client, a first trusted unit randomly generates an M-bit first random number, and sends the first random number and a request for verifying the trusted state of the first trusted unit to a second trusted unit, wherein M is a natural number;
after receiving the first random number and the verification request, the second trusted unit correspondingly generates an M-bit second random number, then requests the TPM for integrity measurement, encrypts the first random number, the configuration register value and the measurement log SML, and sends an encryption result, the second random number and the TPM public key to the first trusted unit;
after receiving the data, the first trusted unit judges whether the client is the first client requesting to establish SSH connection, if so, checks whether a trusted certificate exists locally, and if so, directly performs the next step; otherwise, the integrity measurement is requested to the local trusted unit, then the second random number, the configuration register value of the second random number and the measurement log SML are encrypted, and the encryption result and the TPM public key are sent to the second trusted unit;
the first trusted unit verifies the trusted state of the client according to the data sent by the second trusted unit, if the data passes the verification, a trusted verification passing certificate is generated, the certificate comprises a client IP, a client unique identifier, an IP and an identifier of a local server, the time for generating the certificate and the certificate validity period, and is encrypted by using a TPM public key sent by the client, and the encrypted result and verification passing information are sent to the client together;
after the client receives the data, the trusted state of the server is verified, if the data passes the verification, the second trusted unit also generates a trusted certificate, the content comprises a server IP, a unique identifier of the server, an IP and an identifier of the local client, the time for generating the certificate and the validity period of the certificate, the TPM public key sent by the server is used for encryption, and the encryption result and the verification passing information are sent to the first trusted unit;
after receiving the trusted credential, the first trusted unit decrypts the trusted credential by using the TPM private key of the first trusted unit and stores the trusted credential locally, so that the trusted states of the first trusted unit and the trusted unit pass verification, and otherwise, the first trusted unit is directly disconnected.
In the trusted SSH protocol improvement method based on the post-quantum key exchange algorithm, when a user uses the improved SSH protocol to remotely log in a server, the SSH firstly verifies whether hosts of two communication parties are trusted, and then completes a key negotiation stage and a two-party identity authentication stage between a client and the remote server by using the post-quantum key exchange algorithm. The method has the advantages of strong user transparency, high speed, simple and easily understood algorithm, capability of providing credible certification and post-quantum computer functions on the premise of not reducing the original SSH remote login security, and further enhancement of the SSH security.
It will be understood that the above embodiments are merely exemplary embodiments taken to illustrate the principles of the present invention, which is not limited thereto. It will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the spirit and substance of the invention, and these modifications and improvements are also considered to be within the scope of the invention.