diff --git a/hpki/Project/Sources/Classes/pkiForm.4dm b/hpki/Project/Sources/Classes/pkiForm.4dm index acbc19a..f028912 100644 --- a/hpki/Project/Sources/Classes/pkiForm.4dm +++ b/hpki/Project/Sources/Classes/pkiForm.4dm @@ -19,6 +19,7 @@ Function onLoad() Form:C1466.SHA1:=False:C215 Form:C1466.SHA256:=True:C214 + Form:C1466.SHA384:=False:C215 Form:C1466.SHA512:=False:C215 Form:C1466.list() @@ -31,6 +32,8 @@ Function get algorithm : Text return "sha1" : (Form:C1466.SHA512) return "sha512" + : (Form:C1466.SHA384) + return "sha384" Else return "sha256" End case diff --git a/hpki/Project/Sources/Forms/hpki/form.4DForm b/hpki/Project/Sources/Forms/hpki/form.4DForm index 2b00b4a..514a887 100644 --- a/hpki/Project/Sources/Forms/hpki/form.4DForm +++ b/hpki/Project/Sources/Forms/hpki/form.4DForm @@ -354,51 +354,6 @@ "sizingY": "fixed", "sizingX": "fixed" }, - "SHA1": { - "type": "radio", - "text": "SHA1", - "top": 432, - "left": 329, - "width": 71, - "height": 25, - "events": [ - "onClick" - ], - "dataSourceTypeHint": "boolean", - "dataSource": "Form:C1466.SHA1", - "radioGroup": "SHA", - "focusable": false - }, - "SHA2": { - "type": "radio", - "text": "SHA256", - "top": 432, - "left": 409, - "width": 91, - "height": 25, - "events": [ - "onClick" - ], - "dataSourceTypeHint": "boolean", - "dataSource": "Form:C1466.SHA256", - "radioGroup": "SHA", - "focusable": false - }, - "SHA5": { - "type": "radio", - "text": "SHA512", - "top": 432, - "left": 509, - "width": 91, - "height": 25, - "events": [ - "onClick" - ], - "dataSourceTypeHint": "boolean", - "dataSource": "Form:C1466.SHA512", - "radioGroup": "SHA", - "focusable": false - }, "digestInfo": { "type": "input", "left": 107, @@ -455,6 +410,66 @@ "enterable": false, "sizingX": "grow", "sizingY": "grow" + }, + "SHA1": { + "type": "radio", + "text": "SHA1", + "top": 432, + "left": 259, + "width": 80, + "height": 25, + "events": [ + "onClick" + ], + "dataSourceTypeHint": "boolean", + "dataSource": "Form:C1466.SHA1", + "radioGroup": "SHA", + "focusable": false + }, + "SHA2": { + "type": "radio", + "text": "SHA256", + "top": 432, + "left": 346, + "width": 80, + "height": 25, + "events": [ + "onClick" + ], + "dataSourceTypeHint": "boolean", + "dataSource": "Form:C1466.SHA256", + "radioGroup": "SHA", + "focusable": false + }, + "SHA5": { + "type": "radio", + "text": "SHA512", + "top": 432, + "left": 520, + "width": 80, + "height": 25, + "events": [ + "onClick" + ], + "dataSourceTypeHint": "boolean", + "dataSource": "Form:C1466.SHA512", + "radioGroup": "SHA", + "focusable": false + }, + "SHA3": { + "type": "radio", + "text": "SHA384", + "top": 432, + "left": 433, + "width": 80, + "height": 25, + "events": [ + "onClick" + ], + "dataSourceTypeHint": "boolean", + "dataSource": "Form:C1466.SHA384", + "radioGroup": "SHA", + "focusable": false } } }, @@ -512,7 +527,7 @@ } ], "method": "method.4dm", - "geometryStamp": 1611, + "geometryStamp": 1615, "editor": { "activeView": "View 1", "defaultView": "View 1", diff --git a/hpki/Project/Sources/Forms/jpki/form.4DForm b/hpki/Project/Sources/Forms/jpki/form.4DForm index 748ef40..e2e6a46 100644 --- a/hpki/Project/Sources/Forms/jpki/form.4DForm +++ b/hpki/Project/Sources/Forms/jpki/form.4DForm @@ -522,8 +522,8 @@ "type": "radio", "text": "SHA1", "top": 432, - "left": 329, - "width": 71, + "left": 259, + "width": 80, "height": 25, "events": [ "onClick" @@ -537,8 +537,8 @@ "type": "radio", "text": "SHA256", "top": 432, - "left": 409, - "width": 91, + "left": 346, + "width": 80, "height": 25, "events": [ "onClick" @@ -552,8 +552,8 @@ "type": "radio", "text": "SHA512", "top": 432, - "left": 509, - "width": 91, + "left": 520, + "width": 80, "height": 25, "events": [ "onClick" @@ -590,6 +590,21 @@ "enterable": false, "sizingX": "grow", "sizingY": "grow" + }, + "SHA3": { + "type": "radio", + "text": "SHA384", + "top": 432, + "left": 433, + "width": 80, + "height": 25, + "events": [ + "onClick" + ], + "dataSourceTypeHint": "boolean", + "dataSource": "Form:C1466.SHA384", + "radioGroup": "SHA", + "focusable": false } } }, @@ -647,7 +662,7 @@ } ], "method": "method.4dm", - "geometryStamp": 1678, + "geometryStamp": 1739, "editor": { "activeView": "View 1", "defaultView": "View 1", diff --git a/hpki/Resources/bin/macOS/hpki b/hpki/Resources/bin/macOS/hpki index b3a72ae..0b8918d 100755 Binary files a/hpki/Resources/bin/macOS/hpki and b/hpki/Resources/bin/macOS/hpki differ diff --git a/include/My-Number-Card_macOS.cpp b/include/My-Number-Card_macOS.cpp index 7e86a8f..7e9fe9c 100644 --- a/include/My-Number-Card_macOS.cpp +++ b/include/My-Number-Card_macOS.cpp @@ -199,42 +199,53 @@ static void _apdu_compute_digital_signature_hpki(dispatch_semaphore_t sem, TKSmartCard *smartCard, Json::Value& threadCtx) { - hash_algorithm algorithm = (hash_algorithm)threadCtx["algorithm"].asInt(); - size_t APDU_size; - switch (algorithm) { - case hash_algorithm_sha512: - APDU_size = sizeof(APDU_COMPUTE_DIGITAL_SIGNATURE_KEY_JPKI); - break; - case hash_algorithm_sha384: - APDU_size = sizeof(APDU_COMPUTE_DIGITAL_SIGNATURE_KEY_JPKI) - 0x10; - break; - case hash_algorithm_sha1: - APDU_size = sizeof(APDU_COMPUTE_DIGITAL_SIGNATURE_KEY_JPKI) - 0x30; - break; - default: - APDU_size = sizeof(APDU_COMPUTE_DIGITAL_SIGNATURE_KEY_JPKI) - 0x20; - break; - } + size_t key_length_bits = 2048; + size_t key_length = key_length_bits / 8; + std::vectorpkcs(key_length); - std::vectordata(sizeof(APDU_COMPUTE_DIGITAL_SIGNATURE_KEY_JPKI)); - memcpy(&data[0], - APDU_COMPUTE_DIGITAL_SIGNATURE_KEY_JPKI, - sizeof(APDU_COMPUTE_DIGITAL_SIGNATURE_KEY_JPKI)); + + + //key length=2048; signature length=256 + + pkcs[0] = 0x00; + pkcs[1] = 0x01; + + //padding string + memset(&pkcs[2], + 0xFF, + pkcs.size() - 2); + std::string digestInfo = threadCtx["digestInfo"].asString(); std::vectorbuf(0); hex_to_bytes(digestInfo, buf); - data[0] = 0x00;//0x80 - data[1] = 0x2A;//0x2A - data[2] = 0x9E;//0x9E - data[3] = 0x9A;//0x9A - data[4] = buf.size(); + size_t p = pkcs.size() - buf.size(); + memcpy(&pkcs[p], &buf[0], buf.size()); + pkcs[p - 1] = 0x00; - memcpy(&data[5], &buf[0], buf.size()); + std::vectordata(7 + pkcs.size()+ 2); + + data[0] = 0x00; + data[1] = 0x2A; + data[2] = 0x9E; + data[3] = 0x9A; + + data[4] = 0x00; + data[5] = key_length >> 8; + data[6] = key_length & 0x00FF; + + memcpy(&data[7], &pkcs[0], pkcs.size()); + + data[data.size()-2] = 0x00; + data[data.size()-1] = 0x00; + + std::string apdu; + bytes_to_hex(&data[0], data.size(), apdu); + threadCtx["apdu_pkcs"] = apdu; [smartCard transmitRequest:[NSData dataWithBytes:&data[0] - length:APDU_size] + length:data.size()] reply:^(NSData *response, NSError *error) { if ((error == nil) && (_is_response_positive(response, threadCtx))) { size_t signature_length = [response length] -2; @@ -715,6 +726,22 @@ static void _read_block_cert_jpki(dispatch_semaphore_t sem, ASN1_TIME *notBefore = X509_get_notBefore(x509); ASN1_TIME *notAfter = X509_get_notAfter(x509); + EVP_PKEY *pubkey = X509_get0_pubkey(x509); + if(pubkey) { + const RSA *rsa = EVP_PKEY_get0_RSA(pubkey); + if(rsa) { + BIGNUM *modulus = NULL; + BIGNUM *public_exponent = NULL; + RSA_get0_key(rsa, + (const BIGNUM **)&modulus, + (const BIGNUM **)&public_exponent, + NULL); + if (modulus != NULL) { + certificate["length"] = BN_num_bits(modulus); + } + } + } + std::string textValue; asn_time_to_iso(notBefore, textValue); certificate["notBefore"] = textValue; diff --git a/macOS/hpki.xcodeproj/project.xcworkspace/xcuserdata/miyako.xcuserdatad/UserInterfaceState.xcuserstate b/macOS/hpki.xcodeproj/project.xcworkspace/xcuserdata/miyako.xcuserdatad/UserInterfaceState.xcuserstate index 4251485..45c5a4b 100644 Binary files a/macOS/hpki.xcodeproj/project.xcworkspace/xcuserdata/miyako.xcuserdatad/UserInterfaceState.xcuserstate and b/macOS/hpki.xcodeproj/project.xcworkspace/xcuserdata/miyako.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/macOS/hpki.xcodeproj/xcuserdata/miyako.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/macOS/hpki.xcodeproj/xcuserdata/miyako.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index b9e6736..eb35352 100644 --- a/macOS/hpki.xcodeproj/xcuserdata/miyako.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/macOS/hpki.xcodeproj/xcuserdata/miyako.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,4 +3,38 @@ uuid = "FE0331A1-10C6-484E-8433-F305536C871E" type = "1" version = "2.0"> + + + + + + + + + + diff --git a/macOS/hpki/hpki.m b/macOS/hpki/hpki.m index 133a317..5292cba 100644 --- a/macOS/hpki/hpki.m +++ b/macOS/hpki/hpki.m @@ -247,6 +247,7 @@ int hpki(int argc, char *argv[]) { bytes_to_hex(&digestInfo[0], digestInfo.size(), hex); + threadCtx["hi"] = "hi"; threadCtx["digestInfo"] = hex; threadCtx["algorithm"] = algorithm; }