A method and system for implementing identity authentication based on PAM

By implementing the registration and authentication process in PAM, the problem of communication between PAM and smart key devices is solved, and the identity authentication of Apple and Linux devices is realized, ensuring security in a networkless environment.

CN118779859BActive Publication Date: 2024-11-19FEITIAN TECHNOLOGIES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411273478.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-12
Publication Date
2024-11-19
Estimated Expiration
2044-09-12

AI Technical Summary

Technical Problem

Existing PAMs (pluggable authentication modules) cannot communicate directly with Linux system devices or Apple system devices with smart key devices, making it difficult to implement identity authentication.

Method used

By implementing the registration and authentication process in PAM, using intelligent key devices to generate and verify random numbers and application parameters, send registration and authentication instructions, parse responses, save credential information, and write authentication operation instructions in the PAM configuration file to achieve Authentication between devices.

Benefits of technology

It realizes direct communication between Apple system devices or Linux system devices and smart key devices, which facilitates user identity authentication in a network-free environment and enhances security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118779859B_ABST
    Figure CN118779859B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for implementing identity authentication based on PAM. The method comprises: a registration program saves application parameters, user names, credential information returned by an intelligent key device and a user public key in an authentication file; an authentication operation instruction is written in the first line of a PAM configuration file; a PAM loaded when a user logs in parses the authentication operation instruction in the first line of the PAM configuration file to obtain a control mark, an authentication file path and an authentication program path, and loads an authentication program according to the authentication program path; when an authentication interface is called, the authentication program reads the authentication file under the authentication file path, and sends an authentication instruction to the intelligent key device if the logged-in user matches the user name in the authentication file, processes a legal authentication response according to the control mark and returns the processing result through PAM. The authentication of user identity is realized by PAM, and it can be used in a networkless environment, which is convenient and safe.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information security, and in particular to a method and system for implementing identity authentication based on PAM. Background Art

[0002] Identity authentication is one of the important mechanisms for operating system security. The system uses the authentication mechanism to identify the user's identity. The authentication mechanism is used as a judgment condition for the user to enter the system, which is the first threshold to prevent malicious users from entering the system. In recent years, authentication theory and technology have developed rapidly, resulting in various authentication mechanisms, such as the password mechanism (that is, the password is encrypted and sent to the recipient, and the recipient compares it with the original password after decryption). However, this encryption method is too single. The leakage of the user's account password in a service will involve the security of multiple services. Therefore, in order to enhance the security of the system, many other identity authentication mechanisms have emerged one after another, such as fingerprint authentication, USB authentication, FIDO devices, etc., and hardware devices with these identity authentication mechanisms have emerged. However, these hardware devices cannot communicate directly with Linux system devices or Apple system devices. The existing PAM (English full name: Pluggable Authentication Modules, Chinese full name: pluggable authentication module) has extended functions, but how to use PAM to solve the communication between Linux system devices or Apple system devices and these hardware devices to achieve identity authentication is an urgent problem to be solved. Summary of the invention

[0003] The purpose of the present invention is to overcome the deficiencies of the prior art and to provide a method and system for implementing identity authentication based on PAM.

[0004] In a first aspect, an embodiment of the present invention provides a method for implementing identity authentication based on PAM, including a registration process and an authentication process, wherein the registration process includes:

[0005] Step S1: When the registration interface is called during the operation of the registration program, the registration program parses the input parameters to obtain the authentication method and user name;

[0006] Step S2: The registration program obtains the authentication method from the smart key device, and determines whether the obtained authentication method is consistent with the authentication method obtained by parsing. If yes, step S3 is executed, otherwise an error is reported;

[0007] Step S3: the registration program generates application parameters according to the generated first random number and the user name, generates a registration instruction according to the first random number and the application parameters, and sends the registration instruction to the smart key device;

[0008] Step S4: When the registration program receives the registration response returned by the smart key device, the registration response is parsed, and the credential information and user public key, the application parameters, and the user name obtained by parsing are saved in the authentication file;

[0009] After step S4, the method further includes: writing an authentication operation instruction in the first line of the PAM configuration file, wherein the authentication operation instruction includes: a control mark, an authentication file path, and an authentication program path;

[0010] The authentication process includes:

[0011] Step R1: When the authentication interface in the authentication program is called by the PAM, the authentication program reads the authentication file under the authentication file path, determines whether the currently logged-in user name is consistent with the user name in the authentication file, and if so, generates an authentication instruction based on the credential information and application parameters in the authentication file found and the generated second random number, sends the authentication instruction to the smart key device, and executes step R2; otherwise, an error is reported;

[0012] Step R2: After the authentication program receives the authentication response returned by the smart key device, if the authentication response contains verification success information, the authentication program verifies the signature data in the authentication response, and if the verification is successful, returns the authentication result containing success information to the PAM, and executes step R3; if the verification fails, returns the authentication result containing failure information to the PAM, and executes step R3; if the authentication response contains verification failure information, returns the authentication result containing failure information to the PAM, and executes step R3;

[0013] Step R3: the PAM processes the received authentication result according to the control tag to obtain an identity authentication result, and returns the identity authentication result to the operating system or application program;

[0014] Before step R1, it also includes: when the user logs in to the operating system or application, the currently logged-in user name is obtained and the corresponding PAM is loaded, the PAM parses the authentication operation instruction in the first line of the corresponding PAM configuration file to obtain the control mark, the authentication file path and the authentication program path, and loads the authentication program according to the authentication program path.

[0015] In a second aspect, an embodiment of the present invention provides a system for implementing identity authentication based on PAM, including a registration module, an authentication module and a PAM module, wherein the registration module includes:

[0016] The receiving and parsing unit is used to parse the incoming parameters to obtain the authentication method and user name when the registration interface is called during the registration program running;

[0017] An acquisition and judgment unit, used for acquiring an authentication method from a smart key device, and judging whether the acquired authentication method is consistent with the authentication method obtained by parsing, and if so, triggering the first generation and sending unit, otherwise reporting an error;

[0018] The first generating and sending unit is used to generate application parameters according to the generated first random number and the user name, generate a registration instruction according to the first random number and the application parameter, and send the registration instruction to the smart key device;

[0019] A parsing and saving unit, configured to parse the registration response returned by the smart key device upon receiving the registration response, and save the credential information and user public key, the application parameters, and the user name obtained by parsing in an authentication file;

[0020] The system also includes a writing module, which is used to write an authentication operation instruction in the first line of the PAM configuration file, wherein the authentication operation instruction includes: a control mark, an authentication file path, and an authentication program path;

[0021] The authentication module comprises:

[0022] a reading and judging unit, configured to read the authentication file under the authentication file path when the authentication interface in the authentication program is called by the PAM module, and judge whether the currently logged-in user name is consistent with the user name in the authentication file, and trigger the second generating and sending unit if yes, otherwise reporting an error;

[0023] The second generating and sending unit is used to generate an authentication instruction according to the credential information and application parameters in the authentication file found and the generated second random number, and send the authentication instruction to the smart key device;

[0024] a receiving verification return unit, configured to receive an authentication response returned by the smart key device, and if the authentication response contains verification success information, the authentication program verifies the signature data in the authentication response, and if the verification is successful, returns an authentication result containing success information to the PAM module, and if the verification fails, returns an authentication result containing failure information to the PAM module, and if the authentication response contains verification failure information, returns an authentication result containing failure information to the PAM module;

[0025] The PAM module is used to process the authentication result according to the control mark to obtain an identity authentication result, and return the identity authentication result to the operating system or application program;

[0026] The system also includes an acquisition loading module, which is used to obtain the current logged-in user name and load the corresponding PAM module when the user logs in to the operating system or application program;

[0027] The PAM module is also used to parse the authentication operation instruction in the first line of the corresponding PAM configuration file to obtain the control mark, the authentication file path and the authentication program path, and load the authentication program according to the authentication program path.

[0028] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising at least one processor, a memory, and instructions stored in the memory and executable by the at least one processor, wherein the at least one processor executes the instructions to implement the aforementioned PAM-based identity authentication method.

[0029] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a computer program. When the computer program runs on an electronic device, the electronic device executes the aforementioned method for implementing identity authentication based on PAM.

