Author: jmagne
Update of /cvs/dirsec/esc/src/lib/coolkey
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv2137
Modified Files:
CoolKeyHandler.cpp
Log Message:
Add time stamp to log messages and handle cancelled operation better.
View full diff with command:
/usr/bin/cvs -f diff -kk -u -N -r 1.2 -r 1.3 CoolKeyHandler.cpp
Index: CoolKeyHandler.cpp
===================================================================
RCS file: /cvs/dirsec/esc/src/lib/coolkey/CoolKeyHandler.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CoolKeyHandler.cpp 27 Sep 2006 17:47:46 -0000 1.2
+++ CoolKeyHandler.cpp 24 Feb 2007 02:16:41 -0000 1.3
@@ -21,6 +21,7 @@
#include <assert.h>
#include <stdio.h>
#include <string>
+#include <time.h>
#include "prprf.h"
#include "nss.h"
@@ -46,7 +47,6 @@
//static char *test_extended_login =
"s=325&msg_type=13&invalid_login=0&blocked=0&error=&required_parameter0=id%3DUSER%5FID%26name%3DUser+ID%26desc%3DUser+ID%26type%3Dstring%26option%3Doption1%2Coption2%2Coption3&required_parameter1=id%3DUSER%5FPWD%26name%3DUser+Password%26desc%3DUser+Password%26type%3Dpassword%26option%3D&required_parameter2=id%3DUSER%5FPIN%26name%3DPIN%26desc%3DOne+time+PIN+received+via+mail%26type%3Dpassword%26option%3D";
-
#include <string>
#ifndef CKO_MOZILLA_READER
@@ -59,52 +59,52 @@
void NotifyEndResult(CoolKeyHandler* context, int operation, int result, int
description);
-
struct AutoCKYBuffer : public CKYBuffer
{
- AutoCKYBuffer() { CKYBuffer_InitEmpty(this); };
- AutoCKYBuffer(const char *aHex) { CKYBuffer_InitFromHex(this, aHex); };
- AutoCKYBuffer(unsigned const char *aData, unsigned int aLength) {
CKYBuffer_InitFromData(this, aData, aLength); };
- AutoCKYBuffer(unsigned long aLength) { CKYBuffer_InitFromLen(this, aLength); };
- ~AutoCKYBuffer() { CKYBuffer_FreeData(this); };
+ AutoCKYBuffer() { CKYBuffer_InitEmpty(this); };
+ AutoCKYBuffer(const char *aHex) { CKYBuffer_InitFromHex(this, aHex); };
+ AutoCKYBuffer(unsigned const char *aData, unsigned int aLength) {
CKYBuffer_InitFromData(this, aData, aLength); };
+ AutoCKYBuffer(unsigned long aLength) { CKYBuffer_InitFromLen(this, aLength); };
+ ~AutoCKYBuffer() { CKYBuffer_FreeData(this); };
};
struct KHHttpEvent
{
- KHHttpEvent(CoolKeyHandler *aKeyHandler,NSS_HTTP_HANDLE handle)
- : mKeyHandler(aKeyHandler), mHttpHandle(handle)
- {
- }
+ KHHttpEvent(CoolKeyHandler *aKeyHandler,NSS_HTTP_HANDLE handle)
+ : mKeyHandler(aKeyHandler), mHttpHandle(handle)
+ {
+ }
- virtual ~KHHttpEvent()
- {
- }
+ virtual ~KHHttpEvent()
+ {
+ }
- virtual HRESULT Execute() = 0;
+ virtual HRESULT Execute() = 0;
- CoolKeyHandler *mKeyHandler;
- NSS_HTTP_HANDLE mHttpHandle;
+ CoolKeyHandler *mKeyHandler;
+ NSS_HTTP_HANDLE mHttpHandle;
};
struct KHOnConnectEvent : public KHHttpEvent
{
- KHOnConnectEvent(CoolKeyHandler *aKeyHandler, NSS_HTTP_HANDLE handle)
- : KHHttpEvent(aKeyHandler, handle)
- {
- }
+ KHOnConnectEvent(CoolKeyHandler *aKeyHandler, NSS_HTTP_HANDLE handle)
+ : KHHttpEvent(aKeyHandler, handle)
+ {
+ }
- HRESULT Execute()
- {
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("KHOnConnectEvent::Execute:\n"));
- HRESULT res;
- res = mKeyHandler->OnConnectImpl();
+ HRESULT Execute()
+ {
+ char tBuff[56];
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s
KHOnConnectEvent::Execute:\n",GetTStamp(tBuff,56)));
+ HRESULT res;
+ res = mKeyHandler->OnConnectImpl();
if(res == E_FAIL)
{
- mKeyHandler->OnDisConnectImpl();
+ mKeyHandler->OnDisConnectImpl();
}
- return res;
+ return res;
}
};
@@ -112,128 +112,126 @@
{
public:
- PDUWriterThread(CoolKeyHandler *aHandler) {mAccepting=PR_FALSE; mHandler = aHandler;};
- ~PDUWriterThread() ;
+ PDUWriterThread(CoolKeyHandler *aHandler) {mAccepting=PR_FALSE; mHandler =
aHandler;};
+ ~PDUWriterThread() ;
- HRESULT Init();
+ HRESULT Init();
- HRESULT QueueKHHttpEvent(KHHttpEvent *aEvent);
- HRESULT QueueOnConnectEvent(CoolKeyHandler *aKeyHandler,
+ HRESULT QueueKHHttpEvent(KHHttpEvent *aEvent);
+ HRESULT QueueOnConnectEvent(CoolKeyHandler *aKeyHandler,
NSS_HTTP_HANDLE handle);
- HRESULT Shutdown();
+ HRESULT Shutdown();
- static void ThreadRun(void* arg);
+ static void ThreadRun(void* arg);
- PRLock *mLock;
- PRCondVar *mCondVar;
- PRThread *mThread;
- PRBool mAccepting;
+ PRLock *mLock;
+ PRCondVar *mCondVar;
+ PRThread *mThread;
+ PRBool mAccepting;
- CoolKeyHandler *mHandler;
+ CoolKeyHandler *mHandler;
- std::list<KHHttpEvent*> mPendingEvents;
+ std::list<KHHttpEvent*> mPendingEvents;
};
PDUWriterThread::~PDUWriterThread()
{
-
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG,
("PDUWriterThread::~PDUWriterThread:\n"));
+ char tBuff[56];
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s
PDUWriterThread::~PDUWriterThread:\n",GetTStamp(tBuff,56)));
if (mCondVar ) {
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG,
("CoolKeyHandler::PDUWriterThread::~PDUWriterThreade about to destroy
mCondVar.\n"));
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s
CoolKeyHandler::PDUWriterThread::~PDUWriterThreade about to destroy
mCondVar.\n",GetTStamp(tBuff,56)));
PR_DestroyCondVar(mCondVar);
mCondVar = NULL;
- }
-
- if (mLock ) {
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG,
("CoolKeyHandler::PDUWriterThread::~PDUWriterThread about to destroy
mLock.\n"));
-
- PR_DestroyLock(mLock);
- mLock = NULL;
- }
+ }
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG,
("CoolKeyHandler::PDUWriterThread::~PDUWriterThread leaving....\n"));
+ if (mLock ) {
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s
CoolKeyHandler::PDUWriterThread::~PDUWriterThread about to destroy
mLock.\n",GetTStamp(tBuff,56)));
+ PR_DestroyLock(mLock);
+ mLock = NULL;
+ }
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s
CoolKeyHandler::PDUWriterThread::~PDUWriterThread
leaving....\n",GetTStamp(tBuff,56)));
}
void
PDUWriterThread::ThreadRun(void *arg)
{
+ char tBuff[56];
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s
PDUWriterThread::ThreadRun:\n",GetTStamp(tBuff,56)));
+ PDUWriterThread *pn = (PDUWriterThread*) arg;
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("PDUWriterThread::ThreadRun:\n"));
- PDUWriterThread *pn = (PDUWriterThread*) arg;
-
- while (pn->mAccepting && pn->mLock && pn->mCondVar) {
+ while (pn->mAccepting && pn->mLock && pn->mCondVar) {
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("PDUWriterThread::ThreadRun: top of while
loop accepting %d lock %p cond
%p\n",pn->mAccepting,pn->mLock,pn->mCondVar));
- PR_Lock(pn->mLock);
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s PDUWriterThread::ThreadRun: top of
while loop accepting %d lock %p cond
%p\n",GetTStamp(tBuff,56),pn->mAccepting,pn->mLock,pn->mCondVar));
+ PR_Lock(pn->mLock);
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("PDUWriterThread::ThreadRun: done
PR_Lock()\\n"));
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s PDUWriterThread::ThreadRun: done
PR_Lock()\\n",GetTStamp(tBuff,56)));
[...2857 lines suppressed...]
+ goto failed;
+ }
// get the reader name (though we probably don't need it anymore
- status = PK11_ReadRawAttribute(PK11_TypeGeneric, obj, CKA_LABEL, &label);
- if (status != SECSuccess) {
- goto failed;
- }
+ status = PK11_ReadRawAttribute(PK11_TypeGeneric, obj, CKA_LABEL, &label);
+ if (status != SECSuccess) {
+ goto failed;
+ }
// get the ATR (though, again, we probably don't need it
- status = PK11_ReadRawAttribute(PK11_TypeGeneric, obj, CKA_MOZILLA_ATR, &ATR);
+ status = PK11_ReadRawAttribute(PK11_TypeGeneric, obj, CKA_MOZILLA_ATR, &ATR);
// PK11_DestroyGenericObjects(obj);
- if (status != SECSuccess) {
- goto failed;
- }
+ if (status != SECSuccess) {
+ goto failed;
+ }
// get the CUID/Serial number (we *WILL* continue to need it )
- status = PK11_GetTokenInfo(aSlot,&tokenInfo);
- if (status != SECSuccess) {
- goto failed;
- }
+ status = PK11_GetTokenInfo(aSlot,&tokenInfo);
+ if (status != SECSuccess) {
+ goto failed;
+ }
//get the are we a CoolKey value
- status = PK11_ReadRawAttribute(PK11_TypeGeneric, obj, CKA_MOZILLA_IS_COOL_KEY,
&isCOOLKey);
+ status = PK11_ReadRawAttribute(PK11_TypeGeneric, obj, CKA_MOZILLA_IS_COOL_KEY,
&isCOOLKey);
- PK11_DestroyGenericObjects(obj);
- obj = NULL;
+ PK11_DestroyGenericObjects(obj);
+ obj = NULL;
- if (status != SECSuccess) {
- goto failed;
- }
+ if (status != SECSuccess) {
+ goto failed;
+ }
- if(isCOOLKey.len == 1)
- {
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("CKHGetCoolKeyInfo:
CKA_MOZILLA_IS_COOL_KEY %d.\n",(int) isCOOLKey.data[0]));
+ if(isCOOLKey.len == 1)
+ {
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CKHGetCoolKeyInfo:
CKA_MOZILLA_IS_COOL_KEY %d.\n",GetTStamp(tBuff,56),(int) isCOOLKey.data[0]));
- isACOOLKey=(int) isCOOLKey.data[0];
- }
+ isACOOLKey=(int) isCOOLKey.data[0];
+ }
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("CKHGetCoolKeyInfo: info->flags
%u.\n",tokenInfo.flags));
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CKHGetCoolKeyInfo: info->flags
%u.\n",GetTStamp(tBuff,56),tokenInfo.flags));
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("CKHGetCoolKeyInfo: info->label
%s.\n",(char *)tokenInfo.label));
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("CKHGetCoolKeyInfo: info->manufacturerID
%s.\n",(char *)tokenInfo.manufacturerID));
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("CKHGetCoolKeyInfo: info->model
%s.\n",(char *)tokenInfo.model));
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("CKHGetCoolKeyInfo: info->serialNumber
%s.\n",(char *)tokenInfo.serialNumber));
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CKHGetCoolKeyInfo: info->label
%s.\n",GetTStamp(tBuff,56),(char *)tokenInfo.label));
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CKHGetCoolKeyInfo:
info->manufacturerID %s.\n",GetTStamp(tBuff,56),(char
*)tokenInfo.manufacturerID));
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CKHGetCoolKeyInfo: info->model
%s.\n",GetTStamp(tBuff,56),(char *)tokenInfo.model));
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CKHGetCoolKeyInfo:
info->serialNumber %s.\n",GetTStamp(tBuff,56),(char *)tokenInfo.serialNumber));
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("CKHGetCoolKeyInfo:
info->firmwareVersion.major %d info->firmwareVersion.minor %d
\n",(int)tokenInfo.firmwareVersion.major,(int) tokenInfo.firmwareVersion.minor));
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CKHGetCoolKeyInfo:
info->firmwareVersion.major %d info->firmwareVersion.minor %d
\n",GetTStamp(tBuff,56),(int)tokenInfo.firmwareVersion.major,(int)
tokenInfo.firmwareVersion.minor));
// OK, we have everything we need, now build the COOLKEYInfo structure.
- info = new CoolKeyInfo();
- if (!info) {
- goto failed;
- }
+ info = new CoolKeyInfo();
+ if (!info) {
+ goto failed;
+ }
- atrSize = ATR.len*2+5;
- atrString = (char *)malloc(atrSize);
- hres = CoolKeyBinToHex(ATR.data, ATR.len,
+ atrSize = ATR.len*2+5;
+ atrString = (char *)malloc(atrSize);
+ hres = CoolKeyBinToHex(ATR.data, ATR.len,
(unsigned char *) atrString, atrSize, true);
/* shouldn't the be != S_SUCCESS? */
- if (hres == E_FAIL) {
- free(atrString);
- goto failed;
- }
- SECITEM_FreeItem(&ATR,PR_FALSE);
- ATR.data = NULL;
+ if (hres == E_FAIL) {
+ free(atrString);
+ goto failed;
+ }
+ SECITEM_FreeItem(&ATR,PR_FALSE);
+ ATR.data = NULL;
- PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("CKHGetCoolKeyInfo: info->atr
%s.\n",(char *)atrString));
+ PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CKHGetCoolKeyInfo: info->atr
%s.\n",GetTStamp(tBuff,56),(char *)atrString));
- info->mATR = atrString;
- info->mReaderName= (char *)malloc(label.len+1);
- if (!info->mReaderName) {
- goto failed;
- }
- memcpy(info->mReaderName, label.data, label.len);
- info->mReaderName[label.len] = 0;
- info->mInfoFlags = MapGetFlags(&tokenInfo);
+ info->mATR = atrString;
+ info->mReaderName= (char *)malloc(label.len+1);
+ if (!info->mReaderName) {
+ goto failed;
+ }
+ memcpy(info->mReaderName, label.data, label.len);
+ info->mReaderName[label.len] = 0;
+ info->mInfoFlags = MapGetFlags(&tokenInfo);
//Handle the isCOOLKey flag
- if(isACOOLKey) {
- info->mInfoFlags |= COOLKEY_INFO_IS_REALLY_A_COOLKEY_MASK;
- }
+ if(isACOOLKey) {
+ info->mInfoFlags |= COOLKEY_INFO_IS_REALLY_A_COOLKEY_MASK;
+ }
- info->mCUID = (char *)malloc(35); /* should be a define ! */
- if (!info->mCUID) {
- goto failed;
- }
- hres = getCUIDFromTokenInfo(&tokenInfo, info->mCUID);
+ info->mCUID = (char *)malloc(35); /* should be a define ! */
+ if (!info->mCUID) {
+ goto failed;
+ }
+ hres = getCUIDFromTokenInfo(&tokenInfo, info->mCUID);
/* shouldn't the be != S_SUCCESS? */
- if (hres == E_FAIL) {
- goto failed;
- }
-
- SECITEM_FreeItem(&ATR,PR_FALSE);
- SECITEM_FreeItem(&label,PR_FALSE);
- SECITEM_FreeItem(&isCOOLKey,PR_FALSE);
-
- info->mSlot = PK11_ReferenceSlot(aSlot);
- info->mSeries = PK11_GetSlotSeries(aSlot);
- return info;
+ if (hres == E_FAIL) {
+ goto failed;
+ }
-failed:
- if (ATR.data) {
SECITEM_FreeItem(&ATR,PR_FALSE);
- }
- if (label.data) {
SECITEM_FreeItem(&label,PR_FALSE);
- }
- if (obj) {
- PK11_DestroyGenericObjects(obj);
- }
- if (info) {
- delete info;
- }
- return NULL;
+ SECITEM_FreeItem(&isCOOLKey,PR_FALSE);
+
+ info->mSlot = PK11_ReferenceSlot(aSlot);
+ info->mSeries = PK11_GetSlotSeries(aSlot);
+ return info;
+
+failed:
+ if (ATR.data) {
+ SECITEM_FreeItem(&ATR,PR_FALSE);
+ }
+ if (label.data) {
+ SECITEM_FreeItem(&label,PR_FALSE);
+ }
+ if (obj) {
+ PK11_DestroyGenericObjects(obj);
+ }
+ if (info) {
+ delete info;
+ }
+ return NULL;
}