Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'ludovic/PCSCv2_PART10_PROPERTY_bMaxPINS…

…ize' into proposed
  • Loading branch information...
commit f4c39e20b1328ecb85ccf1f34296f47694f9033e 2 parents 6690975 + 75524a5
@martinpaljak martinpaljak authored
View
11 src/libopensc/internal-winscard.h
@@ -173,6 +173,17 @@ typedef LONG (PCSC_API *SCardGetAttrib_t)(SCARDHANDLE hCard, DWORD dwAttrId,\
#define FEATURE_GET_TLV_PROPERTIES 0x12
#define FEATURE_CCID_ESC_COMMAND 0x13
+/* properties returned by FEATURE_GET_TLV_PROPERTIES */
+#define PCSCv2_PART10_PROPERTY_wLcdLayout 1
+#define PCSCv2_PART10_PROPERTY_bEntryValidationCondition 2
+#define PCSCv2_PART10_PROPERTY_bTimeOut2 3
+#define PCSCv2_PART10_PROPERTY_wLcdMaxCharacters 4
+#define PCSCv2_PART10_PROPERTY_wLcdMaxLines 5
+#define PCSCv2_PART10_PROPERTY_bMinPINSize 6
+#define PCSCv2_PART10_PROPERTY_bMaxPINSize 7
+#define PCSCv2_PART10_PROPERTY_sFirmwareID 8
+#define PCSCv2_PART10_PROPERTY_bPPDUSupport 9
+
/* structures used (but not defined) in PCSC Part 10:
* "IFDs with Secure Pin Entry Capabilities" */
View
98 src/libopensc/reader-pcsc.c
@@ -86,6 +86,8 @@ struct pcsc_private_data {
DWORD pin_properties_ioctl;
+ DWORD get_tlv_properties;
+
int locked;
};
@@ -789,6 +791,8 @@ static void detect_reader_features(sc_reader_t *reader, SCARDHANDLE card_handle)
priv->modify_ioctl_finish = ntohl(pcsc_tlv[i].value);
} else if (pcsc_tlv[i].tag == FEATURE_IFD_PIN_PROPERTIES) {
priv->pin_properties_ioctl = ntohl(pcsc_tlv[i].value);
+ } else if (pcsc_tlv[i].tag == FEATURE_GET_TLV_PROPERTIES) {
+ priv->get_tlv_properties = ntohl(pcsc_tlv[i].value);
} else {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Reader feature %02x is not supported", pcsc_tlv[i].tag);
}
@@ -1029,6 +1033,7 @@ static int pcsc_wait_for_event(sc_context_t *ctx, unsigned int event_mask, sc_re
size_t i;
unsigned int num_watch;
int r = SC_ERROR_INTERNAL;
+ DWORD dwtimeout;
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
@@ -1167,10 +1172,12 @@ static int pcsc_wait_for_event(sc_context_t *ctx, unsigned int event_mask, sc_re
/* Set the timeout if caller wants to time out */
if (timeout == -1) {
- timeout = INFINITE;
+ dwtimeout = INFINITE;
}
+ else
+ dwtimeout = timeout;
- rv = gpriv->SCardGetStatusChange(gpriv->pcsc_wait_ctx, timeout, rgReaderStates, num_watch);
+ rv = gpriv->SCardGetStatusChange(gpriv->pcsc_wait_ctx, dwtimeout, rgReaderStates, num_watch);
if (rv == (LONG) SCARD_E_CANCELLED) {
/* C_Finalize was called, events don't matter */
@@ -1427,6 +1434,91 @@ static int part10_build_modify_pin_block(struct sc_reader *reader, u8 * buf, siz
return SC_SUCCESS;
}
+/* Find a given PCSC v2 part 10 property */
+static int
+part10_find_property_by_tag(unsigned char buffer[], int length,
+ int tag_searched)
+{
+ unsigned char *p;
+ int found = 0, len, value = -1;
+
+ p = buffer;
+ while (p-buffer < length)
+ {
+ if (*p++ == tag_searched)
+ {
+ found = 1;
+ break;
+ }
+
+ /* go to next tag */
+ len = *p++;
+ p += len;
+ }
+
+ if (found)
+ {
+ len = *p++;
+
+ switch(len)
+ {
+ case 1:
+ value = *p;
+ break;
+ case 2:
+ value = *p + (*(p+1)<<8);
+ break;
+ case 4:
+ value = *p + (*(p+1)<<8) + (*(p+2)<<16) + (*(p+3)<<24);
+ break;
+ default:
+ value = -1;
+ }
+ }
+
+ return value;
+} /* part10_find_property_by_tag */
+
+/* Make sure the pin min and max are supported by the reader
+ * and fix the values if needed */
+static int
+part10_check_pin_min_max(sc_reader_t *reader, struct sc_pin_cmd_data *data)
+{
+ int r;
+ unsigned char buffer[256];
+ size_t length = sizeof buffer;
+ struct pcsc_private_data *priv = GET_PRIV_DATA(reader);
+
+ r = pcsc_internal_transmit(reader, NULL, 0, buffer, &length,
+ priv->get_tlv_properties);
+ SC_TEST_RET(reader->ctx, SC_LOG_DEBUG_NORMAL, r,
+ "PC/SC v2 part 10: Get TLV properties failed!");
+
+ /* minimum pin size */
+ r = part10_find_property_by_tag(buffer, length,
+ PCSCv2_PART10_PROPERTY_bMinPINSize);
+ if (r >= 0)
+ {
+ unsigned int value = r;
+
+ if (data->pin1.min_length < value)
+ data->pin1.min_length = r;
+ }
+
+ /* maximum pin size */
+ r = part10_find_property_by_tag(buffer, length,
+ PCSCv2_PART10_PROPERTY_bMaxPINSize);
+ if (r >= 0)
+ {
+ unsigned int value = r;
+
+ if (data->pin1.max_length > value)
+ data->pin1.max_length = r;
+ }
+
+ return 0;
+}
+
/* Do the PIN command */
static int
pcsc_pin_cmd(sc_reader_t *reader, struct sc_pin_cmd_data *data)
@@ -1457,6 +1549,7 @@ pcsc_pin_cmd(sc_reader_t *reader, struct sc_pin_cmd_data *data)
sc_debug(reader->ctx, SC_LOG_DEBUG_NORMAL, "Pinpad reader does not support verification!");
return SC_ERROR_NOT_SUPPORTED;
}
+ part10_check_pin_min_max(reader, data);
r = part10_build_verify_pin_block(reader, sbuf, &scount, data);
ioctl = priv->verify_ioctl ? priv->verify_ioctl : priv->verify_ioctl_start;
break;
@@ -1466,6 +1559,7 @@ pcsc_pin_cmd(sc_reader_t *reader, struct sc_pin_cmd_data *data)
sc_debug(reader->ctx, SC_LOG_DEBUG_NORMAL, "Pinpad reader does not support modification!");
return SC_ERROR_NOT_SUPPORTED;
}
+ part10_check_pin_min_max(reader, data);
r = part10_build_modify_pin_block(reader, sbuf, &scount, data);
ioctl = priv->modify_ioctl ? priv->modify_ioctl : priv->modify_ioctl_start;
break;
View
2  src/pkcs15init/pkcs15-lib.c
@@ -1065,7 +1065,7 @@ sc_pkcs15_create_pin_domain(struct sc_profile *profile,
return r;
}
-int
+static int
sc_pkcs15init_encode_prvkey_content(struct sc_pkcs15_card *p15card, struct sc_pkcs15_prkey *prvkey,
struct sc_pkcs15_object *object)
{
Please sign in to comment.
Something went wrong with that request. Please try again.