[0030] In a fifth aspect, an embodiment of the present invention further provides a chip system, comprising a chip, wherein the chip is coupled to a memory and is used to execute a computer program stored in the memory to execute the aforementioned method for implementing identity authentication based on PAM.

[0031] Compared with the prior art, the present invention has the following advantages: In the technical solution of the present invention, Apple system devices or Linux system devices can directly communicate with the smart key device through PAM, thereby authenticating the user identity when logging into the system or using the APP (application), and can be used in a networkless environment, which is convenient and safe. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 A flowchart of a method for implementing identity authentication based on PAM provided in Example 1 of the present invention;

[0033] Figure 2 A flowchart of a registration process in a method for implementing identity authentication based on PAM provided in Embodiment 2 of the present invention;

[0034] Figure 3 A flowchart of a method for implementing an authentication process in a method for implementing identity authentication based on PAM provided in Embodiment 2 of the present invention;

[0035] Figure 4 This is a flowchart of a specific implementation process of step 215 in the second embodiment of the present invention;

[0036] Figure 5 A block diagram of a system for implementing identity authentication based on PAM provided in Example 3 of the present invention. DETAILED DESCRIPTION

[0037] The present application proposes a method and system for implementing identity authentication based on PAM. The specific implementation methods of the present application are described in detail below in conjunction with the accompanying drawings. Examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.

[0038] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in common dictionaries should be understood to have meanings consistent with the meanings in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.

[0039] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention are further described in detail below with reference to the accompanying drawings.

[0040] Embodiment 1

[0041] The first embodiment of the present invention provides a method for implementing identity authentication based on PAM, such as Figure 1 As shown, it includes the registration process and the authentication process. The registration process includes:

[0042] Step S1: When the registration interface is called during the registration program, the registration program parses the passed-in parameters to obtain the authentication method and user name;

[0043] Step S2: The registration program obtains the authentication method from the smart key device and determines whether the obtained authentication method is consistent with the authentication method obtained by parsing. If yes, step S3 is executed, otherwise an error is reported;

[0044] Step S3: the registration program generates application parameters according to the generated first random number and the user name, generates a registration instruction according to the first random number and the application parameters, and sends the registration instruction to the smart key device;

[0045] Specifically, in this embodiment, the registration program generates application parameters according to the generated first random number and the user name, including: the registration program generates a first random number of a preset length, forms a structure according to the preset first data, the second data, the user name and the first random number, and generates application parameters of the preset length through the first interface according to the structure;

[0046] Furthermore, generating an application parameter of a preset length through the first interface according to the structure includes: generating a first portion of data through a first function in the first interface according to the first data and the second data in the structure, generating a second portion of data through a second function in the first interface according to the user name and the first random number in the structure, and generating an application parameter according to the first portion of data and the second portion of data;

[0047] In this embodiment, after receiving the registration instruction, the smart key device executes steps A1 to A3;

[0048] Step A1: the smart key device receives the registration instruction, parses the registration instruction to obtain the first random number and application parameters and saves them, and determines whether the registration conditions are met. If yes, step A2 is executed, otherwise an error is reported;

[0049] Among them, judging whether the registration conditions are met includes:

[0050] Step A11: the smart key device determines whether the command header and data length obtained by parsing the registration instruction meet the requirements, and if so, executes step A12, otherwise, reports an error;

[0051] Step A12: the smart key device determines whether the value of the acquired signature counter reaches the maximum value, and if so, reports an error, otherwise, executes step A13;

[0052] Step A13: The smart key device determines whether the key state is valid, if so, executes step A2, otherwise reports an error;

[0053] Step A2: the smart key device generates credential information according to the first random number, the application parameter, and the stored user private key, updates the value of the signature counter, and generates first signature data according to the credential information;

[0054] The smart key device generates credential information according to the first random number, the application parameter, and the saved user private key, including: the smart key device generates and saves a user key pair, performs an XOR operation on the first random number and the user private key in the user key pair to obtain a first intermediate value, concatenates the first intermediate value, the application parameter, and the device identifier to obtain a first concatenated value, encrypts the first concatenated value according to a first preset algorithm using the user private key to generate a first ciphertext, performs MAC calculation on the first ciphertext using a second preset algorithm to obtain a first MAC value, and concatenates the first ciphertext and the first MAC value to obtain the credential information;

[0055] Generating the first signature data according to the credential information includes: concatenating the first preset value, the application parameter, the first random number, the credential information, and the user public key in the user key pair to obtain a second concatenated value, signing the second concatenated value using a third preset algorithm and a built-in device private key to obtain a first signature result, and encoding the first signature result to obtain the first signature data;

[0056] Step A3: the smart key device generates a registration response according to the stored user public key, credential information and first signature data, and returns the registration response to the registration program;

[0057] The smart key device generates a registration response according to the stored user public key, credential information and first signature data, including: concatenating the second preset value, the stored user public key, the length of the credential information, the credential information, the device certificate and the first signature data to obtain a registration response;

[0058] Accordingly, step A3 further includes: setting the button state to invalid;

[0059] Step S4: When the registration program receives the registration response returned by the smart key device, it parses the registration response and saves the credential information and user public key, application parameters, and user name obtained by parsing in the authentication file;

[0060] After step S4, the method further includes: writing an authentication operation instruction in the first line of the PAM configuration file, wherein the authentication operation instruction includes: a control mark, an authentication file path, and an authentication program path;

[0061] The certification process includes:

[0062] When a user logs in to the operating system or application, the currently logged-in user name is obtained and the corresponding PAM is loaded. The PAM parses the authentication operation instruction in the first line of the corresponding PAM configuration file to obtain the control mark, the authentication file path and the authentication program path, and loads the authentication program according to the authentication program path, and executes step R1;

[0063] Step R1: When the authentication interface in the authentication program is called by PAM, the authentication program reads the authentication file under the authentication file path, determines whether the currently logged-in user name is consistent with the user name in the authentication file, and generates an authentication instruction based on the credential information and application parameters in the authentication file and the generated second random number, sends the authentication instruction to the smart key device, and executes step R2, otherwise an error is reported;

[0064] In this embodiment, after receiving the authentication instruction, the smart key device executes steps B1 to B3;

[0065] Step B1: The smart key device parses the authentication instruction to obtain the credential information, application parameters and the second random number, and determines whether the authentication condition is met. If yes, step B2 is executed; otherwise, an authentication response including verification failure information is returned to the authentication program;

[0066] Among them, judging whether the certification conditions are met includes:

[0067] Step B11: the smart key device determines whether the length of the command header and the credential information obtained by parsing the authentication instruction meets the requirements. If yes, step B12 is executed. Otherwise, an authentication response including verification failure information is returned to the authentication program.

[0068] Step B12: the smart key device determines whether the value of the signature counter reaches the maximum value, and if so, returns an authentication response including verification failure information to the authentication program, otherwise, executes step B13;

[0069] Step B13: the smart key device determines the third byte data in the authentication instruction, and if it is the third data, executes step B14; if it is the fourth data, executes step B15;

[0070] Step B14: the smart key device verifies the credential information according to the stored first random number, application parameters, and stored user private key. If the verification succeeds, step B16 is executed. If the verification fails, an authentication response including verification failure information is returned to the authentication program.

[0071] Furthermore, step B14 includes: the smart key device performs an XOR operation on the stored first random number and the user private key to obtain a first verification intermediate value, concatenates the first verification intermediate value, the application parameter and the device identifier to obtain a first verification concatenation value, uses the user private key to encrypt the first verification concatenation value according to a first preset algorithm to generate a first verification ciphertext, uses a second preset algorithm to perform MAC calculation on the first verification ciphertext to obtain a first verification MAC value, determines whether the first verification MAC value is consistent with the first MAC value in the credential information, if yes, the verification is successful, and executes step B16, otherwise the verification fails, and returns an authentication response containing verification failure information to the authentication program;

[0072] Step B15: the smart key device checks whether the key state is valid, if so, executes step B16, otherwise returns an authentication response including authentication failure information to the authentication program;

