- Some build/portability fixes for the pkcs15init rewrite

- Add sc_pkcs15_get_<drv>_ops(), yet untested


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1512 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
aet 2003-10-13 20:41:00 +00:00
parent 1bdcd2184c
commit 936ad78b02
7 changed files with 88 additions and 70 deletions

View File

@ -30,12 +30,9 @@
#endif
#include <assert.h>
#include <opensc/pkcs15.h>
#include <opensc/cardctl.h>
#include "profile.h"
#include "pkcs15-init.h"
#include <opensc/cardctl.h>
#ifdef _WIN32
#include <windows.h>
#endif
#undef KEYCACHE_DEBUG
#define MAX_SECRET 32 /* sufficient for 128bit symmetric keys */

View File

@ -707,11 +707,11 @@ cflex_encode_private_key(struct sc_pkcs15_prkey_rsa *rsa,
*key++ = (5 * base + 3) & 0xFF;
*key++ = key_num;
if ((r < bn2cf(&rsa->p, key + 0 * base, base)) < 0
|| (r < bn2cf(&rsa->q, key + 1 * base, base)) < 0
|| (r < bn2cf(&rsa->iqmp, key + 2 * base, base)) < 0
|| (r < bn2cf(&rsa->dmp1, key + 3 * base, base)) < 0
|| (r < bn2cf(&rsa->dmq1, key + 4 * base, base)) < 0)
if ((r = bn2cf(&rsa->p, key + 0 * base, base)) < 0
|| (r = bn2cf(&rsa->q, key + 1 * base, base)) < 0
|| (r = bn2cf(&rsa->iqmp, key + 2 * base, base)) < 0
|| (r = bn2cf(&rsa->dmp1, key + 3 * base, base)) < 0
|| (r = bn2cf(&rsa->dmq1, key + 4 * base, base)) < 0)
return r;
key += 5 * base;
@ -765,14 +765,18 @@ cflex_encode_public_key(struct sc_pkcs15_prkey_rsa *rsa,
return 0;
}
struct sc_pkcs15init_operations sc_pkcs15init_cflex_operations = {
.erase_card = cflex_erase_card,
.create_dir = cflex_create_dir,
.create_domain = cflex_create_domain,
.select_pin_reference = cflex_select_pin_reference,
.create_pin = cflex_create_pin,
.create_key = cflex_create_key,
.generate_key = cflex_generate_key,
.store_key = cflex_store_key,
static struct sc_pkcs15init_operations sc_pkcs15init_cflex_operations;
};
struct sc_pkcs15init_operations *sc_pkcs15init_get_cflex_ops(void)
{
sc_pkcs15init_cflex_operations.erase_card = cflex_erase_card;
sc_pkcs15init_cflex_operations.create_dir = cflex_create_dir;
sc_pkcs15init_cflex_operations.create_domain = cflex_create_domain;
sc_pkcs15init_cflex_operations.select_pin_reference = cflex_select_pin_reference;
sc_pkcs15init_cflex_operations.create_pin = cflex_create_pin;
sc_pkcs15init_cflex_operations.create_key = cflex_create_key;
sc_pkcs15init_cflex_operations.generate_key = cflex_generate_key;
sc_pkcs15init_cflex_operations.store_key = cflex_store_key;
return &sc_pkcs15init_cflex_operations;
}

View File

@ -59,9 +59,6 @@ static int etoken_store_pin(sc_profile_t *profile, sc_card_t *card,
const u8 *pin, size_t pin_len);
static int etoken_create_sec_env(sc_profile_t *, sc_card_t *,
unsigned int, unsigned int);
static int etoken_new_file(struct sc_profile *, struct sc_card *,
unsigned int, unsigned int,
struct sc_file **);
static int etoken_put_key(struct sc_profile *, struct sc_card *,
int, unsigned int, struct sc_pkcs15_prkey_rsa *);
static int etoken_key_algorithm(unsigned int, int *);
@ -660,6 +657,7 @@ etoken_put_key(struct sc_profile *profile, struct sc_card *card,
return r;
}
#if 0
/*
* Allocate a file
*/
@ -737,6 +735,7 @@ etoken_new_file(struct sc_profile *profile, struct sc_card *card,
*out = file;
return 0;
}
#endif
/*
* Extract a key component from the public key file populated by
@ -775,16 +774,18 @@ error(struct sc_profile *profile, const char *fmt, ...)
profile->cbs->error("%s", buffer);
}
struct sc_pkcs15init_operations sc_pkcs15init_etoken_operations = {
.erase_card = etoken_erase,
.create_dir = etoken_create_dir,
.select_pin_reference = etoken_select_pin_reference,
.create_pin = etoken_create_pin,
.select_key_reference = etoken_select_key_reference,
.create_key = etoken_create_key,
.store_key = etoken_store_key,
//.new_pin = etoken_new_pin,
//.new_key = etoken_new_key,
.generate_key = etoken_generate_key
//.new_file = etoken_new_file,
};
static struct sc_pkcs15init_operations sc_pkcs15init_etoken_operations;
struct sc_pkcs15init_operations *sc_pkcs15init_get_etoken_ops(void)
{
sc_pkcs15init_etoken_operations.erase_card = etoken_erase;
sc_pkcs15init_etoken_operations.create_dir = etoken_create_dir;
sc_pkcs15init_etoken_operations.select_pin_reference = etoken_select_pin_reference;
sc_pkcs15init_etoken_operations.create_pin = etoken_create_pin;
sc_pkcs15init_etoken_operations.select_key_reference = etoken_select_key_reference;
sc_pkcs15init_etoken_operations.create_key = etoken_create_key;
sc_pkcs15init_etoken_operations.store_key = etoken_store_key;
sc_pkcs15init_etoken_operations.generate_key = etoken_generate_key;
return &sc_pkcs15init_etoken_operations;
}

View File

@ -1117,13 +1117,16 @@ debug(struct sc_profile *profile, const char *fmt, ...)
printf("%s", buffer); /* XXX */
}
struct sc_pkcs15init_operations sc_pkcs15init_gpk_operations = {
.erase_card = gpk_erase_card,
.create_dir = gpk_create_dir,
.select_pin_reference = gpk_select_pin_reference,
.create_pin = gpk_create_pin,
.create_key = gpk_create_key,
.store_key = gpk_store_key,
// .new_key = gpk_new_key,
// .new_file = gpk_new_file,
};
static struct sc_pkcs15init_operations sc_pkcs15init_gpk_operations;
struct sc_pkcs15init_operations *sc_pkcs15init_get_gpk_ops(void)
{
sc_pkcs15init_gpk_operations.erase_card = gpk_erase_card;
sc_pkcs15init_gpk_operations.create_dir = gpk_create_dir;
sc_pkcs15init_gpk_operations.select_pin_reference = gpk_select_pin_reference;
sc_pkcs15init_gpk_operations.create_pin = gpk_create_pin;
sc_pkcs15init_gpk_operations.create_key = gpk_create_key;
sc_pkcs15init_gpk_operations.store_key = gpk_store_key;
return &sc_pkcs15init_gpk_operations;
}

