Пример #1
0
/*
 * Add a unrelated certificate object and description in PKCS#15 format to the framework
 */
static int sc_pkcs15emu_sc_hsm_add_cd(sc_pkcs15_card_t * p15card, u8 id) {

	sc_card_t *card = p15card->card;
	sc_pkcs15_cert_info_t *cert_info;
	sc_pkcs15_object_t obj;
	u8 fid[2];
	u8 efbin[512];
	const u8 *ptr;
	size_t len;
	int r;

	fid[0] = CD_PREFIX;
	fid[1] = id;

	/* Try to select a related EF containing the PKCS#15 description of the data */
	len = sizeof efbin;
	r = read_file(p15card, fid, efbin, &len);
	LOG_TEST_RET(card->ctx, r, "Could not read EF.DCOD");

	ptr = efbin;

	memset(&obj, 0, sizeof(obj));
	r = sc_pkcs15_decode_cdf_entry(p15card, &obj, &ptr, &len);
	LOG_TEST_RET(card->ctx, r, "Could not decode EF.CD");

	cert_info = (sc_pkcs15_cert_info_t *)obj.data;

	r = sc_pkcs15emu_add_x509_cert(p15card, &obj, cert_info);

	LOG_TEST_RET(card->ctx, r, "Could not add data object to framework");

	return SC_SUCCESS;
}
/*
 * Add a unrelated certificate object and description in PKCS#15 format to the framework
 */
static int sc_pkcs15emu_sc_hsm_add_cd(sc_pkcs15_card_t * p15card, u8 id) {

    sc_card_t *card = p15card->card;
    sc_pkcs15_cert_info_t *cert_info;
    sc_pkcs15_object_t obj;
    sc_file_t *file = NULL;
    sc_path_t path;
    u8 fid[2];
    u8 efbin[512];
    const u8 *ptr;
    size_t len;
    int r;

    fid[0] = CD_PREFIX;
    fid[1] = id;

    /* Try to select a related EF containing the PKCS#15 description of the data */
    sc_path_set(&path, SC_PATH_TYPE_FILE_ID, fid, sizeof(fid), 0, 0);
    r = sc_select_file(card, &path, &file);

    if (r != SC_SUCCESS) {
        return SC_SUCCESS;
    }

    sc_file_free(file);
    r = sc_read_binary(p15card->card, 0, efbin, sizeof(efbin), 0);
    LOG_TEST_RET(card->ctx, r, "Could not read EF.DCOD");

    memset(&obj, 0, sizeof(obj));
    ptr = efbin;
    len = r;

    r = sc_pkcs15_decode_cdf_entry(p15card, &obj, &ptr, &len);
    LOG_TEST_RET(card->ctx, r, "Could not decode EF.CD");

    cert_info = (sc_pkcs15_cert_info_t *)obj.data;

    r = sc_pkcs15emu_add_x509_cert(p15card, &obj, cert_info);

    LOG_TEST_RET(card->ctx, r, "Could not add data object to framework");

    return SC_SUCCESS;
}