[0073] Step B16: the smart key device uses the user public key to decrypt the first ciphertext in the credential information according to the first preset algorithm to obtain a first concatenated value, and determines whether the application parameters and device identification in the first concatenated value are consistent with the application parameters and device identification stored in the device. If all of them are determined to be consistent, step B2 is executed; otherwise, an authentication response containing verification failure information is returned to the authentication program, and the value of the signature counter is updated;

[0074] Step B2: the smart key device generates data to be signed according to the application parameter, the second random number, and the value of the signature counter, signs the data to be signed using the stored user private key to obtain a second signature result, and encodes the second signature result to obtain second signature data;

[0075] Specifically, in this embodiment, step B2 includes: concatenating the application parameter, the second preset value, the value of the signature counter, and the second random number to obtain the data to be signed, using the saved user private key to sign the data to be signed according to the fourth preset algorithm to obtain a second signature result, and encoding the second signature result to obtain the second signature data;

[0076] Step B3: the smart key device generates an authentication response according to the value of the signature counter, the second signature data and the verification success information, and returns the authentication response to the authentication program;

[0077] Specifically, in this embodiment, the smart key device generates an authentication response according to the value of the signature counter, the second signature data and the verification success information, including: the smart key device concatenates the key identifier, the value of the signature counter, the second signature data and the verification success information to obtain the authentication response;

[0078] Correspondingly, step B3 further includes: setting the button state to be invalid;

[0079] Step R2: After the authentication program receives the authentication response returned by the smart key device, if the authentication response contains verification success information, the authentication program verifies the signature data in the authentication response. If the verification is successful, the authentication result containing success information is returned to the PAM, and step R3 is executed. If the verification fails, the authentication result containing failure information is returned to the PAM, and step R3 is executed. If the authentication response contains verification failure information, the authentication result containing failure information is returned to the PAM, and step R3 is executed;

[0080] Specifically, in this embodiment, the authentication program verifies the signature data in the authentication response, including: the authentication program parses the authentication response to obtain a key identifier, a value of a signature counter, and a second signature data, decodes the second signature data to obtain decoded data, decrypts the decoded data using a user public key in the authentication file to obtain a decryption result, generates verification data according to an application parameter in the authentication file, a second preset value, a value of a signature counter, and a second random number, performs a hash calculation on the verification data to obtain a hash result, and determines whether the decryption result matches the hash result, if so, the verification succeeds, otherwise, the verification fails;

[0081] Step R3: the PAM processes the received authentication result according to the control tag to obtain an identity authentication result, and returns the identity authentication result to the operating system or application program;

[0082] In this embodiment, the control tags include: a first type of Optional, a second type of Required, a third type of Requisite, a fourth type of Sufficient, and a fifth type of Binding.

[0083] In the technical solution of the present invention, PAM is used to enable Apple system devices or Linux system devices to directly communicate with the smart key device, thereby authenticating the user identity when logging into the system or using the APP. It can be used in a networkless environment, which is convenient and safe.

[0084] Embodiment 2

[0085] The second embodiment of the present invention provides a method for implementing identity authentication based on PAM, which is applicable to application scenarios such as remote login, lock screen login, identity authentication login, etc. In this embodiment, the login to the operating system is specifically described in detail. The method of this embodiment includes a registration process and an authentication process, such as Figure 2 As shown, the registration process includes:

[0086] Step 100: After the operating system is started, the registration program under the first preset path is installed;

[0087] In this embodiment, the first preset path is / usr / local / FT_PAM / bin, and the registration program is pamu2fcfg;

[0088] Step 101: When the registration interface of the registration program is called, the registration program parses the input parameters to obtain the authentication method and user name;

[0089] Among them, the authentication methods include: Touch authentication (button authentication), PIN authentication + Touch authentication, fingerprint authentication;

[0090] For example, the registration interface in this embodiment is main();

[0091] Specifically, in this embodiment, if the parameter passed in is: / usr / local / FT_PAM / bin / pamu2fcfg -uUSER_NAME, the authentication method obtained by parsing is Touch authentication, and uUSER_NAME is the user name;

[0092] For example, if the parameter passed in is: / usr / local / FT_PAM / bin / pamu2fcfg -uUSER_NAME -N, the authentication method obtained by parsing is PIN authentication, and uUSER_NAME is the user name;

[0093] For example, if the parameter passed in is: / usr / local / FT_PAM / bin / pamu2fcfg -uUSER_NAME -V, the authentication method obtained by parsing is fingerprint authentication, and uUSER_NAME is the user name;

[0094] Step 102: The registration program obtains the authentication method from the smart key device and determines whether the obtained authentication method is consistent with the authentication method obtained by parsing. If yes, step 103 is executed, otherwise an error is reported;

[0095] Among them, the authentication methods include: touch authentication (button authentication), PIN authentication + Touch authentication, fingerprint authentication;

[0096] Step 103: The registration program generates application parameters according to the generated first random number and the user name obtained by parsing, generates a registration instruction according to the first random number and the application parameters, and sends the registration instruction to the smart key device;

[0097] For example, the registration instruction in this embodiment is in APDU format, specifically: 00010000000040CFF69B107235A3E56E18BAA270A3A097DDBD75F4713E7C8126491E9057DC32310102030405060708090A0B0C0D0E0F100102030405060708090A0B0C0D0E0F100000, wherein CFF69B107235A3E56E18BAA270A3A097DDBD75F4713E7C8126491E9057DC3231 57DC32310102030405060708090A0B0C0D0E0F100102030405060708090A0B0C0D0E0F10 is the data in the data domain, CFF69B107235A3E56E18BAA270A3A097DDBD75F4713E7C8126491E9057DC3231 is the first random number of 32 bytes, and 0102030405060708090A0B0C0D0E0F100102030405060708090A0B0C0D0E0F10 is the application parameter of 32 bytes;

[0098] The registration program generates application parameters according to the generated first random number and the user name obtained by parsing, including: the registration program generates a first random number of a preset length and saves it, forms a structure according to the preset first data, the second data, the user name and the first random number, and generates application parameters of the preset length through the first interface according to the structure;

[0099] Furthermore, generating an application parameter of a preset length through the first interface according to the structure includes: generating a first portion of data through a first function in the first interface according to the first data and the second data in the structure, generating a second portion of data through a second function in the first interface according to the user name and the first random number in the structure, and generating an application parameter according to the first portion of data and the second portion of data;

[0100] The preset length is 32 bytes, and the first data and the second data can be preset or input by the user before use;

[0101] The first interface is: prepare_cred(), the structure includes orgin, appid, username and 32-bit random number, the first function is fido_cred_set_rp(), and the second function is fido_cred_set_user();

[0102] Optionally, in this embodiment, if the smart key device supports FIDO authentication, the following may be included before step 103: obtaining a token, and the registration instruction in step 103 also includes a token;

[0103] The token can be saved after the user's identity authentication is successful;

[0104] Step 104: the smart key device parses the registration instruction to obtain the first random number and the application parameter, and determines whether the command header and data length in the registration instruction meet the requirements. If yes, step 105 is executed, otherwise an error is reported;

[0105] Step 105: The smart key device determines whether the value of the signature counter reaches the maximum value, and reports an error if it does, otherwise, executes step 106;

[0106] Step 106: The smart key device determines whether the key state is valid, if so, executes step 107, otherwise reports an error;

[0107] In this embodiment, if the key status of the smart key device is valid, it means that the smart key device has been turned on;

[0108] For example, the error in this step is to return error code 6985 to the registration program;

[0109] Step 107: the smart key device generates and stores a user key pair, performs an XOR operation on the first random number and the user private key to obtain a first intermediate value, and concatenates the first intermediate value, the application parameter, and the device identifier to obtain a first concatenated value;

[0110] In this embodiment, the user key pair includes a user private key and a user public key, the length of the device identifier is 16 bytes, and the length of the first splicing value is 80 bytes; for example, the user key pair is an ECC key pair, wherein the length of the public key is 65 bytes, and the first byte data of the public key is 04;

[0111] Optionally, in this embodiment, before the smart key device generates the user key pair in step 107, the smart key device further includes: determining whether the token stored internally is consistent with the token in the registration instruction, if yes, generating the user key pair and setting the user verification flag to success, otherwise reporting an error and ending;

