- Replaced references to sc_get_pin* with its OpenSSL counter parts (untested)

- UI functionality and maybe more is no longer shipped in opensc>=0.12. This
  and the fact that linking against libopensc in general is discouraged might
be a reason to abandon opensc in future releases.


git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@170 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
frankmorgner
2010-06-25 21:31:36 +00:00
parent 7411c63b47
commit a2012126cd
3 changed files with 64 additions and 75 deletions

View File

@@ -23,7 +23,7 @@
#include <stdio.h> #include <stdio.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <opensc/opensc.h> #include <opensc/opensc.h>
#include <opensc/ui.h> #include <openssl/evp.h>
#include <opensc/log.h> #include <opensc/log.h>
#include "ccid.h" #include "ccid.h"
@@ -775,7 +775,6 @@ perform_PC_to_RDR_Secure(const __u8 *in, size_t inlen, __u8** out, size_t *outle
int sc_result, r; int sc_result, r;
struct sc_pin_cmd_pin curr_pin, new_pin; struct sc_pin_cmd_pin curr_pin, new_pin;
sc_apdu_t apdu; sc_apdu_t apdu;
sc_ui_hints_t hints;
const PC_to_RDR_Secure_t *request = (PC_to_RDR_Secure_t *) in; const PC_to_RDR_Secure_t *request = (PC_to_RDR_Secure_t *) in;
const __u8* abData = in + sizeof *request; const __u8* abData = in + sizeof *request;
size_t abDatalen = inlen - sizeof *request; size_t abDatalen = inlen - sizeof *request;
@@ -792,7 +791,6 @@ perform_PC_to_RDR_Secure(const __u8 *in, size_t inlen, __u8** out, size_t *outle
if (request->bMessageType != 0x69) if (request->bMessageType != 0x69)
sc_debug(ctx, "warning: malformed PC_to_RDR_Secure"); sc_debug(ctx, "warning: malformed PC_to_RDR_Secure");
memset(&hints, 0, sizeof(hints));
memset(&curr_pin, 0, sizeof(curr_pin)); memset(&curr_pin, 0, sizeof(curr_pin));
memset(&new_pin, 0, sizeof(new_pin)); memset(&new_pin, 0, sizeof(new_pin));
@@ -923,58 +921,42 @@ perform_PC_to_RDR_Secure(const __u8 *in, size_t inlen, __u8** out, size_t *outle
modify ? "bytes" : "system units"); modify ? "bytes" : "system units");
/* get the PIN */ /* get the PIN */
hints.dialog_name = "ccid.PC_to_RDR_Secure";
hints.card = card_in_slot[request->bSlot];
if (bNumberMessage == CCID_PIN_MSG_DEFAULT
|| bNumberMessage == CCID_PIN_MSG_REF
|| bNumberMessage == CCID_PIN_NO_MSG) {
/* don't interprete bMsgIndex*, just use defaults */
if (verify)
hints.usage = SC_UI_USAGE_OTHER;
else
hints.usage = SC_UI_USAGE_CHANGE_PIN;
} else if (bNumberMessage == CCID_PIN_MSG1)
hints.usage = SC_UI_USAGE_OTHER;
else if (bNumberMessage == CCID_PIN_MSG2)
hints.usage = SC_UI_USAGE_NEW_PIN;
else {
sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err;
}
if (verify) { if (verify) {
hints.prompt = "PIN Verification"; if (0 > EVP_read_pw_string_min((char *) curr_pin.data,
sc_result = sc_ui_get_pin(&hints, (char **) &curr_pin.data); curr_pin.min_length, curr_pin.max_length,
} else { "Please enter your PIN for verification",
hints.prompt = "PIN Modification"; 0)) {
if (modify->bConfirmPIN & CCID_PIN_CONFIRM_NEW) sc_result = SC_ERROR_INTERNAL;
hints.flags |= SC_UI_PIN_RETYPE; sc_error(ctx, "Could not read PIN.\n");
if (modify->bConfirmPIN & CCID_PIN_INSERT_OLD) {
sc_result = sc_ui_get_pin_pair(&hints, (char **) &curr_pin.data,
(char **) &new_pin.data);
} else {
/* if only the new pin is requested, it is stored in curr_pin */
sc_result = sc_ui_get_pin(&hints, (char **) &curr_pin.data);
}
}
if (sc_result < 0)
goto err;
/* set and check length of PIN */
curr_pin.len = strlen((char *) curr_pin.data);
if ((curr_pin.max_length && curr_pin.len > curr_pin.max_length)
|| curr_pin.len < curr_pin.min_length) {
sc_result = SC_ERROR_PIN_CODE_INCORRECT;
sc_error(ctx, "PIN request required a longer or shorter PIN");
goto err;
}
if (modify) {
new_pin.len = strlen((char *) new_pin.data);
if ((new_pin.max_length && new_pin.len > new_pin.max_length)
|| new_pin.len < new_pin.min_length) {
sc_error(ctx, "PIN request required a longer or shorter PIN");
sc_result = SC_ERROR_PIN_CODE_INCORRECT;
goto err; goto err;
} }
} else {
if (modify->bConfirmPIN & CCID_PIN_INSERT_OLD) {
/* if only the new pin is requested, it is stored in curr_pin */
if (0 > EVP_read_pw_string_min((char *) curr_pin.data,
curr_pin.min_length, curr_pin.max_length,
"Please enter your current PIN for modification",
0)) {
sc_result = SC_ERROR_INTERNAL;
sc_error(ctx, "Could not read current PIN.\n");
goto err;
}
}
if (0 > EVP_read_pw_string_min((char *) new_pin.data,
new_pin.min_length, new_pin.max_length,
"Please enter your new PIN for modification",
modify->bConfirmPIN & CCID_PIN_CONFIRM_NEW)) {
sc_result = SC_ERROR_INTERNAL;
sc_error(ctx, "Could not read new PIN.\n");
goto err;
}
}
/* set length of PIN */
curr_pin.len = strlen((char *) curr_pin.data);
if (modify) {
new_pin.len = strlen((char *) new_pin.data);
} }
/* Note: pin.offset and pin.length_offset are relative to the first /* Note: pin.offset and pin.length_offset are relative to the first

View File

@@ -23,7 +23,7 @@
#include <opensc/asn1.h> #include <opensc/asn1.h>
#include <opensc/log.h> #include <opensc/log.h>
#include <opensc/opensc.h> #include <opensc/opensc.h>
#include <opensc/ui.h> #include <openssl/evp.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/err.h> #include <openssl/err.h>
@@ -591,22 +591,21 @@ pace_reset_retry_counter(struct sm_ctx *ctx, sc_card_t *card,
const char *new, size_t new_len) const char *new, size_t new_len)
{ {
sc_apdu_t apdu; sc_apdu_t apdu;
sc_ui_hints_t hints;
char *p = NULL; char *p = NULL;
int r; int r;
if (ask_for_secret && (!new || !new_len)) { if (ask_for_secret && (!new || !new_len)) {
memset(&hints, 0, sizeof(hints)); p = malloc(MAX_PIN_LEN+1);
hints.dialog_name = "ccid.PACE"; if (!p) {
hints.card = card; sc_error(card->ctx, "Not enough memory for new PIN.\n");
hints.prompt = NULL; return SC_ERROR_OUT_OF_MEMORY;
hints.obj_label = pace_secret_name(PACE_PIN); }
hints.usage = SC_UI_USAGE_NEW_PIN; if (0 > EVP_read_pw_string_min(p,
r = sc_ui_get_pin(&hints, &p); MIN_PIN_LEN, MAX_PIN_LEN+1,
if (r < 0) { "Please enter your new PIN for modification", 0)) {
sc_error(card->ctx, "Could not read new %s (%s).\n", sc_error(card->ctx, "Could not read new PIN.\n");
hints.obj_label, sc_strerror(r)); free(p);
return r; return SC_ERROR_INTERNAL;
} }
new_len = strlen(p); new_len = strlen(p);
new = p; new = p;
@@ -641,22 +640,27 @@ pace_reset_retry_counter(struct sm_ctx *ctx, sc_card_t *card,
static PACE_SEC * static PACE_SEC *
get_psec(sc_card_t *card, const char *pin, size_t length_pin, enum s_type pin_id) get_psec(sc_card_t *card, const char *pin, size_t length_pin, enum s_type pin_id)
{ {
sc_ui_hints_t hints;
char *p = NULL; char *p = NULL;
PACE_SEC *r; PACE_SEC *r;
int sc_result; int sc_result;
char buf[32]; /* XXX max size of mrz */
if (!length_pin || !pin) { if (!length_pin || !pin) {
memset(&hints, 0, sizeof(hints)); if (0 > snprintf(buf, sizeof buf, "Please enter your %s",
hints.dialog_name = "ccid.PACE"; pace_secret_name(pin_id))) {
hints.card = card; sc_error(card->ctx, "Could not create password prompt.\n");
hints.prompt = NULL; return NULL;
hints.obj_label = pace_secret_name(pin_id); }
hints.usage = SC_UI_USAGE_OTHER; p = malloc(MAX_MRZ_LEN);
sc_result = sc_ui_get_pin(&hints, &p); if (!p) {
if (sc_result < 0) { sc_error(card->ctx, "Not enough memory for %s.\n",
pace_secret_name(pin_id));
return NULL;
}
if (0 > EVP_read_pw_string_min(p, 0, MAX_MRZ_LEN,
"Please enter your new PIN for modification", 0)) {
sc_error(card->ctx, "Could not read %s (%s).\n", sc_error(card->ctx, "Could not read %s (%s).\n",
pace_secret_name(pin_id), sc_strerror(sc_result)); pace_secret_name(pin_id));
return NULL; return NULL;
} }
length_pin = strlen(p); length_pin = strlen(p);

View File

@@ -42,6 +42,9 @@ extern "C" {
#define FID_EF_CARDACCESS 0x011C #define FID_EF_CARDACCESS 0x011C
#define MAX_EF_CARDACCESS 2048 #define MAX_EF_CARDACCESS 2048
#define MAX_PIN_LEN 6
#define MIN_PIN_LEN 6
#define MAX_MRZ_LEN 128
int increment_ssc(struct pace_sm_ctx *psmctx); int increment_ssc(struct pace_sm_ctx *psmctx);
int decrement_ssc(struct pace_sm_ctx *psmctx); int decrement_ssc(struct pace_sm_ctx *psmctx);