Commit c88e8798 by kevin

solve verify fail bug

1 parent d0078d4d
......@@ -42,7 +42,7 @@ void CZ_LK_CHECKIT()
else
{//verify failed
char buf[100];
sprintf(buf, "Using unauthorized chip, please chekc with technicians.\n");
sprintf(buf, "Using unauthorized chip, please check with technicians.\n");
std::string msg(buf);
std::cout << msg.c_str() << std::endl;
......
......@@ -450,15 +450,17 @@ void LK_SEETA_VERIFY::get_chip_id(unsigned char chip_id[], int &lenRcv)
void LK_SEETA_VERIFY::write_chip_id_limit_num_to_nvm()
{
uint8_t DES_ENCRYPT_DECRYPT_KEY[128];
memcpy(DES_ENCRYPT_DECRYPT_KEY, "\x01\x09\x09\01\x00\x07\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00", 0x10);
memcpy(DES_ENCRYPT_DECRYPT_KEY, "\x01\x09\x09\01\x00\x07\x01\x01\x01\x02\x03\x04\x05\x06\x07\x08", 0x10);
unsigned char chip_id[300];
int len;
get_chip_id(chip_id, len);
//printf("chip id from hardward:\n");
//for (int i = 0; i < len; ++i)
//{
// printf("%d:%x ", i, chip_id[i]);
//}
//printf("\n");
unsigned char cmd_write_chip[300];
unsigned char chip_id_and_limit_num[300];//mingwen
......@@ -473,17 +475,24 @@ void LK_SEETA_VERIFY::write_chip_id_limit_num_to_nvm()
memcpy(chip_id_and_limit_num + 1, chip_id, 8);
memcpy(chip_id_and_limit_num + 9, "\x05\x00\x00\x01\x00\x00\x00\x00", 8);// limit==10000
printf("write into:\n");
for (int i = 0; i < 17; ++i)
{
printf("%d:%x ", i, chip_id_and_limit_num[i]);
}
//printf("write into:\n");
//for (int i = 0; i < 17; ++i)
//{
// printf("%d:%x ", i, chip_id_and_limit_num[i]);
//}
encrypt_3des(chip_id_and_limit_num, DES_ENCRYPT_DECRYPT_KEY);
memcpy(chip_id_and_limit_num_des, chip_id_and_limit_num + 17, 16);
memcpy(chip_id_and_limit_num_des, chip_id_and_limit_num + 1, 16);
memcpy(cmd_write_chip + 6, chip_id_and_limit_num_des, 16);
//printf("write command:\n");
//for (int i = 0; i <22; ++i)
//{
// printf("%d:%x ", i, cmd_write_chip[i]);
//}
//printf("\n");
unsigned char rec[300];
int rec_len;
int res = SendAPDU(22, cmd_write_chip, &rec_len, rec);//write to nvm
......@@ -508,7 +517,7 @@ void LK_SEETA_VERIFY::write_chip_id_limit_num_to_nvm()
void LK_SEETA_VERIFY::read_chip_id_limit_num_from_nvm(unsigned char chip_id_from_nvm[], int &lenRcv)
{
uint8_t DES_ENCRYPT_DECRYPT_KEY[128];
memcpy(DES_ENCRYPT_DECRYPT_KEY, "\x01\x09\x09\01\x00\x07\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00", 0x10);
memcpy(DES_ENCRYPT_DECRYPT_KEY, "\x01\x09\x09\01\x00\x07\x01\x01\x01\x02\x03\x04\x05\x06\x07\x08", 0x10);
unsigned char cmd_read_chip_id[300];
unsigned char rec[300];
......@@ -518,7 +527,7 @@ void LK_SEETA_VERIFY::read_chip_id_limit_num_from_nvm(unsigned char chip_id_from
memset(cmd_read_chip_id, 0, 300);
memcpy(cmd_read_chip_id, "\x80\x08\x00\x00\x01\x05", 6);
int res = SendAPDU(14, cmd_read_chip_id, &rec_len, rec);//read from nvm
int res = SendAPDU(6, cmd_read_chip_id, &rec_len, rec);//read from nvm
memset(in_out_data, 0 ,300);
memcpy(in_out_data, "\x10", 1);
......@@ -526,11 +535,11 @@ void LK_SEETA_VERIFY::read_chip_id_limit_num_from_nvm(unsigned char chip_id_from
decrypt_3des(in_out_data, DES_ENCRYPT_DECRYPT_KEY);
printf("read from:\n");
for (int i = 0; i < 17; ++i)
{
printf("%d:%x ", i, in_out_data[i]);
}
//printf("read from:\n");
//for (int i = 0; i < 17; ++i)
//{
// printf("%d:%x ", i, in_out_data[i]);
//}
if (0 != res)
{
char buf[100];
......@@ -541,13 +550,16 @@ void LK_SEETA_VERIFY::read_chip_id_limit_num_from_nvm(unsigned char chip_id_from
throw msg.c_str();
}
//for (int i = 0; i < rec_len; ++i)
//printf("read result:\n");
//for (int i = 0; i < 16; ++i)
//{
// printf("%d:%x ", i, rec[i]);
//}
//printf("\n");
lenRcv = 8;
memmove(chip_id_from_nvm, in_out_data + 17, 8);
memmove(chip_id_from_nvm, in_out_data + 1, 8);
return;
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!