[0112] Step 108: The smart key device uses the user private key to encrypt the first concatenated value according to the first preset algorithm to generate a first ciphertext, uses the second preset algorithm to perform MAC calculation on the first ciphertext to obtain a first MAC value, and concatenates the first ciphertext and the first MAC value to obtain credential information;

[0113] In this embodiment, the length of the first ciphertext is 80 bytes, the length of the first MAC value is 16 bytes, the first preset algorithm is AESenc, and the second preset algorithm is AESmac;

[0114] Step 109: The smart key device updates the value of the signature counter and generates first signature data according to the credential information;

[0115] Specifically, in this embodiment, generating the first signature data according to the credential information includes: splicing the first preset value, the application parameter, the first random number, the credential information and the user public key to obtain a second splicing value, using a third preset algorithm and a built-in device private key to sign the second splicing value to obtain a first signature result, and performing Der encoding on the first signature result to obtain the first signature data;

[0116] For example, the first preset value in this embodiment is 00;

[0117] Optionally, in this embodiment, before generating the first signature data according to the credential information, the method further includes: determining whether the user verification identification is successful, if yes, generating the first signature data according to the credential information, otherwise reporting an error and ending;

[0118] Step 110: the smart key device generates a registration response according to the user public key, the credential information and the first signature data, returns the registration response to the registration program, and sets the key status to invalid;

[0119] Specifically, in this embodiment, the smart key device generates a registration response according to the user public key, the credential information and the first signature data, including: concatenating the second preset value, the user public key, the credential information length, the credential information, the device certificate, the signature value of the device certificate, and the first signature data to obtain a registration response;

[0120] Among them, the device certificate is the X509 certificate set during production. If the X509 certificate is not set during production, the default device certificate is used; the X509 certificate and device certificate include the device public key;

[0121] The second preset value in this embodiment is 05, and the length of the credential information length is 1 byte;

[0122]

[0123] Among them, 04876D3449C0E14247EE5A785EAD075C3A949BA61F7F835A8B7B1E605B21718FF663E5FBBEE54CB0466CFE965B8AF88515557760CF4ECC64BD0E6E47F7671FB3D2 is the user's public key.

[0124] 0X60 is the length of the credential information.

[0125] A8CCF559C0792DE1E88938AED2975E144FDD5FF1376811B90CA17CDC0666A59B6ACEC983C365BC63C892B24F5C9AE40F51F30D8865E74EABFCB2A997A71F30D7308E047909034150B660353410FB19F08062523A2EA04D244C87BE6A60AF094E is the credential information.

[0126] is the device certificate;

[0127] 3046022100E209FEFCBC800A06728F04224E5375D700ED7FED1277B059DB9343BC18C1CD5D022100B37415E00E40423D5466FE14ED162895E8765846CBA88961F7B9CEBF03F0A8B5 is the signature value of the device certificate;

[0128] 3045022100A9112979C5EAE0ACE36362A3260B2931BB1F8BE4415CD7B6884BC00C4607225B0220535721507A2C2CEC72F874EB81E1F5F1FD063ECEC4DF61F0F9E158818E7399D4 is the first signature data, where the format of the first signature data is a TLV structure (the V field contains 2 TLV structure), 30 is the tag (Tag), 45 is the total length of the TLV structure (Length), 02 is tag1 (indicating the first TLV structure tag), 21 is the length of the first TLV structure (leght1), 00A9112979C5EAE0ACE36362A3260B2931BB1F8BE4415CD7B6884BC00C4607225B is the value of the first TLV structure (R), 02 is tag2 (indicating the second TLV structure tag), 20 is the length of the second TLV structure (leght2), 535721507A2C2CEC72F874EB81E1F5F1FD063ECEC4DF61F0F9E158818E7399D4 is the value of the second TLV structure (S);

[0129] Step 111: The registration program parses the received registration response and saves the parsed credential information, user public key and device certificate, user name, and application parameters in the created authentication file;

[0130] Specifically, the authentication file in this embodiment is: / etc / u2f_mappings;

[0131] In this embodiment, after registration is completed, the user writes the authentication operation instruction in the first line of the PAM configuration file and then performs the authentication process; wherein the PAM configuration file is created in advance by the user, different parameters correspond to different PAM configuration files, and the authentication operation instruction includes: a control mark, an authentication file path, and an authentication program path. The authentication operation instruction can be manually written into the first line of the PAM configuration file by the user or automatically written into the first line of the PAM configuration file by the terminal device;

[0132] In this embodiment, different operations correspond to different authentication types, including: sudo authority authentication, login authentication, restart and logout user login authentication, lock screen login authentication, sshd configuration login authentication;

[0133] The PAM configuration file corresponding to sudo authorization authentication is / etc / pam.d / sudo, the PAM configuration file corresponding to login authentication is / etc / pam.d / login, the PAM configuration file corresponding to restart and logout user login authentication is / etc / pam.d / authorization, the PAM configuration file corresponding to lock screen login authentication is / etc / pam.d / screensaver_new, and the PAM configuration file corresponding to sshd configuration login authentication is / etc / pam.d / sshd;

[0134] If sudo authentication is performed, add the following authentication operation instruction to the first line of the / etc / pam.d / sudo file: auth sufficient / usr / local / FT_PAM / lib / pam_u2f.so authfile= / etc / u2f_mappingsdebug;

[0135] Among them, sufficient is a control mark;

[0136] / usr / local / FT_PAM / lib / pam_u2f.so is the storage path of pam_u2f.so (authentication program);

[0137] authfile= / etc / u2f_mappings is the save path of the authentication file ( / etc / u2f_mappings) during registration;

[0138] If you perform login authentication, add the following authentication operation instruction to the first line of the / etc / pam.d / login file: Auth sufficient / usr / local / FT_PAM / lib / pam_u2f.so authfile= / etc / u2f_mappings;

[0139] If lock screen login authentication is performed, add the following authentication operation instruction to the first line of the / etc / pam.d / screensaver_new file: auth sufficient / usr / local / FT_PAM / lib / pam_u2f.so authfile= / etc / u2f_mappings;

[0140] If you configure sshd for login authentication, add the following authentication operation instruction to the first line of the / etc / pam.d / sshd file: auth sufficient / usr / local / FT_PAM / lib / pam_u2f.so authfile= / etc / u2f_mappings;

[0141] If you want to restart and exit user login authentication, add the following authentication operation instructions to the first line of the / etc / pam.d / authorization file: auth sufficient / usr / local / FT_PAM / lib / pam_u2f.so authfile= / etc / u2f_mappings;

[0142] The certification process is as follows Figure 3 As shown, including:

[0143] Step 201: The operating system starts to obtain the username of the currently logged-in user and loads PAM;

[0144] Step 202: PAM parses the authentication operation instruction in the first line of the corresponding PAM configuration file to obtain the control tag, the authentication file path and the authentication program path, and loads the authentication program according to the authentication program path;

[0145] In this embodiment, the authentication program path is / usr / local / FT_PAM / lib / pam_u2f.so, and the authentication program is pam_u2f.so;

[0146] Step 203: When the authentication interface in the authentication program is called, the authentication program reads the authentication file under the authentication file path, determines whether the currently logged-in user name is consistent with the user name in the authentication file, and if so, generates an authentication instruction based on the credential information and application parameters in the authentication file found and the generated second random number, sends the authentication instruction to the smart key device, and executes step 204; otherwise, reports an error;

[0147] Specifically, the authentication interface in this embodiment is: pam_sm_authenticate();

[0148] The authentication instruction in this embodiment is in APDU format, wherein the third byte data P1, if 03, indicates that a key needs to be pressed, and if 07, indicates that the validity of the credential information needs to be verified, and the data field includes a 32-byte second random number, a 32-byte application parameter, a 1-byte credential information length, and credential information;

[0149] For example, the authentication instruction is: 000203000000A0A4B69B107235A3E56E18BAA270A3A097DDBD75F4713E7C8126491E9057DC32310102030405060708090A0B0C0D0E0F100102030405060708090A0B0C0D0E0F1096A8CCF559C0792DE1E88938 AED2975E144FDD5FF1376811B90CA17CDC0666A59B6ACEC983C365BC63C892B24F5C9AE40F51F30D8865E74 EABFCB2A997A71F30D7308E047909034150B660353410FB19F08062523A2EA04D244C87BE6A60AF094E0000;

