add PKCS11_change_pin() function

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2489 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
ludovic.rousseau 2005-08-16 11:05:09 +00:00
parent 305b68f10b
commit decb9297dd
3 changed files with 30 additions and 0 deletions

View File

@ -179,6 +179,10 @@ extern int PKCS11_init_token(PKCS11_TOKEN *, const char *pin,
/* Initialize the user PIN on a token */
extern int PKCS11_init_pin(PKCS11_TOKEN *, const char *pin);
/* Change the user PIN on a token */
extern int PKCS11_change_pin(PKCS11_SLOT *, const char *old_pin,
const char *new_pin);
/* Store various objects on the token */
extern int PKCS11_generate_key(PKCS11_TOKEN *, int, unsigned int, char *);
extern int PKCS11_store_private_key(PKCS11_TOKEN *, EVP_PKEY *, char *);
@ -224,6 +228,7 @@ extern void ERR_load_PKCS11_strings(void);
#define PKCS11_F_PKCS11_STORE_CERTIFICATE 19
#define PKCS11_F_PKCS11_SEED_RANDOM 20
#define PKCS11_F_PKCS11_GENERATE_RANDOM 21
#define PKCS11_F_PKCS11_CHANGE_PIN 22
#define PKCS11_F_PKCS11_GETATTR 40
#define PKCS11_ERR_BASE 1024

View File

@ -85,6 +85,7 @@ static ERR_STRING_DATA PKCS11_str_functs[] = {
{ERR_PACK(0, PKCS11_F_PKCS11_GENERATE_KEY, 0), "PKCS11_generate_key"},
{ERR_PACK(0, PKCS11_F_PKCS11_STORE_PUBLIC_KEY, 0), "PKCS11_store_public_key"},
{ERR_PACK(0, PKCS11_F_PKCS11_STORE_CERTIFICATE, 0), "PKCS11_store_certificate"},
{ERR_PACK(0, PKCS11_F_PKCS11_CHANGE_PIN, 0), "PKCS11_change_pin"},
{0, NULL}
};

View File

@ -251,6 +251,30 @@ int PKCS11_init_pin(PKCS11_TOKEN * token, const char *pin)
return pkcs11_check_token(ctx, TOKEN2SLOT(token));
}
/*
* Change the User PIN
*/
int PKCS11_change_pin(PKCS11_SLOT * slot, const char *old_pin,
const char *new_pin)
{
PKCS11_SLOT_private *priv = PRIVSLOT(slot);
PKCS11_CTX *ctx = priv->parent;
int old_len, new_len, rv;
if (!priv->haveSession) {
PKCS11err(PKCS11_F_PKCS11_CHANGE_PIN, PKCS11_NO_SESSION);
return -1;
}
old_len = old_pin ? strlen(old_pin) : 0;
new_len = new_pin ? strlen(new_pin) : 0;
rv = CRYPTOKI_call(ctx, C_SetPIN(priv->session, (CK_UTF8CHAR *) old_pin,
old_len, (CK_UTF8CHAR *) new_pin, new_len));
CRYPTOKI_checkerr(PKCS11_F_PKCS11_CHANGE_PIN, rv);
return pkcs11_check_token(ctx, slot);
}
/*
* Seed the random number generator
*/