6277N/AIn-house patch created to clear any merge conflicts from source in archive
6277N/Arepo to build properly on Solaris.
6277N/A
6277N/A--- CACKey-0.7.4/cackey.c 2016-05-19 14:16:48.230399914 -0400
6277N/A+++ CACKey-0.7.4/cackey.c 2015-07-16 12:20:20.000000000 -0400
6277N/A@@ -35,13 +35,10 @@
6277N/A #ifdef HAVE_STDIO_H
6277N/A # include <stdio.h>
6277N/A #endif
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A #define HAVE_ERRNO_H 1
6277N/A #ifdef HAVE_ERRNO_H
6277N/A # include <errno.h>
6277N/A #endif
6277N/A->>>>>>> trunk
6277N/A #ifdef HAVE_ZLIB_H
6277N/A # ifdef HAVE_LIBZ
6277N/A # include <zlib.h>
6277N/A@@ -51,12 +48,9 @@
6277N/A # undef HAVE_LIBZ
6277N/A # endif
6277N/A #endif
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A #ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST
6277N/A # include <sys/time.h>
6277N/A #endif
6277N/A->>>>>>> trunk
6277N/A
6277N/A #define CK_PTR *
6277N/A #define CK_DEFINE_FUNCTION(returnType, name) returnType name
6277N/A@@ -73,17 +67,6 @@
6277N/A #include "sha1.h"
6277N/A #include "md5.h"
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-/*
6277N/A- * Include these source files in this translation unit so that we can bind to
6277N/A- * functions and not include any symbols in the output shared object.
6277N/A- */
6277N/A-#include "asn1-x509.c"
6277N/A-#include "sha1.c"
6277N/A-#include "md5.c"
6277N/A-
6277N/A-=======
6277N/A->>>>>>> trunk
6277N/A #ifndef CACKEY_CRYPTOKI_VERSION_CODE
6277N/A # define CACKEY_CRYPTOKI_VERSION_CODE 0x021e00
6277N/A #endif
6277N/A@@ -102,10 +85,7 @@
6277N/A #define GSCIS_INSTR_GET_CHALLENGE 0x84
6277N/A #define GSCIS_INSTR_INTERNAL_AUTH 0x88
6277N/A #define GSCIS_INSTR_VERIFY 0x20
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A #define GSCIS_INSTR_CHANGE_REFERENCE 0x24
6277N/A->>>>>>> trunk
6277N/A #define GSCIS_INSTR_SIGN 0x2A
6277N/A #define GSCIS_INSTR_GET_PROP 0x56
6277N/A #define GSCIS_INSTR_GET_ACR 0x4C
6277N/A@@ -173,13 +153,10 @@
6277N/A #define GSCIS_TAG_SECURITY_CODE 0x57
6277N/A #define GSCIS_TAG_CARDID_AID 0x58
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A /*** PIV Codes ***/
6277N/A #define NISTSP800_73_3_INSTR_GET_DATA 0xCB
6277N/A #define NISTSP800_73_3_INSTR_GENAUTH 0x87
6277N/A
6277N/A->>>>>>> trunk
6277N/A /*** PKI Information - EF 7000 ***/
6277N/A #define GSCIS_TAG_CERTIFICATE 0x70
6277N/A #define GSCIS_TAG_CERT_ISSUE_DATE 0x71
6277N/A@@ -187,8 +164,6 @@
6277N/A
6277N/A /** Applet IDs **/
6277N/A #define GSCIS_AID_CCC 0xA0, 0x00, 0x00, 0x01, 0x16, 0xDB, 0x00
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A #define NISTSP800_73_3_PIV_AID 0xA0, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00
6277N/A
6277N/A /* PIV IDs */
6277N/A@@ -207,7 +182,6 @@
6277N/A #define NISTSP800_73_3_OID_SIGNATURE 0x5F, 0xC1, 0x0A
6277N/A #define NISTSP800_73_3_OID_KEYMGT 0x5F, 0xC1, 0x0B
6277N/A #define NISTSP800_73_3_OID_CARDAUTH 0x5F, 0xC1, 0x01
6277N/A->>>>>>> trunk
6277N/A
6277N/A /* Maximum size of data portion of APDUs */
6277N/A /** Do not set this above 250 **/
6277N/A@@ -222,17 +196,6 @@
6277N/A # ifdef HAVE_TIME_H
6277N/A # include <time.h>
6277N/A static time_t cackey_debug_start_time = 0;
6277N/A-<<<<<<< HEAD
6277N/A-# define CACKEY_DEBUG_PRINTTIME { if (cackey_debug_start_time == 0) { cackey_debug_start_time = time(NULL); }; fprintf(cackey_debug_fd(), "[%lu]: ", (unsigned long) (time(NULL) - cackey_debug_start_time)); }
6277N/A-# else
6277N/A-# define CACKEY_DEBUG_PRINTTIME /**/
6277N/A-# endif
6277N/A-
6277N/A-# define CACKEY_DEBUG_PRINTF(x...) { CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: ", __func__, __LINE__); fprintf(cackey_debug_fd(), x); fprintf(cackey_debug_fd(), "\n"); fflush(cackey_debug_fd()); }
6277N/A-# define CACKEY_DEBUG_PRINTBUF(f, x, y) { unsigned char *TMPBUF; unsigned long idx; TMPBUF = (unsigned char *) (x); CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: %s (%s/%lu = {%02x", __func__, __LINE__, f, #x, (unsigned long) (y), TMPBUF[0]); for (idx = 1; idx < (y); idx++) { fprintf(cackey_debug_fd(), ", %02x", TMPBUF[idx]); }; fprintf(cackey_debug_fd(), "})\n"); fflush(cackey_debug_fd()); }
6277N/A-# define CACKEY_DEBUG_PERROR(x) { fprintf(cackey_debug_fd(), "%s():%i: ", __func__, __LINE__); CACKEY_DEBUG_PRINTTIME; perror(x); fflush(cackey_debug_fd()); }
6277N/A-# define free(x) { CACKEY_DEBUG_PRINTF("FREE(%p) (%s)", x, #x); free(x); }
6277N/A-=======
6277N/A static unsigned long CACKEY_DEBUG_GETTIME(void) {
6277N/A if (cackey_debug_start_time == 0) {
6277N/A cackey_debug_start_time = time(NULL);
6277N/A@@ -254,17 +217,16 @@
6277N/A fflush(cackey_debug_fd()); \
6277N/A }
6277N/A # define CACKEY_DEBUG_PRINTBUF(f, x, y) { \
6277N/A- static char buf_user[4096] = {0}, *buf_user_p, *buf_user_print; \
6277N/A+ static char buf_user[4096] = {0}, *buf_user_p; \
6277N/A unsigned long buf_user_size; \
6277N/A unsigned char *TMPBUF; \
6277N/A unsigned long idx; \
6277N/A int snprintf_ret; \
6277N/A TMPBUF = (unsigned char *) (x); \
6277N/A buf_user[0] = 0; \
6277N/A- buf_user[2] = 0; \
6277N/A buf_user_p = buf_user; \
6277N/A buf_user_size = sizeof(buf_user); \
6277N/A- for (idx = 0; idx < (y); idx++) { \
6277N/A+ for (idx = 1; idx < (y); idx++) { \
6277N/A if (buf_user_size <= 0) { \
6277N/A break; \
6277N/A }; \
6277N/A@@ -276,12 +238,10 @@
6277N/A buf_user_size -= snprintf_ret; \
6277N/A }; \
6277N/A buf_user[sizeof(buf_user) - 1] = '\0'; \
6277N/A- buf_user_print = buf_user + 2; \
6277N/A- fprintf(cackey_debug_fd(), "[%lu]: %s():%i: %s (%s/%lu = {%s})\n", CACKEY_DEBUG_GETTIME(), __func__, __LINE__, f, #x, (unsigned long) (y), buf_user_print); \
6277N/A+ fprintf(cackey_debug_fd(), "[%lu]: %s():%i: %s (%s/%lu = {%02x%s})\n", CACKEY_DEBUG_GETTIME(), __func__, __LINE__, f, #x, (unsigned long) (y), TMPBUF[0], buf_user); \
6277N/A fflush(cackey_debug_fd()); \
6277N/A }
6277N/A # define free(x) { CACKEY_DEBUG_PRINTF("FREE(%p) (%s)", (void *) x, #x); free(x); }
6277N/A->>>>>>> trunk
6277N/A
6277N/A static FILE *cackey_debug_fd(void) {
6277N/A static FILE *fd = NULL;
6277N/A@@ -309,15 +269,12 @@
6277N/A }
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A #ifdef CACKEY_DEBUG_LOGFILE
6277N/A if (logfile == NULL) {
6277N/A logfile = CACKEY_DEBUG_LOGFILE;
6277N/A }
6277N/A #endif
6277N/A
6277N/A->>>>>>> trunk
6277N/A if (logfile != NULL) {
6277N/A CACKEY_DEBUG_PRINTF("Found log file: %s", logfile);
6277N/A
6277N/A@@ -331,11 +288,7 @@
6277N/A if (fd == stderr) {
6277N/A CACKEY_DEBUG_PRINTF("Returning stderr");
6277N/A } else {
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTF("Returning %p", fd);
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Returning %p", (void *) fd);
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A return(fd);
6277N/A@@ -346,14 +299,7 @@
6277N/A
6277N/A retval = malloc(size);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTTIME;
6277N/A- fprintf(cackey_debug_fd(), "%s():%i: ", func, line);
6277N/A- fprintf(cackey_debug_fd(), "MALLOC() = %p", retval);
6277N/A- fprintf(cackey_debug_fd(), "\n");
6277N/A-=======
6277N/A fprintf(cackey_debug_fd(), "[%lu]: %s():%i: MALLOC() = %p\n", CACKEY_DEBUG_GETTIME(), func, line, retval);
6277N/A->>>>>>> trunk
6277N/A fflush(cackey_debug_fd());
6277N/A
6277N/A return(retval);
6277N/A@@ -365,14 +311,7 @@
6277N/A retval = realloc(ptr, size);
6277N/A
6277N/A if (retval != ptr) {
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTTIME;
6277N/A- fprintf(cackey_debug_fd(), "%s():%i: ", func, line);
6277N/A- fprintf(cackey_debug_fd(), "REALLOC(%p) = %p", ptr, retval);
6277N/A- fprintf(cackey_debug_fd(), "\n");
6277N/A-=======
6277N/A fprintf(cackey_debug_fd(), "[%lu]: %s():%i: REALLOC(%p) = %p\n", CACKEY_DEBUG_GETTIME(), func, line, ptr, retval);
6277N/A->>>>>>> trunk
6277N/A fflush(cackey_debug_fd());
6277N/A }
6277N/A
6277N/A@@ -388,14 +327,7 @@
6277N/A
6277N/A retval = strdup(ptr);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTTIME;
6277N/A- fprintf(cackey_debug_fd(), "%s():%i: ", func, line);
6277N/A- fprintf(cackey_debug_fd(), "STRDUP_MALLOC() = %p", retval);
6277N/A- fprintf(cackey_debug_fd(), "\n");
6277N/A-=======
6277N/A fprintf(cackey_debug_fd(), "[%lu]: %s():%i: STRDUP_MALLOC() = %p\n", CACKEY_DEBUG_GETTIME(), func, line, retval);
6277N/A->>>>>>> trunk
6277N/A fflush(cackey_debug_fd());
6277N/A
6277N/A return(retval);
6277N/A@@ -777,10 +709,6 @@
6277N/A #else
6277N/A # define CACKEY_DEBUG_PRINTF(x...) /**/
6277N/A # define CACKEY_DEBUG_PRINTBUF(f, x, y) /**/
6277N/A-<<<<<<< HEAD
6277N/A-# define CACKEY_DEBUG_PERROR(x) /**/
6277N/A-=======
6277N/A->>>>>>> trunk
6277N/A # define CACKEY_DEBUG_FUNC_TAG_TO_STR(x) "DEBUG_DISABLED"
6277N/A # define CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(x) "DEBUG_DISABLED"
6277N/A # define CACKEY_DEBUG_FUNC_OBJID_TO_STR(x) "DEBUG_DISABLED"
6277N/A@@ -788,11 +716,6 @@
6277N/A # define CACKEY_DEBUG_FUNC_ATTRIBUTE_TO_STR(x) "DEBUG_DISABLED"
6277N/A #endif
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-struct cackey_pcsc_identity {
6277N/A- unsigned char applet[7];
6277N/A- uint16_t file;
6277N/A-=======
6277N/A /*
6277N/A * Include these source files in this translation unit so that we can bind to
6277N/A * functions and not include any symbols in the output shared object.
6277N/A@@ -809,14 +732,11 @@
6277N/A
6277N/A struct cackey_pcsc_identity {
6277N/A cackey_pcsc_id_type id_type;
6277N/A->>>>>>> trunk
6277N/A
6277N/A size_t certificate_len;
6277N/A unsigned char *certificate;
6277N/A
6277N/A ssize_t keysize;
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A
6277N/A union {
6277N/A struct {
6277N/A@@ -829,7 +749,6 @@
6277N/A char label[32];
6277N/A } piv;
6277N/A } card;
6277N/A->>>>>>> trunk
6277N/A };
6277N/A
6277N/A struct cackey_identity {
6277N/A@@ -874,10 +793,7 @@
6277N/A
6277N/A struct cackey_slot {
6277N/A int active;
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A int internal;
6277N/A->>>>>>> trunk
6277N/A
6277N/A char *pcsc_reader;
6277N/A
6277N/A@@ -894,12 +810,9 @@
6277N/A unsigned char *label;
6277N/A
6277N/A DWORD protocol;
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A
6277N/A unsigned int cached_certs_count;
6277N/A struct cackey_pcsc_identity *cached_certs;
6277N/A->>>>>>> trunk
6277N/A };
6277N/A
6277N/A typedef enum {
6277N/A@@ -931,12 +844,7 @@
6277N/A CACKEY_PCSC_E_LOCKED = -3,
6277N/A CACKEY_PCSC_E_NEEDLOGIN = -4,
6277N/A CACKEY_PCSC_E_TOKENABSENT = -6,
6277N/A-<<<<<<< HEAD
6277N/A CACKEY_PCSC_E_RETRY = -7
6277N/A-=======
6277N/A- CACKEY_PCSC_E_RETRY = -7,
6277N/A- CACKEY_PCSC_E_NODATA = -8
6277N/A->>>>>>> trunk
6277N/A } cackey_ret;
6277N/A
6277N/A struct cackey_tlv_cardurl {
6277N/A@@ -974,19 +882,11 @@
6277N/A #include "cackey_builtin_certs.h"
6277N/A };
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A-#define CACKEY_MACRO_DEFAULT_XSTR(str) CACKEY_MACRO_DEFAULT_STR(str)
6277N/A-#define CACKEY_MACRO_DEFAULT_STR(str) #str
6277N/A-
6277N/A /* Protected Authentication Path command */
6277N/A+#define CACKEY_PIN_COMMAND_DEFAULT_XSTR(str) CACKEY_PIN_COMMAND_DEFAULT_STR(str)
6277N/A+#define CACKEY_PIN_COMMAND_DEFAULT_STR(str) #str
6277N/A static char *cackey_pin_command = NULL;
6277N/A
6277N/A-/* Reader Exclusion or Include-only */
6277N/A-static char *cackey_readers_include_only = NULL;
6277N/A-static char *cackey_readers_exclude = NULL;
6277N/A-
6277N/A->>>>>>> trunk
6277N/A /* PCSC Global Handles */
6277N/A static LPSCARDCONTEXT cackey_pcsc_handle = NULL;
6277N/A
6277N/A@@ -1046,14 +946,11 @@
6277N/A CACKEY_DEBUG_PRINTF("Called.");
6277N/A
6277N/A for (idx = 0; idx < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); idx++) {
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A if (cackey_slots[idx].internal) {
6277N/A /* Skip internal slots */
6277N/A continue;
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A if (cackey_slots[idx].pcsc_card_connected) {
6277N/A CACKEY_DEBUG_PRINTF("SCardDisconnect(%lu) called", (unsigned long) idx);
6277N/A
6277N/A@@ -1226,15 +1123,11 @@
6277N/A
6277N/A slot->slot_reset = 1;
6277N/A slot->pcsc_card_connected = 0;
6277N/A-<<<<<<< HEAD
6277N/A- slot->token_flags = CKF_LOGIN_REQUIRED;
6277N/A-=======
6277N/A if (cackey_pin_command == NULL) {
6277N/A slot->token_flags = CKF_LOGIN_REQUIRED;
6277N/A } else {
6277N/A slot->token_flags = 0;
6277N/A }
6277N/A->>>>>>> trunk
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Returning.");
6277N/A
6277N/A@@ -1243,11 +1136,7 @@
6277N/A
6277N/A /*
6277N/A * SYNPOSIS
6277N/A-<<<<<<< HEAD
6277N/A- * LONG cackey_reconnect_card(struct cackey_slot *slot, DWORD default_protocol, LPDWORD selected_protocol);
6277N/A-=======
6277N/A * LONG cackey_reconnect_card(struct cackey_slot *slot, DWORD default_protocol);
6277N/A->>>>>>> trunk
6277N/A *
6277N/A * ARGUMENTS
6277N/A * cackey_slot *slot
6277N/A@@ -1256,12 +1145,6 @@
6277N/A * DWORD default_protocol
6277N/A * Protocol to attempt first
6277N/A *
6277N/A-<<<<<<< HEAD
6277N/A- * LPDWORD selected_protocol
6277N/A- * [OUT] Protocol selected
6277N/A- *
6277N/A-=======
6277N/A->>>>>>> trunk
6277N/A * RETURN VALUE
6277N/A * The return value from SCardReconnect()
6277N/A *
6277N/A@@ -1274,23 +1157,6 @@
6277N/A * that T=1.
6277N/A *
6277N/A */
6277N/A-<<<<<<< HEAD
6277N/A-static LONG cackey_reconnect_card(struct cackey_slot *slot, DWORD default_protocol, LPDWORD selected_protocol) {
6277N/A- LONG scard_conn_ret;
6277N/A-
6277N/A- scard_conn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, default_protocol, SCARD_RESET_CARD, selected_protocol);
6277N/A-
6277N/A- if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) {
6277N/A- CACKEY_DEBUG_PRINTF("SCardReconnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=0")
6277N/A- scard_conn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, selected_protocol);
6277N/A-
6277N/A- if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) {
6277N/A- CACKEY_DEBUG_PRINTF("SCardReconnect() returned SCARD_E_PROTO_MISMATCH, trying with just T=1")
6277N/A- scard_conn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T1, SCARD_RESET_CARD, selected_protocol);
6277N/A- }
6277N/A- }
6277N/A-
6277N/A-=======
6277N/A static LONG cackey_reconnect_card(struct cackey_slot *slot, DWORD default_protocol) {
6277N/A DWORD selected_protocol;
6277N/A LONG scard_conn_ret;
6277N/A@@ -1313,7 +1179,6 @@
6277N/A slot->protocol = selected_protocol;
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A return(scard_conn_ret);
6277N/A }
6277N/A
6277N/A@@ -1355,11 +1220,7 @@
6277N/A
6277N/A /* Connect to reader, if needed */
6277N/A if (!slot->pcsc_card_connected) {
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTF("SCardConnect(%s) called", slot->pcsc_reader);
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("SCardConnect(%s) called for slot %p", slot->pcsc_reader, slot);
6277N/A->>>>>>> trunk
6277N/A scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &slot->pcsc_card, &protocol);
6277N/A
6277N/A if (scard_conn_ret == SCARD_E_PROTO_MISMATCH) {
6277N/A@@ -1387,11 +1248,7 @@
6277N/A }
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- scard_conn_ret = cackey_reconnect_card(slot, protocol, &protocol);
6277N/A-=======
6277N/A scard_conn_ret = cackey_reconnect_card(slot, protocol);
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A if (scard_conn_ret != SCARD_S_SUCCESS) {
6277N/A@@ -1406,11 +1263,8 @@
6277N/A slot->protocol = protocol;
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Returning in success");
6277N/A
6277N/A->>>>>>> trunk
6277N/A return(CACKEY_PCSC_S_OK);
6277N/A }
6277N/A
6277N/A@@ -1587,12 +1441,6 @@
6277N/A * CACKEY_PCSC_E_GENERIC On error
6277N/A * CACKEY_PCSC_E_TOKENABSENT If the sending failed because the token is
6277N/A * absent
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A- * CACKEY_PCSC_E_RETRY If something that looks retry'able went
6277N/A- * wrong -- try the whole transaction over
6277N/A- * again
6277N/A->>>>>>> trunk
6277N/A *
6277N/A * NOTES
6277N/A * This function will connect to the PC/SC Connection Manager via
6277N/A@@ -1603,18 +1451,10 @@
6277N/A * goes away.
6277N/A *
6277N/A */
6277N/A-<<<<<<< HEAD
6277N/A-static cackey_ret cackey_send_apdu(struct cackey_slot *slot, unsigned char class, unsigned char instruction, unsigned char p1, unsigned char p2, unsigned char lc, unsigned char *data, unsigned char le, uint16_t *respcode, unsigned char *respdata, size_t *respdata_len) {
6277N/A- uint8_t major_rc, minor_rc;
6277N/A- size_t bytes_to_copy, tmp_respdata_len;
6277N/A- LPCSCARD_IO_REQUEST pioSendPci;
6277N/A- DWORD protocol;
6277N/A-=======
6277N/A static cackey_ret cackey_send_apdu(struct cackey_slot *slot, unsigned char class, unsigned char instruction, unsigned char p1, unsigned char p2, unsigned int lc, unsigned char *data, unsigned int le, uint16_t *respcode, unsigned char *respdata, size_t *respdata_len) {
6277N/A uint8_t major_rc, minor_rc;
6277N/A size_t bytes_to_copy, tmp_respdata_len;
6277N/A LPCSCARD_IO_REQUEST pioSendPci;
6277N/A->>>>>>> trunk
6277N/A DWORD xmit_len, recv_len;
6277N/A LONG scard_xmit_ret, scard_reconn_ret;
6277N/A BYTE xmit_buf[1024], recv_buf[1024];
6277N/A@@ -1639,20 +1479,14 @@
6277N/A /* Determine which protocol to send using */
6277N/A switch (slot->protocol) {
6277N/A case SCARD_PROTOCOL_T0:
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Protocol to send datagram is T=0");
6277N/A
6277N/A->>>>>>> trunk
6277N/A pioSendPci = SCARD_PCI_T0;
6277N/A
6277N/A break;
6277N/A case SCARD_PROTOCOL_T1:
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Protocol to send datagram is T=1");
6277N/A
6277N/A->>>>>>> trunk
6277N/A pioSendPci = SCARD_PCI_T1;
6277N/A
6277N/A break;
6277N/A@@ -1669,9 +1503,6 @@
6277N/A xmit_buf[xmit_len++] = p1;
6277N/A xmit_buf[xmit_len++] = p2;
6277N/A if (data) {
6277N/A-<<<<<<< HEAD
6277N/A- xmit_buf[xmit_len++] = lc;
6277N/A-=======
6277N/A if (lc > 255) {
6277N/A CACKEY_DEBUG_PRINTF("CAUTION! Using an Lc greater than 255 is untested. Lc = %u", lc);
6277N/A
6277N/A@@ -1681,16 +1512,12 @@
6277N/A } else {
6277N/A xmit_buf[xmit_len++] = lc;
6277N/A }
6277N/A->>>>>>> trunk
6277N/A for (idx = 0; idx < lc; idx++) {
6277N/A xmit_buf[xmit_len++] = data[idx];
6277N/A }
6277N/A }
6277N/A
6277N/A if (le != 0x00) {
6277N/A-<<<<<<< HEAD
6277N/A- xmit_buf[xmit_len++] = le;
6277N/A-=======
6277N/A if (le > 256) {
6277N/A CACKEY_DEBUG_PRINTF("CAUTION! Using an Le greater than 256 is untested. Le = %u", le);
6277N/A
6277N/A@@ -1702,17 +1529,12 @@
6277N/A } else {
6277N/A xmit_buf[xmit_len++] = le;
6277N/A }
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A /* Begin Smartcard Transaction */
6277N/A cackey_begin_transaction(slot);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- if (class == GSCIS_CLASS_ISO7816 && instruction == GSCIS_INSTR_VERIFY && p1 == 0x00 && p2 == 0x00) {
6277N/A-=======
6277N/A if (class == GSCIS_CLASS_ISO7816 && (instruction == GSCIS_INSTR_VERIFY || instruction == GSCIS_INSTR_CHANGE_REFERENCE) && p1 == 0x00) {
6277N/A->>>>>>> trunk
6277N/A CACKEY_DEBUG_PRINTF("Sending APDU: <<censored>>");
6277N/A } else {
6277N/A CACKEY_DEBUG_PRINTBUF("Sending APDU:", xmit_buf, xmit_len);
6277N/A@@ -1727,11 +1549,8 @@
6277N/A /* Begin Smartcard Transaction */
6277N/A cackey_end_transaction(slot);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A cackey_reconnect_card(slot, slot->protocol);
6277N/A
6277N/A->>>>>>> trunk
6277N/A return(CACKEY_PCSC_E_RETRY);
6277N/A }
6277N/A
6277N/A@@ -1744,17 +1563,9 @@
6277N/A if (scard_xmit_ret == SCARD_W_RESET_CARD) {
6277N/A CACKEY_DEBUG_PRINTF("Reset required, please hold...");
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &protocol);
6277N/A-
6277N/A- if (scard_reconn_ret == SCARD_S_SUCCESS) {
6277N/A- /* Update protocol */
6277N/A- slot->protocol = protocol;
6277N/A-=======
6277N/A scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1);
6277N/A
6277N/A if (scard_reconn_ret == SCARD_S_SUCCESS) {
6277N/A->>>>>>> trunk
6277N/A switch (slot->protocol) {
6277N/A case SCARD_PROTOCOL_T0:
6277N/A pioSendPci = SCARD_PCI_T0;
6277N/A@@ -1831,16 +1642,7 @@
6277N/A /* End Smartcard Transaction */
6277N/A cackey_end_transaction(slot);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A return(CACKEY_PCSC_E_GENERIC);
6277N/A-=======
6277N/A- /* Supply an invalid response code */
6277N/A- if (respcode) {
6277N/A- *respcode = 0;
6277N/A- }
6277N/A-
6277N/A- return(CACKEY_PCSC_E_NODATA);
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A /* Determine result code */
6277N/A@@ -1927,8 +1729,6 @@
6277N/A return(CACKEY_PCSC_E_GENERIC);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A static unsigned char *cackey_read_bertlv_tag(unsigned char *buffer, size_t *buffer_len_p, unsigned char tag, unsigned char *outbuffer, size_t *outbuffer_len_p) {
6277N/A unsigned char *buffer_p;
6277N/A size_t outbuffer_len, buffer_len;
6277N/A@@ -2106,7 +1906,6 @@
6277N/A return(size);
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A /*
6277N/A * SYNPOSIS
6277N/A * ssize_t cackey_read_buffer(struct cackey_slot *slot, unsigned char *buffer, size_t count, unsigned char t_or_v, size_t initial_offset);
6277N/A@@ -2584,8 +2383,6 @@
6277N/A return;
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A static struct cackey_pcsc_identity *cackey_copy_certs(struct cackey_pcsc_identity *dest, struct cackey_pcsc_identity *start, size_t count) {
6277N/A size_t idx;
6277N/A
6277N/A@@ -2622,7 +2419,6 @@
6277N/A return(dest);
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A /*
6277N/A * SYNPOSIS
6277N/A * ...
6277N/A@@ -2640,14 +2436,6 @@
6277N/A static struct cackey_pcsc_identity *cackey_read_certs(struct cackey_slot *slot, struct cackey_pcsc_identity *certs, unsigned long *count) {
6277N/A struct cackey_pcsc_identity *curr_id;
6277N/A struct cackey_tlv_entity *ccc_tlv, *ccc_curr, *app_tlv, *app_curr;
6277N/A-<<<<<<< HEAD
6277N/A- unsigned char ccc_aid[] = {GSCIS_AID_CCC};
6277N/A- unsigned char curr_aid[7];
6277N/A- unsigned long outidx = 0;
6277N/A- cackey_ret transaction_ret;
6277N/A- int certs_resizable;
6277N/A- int send_ret, select_ret;
6277N/A-=======
6277N/A unsigned char ccc_aid[] = {GSCIS_AID_CCC}, piv_aid[] = {NISTSP800_73_3_PIV_AID};
6277N/A unsigned char *piv_oid, piv_oid_pivauth[] = {NISTSP800_73_3_OID_PIVAUTH}, piv_oid_signature[] = {NISTSP800_73_3_OID_SIGNATURE}, piv_oid_keymgt[] = {NISTSP800_73_3_OID_KEYMGT};
6277N/A unsigned char curr_aid[7];
6277N/A@@ -2665,7 +2453,6 @@
6277N/A int uncompress_ret;
6277N/A z_stream gzip_stream;
6277N/A #endif
6277N/A->>>>>>> trunk
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Called.");
6277N/A
6277N/A@@ -2683,8 +2470,6 @@
6277N/A }
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A if (!slot->slot_reset) {
6277N/A if (slot->cached_certs) {
6277N/A if (certs == NULL) {
6277N/A@@ -2708,7 +2493,6 @@
6277N/A slot->cached_certs = NULL;
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A /* Begin a SmartCard transaction */
6277N/A transaction_ret = cackey_begin_transaction(slot);
6277N/A if (transaction_ret != CACKEY_PCSC_S_OK) {
6277N/A@@ -2717,7 +2501,6 @@
6277N/A return(NULL);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A if (certs == NULL) {
6277N/A certs = malloc(sizeof(*certs) * 5);
6277N/A *count = 5;
6277N/A@@ -2729,68 +2512,6 @@
6277N/A /* Select the CCC Applet */
6277N/A send_ret = cackey_select_applet(slot, ccc_aid, sizeof(ccc_aid));
6277N/A if (send_ret != CACKEY_PCSC_S_OK) {
6277N/A- CACKEY_DEBUG_PRINTF("Unable to select CCC Applet, returning in failure");
6277N/A-
6277N/A- /* Terminate SmartCard Transaction */
6277N/A- cackey_end_transaction(slot);
6277N/A-
6277N/A- return(NULL);
6277N/A- }
6277N/A-
6277N/A- /* Read all the applets from the CCC's TLV */
6277N/A- ccc_tlv = cackey_read_tlv(slot);
6277N/A-
6277N/A- /* Look for CARDURLs that coorespond to PKI applets */
6277N/A- for (ccc_curr = ccc_tlv; ccc_curr; ccc_curr = ccc_curr->_next) {
6277N/A- CACKEY_DEBUG_PRINTF("Found tag: %s ... ", CACKEY_DEBUG_FUNC_TAG_TO_STR(ccc_curr->tag));
6277N/A-
6277N/A- if (ccc_curr->tag != GSCIS_TAG_CARDURL) {
6277N/A- CACKEY_DEBUG_PRINTF(" ... skipping it (we only care about CARDURLs)");
6277N/A-
6277N/A- continue;
6277N/A- }
6277N/A-
6277N/A- if ((ccc_curr->value_cardurl->apptype & CACKEY_TLV_APP_PKI) != CACKEY_TLV_APP_PKI) {
6277N/A- CACKEY_DEBUG_PRINTF(" ... skipping it (we only care about PKI applets, this applet supports: %s/%02x)", CACKEY_DEBUG_FUNC_APPTYPE_TO_STR(ccc_curr->value_cardurl->apptype), (unsigned int) ccc_curr->value_cardurl->apptype);
6277N/A-
6277N/A- continue;
6277N/A- }
6277N/A-
6277N/A- CACKEY_DEBUG_PRINTBUF("RID:", ccc_curr->value_cardurl->rid, sizeof(ccc_curr->value_cardurl->rid));
6277N/A- CACKEY_DEBUG_PRINTF("AppID = %s/%04lx", CACKEY_DEBUG_FUNC_OBJID_TO_STR(ccc_curr->value_cardurl->appid), (unsigned long) ccc_curr->value_cardurl->appid);
6277N/A- CACKEY_DEBUG_PRINTF("ObjectID = %s/%04lx", CACKEY_DEBUG_FUNC_OBJID_TO_STR(ccc_curr->value_cardurl->objectid), (unsigned long) ccc_curr->value_cardurl->objectid);
6277N/A-
6277N/A- memcpy(curr_aid, ccc_curr->value_cardurl->rid, sizeof(ccc_curr->value_cardurl->rid));
6277N/A- curr_aid[sizeof(curr_aid) - 2] = (ccc_curr->value_cardurl->appid >> 8) & 0xff;
6277N/A- curr_aid[sizeof(curr_aid) - 1] = ccc_curr->value_cardurl->appid & 0xff;
6277N/A-
6277N/A- /* Select found applet ... */
6277N/A- select_ret = cackey_select_applet(slot, curr_aid, sizeof(curr_aid));
6277N/A- if (select_ret != CACKEY_PCSC_S_OK) {
6277N/A- CACKEY_DEBUG_PRINTF("Failed to select applet, skipping processing of this object");
6277N/A-
6277N/A- continue;
6277N/A- }
6277N/A-
6277N/A- /* ... and object (file) */
6277N/A- select_ret = cackey_select_file(slot, ccc_curr->value_cardurl->objectid);
6277N/A- if (select_ret != CACKEY_PCSC_S_OK) {
6277N/A- CACKEY_DEBUG_PRINTF("Failed to select file, skipping processing of this object");
6277N/A-
6277N/A- continue;
6277N/A- }
6277N/A-
6277N/A- /* Process this file's TLV looking for certificates */
6277N/A- app_tlv = cackey_read_tlv(slot);
6277N/A-
6277N/A- for (app_curr = app_tlv; app_curr; app_curr = app_curr->_next) {
6277N/A- CACKEY_DEBUG_PRINTF("Found tag: %s", CACKEY_DEBUG_FUNC_TAG_TO_STR(app_curr->tag));
6277N/A- if (app_curr->tag != GSCIS_TAG_CERTIFICATE) {
6277N/A- CACKEY_DEBUG_PRINTF(" ... skipping it (we only care about CERTIFICATEs)");
6277N/A-=======
6277N/A- /* Select the CCC Applet */
6277N/A- send_ret = cackey_select_applet(slot, ccc_aid, sizeof(ccc_aid));
6277N/A- if (send_ret != CACKEY_PCSC_S_OK) {
6277N/A /* Try PIV application */
6277N/A send_ret = cackey_select_applet(slot, piv_aid, sizeof(piv_aid));
6277N/A if (send_ret == CACKEY_PCSC_S_OK) {
6277N/A@@ -2803,22 +2524,10 @@
6277N/A /* Terminate SmartCard Transaction */
6277N/A cackey_end_transaction(slot);
6277N/A
6277N/A- if (certs == NULL) {
6277N/A- *count = 0;
6277N/A- }
6277N/A-
6277N/A return(NULL);
6277N/A }
6277N/A }
6277N/A
6277N/A- if (certs == NULL) {
6277N/A- certs = malloc(sizeof(*certs) * 5);
6277N/A- *count = 5;
6277N/A- certs_resizable = 1;
6277N/A- } else {
6277N/A- certs_resizable = 0;
6277N/A- }
6277N/A-
6277N/A if (piv) {
6277N/A for (idx = 0; idx < 3; idx++) {
6277N/A switch (idx) {
6277N/A@@ -2867,46 +2576,10 @@
6277N/A curr_id->certificate = NULL;
6277N/A
6277N/A outidx--;
6277N/A->>>>>>> trunk
6277N/A
6277N/A continue;
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- curr_id = &certs[outidx];
6277N/A- outidx++;
6277N/A-
6277N/A- memcpy(curr_id->applet, curr_aid, sizeof(curr_id->applet));
6277N/A- curr_id->file = ccc_curr->value_cardurl->objectid;
6277N/A- curr_id->keysize = -1;
6277N/A-
6277N/A- CACKEY_DEBUG_PRINTF("Filling curr_id->applet (%p) with %lu bytes:", curr_id->applet, (unsigned long) sizeof(curr_id->applet));
6277N/A- CACKEY_DEBUG_PRINTBUF("VAL:", curr_id->applet, sizeof(curr_id->applet));
6277N/A-
6277N/A- curr_id->certificate_len = app_curr->length;
6277N/A-
6277N/A- curr_id->certificate = malloc(curr_id->certificate_len);
6277N/A- memcpy(curr_id->certificate, app_curr->value, curr_id->certificate_len);
6277N/A-
6277N/A- if (outidx >= *count) {
6277N/A- if (certs_resizable) {
6277N/A- *count *= 2;
6277N/A- certs = realloc(certs, sizeof(*certs) * (*count));
6277N/A- } else {
6277N/A- break;
6277N/A- }
6277N/A- }
6277N/A- }
6277N/A-
6277N/A- cackey_free_tlv(app_tlv);
6277N/A-
6277N/A- if (outidx >= *count) {
6277N/A- break;
6277N/A- }
6277N/A- }
6277N/A-
6277N/A- cackey_free_tlv(ccc_tlv);
6277N/A-=======
6277N/A #ifdef HAVE_LIBZ
6277N/A if (curr_id->certificate_len > 4) {
6277N/A if (memcmp(curr_id->certificate, "\x1f\x8b\x08\x00", 4) == 0) {
6277N/A@@ -3048,21 +2721,13 @@
6277N/A
6277N/A cackey_free_tlv(ccc_tlv);
6277N/A }
6277N/A->>>>>>> trunk
6277N/A
6277N/A *count = outidx;
6277N/A
6277N/A if (certs_resizable) {
6277N/A-<<<<<<< HEAD
6277N/A- certs = realloc(certs, sizeof(*certs) * (*count));
6277N/A- }
6277N/A-
6277N/A-=======
6277N/A if (*count != 0) {
6277N/A certs = realloc(certs, sizeof(*certs) * (*count));
6277N/A } else {
6277N/A- free(certs);
6277N/A-
6277N/A certs = NULL;
6277N/A }
6277N/A }
6277N/A@@ -3070,7 +2735,6 @@
6277N/A slot->cached_certs = cackey_copy_certs(NULL, certs, *count);
6277N/A slot->cached_certs_count = *count;
6277N/A
6277N/A->>>>>>> trunk
6277N/A /* Terminate SmartCard Transaction */
6277N/A cackey_end_transaction(slot);
6277N/A
6277N/A@@ -3092,24 +2756,15 @@
6277N/A *
6277N/A */
6277N/A static ssize_t cackey_signdecrypt(struct cackey_slot *slot, struct cackey_identity *identity, unsigned char *buf, size_t buflen, unsigned char *outbuf, size_t outbuflen, int padInput, int unpadOutput) {
6277N/A-<<<<<<< HEAD
6277N/A- unsigned char *tmpbuf, *tmpbuf_s, *outbuf_s;
6277N/A- unsigned char bytes_to_send, p1;
6277N/A-=======
6277N/A cackey_pcsc_id_type id_type;
6277N/A unsigned char dyn_auth_template[10], *dyn_auth_tmpbuf;
6277N/A unsigned char *tmpbuf, *tmpbuf_s, *outbuf_s, *outbuf_p;
6277N/A unsigned char bytes_to_send, p1, class;
6277N/A->>>>>>> trunk
6277N/A unsigned char blocktype;
6277N/A cackey_ret send_ret;
6277N/A uint16_t respcode;
6277N/A ssize_t retval = 0, unpadoffset;
6277N/A-<<<<<<< HEAD
6277N/A- size_t tmpbuflen, padlen, tmpoutbuflen;
6277N/A-=======
6277N/A size_t tmpbuflen, padlen, tmpoutbuflen, outbuf_len;
6277N/A->>>>>>> trunk
6277N/A int free_tmpbuf = 0;
6277N/A int le;
6277N/A
6277N/A@@ -3145,8 +2800,6 @@
6277N/A return(-1);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A id_type = identity->pcsc_identity->id_type;
6277N/A if (id_type == CACKEY_ID_TYPE_CERT_ONLY) {
6277N/A CACKEY_DEBUG_PRINTF("Error. identity->pcsc_identity is CACKEY_ID_TYPE_CERT_ONLY, which cannot be used for sign/decrypt");
6277N/A@@ -3164,7 +2817,6 @@
6277N/A return(-1);
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A /* Determine identity Key size */
6277N/A if (identity->pcsc_identity->keysize < 0) {
6277N/A identity->pcsc_identity->keysize = x509_to_keysize(identity->pcsc_identity->certificate, identity->pcsc_identity->certificate_len);
6277N/A@@ -3174,11 +2826,7 @@
6277N/A if (padInput) {
6277N/A if (identity->pcsc_identity->keysize > 0) {
6277N/A if (buflen != identity->pcsc_identity->keysize) {
6277N/A-<<<<<<< HEAD
6277N/A if (buflen > (identity->pcsc_identity->keysize + 3)) {
6277N/A-=======
6277N/A- if (buflen > (identity->pcsc_identity->keysize - 3)) {
6277N/A->>>>>>> trunk
6277N/A CACKEY_DEBUG_PRINTF("Error. Message is too large to sign/decrypt");
6277N/A
6277N/A return(-1);
6277N/A@@ -3190,11 +2838,6 @@
6277N/A
6277N/A padlen = tmpbuflen - buflen - 3;
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A- CACKEY_DEBUG_PRINTF("Need to pad the buffer with %llu bytes (tmpbuflen = %llu, buflen = %llu)", (unsigned long long) padlen, (unsigned long long) tmpbuflen, (unsigned long long) buflen);
6277N/A-
6277N/A->>>>>>> trunk
6277N/A /* RSA PKCS#1 EMSA-PKCS1-v1_5 Padding */
6277N/A tmpbuf[0] = 0x00;
6277N/A tmpbuf[1] = 0x01;
6277N/A@@ -3229,13 +2872,6 @@
6277N/A cackey_begin_transaction(slot);
6277N/A
6277N/A /* Select correct applet */
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTF("Selecting applet found at %p ...", identity->pcsc_identity->applet);
6277N/A- cackey_select_applet(slot, identity->pcsc_identity->applet, sizeof(identity->pcsc_identity->applet));
6277N/A-
6277N/A- /* Select correct file */
6277N/A- cackey_select_file(slot, identity->pcsc_identity->file);
6277N/A-=======
6277N/A switch (id_type) {
6277N/A case CACKEY_ID_TYPE_CAC:
6277N/A CACKEY_DEBUG_PRINTF("Selecting applet found at %p ...", identity->pcsc_identity->card.cac.applet);
6277N/A@@ -3272,29 +2908,10 @@
6277N/A case CACKEY_ID_TYPE_CERT_ONLY:
6277N/A break;
6277N/A }
6277N/A->>>>>>> trunk
6277N/A
6277N/A tmpbuf_s = tmpbuf;
6277N/A outbuf_s = outbuf;
6277N/A while (tmpbuflen) {
6277N/A-<<<<<<< HEAD
6277N/A- if (tmpbuflen > 245) {
6277N/A- bytes_to_send = 245;
6277N/A- p1 = 0x80;
6277N/A- le = 0x00;
6277N/A- } else {
6277N/A- bytes_to_send = tmpbuflen;
6277N/A- p1 = 0x00;
6277N/A- le = 0x00;
6277N/A- }
6277N/A-
6277N/A- tmpoutbuflen = outbuflen;
6277N/A-
6277N/A- send_ret = cackey_send_apdu(slot, GSCIS_CLASS_GLOBAL_PLATFORM, GSCIS_INSTR_SIGNDECRYPT, p1, 0x00, bytes_to_send, tmpbuf, le, &respcode, outbuf, &tmpoutbuflen);
6277N/A- if (send_ret != CACKEY_PCSC_S_OK) {
6277N/A- CACKEY_DEBUG_PRINTF("ADPU Sending Failed -- returning in error.");
6277N/A-
6277N/A-=======
6277N/A tmpoutbuflen = outbuflen;
6277N/A
6277N/A if (tmpbuflen > CACKEY_APDU_MTU) {
6277N/A@@ -3332,7 +2949,6 @@
6277N/A }
6277N/A
6277N/A if (send_ret != CACKEY_PCSC_S_OK) {
6277N/A->>>>>>> trunk
6277N/A if (free_tmpbuf) {
6277N/A if (tmpbuf_s) {
6277N/A free(tmpbuf_s);
6277N/A@@ -3342,12 +2958,6 @@
6277N/A /* End transaction */
6277N/A cackey_end_transaction(slot);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- if (respcode == 0x6982) {
6277N/A- CACKEY_DEBUG_PRINTF("Security status not satisified. Returning NEEDLOGIN");
6277N/A-
6277N/A- cackey_mark_slot_reset(slot);
6277N/A-=======
6277N/A if (send_ret == CACKEY_PCSC_E_RETRY) {
6277N/A CACKEY_DEBUG_PRINTF("ADPU Sending Failed -- retrying.");
6277N/A
6277N/A@@ -3365,7 +2975,6 @@
6277N/A
6277N/A cackey_mark_slot_reset(slot);
6277N/A
6277N/A->>>>>>> trunk
6277N/A slot->token_flags = CKF_LOGIN_REQUIRED;
6277N/A
6277N/A return(CACKEY_PCSC_E_NEEDLOGIN);
6277N/A@@ -3375,23 +2984,11 @@
6277N/A CACKEY_DEBUG_PRINTF("Token absent. Returning TOKENABSENT");
6277N/A
6277N/A cackey_mark_slot_reset(slot);
6277N/A-<<<<<<< HEAD
6277N/A- slot->token_flags = CKF_LOGIN_REQUIRED;
6277N/A-=======
6277N/A->>>>>>> trunk
6277N/A
6277N/A return(CACKEY_PCSC_E_TOKENABSENT);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A return(-1);
6277N/A-=======
6277N/A- CACKEY_DEBUG_PRINTF("Something went wrong during signing, resetting the slot and hoping for the best.");
6277N/A-
6277N/A- cackey_mark_slot_reset(slot);
6277N/A-
6277N/A- return(CACKEY_PCSC_E_GENERIC);
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A tmpbuf += bytes_to_send;
6277N/A@@ -3423,8 +3020,6 @@
6277N/A # endif
6277N/A #endif
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A /* We must remove the "7C" tag to get to the signature */
6277N/A switch (id_type) {
6277N/A case CACKEY_ID_TYPE_PIV:
6277N/A@@ -3454,7 +3049,6 @@
6277N/A break;
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A /* Unpad reply */
6277N/A if (unpadOutput) {
6277N/A if (retval < 3) {
6277N/A@@ -3549,90 +3143,20 @@
6277N/A * ...
6277N/A *
6277N/A */
6277N/A-<<<<<<< HEAD
6277N/A-static cackey_ret cackey_login(struct cackey_slot *slot, unsigned char *pin, unsigned long pin_len, int *tries_remaining_p) {
6277N/A- unsigned char cac_pin[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
6277N/A- uint16_t response_code;
6277N/A- int tries_remaining;
6277N/A- int send_ret;
6277N/A-
6277N/A- /* Indicate that we do not know about how many tries are remaining */
6277N/A- if (tries_remaining_p) {
6277N/A- *tries_remaining_p = -1;
6277N/A- }
6277N/A-
6277N/A- /* Apparently, CAC PINs are *EXACTLY* 8 bytes long -- pad with 0xFF if too short */
6277N/A- if (pin_len >= 8) {
6277N/A- memcpy(cac_pin, pin, 8);
6277N/A- } else {
6277N/A- memcpy(cac_pin, pin, pin_len);
6277N/A- }
6277N/A-
6277N/A- /* Issue PIN Verify */
6277N/A- send_ret = cackey_send_apdu(slot, GSCIS_CLASS_ISO7816, GSCIS_INSTR_VERIFY, 0x00, 0x00, sizeof(cac_pin), cac_pin, 0x00, &response_code, NULL, NULL);
6277N/A- if (send_ret != CACKEY_PCSC_S_OK) {
6277N/A- if ((response_code & 0x63C0) == 0x63C0) {
6277N/A- tries_remaining = (response_code & 0xF);
6277N/A-
6277N/A- CACKEY_DEBUG_PRINTF("PIN Verification failed, %i tries remaining", tries_remaining);
6277N/A-
6277N/A- if (tries_remaining_p) {
6277N/A- *tries_remaining_p = tries_remaining;
6277N/A- }
6277N/A-
6277N/A- return(CACKEY_PCSC_E_BADPIN);
6277N/A- }
6277N/A-
6277N/A- if (response_code == 0x6983) {
6277N/A- CACKEY_DEBUG_PRINTF("PIN Verification failed, device is locked");
6277N/A-
6277N/A- return(CACKEY_PCSC_E_LOCKED);
6277N/A- }
6277N/A-
6277N/A- return(CACKEY_PCSC_E_GENERIC);
6277N/A- }
6277N/A-
6277N/A- CACKEY_DEBUG_PRINTF("PIN Verification succeeded");
6277N/A-
6277N/A- return(CACKEY_PCSC_S_OK);
6277N/A-}
6277N/A-
6277N/A-/*
6277N/A- * SYNPOSIS
6277N/A- * ...
6277N/A- *
6277N/A- * ARGUMENTS
6277N/A- * ...
6277N/A- *
6277N/A- * RETURN VALUE
6277N/A- * ...
6277N/A- *
6277N/A- * NOTES
6277N/A- * ...
6277N/A- *
6277N/A- */
6277N/A-static cackey_ret cackey_token_present(struct cackey_slot *slot) {
6277N/A- cackey_ret pcsc_connect_ret;
6277N/A- DWORD reader_len, state, protocol, atr_len;
6277N/A-=======
6277N/A static cackey_ret cackey_token_present(struct cackey_slot *slot) {
6277N/A cackey_ret pcsc_connect_ret;
6277N/A DWORD reader_len = 0, state = 0, protocol = 0, atr_len;
6277N/A->>>>>>> trunk
6277N/A BYTE atr[MAX_ATR_SIZE];
6277N/A LONG status_ret, scard_reconn_ret;
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Called.");
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A if (slot->internal) {
6277N/A CACKEY_DEBUG_PRINTF("Returning token present (internal token)");
6277N/A
6277N/A return(CACKEY_PCSC_S_TOKENPRESENT);
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A pcsc_connect_ret = cackey_connect_card(slot);
6277N/A if (pcsc_connect_ret != CACKEY_PCSC_S_OK) {
6277N/A CACKEY_DEBUG_PRINTF("Unable to connect to card, returning token absent");
6277N/A@@ -3640,11 +3164,8 @@
6277N/A return(CACKEY_PCSC_E_TOKENABSENT);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Calling SCardStatus() to determine card status");
6277N/A
6277N/A->>>>>>> trunk
6277N/A atr_len = sizeof(atr);
6277N/A status_ret = SCardStatus(slot->pcsc_card, NULL, &reader_len, &state, &protocol, atr, &atr_len);
6277N/A
6277N/A@@ -3659,11 +3180,8 @@
6277N/A return(CACKEY_PCSC_E_TOKENABSENT);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Calling SCardStatus() again");
6277N/A
6277N/A->>>>>>> trunk
6277N/A atr_len = sizeof(atr);
6277N/A status_ret = SCardStatus(slot->pcsc_card, NULL, &reader_len, &state, &protocol, atr, &atr_len);
6277N/A }
6277N/A@@ -3674,16 +3192,8 @@
6277N/A if (status_ret == SCARD_W_RESET_CARD) {
6277N/A CACKEY_DEBUG_PRINTF("Reset required, please hold...");
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &protocol);
6277N/A- if (scard_reconn_ret == SCARD_S_SUCCESS) {
6277N/A- /* Update protocol */
6277N/A- slot->protocol = protocol;
6277N/A-
6277N/A-=======
6277N/A scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1);
6277N/A if (scard_reconn_ret == SCARD_S_SUCCESS) {
6277N/A->>>>>>> trunk
6277N/A /* Re-establish transaction, if it was present */
6277N/A if (slot->transaction_depth > 0) {
6277N/A slot->transaction_depth--;
6277N/A@@ -3735,11 +3245,6 @@
6277N/A * ...
6277N/A *
6277N/A */
6277N/A-<<<<<<< HEAD
6277N/A-static ssize_t cackey_pcsc_identity_to_label(struct cackey_pcsc_identity *identity, unsigned char *label_buf, unsigned long label_buf_len) {
6277N/A- unsigned long certificate_len;
6277N/A- char *label_asn1;
6277N/A-=======
6277N/A static cackey_ret cackey_set_pin(struct cackey_slot *slot, unsigned char *old_pin, unsigned long old_pin_len, unsigned char *pin, unsigned long pin_len) {
6277N/A struct cackey_pcsc_identity *pcsc_identities;
6277N/A unsigned char cac_pin[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
6277N/A@@ -3821,9 +3326,6 @@
6277N/A CACKEY_DEBUG_PRINTF("PIN Change succeeded");
6277N/A
6277N/A return(CACKEY_PCSC_S_OK);
6277N/A-
6277N/A- /* Disable a warning, since this is only used in debug mode */
6277N/A- tries_remaining = tries_remaining;
6277N/A }
6277N/A
6277N/A /*
6277N/A@@ -3912,9 +3414,9 @@
6277N/A }
6277N/A
6277N/A if (response_code == 0x6d00) {
6277N/A- if (retries > 0) {
6277N/A+ if (have_piv == 1 && retries > 0) {
6277N/A CACKEY_DEBUG_PRINTF("Got ISO 7816 Response \"6D 00\" in response to a VERIFY request.");
6277N/A- CACKEY_DEBUG_PRINTF("We did not expect this because it is not mentioned in NIST SP 800-73-3 Part 2 Section 3.2.1 or GSC-IS v2.1");
6277N/A+ CACKEY_DEBUG_PRINTF("We did not expect this because it is not mentioned in NIST SP 800-73-3 Part 2 Section 3.2.1");
6277N/A CACKEY_DEBUG_PRINTF("We are going to try to reset the card and select the applet again.");
6277N/A
6277N/A cackey_mark_slot_reset(slot);
6277N/A@@ -3965,7 +3467,6 @@
6277N/A static ssize_t cackey_pcsc_identity_to_label(struct cackey_pcsc_identity *identity, unsigned char *label_buf, unsigned long label_buf_len) {
6277N/A unsigned long certificate_len;
6277N/A void *label_asn1;
6277N/A->>>>>>> trunk
6277N/A void *certificate;
6277N/A int x509_read_ret;
6277N/A
6277N/A@@ -4241,15 +3742,6 @@
6277N/A case CKA_LABEL:
6277N/A CACKEY_DEBUG_PRINTF("Requesting attribute CKA_LABEL (0x%08lx) ...", (unsigned long) curr_attr_type);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- /* XXX: Determine name */
6277N/A- ulValueLen = snprintf((char *) ucTmpBuf, sizeof(ucTmpBuf), "Identity #%lu", (unsigned long) identity_num);
6277N/A- pValue = ucTmpBuf;
6277N/A-
6277N/A- if (ulValueLen >= sizeof(ucTmpBuf)) {
6277N/A- ulValueLen = 0;
6277N/A- pValue = NULL;
6277N/A-=======
6277N/A if (identity->id_type == CACKEY_ID_TYPE_PIV) {
6277N/A pValue = identity->card.piv.label;
6277N/A ulValueLen = strlen(pValue);
6277N/A@@ -4261,7 +3753,6 @@
6277N/A ulValueLen = 0;
6277N/A pValue = NULL;
6277N/A }
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A CACKEY_DEBUG_PRINTF(" ... returning (%p/%lu)", pValue, (unsigned long) ulValueLen);
6277N/A@@ -4650,11 +4141,7 @@
6277N/A
6277N/A *pulCount = numattrs;
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTF("Returning %lu objects (%p).", numattrs, retval);
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Returning %lu objects (%p).", numattrs, (void *) retval);
6277N/A->>>>>>> trunk
6277N/A
6277N/A return(retval);
6277N/A }
6277N/A@@ -4688,8 +4175,6 @@
6277N/A free(identities);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A static unsigned long cackey_read_dod_identities(struct cackey_identity *identities, unsigned long num_dod_certs) {
6277N/A unsigned long cert_idx, id_idx = 0;
6277N/A
6277N/A@@ -4714,36 +4199,10 @@
6277N/A return(id_idx);
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A static struct cackey_identity *cackey_read_identities(struct cackey_slot *slot, unsigned long *ids_found) {
6277N/A struct cackey_pcsc_identity *pcsc_identities;
6277N/A struct cackey_identity *identities;
6277N/A unsigned long num_ids, id_idx, curr_id_type;
6277N/A-<<<<<<< HEAD
6277N/A- unsigned long num_certs, num_extra_certs, cert_idx;
6277N/A- int include_extra_certs = 1;
6277N/A-
6277N/A- CACKEY_DEBUG_PRINTF("Called.");
6277N/A-
6277N/A- if (getenv("CACKEY_NO_EXTRA_CERTS") != NULL) {
6277N/A- CACKEY_DEBUG_PRINTF("Asked not to include extra (DoD) certificates");
6277N/A-
6277N/A- include_extra_certs = 0;
6277N/A- }
6277N/A-
6277N/A- if (include_extra_certs) {
6277N/A- num_extra_certs = sizeof(extra_certs) / sizeof(extra_certs[0]);
6277N/A-
6277N/A- CACKEY_DEBUG_PRINTF("Including %i DoD Certificates as objects on this token", num_extra_certs);
6277N/A- } else {
6277N/A- num_extra_certs = 0;
6277N/A- }
6277N/A-
6277N/A- if (ids_found == NULL) {
6277N/A- CACKEY_DEBUG_PRINTF("Error. ids_found is NULL");
6277N/A-
6277N/A- return(NULL);
6277N/A-=======
6277N/A unsigned long num_certs, num_dod_certs, cert_idx;
6277N/A int include_extra_certs = 0, include_dod_certs;
6277N/A
6277N/A@@ -4801,21 +4260,16 @@
6277N/A *ids_found = num_ids;
6277N/A
6277N/A return(identities);
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A pcsc_identities = cackey_read_certs(slot, NULL, &num_certs);
6277N/A if (pcsc_identities != NULL) {
6277N/A /* Convert number of Certs to number of objects */
6277N/A num_ids = (CKO_PRIVATE_KEY - CKO_CERTIFICATE + 1) * num_certs;
6277N/A-<<<<<<< HEAD
6277N/A- num_ids += num_extra_certs * 3;
6277N/A-=======
6277N/A
6277N/A if (include_extra_certs) {
6277N/A num_ids += cackey_read_dod_identities(NULL, num_dod_certs);
6277N/A }
6277N/A->>>>>>> trunk
6277N/A
6277N/A identities = malloc(num_ids * sizeof(*identities));
6277N/A
6277N/A@@ -4835,29 +4289,6 @@
6277N/A }
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- cackey_free_certs(pcsc_identities, num_certs, 1);
6277N/A-
6277N/A- /* Add DoD Certificates and Netscape Trust Objects */
6277N/A- for (cert_idx = 0; cert_idx < num_extra_certs; cert_idx++) {
6277N/A- identities[id_idx].pcsc_identity = NULL;
6277N/A- identities[id_idx].attributes = cackey_get_attributes(CKO_CERTIFICATE, &extra_certs[cert_idx], 0xf000 | cert_idx, &identities[id_idx].attributes_count);
6277N/A- id_idx++;
6277N/A-
6277N/A- identities[id_idx].pcsc_identity = NULL;
6277N/A- identities[id_idx].attributes = cackey_get_attributes(CKO_PUBLIC_KEY, &extra_certs[cert_idx], 0xf000 | cert_idx, &identities[id_idx].attributes_count);
6277N/A- id_idx++;
6277N/A-
6277N/A- identities[id_idx].pcsc_identity = NULL;
6277N/A- identities[id_idx].attributes = cackey_get_attributes(CKO_NETSCAPE_TRUST, &extra_certs[cert_idx], 0xf000 | cert_idx, &identities[id_idx].attributes_count);
6277N/A- id_idx++;
6277N/A- }
6277N/A-
6277N/A- *ids_found = num_ids;
6277N/A- return(identities);
6277N/A- }
6277N/A-
6277N/A-=======
6277N/A if (include_extra_certs) {
6277N/A CACKEY_DEBUG_PRINTF("Including US Government Certificates on hardware slot");
6277N/A
6277N/A@@ -4872,17 +4303,10 @@
6277N/A }
6277N/A
6277N/A
6277N/A->>>>>>> trunk
6277N/A *ids_found = 0;
6277N/A return(NULL);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(CK_VOID_PTR pInitArgs) {
6277N/A- CK_C_INITIALIZE_ARGS CK_PTR args;
6277N/A- uint32_t idx;
6277N/A- int mutex_init_ret;
6277N/A-=======
6277N/A static cackey_ret cackey_get_pin(char *pinbuf) {
6277N/A FILE *pinfd;
6277N/A char *fgets_ret;
6277N/A@@ -4941,7 +4365,6 @@
6277N/A uint32_t idx, highest_slot;
6277N/A int mutex_init_ret;
6277N/A int include_dod_certs;
6277N/A->>>>>>> trunk
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Called.");
6277N/A
6277N/A@@ -4982,8 +4405,6 @@
6277N/A cackey_slots[idx].slot_reset = 0;
6277N/A cackey_slots[idx].token_flags = 0;
6277N/A cackey_slots[idx].label = NULL;
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A cackey_slots[idx].internal = 0;
6277N/A }
6277N/A
6277N/A@@ -5013,7 +4434,6 @@
6277N/A cackey_slots[highest_slot].label = (unsigned char *) "US Government Certificates";
6277N/A cackey_slots[highest_slot].pcsc_reader = "CACKey";
6277N/A cackey_slots[highest_slot].token_flags = 0;
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A cackey_initialized = 1;
6277N/A@@ -5030,56 +4450,25 @@
6277N/A cackey_biglock_init = 1;
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A /* Define a command to prompt user for a PIN */
6277N/A #ifdef CACKEY_PIN_COMMAND_DEFAULT
6277N/A- cackey_pin_command = strdup(CACKEY_MACRO_DEFAULT_XSTR(CACKEY_PIN_COMMAND_DEFAULT));
6277N/A+ cackey_pin_command = CACKEY_PIN_COMMAND_DEFAULT_XSTR(CACKEY_PIN_COMMAND_DEFAULT);
6277N/A #endif
6277N/A
6277N/A #ifdef CACKEY_PIN_COMMAND_XONLY_DEFAULT
6277N/A if (getenv("DISPLAY") != NULL) {
6277N/A- cackey_pin_command = strdup(CACKEY_MACRO_DEFAULT_XSTR(CACKEY_PIN_COMMAND_XONLY_DEFAULT));
6277N/A+ cackey_pin_command = CACKEY_PIN_COMMAND_DEFAULT_XSTR(CACKEY_PIN_COMMAND_XONLY_DEFAULT);
6277N/A }
6277N/A #endif
6277N/A
6277N/A if (getenv("CACKEY_PIN_COMMAND") != NULL) {
6277N/A- cackey_pin_command = strdup(getenv("CACKEY_PIN_COMMAND"));
6277N/A+ cackey_pin_command = getenv("CACKEY_PIN_COMMAND");
6277N/A }
6277N/A
6277N/A if (getenv("CACKEY_PIN_COMMAND_XONLY") != NULL && getenv("DISPLAY") != NULL) {
6277N/A- cackey_pin_command = strdup(getenv("CACKEY_PIN_COMMAND_XONLY"));
6277N/A+ cackey_pin_command = getenv("CACKEY_PIN_COMMAND_XONLY");
6277N/A }
6277N/A
6277N/A-#ifdef CACKEY_READERS_INCLUDE_ONLY_DEFAULT
6277N/A- cackey_readers_include_only = strdup(CACKEY_MACRO_DEFAULT_XSTR(CACKEY_READERS_INCLUDE_ONLY_DEFAULT));
6277N/A-#endif
6277N/A-
6277N/A-#ifdef CACKEY_READERS_EXCLUDE_DEFAULT
6277N/A- cackey_readers_exclude = strdup(CACKEY_MACRO_DEFAULT_XSTR(CACKEY_READERS_EXCLUDE_DEFAULT));
6277N/A-#endif
6277N/A-
6277N/A- if (getenv("CACKEY_READERS_INCLUDE_ONLY") != NULL) {
6277N/A- cackey_readers_include_only = strdup(getenv("CACKEY_READERS_INCLUDE_ONLY"));
6277N/A-
6277N/A- if (cackey_readers_include_only[0] == '\0') {
6277N/A- free(cackey_readers_include_only);
6277N/A-
6277N/A- cackey_readers_include_only = NULL;
6277N/A- }
6277N/A- }
6277N/A-
6277N/A- if (getenv("CACKEY_READERS_EXCLUDE") != NULL) {
6277N/A- cackey_readers_exclude = strdup(getenv("CACKEY_READERS_EXCLUDE"));
6277N/A-
6277N/A- if (cackey_readers_exclude[0] == '\0') {
6277N/A- free(cackey_readers_exclude);
6277N/A-
6277N/A- cackey_readers_exclude = NULL;
6277N/A- }
6277N/A- }
6277N/A-
6277N/A->>>>>>> trunk
6277N/A CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK);
6277N/A
6277N/A return(CKR_OK);
6277N/A@@ -5108,17 +4497,6 @@
6277N/A }
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- cackey_slots_disconnect_all();
6277N/A-
6277N/A- for (idx = 0; idx < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); idx++) {
6277N/A- if (cackey_slots[idx].pcsc_reader) {
6277N/A- free(cackey_slots[idx].pcsc_reader);
6277N/A- }
6277N/A- }
6277N/A-
6277N/A- cackey_pcsc_disconnect();
6277N/A-=======
6277N/A cackey_slots_disconnect_all();
6277N/A
6277N/A for (idx = 0; idx < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); idx++) {
6277N/A@@ -5139,25 +4517,6 @@
6277N/A
6277N/A cackey_pcsc_disconnect();
6277N/A
6277N/A- if (cackey_pin_command != NULL) {
6277N/A- free(cackey_pin_command);
6277N/A-
6277N/A- cackey_pin_command = NULL;
6277N/A- }
6277N/A-
6277N/A- if (cackey_readers_include_only != NULL) {
6277N/A- free(cackey_readers_include_only);
6277N/A-
6277N/A- cackey_readers_include_only = NULL;
6277N/A- }
6277N/A-
6277N/A- if (cackey_readers_exclude != NULL) {
6277N/A- free(cackey_readers_exclude);
6277N/A-
6277N/A- cackey_readers_exclude = NULL;
6277N/A- }
6277N/A->>>>>>> trunk
6277N/A-
6277N/A cackey_initialized = 0;
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK);
6277N/A@@ -5206,27 +4565,15 @@
6277N/A * Process list of readers, and create mapping between reader name and slot ID
6277N/A */
6277N/A CK_DEFINE_FUNCTION(CK_RV, C_GetSlotList)(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, CK_ULONG_PTR pulCount) {
6277N/A-<<<<<<< HEAD
6277N/A- int mutex_retval;
6277N/A- int pcsc_connect_ret;
6277N/A- CK_ULONG count, slot_count = 0, currslot;
6277N/A- char *pcsc_readers, *pcsc_readers_s, *pcsc_readers_e;
6277N/A- DWORD pcsc_readers_len;
6277N/A- LONG scard_listreaders_ret;
6277N/A- size_t curr_reader_len;
6277N/A-=======
6277N/A static int first_call = 1;
6277N/A int mutex_retval;
6277N/A int pcsc_connect_ret;
6277N/A CK_ULONG count, slot_count = 0, currslot, slot_idx;
6277N/A char *pcsc_readers, *pcsc_readers_s, *pcsc_readers_e;
6277N/A- char *reader_check_pattern;
6277N/A DWORD pcsc_readers_len;
6277N/A LONG scard_listreaders_ret;
6277N/A size_t curr_reader_len;
6277N/A int slot_reset;
6277N/A- int include_reader;
6277N/A->>>>>>> trunk
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Called.");
6277N/A
6277N/A@@ -5250,28 +4597,6 @@
6277N/A }
6277N/A
6277N/A /* Clear list of slots */
6277N/A-<<<<<<< HEAD
6277N/A- if (pSlotList) {
6277N/A- CACKEY_DEBUG_PRINTF("Purging all slot information.");
6277N/A-
6277N/A- /* Only update the list of slots if we are actually being supply the slot information */
6277N/A- cackey_slots_disconnect_all();
6277N/A-
6277N/A- for (currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) {
6277N/A- if (cackey_slots[currslot].pcsc_reader) {
6277N/A- free(cackey_slots[currslot].pcsc_reader);
6277N/A-
6277N/A- cackey_slots[currslot].pcsc_reader = NULL;
6277N/A- }
6277N/A-
6277N/A- if (cackey_slots[currslot].label) {
6277N/A- free(cackey_slots[currslot].label);
6277N/A-
6277N/A- cackey_slots[currslot].label = NULL;
6277N/A- }
6277N/A-
6277N/A- cackey_slots[currslot].active = 0;
6277N/A-=======
6277N/A slot_reset = 0;
6277N/A if (pSlotList) {
6277N/A if (first_call) {
6277N/A@@ -5324,16 +4649,12 @@
6277N/A }
6277N/A } else {
6277N/A
6277N/A->>>>>>> trunk
6277N/A }
6277N/A }
6277N/A
6277N/A /* Determine list of readers */
6277N/A pcsc_connect_ret = cackey_pcsc_connect();
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A /* XXX: CAN HANG HERE ! */
6277N/A->>>>>>> trunk
6277N/A if (pcsc_connect_ret != CACKEY_PCSC_S_OK) {
6277N/A CACKEY_DEBUG_PRINTF("Connection to PC/SC failed, assuming no slots");
6277N/A
6277N/A@@ -5364,9 +4685,6 @@
6277N/A /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */
6277N/A /* Bug 594911: https://bugzilla.redhat.com/show_bug.cgi?id=594911 */
6277N/A currslot = 1;
6277N/A-<<<<<<< HEAD
6277N/A- while (pcsc_readers < pcsc_readers_e) {
6277N/A-=======
6277N/A slot_count = 0;
6277N/A while (pcsc_readers < pcsc_readers_e) {
6277N/A /* Find next available slot */
6277N/A@@ -5376,7 +4694,6 @@
6277N/A }
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A curr_reader_len = strlen(pcsc_readers);
6277N/A
6277N/A if ((pcsc_readers + curr_reader_len) > pcsc_readers_e) {
6277N/A@@ -5393,55 +4710,8 @@
6277N/A break;
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTF("Found reader: %s", pcsc_readers);
6277N/A-
6277N/A- /* Only update the list of slots if we are actually being asked supply the slot information */
6277N/A- if (pSlotList) {
6277N/A- cackey_slots[currslot].active = 1;
6277N/A- cackey_slots[currslot].pcsc_reader = strdup(pcsc_readers);
6277N/A- cackey_slots[currslot].pcsc_card_connected = 0;
6277N/A- cackey_slots[currslot].transaction_depth = 0;
6277N/A- cackey_slots[currslot].transaction_need_hw_lock = 0;
6277N/A- cackey_slots[currslot].slot_reset = 1;
6277N/A- cackey_slots[currslot].token_flags = CKF_LOGIN_REQUIRED;
6277N/A- cackey_slots[currslot].label = NULL;
6277N/A-
6277N/A- cackey_mark_slot_reset(&cackey_slots[currslot]);
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Found reader: %s (currslot = %lu)", pcsc_readers, (unsigned long) currslot);
6277N/A
6277N/A- if (cackey_readers_include_only != NULL) {
6277N/A- CACKEY_DEBUG_PRINTF("Asked to include only readers matching: %s", cackey_readers_include_only);
6277N/A-
6277N/A- include_reader = 0;
6277N/A- reader_check_pattern = cackey_readers_include_only;
6277N/A- } else if (cackey_readers_exclude != NULL) {
6277N/A- CACKEY_DEBUG_PRINTF("Asked to exclude readers matching: %s", cackey_readers_exclude);
6277N/A-
6277N/A- include_reader = 1;
6277N/A- reader_check_pattern = cackey_readers_exclude;
6277N/A- } else {
6277N/A- include_reader = 1;
6277N/A- reader_check_pattern = NULL;
6277N/A- }
6277N/A-
6277N/A- if (reader_check_pattern != NULL) {
6277N/A- if (strstr(pcsc_readers, reader_check_pattern) != NULL) {
6277N/A- CACKEY_DEBUG_PRINTF("This reader matched the pattern.");
6277N/A-
6277N/A- include_reader = !include_reader;
6277N/A- }
6277N/A- }
6277N/A-
6277N/A- if (include_reader != 1) {
6277N/A- CACKEY_DEBUG_PRINTF("Skipping this reader.");
6277N/A-
6277N/A- pcsc_readers += curr_reader_len + 1;
6277N/A-
6277N/A- continue;
6277N/A- }
6277N/A-
6277N/A /* Only update the list of slots if we are actually being asked supply the slot information */
6277N/A if (pSlotList) {
6277N/A if (slot_reset) {
6277N/A@@ -5467,28 +4737,18 @@
6277N/A
6277N/A slot_count++;
6277N/A }
6277N/A->>>>>>> trunk
6277N/A }
6277N/A currslot++;
6277N/A
6277N/A pcsc_readers += curr_reader_len + 1;
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */
6277N/A- /* Bug 594911: https://bugzilla.redhat.com/show_bug.cgi?id=594911 */
6277N/A- if (currslot > 1) {
6277N/A- /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */
6277N/A- /* Bug 594911: https://bugzilla.redhat.com/show_bug.cgi?id=594911 */
6277N/A- slot_count = currslot - 1;
6277N/A-=======
6277N/A for (currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) {
6277N/A if (cackey_slots[currslot].active) {
6277N/A CACKEY_DEBUG_PRINTF("Found active slot %lu, reader = %s", (unsigned long) currslot, cackey_slots[currslot].pcsc_reader);
6277N/A
6277N/A slot_count++;
6277N/A }
6277N/A->>>>>>> trunk
6277N/A }
6277N/A } else {
6277N/A CACKEY_DEBUG_PRINTF("Second call to SCardListReaders failed, return %s/%li", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_listreaders_ret), (long) scard_listreaders_ret);
6277N/A@@ -5519,15 +4779,6 @@
6277N/A if (count < slot_count) {
6277N/A CACKEY_DEBUG_PRINTF("Error. User allocated %lu entries, but we have %lu entries.", count, slot_count);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- return(CKR_BUFFER_TOO_SMALL);
6277N/A- }
6277N/A-
6277N/A- for (currslot = 0; currslot < slot_count; currslot++) {
6277N/A- /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */
6277N/A- /* Bug 594911: https://bugzilla.redhat.com/show_bug.cgi?id=594911 */
6277N/A- pSlotList[currslot] = currslot + 1;
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Returning CKR_BUFFER_TOO_SMALL");
6277N/A
6277N/A return(CKR_BUFFER_TOO_SMALL);
6277N/A@@ -5561,7 +4812,6 @@
6277N/A CACKEY_DEBUG_PRINTF("Error. Unlocking failed.");
6277N/A
6277N/A return(CKR_GENERAL_ERROR);
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A *pulCount = slot_count;
6277N/A@@ -5613,15 +4863,11 @@
6277N/A return(CKR_SLOT_ID_INVALID);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- pInfo->flags = CKF_REMOVABLE_DEVICE | CKF_HW_SLOT;
6277N/A-=======
6277N/A pInfo->flags = CKF_HW_SLOT;
6277N/A
6277N/A if (!cackey_slots[slotID].internal) {
6277N/A pInfo->flags |= CKF_REMOVABLE_DEVICE;
6277N/A }
6277N/A->>>>>>> trunk
6277N/A
6277N/A if (cackey_token_present(&cackey_slots[slotID]) == CACKEY_PCSC_S_TOKENPRESENT) {
6277N/A pInfo->flags |= CKF_TOKEN_PRESENT;
6277N/A@@ -5764,13 +5010,10 @@
6277N/A
6277N/A pInfo->flags = CKF_WRITE_PROTECTED | CKF_USER_PIN_INITIALIZED | CKF_TOKEN_INITIALIZED | cackey_slots[slotID].token_flags;
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A if (cackey_pin_command != NULL) {
6277N/A pInfo->flags |= CKF_PROTECTED_AUTHENTICATION_PATH;
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A pInfo->ulMaxSessionCount = (sizeof(cackey_sessions) / sizeof(cackey_sessions[0])) - 1;
6277N/A pInfo->ulSessionCount = CK_UNAVAILABLE_INFORMATION;
6277N/A pInfo->ulMaxRwSessionCount = 0;
6277N/A@@ -5933,17 +5176,12 @@
6277N/A return(CKR_TOKEN_WRITE_PROTECTED);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-/* We don't support this method. */
6277N/A-CK_DEFINE_FUNCTION(CK_RV, C_SetPIN)(CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin, CK_ULONG ulOldPinLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewPinLen) {
6277N/A-=======
6277N/A CK_DEFINE_FUNCTION(CK_RV, C_SetPIN)(CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin, CK_ULONG ulOldPinLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewPinLen) {
6277N/A char oldpinbuf[64], newpinbuf[64];
6277N/A cackey_ret set_pin_ret, get_pin_ret;
6277N/A CK_SLOT_ID slotID;
6277N/A int mutex_retval;
6277N/A
6277N/A->>>>>>> trunk
6277N/A CACKEY_DEBUG_PRINTF("Called.");
6277N/A
6277N/A if (!cackey_initialized) {
6277N/A@@ -5952,11 +5190,6 @@
6277N/A return(CKR_CRYPTOKI_NOT_INITIALIZED);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTF("Returning CKR_FUNCTION_NOT_SUPPORTED (%i)", CKR_FUNCTION_NOT_SUPPORTED);
6277N/A-
6277N/A- return(CKR_FUNCTION_NOT_SUPPORTED);
6277N/A-=======
6277N/A mutex_retval = cackey_mutex_lock(cackey_biglock);
6277N/A if (mutex_retval != 0) {
6277N/A CACKEY_DEBUG_PRINTF("Error. Locking failed.");
6277N/A@@ -6091,7 +5324,6 @@
6277N/A }
6277N/A
6277N/A return(CKR_GENERAL_ERROR);
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A CK_DEFINE_FUNCTION(CK_RV, C_OpenSession)(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication, CK_NOTIFY notify, CK_SESSION_HANDLE_PTR phSession) {
6277N/A@@ -6377,15 +5609,10 @@
6277N/A return(CKR_FUNCTION_NOT_SUPPORTED);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-CK_DEFINE_FUNCTION(CK_RV, C_Login)(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) {
6277N/A- CK_SLOT_ID slotID;
6277N/A-=======
6277N/A CK_DEFINE_FUNCTION(CK_RV, _C_LoginMutexArg)(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen, int lock_mutex) {
6277N/A CK_SLOT_ID slotID;
6277N/A cackey_ret get_pin_ret;
6277N/A char pinbuf[64];
6277N/A->>>>>>> trunk
6277N/A int mutex_retval;
6277N/A int tries_remaining;
6277N/A int login_ret;
6277N/A@@ -6410,17 +5637,6 @@
6277N/A return(CKR_USER_TYPE_INVALID);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- mutex_retval = cackey_mutex_lock(cackey_biglock);
6277N/A- if (mutex_retval != 0) {
6277N/A- CACKEY_DEBUG_PRINTF("Error. Locking failed.");
6277N/A-
6277N/A- return(CKR_GENERAL_ERROR);
6277N/A- }
6277N/A-
6277N/A- if (!cackey_sessions[hSession].active) {
6277N/A- cackey_mutex_unlock(cackey_biglock);
6277N/A-=======
6277N/A if (lock_mutex) {
6277N/A mutex_retval = cackey_mutex_lock(cackey_biglock);
6277N/A if (mutex_retval != 0) {
6277N/A@@ -6434,7 +5650,6 @@
6277N/A if (lock_mutex) {
6277N/A cackey_mutex_unlock(cackey_biglock);
6277N/A }
6277N/A->>>>>>> trunk
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Error. Session not active.");
6277N/A
6277N/A@@ -6446,35 +5661,23 @@
6277N/A if (slotID < 0 || slotID >= (sizeof(cackey_slots) / sizeof(cackey_slots[0]))) {
6277N/A CACKEY_DEBUG_PRINTF("Error. Invalid slot requested (%lu), outside of valid range", slotID);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A if (lock_mutex) {
6277N/A cackey_mutex_unlock(cackey_biglock);
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A return(CKR_GENERAL_ERROR);
6277N/A }
6277N/A
6277N/A if (cackey_slots[slotID].active == 0) {
6277N/A CACKEY_DEBUG_PRINTF("Error. Invalid slot requested (%lu), slot not currently active", slotID);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- cackey_mutex_unlock(cackey_biglock);
6277N/A-=======
6277N/A if (lock_mutex) {
6277N/A cackey_mutex_unlock(cackey_biglock);
6277N/A }
6277N/A->>>>>>> trunk
6277N/A
6277N/A return(CKR_GENERAL_ERROR);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- login_ret = cackey_login(&cackey_slots[slotID], pPin, ulPinLen, &tries_remaining);
6277N/A- if (login_ret != CACKEY_PCSC_S_OK) {
6277N/A- cackey_mutex_unlock(cackey_biglock);
6277N/A-=======
6277N/A if (cackey_pin_command != NULL) {
6277N/A if (pPin != NULL) {
6277N/A CACKEY_DEBUG_PRINTF("Protected authentication path in effect and PIN provided !?");
6277N/A@@ -6501,18 +5704,14 @@
6277N/A if (lock_mutex) {
6277N/A cackey_mutex_unlock(cackey_biglock);
6277N/A }
6277N/A->>>>>>> trunk
6277N/A
6277N/A if (login_ret == CACKEY_PCSC_E_LOCKED) {
6277N/A CACKEY_DEBUG_PRINTF("Error. Token is locked.");
6277N/A
6277N/A cackey_slots[slotID].token_flags |= CKF_USER_PIN_LOCKED;
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Returning CKR_PIN_LOCKED (%i)", (int) CKR_PIN_LOCKED);
6277N/A
6277N/A->>>>>>> trunk
6277N/A return(CKR_PIN_LOCKED);
6277N/A } else if (login_ret == CACKEY_PCSC_E_BADPIN) {
6277N/A CACKEY_DEBUG_PRINTF("Error. Invalid PIN.");
6277N/A@@ -6523,11 +5722,8 @@
6277N/A cackey_slots[slotID].token_flags |= CKF_USER_PIN_FINAL_TRY;
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Returning CKR_PIN_INCORRECT (%i)", (int) CKR_PIN_INCORRECT);
6277N/A
6277N/A->>>>>>> trunk
6277N/A return(CKR_PIN_INCORRECT);
6277N/A }
6277N/A
6277N/A@@ -6540,13 +5736,6 @@
6277N/A
6277N/A cackey_sessions[hSession].state = CKS_RO_USER_FUNCTIONS;
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- mutex_retval = cackey_mutex_unlock(cackey_biglock);
6277N/A- if (mutex_retval != 0) {
6277N/A- CACKEY_DEBUG_PRINTF("Error. Unlocking failed.");
6277N/A-
6277N/A- return(CKR_GENERAL_ERROR);
6277N/A-=======
6277N/A if (lock_mutex) {
6277N/A mutex_retval = cackey_mutex_unlock(cackey_biglock);
6277N/A if (mutex_retval != 0) {
6277N/A@@ -6554,7 +5743,6 @@
6277N/A
6277N/A return(CKR_GENERAL_ERROR);
6277N/A }
6277N/A->>>>>>> trunk
6277N/A }
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK);
6277N/A@@ -6562,13 +5750,10 @@
6277N/A return(CKR_OK);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A CK_DEFINE_FUNCTION(CK_RV, C_Login)(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) {
6277N/A return(_C_LoginMutexArg(hSession, userType, pPin, ulPinLen, 1));
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A CK_DEFINE_FUNCTION(CK_RV, C_Logout)(CK_SESSION_HANDLE hSession) {
6277N/A CK_SLOT_ID slotID;
6277N/A int mutex_retval;
6277N/A@@ -6619,16 +5804,12 @@
6277N/A }
6277N/A
6277N/A cackey_sessions[hSession].state = CKS_RO_PUBLIC_SESSION;
6277N/A-<<<<<<< HEAD
6277N/A- cackey_slots[slotID].token_flags = CKF_LOGIN_REQUIRED;
6277N/A-=======
6277N/A
6277N/A if (cackey_pin_command == NULL) {
6277N/A cackey_slots[slotID].token_flags = CKF_LOGIN_REQUIRED;
6277N/A } else {
6277N/A cackey_slots[slotID].token_flags = 0;
6277N/A }
6277N/A->>>>>>> trunk
6277N/A
6277N/A mutex_retval = cackey_mutex_unlock(cackey_biglock);
6277N/A if (mutex_retval != 0) {
6277N/A@@ -7041,13 +6222,10 @@
6277N/A CK_ULONG curr_id_idx, curr_out_id_idx, curr_attr_idx, sess_attr_idx;
6277N/A CK_ULONG matched_count, prev_matched_count;
6277N/A int mutex_retval;
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A #ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST
6277N/A struct timeval start, end;
6277N/A uint64_t start_int, end_int;
6277N/A #endif
6277N/A->>>>>>> trunk
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Called.");
6277N/A
6277N/A@@ -7113,13 +6291,10 @@
6277N/A return(CKR_OPERATION_NOT_INITIALIZED);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A #ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST
6277N/A gettimeofday(&start, NULL);
6277N/A #endif
6277N/A
6277N/A->>>>>>> trunk
6277N/A curr_out_id_idx = 0;
6277N/A for (curr_id_idx = cackey_sessions[hSession].search_curr_id; curr_id_idx < cackey_sessions[hSession].identities_count && ulMaxObjectCount; curr_id_idx++) {
6277N/A curr_id = &cackey_sessions[hSession].identities[curr_id_idx];
6277N/A@@ -7165,8 +6340,6 @@
6277N/A cackey_sessions[hSession].search_curr_id = curr_id_idx;
6277N/A *pulObjectCount = curr_out_id_idx;
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A #ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST
6277N/A gettimeofday(&end, NULL);
6277N/A start_int = (start.tv_sec * 1000000) + start.tv_usec;
6277N/A@@ -7174,7 +6347,6 @@
6277N/A fprintf(stderr, "Search took %lu microseconds\n", (unsigned long) (end_int - start_int));
6277N/A #endif
6277N/A
6277N/A->>>>>>> trunk
6277N/A mutex_retval = cackey_mutex_unlock(cackey_biglock);
6277N/A if (mutex_retval != 0) {
6277N/A CACKEY_DEBUG_PRINTF("Error. Unlocking failed.");
6277N/A@@ -7562,15 +6734,12 @@
6277N/A /* Ask card to decrypt */
6277N/A buflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].decrypt_identity, pEncryptedPart, ulEncryptedPartLen, buf, sizeof(buf), 0, 1);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A if (buflen == CACKEY_PCSC_E_NEEDLOGIN && cackey_pin_command != NULL) {
6277N/A if (_C_LoginMutexArg(hSession, CKU_USER, NULL, 0, 0) == CKR_OK) {
6277N/A buflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].decrypt_identity, pEncryptedPart, ulEncryptedPartLen, buf, sizeof(buf), 0, 1);
6277N/A }
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A if (buflen < 0) {
6277N/A /* Decryption failed. */
6277N/A if (buflen == CACKEY_PCSC_E_NEEDLOGIN) {
6277N/A@@ -7578,11 +6747,8 @@
6277N/A } else if (buflen == CACKEY_PCSC_E_TOKENABSENT) {
6277N/A retval = CKR_DEVICE_REMOVED;
6277N/A } else {
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Failed to send APDU, error = %li", (long int) buflen);
6277N/A
6277N/A->>>>>>> trunk
6277N/A retval = CKR_GENERAL_ERROR;
6277N/A }
6277N/A } else if (((unsigned long) buflen) > *pulPartLen && pPart) {
6277N/A@@ -7822,11 +6988,7 @@
6277N/A cackey_sessions[hSession].sign_bufused = 0;
6277N/A cackey_sessions[hSession].sign_buf = malloc(sizeof(*cackey_sessions[hSession].sign_buf) * cackey_sessions[hSession].sign_buflen);
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTF("Session %lu sign_identity is %p (identity #%lu)", (unsigned long) hSession, &cackey_sessions[hSession].identities[hKey], (unsigned long) hKey);
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Session %lu sign_identity is %p (identity #%lu)", (unsigned long) hSession, (void *) &cackey_sessions[hSession].identities[hKey], (unsigned long) hKey);
6277N/A->>>>>>> trunk
6277N/A cackey_sessions[hSession].sign_identity = &cackey_sessions[hSession].identities[hKey];
6277N/A
6277N/A mutex_retval = cackey_mutex_unlock(cackey_biglock);
6277N/A@@ -7933,11 +7095,6 @@
6277N/A
6277N/A CK_DEFINE_FUNCTION(CK_RV, C_SignUpdate)(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen) {
6277N/A int mutex_retval;
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A- int resizeRetry;
6277N/A- int needResize;
6277N/A->>>>>>> trunk
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Called.");
6277N/A
6277N/A@@ -7998,47 +7155,12 @@
6277N/A switch (cackey_sessions[hSession].sign_mechanism) {
6277N/A case CKM_RSA_PKCS:
6277N/A /* Accumulate directly */
6277N/A-<<<<<<< HEAD
6277N/A if ((cackey_sessions[hSession].sign_bufused + ulPartLen) > cackey_sessions[hSession].sign_buflen) {
6277N/A-=======
6277N/A- for (resizeRetry = 0; resizeRetry < 11; resizeRetry++) {
6277N/A- needResize = 0;
6277N/A- if ((cackey_sessions[hSession].sign_bufused + ulPartLen) > cackey_sessions[hSession].sign_buflen) {
6277N/A- needResize = 1;
6277N/A- }
6277N/A-
6277N/A- if (!needResize) {
6277N/A- break;
6277N/A- }
6277N/A-
6277N/A- CACKEY_DEBUG_PRINTF("Resizing signing buffer (try #%i of 10 -- 11th is fatal)", resizeRetry);
6277N/A-
6277N/A- if (resizeRetry == 10) {
6277N/A- free(cackey_sessions[hSession].sign_buf);
6277N/A-
6277N/A- cackey_sessions[hSession].sign_buflen = 0;
6277N/A- cackey_sessions[hSession].sign_buf = NULL;
6277N/A-
6277N/A- break;
6277N/A- }
6277N/A-
6277N/A->>>>>>> trunk
6277N/A cackey_sessions[hSession].sign_buflen *= 2;
6277N/A
6277N/A cackey_sessions[hSession].sign_buf = realloc(cackey_sessions[hSession].sign_buf, sizeof(*cackey_sessions[hSession].sign_buf) * cackey_sessions[hSession].sign_buflen);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A- if (cackey_sessions[hSession].sign_buf == NULL) {
6277N/A- cackey_mutex_unlock(cackey_biglock);
6277N/A-
6277N/A- CACKEY_DEBUG_PRINTF("Error. Signing buffer is NULL.");
6277N/A-
6277N/A- return(CKR_GENERAL_ERROR);
6277N/A- }
6277N/A-
6277N/A->>>>>>> trunk
6277N/A memcpy(cackey_sessions[hSession].sign_buf + cackey_sessions[hSession].sign_bufused, pPart, ulPartLen);
6277N/A
6277N/A cackey_sessions[hSession].sign_bufused += ulPartLen;
6277N/A@@ -8128,11 +7250,6 @@
6277N/A switch (cackey_sessions[hSession].sign_mechanism) {
6277N/A case CKM_RSA_PKCS:
6277N/A /* Ask card to sign */
6277N/A-<<<<<<< HEAD
6277N/A- CACKEY_DEBUG_PRINTF("Asking to sign from identity %p in session %lu", cackey_sessions[hSession].sign_identity, (unsigned long) hSession);
6277N/A- sigbuflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].sign_identity, cackey_sessions[hSession].sign_buf, cackey_sessions[hSession].sign_bufused, sigbuf, sizeof(sigbuf), 1, 0);
6277N/A-
6277N/A-=======
6277N/A CACKEY_DEBUG_PRINTF("Asking to sign from identity %p in session %lu", (void *) cackey_sessions[hSession].sign_identity, (unsigned long) hSession);
6277N/A sigbuflen = cackey_signdecrypt(&cackey_slots[slotID], cackey_sessions[hSession].sign_identity, cackey_sessions[hSession].sign_buf, cackey_sessions[hSession].sign_bufused, sigbuf, sizeof(sigbuf), 1, 0);
6277N/A
6277N/A@@ -8142,7 +7259,6 @@
6277N/A }
6277N/A }
6277N/A
6277N/A->>>>>>> trunk
6277N/A if (sigbuflen < 0) {
6277N/A /* Signing failed. */
6277N/A if (sigbuflen == CACKEY_PCSC_E_NEEDLOGIN) {
6277N/A@@ -8485,10 +7601,6 @@
6277N/A }
6277N/A
6277N/A CK_DEFINE_FUNCTION(CK_RV, C_GetFunctionList)(CK_FUNCTION_LIST_PTR_PTR ppFunctionList) {
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A- static CK_FUNCTION_LIST_PTR spFunctionList = NULL;
6277N/A->>>>>>> trunk
6277N/A CK_FUNCTION_LIST_PTR pFunctionList;
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Called.");
6277N/A@@ -8499,17 +7611,6 @@
6277N/A return(CKR_ARGUMENTS_BAD);
6277N/A }
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A- if (spFunctionList != NULL) {
6277N/A- *ppFunctionList = spFunctionList;
6277N/A-
6277N/A- CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK);
6277N/A-
6277N/A- return(CKR_OK);
6277N/A- }
6277N/A-
6277N/A->>>>>>> trunk
6277N/A pFunctionList = malloc(sizeof(*pFunctionList));
6277N/A
6277N/A pFunctionList->version.major = ((CACKEY_CRYPTOKI_VERSION_CODE) >> 16) & 0xff;
6277N/A@@ -8584,17 +7685,10 @@
6277N/A pFunctionList->C_CancelFunction = C_CancelFunction;
6277N/A pFunctionList->C_GetFunctionList = C_GetFunctionList;
6277N/A
6277N/A-<<<<<<< HEAD
6277N/A-=======
6277N/A- spFunctionList = pFunctionList;
6277N/A->>>>>>> trunk
6277N/A *ppFunctionList = pFunctionList;
6277N/A
6277N/A CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK);
6277N/A
6277N/A return(CKR_OK);
6277N/A }
6277N/A-<<<<<<< HEAD
6277N/A
6277N/A-=======
6277N/A->>>>>>> trunk