[0150] A4B69B107235A3E56E18BAA270A3A097DDBD75F4713E7C8126491E9057DC3231 in the data field is the 32-byte second random number, 0102030405060708090A0B0C0D0E0F100102030405060708090A0B0C0D0E0F10 is the 32-byte application parameter, 96 is the 1-byte credential information length, and A8CCF559C0792 is the credential information length. DE1E88938AED2975E144FDD5FF1376811B90CA17CDC0666A59B6ACEC983C365BC63C892B24F5C9AE40F51F30D8865E74EABFCB2A997A71F30D7308E047909034150B660353410FB19F08062523A2EA04D244C87BE6A60AF094E is the voucher information;

[0151] Step 204: the smart key device parses the received authentication instruction to obtain a command header, a second random number, application parameters, credential information length, and credential information;

[0152] Step 205: the smart key device determines whether the length of the command header and the credential information meets the requirements, if yes, executes step 206, otherwise returns an authentication response including authentication failure information to the authentication program, and executes step 213;

[0153] Step 206: The smart key device determines whether the value of the signature counter reaches the maximum value. If yes, it returns an authentication response including verification failure information to the authentication program and executes step 213. Otherwise, it executes step 207.

[0154] Step 207: the smart key device determines the third byte data in the authentication instruction, if it is 07, execute step 208, if it is 03, execute step 209;

[0155] Step 208: The smart key device verifies the credential information according to the stored first random number, application parameters, and stored user private key. If the verification succeeds, step 210 is executed. If the verification fails, an authentication response including verification failure information is returned to the authentication program, and step 213 is executed.

[0156] Specifically, step 208 specifically includes: the smart key device performs an XOR operation on the stored first random number and the stored user private key to obtain a first verification intermediate value, splices the first verification intermediate value, the application parameter and the device identifier to obtain a first verification splicing value, uses the user private key to encrypt the first verification splicing value according to a first preset algorithm to generate a first verification ciphertext, uses a second preset algorithm to perform MAC calculation on the first verification ciphertext to obtain a first verification MAC value, determines whether the first verification MAC value is consistent with the first MAC value in the credential information, if yes, the verification is successful, and executes step 210, otherwise the verification fails, and returns an authentication response containing verification failure information to the authentication program, and executes step 213;

[0157] In this embodiment, the verification failure in step 208 returns an error code to the authentication program, for example, the error code is 6A80;

[0158] Step 209: the smart key device checks whether the key state is valid, if so, executes step 210, otherwise returns an authentication response including authentication failure information to the authentication program, and executes step 213;

[0159] In this embodiment, when the judgment in step 209 is no, an error code is returned to the authentication program, for example, the error code is 6985;

[0160] Step 210: the smart key device uses the user public key to decrypt the first ciphertext in the credential information according to the first preset algorithm to obtain a first concatenated value, and determines whether the application parameters and device identification in the first concatenated value are consistent with the application parameters and device identification stored in the device. If all of them are determined to be consistent, step 211 is executed; otherwise, an authentication response containing verification failure information is returned to the authentication program, the value of the signature counter is updated, and step 213 is executed;

[0161] In this embodiment, when the judgment in step 210 is negative, an error code is returned to the middleware, for example, the error code is 6A80;

[0162] Optionally, updating the value of the signature counter is specifically as follows: the value of the signature counter is incremented by 1;

[0163] Step 211: the smart key device generates data to be signed according to the application parameter, the second random number and the value of the signature counter, signs the data to be signed using the user private key to obtain a second signature result, and performs Der encoding on the second signature result to obtain second signature data;

[0164] Specifically, in this embodiment, step 211 specifically includes: the smart key device concatenates the application parameter, the second preset value, the value of the signature counter, and the second random number to obtain the data to be signed, calculates a digest of the data to be signed according to the fourth preset algorithm to obtain a digest value, signs the digest value using the user private key to obtain a second signature result, and performs Der encoding on the second signature result to obtain the second signature data;

[0165] For example, the second preset value in this embodiment is 01, the value of the signature counter is 4-byte length data; the fourth preset algorithm is the SHA256 algorithm;

[0166] Step 212: the smart key device generates an authentication response according to the value of the signature counter, the second signature data and the verification success information, returns the authentication response to the authentication program, and sets the key state to be invalid;

[0167] Specifically, in step 212, the smart key device generates an authentication response according to the value of the signature counter, the second signature data and the verification success information, including: concatenating the key identifier, the value of the signature counter, the second signature data and the verification success information to obtain the authentication response;

[0168] The key identifier is used to identify whether a key is involved. For example, 01 indicates that the authentication process has key confirmation, and 00 indicates that the authentication process has no key confirmation.

[0169] For example, the authentication response is 0100000039304402200EFB59F91668F2380343746217D969B46633C49FE3661B903ACCE1B2FDD4191A0220672ECD2DA698FA373483B767DF1CE707465A22F1825023DEB837DDBDDEC0C9D69000;

