Secure communication method and apparatus
A secure communication method and apparatus are disclosed, to ensure security of a direct communication between terminal devices. In this application, a first terminal device may receive a key generation parameter from a first network element, where the key generation parameter includes a ProSe temporary identity of the first terminal device. Then, the first terminal device may generate a first discovery key based on the key generation parameter. The first terminal device sends a ProSe request message, where the ProSe request message includes the ProSe temporary identity and a message integrity code, and the message integrity code is generated based on the discovery key. The second terminal device receives the ProSe request message, and verifies the first terminal device based on the message integrity code, to ensure the security of a direct communication between the first terminal device and the second terminal device.
1 . A secure communication method, comprising:
sending, by a first terminal device, a parameter obtaining request to a first network element, wherein the parameter obtaining request comprises an identity of a first terminal device;
receiving, by the first terminal device from the first network element, a parameter obtaining response comprising a key generation parameter, wherein the key generation parameter comprises a ProSe temporary identity of the first terminal device that is allocated by the first network element only after an authorization check on the first terminal device succeeds;
generating, by the first terminal device, a first discovery key at a ProSe granularity by inputting a root key and the key generation parameter, comprising the ProSe temporary identity, into a key derivation function;
generating, by the first terminal device, a message integrity code based on the first discovery key; and
sending, by the first terminal device, a ProSe request message, wherein the ProSe request message comprises the ProSe temporary identity and the message integrity code.
2 . The method according to claim 1 , wherein the generating, by the first terminal device, the message integrity code based on the first discovery key comprises:
generating, by the first terminal device, a subkey based on the first discovery key; and
generating, by the first terminal device, the message integrity code based on the subkey.
3 . The method according to claim 1 , wherein the parameter obtaining response further comprises a validity time of the ProSe temporary identity.
4 . The method according to claim 3 , further comprising:
storing, by the first terminal device, the first discovery key and the validity time.
5 . The method according to claim 4 , further comprising:
deleting, by the first terminal device, the first discovery key after the validity time expires.
6 . A secure communication method, comprising:
receiving, by a first network element, a parameter obtaining request from a first terminal device, wherein the parameter obtaining request comprises an identity of the first terminal device;
allocating, by the first network element, a ProSe temporary identity to the first terminal device only after an authorization check on the first terminal device based on the identity of the first terminal device succeeds;
sending, by the first network element, a key generation parameter, wherein the key generation parameter comprises the ProSe temporary identity of the first terminal device;
receiving, by the first network element, a verification request from a second terminal device, wherein the verification request comprises the ProSe temporary identity and a message integrity code;
determining, by the first network element, a first discovery key at a ProSe granularity of the first terminal device by inputting the ProSe temporary identity and a root key into a key derivation function;
generating, by the first network element, an expected message integrity code based on the first discovery key; and
sending, by the first network element, a verification response to the second terminal device after verifying the first terminal device based on the message integrity code and the expected message integrity code, wherein the verification response indicates a verification result for the first terminal device.
7 . The method according to claim 6 , wherein the sending, by the first network element, the key generation parameter comprises:
obtaining, by the first network element, the first discovery key based on the ProSe temporary identity; and
sending, by the first network element, a parameter obtaining response to the first terminal device, wherein the parameter obtaining response comprises the key generation parameter.
8 . The method according to claim 6 , further comprising:
storing, by the first network element, a correspondence between the ProSe temporary identity and the first discovery key.
9 . The method according to claim 7 , wherein the obtaining, by the first network element, the first discovery key based on the ProSe temporary identity comprises:
generating, by the first network element, the first discovery key, wherein the root key is a key allocated or pre-configured for the first terminal device;
obtaining, by the first network element, the first discovery key from a key generation network element based on the ProSe temporary identity; or
obtaining, by the first network element, a second discovery key from the key generation network element based on the identity of the first terminal device, and generating the first discovery key based on the second discovery key and the ProSe temporary identity.
10 . The method according to claim 9 , wherein the obtaining, by the first network element, the first discovery key from the key generation network element based on the ProSe temporary identity comprises:
sending, by the first network element, a first key obtaining request to the key generation network element, wherein the first key obtaining request comprises the ProSe temporary identity and the identity of the first terminal device; and
receiving, by the first network element, a first key obtaining response from the key generation network element, wherein the first key obtaining response comprises the first discovery key.
11 . The method according to claim 9 , wherein the obtaining, by the first network element, the second discovery key from the key generation network element based on the identity of the first terminal device comprises:
sending, by the first network element, a second key obtaining request to the key generation network element, wherein the second key obtaining request comprises the identity of the first terminal device; and
receiving, by the first network element, a second key obtaining response from the key generation network element, wherein the second key obtaining response comprises the second discovery key.
12 . The method according to claim 6 , wherein the generating, by the first network element, the expected message integrity code based on the first discovery key comprises:
generating, by the first network element, a subkey based on the first discovery key; and
generating, by the first network element, the expected message integrity code based on the subkey.
13 . An apparatus, comprising:
a processor coupled to a memory storing instructions and configured to execute the instructions to cause the apparatus to:
send a parameter obtaining request to a first network element, wherein the parameter obtaining request comprises an identity of the apparatus; and
receive a parameter obtaining response from the first network element, wherein the parameter obtaining response comprises a key generation parameter, wherein the key generation parameter comprises a ProSe temporary identity of the apparatus that is allocated by the first network element only after an authorization check on the apparatus succeeds;
generate a first discovery key at a ProSe granularity by inputting a root key and the key generation parameter, comprising the ProSe temporary identity, into a key derivation function;
generate a message integrity code based on the first discovery key; and
send a ProSe request message, wherein the ProSe request message comprises the ProSe temporary identity and the message integrity code.
14 . The apparatus according to claim 13 , wherein the instructions cause the apparatus to generate the message integrity code based on the first discovery key by:
generating a subkey based on the first discovery key; and
generating the message integrity code based on the subkey.
15 . The apparatus according to claim 13 , wherein the parameter obtaining response further comprises a validity time of the ProSe temporary identity; and
wherein the instructions further cause the apparatus to store the first discovery key and the validity time.
16 . The apparatus according to claim 15 , wherein the instructions further cause the apparatus to delete the first discovery key after the validity time expires.
17 . An apparatus, comprising:
a processor coupled to a memory storing instructions and configured to execute the instructions to cause the apparatus to:
receive a parameter obtaining request from a first terminal device, wherein the parameter obtaining request comprises an identity of the first terminal device;
allocate a ProSe temporary identity to the first terminal device only after an authorization check on the first terminal device based on the identity of the first terminal device succeeds;
send a key generation parameter, wherein the key generation parameter comprises the ProSe temporary identity of the first terminal device;
receive a verification request from a second terminal device, wherein the verification request comprises the ProSe temporary identity and a message integrity code;
determine a first discovery key at a ProSe granularity of the first terminal device by inputting the ProSe temporary identity and a root key into a key derivation function;
generate an expected message integrity code based on the first discovery key; and
send a verification response to the second terminal device after verifying the first terminal device based on the message integrity code and the expected message integrity code, wherein the verification response indicates a verification result for the first terminal device.
18 . The apparatus according to claim 17 , wherein the instructions cause the apparatus to generate the message integrity code based on the first discovery key by:
obtaining the first discovery key based on the ProSe temporary identity; and
sending a parameter obtaining response to the first terminal device, wherein the parameter obtaining response comprises the key generation parameter.