Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
miyako committed Dec 10, 2024
1 parent 1debbb8 commit f7aa466
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 49 deletions.
47 changes: 20 additions & 27 deletions include/My-Number-Card_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,20 +882,22 @@ static void _apdu_compute_digital_signature_jpki(SCARDHANDLE hCard, const SCARD_

if (lResult == SCARD_S_SUCCESS) {

size_t signature_length = cbRecvLength - 2;
std::vector<uint8_t>buf(signature_length);

memcpy(&buf[0], &pbRecvBuffer[0], signature_length);

std::string hex;
bytes_to_hex(&buf[0], signature_length, hex);
threadCtx["signature"] = hex;
std::string b64;
bytes_to_b64(&buf[0], signature_length, b64);
threadCtx["signature_base64"] = b64;
threadCtx["success"] = true;
BYTE SW1 = pbRecvBuffer[cbRecvLength - 2];
BYTE SW2 = pbRecvBuffer[cbRecvLength - 1];

if (_is_response_positive(SW1, SW2, threadCtx)) {
size_t signature_length = cbRecvLength - 2;
std::vector<uint8_t>buf(signature_length);
memcpy(&buf[0], &pbRecvBuffer[0], signature_length);
std::string hex;
bytes_to_hex(&buf[0], signature_length, hex);
threadCtx["signature"] = hex;
std::string b64;
bytes_to_b64(&buf[0], signature_length, b64);
threadCtx["signature_base64"] = b64;
threadCtx["success"] = true;
}
}

}

static void _apdu_select_jpki_key_identity(SCARDHANDLE hCard, const SCARD_IO_REQUEST* pioSendPci, Json::Value& threadCtx) {
Expand Down Expand Up @@ -1021,10 +1023,12 @@ static void _apdu_compute_digital_signature_hpki(SCARDHANDLE hCard, const SCARD_
&cbRecvLength);

if (lResult == SCARD_S_SUCCESS) {

size_t signature_length = cbRecvLength - 2;

if (signature_length > 0) {
BYTE SW1 = pbRecvBuffer[cbRecvLength - 2];
BYTE SW2 = pbRecvBuffer[cbRecvLength - 1];

if (_is_response_positive(SW1, SW2, threadCtx)) {
size_t signature_length = cbRecvLength - 2;
std::vector<uint8_t>buf(signature_length);
memcpy(&buf[0], &pbRecvBuffer[0], signature_length);
std::string hex;
Expand All @@ -1035,17 +1039,6 @@ static void _apdu_compute_digital_signature_hpki(SCARDHANDLE hCard, const SCARD_
threadCtx["signature_base64"] = b64;
threadCtx["success"] = true;
}
else {
uint8_t SW1 = pbRecvBuffer[0];
uint8_t SW2 = pbRecvBuffer[1];
std::string hi, lo;

bytes_to_hex(&SW1, sizeof(uint8_t), hi);
bytes_to_hex(&SW2, sizeof(uint8_t), lo);

threadCtx["response"] = hi + lo;

}
}
}

Expand Down
35 changes: 13 additions & 22 deletions windows/hpki/hpki.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ return 0;
int inputIsStream = true;
int outputIsStream = true;
hash_algorithm algorithm = hash_algorithm_sha256;
int cardType = pki_type_unknown;

while ((opt = getopt_long(argc, argv, OPT_LIST, longopts, &longoptind)) != -1)
{
switch (opt)
Expand Down Expand Up @@ -122,15 +122,6 @@ return 0;
signWithCertificateIdentity = true;
}
break;
case 't':
type = (optarg);
if (type == "hpki") {
cardType = pki_type_h;
}
if (type == "jpki") {
cardType = pki_type_j;
}
break;
case 'r':
slot = (optarg);
break;
Expand Down Expand Up @@ -298,19 +289,19 @@ return 0;
threadCtx.removeMember("data");
threadCtx.removeMember("certificateType");

if (threadCtx["historicalBytes"].isString()) {
std::string historicalBytes = threadCtx["historicalBytes"].asString();
if (historicalBytes == ID_HPKI) {
threadCtx["cardType"] = NAME_HPKI;
}
if (historicalBytes == ID_JPKI) {
threadCtx["cardType"] = NAME_JPKI;
}
if (historicalBytes == ID_JGID) {
threadCtx["cardType"] = NAME_JPKI;
}
threadCtx.removeMember("historicalBytes");
if (threadCtx["historicalBytes"].isString()) {
std::string historicalBytes = threadCtx["historicalBytes"].asString();
if (historicalBytes == ID_HPKI) {
threadCtx["cardType"] = NAME_HPKI;
}
if (historicalBytes == ID_JPKI) {
threadCtx["cardType"] = NAME_JPKI;
}
if (historicalBytes == ID_JGID) {
threadCtx["cardType"] = NAME_JPKI;
}
threadCtx.removeMember("historicalBytes");
}

StreamWriterBuilder builder;
builder["commentStyle"] = "None";
Expand Down

0 comments on commit f7aa466

Please sign in to comment.