- fixed sc_pkcs15_change_pin()
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@62 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
bc946d6bfe
commit
06fc4565ba
@ -50,8 +50,9 @@ AC_FUNC_MALLOC
|
||||
AC_FUNC_MEMCMP
|
||||
AC_CHECK_FUNCS(memset strdup)
|
||||
|
||||
#AC_CONFIG_FILES(Makefile)
|
||||
|
||||
AC_SUBST(ac_aux_dir)
|
||||
|
||||
AC_OUTPUT(Makefile src/Makefile)
|
||||
CFLAGS="${CFLAGS} -Wall"
|
||||
|
||||
AC_CONFIG_FILES(Makefile src/Makefile)
|
||||
AC_OUTPUT
|
||||
|
@ -6,6 +6,6 @@ libopensc_la_SOURCES = sc-asn1.c sc-base64.c sc-defaults.c \
|
||||
sc-sec.c sc.c sc-pkcs15.c sc-pkcs15-cert.c \
|
||||
sc-pkcs15-pin.c sc-pkcs15-prkey.c \
|
||||
sc-pkcs15-defaults.c sc-pkcs15-sec.c
|
||||
libopensc_la_LDFLAGS = -version-info 0:1:0
|
||||
libopensc_la_LDFLAGS = -version-info 0:2:0
|
||||
include_HEADERS = opensc.h opensc-pkcs15.h
|
||||
noinst_HEADERS = sc-asn1.h
|
||||
|
@ -213,7 +213,8 @@ int sc_compute_signature(struct sc_card *card, const u8 * data,
|
||||
int sc_verify(struct sc_card *card, int ref, const u8 *buf, int buflen,
|
||||
int *tries_left);
|
||||
int sc_change_reference_data(struct sc_card *card, int ref, const u8 *old,
|
||||
int oldlen, const u8 *new, int newlen);
|
||||
int oldlen, const u8 *new, int newlen,
|
||||
int *tries_left);
|
||||
int sc_reset_retry_counter(struct sc_card *card, int ref, const u8 *puk,
|
||||
int puklen, const u8 *new, int newlen);
|
||||
|
||||
|
@ -201,10 +201,8 @@ int sc_pkcs15_change_pin(struct sc_pkcs15_card *p15card,
|
||||
{
|
||||
int r;
|
||||
struct sc_file file;
|
||||
struct sc_apdu apdu;
|
||||
struct sc_card *card;
|
||||
char pinbuf[SC_MAX_PIN_SIZE * 2];
|
||||
char resp[MAX_BUFFER_SIZE];
|
||||
u8 pinbuf[SC_MAX_PIN_SIZE * 2];
|
||||
|
||||
assert(p15card != NULL);
|
||||
if (pin->magic != SC_PKCS15_PIN_MAGIC)
|
||||
@ -220,31 +218,14 @@ int sc_pkcs15_change_pin(struct sc_pkcs15_card *p15card,
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
sc_format_apdu(p15card->card, &apdu, SC_APDU_CASE_3_SHORT,
|
||||
0x24, 0, pin->auth_id.value[0]);
|
||||
apdu.lc = pin->stored_length * 2;
|
||||
apdu.data = pinbuf;
|
||||
apdu.datalen = pin->stored_length * 2;
|
||||
apdu.resp = resp;
|
||||
apdu.resplen = 2;
|
||||
memset(pinbuf, pin->pad_char, pin->stored_length * 2);
|
||||
|
||||
memcpy(pinbuf, oldpin, oldpinlen);
|
||||
memcpy(pinbuf + pin->stored_length, newpin, newpinlen);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
r = sc_change_reference_data(card, pin->auth_id.value[0], pinbuf,
|
||||
pin->stored_length, pinbuf+pin->stored_length,
|
||||
pin->stored_length, &pin->tries_left);
|
||||
memset(pinbuf, 0, pin->stored_length * 2);
|
||||
|
||||
if (r)
|
||||
return r;
|
||||
if (apdu.resplen == 2) {
|
||||
if (apdu.resp[0] == 0x90 && apdu.resp[1] == 0x00)
|
||||
return 0;
|
||||
if (apdu.resp[0] == 0x63 && (apdu.resp[1] & 0xF0) == 0xC0) {
|
||||
pin->tries_left = apdu.resp[1] & 0x0F;
|
||||
return SC_ERROR_PIN_CODE_INCORRECT;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sc_pkcs15_find_pin_by_auth_id(struct sc_pkcs15_card *card,
|
||||
|
@ -179,7 +179,8 @@ int sc_verify(struct sc_card *card, int ref, const u8 *pin, int pinlen,
|
||||
}
|
||||
|
||||
int sc_change_reference_data(struct sc_card *card, int ref, const u8 *old,
|
||||
int oldlen, const u8 *new, int newlen)
|
||||
int oldlen, const u8 *new, int newlen,
|
||||
int *tries_left)
|
||||
{
|
||||
struct sc_apdu apdu;
|
||||
u8 sbuf[MAX_BUFFER_SIZE];
|
||||
@ -201,6 +202,11 @@ int sc_change_reference_data(struct sc_card *card, int ref, const u8 *old,
|
||||
memset(sbuf, 0, len);
|
||||
if (r)
|
||||
return r;
|
||||
if (apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0) {
|
||||
if (tries_left != NULL)
|
||||
*tries_left = apdu.sw2 & 0x0F;
|
||||
return SC_ERROR_PIN_CODE_INCORRECT;
|
||||
}
|
||||
return sc_sw_to_errorcode(apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user