A method and device for implementing key import and key use
By using the Keystore in the SoftPOS system to save the master key and perform data processing through the working key, the problem of difficult key security in the SoftPOS system is solved, and the secure storage and processing of keys is realized.
Patent Information
- Application Number
- CN202411774048.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-12-05
AI Technical Summary
The SoftPOS system lacks SM security areas, and the PCI MPoC specification requires that the master key cannot appear in memory, making it difficult to guarantee the security of the key.
Save the master key through the Keystore, and use the working key for data processing during the key import and use process to ensure that the master key always exists in ciphertext and avoids long-term storage in memory.
The secure storage and processing of keys is realized, ensuring the security of keys in the SoftPOS system, and avoiding the risk of key leakage.
Smart Images

Figure CN119254437B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information security, and in particular to a method and device for implementing key import and key use. Background Art
[0002] SoftPOS (full name: Software POS) refers to the technology that uses software applications and mobile devices (such as smartphones, tablets, etc.) to complete retail transaction processing. SoftPOS systems usually include an application that can accept credit and debit card payments by connecting to the payment service provider's network. Compared with traditional POS devices, SoftPOS does not have an SM (English full name: Safe Module, Chinese full name: Security Module) security area, and the PCI MPoC specification requires that the master key cannot appear in the memory, so how to ensure the security of the key in SoftPOS 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 device for implementing key import and key use.
[0004] In a first aspect, an embodiment of the present invention provides a method for implementing key import and key use, which is applicable to a mobile device including a SoftPOS and a Keystore, wherein the SoftPOS includes an upper layer application and an SDK, wherein the SDK is integrated into the upper layer application or is independently configured with the upper layer application, and wherein the method includes a key import process and a key use process, wherein the key import process includes:
[0005] Step S1: When the key import interface of the SDK is called by the upper-layer application, the SDK calls the first interface of the Keystore and forwards the certificate chain returned by the first interface to the push service;
[0006] Step S2: The SDK receives the first encryption result, the first random number, the second encryption result and the label data returned by the push service forwarding HSM; the first encryption result is obtained by encrypting the first key generated by the HSM using the encapsulated public key in the first certificate of the certificate chain, and the second encryption result and the label data are obtained by processing the first random number and the master key generated by the HSM using the first key;
[0007] Step S3: the SDK sends the first encryption result, the first random number, the second encryption result, and the tag data to the Keystore for verification. If the verification is successful, the SDK stores the generated master key identifier and the master key obtained by decrypting the second encryption result through the Keystore in the Keystore in correspondence.
[0008] The key usage process includes:
[0009] Step T1: When the key encryption interface of the SDK is called by the upper-layer application, the SDK sends the master key identifier, the built-in preset data and the generated second random number to the Keystore, and receives the first working key returned by the Keystore, which is obtained by encrypting the built-in preset data and the second random number using the master key corresponding to the master key identifier;
[0010] Step T2: the SDK uses the first working key to encrypt the data to be processed to obtain a first ciphertext of the data to be processed, and sends the built-in preset data, the second random number and the first ciphertext of the data to be processed to the push service;
[0011] Step T3: the SDK receives the processing result ciphertext and the third random number returned by the HSM and forwarded by the push service;
[0012] Step T4: The SDK sends the third random number and the built-in preset data to the Keystore, receives a fourth working key returned by the Keystore, which is obtained by encrypting the built-in preset data and the third random number using the master key corresponding to the master key identifier, decrypts the processing result ciphertext using the fourth working key, obtains the processing result after successful decryption, performs subsequent operations based on the processing result, and clears the first working key and the fourth working key.
[0013] In a second aspect, an embodiment of the present invention further provides a device for implementing key import and key use, which is applied to a mobile device including a SoftPOS and a Keystore. The device is specifically arranged in the SoftPOS, integrated into an upper layer application in the SoftPOS or independently arranged from the upper layer application. The device includes a key import module and a key use module. The key import module includes:
[0014] A first receiving and forwarding unit, configured to call a first interface of the Keystore when the key import interface is called by the upper layer application, and forward the certificate chain returned by the first interface to the push service;
[0015] The first receiving unit is used to receive the first encryption result, the first random number, the second encryption result and the label data returned by the push service forwarding HSM; the first encryption result is obtained by encrypting the first key generated by the HSM using the encapsulated public key in the first certificate of the certificate chain, and the second encryption result and the label data are obtained by processing the first random number and the master key generated by the HSM using the first key;
[0016] A first sending unit, used for sending the first encryption result, the first random number, the second encryption result, and the label data to the Keystore for verification, and if the verification is successful, storing the generated master key identifier and the master key obtained by decrypting the second encryption result by the Keystore in the Keystore in correspondence;
[0017] The key usage module includes:
[0018] A first sending and receiving unit is used to send the master key identifier, the built-in preset data and the generated second random number to the Keystore when the key encryption interface is called by the upper layer application, and receive a first working key returned by the Keystore that is obtained by encrypting the built-in preset data and the second random number using the master key corresponding to the master key identifier;
[0019] A first encryption and sending unit, configured to encrypt the data to be processed using the first working key to obtain a first ciphertext of the data to be processed, and send the built-in preset data, the second random number and the first ciphertext of the data to be processed to the push service;
[0020] A second receiving and forwarding unit, configured to receive the processing result ciphertext and the third random number returned by the HSM and forwarded by the push service;
[0021] a sending and receiving decryption unit, configured to send the third random number and the built-in preset data to the Keystore, receive a fourth working key returned by the Keystore, which is obtained by encrypting the built-in preset data and the third random number using the master key corresponding to the master key identifier, decrypt the processing result ciphertext using the fourth working key, obtain a processing result upon successful decryption, perform subsequent operations based on the processing result, and clear the first working key and the fourth working key.
[0022] 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 method.
[0023] 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, and when the computer program runs on an electronic device, the electronic device executes any one of the methods described above.
[0024] 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 any of the methods described above.
[0025] Compared with the prior art, the present invention has the following advantages: in the technical solution of the present invention, a Keystore (Chinese name: key library) is used to store a master key, and the master key exists in ciphertext form during transmission and when it is passed to the Keystore. A working key is generated based on the master key in the Keystroe, and the working key is used for data processing. After the processing is completed, the working key is cleared, and the working key for each processing process is different, thereby achieving simple and safe implementation. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 A flowchart of a method for implementing key import and key use provided in Embodiment 1 of the present invention;
[0027] Figure 2 A schematic diagram of a system framework applicable to a method for implementing key import and key use provided in Embodiment 2 of the present invention;
[0028] Figure 3 A flowchart of a key import process of a method for implementing key import and key use provided in Embodiment 2 of the present invention;
[0029] Figure 4 A key usage process flow chart of a method for implementing key import and key usage provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0030] The present application proposes a method and device for implementing key import and key use. 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.
[0031] 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.
[0032] 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.
[0033] In this embodiment, Keystore is a secure container specifically used to store keys. The keys in Keystore exist permanently (i.e., the keys still exist after the application is closed or the device is restarted). The keys are suitable for sensitive information processing such as data encryption, signature, and identity authentication. The validity period, scope of use, and usage restrictions of the keys in Keystore can also be set to ensure that the keys can be safely deleted when not needed, and the keys can be used safely and reliably. The keys in Keystore are protected by hardware acceleration and a physical security module (TPM or HSM) to prevent the keys from being extracted or exposed, thereby enhancing key security.
[0034] Embodiment 1
[0035] Embodiment 1 of the present invention provides a method for implementing key import and key use, which is applicable to a mobile device including a Keystore and a SoftPOS. The SoftPOS includes an upper-layer application and an SDK (English full name: Software Development Kit, Chinese full name: Software Development Kit). The SDK is integrated into the upper-layer application, or the SDK and the upper-layer application are independently set.
[0036] like Figure 1 As shown, the method of this embodiment includes a key import process and a key use process, and the key import process includes:
[0037] Step S1: When the key import interface of the SDK is called by the upper-layer application, the SDK calls the first interface of the Keystore and forwards the certificate chain returned by the first interface to the push service;
[0038] In this embodiment, after the SDK calls the first interface of the Keystore, it also includes: when the first interface of the Keystore is called, the Keystore generates and saves an encapsulation key pair, generates a first certificate based on the encapsulation public key in the encapsulation key pair, generates a certificate chain based on the first certificate, and returns the certificate chain to the SDK.
[0039] Among them, in this embodiment, between step S1 and step S2, the following is also included:
[0040] Step B1: The push service verifies the received certificate chain using the verification certificate. If the verification succeeds, the encapsulated public key in the first certificate in the certificate chain is imported into the HSM, and step B2 is executed. If the verification fails, verification failure information is returned to the SDK.
[0041] The certificate chain includes a first certificate, a second certificate, a third certificate and a fourth certificate, and step B1 includes:
[0042] Step B11: The push service uses the public key in the fourth certificate to verify the third certificate. If the verification succeeds, step B12 is executed. If the verification fails, verification failure information is returned to the SDK.
[0043] Step B12: The push service uses the public key in the third certificate to verify the second certificate. If the verification succeeds, step B13 is executed. If the verification fails, verification failure information is returned to the SDK.
[0044] Step B13: The push service uses the public key in the second certificate to verify the first certificate. If the verification succeeds, step B14 is executed. If the verification fails, verification failure information is returned to the SDK.
[0045] Step B14: The push service determines whether the status of the verification certificate is valid. If so, step B15 is executed. Otherwise, verification failure information is returned to the SDK.
[0046] Optionally, in this embodiment, before step B14, the method further includes: the push service obtains and updates the status of the verification certificate according to a preset designated website at a preset time interval;
[0047] Optionally, before step B14, it also includes: the push service obtains the verification certificate revocation list according to the preset designated URL, and determines whether the fourth certificate is in the verification certificate revocation list. If so, it returns the verification failure information to the SDK, otherwise executes step B14; and / or before step B15, it also includes: determine whether the fourth certificate is within the validity period, if so, execute step B15, otherwise report an error.
[0048] Step B15: The push service determines whether the public key in the fourth certificate is consistent with the public key in the verification certificate. If so, the public key in the first certificate is imported into the HSM. If the verification fails, verification failure information is returned to the SDK.
[0049] Optionally, in this embodiment, before step B1, the process further includes: the push service downloads the verification certificate according to a preset designated website.
[0050] Step B2: The HSM saves the encapsulated public key, generates a first key, and uses the encapsulated public key to encrypt the first key to obtain a first encryption result;
[0051] Step B3: The HSM generates and saves a master key, and uses the first key to process the master key and the generated first random number in a preset mode according to a first preset algorithm to obtain label data and a second encryption result;
[0052] Step B4: The HSM returns the first encryption result, the second encryption result, the first random number and the label data to the push service;
[0053] Step B5: the push service receives the first encryption result, the second encryption result, the first random number and the tag data and forwards them to the SDK;
[0054] In this embodiment, step B5 includes: the push service receives the first encryption result, the first random number, the second encryption result and the label data returned by the HSM and assembles them according to a preset format, and sends the assembled result to the SDK.
[0055] Step S2: SDK receives the first encryption result, the first random number, the second encryption result and the label data returned by the HSM forwarded by the push service;
[0056] In this embodiment, the first encryption result is obtained by encrypting the first key generated by the HSM using the encapsulated public key in the first certificate of the certificate chain, and the second encryption result and the label data are obtained by processing the first random number and the master key generated by the HSM using the first key;
[0057] Step S3: The SDK sends the first encryption result, the first random number, the second encryption result, and the tag data to the Keystore for verification. If the verification is successful, the SDK stores the generated master key identifier and the master key obtained by decrypting the second encryption result through the Keystore in the Keystore in correspondence.
[0058] Specifically, in this embodiment, step S3 includes:
[0059] Step S31: SDK generates a master key identifier, and sends the master key identifier and assembly result to Keystore;
[0060] Step S32: Keystore determines whether the format of the assembly result is legal, if yes, executes step S33, otherwise returns an error message to the SDK;
[0061] Step S33: Keystore parses the assembly result to obtain the first encryption result, the second encryption result, the first random number and the label data, uses the encapsulation private key in the stored encapsulation key pair to decrypt the first encryption result, obtains the first key upon successful decryption, and generates the label data according to the second encryption result and the first random number;
[0062] Step S34: Keystore determines whether the generated tag data is the same as the tag data obtained by parsing. If yes, step S35 is executed. Otherwise, an error message is returned to the SDK.
[0063] Step S35: Keystore uses the first key to decrypt the second encryption result, and stores the master key and the master key identifier obtained by decryption in correspondence.
[0064] The key usage process includes:
[0065] Step T1: When the key encryption interface of the SDK is called by the upper-layer application, the SDK sends the master key identifier, the built-in preset data and the generated second random number to the Keystore, and receives the first working key returned by the Keystore, which is obtained by encrypting the preset data and the second random number using the master key corresponding to the master key identifier;
[0066] In this embodiment, after sending the master key identifier, built-in preset data and the generated second random number to the Keystore in step T1, it also includes: the Keystore obtains the corresponding saved master key according to the received master key identifier, uses the master key to encrypt the received preset data and the second random number to obtain a first working key, and returns the first working key to the SDK.
[0067] Step T2: The SDK uses the first working key to encrypt the data to be processed to obtain the first ciphertext of the data to be processed, and sends the preset data, the second random number and the first ciphertext of the data to be processed to the push service;
[0068] In this embodiment, the following steps are included between step T2 and step T3:
[0069] Step Y1: The push service receives the preset data, the second random number and the first ciphertext of the data to be processed and forwards them to the HSM;
[0070] Step Y2: The HSM uses the saved master key to encrypt the received preset data and the second random number to obtain a second working key, uses the second working key to decrypt the received first ciphertext of the data to be processed, decrypts successfully to obtain the data to be processed, uses the saved bank key to encrypt the data to be processed to obtain a second ciphertext of the data to be processed, and returns the second ciphertext of the data to be processed to the push service;
[0071] Step Y3: the push service receives the second ciphertext of the data to be processed returned by the HSM, forwards the second ciphertext of the data to be processed to the acquirer, receives the first ciphertext data returned by the acquirer and forwards it to the HSM;
[0072] Step Y4: The HSM uses the stored bank key to decrypt the received first ciphertext data, and the decryption is successful to obtain a processing result;
[0073] Step Y5: The HSM generates a third random number, uses the saved master key to encrypt the preset data and the third random number to obtain a third working key, uses the third working key to encrypt the processing result to obtain a processing result ciphertext, sends the processing result ciphertext and the third random number to the push service, and clears the second working key and the third working key;
[0074] Step Y6: The push service receives the processing result ciphertext and the third random number returned by the HSM and forwards them to the SDK, clearing the second working key and the third working key.
[0075] Step T3: The SDK receives the processing result ciphertext and the third random number returned by the HSM forwarded by the push service;
[0076] Step T4: The SDK sends the third random number and preset data to the Keystore, receives the fourth working key returned by the Keystore, which is obtained by encrypting the preset data and the third random number using the master key corresponding to the master key identifier, decrypts the processing result ciphertext using the fourth working key, obtains the processing result after successful decryption, performs subsequent operations based on the processing result, and clears the first working key and the fourth working key.
[0077] In this embodiment, the process in which the SDK sends the third random number and preset data to the Keystore and receives the fourth working key obtained by encrypting the preset data and the third random number with the master key returned by the Keystore in step T4 also includes: the Keystore uses the saved master key to encrypt the received preset data and the third random number to obtain the fourth working key, returns the fourth working key to the SDK, and clears the first working key and the fourth working key.
[0078] The method of this embodiment uses Keystore to save the master key, and the master key exists in ciphertext form during the transmission process and when it is passed to Keystore. A working key is generated based on the master key in Keystroe, and the working key is used for data processing. The working key is cleared after the processing is completed. The working key for each processing process is different, which implements simplicity and security.
[0079] Embodiment 2
[0080] Embodiment 2 of the present invention provides a method for implementing key import and key use, which is applicable to systems including Keystore, SDK, push service, and HSM, such as Figure 2 As shown, the Keystore and SDK are set in the mobile phone, and the SDK can be integrated into the upper-layer application in the SoftPOS of the mobile phone, or can be set in the SoftPOS of the mobile phone separately from the upper-layer application; the Keystore communicates with the SDK, and the SDK and the upper-layer application both communicate with the push service, and the push service communicates with the HSM; the user can trigger the Generate Key button of the upper-layer application, and then the upper-layer application calls the key import interface of the SDK to perform the key import operation, or the user can trigger the Transaction Confirmation button of the upper-layer application, and then the upper-layer application calls the key encryption interface of the SDK to use the key to complete the transaction operation;
[0081] like Figure 3 As shown, the key import process in this embodiment includes:
[0082] Step 101: When the key import interface of the SDK is called by the upper-layer application, the SDK calls the first interface of the Keystore;
[0083] The upper layer application in this embodiment may be a third-party application or an application of an SDK developer, and the upper layer application calls the SDK when receiving the user's import key trigger information;
[0084] For example, the first interface in this embodiment is:
[0085] KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,ANDROID_KEY_STORE);
[0086] KeyGenParameterSpec build = new KeyGenParameterSpec.Builder("0BFA5C2ECE6D486BBC0FC11C9233AB1347B925137FDAAB9AB7D924F6DB616AEB",
[0087] KeyProperties.PURPOSE_WRAP_KEY)
[0088] .setDigests(KeyProperties.DIGEST_SHA256)
[0089] .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_OAEP)
[0090] .setBlockModes(KeyProperties.BLOCK_MODE_ECB)
[0091] .setIsStrongBoxBacked(true)
[0092] .setAttestationChallenge(challenge)
[0093] .build();
[0094] keyPairGenerator.initialize(build);
[0095] KeyPair keyPair = keyPairGenerator.generateKeyPair();
[0096] Step 102: When the first interface of the Keystore is called, the Keystore generates an encapsulation key pair, generates a first certificate according to the encapsulation public key in the encapsulation key pair, generates a certificate chain according to the first certificate, and returns the certificate chain;
[0097] In this embodiment, the encapsulation key pair is an RSA key pair, including an encapsulation private key and an encapsulation public key; the certificate chain includes a first certificate, a second certificate, a third certificate and a fourth certificate;
[0098] Step 103: The SDK forwards the certificate chain to the push service;
[0099] Step 104: The push service verifies the received certificate chain using the verification certificate. If the verification succeeds, the encapsulated public key in the first certificate in the certificate chain is imported into the HSM. If the verification fails, verification failure information is returned to the SDK.
[0100] In this embodiment, before step 104, the method further includes: the push service downloads the verification certificate from Google according to a preset designated website;
[0101] The verification certificate in this embodiment is an x509 certificate, and the specified website is: https: / / developer.android.google.cn / privacy-and-security / security-key-attestation;
[0102] Specifically, step 104 includes:
[0103] Step A1: The push service uses the public key in the fourth certificate in the certificate chain to verify the third certificate in the certificate chain. If the verification succeeds, step A2 is executed. If the verification fails, verification failure information is returned to the SDK.
[0104] Step A2: The push service uses the public key in the third certificate in the certificate chain to verify the second certificate in the certificate chain. If the verification succeeds, step A3 is executed. If the verification fails, verification failure information is returned to the SDK.
[0105] Step A3: The push service uses the public key in the second certificate in the certificate chain to verify the first certificate in the certificate chain. If the verification succeeds, step A4 is executed. If the verification fails, verification failure information is returned to the SDK.
[0106] Step A4: The push service determines whether the status of the verification certificate is valid. If so, it executes step A5. Otherwise, it returns verification failure information to the SDK.
[0107] In this embodiment, the push service obtains and updates the status of the verification certificate from Google according to a preset designated URL at a preset time interval;
[0108] Optionally, in this embodiment, before step A4, the method further includes: the push service obtains a verification certificate revocation list from Google according to a preset designated website, and determines whether the fourth certificate in the certificate chain is in the verification certificate revocation list, and if so, returns verification failure information to the SDK, otherwise, executing step A4;
[0109] Step A5: The push service determines whether the public key in the fourth certificate in the certificate chain is consistent with the public key in the verification certificate. If yes, the encapsulated public key in the first certificate is imported into the HSM. Otherwise, verification failure information is returned to the SDK.
[0110] Optionally, in this embodiment, before step A5, the method further includes: determining whether the fourth certificate in the certificate chain is within the validity period, if yes, continuing to execute the next step, otherwise reporting an error;
[0111] Step 105: The HSM saves the encapsulated public key in the first certificate in the certificate chain, generates a first key, and uses the encapsulated public key in the first certificate to encrypt the first key to obtain a first encryption result;
[0112] The first key in this embodiment is an AES256 key;
[0113] Specifically, in this embodiment, the HSM generates a first key through a first generation interface, and encrypts the first key using the encapsulated public key in the first certificate through a first encryption interface to obtain a first encryption result;
[0114] For example, the first generation interface is: genSymmKey(), and the first encryption interface is LMKToOther();
[0115] For example, the first key generated in this embodiment is: 1A312F1DF82222D6CE7CD62AC25DCB7B82BB49840DDD8308712E7E4CC6EF97A4, and the first encryption result is: 84788769C6174E5A3DAE247117FA0A663E662DB9DEC672351AF98EC0315B 92C903209D30742D7EF45E7E8CF029A03A6D1555A60F75510127E9CC96E46B4CE09E91E2F74 4A8C47FD4BC90FB63175DFBFD491F089DF7291569C40A119D4509568DB4BEF6918BF5E609AD5 D07ED9DC67548D326BEFA6B83C4AC2CFC31A2830E14573945526356C2C0227DEC1DFD6ACBAB 255050CA5AF74E9866F3038303AD1B80E7969D4FD1210B90FC8A096C736932701A1793FDD55D A59EB78160AE8BC51ECC96A64FF1B50568982FC193E6B6BB8D138EDF9693702CF032B40F07E BB57FC4479CA96D14FF7232E09421B559BD342E211795B572C8EDF002CA4644BA5CDF95ACD9;
[0116] Step 106: The HSM generates a master key and a first random number, saves the master key, and encrypts the master key and the first random number using the first key in the GCM mode according to the AES algorithm to obtain the tag data and the second encryption result;
[0117] The master key in this embodiment is an AES128 key;
[0118] Specifically, the HSM generates a master key through a first generation interface, generates a first random number through a second generation interface, and encrypts the generated master key and the first random number using the first key in the GCM mode according to the AES algorithm through a first processing interface to obtain the tag data and the second encryption result;
[0119] For example, the second generation interface is genRandom(), and the first processing interface is: LMKToOther();
[0120] Specifically, in this embodiment, the master key and the first random number are encrypted using the first key in the GCM mode according to the AES algorithm to obtain the tag data and the second encryption result, including: segmenting the master key, using the first key to perform encryption operation on each segment of data according to the AES algorithm, splicing all encryption operation results to obtain the second encryption result, performing a preset operation on each encryption operation result and the first random number respectively and splicing the operation results to obtain verification information, and using the GCM algorithm to calculate the verification information to obtain the tag data;
[0121] For example, in this embodiment, the master key is: F2D9673A260747A1B24D6F9DD90559EC, the first random number is: 6540451C2812BD4C852BA319, the tag data is: F78A2939821B16EB5C9C823B11B1A474, and the second encryption result is: 9AFC544A9DF3F1F74535190A90E08F62;
[0122] Step 107: The HSM returns the first encryption result, the second encryption result, the first random number and the label data to the push service;
[0123] For example, in this embodiment, the data returned to the push service in step 107 is:
[0124] Step 108: The push service assembles the received first encryption result, the first random number, the second encryption result and the tag data according to a preset format, and sends the assembled result to the SDK;
[0125] Specifically, the preset format in this embodiment is the ASN.1 format;
[0126] Step 109: SDK generates a master key identifier, and sends the master key identifier and assembly result to Keystore;
[0127] In this embodiment, the master key identifier may be a key name or a key ID;
[0128] Step 110: Keystore determines whether the format of the assembly result is legal. If so, step 111 is executed. Otherwise, an error message is returned to the SDK.
[0129] Step 111: Keystore parses the assembly result to obtain the first encryption result, the second encryption result, the first random number and the label data, uses the saved encapsulation private key to decrypt the first encryption result, successfully decrypts to obtain the first key, and generates the label data according to the second encryption result and the first random number;
[0130] In this embodiment, the tag data is generated according to the second encryption result and the first random number, including: segmenting the second encryption result, respectively operating each segment of data with the first random number and concatenating the operation results to obtain verification information, and using the GCM algorithm to calculate the verification information to obtain the tag data;
[0131] Step 112: Keystore determines whether the generated tag data is the same as the parsed tag data. If yes, it executes step 113. Otherwise, it returns an error message to the SDK.
[0132] Step 113: Keystore decrypts the second encryption result using the first key, and stores the decrypted master key and the received master key identifier in correspondence with each other;
[0133] In this embodiment, the Keystore uses the first key to decrypt the second encryption result, including: using the first key to decrypt each segment of the second encryption result, and concatenating all the decrypted results to obtain a master key.
[0134] The key usage process in this embodiment is as follows Figure 4 As shown, including:
[0135] Step 201: When the key encryption interface of the SDK is called by the upper layer application, the SDK generates a second random number and sends the master key identifier, the built-in preset data and the second random number to the Keystore;
[0136] The upper layer application in this embodiment may be a third-party application or a developer's application, and the upper layer application calls the SDK when receiving the user's data processing trigger information;
[0137] For example, the preset data in this embodiment is: 6674637873616665, and the second random number is: 5f6e6ba0b5145677;
[0138] Step 202: Keystore obtains the corresponding saved master key according to the received master key identifier, uses the master key to encrypt the received preset data and the second random number to obtain a first working key, and returns the first working key to the SDK;
[0139] Specifically, in this embodiment, the Keystore uses the saved master key through the second encryption interface to encrypt the received preset data and the second random number to obtain the first working key;
[0140] For example, in this embodiment, the second encryption interface is: Cipher c = Cipher.getInstance("AES / ECB / NoPadding");
[0141] c.init(Cipher.ENCRYPT_MODE);
[0142] Keystore uses the master key F2D9673A260747A1B24D6F9DD90559EC through the second encryption interface to encrypt the preset data 6674637873616665 and the second random number 5f6e6ba0b5145677 to obtain the first working key C21047EE3761BF44E3C9676C9226B7BD;
[0143] Step 203: The SDK uses the received first working key to encrypt the data to be processed to obtain a first ciphertext of the data to be processed, and sends the preset data, the second random number and the first ciphertext of the data to be processed to the push service;
[0144] In this embodiment, the upper layer application uses the data to be processed as a parameter to call the key encryption interface of the SDK;
[0145] In this embodiment, the SDK uses the first working key C21047EE3761BF44E3C9676C9226B7BD to encrypt the data to be processed 12345678901234561234567890123456 to obtain the first ciphertext of the data to be processed 2E90841D587CD596D6E0EAE368E77AE7;
[0146] Step 204: The push service forwards the preset data, the second random number and the first ciphertext of the data to be processed to the HSM;
[0147] Step 205: The HSM uses the stored master key to encrypt the received preset data and the second random number to obtain a second working key, and uses the second working key to decrypt the received ciphertext of the first data to be processed, and the data to be processed is obtained upon successful decryption;
[0148] Specifically, in this embodiment, the HSM encrypts the received preset data and the second random number using the saved master key through the third encryption interface to obtain the second working key, and decrypts the received ciphertext of the data to be processed using the second working key through the first decryption interface;
[0149] For example, in this embodiment, the third encryption interface is: LMKToOther(), and the first decryption interface is: DataDec();
[0150] The preset data 6674637873616665 and the second random number 5f6e6ba0b5145677 are encrypted using the saved master key F2D9673A260747A1B24D6F9DD90559EC to obtain the second working key: C21047EE3761BF44E3C9676C9226B7BD; the first ciphertext of the data to be processed 2E90841D587CD596D6E0EAE368E77AE7 is decrypted using the second working key C21047EE3761BF44E3C9676C9226B7BD to obtain the data to be processed: 12345678901234561234567890123456;
[0151] Step 206: The HSM uses the stored bank key to encrypt the data to be processed to obtain a second ciphertext of the data to be processed, and returns the second ciphertext of the data to be processed to the push service;
[0152] Specifically, in this embodiment, the HSM uses the stored bank key to encrypt the data to be processed through the fourth encryption interface to obtain the second ciphertext of the data to be processed;
[0153] For example, in this embodiment, the fourth encryption interface is: DataEnc();
[0154] HSM uses the bank key 69A0D910B052E3C95027E630D43E16B1 to encrypt the data to be processed 12345678901234561234567890123456 to obtain the second ciphertext of the data to be processed F1515A3EFA7DAA0D4C0DBCA112147F68;
[0155] Step 207: The push service forwards the received second ciphertext of the data to be processed to the acquiring institution;
[0156] For example, in this embodiment, the ciphertext of the data to be processed forwarded by the push service to the acquirer is F1515A3EFA7DAA0D4C0DBCA112147F68;
[0157] Step 208: The push service receives the first ciphertext data returned by the acquirer and forwards it to the HSM;
[0158] For example, the first ciphertext data received by the push service in step 208 is B89E7B90F39B0C99E38F3C8280D6D2D5;
[0159] Step 209: The HSM decrypts the first ciphertext data using the stored bank key, and the decryption is successful to obtain a processing result;
[0160] Specifically, in this embodiment, the HSM decrypts the first ciphertext data using the stored bank key through the first decryption interface;
[0161] For example, the processing result obtained by successful decryption in step 209 is 1111111111111111111111111111111111;
[0162] Step 210: The HSM generates a third random number, uses the saved master key to encrypt the preset data and the third random number to obtain a third working key, and uses the third working key to encrypt the processing result to obtain a ciphertext of the processing result;
[0163] Specifically, in this embodiment, the HSM generates a third random number through a fourth generation interface, encrypts the preset data and the third random number using the saved master key through a fourth encryption interface to obtain a third working key, and encrypts the processing result using the third working key through the fourth encryption interface to obtain a processing result ciphertext; for example, the fourth generation interface is: genRandom();
[0164] In this embodiment, the third random number generated in step 210 is 6012b81296344367. The HSM uses the master key F2D9673A260747A1B24D6F9DD90559EC to encrypt the preset data 6674637873616665 and the third random number 6012b81296344367 to obtain a third working key: 9AE692AD8FD2D0FA8B6D41C316417AB6; the processing result 1 ...
[0165] Step 211: The HSM sends the processing result ciphertext and the third random number to the push service, and clears the second working key and the third working key;
[0166] For example, in this embodiment, the ciphertext of the processing result sent by the HSM to the push service in step 211 is 55BBBD2B9CE41AC799A4AD39F4BD8B27, and the third random number is 6012b81296344367;
[0167] Step 212: The push service forwards the processing result ciphertext and the third random number to the SDK;
[0168] Step 213: The SDK sends the third random number and preset data to the Keystore;
[0169] For example, in this embodiment, the third random number sent by the SDK to the Keystore in step 213 is 6012b81296344367, and the preset data is 6674637873616665;
[0170] Step 214: Keystore uses the obtained master key to encrypt the received preset data and the third random number to obtain a fourth working key, returns the fourth working key to the SDK, and clears the first working key and the fourth working key;
[0171] For example, in this embodiment, in step 214, the Keystore uses the master key F2D9673A260747A1B24D6F9DD90559EC to encrypt the preset data 6674637873616665 and the third random number 6012b81296344367 to obtain a fourth working key of 9AE692AD8FD2D0FA8B6D41C316417AB6;
[0172] The Keystore in this embodiment uses the saved master key through the second encryption interface to encrypt the received preset data and the third random number to obtain the fourth working key;
[0173] Step 215: The SDK uses the received fourth working key to decrypt the processing result ciphertext, and obtains the processing result if the decryption is successful. The SDK performs subsequent operations according to the processing result, and clears the received first working key and fourth working key.
[0174] The SDK in this embodiment decrypts the encrypted processing result using the received fourth working key through the second encryption interface;
[0175] For example, in this embodiment, in step 215, the SDK uses the fourth working key 9AE692AD8FD2D0FA8B6D41C316417AB6 to decrypt the encrypted processing result 55BBBD2B9CE41AC799A4AD39F4BD8B27, and the decryption is successful to obtain the processing result 11111111111111111111111111111111111;
[0176] In this embodiment, the processing result includes transaction success or transaction failure.
[0177] Embodiment 3
[0178] Embodiment 3 of the present invention provides a device for implementing key import and key use, which is applied to a mobile device including a SoftPOS and a Keystore. The device is specifically arranged in the SoftPOS, integrated into an upper layer application in the SoftPOS or arranged independently from the upper layer application. The device includes a key import module and a key use module. The key import module includes:
[0179] A first receiving and forwarding unit is used to call the first interface of the Keystore when the key import interface is called by the upper layer application, and forward the certificate chain returned by the first interface to the push service;
[0180] The first receiving unit is used to receive the first encryption result, the first random number, the second encryption result and the label data returned by the HSM forwarded by the push service; the first encryption result is obtained by encrypting the first key generated by the HSM using the encapsulated public key in the first certificate of the certificate chain, and the second encryption result and the label data are obtained by processing the first random number and the master key generated by the HSM using the first key;
[0181] A first sending unit is used to send the first encryption result, the first random number, the second encryption result, and the label data to the Keystore for verification. If the verification is successful, the generated master key identifier and the master key obtained by decrypting the second encryption result by the Keystore are stored in the Keystore in correspondence;
[0182] The key usage module includes:
[0183] A first sending and receiving unit is used to send the master key identifier, the built-in preset data and the generated second random number to the Keystore when the key encryption interface is called by the upper layer application, and receive the first working key returned by the Keystore by encrypting the preset data and the second random number using the master key corresponding to the master key identifier;
[0184] A first encryption and sending unit is used to encrypt the data to be processed using the first working key to obtain a first ciphertext of the data to be processed, and send the preset data, the second random number and the first ciphertext of the data to be processed to the push service;
[0185] A second receiving and forwarding unit, used to receive the processing result ciphertext and the third random number returned by the HSM forwarded by the push service;
[0186] A sending and receiving decryption unit is used to send a third random number and preset data to the Keystore, receive a fourth working key returned by the Keystore, which is obtained by encrypting the preset data and the third random number using a master key corresponding to the master key identifier, use the fourth working key to decrypt the processing result ciphertext, obtain the processing result after successful decryption, perform subsequent operations based on the processing result, and clear the first working key and the fourth working key.
[0187] The implementation functions of the push service, HSM and Keystore in this embodiment can refer to Embodiment 1 and Embodiment 2, and will not be repeated here.
[0188] 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 implementation method of key import and key use 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 implementation method of key import and key use disclosed in the above embodiment.
[0189] 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 method flow 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, data center, etc. that contains one or more servers that can be integrated with a medium. 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.
[0190] 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.
[0191] 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 key import and key use, characterized in that: Applicable to a mobile device including a SoftPOS and a Keystore, wherein the SoftPOS includes an upper layer application and an SDK, wherein the SDK is integrated into the upper layer application or is independently configured with the upper layer application, wherein the method includes a key import process and a key use process, wherein the key import process includes: Step S1: When the key import interface of the SDK is called by the upper-layer application, the SDK calls the first interface of the Keystore and forwards the certificate chain returned by the first interface to the push service; Step S2: The SDK receives the first encryption result, the first random number, the second encryption result and the label data returned by the push service forwarding HSM; the first encryption result is obtained by encrypting the first key generated by the HSM using the encapsulated public key in the first certificate of the certificate chain, and the second encryption result and the label data are obtained by processing the first random number and the master key generated by the HSM using the first key; Step S3: the SDK sends the first encryption result, the first random number, the second encryption result, and the tag data to the Keystore for verification. If the verification is successful, the SDK stores the generated master key identifier and the master key obtained by decrypting the second encryption result through the Keystore in the Keystore in correspondence. The key usage process includes: Step T1: When the key encryption interface of the SDK is called by the upper-layer application, the SDK sends the master key identifier, the built-in preset data and the generated second random number to the Keystore, and receives the first working key returned by the Keystore, which is obtained by encrypting the preset data and the second random number using the master key corresponding to the master key identifier; Step T2: the SDK uses the first working key to encrypt the data to be processed to obtain a first ciphertext of the data to be processed, and sends the preset data, the second random number and the first ciphertext of the data to be processed to the push service; Step T3: the SDK receives the processing result ciphertext and the third random number returned by the HSM and forwarded by the push service; Step T4: The SDK sends the third random number and the preset data to the Keystore, receives the fourth working key returned by the Keystore, which is obtained by encrypting the preset data and the third random number using the master key corresponding to the master key identifier, uses the fourth working key to decrypt the processing result ciphertext, obtains the processing result after successful decryption, performs subsequent operations based on the processing result, and clears the first working key and the fourth working key.
2. The method for implementing key import and key use according to claim 1, characterized in that: After the SDK calls the first interface of the Keystore, it also includes: when the first interface of the Keystore is called, the Keystore generates and saves an encapsulation key pair, generates a first certificate according to the encapsulation public key in the encapsulation key pair, generates a certificate chain according to the first certificate, and returns the certificate chain to the SDK.
3. The method for implementing key import and key use according to claim 1, characterized in that: The step S1 and the step S2 also include: Step B1: the push service verifies the received certificate chain using the verification certificate. If the verification succeeds, the encapsulated public key in the first certificate in the certificate chain is imported into the HSM, and step B2 is executed. If the verification fails, verification failure information is returned to the SDK. Step B2: the HSM saves the encapsulated public key, generates a first key, and uses the encapsulated public key to encrypt the first key to obtain a first encryption result; Step B3: the HSM generates and stores a master key, and uses the first key to process the master key and the generated first random number in a preset mode according to a first preset algorithm to obtain label data and a second encryption result; Step B4: the HSM returns the first encryption result, the second encryption result, the first random number and the label data to the push service; Step B5: The push service receives the first encryption result, the second encryption result, the first random number and the tag data and forwards them to the SDK.
4. The method for implementing key import and key use according to claim 3, characterized in that: The certificate chain includes a first certificate, a second certificate, a third certificate and a fourth certificate, and step B1 includes: Step B11: the push service verifies the third certificate using the public key in the fourth certificate. If the verification succeeds, step B12 is executed. If the verification fails, verification failure information is returned to the SDK. Step B12: the push service verifies the second certificate using the public key in the third certificate. If the verification succeeds, step B13 is executed. If the verification fails, verification failure information is returned to the SDK. Step B13: the push service verifies the first certificate using the public key in the second certificate. If the verification succeeds, step B14 is executed. If the verification fails, verification failure information is returned to the SDK. Step B14: the push service determines whether the status of the verification certificate is valid, and if so, executes step B15, otherwise returns verification failure information to the SDK; Step B15: The push service determines whether the public key in the fourth certificate is consistent with the public key in the verification certificate. If so, the public key in the first certificate is imported into the HSM. If the verification fails, verification failure information is returned to the SDK.
5. The method for implementing key import and key use according to claim 4, characterized in that: Before step B14, the method further includes: the push service obtains and updates the status of the verification certificate according to a preset designated website at a preset time interval.
6. The method for implementing key import and key use as claimed in claim 4, characterized in that: Before step B14, the push service also includes: obtaining a verification certificate revocation list according to a preset designated website, determining whether the fourth certificate is in the verification certificate revocation list, and if so, returning verification failure information to the SDK, otherwise executing step B14; and / or Before step B15, the method further includes: determining whether the fourth certificate is within the validity period, if yes, executing step B15, otherwise reporting an error.
7. The method for implementing key import and key use according to claim 3, characterized in that: Before step B1, the method further includes: the push service downloading the verification certificate according to a preset designated website.
8. The method for implementing key import and key use as claimed in claim 3, characterized in that: The step B5 includes: the push service receives the first encryption result, the first random number, the second encryption result and the label data returned by the HSM and assembles them according to a preset format, and sends the assembled result to the SDK.
9. The method for implementing key import and key use according to claim 8, characterized in that: The step S3 comprises: Step S31: the SDK generates a master key identifier, and sends the master key identifier and the assembly result to the Keystore; Step S32: the Keystore determines whether the format of the assembly result is legal, and if so, executes step S33, otherwise, returns an error message to the SDK; Step S33: the Keystore parses the assembly result to obtain a first encryption result, a second encryption result, a first random number and label data, decrypts the first encryption result using the encapsulation private key in the stored encapsulation key pair, obtains the first key upon successful decryption, and generates label data according to the second encryption result and the first random number; Step S34: the Keystore determines whether the generated tag data is the same as the tag data obtained by parsing, and if so, executes step S35, otherwise, returns an error message to the SDK; Step S35: the Keystore uses the first key to decrypt the second encryption result, and stores the decrypted master key and the master key identifier in correspondence with each other.
10. The method for implementing key import and key use according to claim 1, characterized in that: After sending the master key identifier, built-in preset data and the generated second random number to the Keystore in step T1, the Keystore also includes: obtaining the corresponding saved master key according to the received master key identifier, using the master key to encrypt the received preset data and the second random number to obtain a first working key, and returning the first working key to the SDK.
11. The method for implementing key import and key use according to claim 1, characterized in that: The step T2 and the step T3 also include: Step Y1: the push service receives the preset data, the second random number and the first ciphertext of the data to be processed and forwards them to the HSM; Step Y2: the HSM uses the saved master key to encrypt the received preset data and the second random number to obtain a second working key, uses the second working key to decrypt the received first ciphertext of the data to be processed, decrypts successfully to obtain the data to be processed, uses the saved bank key to encrypt the data to be processed to obtain a second ciphertext of the data to be processed, and returns the second ciphertext of the data to be processed to the push service; Step Y3: the push service receives the second ciphertext of the data to be processed returned by the HSM, forwards the second ciphertext of the data to be processed to the acquirer, receives the first ciphertext data returned by the acquirer and forwards it to the HSM; Step Y4: the HSM uses the stored bank key to decrypt the received first ciphertext data, and obtains a processing result if the decryption is successful; Step Y5: the HSM generates a third random number, uses the saved master key to encrypt the preset data and the third random number to obtain a third working key, uses the third working key to encrypt the processing result to obtain a processing result ciphertext, sends the processing result ciphertext and the third random number to the push service, and clears the second working key and the third working key; Step Y6: The push service receives the processing result ciphertext and the third random number returned by the HSM and forwards them to the SDK, and clears the second working key and the third working key.
12. The method for implementing key import and key use according to claim 1, characterized in that: The step T4 in which the SDK sends the third random number and the preset data to the Keystore and receives the fourth working key returned by the Keystore by encrypting the preset data and the third random number with the master key also includes: the Keystore uses the saved master key to encrypt the received preset data and the third random number to obtain a fourth working key, returns the fourth working key to the SDK, and clears the first working key and the fourth working key.
13. A device for implementing key import and key use, characterized in that: Applied to a mobile device including a SoftPOS and a Keystore, the device is specifically arranged in the SoftPOS, integrated into an upper layer application in the SoftPOS or arranged independently from the upper layer application, the device includes a key import module and a key use module, and the key import module includes: A first receiving and forwarding unit, configured to call a first interface of the Keystore when the key import interface is called by the upper layer application, and forward the certificate chain returned by the first interface to the push service; The first receiving unit is used to receive the first encryption result, the first random number, the second encryption result and the label data returned by the push service forwarding HSM; the first encryption result is obtained by encrypting the first key generated by the HSM using the encapsulated public key in the first certificate of the certificate chain, and the second encryption result and the label data are obtained by processing the first random number and the master key generated by the HSM using the first key; A first sending unit, used for sending the first encryption result, the first random number, the second encryption result, and the label data to the Keystore for verification, and if the verification is successful, storing the generated master key identifier and the master key obtained by decrypting the second encryption result by the Keystore in the Keystore in correspondence; The key use module includes: A first sending and receiving unit is used to send the master key identifier, the built-in preset data and the generated second random number to the Keystore when the key encryption interface is called by the upper layer application, and receive a first working key returned by the Keystore that is obtained by encrypting the preset data and the second random number using the master key corresponding to the master key identifier; A first encryption and sending unit, configured to encrypt the data to be processed using the first working key to obtain a first ciphertext of the data to be processed, and send the preset data, the second random number and the first ciphertext of the data to be processed to the push service; A second receiving and forwarding unit, configured to receive the processing result ciphertext and the third random number returned by the HSM and forwarded by the push service; a sending and receiving decryption unit, used for sending the third random number and the preset data to the Keystore, receiving a fourth working key returned by the Keystore, which is obtained by encrypting the preset data and the third random number using the master key corresponding to the master key identifier, decrypting the processing result ciphertext using the fourth working key, obtaining a processing result upon successful decryption, performing subsequent operations according to the processing result, and clearing the first working key and the fourth working key.
14. 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 12.
15. 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 perform the method according to any one of claims 1 to 12.
16. 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 12.
Citation Information
Patent Citations
Method, device and system for implementing secret key import
CN107888381A
Communication method and system
CN115314189A