patch to improve wesctos pkcs15init, submitted by Francois Leblanc
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3823 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
babc99bf58
commit
4f316b2f2a
|
@ -97,39 +97,27 @@ static int westcos_pkcs15_create_pin(sc_profile_t *profile,
|
|||
const u8 *puk, size_t puk_len)
|
||||
{
|
||||
int r;
|
||||
sc_file_t *file = sc_file_new();
|
||||
sc_file_t *pinfile = NULL;
|
||||
sc_path_t path;
|
||||
|
||||
if(pin_len>9 || puk_len>9)
|
||||
return SC_ERROR_INVALID_ARGUMENTS;
|
||||
|
||||
file->type = SC_FILE_TYPE_INTERNAL_EF;
|
||||
file->ef_structure = SC_FILE_EF_TRANSPARENT;
|
||||
file->shareable = 0;
|
||||
r = sc_profile_get_file(profile, "PINFILE", &pinfile);
|
||||
if(r < 0) return r;
|
||||
|
||||
file->id = 0xAAAA;
|
||||
file->size = 37;
|
||||
|
||||
r = sc_file_add_acl_entry(file, SC_AC_OP_READ, SC_AC_NONE, 0);
|
||||
if(r) return r;
|
||||
r = sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, SC_AC_NONE, 0);
|
||||
if(r) return r;
|
||||
r = sc_file_add_acl_entry(file, SC_AC_OP_ERASE, SC_AC_NONE, 0);
|
||||
if(r) return r;
|
||||
|
||||
r = sc_create_file(card, file);
|
||||
r = sc_create_file(card, pinfile);
|
||||
if(r)
|
||||
{
|
||||
if(r != SC_ERROR_FILE_ALREADY_EXISTS)
|
||||
return (r);
|
||||
|
||||
sc_format_path("3F005015AAAA", &path);
|
||||
r = sc_select_file(card, &path, NULL);
|
||||
r = sc_select_file(card, &pinfile->path, NULL);
|
||||
if(r) return (r);
|
||||
}
|
||||
|
||||
if(file)
|
||||
sc_file_free(file);
|
||||
if(pinfile)
|
||||
sc_file_free(pinfile);
|
||||
|
||||
if(pin != NULL)
|
||||
{
|
||||
|
@ -189,62 +177,14 @@ static int westcos_pkcs15init_create_key(sc_profile_t *profile,
|
|||
sc_card_t *card,
|
||||
sc_pkcs15_object_t *obj)
|
||||
{
|
||||
int r;
|
||||
size_t size;
|
||||
sc_file_t *keyfile = NULL;
|
||||
sc_pkcs15_prkey_info_t *key_info = (sc_pkcs15_prkey_info_t *) obj->data;
|
||||
|
||||
if (obj->type != SC_PKCS15_TYPE_PRKEY_RSA) {
|
||||
return SC_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
switch (key_info->modulus_length) {
|
||||
case 128: size = 112; break;
|
||||
case 256: size = 184; break;
|
||||
case 512: size = 336; break;
|
||||
case 768: size = 480; break;
|
||||
case 1024: size = 616; break;
|
||||
case 1536: size = 912; break;
|
||||
case 2048: size = 1200; break;
|
||||
default:
|
||||
r = SC_ERROR_INVALID_ARGUMENTS;
|
||||
goto out;
|
||||
return 0;
|
||||
}
|
||||
|
||||
keyfile = sc_file_new();
|
||||
if(keyfile == NULL)
|
||||
return SC_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
keyfile->path = key_info->path;
|
||||
|
||||
keyfile->type = SC_FILE_TYPE_WORKING_EF;
|
||||
keyfile->ef_structure = SC_FILE_EF_TRANSPARENT;
|
||||
keyfile->shareable = 0;
|
||||
keyfile->size = size;
|
||||
|
||||
r = sc_file_add_acl_entry(keyfile, SC_AC_OP_READ, SC_AC_CHV, 0);
|
||||
if(r) goto out;
|
||||
r = sc_file_add_acl_entry(keyfile, SC_AC_OP_UPDATE, SC_AC_CHV, 0);
|
||||
if(r) goto out;
|
||||
r = sc_file_add_acl_entry(keyfile, SC_AC_OP_ERASE, SC_AC_CHV, 0);
|
||||
if(r) goto out;
|
||||
|
||||
r = sc_pkcs15init_create_file(profile, card, keyfile);
|
||||
if(r)
|
||||
{
|
||||
if(r != SC_ERROR_FILE_ALREADY_EXISTS)
|
||||
goto out;
|
||||
r = 0;
|
||||
}
|
||||
|
||||
out:
|
||||
if(keyfile)
|
||||
sc_file_free(keyfile);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Store a private key
|
||||
|
@ -293,7 +233,6 @@ static int westcos_pkcs15init_generate_key(sc_profile_t *profile,
|
|||
goto out;
|
||||
}
|
||||
|
||||
/* pkcs11 re-route routine cryptage vers la carte fixe default to use openssl */
|
||||
if(!BN_set_word(bn, RSA_F4) ||
|
||||
!RSA_generate_key_ex(rsa, key_info->modulus_length, bn, NULL))
|
||||
#else
|
||||
|
@ -350,9 +289,14 @@ static int westcos_pkcs15init_generate_key(sc_profile_t *profile,
|
|||
if (r != SC_SUCCESS)
|
||||
pbuf[0] = '\0';
|
||||
|
||||
return r;
|
||||
goto out;
|
||||
}
|
||||
|
||||
prkf->size = lg;
|
||||
|
||||
r = sc_pkcs15init_create_file(profile, card, prkf);
|
||||
if(r) goto out;
|
||||
|
||||
r = sc_pkcs15init_update_file(profile, card, prkf, p, lg);
|
||||
if(r) goto out;
|
||||
|
||||
|
|
|
@ -87,6 +87,14 @@ filesystem {
|
|||
acl = $unprotected;
|
||||
size = 5000;
|
||||
|
||||
EF PINFILE {
|
||||
file-id = AAAA;
|
||||
type = INTERNAL-EF;
|
||||
structure = TRANSPARENT;
|
||||
size = 100;
|
||||
acl = *=NEVER;
|
||||
}
|
||||
|
||||
EF PKCS15-ODF {
|
||||
file-id = 5031;
|
||||
size = $odf-size;
|
||||
|
|
Loading…
Reference in New Issue