Method and terminal for controlling application operation
By generating and verifying authentication codes in the POS system, the problem of easy attacks during application runtime is solved, and effective monitoring of installed applications and data security is achieved.
Patent Information
- Application Number
- CN202411881354.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-03-28
AI Technical Summary
The existing POS system is not monitored and managed after the application is installed, which makes the application runtime easily attacked and affects system security.
By obtaining the preset session key and current application package, the current authentication code is generated and verified with the pre-stored installation authentication code. If the verification is passed, the application will be run to ensure the security of the application data.
Effectively monitor the data security of installed applications, prevent tampering, improve application security, and thus ensure the overall security of the system.
Smart Images

Figure CN119720173A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of application control, and in particular to a method and a terminal for controlling application operation. Background Art
[0002] With the improvement of mass consumption level, POS (Point Of Sale) machines are widely used. Among them, the number of malicious programs used to attack POS machine applications has also increased. Malicious programs invade POS machine systems through various channels, attempting to tamper with application data, steal sensitive information or interfere with normal transaction processes, posing a great threat to customer financial security and the normal operation of merchants.
[0003] To address this problem, existing POS systems verify whether the application package contains an extended signature during the application installation process, and prevent the installation of unknown applications by verifying the extended signature, thereby ensuring application security. However, the POS system does not monitor and manage the installation of completed applications, resulting in attacks during application operation, which affects system security. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method and a terminal for controlling the operation of an application, which can perform security management and control on the operation of the application and improve the security of the system.
[0005] In order to solve the above technical problems, a technical solution adopted by the present invention is: A method for controlling application execution, comprising: In response to the application running instruction, obtaining a preset session key and a current application package of the application; generating a current authentication code according to the session key and the current application package; Performing data verification on the current authentication code according to a pre-stored installation authentication code, wherein the installation authentication code is an authentication code generated when the application is installed; If the verification passes, the application is run.
[0006] In order to solve the above technical problems, another technical solution adopted by the present invention is: A terminal for controlling application running includes a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, each step in the above-mentioned method for controlling application running is implemented.
[0007] The beneficial effect of the present invention is that when the application is running, the current authentication code is generated according to the pre-stored session key and the current application package, and then the current authentication code generated by the application when it is running is verified according to the installation authentication code generated when the application is installed. If the verification passes, it means that the current data of the application package is consistent with the installation data of the application package, that is, the application has not been tampered with, so the application can be run. The present invention generates a corresponding authentication code when applying to verify the data security of the application, can effectively monitor the installed application, improve the security of the installed application, and thus ensure the security of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 A flowchart of a method for controlling application execution provided by an embodiment of the present invention; Figure 2 Another flow chart of a method for controlling application execution provided by an embodiment of the present invention; Figure 3 A schematic diagram of the structure of a terminal for controlling the running of an application provided by an embodiment of the present invention; Description of labels: 100. A terminal for controlling the running of an application; 101. a memory; 102. a processor. DETAILED DESCRIPTION
[0009] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.
[0010] An embodiment of the present invention provides a method for controlling application execution, comprising: In response to an application execution instruction, obtaining a preset session key and a current application package of the application; generating a current authentication code according to the session key and the current application package; Performing data verification on the current authentication code according to a pre-stored installation authentication code, wherein the installation authentication code is an authentication code generated when the application is installed; If the verification passes, the application is run.
[0011] From the above description, it can be seen that the beneficial effect of the present invention is that when the application is running, the current authentication code will be generated according to the pre-stored session key and the current application package, and then the current authentication code generated by the application when it is running will be verified according to the installation authentication code generated when the application is installed. If the verification passes, it means that the current data of the application package is consistent with the installation data of the application package, that is, the application has not been tampered with, so the application can be run. The present invention generates a corresponding authentication code when applying to verify the data security of the application, can effectively monitor the installed application, improve the security of the installed application, and thus ensure the security of the system.
[0012] Furthermore, before responding to the application execution instruction, the method further includes: The security element of the key service control device is called to generate and store the session key.
[0013] As can be seen from the above description, the key service controls the security element to randomly generate a session key to ensure the randomness and security of the authentication code generated by the application and prevent malicious programs from forging the authentication code.
[0014] Furthermore, it also includes: In response to the installation instruction of the application, calling the key service through the application package management service to obtain the session key and obtain the installation application package of the application; generating the installation authentication code according to the session key and the installation application package; If the installation authentication code is successfully generated, the application installation is completed based on the installation application package; After the installation is complete, an authentication file is generated according to the installation authentication code, and the authentication file is stored in the installation path of the application.
[0015] As can be seen from the above description, the application will perform a signature verification service when it is installed. The signature verification service can effectively ensure the data reliability of the installed application package. Therefore, the installation authentication code generated by the installation application package during installation is used as the standard value for verifying subsequent application packages, which can effectively improve the accuracy of verification. The installation authentication code is stored in the form of a file in the installation path, which is convenient for the application to quickly obtain when it is started and run, thereby speeding up the efficiency of application verification.
[0016] Further, in response to the running instruction of the application, obtaining a preset session key and a current application package of the application includes: In response to the running instruction of the application, the application activity management service calls the application package management service to obtain the current application package of the application, and the application package management service calls the key service to obtain the session key.
[0017] From the above description, we can know that when the application is running, it will first call the application package management service through the application activity management service to obtain the current application package and the pre-stored session key in order to perform the data verification procedure. Based on the native service to obtain relevant data, it ensures that the application can be quickly verified before starting, avoiding the problem of abnormal startup of the application.
[0018] Further, generating a current authentication code according to the session key and the current application package includes: The session key and the current application package are calculated using a message authentication code algorithm based on a hash function to obtain a current authentication code.
[0019] From the above description, it can be seen that in order to avoid the verification process taking too long to affect the startup efficiency of the application, an algorithm with high computational efficiency is used to generate the current authentication code to increase the data verification speed.
[0020] Further, performing data verification on the current authentication code according to the pre-stored installation authentication code includes: The current authentication code is compared with the pre-stored installation authentication code to see if they are consistent. If they are consistent, the verification passes; if they are inconsistent, the verification fails.
[0021] From the above description, it can be seen that the current authentication code and the installation authentication code are generated based on the same method, so when they are consistent, it means that the application has not been tampered with. Data verification is performed by comparing the authentication codes to improve the verification efficiency.
[0022] Furthermore, it also includes: If it is detected that the device is attacked, the security element is controlled to clear the session key.
[0023] From the above description, it can be seen that when the device is attacked, the session key is cleared so that all applications cannot generate authentication codes, thereby ensuring the security of the device.
[0024] Furthermore, it also includes: If the installation authentication code fails to be generated, the installation of the application is not allowed.
[0025] From the above description, it can be seen that when the session key is cleared, the application cannot obtain the session key when installing, so the installation authentication code cannot be generated, which means that the device is under attack. At this time, the device is not allowed to install the application, thereby ensuring device security.
[0026] Furthermore, it also includes: If the current authentication code fails to be generated or verified, the application is not allowed to run.
[0027] From the above description, it can be seen that if the current authentication code generation fails, the session key cannot be obtained, that is, the device is under attack, so the application is not allowed to run. If the current authentication code verification fails, it means that the application has been tampered with, so the application is not allowed to run. In this way, the data security of the installed application is monitored to ensure system security.
[0028] Another embodiment of the present invention provides a terminal for controlling the running of an application, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor implements each step of the above-mentioned method for controlling the running of an application when executing the computer program.
[0029] From the above description, it can be seen that the beneficial effect of the present invention is that when the application is running, the current authentication code will be generated according to the pre-stored session key and the current application package, and then the current authentication code generated by the application when it is running will be verified according to the installation authentication code generated when the application is installed. If the verification passes, it means that the current data of the application package is consistent with the installation data of the application package, that is, the application has not been tampered with, so the application can be run. The present invention generates a corresponding authentication code when applying to verify the data security of the application, can effectively monitor the installed application, improve the security of the installed application, and thus ensure the security of the system.
[0030] The above-mentioned method and terminal for controlling the running of an application of the present invention can be applied to electronic devices based on the Android system, and are described below through specific implementation methods: Please refer to Figure 1 , Embodiment 1 of the present invention is: A method for controlling application operation, specifically comprising: S1. In response to an application running instruction, obtain a preset session key and a current application package of the application.
[0031] Specifically, before step S1, the method further includes: S101, calling a security element of a key service control device to generate and save the session key.
[0032] In some embodiments, in response to an activation instruction of the device, the above step S101 is performed during the device activation process. The key service notifies the underlying secure element to generate a random session key so that applications installed or running on the device generate authentication codes based on the same session key.
[0033] In an optional implementation, the security element may generate and store multiple session keys, and use different session keys to generate authentication codes for different types of applications.
[0034] Specifically, the step S1 includes: S11. In response to a running instruction of an application, calling an application package management service through an application activity management service to obtain a current application package of the application, and calling the key service through the application package management service to obtain the session key.
[0035] In some embodiments, when a user clicks an application icon on a device to trigger an application execution instruction, the application activity management service calls an interface in the application package management service for verifying the authentication code, wherein the parameter for calling the interface is the file path of the application.
[0036] Specifically, the method further includes: S102: In response to the installation instruction of the application, call the key service through the application package management service to obtain the session key, and obtain the installation application package of the application.
[0037] In some embodiments, the application package management service calls the key service interface to retrieve the session key from the secure element.
[0038] S103: Generate the installation authentication code according to the session key and the installation application package.
[0039] S104: If the installation authentication code is generated successfully, the application installation is completed based on the installation application package.
[0040] S105. After the installation is complete, generate an authentication file according to the installation authentication code, and store the authentication file in the installation path of the application.
[0041] S2. Generate a current authentication code according to the session key and the current application package.
[0042] Specifically, the step S2 includes: S21. Calculate the session key and the current application package using a message authentication code algorithm based on a hash function to obtain a current authentication code.
[0043] S3. Perform data verification on the current authentication code according to a pre-stored installation authentication code, where the installation authentication code is an authentication code generated when the application is installed.
[0044] Specifically, step S3 includes: S31, comparing the current authentication code with the pre-stored installation authentication code to see if they are consistent, if they are consistent, the verification passes, if they are inconsistent, the verification fails.
[0045] S4. If the verification passes, run the application.
[0046] Specifically, the method further includes: if the verification fails, not allowing the application to run.
[0047] In some embodiments, if the verification passes, the application is started and run in a normal manner. If the verification fails, the application activity management service will forcibly end the application startup operation to prohibit the application from running.
[0048] Embodiment 2 of the present invention is: A method for controlling application execution, which differs from the first embodiment in that: if it is detected that a device is attacked, the security element is controlled to clear the session key.
[0049] In this embodiment, the method further includes: if the installation authentication code fails to be generated, then the application is not allowed to be installed. If the current authentication code fails to be generated, then the application is not allowed to be run.
[0050] Once the device's session key is cleared, the device will fail to install or run applications. The device can only wait for the next activation to regenerate the session key, thereby achieving application installation and operation.
[0051] Please refer to Figure 2 , Embodiment 3 of the present invention is: The method for controlling application execution in the second embodiment is applied to an Android-based POS terminal.
[0052] Step 1: The POS terminal is programmed with the system. The POS terminal is in an inactive state during the system programming.
[0053] Step 2: The POS terminal performs device activation. During the activation process, the Pinpad service (key service) notifies the underlying secure element SE to generate a random session key and save it persistently. Pinpad is an encrypted numeric keypad designed for highly secure password input. The Pinpad service manages and enables the encrypted numeric keypad, which allows users to securely enter the Pin code for transaction verification.
[0054] Step 3: After the POS terminal is activated successfully, the POS terminal will restart.
[0055] Step 4. When the POS terminal installs APK (Android application package), PKMS (Package Manager Service) will call the interface of Pinpad service to obtain the session key and Apk file in SE, and calculate the session key and Apk file based on Hmac algorithm (message authentication code algorithm based on hash function) to obtain Mac1 (Message Authentication Code), and save it in the installation directory as a file. If Mac generation fails, the application installation fails.
[0056] Step 5. When the user clicks the APP (application) icon on the POS terminal to trigger the run command, AMS (ActivityManager Service) will call the PKMS interface for verifying the Mac. The calling parameter of the interface is the path of the Apk file.
[0057] Step 6: PKMS calls the interface of the Pinpad service to obtain the session key and the Apk file in the SE, and recalculates the session key and the Apk file based on the Hmac algorithm to obtain Mac2. Among them, PKMS calls the interface of the Pinpad service through Binder, which is a mechanism for inter-process communication (IPC) in the Android system.
[0058] Step 7: Compare Mac1 and Mac2 to see if they are consistent. If they are consistent, the verification is successful and AMS opens and runs the APP normally. If they are inconsistent, the verification fails and AMS ends the App opening operation.
[0059] When the POS terminal detects that the device has been attacked, the secure element SE will actively clear the session key.
[0060] Please refer to Figure 3 , Embodiment 4 of the present invention is: A terminal 100 for controlling the running of an application includes a memory 101, a processor 102, and a computer program stored in the memory 101 and running on the processor 102. When the processor 102 executes the computer program, each step in a method for controlling the running of an application in the above-mentioned embodiment 1 or embodiment 2 is implemented.
[0061] In summary, the present invention provides a method and terminal for controlling the operation of an application. The security element of the device generates and saves a session key. When the application is installed, an installation authentication code is generated based on the session key and the installation application package. When the application is running, a current authentication code is generated based on the session key and the current application package, and the current authentication code is compared with the installation authentication code. If the comparison is consistent, it means that the current data of the application package is consistent with the installation data of the application package, that is, the application has not been tampered with, so the application can be run. If the comparison is inconsistent, it means that the current data of the application package is inconsistent with the application package data, that is, the application has been tampered with, so the application is not allowed. The present invention generates a corresponding authentication code when applying to verify the data security of the application, and can effectively monitor the installed applications. In addition, when the device is attacked, the session key is cleared, resulting in the inability of the application to generate an authentication code, so all applications cannot be installed and run, which improves the security of the installed applications in the device, thereby ensuring system security.
[0062] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for controlling application operation, characterized in that: include: In response to an application execution instruction, obtaining a preset session key and a current application package of the application; generating a current authentication code according to the session key and the current application package; Performing data verification on the current authentication code according to a pre-stored installation authentication code, wherein the installation authentication code is an authentication code generated when the application is installed; If the verification passes, the application is run.
2. A method for controlling application execution according to claim 1, characterized in that: Before responding to the application's running instruction, the method further includes: The security element of the key service control device is called to generate and store the session key.
3. A method for controlling application execution according to claim 2, characterized in that: Also includes: In response to the installation instruction of the application, calling the key service through the application package management service to obtain the session key and obtain the installation application package of the application; generating the installation authentication code according to the session key and the installation application package; If the installation authentication code is successfully generated, the application installation is completed based on the installation application package; After the installation is complete, an authentication file is generated according to the installation authentication code, and the authentication file is stored in the installation path of the application.
4. A method for controlling application execution according to claim 2, characterized in that: In response to the running instruction of the application, obtaining a preset session key and a current application package of the application includes: In response to the running instruction of the application, the application activity management service calls the application package management service to obtain the current application package of the application, and the application package management service calls the key service to obtain the session key.
5. A method for controlling application execution according to claim 1, characterized in that: Generating a current authentication code according to the session key and the current application package includes: The session key and the current application package are calculated using a message authentication code algorithm based on a hash function to obtain a current authentication code.
6. A method for controlling application execution according to claim 3, characterized in that: Performing data verification on the current authentication code according to the pre-stored installation authentication code includes: The current authentication code is compared with the pre-stored installation authentication code to see if they are consistent. If they are consistent, the verification passes; if they are inconsistent, the verification fails.
7. A method for controlling application execution according to claim 2, characterized in that: Also includes: If it is detected that the device is attacked, the security element is controlled to clear the session key.
8. A method for controlling application execution according to claim 7, characterized in that: Also includes: If the installation authentication code fails to be generated, the installation of the application is not allowed.
9. A method for controlling application execution according to claim 7, characterized in that: Also includes: If the current authentication code fails to be generated or verified, the application is not allowed to run.
10. A terminal for controlling the running of an application, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the processor implements the steps of the method for controlling application execution as described in any one of claims 1 to 9.