/* Copyright (C) 2001 Juha Yrjölä * All rights reserved. * * PKCS#15 objects test */ #include #include #include #include #include "sc-test.h" struct sc_pkcs15_card *p15card; static int dump_objects(const char *what, int type) { struct sc_pkcs15_object **objs; int count, i; printf("\nEnumerating %s... ", what); fflush(stdout); sc_lock(card); count = sc_pkcs15_get_objects(p15card, type, NULL, 0); if (count < 0) { printf("failed.\n"); fprintf(stderr, "Error enumerating %s: %s\n", what, sc_strerror(count)); sc_unlock(card); return 1; } if (count == 0) { printf("none found.\n"); sc_unlock(card); return 0; } printf("%u found.\n", count); objs = calloc(count, sizeof(*objs)); if ((count = sc_pkcs15_get_objects(p15card, type, objs, count)) < 0) { fprintf(stderr, "Error enumerating %s: %s\n", what, sc_strerror(count)); } else { for (i = 0; i < count; i++) sc_test_print_object(objs[i]); } free(objs); sc_unlock(card); return (count < 0) ? 1 : 0; } int main(int argc, char *argv[]) { int i; i = sc_test_init(&argc, argv); if (i < 0) return 1; printf("Looking for a PKCS#15 compatible Smart Card... "); fflush(stdout); sc_lock(card); i = sc_pkcs15_bind(card, &p15card); sc_unlock(card); if (i) { fprintf(stderr, "failed: %s\n", sc_strerror(i)); return 1; } printf("found.\n"); sc_pkcs15_print_card(p15card); dump_objects("PIN codes", SC_PKCS15_TYPE_AUTH_PIN); dump_objects("RSA private keys", SC_PKCS15_TYPE_PRKEY_RSA); dump_objects("RSA public keys", SC_PKCS15_TYPE_PUBKEY_RSA); dump_objects("X.509 certificates", SC_PKCS15_TYPE_CERT_X509); sc_pkcs15_unbind(p15card); sc_test_cleanup(); return 0; }