static int sda_test_pk(void) { const struct emv_pk *pk = &vsdc_01; struct tlvdb *db; db = tlvdb_external(0x90, sizeof(issuer_cert), issuer_cert); tlvdb_add(db, tlvdb_external(0x9f32, sizeof(issuer_exp), issuer_exp)); tlvdb_add(db, tlvdb_external(0x92, sizeof(issuer_rem), issuer_rem)); struct emv_pk *ipk = emv_pki_recover_issuer_cert(pk, db); if (!ipk) { fprintf(stderr, "Could not recover Issuer certificate!\n"); tlvdb_free(db); return 2; } tlvdb_add(db, tlvdb_external(0x93, sizeof(ssad_cr), ssad_cr)); struct tlvdb *dacdb = emv_pki_recover_dac(ipk, db, ssd1, sizeof(ssd1)); if (!dacdb) { fprintf(stderr, "Could not recover DAC!\n"); emv_pk_free(ipk); tlvdb_free(db); return 2; } const struct tlv *dac = tlvdb_get(dacdb, 0x9f45, NULL); if (!dac) { fprintf(stderr, "DAC not found!\n"); tlvdb_free(dacdb); emv_pk_free(ipk); tlvdb_free(db); return 2; } dump_buffer(dac->value, dac->len, stdout); tlvdb_free(dacdb); emv_pk_free(ipk); tlvdb_free(db); return 0; }
static int cda_test_pk(void) { const struct emv_pk *pk = &mchip_05; struct tlvdb *db; db = tlvdb_external(0x90, sizeof(issuer_cert), issuer_cert); tlvdb_add(db, tlvdb_external(0x9f32, sizeof(issuer_exp), issuer_exp)); tlvdb_add(db, tlvdb_external(0x92, sizeof(issuer_rem), issuer_rem)); tlvdb_add(db, tlvdb_external(0x5a, sizeof(pan), pan)); struct emv_pk *ipk = emv_pki_recover_issuer_cert(pk, db); if (!ipk) { fprintf(stderr, "Could not recover Issuer certificate!\n"); tlvdb_free(db); return 2; } tlvdb_add(db, tlvdb_external(0x9f46, sizeof(icc_cert), icc_cert)); tlvdb_add(db, tlvdb_external(0x9f47, sizeof(icc_exp), icc_exp)); /*tlvdb_add(db, tlvdb_external(0x9f48, sizeof(issuer_rem), issuer_rem));*/ struct emv_pk *iccpk = emv_pki_recover_icc_cert(ipk, db, &ssd1_tlv); if (!iccpk) { fprintf(stderr, "Could not recover ICC certificate!\n"); emv_pk_free(ipk); tlvdb_free(db); return 2; } tlvdb_add(db, tlvdb_fixed(0x9f37, sizeof(dd1), dd1)); struct tlvdb *cda_db; cda_db = tlvdb_fixed(0x9f27, 1, (unsigned char[]){ 0x40 });
/*tlvdb_add(db, tlvdb_external(0x9f48, sizeof(issuer_rem), issuer_rem));*/ struct emv_pk *iccpk = emv_pki_recover_icc_cert(ipk, db, &ssd1_tlv); if (!iccpk) { fprintf(stderr, "Could not recover ICC certificate!\n"); emv_pk_free(ipk); tlvdb_free(db); return 2; } tlvdb_add(db, tlvdb_fixed(0x9f37, sizeof(dd1), dd1)); struct tlvdb *cda_db; cda_db = tlvdb_fixed(0x9f27, 1, (unsigned char[]){ 0x40 }); tlvdb_add(cda_db, tlvdb_fixed(0x9f36, 2, (unsigned char[]) { 0x00, 0x10 })); tlvdb_add(cda_db, tlvdb_external(0x9f4b, sizeof(sdad_cr), sdad_cr)); tlvdb_add(cda_db, tlvdb_fixed(0x9f10, 0x12, (unsigned char[]) { 0x00, 0x10, 0x90, 0x40, 0x01, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff})); struct tlvdb *idndb = emv_pki_perform_cda(iccpk, db, cda_db, NULL, &crm1_tlv, NULL); if (!idndb) { fprintf(stderr, "Could not recover IDN!\n"); tlvdb_free(cda_db); emv_pk_free(iccpk); emv_pk_free(ipk); tlvdb_free(db); return 2; }