Chinese national cryptographic algorithm-based identity authentication and data encryption method for coap
Through the CoAP protocol identity authentication and data encryption method based on Guomi, the SM4 and SM3 algorithms are used to realize efficient identity authentication and key negotiation in the resource-constrained environment in the CoAP protocol, solving the problem of large computing overhead of the traditional CoAP protocol. Ensures the security and integrity of data transmission.
Patent Information
- Application Number
- PCT/CN2023/106459
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-06-29
- Filing Date
- 2023-07-10
- Publication Date
- 2025-01-02
AI Technical Summary
Traditional CoAP protocols require an additional protocol layer in terms of identity authentication and data encryption, resulting in high computing overhead and unable to meet the needs of resource-constrained environments.
Using the CoAP protocol identity authentication and data encryption method based on the National Secret, the identity authentication data of the client and server are preconfigured, and the SM4 and SM3 algorithms are used for two-way identity authentication and key negotiation. Only two handshake messages are needed to ensure data transmission. confidentiality and integrity.
It realizes efficient identity authentication and data encryption in resource-constrained environments, saves computing overhead, prevents replay attacks, and ensures the confidentiality of important data and message integrity.
Smart Images

Figure CN2023106459_02012025_PF_FP_ABST
Abstract
Description
A CoAP protocol identity authentication and data encryption method based on national secrets Technical Field
[0001] The present invention belongs to the technical field of message transmission, and in particular relates to a CoAP protocol identity authentication and data encryption method based on national encryption. Background Art
[0002] With the rapid development of the Internet of Things (IoT), security in IoT environments has become crucial. The CoAP protocol is an IoT transmission protocol based on a request / response model. Its lightweight, non-persistent communication characteristics make it suitable for low-power IoT environments. Because the traditional CoAP protocol was not designed with security in mind, the subsequent RFC7252 standard stipulates that CoAP requires the introduction of a separate protocol layer during communication, resulting in excessive computational overhead. Therefore, proposing a lightweight CoAP protocol protection method is of great research significance.
[0003] The National Cryptography Algorithm (NCA) is a set of domestically developed cryptographic algorithm standards and application specifications approved by the State Cryptography Administration. It is a set of data encryption processing algorithms independently developed in my country. Currently published algorithms include SM2 (symmetric encryption algorithm), SM3 (hash encryption algorithm), SM4 (symmetric encryption algorithm), and SM9 (asymmetric encryption algorithm). Unpublished algorithms include SM1 (symmetric encryption algorithm) and SM7 (block encryption algorithm). Previous encryption algorithms were developed by foreign countries, making it difficult to guarantee their security. Therefore, the promotion of NCA is crucial for improving my country's cybersecurity.
[0004] CoAP (Constrained Application Protocol) is an application layer protocol developed by the IETF's CoRE working group for resource-constrained environments. These environments primarily refer to IoT devices with limited storage space, computing power, and communication bandwidth. To adapt to resource-constrained environments, CoAP is designed to be lightweight, using binary format to define packet contents. This makes data packets much smaller than HTTP, with a minimum of just four bytes required for a CoAP packet. CoAP was originally designed to enable resource-constrained devices to exchange data using an HTTP-like application layer. Therefore, CoAP implements a RESTful resource access model. CoAP is a request / response message transmission protocol, layered on top of UDP / IP. However, current CoAP protection solutions generally require significant network resources, which contradicts the design philosophy of CoAP. Traditional CoAP relies on DTLS for authentication and data encryption. However, this approach requires the introduction of a separate protocol layer and the use of computationally complex and resource-intensive cipher suites, making it unsuitable for resource-constrained networks and inconsistent with the original design of CoAP.
[0005] Summary of the Invention
[0006] The purpose of the present invention is to provide a CoAP protocol identity authentication and data encryption method based on national secrets to solve the problems existing in the above-mentioned prior art.
[0007] To achieve the above objectives, the present invention provides a CoAP protocol identity authentication and data encryption method based on national encryption, comprising:
[0008] The client and server are pre-configured with identity authentication data; the client and server perform identity authentication based on the identity authentication data, determine the security of the client and server, and simultaneously perform key negotiation to obtain a session key. If the security is determined to meet the requirements, data transmission is completed based on the session key.
[0009] Optionally, the process of pre-configuring authentication data includes:
[0010] Constructing a first identity authentication table based on each client's own device identifier, the SM4 symmetric key pre-shared with the server, and the session key, wherein the initial value of the session key in the first identity authentication table is empty;
[0011] A second identity authentication table is constructed according to each client's own device identifier, the pre-shared SM4 symmetric key corresponding to the identifier, the session key, and the permission status, wherein the initial value of the session key in the second identity authentication table is empty and the default value of the permission status is 0.
[0012] Optionally, the identity authentication includes identity authentication of the server to the client and identity authentication of the client to the server.
[0013] Optionally, the server's authentication process for the client includes:
[0014] When a client requests data, the request time is recorded and a first random number with the same number of digits as the request time is generated. The information of the requesting client stored in the first identity authentication table is extracted. A first hash value obtained by concatenating the first random number, the request time, and the SM4 symmetric key corresponding to the client's own device identifier is calculated. The first hash value is intercepted to obtain a first plaintext. The first plaintext, the request time, and the SM4 symmetric key are concatenated and encrypted to obtain a first ciphertext. The first ciphertext, the request time, and the client's own device identifier are concatenated and stored as a payload. The request time is identified as a CON type, and the request with the payload is sent to the target server.
[0015] After the target server receives the request, it determines whether the difference between the receiving time and the request time is within a preset range. If it is within the preset range, it matches the device identifier contained in the payload with the second identity authentication table, and uses the SM4 symmetric key corresponding to the identifier in the matching result to decrypt the first ciphertext to obtain the first plaintext and a new random number. After connecting the request time, the new random number, and the SM4 symmetric key corresponding to the identifier, it calculates the second hash value. After intercepting the second hash value, it determines whether it is equal to the first plaintext, thereby completing the server's identity authentication of the client.
[0016] Optionally, the client's identity authentication and key negotiation process with the server includes:
[0017] After the server authenticates the client, it generates a second random number and concatenates it with the first random number to obtain a session key and updates the second identity authentication table; concatenates the second random number, the first random number, and the reception time to calculate a third hash value, intercepts the third hash value to obtain a second plaintext, encrypts the second random number and the second plaintext with the SM4 symmetric key to obtain a second ciphertext, concatenates the second ciphertext with the reception time, and sends the response information to the client;
[0018] After receiving the response information, the client obtains the current time and determines whether the difference between the current time and the reception time is within a preset range. If so, the client uses the SM4 symmetric key to decrypt the second ciphertext to obtain the second plaintext and the new random number. The first random number, the new random number, and the reception time are concatenated to calculate a fourth hash value. The fourth hash value is intercepted and determined to be equal to the second plaintext, completing the client's identity authentication process for the server;
[0019] The first random number is concatenated with the second random number to obtain a session key, and the first identity authentication table is updated.
[0020] Optionally, the data transmission process includes:
[0021] When the server receives a data request from the client, it determines whether identity authentication has been passed based on the permission status. If identity authentication has been passed, it obtains the client's corresponding session key, concatenates the requested resource with the request time, calculates a hash value, and intercepts the third plaintext to obtain a third ciphertext. The value obtained by concatenating the requested resource with the third plaintext is encrypted based on the session key to obtain a third ciphertext, and the third ciphertext is concatenated with the request time as the server's response information.
[0022] After the client receives the response information, it records the receiving time and determines whether the difference between the request time and the receiving time is within the preset range. If so, it decrypts the third ciphertext according to the session key to obtain the third plaintext and the resource, calculates the hash value of the resource and the request time, and determines whether the resource is correct based on the hash value.
[0023] Optionally, the calculation of hash values is based on the SM3 algorithm, the encryption uses the SM4 algorithm, and the truncation length of the hash value is 64 bits.
[0024] Optionally, when the server resources are changed, the server resends a CON request message and sends the changed resources to the client again. After receiving the message, the client returns an empty response message.
[0025] The technical effects of the present invention are:
[0026] The present invention establishes an identity table for each client and server, and important data can only be obtained by looking up the table by both parties; using a pre-shared key method, the SM4 and SM3 algorithms are adopted to complete two-way identity authentication and key negotiation before data transmission between the client and the server, using only two handshake messages, and still able to ensure the confidentiality of important data during identity authentication and the integrity of messages; using timestamps and random numbers to prevent replay attacks; and adopting the observer mode, which is the most cost-effective in practical CoAP applications, for data transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings, which constitute part of this application, are intended to provide a further understanding of this application. The exemplary embodiments and descriptions of this application are intended to explain this application and do not constitute an improper limitation on this application. In the accompanying drawings:
[0028] FIG1 is a schematic diagram of a method flow in an embodiment of the present invention. DETAILED DESCRIPTION
[0029] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0030] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0031] Example 1
[0032] As shown in FIG1 , this embodiment provides a CoAP protocol identity authentication and data encryption method based on national encryption, including:
[0033] One-time device configuration phase: Pre-configure the required data before identity authentication to ensure that the client and server successfully complete identity authentication.
[0034] Step 1: Each client stores a symmetric key (K) consisting of its own device identifier (IDi, i=1, 2, 3...), and the SM4 symmetric key (K mi , i=1,2,3...) and the negotiated session key (K si , i = 1, 2, 3, ...). Before identity authentication, the session key in this table is empty. The server stores an identity table consisting of each client's device identifier, the corresponding SM4 pre-shared key, the negotiated session key, and the Authorized field. Before identity authentication, the session key in this table is empty, and Authorized defaults to 0. The identity table for client ID1 is shown in Table 1, and the server identity table is shown in Table 2.
[0035] Table 1
[0036] Identity authentication and key negotiation phase: Add identity authentication and key negotiation functions before data transmission to ensure that the CoAP client and server are trustworthy during data transmission and use the negotiated key for subsequent data transmission.
[0037] Step 2: Client ID1 records the current time T1, which is 64 bits, and then generates a 64-bit random number N C , use SM3 algorithm to calculate N C , T1, and the pre-shared key K of ID1 m1 The hash value H1 after connection, take the first 64 bits of H1 as the plaintext P1, and convert N C Connect to P1 and retrieve the pre-shared key K from the table m1 Use the SM4 algorithm to encrypt the concatenated plaintext to obtain the ciphertext C1. Concatenate C1, T1, and ID1 and put them into the payload field. Set the URI to / localhost:5683 / authorize, identify the T field in the protocol header as the CON type, and send the message to the server in the form of a POST request.
[0038] Step 3: After receiving the request, the server records the current time T2, then extracts the valid value in the payload field, calculates |T2-T1|, and checks whether the value is within the specified time range. If so, it queries the identity table in the server to see if there is the same device identifier. If so, it extracts the corresponding pre-shared key K m1 , then use K m1 Decrypt C1 to get the plaintext N C ' and P1, use SM3 algorithm to calculate N C ', T1 and K m1 The hash value H2 after the connection, if the first 64 bits of H2 are equal to P1, it means that the information sent by the client through the payload is correct and the server has verified the identity of the client. The server generates a 64-bit random number N S , N C With N S Connect to get K s1 Stored as a new session key in the server table, and the Authorized field corresponding to the client in the table is changed from 0 to 1. The server will obtain N from client ID1. C , self-generated N S And the recorded T2 connection is used to calculate the hash value using the SM3 algorithm to obtain H3, and the first 64 bits of H3 are taken as the plaintext P2, and N S Connect to P2 and use K m1 The SM4 algorithm is used to encrypt the concatenated plaintext to obtain the ciphertext C2, C2 and T2 are concatenated and placed in the payload field, and a response is sent to the client.
[0039] Step 4: After receiving the response, the client records the current time T3, takes out the valid value in the payload field, calculates |T3-T2|, and checks whether the value is within the specified time range. If so, it uses the pre-shared key K m1 Decrypt C2 to get the plaintext N S ' and P2, N C 、N S ', T2 connects and uses the SM3 algorithm to calculate the hash value to obtain H4. If the first 64 bits of H4 are equal to P2, it means that the random number N sent by the server through the payload is S If the information is correct and the client verifies the server's identity, C With N S Connect to get K s1 The new session key is stored in the client table. The authentication and key negotiation phase ends.
[0040] Data transmission phase.
[0041] Step 5: Client ID1 identifies the T field in the protocol header as the CON type, sets the URI to / localhost:5683 / observe, stores the identifier ID1 in the created option No. 256, sets the observe option field to 0 to indicate that a request to observe resources is made to the server, and sends a GET request to the server.
[0042] Step 6: After receiving the GET request from the client, the server records the current time T4 and checks whether the observe field in the request is 0. If it is 0, the server takes out the device identifier in option 256 and checks the identity table in the server to see if it is the correct ID1. If it is correct, it checks whether the Authorized field corresponding to the device identifier is 1. If it is 1, it indicates that the device has been authenticated and is a legitimate device. It stores ID1 in the observer list and takes out the corresponding session key K from the identity table. s1 Connect the 64-bit resource M1 with T4 and calculate the hash value using the SM3 algorithm to get H5. Take the first 64 bits of H5 as the plaintext P3 and use K s1 The SM4 algorithm is used to encrypt the concatenation of M1 and P3 to obtain ciphertext C3. The concatenation of C3 and T4 is put into the payload and a response is sent to the client.
[0043] Step 7: After receiving the message, the client records the current time T5, extracts the valid value in the payload, calculates |T5-T4|, and checks whether the value is within the specified time range. If so, it extracts the corresponding session key K from the table. s1Decrypt C3 to obtain M1' and P3. Use the SM3 algorithm to calculate the hash value H6 after concatenating M1' and T4. If the first 64 bits of H6 are equal to P3, it means that the resource M1' sent by the server to the client is correct.
[0044] Step 8: When the server resources change, the server resends a CON request message and sends the changed resources to the client again. The specific steps are similar to step 7.
[0045] Step 9: After receiving the message, the client returns an empty response message.
[0046] The meanings of the symbols in the present invention are shown in Table 3.
[0047] Table 3
[0048] The present invention establishes an identity table for each client and server, and important data can only be obtained by looking up the table by both parties; using a pre-shared key method, the SM4 and SM3 algorithms are adopted to complete two-way identity authentication and key negotiation before data transmission between the client and the server, using only two handshake messages, and still able to ensure the confidentiality of important data during identity authentication and the integrity of messages; using timestamps and random numbers to prevent replay attacks; and adopting the observer mode, which is the most cost-effective in practical CoAP applications, for data transmission.
[0049] The above description is merely a preferred embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. A CoAP protocol identity authentication and data encryption method based on national secrets, characterized in that: The following steps are involved: Pre-configure the authentication data of the client and server; The client and the server perform identity authentication based on the identity authentication data, determine the security of the client and the server, and simultaneously perform key negotiation to obtain a session key. If the security is determined to meet the requirements, data transmission is completed based on the session key.
2. According to the CoAP protocol identity authentication and data encryption method based on national secrets according to claim 1, it is characterized in that: The process of pre-configuring authentication data includes: Constructing a first identity authentication table according to each client's own device identifier, the SM4 symmetric key pre-shared with the server, and the session key, wherein the initial value of the session key in the first identity authentication table is empty; A second identity authentication table is constructed according to each client's own device identifier, the pre-shared SM4 symmetric key corresponding to the identifier, the session key, and the permission status, wherein the initial value of the session key in the second identity authentication table is empty and the default value of the permission status is 0.
3. According to claim 2, the CoAP protocol identity authentication and data encryption method based on national secrets is characterized in that: The identity authentication includes the identity authentication of the server to the client and the identity authentication of the client to the server.
4. According to claim 3, the CoAP protocol identity authentication and data encryption method based on national secrets is characterized in that: The server's authentication process for the client includes: When the client requests data, the request time is recorded, and a first random number with the same number of digits as the request time is generated, the information of the client that issued the request stored in the first identity authentication table is extracted, the first random number, the request time, and the first hash value after the SM4 symmetric key corresponding to the own device identifier are connected are calculated, the first hash value is intercepted to obtain the first plaintext; the first plaintext, the request time, and the SM4 symmetric key are connected and encrypted to obtain the first ciphertext; the first ciphertext, the request time, and the own device identifier are connected and stored as a payload; the request time is identified as a CON type, and the request with the payload is sent to the target server; After receiving the request, the target server determines whether the difference between the receiving time and the request time is within a preset range. If it is within the preset range, the device identifier contained in the payload is matched with the second identity authentication table, and the first ciphertext is decrypted using the SM4 symmetric key corresponding to the identifier in the matching result to obtain the first plaintext and a new random number. The request time, the new random number, and the SM4 symmetric key corresponding to the identifier are connected to calculate the second hash value. After intercepting the second hash value, it is determined whether it is equal to the first plaintext, thereby completing the server's identity authentication of the client.
5. According to claim 4, the CoAP protocol identity authentication and data encryption method based on national secrets is characterized in that: The client's identity authentication and key negotiation process for the server includes: After the server authenticates the client, it generates a second random number and connects it with the first random number to obtain a session key and updates the second authentication table; after connecting the second random number, the first random number, and the receiving time, it calculates a third hash value, intercepts the third hash value to obtain a second plaintext, encrypts the second random number and the second plaintext with the SM4 symmetric key to obtain a second ciphertext, connects the second ciphertext with the receiving time, and sends it as a response message to the client; After receiving the response information, the client obtains the current time and determines whether the difference between the current time and the receiving time is within the preset range. If so, the SM4 symmetric key is used to decrypt the second ciphertext to obtain the second plaintext and the new random number. The first random number, the new random number, and the receiving time are connected to calculate the fourth hash value, the fourth hash value is intercepted and determined whether it is equal to the second plaintext, and the client completes the identity authentication process of the server; The first random number is concatenated with the second random number to obtain a session key, and the first identity authentication table is updated.
6. The CoAP protocol identity authentication and data encryption method based on national secrets according to claim 2 is characterized in that: The data transfer process includes: When the server receives a data request from the client, it determines whether the identity authentication has been passed according to the permission status. If the identity authentication has been passed, it obtains the session key corresponding to the client, connects the requested resource with the request time, calculates the hash value and intercepts it to obtain the third plaintext, encrypts the value obtained by connecting the requested resource with the third plaintext based on the session key to obtain the third ciphertext, and connects the third ciphertext with the request time as the response information of the server; After the client receives the response information, it records the receiving time and determines whether the difference between the request time and the receiving time is within a preset range. If so, it decrypts the third ciphertext according to the session key to obtain the third plaintext and the resource, calculates the hash value of the resource and the request time, and determines whether the resource is correct based on the hash value.
7. The CoAP protocol identity authentication and data encryption method based on national secrets according to any one of claims 1 to 6, characterized in that: The calculation of hash values is based on the SM3 algorithm, the encryption uses the SM4 algorithm, and the truncation length of the hash value is 64 bits.
8. The CoAP protocol identity authentication and data encryption method based on national secrets according to claim 1 is characterized in that: When the server resources change, the server resends a CON request message to send the changed resources to the client again. After receiving the message, the client returns an empty response message.
Citation Information
Patent Citations
Terminal permission control method and device, computer equipment and storage medium
CN112087417A
Encrypted communication system and method for Internet of Things
CN112423276A
Kerberos identity authentication protocol improvement method based on national cryptographic algorithm
CN113612797A
Power distribution Internet of Things service security interaction method and system based on national cryptographic algorithm
CN114024698A
Internet of things devices for use with an encryption service
US20210019429A1
Cited By
Communication method based on national secret encryption network protocol, server and client
CN119814308A
Modbus protocol security enhancement method and system in unicast communication scene
CN120342628A
Train control system data encryption authentication method and device
CN120358496A
Message data security improvement method and device, equipment, storage medium and computer program product
CN120378197A
Power grid data secure transmission system and method based on quantum cryptography, and medium
CN120389855A
