Ejemplo n.º 1
0
/*
 * Create a new DF
 * This will usually be the application DF
 */
static int
gpk_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *df)
{
	struct sc_file	*pinfile;
	int		r, locked;

	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
	if (sc_card_ctl(p15card->card, SC_CARDCTL_GPK_IS_LOCKED, &locked) == 0
			&& locked) {
		sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL,
			"This card is already personalized, unable to "
			"create PKCS#15 structure.");
		return SC_ERROR_NOT_SUPPORTED;
	}

	/* Create the DF. */
	r = sc_pkcs15init_create_file(profile, p15card, df);
	if (r < 0)
		return r;

	/* See if there's a file called "pinfile" that resides within
	 * this DF. If so, create it */
	if (sc_profile_get_file(profile, "pinfile", &pinfile) >= 0) {
		/* Build the pin file's path from the DF path + its
		 * file ID */
		pinfile->path = df->path;
		sc_append_file_id(&pinfile->path, pinfile->id);

		r = gpk_init_pinfile(profile, p15card, pinfile);
		sc_file_free(pinfile);
		if (r < 0)
			return r;

		/* TODO: What for it was used ?
		for (i = 0; i < GPK_MAX_PINS; i++)
		*	sc_keycache_put_pin(&df->path, GPK_PIN_SCOPE|i, (const u8 *) "        ");
		*/
	}

	SC_FUNC_RETURN(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r);
}
Ejemplo n.º 2
0
/*
 * Create a new DF
 * This will usually be the application DF
 */
static int
gpk_create_dir(sc_profile_t *profile, sc_card_t *card, sc_file_t *df)
{
    struct sc_file	*pinfile;
    int		r, locked, i;

    if (sc_card_ctl(card, SC_CARDCTL_GPK_IS_LOCKED, &locked) == 0
            && locked) {
        sc_error(card->ctx,
                 "This card is already personalized, unable to "
                 "create PKCS#15 structure.");
        return SC_ERROR_NOT_SUPPORTED;
    }

    /* Create the DF. */
    r = sc_pkcs15init_create_file(profile, card, df);
    if (r < 0)
        return r;

    /* See if there's a file called "pinfile" that resides within
     * this DF. If so, create it */
    if (sc_profile_get_file(profile, "pinfile", &pinfile) >= 0) {
        /* Build the pin file's path from the DF path + its
         * file ID */
        pinfile->path = df->path;
        sc_append_file_id(&pinfile->path, pinfile->id);

        r = gpk_init_pinfile(profile, card, pinfile);
        sc_file_free(pinfile);
        if (r < 0)
            return r;

        for (i = 0; i < GPK_MAX_PINS; i++)
            sc_keycache_put_pin(&df->path, GPK_PIN_SCOPE|i, (const u8 *) "        ");
    }

    return r;
}