int main(int argc, char **argv) { const char *fname; FILE *f; struct emu_fs *fs; if (argc > 2) return 1; if (argc == 1) { fname = openemv_config_get("scard.emu.file"); f = fopen(fname, "r"); } else if (!strcmp(argv[1], "-")) { fname = "<stdin>"; f = stdin; } else { fname = argv[1]; f = fopen(fname, "r"); } if (!f) { perror("fopen"); return 1; } fs = emu_fs_parse(f, fname); if (!fs) return 1; fclose(f); const struct emu_df *df = emu_fs_get_df(fs, NULL, 0); if (!df) return 1; const struct emu_property *prop = emu_df_get_property(df, "name"); if (!prop) return 1; const struct emu_value *value = emu_property_get_value(prop); if (!value) return 1; size_t buf_len; const unsigned char *buf = emu_value_get(value, 1, &buf_len); if (!buf) return 1; dump_buffer(buf, buf_len, stdout); buf = emu_df_get_value(df, "name", 1, &buf_len); if (!buf) return 1; dump_buffer(buf, buf_len, stdout); emu_fs_free(fs); return 0; }
int main(int argc, char **argv) { FILE *f; const char *fname; int rc = 0; fname = openemv_config_get("capk"); f = fopen(fname, "r"); if (!f) { perror("fopen"); return 1; } while (!feof(f)) { char buf[BUFSIZ]; if (fgets(buf, sizeof(buf), f) == NULL) break; struct emv_pk *pk = emv_pk_parse_pk(buf); if (!pk) continue; fprintf(stderr, "Verifying CA PK for %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx %zd bits...", pk->rid[0], pk->rid[1], pk->rid[2], pk->rid[3], pk->rid[4], pk->index, pk->mlen * 8); if (emv_pk_verify(pk)) { fprintf(stderr, "OK\n"); if (argc > 2 && argv[2][0] == 'v') { unsigned char *c; c = emv_pk_dump_pk(pk); if (c) printf("%s\n", c); free(c); } } else { fprintf(stderr, "Failed!\n"); rc = 1; } emv_pk_free(pk); } fclose(f); return rc; }
struct sc *scard_init(const char *driver) { if (!driver) driver = openemv_config_get("scard.driver"); if (!driver) return NULL; else if (!strcmp(driver, "pcsc")) return scard_pcsc_init(); else if (!strcmp(driver, "emu")) return scard_emu_init(); else if (!strcmp(driver, "apduio_t0")) return scard_apduio_t0_init(); else if (!strcmp(driver, "apduio_t1")) return scard_apduio_t1_init(); else return NULL; }