[0170] Among them, 0X01 is the key identifier, 00000003 is the value of the signature counter, 304402200EFB59F91668F2380343746217D969B46633C49FE3661B903ACCE1B2FDD4191A0220672ECD2DA698FA373483B767DF1CE707465A22F1 825023DEB837DDBDDEC0C9D6 is the second signature data (30 is the tag, 44 is the total length, 02 is the first structure tag, 20 is the length of the first structure, 0EFB59F91668F2380343746217D969B46633C49FE3661B903ACCE1B2FDD4191A is the value of the first structure (public key), 02 is the second structure tag, 20 is the length of the second structure, 672ECD2DA698FA373483B767DF1CE707465A22F1825023DEB837DDBDDEC0C9D6 is the value of the second structure (signature value), 9000 is the verification success information;

[0171] Step 213: The authentication program receives the authentication response returned by the smart key device, and determines whether the authentication response contains verification success information. If yes, execute step 214; otherwise, return the authentication result containing failure information to the PAM, and execute step 215;

[0172] Step 214: the authentication program verifies the second signature data in the authentication response. If the verification succeeds, the authentication result including success information is returned to the PAM, and step 215 is executed. If the verification fails, the authentication result including failure information is returned to the PAM, and step 215 is executed.

[0173] Specifically, in this embodiment, the authentication program verifies the second signature data in the authentication response, including: the authentication program parses the authentication response to obtain the key identifier, the value of the signature counter and the second signature data, decodes the second signature data to obtain decoded data, decrypts the decoded data using the user public key in the authentication file to obtain a decryption result, generates verification data according to the application parameter, the second random number and the value of the signature counter in the authentication file, performs hash calculation on the verification data to obtain a hash result, and determines whether the decryption result matches the hash result, if yes, the verification succeeds, otherwise the verification fails;

[0174] Step 215: PAM processes the received authentication result according to the control tag to obtain an identity authentication result, and returns the identity authentication result to the operating system;

[0175] The control tags include Binding (the user identity can be authenticated only when the authentication results of all authentication operation instructions with Binding tags are all successful; if an error occurs during the processing of any authentication operation instruction with Required tag, PAM does not immediately return the failed authentication result to the operating system, but returns the failed authentication result to the operating system after all authentication operation instructions are processed), Requisite (the user identity can be authenticated only when the authentication results of all authentication operation instructions with Requisite tag are all successful; if an error occurs during the processing of any authentication operation instruction with Requisite tag, PAM immediately returns the failed authentication result to the operating system), Sufficient (if the authentication result of the authentication operation instruction with sufficient tag is successful and no necessary failure information is recorded, PAM immediately returns the successful authentication result to the operating system without processing other authentication operation instructions), as well as Optional and Required (if an error occurs during the processing of the authentication operation instruction with Optional or Required tag, the next authentication operation instruction will continue to be processed, that is, even if an error occurs during the processing of the specified authentication operation instruction, the user is allowed to enjoy the services provided by the operating system);

[0176] Specifically, in this embodiment, the specific implementation process of step 215 is as follows: Figure 4 As shown, including:

[0177] Step T1: PAM determines the type of the control tag. If it is Optional, it executes step T2; if it is Required, it executes step T5; if it is Requisite, it executes step T8; if it is Sufficient, it executes step T11; if it is Binding, it executes step T14;

[0178] Step T2: PAM determines whether the authentication result includes success information. If yes, it executes step T3; otherwise, it executes step T4.

[0179] Step T3: PAM records this authentication as optional success information and executes step T17;

[0180] Step T4: PAM determines whether necessary failure information is recorded. If yes, execute step T17. Otherwise, record the necessary failure information of this authentication and execute step T17.

[0181] Step T5: PAM determines whether the authentication result includes success information. If yes, it executes step T6; otherwise, it executes step T7.

[0182] Step T6: PAM records the necessary success information for this authentication and executes step T17;

[0183] Step T7: PAM determines whether necessary failure information is recorded. If yes, execute step T17; otherwise, record the necessary failure information of this authentication and execute step T17;

[0184] Step T8: PAM determines whether the authentication result includes success information, if yes, executes step T9, otherwise executes step T10;

[0185] Step T9: PAM records the necessary success information of this authentication and executes step T17;

[0186] Step T10: PAM records the authentication as the necessary failure information or the first necessary failure information, returns the identity authentication result as failure to the operating system, and executes step 216;

[0187] Step T11: PAM determines whether the authentication result includes success information, if yes, executes step T12, otherwise executes step T13;

[0188] Step T12: PAM determines whether necessary failure information is recorded. If yes, it records necessary success information for this authentication and executes step T17. Otherwise, it records necessary success information for this authentication and returns the identity authentication result as success to the operating system and executes step 216.

[0189] Step T13: PAM determines whether the necessary failure information is recorded. If yes, execute step T17; otherwise, record the failure information of this authentication as optional and execute step T17;

[0190] Step T14: PAM determines whether the authentication result includes success information, if yes, executes step T15, otherwise executes step T16;

[0191] Step T15: PAM determines whether necessary failure information is recorded. If yes, it records necessary success information for this authentication and executes step T17. Otherwise, it records necessary success information for this authentication and returns the identity authentication result as success to the operating system and executes step 216.

[0192] Step T16: PAM determines whether necessary failure information is recorded. If yes, execute step T17. Otherwise, record the necessary failure information of this authentication and execute step T17.

[0193] Step T17: PAM determines whether the current authentication operation instruction is the last authentication operation instruction in the PAM configuration file. If yes, step T18 is executed. Otherwise, the process returns to step 202 to parse the next authentication operation instruction in the PAM configuration file.

[0194] Step T18: PAM determines whether the necessary failure information is recorded. If yes, it returns the identity authentication result as failure to the operating system and executes step 216. Otherwise, it executes step T19.

[0195] Step T19: PAM determines whether the necessary success information is recorded. If yes, it returns the identity authentication result to the operating system as success, and executes step 216. Otherwise, it returns the identity authentication result to the operating system as failure, and executes step 216.

[0196] Step 216: The operating system performs subsequent operations according to the received identity authentication result;

[0197] Specifically, in this embodiment, step 216 also includes: if the identity authentication result is successful, allowing the user to log in; if the identity authentication result is failed, denying the user to log in.

[0198] The method in this embodiment is also applicable to the scenario of verifying the user identity when logging into an application, that is, the executor of steps 201 and 216 is the application, and step 216 also includes: if the identity authentication result is successful, the application allows the user to access, if the identity authentication result is failed, the application denies the user access.

[0199] Embodiment 3

[0200] Embodiment 3 of the present invention provides a system for implementing identity authentication based on PAM, such as Figure 5 As shown, it includes registration module, authentication module and PAM module. The registration module includes:

[0201] The receiving and parsing unit is used to parse the incoming parameters to obtain the authentication method and user name when the registration interface is called during the registration program running;

[0202] An acquisition and judgment unit is used to acquire an authentication method from a smart key device, and judge whether the acquired authentication method is consistent with the authentication method obtained by parsing. If yes, the first generation and sending unit is triggered, otherwise an error is reported;

[0203] A first generating and sending unit, used to generate application parameters according to the generated first random number and the user name, generate a registration instruction according to the first random number and the application parameters, and send the registration instruction to the smart key device;

[0204] In this embodiment, the first generating and sending unit generates application parameters according to the generated first random number and the user name, including: the first generating and sending unit generates a first random number of a preset length, forms a structure according to the preset first data, the second data, the user name and the first random number, and generates application parameters of the preset length through the first interface according to the structure;

[0205] More specifically, generating an application parameter of a preset length through the first interface according to the structure includes: generating a first portion of data through a first function in the first interface according to the first data and the second data in the structure, generating a second portion of data through a second function in the first interface according to the user name and the first random number in the structure, and generating an application parameter according to the first portion of data and the second portion of data;

[0206] In this embodiment, the operation performed by the smart key device after receiving the registration instruction is the same as that of Embodiment 1 and Embodiment 2, and will not be described in detail here;

[0207] The parsing and saving unit is used to parse the registration response returned by the smart key device when receiving the registration response, and save the credential information and user public key, application parameters, and user name obtained by parsing in the authentication file;

[0208] The system also includes a writing module, which is used to write the authentication operation instruction in the first line of the PAM configuration file, and the authentication operation instruction includes: a control mark, an authentication file path and an authentication program path;

[0209] The certification modules include:

[0210] A reading and judging unit is used to read the authentication file under the authentication file path when the authentication interface in the authentication program is called by the PAM module, and judge whether the currently logged-in user name is consistent with the user name in the authentication file. If yes, the second generation and sending unit is triggered, otherwise an error is reported;

[0211] A second generating and sending unit, used to generate an authentication instruction according to the credential information and application parameters in the authentication file found and the generated second random number, and send the authentication instruction to the smart key device;

[0212] In this embodiment, the operation performed by the smart key device after receiving the authentication instruction is the same as that of Embodiment 1 and Embodiment 2, and will not be described in detail here;

[0213] A receiving verification return unit, configured to, after receiving an authentication response returned by the smart key device, if the authentication response contains verification success information, the authentication program verifies the signature data in the authentication response, and if the verification is successful, returns an authentication result containing success information to the PAM module, and if the verification fails, returns an authentication result containing failure information to the PAM module, and if the authentication response contains verification failure information, returns an authentication result containing failure information to the PAM module;

[0214] In this embodiment, the receiving and verifying unit verifies the signature data in the authentication response, including: the receiving and verifying unit parses the authentication response to obtain a key identifier, a value of a signature counter, and a second signature data, decodes the second signature data to obtain decoded data, decrypts the decoded data using a user public key in the authentication file to obtain a decryption result, generates verification data according to an application parameter in the authentication file, a second preset value, a value of a signature counter, and a second random number, performs a hash calculation on the verification data to obtain a hash result, and determines whether the decryption result matches the hash result, if so, the verification succeeds, otherwise, the verification fails;

[0215] The PAM module is used to process the authentication result according to the control tag to obtain the identity authentication result, and return the identity authentication result to the operating system or application program;

[0216] In this embodiment, the authentication result is processed according to the control mark to obtain the identity verification result, and the specific implementation process of returning the identity verification result to the operating system or application is the same as step 215 in the second embodiment, which will not be repeated here.

[0217] The system also includes an acquisition loading module, which is used to obtain the current logged-in user name and load the corresponding PAM module when the user logs into the operating system;

[0218] The PAM module is also used to parse the authentication operation instructions in the first line of the corresponding PAM configuration file to obtain the control mark, authentication file path and authentication program path, and load the authentication program according to the authentication program path.

[0219] Optionally, an embodiment of the present application further provides an electronic device, the electronic device comprising at least one processor, a memory, and instructions stored in the memory and executable by at least one processor, and at least one processor executes the instructions to implement the method for identity authentication based on PAM in the above embodiment. When the electronic device is a chip system, it can be composed of a chip, or it can include a chip and other discrete devices, which is not specifically limited in the embodiment of the present application; the chip is coupled to the memory, and is used to execute a computer program stored in the memory to execute the method for identity authentication based on PAM disclosed in the above embodiment.

[0220] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using a software program, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs. When a computer program is loaded and executed on an electronic device, the process or function described in the embodiment of the present application is generated in whole or in part. The computer program can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a base station, electronic device, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another base station, electronic device, server or data center. The computer-readable storage medium can be any available medium that can be accessed by an electronic device or a data storage device such as a server or data center that contains one or more media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc. In the embodiment of the present application, the electronic device may include the system described above.

[0221] Although the present application is described herein in conjunction with various embodiments, in the process of implementing the claimed application, those skilled in the art may understand and implement other variations of the disclosed embodiments by viewing the drawings, the disclosure, and the appended claims. In the claims, the word "comprising" does not exclude other components or steps, and "one" or "an" does not exclude multiple situations. A single processor or other unit may implement several functions listed in a claim. Certain measures are recorded in different dependent claims, but this does not mean that these measures cannot be combined to produce good results.

[0222] Although the present application has been described in conjunction with specific features and embodiments thereof, it is obvious that various modifications and combinations may be made thereto without departing from the spirit and scope of the present application. Accordingly, this specification and the drawings are merely exemplary illustrations of the present application as defined by the appended claims, and are deemed to have covered any and all modifications, variations, combinations or equivalents within the scope of the present application. Obviously, those skilled in the art may make various modifications and variations to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A method for implementing identity authentication based on PAM, characterized in that: The registration process includes a registration process and an authentication process. The registration process includes: Step S1: When the registration interface is called during the operation of the registration program, the registration program parses the input parameters to obtain the authentication method and user name; Step S2: The registration program obtains the authentication method from the smart key device, and determines whether the obtained authentication method is consistent with the authentication method obtained by parsing. If yes, step S3 is executed, otherwise an error is reported; Step S3: the registration program generates application parameters according to the generated first random number and the user name, generates a registration instruction according to the first random number and the application parameters, and sends the registration instruction to the smart key device; Step S4: When the registration program receives the registration response returned by the smart key device, the registration response is parsed, and the credential information and user public key, the application parameters, and the user name obtained by parsing are saved in the authentication file; After step S4, the method further includes: writing an authentication operation instruction in the first line of the PAM configuration file, wherein the authentication operation instruction includes: a control mark, an authentication file path, and an authentication program path; The authentication process includes: Step R1: When the authentication interface in the authentication program is called by the PAM, the authentication program reads the authentication file under the authentication file path, determines whether the currently logged-in user name is consistent with the user name in the authentication file, and if so, generates an authentication instruction based on the credential information and application parameters in the authentication file found and the generated second random number, sends the authentication instruction to the smart key device, and executes step R2; otherwise, an error is reported; Step R2: After the authentication program receives the authentication response returned by the smart key device, if the authentication response contains verification success information, the authentication program verifies the signature data in the authentication response, and if the verification is successful, returns the authentication result containing success information to the PAM, and executes step R3; if the verification fails, returns the authentication result containing failure information to the PAM, and executes step R3; if the authentication response contains verification failure information, returns the authentication result containing failure information to the PAM, and executes step R3; Step R3: the PAM processes the received authentication result according to the control tag to obtain an identity authentication result, and returns the identity authentication result to the operating system or application program; Before step R1, it also includes: when the user logs in to the operating system or application, the currently logged-in user name is obtained and the corresponding PAM is loaded, the PAM parses the authentication operation instruction in the first line of the corresponding PAM configuration file to obtain the control mark, the authentication file path and the authentication program path, and loads the authentication program according to the authentication program path.

2. The method for implementing identity authentication based on PAM as claimed in claim 1, characterized in that: The registration program in step S3 generates application parameters based on the generated first random number and the user name, including: the registration program generates a first random number of a preset length, forms a structure based on preset first data, second data, the user name and the first random number, and generates application parameters of a preset length through a first interface based on the structure.

3. The method for implementing identity authentication based on PAM as claimed in claim 2, characterized in that: The method of generating application parameters of preset length according to the structure through the first interface includes: generating a first portion of data according to the first data and the second data in the structure through a first function in the first interface, generating a second portion of data according to the user name and the first random number in the structure through a second function in the first interface, and generating application parameters according to the first portion of data and the second portion of data.

4. The method for implementing identity authentication based on PAM as claimed in claim 1, characterized in that: Also includes: Step A1: The smart key device receives the registration instruction, parses the registration instruction to obtain the first random number and application parameters and saves them, and determines whether the registration conditions are met. If yes, step A2 is executed, otherwise an error is reported; Step A2: the smart key device generates credential information according to the first random number, the application parameter, and the stored user private key, updates the value of the signature counter, and generates first signature data according to the credential information; Step A3: The smart key device generates a registration response according to the stored user public key, the credential information and the first signature data, and returns the registration response to the registration program.

5. The method for implementing identity authentication based on PAM as claimed in claim 4, characterized in that: The determination of whether the registration conditions are met in step A1 includes: Step A11: the smart key device determines whether the command header and data length obtained by parsing the registration instruction meet the requirements, and if so, executes step A12, otherwise reports an error; Step A12: the smart key device determines whether the value of the signature counter reaches the maximum value, and reports an error if it does, otherwise executes step A13; Step A13: The smart key device determines whether the key state is valid, and if so, executes step A2, otherwise reports an error; The step A3 also includes: setting the button status to invalid.

6. The method for implementing identity authentication based on PAM as claimed in claim 4, characterized in that: The smart key device in step A2 generates credential information based on the first random number, the application parameters, and the saved user private key, including: the smart key device generates and saves a user key pair, performs an XOR operation on the first random number and the user private key in the user key pair to obtain a first intermediate value, concatenates the first intermediate value, the application parameters, and a device identifier to obtain a first concatenated value, uses the user private key to encrypt the first concatenated value according to a first preset algorithm to generate a first ciphertext, uses a second preset algorithm to perform MAC calculation on the first ciphertext to obtain a first MAC value, and concatenates the first ciphertext with the first MAC value to obtain credential information.

7. The method for implementing identity authentication based on PAM as claimed in claim 4, characterized in that: The generating of the first signature data according to the credential information in step A2 includes: concatenating the first preset value, the application parameter, the first random number, the credential information, and the user public key in the user key pair to obtain a second concatenated value, signing the second concatenated value using a third preset algorithm and a built-in device private key to obtain a first signature result, and encoding the first signature result to obtain first signature data.

8. The method for implementing identity authentication based on PAM as claimed in claim 4, characterized in that: The smart key device generates a registration response based on the saved user public key, the credential information and the first signature data, including: splicing the second preset value, the saved user public key, the length of the credential information, the credential information, the device certificate, and the first signature data to obtain a registration response.

9. The method for implementing identity authentication based on PAM as claimed in claim 1, characterized in that: Also includes: Step B1: the smart key device parses the authentication instruction to obtain the credential information, application parameters and the second random number, and determines whether the authentication condition is met. If yes, step B2 is executed; otherwise, an authentication response including verification failure information is returned to the authentication program; Step B2: the smart key device generates the data to be signed according to the application parameter, the second random number, and the value of the signature counter, signs the data to be signed using the stored user private key to obtain a second signature result, and encodes the second signature result to obtain second signature data; Step B3: The smart key device generates an authentication response according to the value of the signature counter, the second signature data and the verification success information, and returns the authentication response to the authentication program.

10. The method for implementing identity authentication based on PAM as claimed in claim 9, characterized in that: The determination of whether the authentication condition is met in step B1 includes: Step B11: the smart key device determines whether the length of the command header and the credential information obtained by parsing the authentication instruction meets the requirements, and if so, executes step B12, otherwise returns an authentication response containing verification failure information to the authentication program; Step B12: the smart key device determines whether the value of the signature counter reaches the maximum value, and if so, returns an authentication response including verification failure information to the authentication program, otherwise, executes step B13; Step B13: the smart key device determines the third byte data in the authentication instruction, and if it is the third byte data, executes step B14; if it is the fourth byte data, executes step B15; Step B14: the smart key device verifies the credential information according to the first random number, the application parameter, and the user private key. If the verification succeeds, step B16 is executed. If the verification fails, an authentication response including verification failure information is returned to the authentication program. Step B15: the smart key device checks whether the key state is valid, and if so, executes step B16, otherwise returns an authentication response including authentication failure information to the authentication program; Step B16: the smart key device uses the user public key to decrypt the first ciphertext in the credential information according to a first preset algorithm to obtain a first concatenated value, and determines whether the application parameters and device identification in the first concatenated value are consistent with the application parameters and device identification stored in the device. If all of them are determined to be consistent, step B2 is executed; otherwise, an authentication response containing verification failure information is returned to the authentication program, and the value of the signature counter is updated; Step B3 also includes: setting the button state to be invalid.

11. The method for implementing identity authentication based on PAM as claimed in claim 10, characterized in that: The step B14 includes: the smart key device performs an XOR operation on the first random number and the user private key to obtain a first verification intermediate value, concatenates the first verification intermediate value, the application parameter and the device identifier to obtain a first verification concatenation value, uses the user private key to encrypt the first verification concatenation value according to a first preset algorithm to generate a first verification ciphertext, uses a second preset algorithm to perform MAC calculation on the first verification ciphertext to obtain a first verification MAC value, and determines whether the first verification MAC value is consistent with the first MAC value in the credential information. If so, the verification is successful and step B16 is executed; otherwise, the verification fails and an authentication response containing verification failure information is returned to the authentication program.

12. The method for implementing identity authentication based on PAM as claimed in claim 9, characterized in that: The step B2 includes: the smart key device concatenates the application parameter, the second preset value, the value of the signature counter and the second random number to obtain the data to be signed, uses the saved user private key to sign the data to be signed according to the fourth preset algorithm to obtain a second signature result, and encodes the second signature result to obtain second signature data.

13. The method for implementing identity authentication based on PAM as claimed in claim 9, characterized in that: The smart key device generates an authentication response according to the value of the signature counter, the second signature data and the verification success information, including: the smart key device concatenates the key identifier, the value of the signature counter, the second signature data and the verification success information to obtain the authentication response.

14. The method for implementing identity authentication based on PAM as claimed in claim 1, characterized in that: The authentication program in step R2 verifies the signature data in the authentication response, including: the authentication program parses the authentication response to obtain a key identifier, a signature counter value, and a second signature data, decodes the second signature data to obtain decoded data, decrypts the decoded data using the user public key in the authentication file to obtain a decryption result, generates verification data according to application parameters in the authentication file, a second preset value, the signature counter value, and the second random number, performs hash calculation on the verification data to obtain a hash result, and determines whether the decryption result matches the hash result. If so, verification succeeds, otherwise, verification fails.

15. The method for implementing identity authentication based on PAM as claimed in claim 1, characterized in that: The step R3 comprises: Step R2-1: The PAM determines the type of the control mark, and if it is the first type, executes step R2-2; if it is the second type, executes step R2-5; if it is the third type, executes step R2-8; if it is the fourth type, executes step R2-11; if it is the fifth type, executes step R2-14; Step R2-2: The PAM determines whether the authentication result includes success information, if yes, executes step R2-3, otherwise executes step R2-4; Step R2-3: The PAM records this authentication as optional success information, and executes step R2-17; Step R2-4: The PAM determines whether necessary failure information is recorded, if yes, executes step R2-17, otherwise, records the necessary failure information of this authentication, and executes step R2-17; Step R2-5: The PAM determines whether the authentication result includes success information, if yes, executes step R2-6, otherwise executes step R2-7; Step R2-6: The PAM records the necessary success information for this authentication, and executes step R2-17; Step R2-7: The PAM determines whether necessary failure information is recorded, if yes, executes step R2-17, otherwise, records the necessary failure information of this authentication, and executes step R2-17; Step R2-8: The PAM determines whether the authentication result includes success information, if yes, executes step R2-9, otherwise, executes step R2-10; Step R2-9: The PAM records the necessary success information of this authentication and executes step R2-17; Step R2-10: the PAM records the necessary failure information or the first necessary failure information of this authentication, and returns the identity authentication result as failure to the operating system or application; Step R2-11: The PAM determines whether the authentication result includes success information, if yes, executes step R2-12, otherwise, executes step R2-13; Step R2-12: The PAM determines whether necessary failure information is recorded. If yes, the PAM records necessary success information for this authentication and executes step R2-17. Otherwise, the PAM records necessary success information for this authentication and returns a successful identity authentication result to the operating system or application. Step R2-13: The PAM determines whether the necessary failure information is recorded, and if so, executes step R2-17; otherwise, records the failure information of this authentication as optional, and executes step R2-17; Step R2-14: the PAM determines whether the authentication result includes success information, if yes, executes step R2-15, otherwise, executes step R2-16; Step R2-15: The PAM determines whether necessary failure information is recorded. If yes, the PAM records necessary success information for this authentication and executes step R2-17. Otherwise, the PAM records necessary success information for this authentication and returns a successful identity authentication result to the operating system or application. Step R2-16: The PAM determines whether necessary failure information is recorded, if yes, executes step R2-17, otherwise, records the necessary failure information of this authentication, and executes step R2-17; Step R2-17: the PAM determines whether the current authentication operation instruction is the last authentication operation instruction in the PAM configuration file, if yes, executes step R2-18, otherwise processes the next authentication operation instruction in the PAM configuration file; Step R2-18: The PAM determines whether the necessary failure information is recorded. If yes, it returns the identity authentication result as failure to the operating system or application program. Otherwise, it executes step R2-19. Step R2-19: The PAM determines whether the necessary success information is recorded. If so, it returns an authentication result of success to the operating system or application. Otherwise, it returns an authentication result of failure to the operating system or application.

16. A system for implementing identity authentication based on PAM, characterized in that: It includes a registration module, an authentication module and a PAM module. The registration module includes: The receiving and parsing unit is used to parse the incoming parameters to obtain the authentication method and user name when the registration interface is called during the registration program running; An acquisition and judgment unit, used for acquiring an authentication method from a smart key device, and judging whether the acquired authentication method is consistent with the authentication method obtained by parsing, and if so, triggering the first generation and sending unit, otherwise reporting an error; The first generating and sending unit is used to generate application parameters according to the generated first random number and the user name, generate a registration instruction according to the first random number and the application parameter, and send the registration instruction to the smart key device; A parsing and saving unit, configured to parse the registration response returned by the smart key device upon receiving the registration response, and save the credential information and user public key, the application parameters, and the user name obtained by parsing in an authentication file; The system also includes a writing module, which is used to write an authentication operation instruction in the first line of the PAM configuration file, wherein the authentication operation instruction includes: a control mark, an authentication file path, and an authentication program path; The authentication module comprises: a reading and judging unit, configured to read the authentication file under the authentication file path when the authentication interface in the authentication program is called by the PAM module, and judge whether the currently logged-in user name is consistent with the user name in the authentication file, and trigger the second generating and sending unit if yes, otherwise reporting an error; The second generating and sending unit is used to generate an authentication instruction according to the credential information and application parameters in the authentication file found and the generated second random number, and send the authentication instruction to the smart key device; a receiving verification return unit, configured to receive an authentication response returned by the smart key device, and if the authentication response contains verification success information, the authentication program verifies the signature data in the authentication response, and if the verification is successful, returns an authentication result containing success information to the PAM module, and if the verification fails, returns an authentication result containing failure information to the PAM module, and if the authentication response contains verification failure information, returns an authentication result containing failure information to the PAM module; The PAM module is used to process the authentication result according to the control mark to obtain an identity authentication result, and return the identity authentication result to the operating system or application program; The system also includes an acquisition loading module, which is used to obtain the current logged-in user name and load the corresponding PAM module when the user logs in to the operating system or application program; The PAM module is also used to parse the authentication operation instruction in the first line of the corresponding PAM configuration file to obtain the control mark, the authentication file path and the authentication program path, and load the authentication program according to the authentication program path.

17. An electronic device, characterized in that: The electronic device includes at least one processor, a memory, and instructions stored in the memory and executable by the at least one processor, and the at least one processor executes the instructions to implement the method according to any one of claims 1 to 15.

18. A computer-readable storage medium, characterized in that: The computer-readable storage medium comprises a computer program, and when the computer program is executed on an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 15.

19. A chip system, characterized in that: The invention comprises a chip, wherein the chip is coupled to a memory and is used to execute a computer program stored in the memory to execute the method according to any one of claims 1 to 15.