[Pcsclite-cvs-commit] PKCS11/src p11_crypt.c,1.9,1.10 p11_key.c,1.9,1.10 p11_object.c,1.22,1.23 p11_session.c,1.11,1.12 p11_sign.c,1.12,1.13 p11_token.c,1.13,1.14 p11x_msc.c,1.8,1.9 p11x_object.c,1.39,1.40 p11x_session.c,1.5,1.6 p11x_slot.c,1.29,1.30 p11x_state.c,1.15,1.16
rousseau@quantz.debian.org
rousseau@quantz.debian.org
Sat, 04 Oct 2003 10:30:21 +0200
Update of /cvsroot/muscleapps/PKCS11/src
In directory quantz:/tmp/cvs-serv24817
Modified Files:
p11_crypt.c p11_key.c p11_object.c p11_session.c p11_sign.c
p11_token.c p11x_msc.c p11x_object.c p11x_session.c
p11x_slot.c p11x_state.c
Log Message:
dos2unix conversion
Index: p11_crypt.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_crypt.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- p11_crypt.c 5 Jun 2003 00:46:49 -0000 1.9
+++ p11_crypt.c 4 Oct 2003 08:30:18 -0000 1.10
@@ -16,48 +16,48 @@
#include <openssl/rsa.h>
*/
-/**
- * Padding algorithm defined in RSA's PKCS #1.
- * to: pre-allocated buffer to receive the padded data
- * toLen: the length of the buffer. This should be the same as the size
- * of the RSA modulus. (toLen - 3) > fromLen.
- * from: data to be padded.
- * fromLen: size of data to be padded. fromLen < (toLen-3).
- * Returns: nonzero for success, zero for failure.
- */
-int
-padRSAType1(CK_BYTE* to, CK_ULONG toLen, CK_BYTE*from, CK_ULONG fromLen)
-{
- int i = 0;
- int padLen = toLen - 3 - fromLen;
-
- assert( toLen > fromLen );
- assert( padLen >= 0 );
- if( toLen < fromLen || padLen < 0 ) {
- return 0;
- }
-
- /* First byte: 00 */
- to[i++] = 0x00;
-
- /* Second Byte: Block Type == 01 */
- to[i++] = 0x01;
-
- /* Padding String, each byte is 0xFF for block type 01 */
- memset(to+i, 0xFF, padLen);
- i += padLen;
-
- /* Separator byte: 00 */
- to[i++] = 0x00;
-
- /* Finally, the data */
- memcpy(to+i, from, fromLen);
- i += fromLen;
-
- assert( (CK_ULONG) i == toLen );
-
- return 1;
-}
+/**
+ * Padding algorithm defined in RSA's PKCS #1.
+ * to: pre-allocated buffer to receive the padded data
+ * toLen: the length of the buffer. This should be the same as the size
+ * of the RSA modulus. (toLen - 3) > fromLen.
+ * from: data to be padded.
+ * fromLen: size of data to be padded. fromLen < (toLen-3).
+ * Returns: nonzero for success, zero for failure.
+ */
+int
+padRSAType1(CK_BYTE* to, CK_ULONG toLen, CK_BYTE*from, CK_ULONG fromLen)
+{
+ int i = 0;
+ int padLen = toLen - 3 - fromLen;
+
+ assert( toLen > fromLen );
+ assert( padLen >= 0 );
+ if( toLen < fromLen || padLen < 0 ) {
+ return 0;
+ }
+
+ /* First byte: 00 */
+ to[i++] = 0x00;
+
+ /* Second Byte: Block Type == 01 */
+ to[i++] = 0x01;
+
+ /* Padding String, each byte is 0xFF for block type 01 */
+ memset(to+i, 0xFF, padLen);
+ i += padLen;
+
+ /* Separator byte: 00 */
+ to[i++] = 0x00;
+
+ /* Finally, the data */
+ memcpy(to+i, from, fromLen);
+ i += fromLen;
+
+ assert( (CK_ULONG) i == toLen );
+
+ return 1;
+}
/* C_EncryptInit initializes an encryption operation. */
@@ -75,12 +75,12 @@
thread_MutexLock(st.async_lock);
- /* Added by Netscape */
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+ /* Added by Netscape */
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
/* end */
log_Log(LOG_LOW, "Encrypt mech: %X", *pMechanism);
@@ -141,16 +141,16 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
-
- slotID = session->session.slotID;
- slot = &st.slots[slotID-1];
-
- key = (P11_Object *)session->sign_key;
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
+
+ slotID = session->session.slotID;
+ slot = &st.slots[slotID-1];
+
+ key = (P11_Object *)session->sign_key;
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_SESSION_HANDLE_INVALID;
@@ -307,10 +307,10 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
}
log_Log(LOG_LOW, "Decrypt mech: %X", *pMechanism);
@@ -370,16 +370,16 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
-
- slotID = session->session.slotID;
- slot = &st.slots[slotID-1];
-
- key = (P11_Object *)session->sign_key;
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
+
+ slotID = session->session.slotID;
+ slot = &st.slots[slotID-1];
+
+ key = (P11_Object *)session->sign_key;
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_SESSION_HANDLE_INVALID;
Index: p11_key.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_key.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- p11_key.c 5 Jun 2003 00:46:49 -0000 1.9
+++ p11_key.c 4 Oct 2003 08:30:18 -0000 1.10
@@ -75,11 +75,11 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_SESSION_HANDLE_INVALID;
@@ -191,14 +191,14 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
-
- slotID = session->session.slotID;
- slot = &st.slots[slotID-1];
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
+
+ slotID = session->session.slotID;
+ slot = &st.slots[slotID-1];
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_SESSION_HANDLE_INVALID;
Index: p11_object.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_object.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- p11_object.c 5 Jun 2003 00:46:49 -0000 1.22
+++ p11_object.c 4 Oct 2003 08:30:18 -0000 1.23
@@ -34,11 +34,11 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_SESSION_HANDLE_INVALID;
@@ -240,11 +240,11 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
log_Log(LOG_LOW, "Object handle: %lX", hObject);
object_FreeObject(session->session.slotID, (P11_Object *)hObject);
@@ -414,11 +414,11 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_SESSION_HANDLE_INVALID;
@@ -480,12 +480,12 @@
P11_LOG_START("C_FindObjectsInit");
thread_MutexLock(st.async_lock);
-
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_SESSION_HANDLE_INVALID;
@@ -574,15 +574,15 @@
P11_LOG_START("C_FindObjects");
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
+ session = session_LookupSession(hSession);
if( session == NULL ) {
// if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_SESSION_HANDLE_INVALID;
goto finish;
}
- slot = &st.slots[session->session.slotID - 1];
- if (CKR_ERROR(rv = slot_TokenChanged()))
+ slot = &st.slots[session->session.slotID - 1];
+ if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_SESSION_HANDLE_INVALID;
else if (!phObject || !ulMaxObjectCount || !pulObjectCount)
rv= CKR_ARGUMENTS_BAD;
@@ -645,7 +645,7 @@
thread_MutexLock(st.async_lock);
// if (CKR_ERROR(rv = slot_TokenChanged()))
- session = session_LookupSession(hSession);
+ session = session_LookupSession(hSession);
if( session == NULL ) {
rv = CKR_SESSION_HANDLE_INVALID;
goto finish;
Index: p11_session.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_session.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- p11_session.c 5 Jun 2003 00:46:49 -0000 1.11
+++ p11_session.c 4 Oct 2003 08:30:18 -0000 1.12
@@ -86,26 +86,26 @@
return rv;
}
-static CK_RV
-closeSessionLocked(CK_SESSION_HANDLE hSession)
-{
- CK_RV rv = CKR_OK;
- P11_Session *session;
- CK_SLOT_ID slotID;
-
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- return CKR_SESSION_HANDLE_INVALID;
- }
- slotID = session->session.slotID;
-
- if (CKR_ERROR(rv = slot_TokenChanged()))
- rv = CKR_DEVICE_REMOVED;
- else if (!CKR_ERROR(rv = session_FreeSession(session)))
- rv = slot_ReleaseConnection(slotID);
-
- return rv;
-}
+static CK_RV
+closeSessionLocked(CK_SESSION_HANDLE hSession)
+{
+ CK_RV rv = CKR_OK;
+ P11_Session *session;
+ CK_SLOT_ID slotID;
+
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ return CKR_SESSION_HANDLE_INVALID;
+ }
+ slotID = session->session.slotID;
+
+ if (CKR_ERROR(rv = slot_TokenChanged()))
+ rv = CKR_DEVICE_REMOVED;
+ else if (!CKR_ERROR(rv = session_FreeSession(session)))
+ rv = slot_ReleaseConnection(slotID);
+
+ return rv;
+}
/* C_CloseSession closes a session between an application and a
@@ -131,8 +131,8 @@
else if (!CKR_ERROR(rv = session_FreeSession(hSession)))
rv = slot_ReleaseConnection(slotID);
*/
-
- rv = closeSessionLocked(hSession);
+
+ rv = closeSessionLocked(hSession);
thread_MutexUnlock(st.async_lock);
@@ -169,11 +169,11 @@
/*
if (session_l->session.slotID == slotID)
C_CloseSession((CK_SESSION_HANDLE)session_l);
-*/
- if (session_l->session.slotID == slotID) {
- /* Fixme: ignore errors? */
- closeSessionLocked(session_l->handle);
- }
+*/
+ if (session_l->session.slotID == slotID) {
+ /* Fixme: ignore errors? */
+ closeSessionLocked(session_l->handle);
+ }
@@ -181,7 +181,7 @@
}
}
- thread_MutexUnlock(st.async_lock);
+ thread_MutexUnlock(st.async_lock);
P11_LOG_END("C_CloseAllSessions");
@@ -202,12 +202,12 @@
P11_LOG_START("C_GetSessionInfo");
thread_MutexLock(st.async_lock);
-
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_DEVICE_REMOVED;
@@ -302,11 +302,11 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_DEVICE_REMOVED;
@@ -354,11 +354,11 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_DEVICE_REMOVED;
Index: p11_sign.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_sign.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- p11_sign.c 5 Jun 2003 00:46:49 -0000 1.12
+++ p11_sign.c 4 Oct 2003 08:30:18 -0000 1.13
@@ -32,10 +32,10 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
}
if (CKR_ERROR(rv = slot_TokenChanged()))
@@ -85,23 +85,23 @@
P11_Object *key; // = (P11_Object *)session->sign_key;
CK_BYTE *to = 0;
CK_ULONG tlen;
- P11_Slot *slot;
- CK_ULONG slotID;
+ P11_Slot *slot;
+ CK_ULONG slotID;
P11_LOG_START("C_Sign");
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
-
- slotID = session->session.slotID;
- slot = &st.slots[slotID-1];
-
- key = (P11_Object *)session->sign_key;
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
+
+ slotID = session->session.slotID;
+ slot = &st.slots[slotID-1];
+
+ key = (P11_Object *)session->sign_key;
log_Log(LOG_LOW, "Output buffer len: %lu", *pulSignatureLen);
@@ -147,10 +147,10 @@
log_Log(LOG_LOW, "Pad and Sign object keyNum: %lu tlen: %lu",
key->msc_key->keyNum, tlen);
- if (!to)
- rv = CKR_HOST_MEMORY;
- else if (!padRSAType1(to, tlen, pData, ulDataLen))
- rv = CKR_FUNCTION_FAILED;
+ if (!to)
+ rv = CKR_HOST_MEMORY;
+ else if (!padRSAType1(to, tlen, pData, ulDataLen))
+ rv = CKR_FUNCTION_FAILED;
/*
if (!to)
rv = CKR_HOST_MEMORY;
@@ -159,8 +159,8 @@
*/
else if (MSC_ERROR(msc_ComputeCrypt(
- slot,
- slotID,
+ slot,
+ slotID,
&slot->conn,
&cryptInit,
to,
@@ -181,8 +181,8 @@
key->msc_key->keyNum, ulDataLen);
if (MSC_ERROR(msc_ComputeCrypt(
- slot,
- slotID,
+ slot,
+ slotID,
&slot->conn,
&cryptInit,
pData,
Index: p11_token.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_token.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- p11_token.c 5 Jun 2003 00:46:49 -0000 1.13
+++ p11_token.c 4 Oct 2003 08:30:18 -0000 1.14
@@ -291,11 +291,11 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
// if (CKR_ERROR(rv = slot_TokenChanged()))
// rv = CKR_DEVICE_REMOVED;
@@ -356,11 +356,11 @@
thread_MutexLock(st.async_lock);
- session = session_LookupSession(hSession);
- if( session == NULL ) {
- rv = CKR_SESSION_HANDLE_INVALID;
- goto finish;
- }
+ session = session_LookupSession(hSession);
+ if( session == NULL ) {
+ rv = CKR_SESSION_HANDLE_INVALID;
+ goto finish;
+ }
if (CKR_ERROR(rv = slot_TokenChanged()))
rv = CKR_DEVICE_REMOVED;
Index: p11x_msc.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_msc.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- p11x_msc.c 5 Jun 2003 00:46:49 -0000 1.8
+++ p11x_msc.c 4 Oct 2003 08:30:18 -0000 1.9
@@ -302,8 +302,8 @@
return rv;
}
-MSC_RV msc_ComputeCrypt(
- P11_Slot* slot,
+MSC_RV msc_ComputeCrypt(
+ P11_Slot* slot,
CK_ULONG slotID,
MSCLPTokenConnection pConnection,
MSCLPCryptInit cryptInit,
@@ -330,7 +330,7 @@
if (rv == MSC_UNAUTHORIZED)
{
- if (CKR_ERROR(slot_ReverifySlotPins(slot, slotID)))
+ if (CKR_ERROR(slot_ReverifySlotPins(slot, slotID)))
break;
}
else
Index: p11x_object.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_object.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- p11x_object.c 5 Jun 2003 00:46:49 -0000 1.39
+++ p11x_object.c 4 Oct 2003 08:30:18 -0000 1.40
@@ -11,8 +11,8 @@
******************************************************************************/
#include "cryptoki.h"
-#include "crackcert.h"
-#include <assert.h>
+#include "crackcert.h"
+#include <assert.h>
/* #include <openssl/x509.h> */
@@ -1634,10 +1634,10 @@
{
log_Log(LOG_LOW, "object_InferClassAttributes: got CKO_CERTIFICATE");
-/*
- * DJN: PKCS #11 Certificates don't have CKA_MODULUS or CKA_PUBLIC_EXPONENT
- * attributes
- */
+/*
+ * DJN: PKCS #11 Certificates don't have CKA_MODULUS or CKA_PUBLIC_EXPONENT
+ * attributes
+ */
#if 0
if (CKR_ERROR_NOLOG(object_GetAttrib(CKA_MODULUS, object, &t_attrib)) &&
!CKR_ERROR(object_GetCertModulus((CK_BYTE *)obj_attrib->attrib.pValue,
@@ -1658,8 +1658,8 @@
log_Log(LOG_LOW, "object_InferClassAttributes: got CKA_PUBLIC_EXPONENT");
(void)CKR_ERROR(object_AddAttribute(object, CKA_PUBLIC_EXPONENT, FALSE, buf, len, &t_attrib));
}
-#endif
-/* DJN */
+#endif
+/* DJN */
if (CKR_ERROR_NOLOG(object_GetAttrib(CKA_SUBJECT, object, &t_attrib)) &&
@@ -1696,54 +1696,54 @@
return rv;
}
-
-typedef enum {
- CERT_SUBJECT,
- CERT_SERIAL,
- CERT_ISSUER
-} CertField;
-
-static CK_RV
-getCertData(CK_BYTE *cert, CK_ULONG cert_size, CK_BYTE *out, CK_ULONG *out_len,
-CertField field)
-{
- /*
- * No memory is allocated by GetCertFields. These SECItems will only
- * point into the cert buffer, so they should not be freed.
- */
- CCItem issuer;
- CCItem serial;
- CCItem derSN;
- CCItem subject;
- CCItem valid;
- CCItem subjkey;
- SECStatus rv;
-
- rv = GetCertFields(cert, cert_size, &issuer, &serial, &derSN, &subject,
- &valid, &subjkey);
- if( rv != SECSuccess ) {
- return CKR_FUNCTION_FAILED;
- }
- if( out ) {
- CCItem *item;
- switch( field ) {
- case CERT_SERIAL:
- item = &derSN;
- break;
- case CERT_SUBJECT:
- item = &subject;
- break;
- case CERT_ISSUER:
- item = &issuer;
- break;
- default:
- assert(0);
- return CKR_FUNCTION_FAILED;
- }
- memcpy(out, item->data, item->len);
- *out_len = item->len;
- }
- return CKR_OK;
+
+typedef enum {
+ CERT_SUBJECT,
+ CERT_SERIAL,
+ CERT_ISSUER
+} CertField;
+
+static CK_RV
+getCertData(CK_BYTE *cert, CK_ULONG cert_size, CK_BYTE *out, CK_ULONG *out_len,
+CertField field)
+{
+ /*
+ * No memory is allocated by GetCertFields. These SECItems will only
+ * point into the cert buffer, so they should not be freed.
+ */
+ CCItem issuer;
+ CCItem serial;
+ CCItem derSN;
+ CCItem subject;
+ CCItem valid;
+ CCItem subjkey;
+ SECStatus rv;
+
+ rv = GetCertFields(cert, cert_size, &issuer, &serial, &derSN, &subject,
+ &valid, &subjkey);
+ if( rv != SECSuccess ) {
+ return CKR_FUNCTION_FAILED;
+ }
+ if( out ) {
+ CCItem *item;
+ switch( field ) {
+ case CERT_SERIAL:
+ item = &derSN;
+ break;
+ case CERT_SUBJECT:
+ item = &subject;
+ break;
+ case CERT_ISSUER:
+ item = &issuer;
+ break;
+ default:
+ assert(0);
+ return CKR_FUNCTION_FAILED;
+ }
+ memcpy(out, item->data, item->len);
+ *out_len = item->len;
+ }
+ return CKR_OK;
}
/******************************************************************************
@@ -1809,11 +1809,11 @@
return getCertData(cert, cert_size, out, out_len, CERT_ISSUER);
}
-/*
- * DJN: No need to get cert modulus or public exponent. PKCS #11 doesn't
- * support these attributes for a certificate anyway.
- */
-#if 0
+/*
+ * DJN: No need to get cert modulus or public exponent. PKCS #11 doesn't
+ * support these attributes for a certificate anyway.
+ */
+#if 0
/******************************************************************************
** Function: object_GetCertModulus
Index: p11x_session.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_session.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- p11x_session.c 5 Jun 2003 00:46:49 -0000 1.5
+++ p11x_session.c 4 Oct 2003 08:30:18 -0000 1.6
@@ -12,31 +12,31 @@
#include "cryptoki.h"
-/******************************************************************************
-** Function: session_LookupSession
-**
-** Looks up the session in the hash table, given its handle.
-**
-** Parameters:
-** handle - handle of the session
-**
-** Returns:
-** Pointer to the session with the given handle, if found.
-** NULL if no session is found with the given handle.
-*******************************************************************************/
-P11_Session*
-session_LookupSession(CK_SESSION_HANDLE handle)
-{
- P11_Session *cur;
-
- cur = st.session_hash[handle % NUM_SESSION_HASH_SLOTS];
- for( ; cur ; cur = cur->hnext) {
- if( cur->handle == handle ) {
- return cur;
- }
- }
- return NULL;
-}
+/******************************************************************************
+** Function: session_LookupSession
+**
+** Looks up the session in the hash table, given its handle.
+**
+** Parameters:
+** handle - handle of the session
+**
+** Returns:
+** Pointer to the session with the given handle, if found.
+** NULL if no session is found with the given handle.
+*******************************************************************************/
+P11_Session*
+session_LookupSession(CK_SESSION_HANDLE handle)
+{
+ P11_Session *cur;
+
+ cur = st.session_hash[handle % NUM_SESSION_HASH_SLOTS];
+ for( ; cur ; cur = cur->hnext) {
+ if( cur->handle == handle ) {
+ return cur;
+ }
+ }
+ return NULL;
+}
/******************************************************************************
** Function: session_AddSession
@@ -44,7 +44,7 @@
** Adds a new session
**
** Parameters:
-** phandle - Returns the handle for the new session
+** phandle - Returns the handle for the new session
** psession - Returns a pointer to the new session
**
** Returns:
@@ -54,7 +54,7 @@
CK_RV session_AddSession(CK_SESSION_HANDLE *phandle, P11_Session **psession)
{
CK_RV rv = CKR_OK;
- unsigned int idx;
+ unsigned int idx;
if (st.sessions)
{
@@ -64,9 +64,9 @@
goto finish;
}
- st.sessions->prev->next = st.sessions;
- st.sessions = st.sessions->prev;
- st.sessions->check = st.sessions;
+ st.sessions->prev->next = st.sessions;
+ st.sessions = st.sessions->prev;
+ st.sessions->check = st.sessions;
}
else
@@ -76,30 +76,30 @@
rv = CKR_HOST_MEMORY;
goto finish;
}
-
- st.sessions->check = st.sessions;
+
+ st.sessions->check = st.sessions;
}
- *psession = st.sessions;
+ *psession = st.sessions;
+
+ /*
+ * Find an unused session handle
+ */
+ do {
+ st.last_session_handle++;
+ } while( (st.last_session_handle == CK_INVALID_HANDLE) ||
+ session_LookupSession(st.last_session_handle) );
+ *phandle = st.last_session_handle;
+ (*psession)->handle = st.last_session_handle;
+
+ /*
+ * Put this session in the session hashtable
+ */
+ idx = (*psession)->handle % NUM_SESSION_HASH_SLOTS;
+ (*psession)->hnext = st.session_hash[idx];
+ st.session_hash[idx] = *psession;
- /*
- * Find an unused session handle
- */
- do {
- st.last_session_handle++;
- } while( (st.last_session_handle == CK_INVALID_HANDLE) ||
- session_LookupSession(st.last_session_handle) );
- *phandle = st.last_session_handle;
- (*psession)->handle = st.last_session_handle;
-
- /*
- * Put this session in the session hashtable
- */
- idx = (*psession)->handle % NUM_SESSION_HASH_SLOTS;
- (*psession)->hnext = st.session_hash[idx];
- st.session_hash[idx] = *psession;
-
finish:
return rv;
}
@@ -122,47 +122,47 @@
unsigned int idx;
- log_Log(LOG_LOW, "Removing session: %lX", session->handle);
-
- /*
- * take the session out of the session hashtable
- */
- idx = session->handle % NUM_SESSION_HASH_SLOTS;
- if( st.session_hash[idx] == session ) {
- /* first session in the list */
- st.session_hash[idx] = session->hnext;
- } else {
- P11_Session *prev = st.session_hash[idx];
- while( prev->hnext != session ) {
+ log_Log(LOG_LOW, "Removing session: %lX", session->handle);
+
+ /*
+ * take the session out of the session hashtable
+ */
+ idx = session->handle % NUM_SESSION_HASH_SLOTS;
+ if( st.session_hash[idx] == session ) {
+ /* first session in the list */
+ st.session_hash[idx] = session->hnext;
+ } else {
+ P11_Session *prev = st.session_hash[idx];
+ while( prev->hnext != session ) {
prev = prev->hnext;
}
- prev->hnext = prev->hnext->hnext;
- }
+ prev->hnext = prev->hnext->hnext;
+ }
- /*
- * Take the session out of the session list
- */
+ /*
+ * Take the session out of the session list
+ */
- if (session->prev) /* Fixme: check for head of list? st.sessions */
- {
+ if (session->prev) /* Fixme: check for head of list? st.sessions */
+ {
session->prev->next = session->next;
- if (session == st.sessions) /* Fixme: Is this needed? */
- st.sessions = session->prev;
- }
-
- if (session->next)
- {
- session->next->prev = session->prev;
+ if (session == st.sessions) /* Fixme: Is this needed? */
+ st.sessions = session->prev;
+ }
- if (session == st.sessions)
- st.sessions = session->next;
- }
-
- if (!session->prev && !session->next)
- st.sessions = 0x00;
-
- if (session->search_attrib)
- free(session->search_attrib);
+ if (session->next)
+ {
+ session->next->prev = session->prev;
+
+ if (session == st.sessions)
+ st.sessions = session->next;
+ }
+
+ if (!session->prev && !session->next)
+ st.sessions = 0x00;
+
+ if (session->search_attrib)
+ free(session->search_attrib);
/* Clear memory, just to be safe */
Index: p11x_slot.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_slot.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- p11x_slot.c 29 Aug 2003 14:20:38 -0000 1.29
+++ p11x_slot.c 4 Oct 2003 08:30:18 -0000 1.30
@@ -69,7 +69,7 @@
else if (st.prefs.threaded)
(void)CKR_ERROR(rv = slot_ReleaseConnection(slotID));
- log_Log(LOG_LOW, "End transaction: %lu,\t\trv=%lx", slotID, rv);
+ log_Log(LOG_LOW, "End transaction: %lu,\t\trv=%lx", slotID, rv);
return rv;
}
@@ -1080,12 +1080,12 @@
else
for (i = 0; i < st.slot_count; i++)
{
- /*
- * If the slot-watcher thread is not running, manually
- * check to see if the token has been inserted.
- */
- if ( !(st.prefs.threaded && st.create_threads)
- && !(st.slots[i].slot_info.flags & CKF_TOKEN_PRESENT))
+ /*
+ * If the slot-watcher thread is not running, manually
+ * check to see if the token has been inserted.
+ */
+ if ( !(st.prefs.threaded && st.create_threads)
+ && !(st.slots[i].slot_info.flags & CKF_TOKEN_PRESENT))
{
slot_UpdateSlot(i + 1);
@@ -1151,8 +1151,8 @@
/******************************************************************************
** Function: slot_ReverifyPins()
**
-** Reverifies cached PIN's on a particular slot. If any cached PIN fails to
-** verify then this will kill that PIN so that it won't be used again. This
+** Reverifies cached PIN's on a particular slot. If any cached PIN fails to
+** verify then this will kill that PIN so that it won't be used again. This
** is to prevent the caching mechanism from inadvertantly locking a token.
**
** Parameters:
@@ -1167,28 +1167,28 @@
CK_RV rv = CKR_OK;
if (slot->conn.hCard ) {
- if (slot->pins[CKU_SO].pin_size) {
- rv = slot_VerifyPIN(slotID,
- CKU_SO,
- slot->pins[CKU_SO].pin,
- slot->pins[CKU_SO].pin_size);
- }
+ if (slot->pins[CKU_SO].pin_size) {
+ rv = slot_VerifyPIN(slotID,
+ CKU_SO,
+ slot->pins[CKU_SO].pin,
+ slot->pins[CKU_SO].pin_size);
+ }
- if (CKR_ERROR(rv)) {
- slot->pins[CKU_SO].pin_size = 0;
- memset(slot->pins[CKU_SO].pin, 0x00,
- sizeof(slot->pins[CKU_SO].pin));
- } else if (slot->pins[CKU_USER].pin_size) {
- rv = slot_VerifyPIN(slotID,
- CKU_USER,
- slot->pins[CKU_USER].pin,
- slot->pins[CKU_USER].pin_size);
+ if (CKR_ERROR(rv)) {
+ slot->pins[CKU_SO].pin_size = 0;
+ memset(slot->pins[CKU_SO].pin, 0x00,
+ sizeof(slot->pins[CKU_SO].pin));
+ } else if (slot->pins[CKU_USER].pin_size) {
+ rv = slot_VerifyPIN(slotID,
+ CKU_USER,
+ slot->pins[CKU_USER].pin,
+ slot->pins[CKU_USER].pin_size);
- if (CKR_ERROR(rv)) {
- slot->pins[CKU_USER].pin_size = 0;
- memset(slot->pins[CKU_USER].pin, 0x00,
- sizeof(slot->pins[CKU_USER].pin));
- } else {
+ if (CKR_ERROR(rv)) {
+ slot->pins[CKU_USER].pin_size = 0;
+ memset(slot->pins[CKU_USER].pin, 0x00,
+ sizeof(slot->pins[CKU_USER].pin));
+ } else {
slot_UserMode(slotID);
}
}
@@ -1197,30 +1197,31 @@
return rv;
}
-/******************************************************************************
-** Function: slot_ReverifyPins()
-**
-** Reverifies cached PIN's on all slots. If any cached PIN fails to verify
-** then this will kill that PIN so that it won't be used again. This is to
-** prevent the caching mechanism from inadvertantly locking a token.
-**
-** Parameters:
-** none
-**
-** Returns:
-** Error from slot_VerifyPIN
-** CKR_OK
-*******************************************************************************/
-CK_RV slot_ReverifyPins()
-{
- CK_RV rv = CKR_OK;
- CK_ULONG i;
-
- log_Log(LOG_LOW, "Reverifying all cached PIN's");
-
- for (i = 0; i < st.slot_count; i++) {
- slot_ReverifySlotPins(&st.slots[i], i+1);
- }
-
- return rv;
-}
\ No newline at end of file
+/******************************************************************************
+** Function: slot_ReverifyPins()
+**
+** Reverifies cached PIN's on all slots. If any cached PIN fails to verify
+** then this will kill that PIN so that it won't be used again. This is to
+** prevent the caching mechanism from inadvertantly locking a token.
+**
+** Parameters:
+** none
+**
+** Returns:
+** Error from slot_VerifyPIN
+** CKR_OK
+*******************************************************************************/
+CK_RV slot_ReverifyPins()
+{
+ CK_RV rv = CKR_OK;
+ CK_ULONG i;
+
+ log_Log(LOG_LOW, "Reverifying all cached PIN's");
+
+ for (i = 0; i < st.slot_count; i++) {
+ slot_ReverifySlotPins(&st.slots[i], i+1);
+ }
+
+ return rv;
+}
+
Index: p11x_state.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_state.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- p11x_state.c 5 Jun 2003 00:46:49 -0000 1.15
+++ p11x_state.c 4 Oct 2003 08:30:18 -0000 1.16
@@ -57,11 +57,11 @@
CK_RV state_Init()
{
CK_RV rv = CKR_OK;
-
- /*
- * initialize session hash table
- */
- memset(st.session_hash, 0, sizeof(P11_Session*) * NUM_SESSION_HASH_SLOTS);
+
+ /*
+ * initialize session hash table
+ */
+ memset(st.session_hash, 0, sizeof(P11_Session*) * NUM_SESSION_HASH_SLOTS);
if (!st.initialized)
util_ReadPreferences();