A method and module for securely inputting and verifying USBKey PIN code
By installing the kernel keyboard hook in the kernel driver to intercept and encode the USBKey PIN code, the monitoring and interception problems of the PIN code input and verification process in the prior art are solved, and the security of the USBKey system is significantly improved.
Patent Information
- Application Number
- CN201911405393.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-31
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2039-12-31
AI Technical Summary
The prior art cannot effectively prevent viruses or Trojans from monitoring and intercepting USBKey PIN code input and verification processes, resulting in leakage of PIN information and affecting the security of USBKey system.
By installing the kernel keyboard hook in the kernel driver, the PIN code entered by the physical keyboard is intercepted, and the PIN code entered by the soft keyboard is encoded and parsed, to prevent the leakage of PIN information and improve the security of the input and verification process.
Effectively prevent viruses or Trojans from monitoring and intercepting PIN codes, prevent PIN information from leaking, and improve security when using USBKey.
Smart Images

Figure CN111222128B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to, in particular to, a method and module for safely inputting and verifying a USBKey PIN code. Background Art
[0002] As an identity authentication medium, USBKey is widely used in identity authentication and financial transfer transactions. Its characteristic is that the private key is stored in a secure storage area inside the USBKey and is not allowed to leave the device.
[0003] When using USBKey for identity authentication or transfer transactions, you need to verify the USBKey PIN code first and obtain the USBKey user authority before you can use the private key in the Key for signing or decryption operations. The leakage of the PIN code directly affects the security of the USBKey system. An attacker can monitor the PIN code through a Trojan or virus and steal the USBKey device, and then illegally obtain the right to use the private key in the Key. The existing technology mainly protects the PIN code through the following methods:
[0004] (1) Install the application layer keyboard hook to improve the security of the PIN input process. When entering the USBKey PIN code, the application layer pops up the PIN code UI window and installs the WH_KEYBOARD or WH_KEYBOARD_LL keyboard hook to intercept and protect the PIN code entered through the keyboard. However, this method can only intercept the application layer's monitoring and intercepting keyboard recording behaviors, and cannot protect the kernel layer keyboard filter driver from monitoring the PIN code.
[0005] (2) Replace the pointer of the dispatch function of the existing kbdclass keyboard class driver object. Directly hook the IRP_MJ_READ read request processing dispatch function KeyboardClassRead of the keyboard class driver to filter the keyboard read request. However, the keyboard class driver receives the keyboard's IRP request later than the filter driver bound to the keyboard class driver device stack. If other keyboard class filter driver devices are installed in the system, the IRP information of the keyboard class driver's read request processing will be processed by the filter driver on the device stack, and the PIN information entered by the keyboard will be easily leaked. Simply replacing the KeyboardClassRead dispatch function is not conducive to the installation and uninstallation of the driver. The keyboard's read request is always in an "unfinished" state, which can easily cause a blue screen crash when a key is pressed.
[0006] (3) Install a keyboard filter device in the keyboard device stack, bind the device to the keyboard filter driver device, and monitor and intercept keyboard input behavior from the kernel driver layer. However, the IRP request generated when a keyboard key is pressed is first sent to the filter driver bound to the keyboard filter driver device. There can be multiple filter driver devices on the device stack, and the keyboard filter driver device at the top of the stack receives the IRP request and obtains the keyboard data first. The data on the device stack is related to the order in which the filter drivers are installed. If other filter drivers obtain the keyboard data first, the input PIN information will be leaked. Summary of the invention
[0007] In view of the defects existing in the prior art, the purpose of the present invention is to provide a method and module for securely inputting and verifying USBKey PIN codes, by installing a kernel keyboard hook in the kernel driver through the application layer, so as to prevent viruses or Trojan programs from monitoring and intercepting the PIN code input and verification process, prevent PIN information leakage, and improve the security when using USBKey.
[0008] To achieve the above purpose, the technical solution adopted by the present invention is as follows:
[0009] A method for safely inputting and verifying a USBKey PIN code, the method comprising: installing a kernel keyboard hook, inputting a USBKey PIN code, verifying the USBKey PIN code, and uninstalling the kernel keyboard hook;
[0010] The inputting of USBKey PIN code includes: inputting USBKey PIN code by soft keyboard and inputting USBKey PIN code by physical keyboard, wherein the inputting of USBKey PIN code by soft keyboard includes:
[0011] The application layer of the USBKey encodes the PIN code input by the soft keyboard, and sends the encoded PIN code and corresponding identification information to the kernel driver of the USBKey;
[0012] The kernel driver obtains the memory location of the encoded PIN code in the kernel driver according to the identification information of the encoded PIN code, parses the encoded PIN code, and appends the parsed PIN code to the end of the memory location to complete the soft keyboard input of the PIN code;
[0013] The physical keyboard input USBKey PIN code includes:
[0014] The kernel driver intercepts the PIN code input by the physical keyboard through the currently installed kernel keyboard hook, obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, appends the current PIN code to the end of the memory location, and completes the physical keyboard input of the PIN code;
[0015] The verification of the USBKey PIN code includes:
[0016] The application layer sends a verification PIN instruction and identification information of the current PIN code to the kernel driver;
[0017] The kernel driver obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, extracts the current PIN code, encrypts and encapsulates the current PIN code into ciphertext information, and returns it to the application layer;
[0018] The application layer forwards the ciphertext information to the USBKey for verification.
[0019] Further, in the above-mentioned method for securely inputting and verifying a USBKey PIN code, the installation of the kernel keyboard hook comprises:
[0020] When the PIN input window acquires the focus, the application layer opens the kernel driver device;
[0021] When the kernel driver device is successfully opened, the application layer sends a first IOCtrl instruction to the kernel driver to start the kernel keyboard hook;
[0022] When the kernel keyboard hook is started, the application layer sends the identification information of the PIN code to the kernel driver, and the identification information of the PIN code includes: USBKey device handle information, process and thread information of the PIN input window, PIN input window handle, PIN operation type, PIN complexity, PIN length, random number and algorithm identification.
[0023] Further, in the above-mentioned method for securely inputting and verifying a USBKey PIN code, the installation of the kernel keyboard hook comprises:
[0024] The kernel driver receives the first IOCtrl instruction and the identification information of the PIN code issued by the application layer, and starts the kernel keyboard hook;
[0025] The kernel driver starts the kernel keyboard hook including:
[0026] Search for the keyboard driver according to the name of the keyboard device, record the starting address and space range of the keyboard driver, and exit if the keyboard driver is not found;
[0027] Open the corresponding keyboard port driver according to the name of the USB type keyboard port driver and the name of the PS / 2 type keyboard port driver. If both of the two keyboard port drivers fail to be opened, then exit the execution;
[0028] Traverse the device object chain bound to the found keyboard port driver object in turn, obtain the bound device information and determine whether the address space pointed to by the device extension pointer is within the address range of the keyboard class driver, so as to find the bound keyboard class driver;
[0029] Recording the pointer of the keyboard class driver callback instance function address pointed to by the device extension, when enabling the kernel keyboard hook, replacing the pointer with the rewritten keyboard class driver callback instance function address; when uninstalling the kernel keyboard hook, restoring it to the recorded original pointer;
[0030] The identification information of the PIN code of the currently installed kernel keyboard hook is set according to the identification information of the PIN code.
[0031] Further, in the above-mentioned method for securely inputting and verifying a USBKey PIN code, the soft keyboard inputting a USBKey PIN code specifically comprises:
[0032] The application layer generates a random number, establishes a mapping relationship between the soft keyboard and the PIN code according to the random number, randomly disperses the layout of the soft keyboard, displays a UI window of the dispersed soft keyboard, communicates with the kernel driver through IOCtrl, and sends the random number to the kernel driver;
[0033] The application layer encodes the PIN code input by the soft keyboard according to the random number, and sends the encoded PIN code and corresponding identification information to the kernel driver of the USBKey;
[0034] The kernel driver parses the encoded PIN code according to the random number in the identification information of the encoded PIN code, searches for the memory location where the PIN code is stored in the kernel driver according to the USBKey device handle information, the process information of the PIN input window, the PIN input window handle and the PIN operation type in the identification information, appends the parsed PIN code to the end of the memory location, and completes the soft keyboard input character.
[0035] Further, in the above-mentioned method for securely inputting and verifying a USBKey PIN code, the physical keyboard inputting a USBKey PIN code specifically includes:
[0036] The kernel driver intercepts the PIN code input by the physical keyboard through the currently installed kernel keyboard hook, and stores the current PIN code in a dispersed manner in the memory according to the USBKey device handle information in the identification information of the current PIN code, the process information of the PIN input window, the PIN input window handle and the PIN operation type.
[0037] Further, in the above-mentioned method for securely inputting and verifying a USBKey PIN code, the kernel driver encrypts and encapsulates the current PIN code into ciphertext information and returns it to the application layer, including:
[0038] The kernel driver encrypts and encapsulates the current PIN code into ciphertext information according to the algorithm identifier in the identification information of the current PIN code, and then returns the ciphertext information to the application layer.
[0039] Further, in the above-mentioned method for securely inputting and verifying a USBKey PIN code, the application layer forwarding the ciphertext information to the USBKey for verification includes:
[0040] The application layer encapsulates the ciphertext information into an APDU instruction for verifying the PIN code according to the COS instruction set and then forwards it to the USBKey;
[0041] The USBKey performs PIN verification on the ciphertext information in the APDU instruction through the on-chip operating system COS, and returns the PIN verification result to the application layer.
[0042] Further, in the above-mentioned method for securely inputting and verifying a USBKey PIN code, the uninstallation of the kernel keyboard hook comprises:
[0043] When the PIN input window loses focus, the application layer sends a second IOCtrl instruction to the kernel driver to disable the kernel keyboard hook.
[0044] Further, in the above-mentioned method for securely inputting and verifying a USBKey PIN code, the uninstallation of the kernel keyboard hook comprises:
[0045] When it is detected that the process of the PIN input window is forcibly terminated or abnormally exited, the kernel driver checks the enabled state of the currently installed kernel keyboard hook and the process associated data;
[0046] If the currently exited process is in the state of enabling the kernel keyboard hook, the currently installed kernel keyboard hook will be automatically uninstalled;
[0047] If the currently exited process has recorded keyboard input data in the kernel driver, the data is cleared.
[0048] The embodiment of the present invention also provides a system for securely inputting and verifying a USBKey PIN code, the system comprising: installing a kernel keyboard hook module, inputting a USBKey PIN code module, verifying a USBKey PIN code module and uninstalling a kernel keyboard hook module;
[0049] The USBKey PIN code input module includes: a soft keyboard USBKey PIN code input module and a physical keyboard USBKey PIN code input module, and the soft keyboard USBKey PIN code input module is used to:
[0050] The application layer of the USBKey encodes the PIN code input by the soft keyboard, and sends the encoded PIN code and corresponding identification information to the kernel driver of the USBKey;
[0051] The kernel driver obtains the memory location of the encoded PIN code in the kernel driver according to the identification information of the encoded PIN code, parses the encoded PIN code, and appends the parsed PIN code to the end of the memory location to complete the soft keyboard input of the PIN code;
[0052] The physical keyboard input USBKey PIN code module is used for:
[0053] The kernel driver intercepts the PIN code input by the physical keyboard through the currently installed kernel keyboard hook, obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, appends the current PIN code to the end of the memory location, and completes the physical keyboard input of the PIN code;
[0054] The USBKey PIN code verification module is used to:
[0055] The application layer sends a verification PIN instruction and identification information of the current PIN code to the kernel driver;
[0056] The kernel driver obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, extracts the current PIN code, encrypts and encapsulates the current PIN code into ciphertext information, and returns it to the application layer;
[0057] The application layer forwards the ciphertext information to the USBKey for verification.
[0058] The beneficial effects of the present invention are as follows: the method and system provided by the present invention install a kernel keyboard hook in the kernel driver through the application layer, thereby preventing viruses or Trojan programs from the application layer and the kernel layer from monitoring and intercepting the PIN code input and verification process, preventing PIN information leakage, and improving the security when using USBKey. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Figure 1 A schematic diagram of a flow chart of verifying a USBKey PIN code provided in an embodiment of the present invention;
[0060] Figure 2A schematic diagram of a process of installing a kernel keyboard hook at the application layer provided in an embodiment of the present invention;
[0061] Figure 3 A schematic diagram of a process of installing a kernel keyboard hook for a kernel driver provided in an embodiment of the present invention;
[0062] Figure 4 A schematic diagram of a process of inputting a PIN code through a soft keyboard provided in an embodiment of the present invention;
[0063] Figure 5 The figure is a schematic diagram of the process of verifying the USBKey PIN code provided in the embodiment of the present invention. DETAILED DESCRIPTION
[0064] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0065] The present invention provides a method for safely inputting and verifying a USBKey PIN code, the method comprising: installing a kernel keyboard hook, inputting a USBKey PIN code, verifying the USBKey PIN code and uninstalling the kernel keyboard hook;
[0066] Entering the USBKey PIN code includes: entering the USBKey PIN code using the soft keyboard and entering the USBKey PIN code using the physical keyboard. Entering the USBKey PIN code using the soft keyboard includes:
[0067] The application layer of USBKey encodes the PIN code input by the soft keyboard, and sends the encoded PIN code and corresponding identification information to the kernel driver of USBKey;
[0068] The kernel driver obtains the memory location of the encoded PIN code in the kernel driver according to the identification information of the encoded PIN code, parses the encoded PIN code, and appends the parsed PIN code to the end of the memory location, thereby completing the soft keyboard input of the PIN code;
[0069] Entering the USBKey PIN code on the physical keyboard includes:
[0070] The kernel driver intercepts the PIN code input by the physical keyboard through the currently installed kernel keyboard hook, obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, appends the current PIN code to the end of the memory location, and completes the physical keyboard input of the PIN code;
[0071] like Figure 1 As shown, verifying the USBKey PIN code includes:
[0072] S1. The application layer sends a verification PIN instruction and identification information of the current PIN code to the kernel driver;
[0073] S2. The kernel driver obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, extracts the current PIN code, encrypts and encapsulates the current PIN code into ciphertext information, and returns it to the application layer;
[0074] S3. The application layer forwards the ciphertext information to USBKey for verification.
[0075] When the application layer is the execution subject, installing the kernel keyboard hook includes:
[0076] When the PIN input window gets the focus, the application layer opens the kernel driver device;
[0077] When the kernel driver device is successfully opened, the application layer sends the first IOCtrl instruction to the kernel driver to start the kernel keyboard hook;
[0078] When the kernel keyboard hook is started, the application layer sends the identification information of the PIN code to the kernel driver. The identification information of the PIN code includes: USBKey device handle information, process and thread information of the PIN input window, PIN input window handle, PIN operation type, PIN complexity, PIN length, random number and algorithm identification.
[0079] When the kernel driver is the execution subject, installing the kernel keyboard hook includes:
[0080] The kernel driver receives the first IOCtrl instruction and the identification information of the PIN code sent by the application layer, and starts the kernel keyboard hook;
[0081] The kernel driver starts the kernel keyboard hook including:
[0082] Search for the keyboard driver according to the name of the keyboard device, record the starting address and space range of the keyboard driver, and exit if the keyboard driver is not found;
[0083] Open the corresponding keyboard port driver according to the name of the USB type keyboard port driver and the name of the PS / 2 type keyboard port driver. If both of the two keyboard port drivers fail to be opened, then exit the execution;
[0084] Traverse the device object chain bound to the found keyboard port driver object in turn, obtain the bound device information and determine whether the address space pointed to by the device extension pointer is within the address range of the keyboard class driver, so as to find the bound keyboard class driver;
[0085] Record the pointer of the keyboard class driver callback instance function address pointed to by the device extension. When the kernel keyboard hook is enabled, replace the pointer with the rewritten keyboard class driver callback instance function address; when the kernel keyboard hook is uninstalled, restore it to the recorded original pointer;
[0086] The identification information of the PIN code of the currently installed kernel keyboard hook is set according to the identification information of the PIN code.
[0087] The soft keyboard input USBKey PIN code includes:
[0088] The application layer generates random numbers, establishes a mapping relationship between the soft keyboard and the PIN code based on the random numbers, and randomly disperses the layout of the soft keyboard, displays the UI window of the dispersed soft keyboard, communicates with the kernel driver through IOCtrl, and sends the random numbers to the kernel driver;
[0089] The application layer encodes the PIN code input by the soft keyboard according to the random number, and sends the encoded PIN code and the corresponding identification information to the kernel driver of USBKey;
[0090] The kernel driver parses the encoded PIN code according to the random number in the identification information of the encoded PIN code, searches for the memory location where the PIN code is stored in the kernel driver according to the USBKey device handle information, the process information of the PIN input window, the PIN input window handle and the PIN operation type in the identification information, appends the parsed PIN code to the end of the memory location, and completes the soft keyboard input character.
[0091] Entering the USBKey PIN code on the physical keyboard includes:
[0092] The kernel driver intercepts the PIN code input by the physical keyboard through the currently installed kernel keyboard hook, and stores the current PIN code in memory in a dispersed manner according to the USBKey device handle information in the identification information of the current PIN code, the process information of the PIN input window, the PIN input window handle and the PIN operation type.
[0093] The kernel driver encrypts the current PIN code into ciphertext information and returns it to the application layer, including:
[0094] The kernel driver encrypts and encapsulates the current PIN code into ciphertext information according to the algorithm identifier in the identification information of the current PIN code, and then returns it to the application layer.
[0095] Step S3 includes:
[0096] The application layer encapsulates the ciphertext information into an APDU command for verifying the PIN code according to the COS command set and forwards it to the USBKey;
[0097] USBKey performs PIN verification on the ciphertext information in the APDU command through the on-chip operating system COS and returns the PIN verification result to the application layer.
[0098] There are two ways to uninstall the kernel keyboard hook:
[0099] The first one, uninstalling the kernel keyboard hook includes:
[0100] When the PIN input window loses focus, the application layer sends a second IOCtrl instruction to the kernel driver to deactivate the kernel keyboard hook.
[0101] The second method is to uninstall the kernel keyboard hook:
[0102] When it is detected that the process of the PIN input window is forcibly terminated or abnormally exited, the kernel driver checks the enabled state of the currently installed kernel keyboard hook and the process-related data;
[0103] If the currently exited process is in the state of enabling the kernel keyboard hook, the currently installed kernel keyboard hook will be automatically uninstalled;
[0104] If the currently exited process has recorded keyboard input data in the kernel driver, the data will be cleared.
[0105] The USBKey middleware PIN protection module (kernel driver) is implemented in the inner layer of Ring0, and the application layer accesses the kernel device through the device name. The kernel driver is installed together with the USBKey management tool, and the driver service starts automatically with the system.
[0106] Set the IRP_MJ_DEVICE_CONTROL routine in the kernel driver to provide a control interface to the USBKey middleware in the application layer, which is used to receive the installation / uninstallation kernel keyboard hook request, set the random factor, soft keyboard input PIN operation, query PIN information (complexity, PIN length, character set, etc.), verify PIN, and clear PIN. Rewrite the callback instance of the KbdClass keyboard class driver in the system kernel driver layer to filter the keyboard input USBKey PIN code behavior and improve the security of the PIN code input process.
[0107] 1) Kernel keyboard hook installation
[0108] The kernel keyboard hook installation process is related to the PIN code input window and is only installed when the PIN code input box is focused and activated.
[0109] The process of installing the hook is divided into: application layer processing and kernel driver layer processing.
[0110] Application layer processing: such as Figure 2As shown, first the PIN input window gets the focus and tries to open the kernel driver device. If the device fails to open, it will jump out. If the kernel driver device opens successfully, the application layer sends an IOCtrl control instruction to the kernel driver to start the keyboard hook. When the kernel keyboard hook is started at the application layer, the identification information of the PIN code is sent to the kernel driver.
[0111] The identification information of the PIN code includes but is not limited to the USBKey device handle information, the process and thread information of the PIN window, the PIN code input box window handle, the PIN operation type, the PIN complexity, the PIN length, the random number, the algorithm identifier, etc.
[0112] Kernel driver layer processing: such as Figure 3 As shown, the kernel driver layer receives the IOCtrl instruction sent by the application layer and opens the kernel keyboard hook in the kernel. The processing steps are as follows:
[0113] 1. First, search for the keyboard driver according to the name of the keyboard device\\Driver\\Kbdclass, and record the starting address and space range of the keyboard driver; if the keyboard device does not exist, jump out; otherwise, proceed to the next step.
[0114] 2. Open the corresponding keyboard port driver according to the name of the USB keyboard port driver \\Driver\\Kbdhid and the name of the PS / 2 keyboard port driver \\Driver\\i8042prt. If the opening of both keyboard port drivers fails, exit; otherwise, proceed to the next step.
[0115] 3. Traverse the device object chain bound to the found keyboard port driver object in turn, obtain the bound device information and determine whether the address space pointed to by the DeviceExtension device extension pointer is within the address range of the keyboard class driver to find the bound keyboard class driver. If a matching device has been found, proceed to the next step; otherwise, continue to execute this process until all bound devices are traversed.
[0116] 4. Record the pointer of the DeviceExtension device extension pointing to the keyboard class driver callback instance function address, which is used to restore the original function pointer when uninstalling the keyboard hook, fill in the keyboard class driver object, and replace the function pointer with the rewritten keyboard class driver callback instance address.
[0117] 5. Set the keyboard hook PIN code identification information. The PIN identification information includes: main process, device handle, PIN operation type (check or modify PIN), PIN type (new PIN, PIN confirmation, old PIN, check PIN), random number, algorithm identification, which is used to distinguish different USBKey devices, different processes and threads, different windows, and different PIN types.
[0118] 2) PIN input process
[0119] There are two situations for entering a PIN code:
[0120] a. Input through the physical keyboard: The kernel driver receives the keyboard data sent by the keyboard port driver and enters the keyboard device processing instance. The USBKey device handle, process information, PIN window, PIN operation type and other parameters of the currently installed kernel keyboard hook are stored in memory in a scattered manner.
[0121] b. Input through the soft keyboard:
[0122] Application layer preparation: Generate random numbers, establish soft keyboard key and character mapping relationship based on random numbers, randomly scatter and display soft keyboard UI window; communicate with kernel driver through IOCtrl to send random numbers to kernel driver;
[0123] Soft keyboard input characters: When the user clicks the soft keyboard, the application layer converts the input characters into a code and sends IOCtrl to the kernel driver;
[0124] Kernel driver processing: The kernel driver receives the IOCtrl command from the application, restores the characters of the actual PIN input with random factors, and searches for the PIN code stored in the system kernel layer memory location based on the USBKey device handle, process information, PIN window, and PIN operation type, and appends the extracted PIN code information to the end of the PIN code to complete the soft keyboard input characters. Figure 4 As shown, the specific process is as follows:
[0125] 1. The application layer generates random numbers and disperses the keyboard, and the layout displays the dispersed soft keyboard UI interface;
[0126] 2. The application layer communicates with the kernel driver through IOCtrl and sends the random number to the kernel driver;
[0127] 3. The user clicks the soft keyboard to enter characters;
[0128] 4. The application layer encodes the input characters and sends them to the kernel driver through IOCtrl;
[0129] 5. The kernel driver receives the IOCtrl command from the upper soft keyboard and extracts the encoded characters;
[0130] 6. The kernel driver uses the random number to restore the actual PIN code entered, and appends the restored PIN code to the end of the memory location where the PIN code is located;
[0131] 7. Complete the behavior of entering the PIN code on the soft keyboard.
[0132] 3) Verify PIN
[0133] like Figure 5 As shown, the specific process is as follows:
[0134] 1. The USBKey application layer middleware sends the IOCtrl verification PIN command, and sends the thread handle, window handle, PIN type and other information of the current PIN identification information to the kernel driver;
[0135] 2. The kernel driver receives the IOCtrl command of the application layer to verify the PIN code, extracts the original PIN according to the PIN identification information, encrypts and encapsulates it into ciphertext information and returns it to the application layer;
[0136] 3. The application layer calls the USBKey middleware to process the ciphertext information, and encapsulates the processed data in the APDU instruction format and sends it to the USBKey;
[0137] 4. COS in USBKey receives the upper-layer APDU command to verify the PIN and returns the verification result;
[0138] 5. Complete the PIN code verification process.
[0139] 4) Kernel keyboard hook uninstallation
[0140] When the PIN code input window of the application layer loses focus, the application layer actively sends an IOCtrl command to the kernel driver to deactivate the kernel keyboard hook.
[0141] Another special case is that the process where the PIN window is located is forced to end or abnormally exits, which is handled by the kernel driver. The kernel driver actively monitors the exit behavior of the application layer process and immediately checks the kernel keyboard hook enablement status and process-related data information. And responds as follows:
[0142] Keyboard hook status recovery: If the currently exited process is in the state of enabling the kernel keyboard hook, the kernel keyboard hook will be automatically uninstalled to ensure that the user can use the keyboard device normally; otherwise, no processing will be done.
[0143] Process-related data cleaning: If it is found that the currently exited process has recorded keyboard input data in the kernel driver, the data will be cleared; otherwise, no processing will be done.
[0144] The embodiment of the present invention also provides a system for securely inputting and verifying a USBKey PIN code, the system comprising: installing a kernel keyboard hook module, inputting a USBKey PIN code module, verifying a USBKey PIN code module and uninstalling a kernel keyboard hook module;
[0145] The USBKey PIN code input module includes: a soft keyboard USBKey PIN code input module and a physical keyboard USBKey PIN code input module. The soft keyboard USBKey PIN code input module is used for:
[0146] The application layer of USBKey encodes the PIN code input by the soft keyboard, and sends the encoded PIN code and corresponding identification information to the kernel driver of USBKey;
[0147] The kernel driver obtains the memory location of the encoded PIN code in the kernel driver according to the identification information of the encoded PIN code, parses the encoded PIN code, and appends the parsed PIN code to the end of the memory location, thereby completing the soft keyboard input of the PIN code;
[0148] The USBKey PIN code module is used to enter the physical keyboard:
[0149] The kernel driver intercepts the PIN code input by the physical keyboard through the currently installed kernel keyboard hook, obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, appends the current PIN code to the end of the memory location, and completes the physical keyboard input of the PIN code;
[0150] The USBKey PIN verification module is used to:
[0151] The application layer sends a verification PIN instruction and identification information of the current PIN code to the kernel driver;
[0152] The kernel driver obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, extracts the current PIN code, encrypts and encapsulates the current PIN code into ciphertext information, and returns it to the application layer;
[0153] The application layer forwards the ciphertext information to the USBKey for verification.
[0154] The present invention includes the following advantages:
[0155] 1) Through the Ring0 layer kernel driver, security protection is implemented for the physical keyboard PIN input and PIN verification process.
[0156] 2) Provide an application-layer soft keyboard UI, directly communicate with the kernel through IOCtrl to input the PIN code, use random numbers to disperse the keyboard layout during data transmission, and restore the actual PIN code in the kernel.
[0157] 3) The PIN operations provided by the Ring0 layer kernel driver include but are not limited to PIN input, PIN verification, PIN modification, PIN complexity query, PIN length query, and PIN data clearing operations.
[0158] 4) The USBKey PIN processing method based on the USBKey PIN code identification in the kernel implements support for multi-device, multi-process, and multi-type PIN operation methods.
[0159] 5) The kernel driver automatically monitors the abnormal exit of the application layer process and releases the processing method of the process related data information stored in the kernel.
[0160] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A method for securely inputting and verifying a USBKey PIN code, characterized in that: The method comprises: installing a kernel keyboard hook, inputting a USBKey PIN code, verifying the USBKey PIN code and uninstalling the kernel keyboard hook; The inputting of USBKey PIN code includes: inputting USBKey PIN code by soft keyboard and inputting USBKey PIN code by physical keyboard, wherein the inputting of USBKey PIN code by soft keyboard includes: The application layer of the USBKey encodes the PIN code input by the soft keyboard, and sends the encoded PIN code and corresponding identification information to the kernel driver of the USBKey; The kernel driver obtains the memory location of the encoded PIN code in the kernel driver according to the identification information of the encoded PIN code, parses the encoded PIN code, and appends the parsed PIN code to the end of the memory location to complete the soft keyboard input of the PIN code; The physical keyboard input USBKey PIN code includes: The kernel driver intercepts the PIN code input by the physical keyboard through the currently installed kernel keyboard hook, obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, appends the current PIN code to the end of the memory location, and completes the physical keyboard input of the PIN code; The verification of the USBKey PIN code includes: The application layer sends a verification PIN instruction and identification information of the current PIN code to the kernel driver; The kernel driver obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, extracts the current PIN code, encrypts and encapsulates the current PIN code into ciphertext information, and returns it to the application layer; The application layer forwards the ciphertext information to the USBKey for verification; The installation of the kernel keyboard hook includes: When the PIN input window acquires the focus, the application layer opens the kernel driver device; When the kernel driver device is successfully opened, the application layer sends a first IOCtrl instruction to the kernel driver to start the kernel keyboard hook; When the kernel keyboard hook is started, the application layer sends the identification information of the PIN code to the kernel driver, and the identification information of the PIN code includes: USBKey device handle information, process and thread information of the PIN input window, PIN input window handle, PIN operation type, PIN complexity, PIN length, random number and algorithm identification; The installation of the kernel keyboard hook includes: The kernel driver receives the first IOCtrl instruction and the identification information of the PIN code issued by the application layer, and starts the kernel keyboard hook; The kernel driver starts the kernel keyboard hook including: Search for the keyboard driver according to the name of the keyboard device, record the starting address and space range of the keyboard driver, and exit if the keyboard driver is not found; Open the corresponding keyboard port driver according to the name of the USB type keyboard port driver and the name of the PS / 2 type keyboard port driver. If both of the two keyboard port drivers fail to be opened, then exit the execution; Traverse the device object chain bound to the found keyboard port driver object in turn, obtain the bound device information and determine whether the address space pointed to by the device extension pointer is within the address range of the keyboard class driver, so as to find the bound keyboard class driver; Recording the pointer of the keyboard class driver callback instance function address pointed to by the device extension pointer, and replacing the pointer with the rewritten keyboard class driver callback instance function address when the kernel keyboard hook is enabled; and restoring it to the recorded original pointer when the kernel keyboard hook is uninstalled; The identification information of the PIN code of the currently installed kernel keyboard hook is set according to the identification information of the PIN code.
2. A method for securely inputting and verifying a USBKey PIN code according to claim 1, characterized in that: The soft keyboard input USBKey PIN code specifically includes: The application layer generates a random number, establishes a mapping relationship between the soft keyboard and the PIN code according to the random number, randomly disperses the layout of the soft keyboard, displays a UI window of the dispersed soft keyboard, communicates with the kernel driver through IOCtrl, and sends the random number to the kernel driver; The application layer encodes the PIN code input by the soft keyboard according to the random number, and sends the encoded PIN code and corresponding identification information to the kernel driver of the USBKey; The kernel driver parses the encoded PIN code according to the random number in the identification information of the encoded PIN code, searches for the memory location where the PIN code is stored in the kernel driver according to the USBKey device handle information, the process information of the PIN input window, the PIN input window handle and the PIN operation type in the identification information, appends the parsed PIN code to the end of the memory location, and completes the soft keyboard input character.
3. A method for securely inputting and verifying a USBKey PIN code according to claim 1, characterized in that: The physical keyboard input USBKey PIN code specifically includes: The kernel driver intercepts the PIN code input by the physical keyboard through the currently installed kernel keyboard hook, and stores the current PIN code in a dispersed manner in the memory according to the USBKey device handle information in the identification information of the current PIN code, the process information of the PIN input window, the PIN input window handle and the PIN operation type.
4. A method for securely inputting and verifying a USBKey PIN code according to claim 1, characterized in that: The kernel driver encrypts and encapsulates the current PIN code into ciphertext information and returns it to the application layer, including: The kernel driver encrypts and encapsulates the current PIN code into ciphertext information according to the algorithm identifier in the identification information of the current PIN code, and then returns the ciphertext information to the application layer.
5. A method for securely inputting and verifying a USBKey PIN code according to claim 1, characterized in that: The application layer forwards the ciphertext information to the USBKey for verification, including: The application layer encapsulates the ciphertext information into an APDU instruction for verifying the PIN code according to the COS instruction set and then forwards it to the USBKey; The USBKey performs PIN verification on the ciphertext information in the APDU instruction through the on-chip operating system COS, and returns the PIN verification result to the application layer.
6. A method for securely inputting and verifying a USBKey PIN code according to any one of claims 1 to 5, characterized in that: The uninstall kernel keyboard hook comprises: When the PIN input window loses focus, the application layer sends a second IOCtrl instruction to the kernel driver to disable the kernel keyboard hook.
7. A method for securely inputting and verifying a USBKey PIN code according to any one of claims 1 to 5, characterized in that: The uninstall kernel keyboard hook comprises: When it is detected that the process of the PIN input window is forcibly terminated or abnormally exited, the kernel driver checks the enabled state of the currently installed kernel keyboard hook and the process associated data; If the currently exited process is in the state of enabling the kernel keyboard hook, the currently installed kernel keyboard hook will be automatically uninstalled; If the currently exited process has recorded keyboard input data in the kernel driver, the data is cleared.
8. A system for securely inputting and verifying a USBKey PIN code, characterized in that: The system comprises: installing a kernel keyboard hook module, inputting a USBKey PIN code module, verifying a USBKey PIN code module and uninstalling the kernel keyboard hook module; The installation of the kernel keyboard hook module is used to: When the PIN input window gets the focus, the application layer opens the kernel driver device; When the kernel driver device is successfully opened, the application layer sends a first IOCtrl instruction to the kernel driver to start the kernel keyboard hook; When the kernel keyboard hook is started, the application layer sends the identification information of the PIN code to the kernel driver, and the identification information of the PIN code includes: USBKey device handle information, process and thread information of the PIN input window, PIN input window handle, PIN operation type, PIN complexity, PIN length, random number and algorithm identification; The USBKey PIN code input module includes: a soft keyboard USBKey PIN code input module and a physical keyboard USBKey PIN code input module, and the soft keyboard USBKey PIN code input module is used to: The application layer of the USBKey encodes the PIN code input by the soft keyboard, and sends the encoded PIN code and corresponding identification information to the kernel driver of the USBKey; The kernel driver obtains the memory location of the encoded PIN code in the kernel driver according to the identification information of the encoded PIN code, parses the encoded PIN code, and appends the parsed PIN code to the end of the memory location to complete the soft keyboard input of the PIN code; The physical keyboard input USBKey PIN code module is used for: The kernel driver intercepts the PIN code input by the physical keyboard through the currently installed kernel keyboard hook, obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, appends the current PIN code to the end of the memory location, and completes the physical keyboard input of the PIN code; The USBKey PIN code verification module is used to: The application layer sends a verification PIN instruction and identification information of the current PIN code to the kernel driver; The kernel driver obtains the memory location of the current PIN code in the kernel driver according to the identification information of the current PIN code, extracts the current PIN code, encrypts and encapsulates the current PIN code into ciphertext information, and returns it to the application layer; The application layer forwards the ciphertext information to the USBKey for verification; The installation of the kernel keyboard hook includes: The kernel driver receives the first IOCtrl instruction and the identification information of the PIN code issued by the application layer, and starts the kernel keyboard hook; The kernel driver starts the kernel keyboard hook including: Search for the keyboard driver according to the name of the keyboard device, record the starting address and space range of the keyboard driver, and exit if the keyboard driver is not found; Open the corresponding keyboard port driver according to the name of the USB type keyboard port driver and the name of the PS / 2 type keyboard port driver. If both of the two keyboard port drivers fail to be opened, then exit the execution; Traverse the device object chain bound to the found keyboard port driver object in turn, obtain the bound device information and determine whether the address space pointed to by the device extension pointer is within the address range of the keyboard class driver, so as to find the bound keyboard class driver; Recording the pointer of the keyboard class driver callback instance function address pointed to by the device extension pointer, and replacing the pointer with the rewritten keyboard class driver callback instance function address when the kernel keyboard hook is enabled; and restoring it to the recorded original pointer when the kernel keyboard hook is uninstalled; The identification information of the PIN code of the currently installed kernel keyboard hook is set according to the identification information of the PIN code.
