Example #1
0
struct emv_pk *emv_pk_get_ca_pk(const unsigned char *rid, unsigned char idx)
{
	struct emv_pk *pk = NULL;

	if (!pk) {
		char *fname = emv_pk_get_ca_pk_file(NULL, rid, idx);
		if (fname) {
			pk = emv_pk_get_ca_pk_from_file(fname, rid, idx);
			free(fname);
		}
	}

	if (!pk) {
		char *fname = emv_pk_get_ca_pk_rid_file(NULL, rid);
		if (fname) {
			pk = emv_pk_get_ca_pk_from_file(fname, rid, idx);
			free(fname);
		}
	}

	if (!pk) {
		const char *fname = openemv_config_get_str("capk.file", NULL);
		if (!fname) {
			fprintf(stderr, "No CA PK file specified!\n");
			return NULL;
		}

		pk = emv_pk_get_ca_pk_from_file(fname, rid, idx);
	}
	if (!pk)
		return NULL;

	printf("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)) {
		printf("OK\n");

		return pk;
	}

	printf("Failed!\n");
	emv_pk_free(pk);

	return NULL;
}
Example #2
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;
}