Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is only the present invention's part embodiment, rather than whole embodiment.Based on the embodiment in the present invention, those skilled in the art, not making the every other embodiment obtaining under creative work prerequisite, belong to the scope of protection of the invention.
Embodiment 1
The present embodiment provides a kind of endorsement method of signature device, wherein equipment can be USBKey equipment, also can be that other can do the equipment of signing, the record data of mentioning in the present embodiment can contrast the parameter UserID mentioning in background technology and understand, the signature pre-service result of mentioning in the present embodiment can contrast the Z value of mentioning in background technology to be understood, and this endorsement method comprises:
Step 1: device power, initialization;
Step 2: equipment receives the instruction that host computer issues;
Step 3: equipment judges the type of the instruction receiving, carries out command adapted thereto operation according to the type of described instruction, and returns to response message to host computer;
This step specifically comprises: the type that judges described instruction when equipment is when opening application instruction, according to the described Apply Names comprising in application instruction of opening, open the application corresponding with described Apply Names on equipment, to host computer, return and open application responds message;
The type that judges described instruction when equipment is when opening container instruction, according to the described application identities comprising in container instruction of opening, determine current application, according to the described Container Name comprising in container instruction of opening, open the specified containers corresponding with described Container Name under current application, to host computer, return and open container response message;
Whether the type that judges described instruction when equipment when producing key to instruction, stores signature pre-service result in the default memory block of judgement, be first to remove described signature pre-service result in default memory block to carry out and generate the right operation of key; Otherwise directly carry out, generate the right operation of key; The right operation of described generation key is specially: according to described generation key, the application identities comprising in instruction and container identification are determined to the specified containers under current application, according to described generation key, the key information comprising in instruction is created to public and private key file structure in specified containers, according to described generation key, the file identification comprising in instruction and recording mechanism are filled to the key pair that obtains generation to the presupposed information in described public and private key file structure, to host computer, return and produce key to response message;
When equipment judges that the type of described instruction is signature command, according to the application identities comprising in described signature command and container identification, determine the specified containers under current application, in the default memory block of judgement, whether store signature pre-service result, directly to obtain described signature pre-service result, otherwise obtain file identification and recording mechanism according to the right file structure of the key in specified containers, according to the file identification obtaining and recording mechanism, from the log file corresponding with described file identification, obtain record data corresponding with described recording mechanism, according to the PKI of cipher key pair and described record data, calculate a signature pre-service result and store default memory block into,
According to the private key of the cipher key pair in described signature pre-service result, specified containers, the data to be signed that comprise in described signature command are calculated to signature result, to host computer, return to signature response message.
The endorsement method that the present embodiment proposes, receive open container instruction and produce key during to instruction operation the signature key associated with main body is put in specified containers, when receiving signature command the signature operation of doing use the described signature key associated with main body, thereby strengthened the association between main body and signature key, can effectively prevent the abuse of identity and mandate, strengthen the security of signature.
Embodiment 2
The present embodiment provides a kind of endorsement method of signature device, wherein equipment can be USBKey equipment, also can be that other can do the equipment of signing, the record data of mentioning in the present embodiment can contrast the parameter UserID mentioning in background technology to be understood, and the signature pre-service result of mentioning in the present embodiment can contrast the Z value of mentioning in background technology and understand.
The endorsement method that the present embodiment proposes has comprised record data management process and signature process, as shown in Figure 1, the wherein inter-process flow process of step 8-18 equipment when to be keeper manage log file or record data, step 19-30 is that user uses equipment to do the inter-process flow process that produces key equipment when with signature operation, and the method comprises:
Step 1: device power, initialization;
Step 2: equipment receives the instruction that host computer issues;
Step 3: equipment judges the type of the instruction receiving, if open application instruction, perform step 4, if test PIN instruction, perform step 6, if create log file instruction, perform step 10, if write recording instruction, perform step 13, if open container instruction, perform step 15, if produce key, instruction is performed step to 18, if signature command performs step 21;
Concrete in the present embodiment, according to the 1st and the 2nd of the instruction receiving the byte decision instruction type, the instruction receiving when the 1st and the 2nd byte is 0,x80 26 is to open application instruction, the instruction receiving when the 1st and the 2nd byte is 80 18 is to test PIN instruction, the instruction receiving when the 1st and the 2nd byte is 0,x80 30 is to create log file instruction, the instruction receiving when the 1st and the 2nd byte is 0x80 3A is to write recording instruction, the instruction receiving when the 1st and the 2nd byte is 0,x80 42 is to open container instruction, the instruction receiving when the 1st and the 2nd byte is 0,x80 70 is to produce key to instruction, the instruction receiving when the 1st and the 2nd byte is 0,x80 74 is signature command.
Step 4: open an application on equipment according to opening the Apply Names comprising in application instruction;
This step specifically comprises:
Step 4-1: obtain a length value according to the 5th and the 6th byte opening application instruction, whether the length that judges the 6th byte data field data afterwards conforms to this length value, be to perform step 4-2, otherwise generate, comprise opening application responds message and performing step 5 of status code;
Preferably, the status code value comprising in application responds message of opening that this step generates is the second preset value, and for example the second preset value is 0x6700.
Step 4-2: according to the described data field data title that is applied, open application corresponding with this Apply Names on equipment;
Further, when there is not the application corresponding with this Apply Names on equipment, generate comprise status code open application responds message, and this status code value is the 3rd preset value, for example the 3rd preset value is 0x6A8B.Or on the equipment finding existing application of opening and equipment do not support to open simultaneously multiple application generate comprise status code open application responds message, and this status code value is the 4th preset value, for example the 4th preset value is 0x6A90.
That for example: the application instruction of opening receiving is 80 26 00 00 00000C Application1, opens is applied as Application1.
Step 5: return and open application responds message to host computer, then return to step 2.
Concrete, when step 4 is correct while carrying out this step returns comprise status code and response data open application responds message, and the status code SW1SW2 value comprising is the first preset value, for example the first preset value is 0x9000; The response data comprising is specially the attribute information of application, as apply lower establishment file and container authority, apply supported maximum number of containers, apply supported maximum certificate quantity, apply supported maximum number of files and attribute information such as application ID etc.; When step 4 occur in the process of implementation this step when wrong return comprise status code open application instruction response message, and the status code SW1SW2 value comprising is other values.For example, other values comprise 0x6700,0x6A8B, 0x6A90 etc.
Step 6: obtain PINID, application ID and PIN code from test PIN instruction;
This step specifically comprises:
Step 6-1: obtain PINID according to the 4th byte testing PIN instruction, according to 5-7 byte, obtain a length value, whether the length that judges the 7th byte data field data afterwards conforms to this length value, be to perform step 6-2, otherwise generate, comprise testing PIN response message and performing step 9 of status code;
Preferably, the status code value comprising in PIN response message of testing that this step generates is the second preset value, and for example the second preset value is 0x6700.
Step 6-2: ID and PIN code are applied from described data field data according to the first preset structure.
Concrete, described the first preset structure is: apply ID(2 byte)+PIN code (16 bytes).
Step 7: determine registrant's identity according to PINID, ID determines current application according to application, and verifies that whether PIN code is correct, is to perform step 8, otherwise execution step 9;
Preferably, when PINID value is 0x00, registrant's identity is keeper, and when PINID value is 0x01, registrant's identity is user.
Further, when being the application of not opening according to the definite current application of application ID, generating and comprise testing PIN response message and performing step 9 of status code; Preferably, this status code value is the 5th preset value, and for example the 5th preset value is 0x698A.
Step 8: current logging status is set according to registrant's identity;
Concrete, when registrant's identity arranges current logging status during for keeper, be keeper's logging status, when registrant's identity arranges current logging status during for user, be user's logging status.
For example, the checking PIN instruction receiving is 80 18 00 00 000,012 0,100 31 32 33 34 35 36 37 38 31 32 33 34 35 36 37 38, according to this instruction, determine that registrant's identity is for keeper, the application ID obtaining from instruction is 0x0100, PIN code is 31 32 33 34 35 36 37 38 31 32 33 34 35 36 37 38, current logging status is set when checking PIN code is correct for keeper's login.
Step 9: return and test PIN response message to host computer, then return to step 2.
Concrete, when step 6-step 8 is correct while carrying out this step returns comprise status code test PIN response message, and the status code SW1SW2 value comprising is the first preset value, for example the first preset value is 0x9000; When step 6-step 8 occur in the process of implementation when wrong that this step is returned to test the status code SW1SW2 value comprising in PIN response message be other values.For example, other values comprise 0x6700,0x698A etc.
Step 10: judge whether current logging status is keeper's logging status, is to perform step 11, otherwise returns to the status code of not supporting, returns to step 2;
Step 11: determine current application according to creating the application ID comprising in log file instruction, create a log file according to creating the log file information comprising in log file instruction under current application;
This step specifically comprises:
Step 11-1: according to the 3rd and the 4th of the instruction of described establishment log file the byte ID that is applied, ID determines current application according to this application;
Further, if can not find application according to application ID on equipment, generate the establishment log file response message that comprises status code, preferred, the value of described status code SW1SW2 is the 6th preset value, and for example the 6th preset value is 0x6A88.
Step 11-2: obtain a length value according to the 5th of the instruction of described establishment log file the to the 7th byte, whether the length that judges the 7th the data field data after byte conforms to this length value, be to carry out next step, otherwise generate the establishment log file response message that comprises status code;
Preferably, in this step, the value of SW1SW2 is the second preset value, and for example the second preset value is 0x6700.
Step 11-3: obtain the log file information that will create according to the second preset structure from described data field data;
Described log file information comprises: filename, file size, read right sign and write permission sign.Described the second preset structure is: filename (32 bytes)+file size (4 bytes)+read right sign (4 bytes)+write permission sign (4 bytes).Preferably, 32 byte 0 covers of filename less than; It is readable that read right is designated 10000000 expressions, and write permission is designated 10000000 signs and can writes.
Step 11-4: create log file according to log file information under current application.
Further, this step can also comprise according to the filename in log file information judging under current application whether had file of the same name, is to generate the establishment log file response message that comprises status code, otherwise creates log file under current application; Preferably, in this step, the value of SW1SW2 is the 7th preset value, and for example the 7th preset value is 0x6A92.
For example: the establishment log file instruction receiving is: 80 30 1001 00002C useridrecordfile1 000,000,000,000,000,000,000,000,000,000 00,010,000 10,000,000 10000000; The log file creating according to this instruction is useridrecordfile1, and this log file be one readable, can written document.
Step 12: return and create log file response message to host computer, then return to step 2.
Concrete, the status code SW1SW2 value comprising in the establishment log file response message that this step is returned when the correct execution of step 11 is the first preset value, for example the first preset value is 0x9000, in the data field of establishment log file response message, goes back include file name and file ID; The status code SW1SW2 comprising in the establishment log file response message that this step is returned when makeing mistakes in step 11 implementation is taken as other values, for example: other values comprise 0x6700,0x6A88,0x6A92 etc.
Step 13: determine current application according to writing the application ID comprising in recording instruction, according to writing the filename comprising in recording instruction, under current application, find a log file, according to writing the side-play amount comprising in instruction, by writing the record data to be written that comprise in recording instruction, be written to the appropriate address in this log file;
This step specifically comprises:
Step 13-1: according to the 5th and the 6th of said write recording instruction the byte ID that is applied, ID determines current application according to this application;
Step 13-2: obtain a length value according to the 7th and the 8th of said write recording instruction the byte, whether the length that judges the 8th the data field data after byte conforms to this length value, to carry out next step, otherwise generate comprise status code write recording responses message;
Preferably, in this step, the value of SW1SW2 is the second preset value, and for example the second preset value is 0x6700.
Step 13-3: obtain side-play amount, filename and record data to be written according to the 3rd preset structure from described data field data;
Concrete, described the 3rd preset structure is: length (2 bytes)+record data to be written of side-play amount (2 bytes)+filename length (2 bytes)+filename+record data to be written.
Further, this step can also comprise the process of the filename comprising in the 3rd preset structure and record data to be written length separately being verified according to the length of the filename length in the 3rd preset structure and record data to be written.When there is the situation of size error, generate comprise status code write recording responses message; Preferably, in this step, the value of SW1SW2 is the second preset value, and for example the second preset value is 0x6700.
Step 13-4: find a log file according to filename under current application, determine in log file according to side-play amount and a writing address described record data to be written are write to this writing address.
Concrete, according to this writing address, can determine the recording mechanism of record data.For example, writing address is 0000, and corresponding recording mechanism is 1.
Further, this step can also comprise:
The first step: judging under current application whether have the log file corresponding with this filename according to filename, is to carry out second step, otherwise generate comprise status code write recording responses message; Preferably, in this step, the value of SW1SW2 is the 8th preset value, and for example the 8th preset value is 0x6A93.
Second step: judge whether side-play amount exceeds the size of described log file, be generate comprise status code write recording responses message, otherwise determine an assigned address in log file, described record data to be written are write to this assigned address.Preferably, in this step, the value of SW1SW2 is the 9th preset value, and for example the 9th preset value is 0x6B00.
For example: the recording instruction that writes of receiving is 80 3A 00 00 000,029 0,100 0,000 1100 useridrecordfile1 1,000 1234567812345678, record data 1234567812345678 is write to the position that in log file useridrecordfile1, offset address is 0000.
Step 14: return and write recording responses message to host computer, then return to step 2.
For example: this step is returned while carrying out the status code SW1SW2 value comprising in recording responses message that writes is the first preset value when step 13 is correct, and for example the first preset value is 0x9000, write in the data field of recording responses message and also comprise recording mechanism; The status code SW1SW2 comprising in recording responses message that writes that this step is returned when makeing mistakes in step 13 implementation is taken as other values, for example: other values comprise 0x6700,0x6A93,0x6B00 etc.
Step 15: judge whether current logging status is user's logging status, is to perform step 16, otherwise returns to the status code of not supporting, returns to step 2;
Step 16: determine current application according to opening the application ID comprising in container instruction, open the specified containers under current application according to opening the Container Name comprising in container instruction;
This step specifically comprises:
Step 16-1: obtain a length value according to the 5th to the 7th byte opening container instruction, whether the length that judges the 7th byte data field data afterwards conforms to this length value, to carry out next step, otherwise generate comprise status code open container response message, execution step 17;
Preferably, the value of status code SW1SW2 is the second preset value described in this step, and for example the second preset value is 6700.
Step 16-2: ID and Container Name are applied from described data field data according to the 4th preset structure;
Concrete, described the 4th preset structure is: application ID+ Container Name;
Step 16-3: ID determines current application according to application, finds specified containers according to Container Name under current application, opens specified containers;
Further, if can not find application according to application ID on equipment, generate comprise status code open container response message, preferred, the value of described status code SW1SW2 is the 6th preset value, for example the 6th preset value is 0x6A88.If can not find specified containers according to Container Name under current application, generate comprise status code open container response message, preferred, the value of described status code SW1SW2 is the tenth preset value, for example the tenth preset value is 0x6A91.
The container of mentioning in the present embodiment be one for deposit unsymmetrical key to the object logic of session key.
For example: the container instruction of opening receiving is 80 42 00 00 00000C 0100 Container1 0002, opening application ID is the specified containers Container1 under 0100.
Step 17: return and open container response message to host computer, then return to step 2.
Concrete, when step 16 is correct while carrying out this step returns comprise status code and response data open container response message, and the status code SW1SW2 value comprising is the first preset value, the response data comprising is specially Container ID; When step 16 occur in the process of implementation this step when wrong return comprise status code open container response message, and the status code SW1SW2 comprising is taken as other values.For example, other values are 0x6700,0x6A88 and 0x6A91.
Step 18: judge whether current logging status is user's logging status, is to perform step 19, otherwise returns to the status code of not supporting, returns to step 2;
Step 19: the application ID comprising in instruction and Container ID are determined to the specified containers under current application according to producing key, according to producing key, the key information comprising in instruction is created to public and private key file structure in specified containers, according to producing key, the file ID comprising in instruction and recording mechanism are filled to the key pair that obtains generation to the presupposed information in described public and private key file structure;
Specifically comprising of this step:
Step 19-1: the 5th of instruction the to the 7th byte obtained to a length value according to producing key, whether the length that judges the 7th byte data field data afterwards conforms to this length value, to carry out next step, otherwise generate comprise status code open container response message;
Preferably, length value is preset length described in this step, and the value of for example preset length is 8, and the value of described status code SW1SW2 is the second preset value, and for example the second preset value is 0x6700.
Step 19-2: ID, Container ID, key information, file ID and recording mechanism are applied from described data field data according to the 5th preset structure;
Concrete, described the 5th preset structure is: apply ID(2 byte)+Container ID (2 bytes)+key information (4 bytes)+file ID (2 bytes)+recording mechanism (2 bytes); Described key information comprises that the right position of generation key is long.
Step 19-3: determine the specified containers under current application according to application ID and Container ID, according to producing key, the key information comprising in instruction is created to public and private key file structure in specified containers;
Further, if can not find application according to application ID on equipment, generate the generation key that comprises status code to response message, preferred, the value of described status code SW1SW2 is the 6th preset value, and for example the 6th preset value is 0x6A88.If can not find specified containers according to Container ID under current application, generate the generation key that comprises status code to response message, preferred, the value of described status code SW1SW2 is the 11 preset value, for example the 11 preset value is 0x6A94.
Concrete, described public and private key file structure is as follows:
Step 19-4: the presupposed information in described public and private key file structure is filled to the key pair that obtains generation according to described file ID and recording mechanism.
Concrete, described presupposed information comprises uidRecordFID and uidRecordNo.
For example, the generation key receiving is 80 70 00 00 00000C 0,100 0,100 000 10,000 1,001 0100 to instruction, and the presupposed information comprising in the right file structure of the key of generation is: uidRecordFID=1001, uidRecordNo=0100.
Further, before above-mentioned steps 19-2, also comprise: judge whether described generation key meets the 5th preset structure to the data field data of instruction, to perform step the key pair of 19-2 to step 19-4 generation SM2 type, otherwise generate the key pair of other types, the key of other types to and corresponding endorsement method not within the scope of the invention, at this, do not describe in detail.
Preferably, before above-mentioned steps 19, can also comprise: in the default memory block of judgement, whether storing signature pre-service result, is that the described signature pre-service result of first removing in default memory block performs step 19 again; Otherwise directly perform step 19.And the signature pre-service result store calculating in step 19 is arrived to default memory block.
Step 20: return and produce key to response message to host computer, then return to step 2.
Concrete, when step 19 is correct while carrying out, this step is returned to the generation key that comprises status code and response data to response message, and the status code SW1SW2 value comprising is the first preset value, and the response data comprising is specially the key of generation to related data; When mistake appears in step 19 in the process of implementation, this step is returned to the generation key that comprises status code to response message, and the status code SW1SW2 comprising is taken as other values.For example, other values are 0x6700,0x6A88 and 0x6A94.
Step 21: judge whether current logging status is user's logging status, is to perform step 22, otherwise returns to the status code of not supporting, returns to step 2;
Step 22: determine the specified containers under current application according to the application ID comprising in signature command and Container ID, according to the right file structure of the key in specified containers, obtain file ID and recording mechanism, according to the file ID obtaining and recording mechanism, from log file, obtain record data, according to cipher key pair PKI and described record data, calculate a signature pre-service result, according to signature pre-service result, cipher key pair private key, the data to be signed that comprise in signature command are calculated to signature result;
This step specifically comprises:
Step 22-1: obtain a length value according to the 5th of signature command the to the 7th byte, judge whether the length of the 7th byte data field data afterwards conforms to this length value, be to carry out next step, otherwise generate the signature response message that comprises status code;
Preferably, the value of described status code SW1SW2 is the second preset value, and for example the second preset value is 0x6700.
Step 22-2: ID, Container ID and data to be signed are applied from described data field data according to the 6th preset structure;
Concrete, described the 6th preset structure is: application ID+ Container ID+data to be signed;
Step 22-3: determine the specified containers under current application according to application ID and Container ID, from specified containers, obtain key pair, according to the right file structure of key, obtain file ID and recording mechanism, according to the file ID obtaining and recording mechanism, from log file, obtain record data;
Concrete, according to file ID, find a log file, according to recording mechanism, can in this log file, read record data.
Further, if can not find application according to application ID on equipment, generate the signature response message that comprises status code, preferred, the value of this status code SW1SW2 is the 6th preset value, and for example the 6th preset value is 6A88.If can not find specified containers according to Container ID under current application, generate the signature response message that comprises status code, preferred, the value of this status code SW1SW2 is the 11 preset value, for example the 11 preset value is 6A94; If obtain from specified containers less than key pair, generate the signature response message that comprises status code, preferred, the value of described status code SW1SW2 is the 12 preset value, for example the 12 preset value is 6A95.If can not find corresponding with it log file or obtain less than corresponding with it record data according to file ID and recording mechanism, generate the signature response message that comprises status code, preferred, described status code value is the 13 preset value.
Step 22-4: calculate a signature pre-service result according to the PKI of cipher key pair and the described record data that obtain, according to the private key of signature pre-service result, cipher key pair, described data to be signed are calculated to signature result.
For example, the signature command receiving is: 80 74 03 00 000,024 01,000,100 12345678123456781234567812345678.
Preferably, in above-mentioned steps 22, can also comprise: in the default memory block of judgement, whether store signature pre-service result, to obtain described signature pre-service result, otherwise obtain file identification and recording mechanism according to the right file structure of the key in specified containers, according to the file identification obtaining and recording mechanism, from the log file corresponding with described file identification, obtain record data corresponding with described recording mechanism, according to cipher key pair PKI and described record data, calculate a signature pre-service result and store default memory block into.
Step 23: return to signature response message to host computer, then return to step 2.
It should be noted that, before above-mentioned steps 22, also comprising: whether the 3rd byte that judges signature command is default value, is to perform step 22 execution SM2 signatures, otherwise carries out other algorithm signatures, other algorithms are signed not within the scope of the invention, at this, do not describe in detail.Preferably, described default value is 0x03.
Concrete, when step 22 is correct while carrying out, this step is returned to the signature response message that comprises status code and response data, and the status code SW1SW2 value comprising is the first preset value, and the response data comprising is specially signature result; When mistake appears in step 22 in the process of implementation, this step is returned to the signature response message that comprises status code, and the status code SW1SW2 comprising is taken as other values.For example, other values are 0x6700,0x6A88,0x6A94 and 0x6A95.
The endorsement method of the signature device that the present embodiment proposes, may be summarized to be: first, the management function of infosystem possesses the distribution function of initializing of USBKey, at initial phase, in USBKey, create log file and preserve the record data of user's related application, after initialization completes, USBKey enters the application stage.
When user applies for certificate, in USBKey, generate key to rear, automatic mark with indicated with key associated record data, when signature operation, use.
When signature, use and specified with key, the record data that are associated are calculated to Z value, thereby complete the preprocessing function of endorsement method, complete signature.
What in the present embodiment, mention is preferably implementation of one, the implementation of embodiment 1 relatively, it is registrant's identity that the endorsement method of the present embodiment further defines main body, when logining, keeper can complete the establishment of record data, when user's login is signed, by opening application instruction, open container instruction, produce key instruction and signature command are completed to whole signature process, can reach equally association between strengthening main body and signature key, effectively prevent identity and mandate abuse, strengthen the effect of the security of signing.The ID mentioning in the present embodiment does same understanding with the sign of mentioning in embodiment 1.
The above; only for preferably embodiment of the present invention, but protection scope of the present invention is not limited to this, is anyly familiar with those skilled in the art in technical scope disclosed by the invention; the variation that can expect easily or replacement, within all should being encompassed in protection scope of the present invention.Therefore, protection scope of the present invention should be as the criterion with the protection domain of claim.