View File

@ -321,6 +321,11 @@ extern int sc_pkcs15init_requires_restrictive_usage(
extern int sc_pkcs15_create_pin_domain(sc_profile_t *, sc_card_t *,
const sc_pkcs15_id_t *, sc_file_t **);
extern struct sc_pkcs15init_operations *sc_pkcs15init_get_gpk_ops(void);
extern struct sc_pkcs15init_operations *sc_pkcs15init_get_miocos_ops(void);
extern struct sc_pkcs15init_operations *sc_pkcs15init_get_cflex_ops(void);
extern struct sc_pkcs15init_operations *sc_pkcs15init_get_etoken_ops(void);
#ifdef __cplusplus
}
#endif

View File

@ -113,23 +113,27 @@ static struct sc_pkcs15_df * find_df_by_type(struct sc_pkcs15_card *, int);
static void default_error_handler(const char *fmt, ...);
static void default_debug_handler(int, const char *fmt, ...);
/* Card specific functions */
extern struct sc_pkcs15init_operations sc_pkcs15init_gpk_operations;
extern struct sc_pkcs15init_operations sc_pkcs15init_miocos_operations;
extern struct sc_pkcs15init_operations sc_pkcs15init_cflex_operations;
extern struct sc_pkcs15init_operations sc_pkcs15init_etoken_operations;
static struct profile_operations {
char *name;
void *func;
} profile_operations[] = {
{ "gpk", (void *) sc_pkcs15init_get_gpk_ops },
{ "miocos", (void *) sc_pkcs15init_get_miocos_ops },
{ "flex", (void *) sc_pkcs15init_get_cflex_ops },
{ "etoken", (void *) sc_pkcs15init_get_etoken_ops },
{ NULL, NULL },
};
static struct sc_pkcs15init_callbacks callbacks = {
default_error_handler,
default_debug_handler,
NULL,
NULL
NULL,
};
#define p15init_error callbacks.error
#define p15init_debug callbacks.debug
/*
* Set the application callbacks
*/
@ -182,11 +186,12 @@ sc_pkcs15init_bind(struct sc_card *card, const char *name,
struct sc_profile **result)
{
struct sc_profile *profile;
struct sc_pkcs15init_operations * (* func)(void) = NULL;
const char *driver = card->driver->short_name;
char main_profile[128],
card_profile[PATH_MAX],
*option = "default";
int r;
int r, i;
/* Put the card into administrative mode */
r = sc_pkcs15init_set_lifecycle(card, SC_CARDCTRL_LIFECYCLE_ADMIN);
@ -194,17 +199,16 @@ sc_pkcs15init_bind(struct sc_card *card, const char *name,
return r;
profile = sc_profile_new();
profile->cbs = &callbacks;
if (!strcasecmp(driver, "GPK"))
profile->ops = &sc_pkcs15init_gpk_operations;
else if (!strcasecmp(driver, "MioCOS"))
profile->ops = &sc_pkcs15init_miocos_operations;
else if (!strcasecmp(driver, "flex"))
profile->ops = &sc_pkcs15init_cflex_operations;
else if (!strcasecmp(driver, "eToken"))
profile->ops = &sc_pkcs15init_etoken_operations;
else {
for (i = 0; profile_operations[i].name; i++) {
if (!strcasecmp(driver, profile_operations[i].name)) {
func = (struct sc_pkcs15init_operations * (*)(void)) profile_operations[i].func;
break;
}
}
if (func) {
profile->ops = func();
} else {
p15init_error("Unsupported card driver %s", driver);
sc_profile_free(profile);
return SC_ERROR_NOT_SUPPORTED;

View File

@ -199,10 +199,14 @@ miocos_new_key(struct sc_profile *profile, struct sc_card *card,
return r;
}
struct sc_pkcs15init_operations sc_pkcs15init_miocos_operations = {
NULL,
.init_app = miocos_init_app,
.new_pin = miocos_new_pin,
.new_key = miocos_new_key,
.new_file = miocos_new_file,
};
static struct sc_pkcs15init_operations sc_pkcs15init_miocos_operations;
struct sc_pkcs15init_operations *sc_pkcs15init_get_miocos_ops(void)
{
sc_pkcs15init_miocos_operations.init_app = miocos_init_app;
sc_pkcs15init_miocos_operations.new_pin = miocos_new_pin;
sc_pkcs15init_miocos_operations.new_key = miocos_new_key;
sc_pkcs15init_miocos_operations.new_file = miocos_new_file;
return &sc_pkcs15init_miocos_operations;
}