From 16b60483367f27632405ca18f8808e121f8e4f0c Mon Sep 17 00:00:00 2001 From: awnuk Date: Tue, 17 Aug 2010 23:41:50 +0000 Subject: Fixed bugzilla bug #624847. git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@1207 c9f7a03b-bd48-0410-a16d-cbbf54688b0b --- pki/base/tps/src/include/selftests/TPSPresence.h | 1 + pki/base/tps/src/include/selftests/TPSValidity.h | 1 + pki/base/tps/src/selftests/TPSPresence.cpp | 63 +++++++++++------- pki/base/tps/src/selftests/TPSValidity.cpp | 85 ++++++++++++++---------- 4 files changed, 92 insertions(+), 58 deletions(-) diff --git a/pki/base/tps/src/include/selftests/TPSPresence.h b/pki/base/tps/src/include/selftests/TPSPresence.h index 4f3f88abf..114f4ae57 100644 --- a/pki/base/tps/src/include/selftests/TPSPresence.h +++ b/pki/base/tps/src/include/selftests/TPSPresence.h @@ -70,6 +70,7 @@ class TPSPresence : public SelfTest static bool onDemandCritical; static int initialized; static char *nickname; + static const char *UNINITIALIZED_NICKNAME; static const char *NICKNAME_NAME; static const char *CRITICAL_TEST_NAME; }; diff --git a/pki/base/tps/src/include/selftests/TPSValidity.h b/pki/base/tps/src/include/selftests/TPSValidity.h index 2c05363ea..548052a83 100644 --- a/pki/base/tps/src/include/selftests/TPSValidity.h +++ b/pki/base/tps/src/include/selftests/TPSValidity.h @@ -71,6 +71,7 @@ class TPSValidity : public SelfTest static bool onDemandCritical; static int initialized; static char *nickname; + static const char *UNINITIALIZED_NICKNAME; static const char *NICKNAME_NAME; static const char *CRITICAL_TEST_NAME; }; diff --git a/pki/base/tps/src/selftests/TPSPresence.cpp b/pki/base/tps/src/selftests/TPSPresence.cpp index 6e2e562c9..7f37fd0fb 100644 --- a/pki/base/tps/src/selftests/TPSPresence.cpp +++ b/pki/base/tps/src/selftests/TPSPresence.cpp @@ -57,6 +57,7 @@ bool TPSPresence::onDemandEnabled = false; bool TPSPresence::startupCritical = false; bool TPSPresence::onDemandCritical = false; char *TPSPresence::nickname = 0; +const char *TPSPresence::UNINITIALIZED_NICKNAME = "[HSM_LABEL][NICKNAME]"; const char *TPSPresence::NICKNAME_NAME = "selftests.plugin.TPSPresence.nickname"; const char *TPSPresence::CRITICAL_TEST_NAME = "TPSPresence:critical"; const char *TPSPresence::TEST_NAME = "TPSPresence"; @@ -94,9 +95,17 @@ void TPSPresence::Initialize (ConfigStore *cfg) } char* n = (char*)(cfg->GetConfigAsString(TPSPresence::NICKNAME_NAME)); if (n != 0 && PL_strlen(n) > 0) { + if (PL_strstr (n, TPSPresence::UNINITIALIZED_NICKNAME) != NULL) { + TPSPresence::initialized = 0; + } else { + TPSPresence::nickname = n; + } + TPSPresence::nickname = n; } - TPSPresence::initialized = 2; + if (TPSPresence::initialized == 1) { + TPSPresence::initialized = 2; + } } RA::SelfTestLog("TPSPresence::Initialize", "%s", ((initialized==2)?"successfully completed":"failed")); } @@ -112,11 +121,15 @@ void TPSPresence::Initialize (ConfigStore *cfg) int TPSPresence::runSelfTest () { int rc = 0; - if (TPSPresence::nickname != 0 && PL_strlen(TPSPresence::nickname) > 0) { - rc = TPSPresence::runSelfTest (TPSPresence::nickname); - } else { - rc = -3; + + if (TPSPresence::initialized == 2) { + if (TPSPresence::nickname != 0 && PL_strlen(TPSPresence::nickname) > 0) { + rc = TPSPresence::runSelfTest (TPSPresence::nickname); + } else { + rc = -3; + } } + return rc; } @@ -126,21 +139,23 @@ int TPSPresence::runSelfTest (const char *nick_name) CERTCertDBHandle *handle = 0; CERTCertificate *cert = 0; - if (nick_name != 0 && PL_strlen(nick_name) > 0) { - handle = CERT_GetDefaultCertDB(); - if (handle != 0) { - cert = CERT_FindCertByNickname( handle, (char *) nick_name); - if (cert != 0) { - CERT_DestroyCertificate (cert); - cert = 0; + if (TPSPresence::initialized == 2) { + if (nick_name != 0 && PL_strlen(nick_name) > 0) { + handle = CERT_GetDefaultCertDB(); + if (handle != 0) { + cert = CERT_FindCertByNickname( handle, (char *) nick_name); + if (cert != 0) { + CERT_DestroyCertificate (cert); + cert = 0; + } else { + rc = 2; + } } else { - rc = 2; + rc = -1; } } else { - rc = -1; + rc = TPSPresence::runSelfTest (); } - } else { - rc = TPSPresence::runSelfTest (); } return rc; @@ -151,14 +166,16 @@ int TPSPresence::runSelfTest (const char *nick_name, CERTCertificate **cert) int rc = 0; CERTCertDBHandle *handle = 0; - handle = CERT_GetDefaultCertDB(); - if (handle != 0) { - *cert = CERT_FindCertByNickname( handle, (char *) nick_name); - if (*cert == NULL) { - rc = 2; + if (TPSPresence::initialized == 2) { + handle = CERT_GetDefaultCertDB(); + if (handle != 0) { + *cert = CERT_FindCertByNickname( handle, (char *) nick_name); + if (*cert == NULL) { + rc = 2; + } + } else { + rc = 1; } - } else { - rc = 1; } return rc; diff --git a/pki/base/tps/src/selftests/TPSValidity.cpp b/pki/base/tps/src/selftests/TPSValidity.cpp index 988870564..e70263e80 100644 --- a/pki/base/tps/src/selftests/TPSValidity.cpp +++ b/pki/base/tps/src/selftests/TPSValidity.cpp @@ -57,6 +57,7 @@ bool TPSValidity::onDemandEnabled = false; bool TPSValidity::startupCritical = false; bool TPSValidity::onDemandCritical = false; char *TPSValidity::nickname = 0; +const char *TPSValidity::UNINITIALIZED_NICKNAME = "[HSM_LABEL][NICKNAME]"; const char *TPSValidity::NICKNAME_NAME = "selftests.plugin.TPSValidity.nickname"; const char *TPSValidity::CRITICAL_TEST_NAME = "TPSValidity:critical"; const char *TPSValidity::TEST_NAME = "TPSValidity"; @@ -95,9 +96,15 @@ void TPSValidity::Initialize (ConfigStore *cfg) } char* n = (char*)(cfg->GetConfigAsString(TPSValidity::NICKNAME_NAME)); if (n != NULL && PL_strlen(n) > 0) { - TPSValidity::nickname = n; + if (PL_strstr (n, TPSValidity::UNINITIALIZED_NICKNAME) != NULL) { + TPSValidity::initialized = 0; + } else { + TPSValidity::nickname = n; + } + } + if (TPSValidity::initialized == 1) { + TPSValidity::initialized = 2; } - TPSValidity::initialized = 2; } RA::SelfTestLog("TPSValidity::Initialize", "%s", ((initialized==2)?"successfully completed":"failed")); } @@ -113,11 +120,15 @@ void TPSValidity::Initialize (ConfigStore *cfg) int TPSValidity::runSelfTest () { int rc = 0; - if (TPSValidity::nickname != NULL && PL_strlen(TPSValidity::nickname) > 0) { - rc = TPSValidity::runSelfTest (TPSValidity::nickname); - } else { - rc = -3; + + if (TPSValidity::initialized == 2) { + if (TPSValidity::nickname != NULL && PL_strlen(TPSValidity::nickname) > 0) { + rc = TPSValidity::runSelfTest (TPSValidity::nickname); + } else { + rc = -3; + } } + return rc; } @@ -129,24 +140,26 @@ int TPSValidity::runSelfTest (const char *nick_name) CERTCertDBHandle *handle = 0; CERTCertificate *cert = 0; - handle = CERT_GetDefaultCertDB(); - if (handle != 0) { - cert = CERT_FindCertByNickname( handle, (char *) nick_name); - if (cert != 0) { - now = PR_Now(); - certTimeValidity = CERT_CheckCertValidTimes (cert, now, PR_FALSE); - if (certTimeValidity == secCertTimeExpired) { - rc = 4; - } else if (certTimeValidity == secCertTimeNotValidYet) { - rc = 5; + if (TPSValidity::initialized == 2) { + handle = CERT_GetDefaultCertDB(); + if (handle != 0) { + cert = CERT_FindCertByNickname( handle, (char *) nick_name); + if (cert != 0) { + now = PR_Now(); + certTimeValidity = CERT_CheckCertValidTimes (cert, now, PR_FALSE); + if (certTimeValidity == secCertTimeExpired) { + rc = 4; + } else if (certTimeValidity == secCertTimeNotValidYet) { + rc = 5; + } + CERT_DestroyCertificate (cert); + cert = 0; + } else { + rc = 2; } - CERT_DestroyCertificate (cert); - cert = 0; } else { - rc = 2; + rc = -1; } - } else { - rc = -1; } return rc; @@ -158,20 +171,22 @@ int TPSValidity::runSelfTest (const char *nick_name, CERTCertificate *cert) PRTime now; int rc = 0; - if (cert != 0) { - now = PR_Now(); - certTimeValidity = CERT_CheckCertValidTimes (cert, now, PR_FALSE); - if (certTimeValidity == secCertTimeExpired) { - rc = 4; - } else if (certTimeValidity == secCertTimeNotValidYet) { - rc = 5; - } - CERT_DestroyCertificate (cert); - cert = 0; - } else if (nick_name != 0 && PL_strlen(nick_name) > 0) { - rc = TPSValidity::runSelfTest (nick_name); - } else { - rc = TPSValidity::runSelfTest (); + if (TPSValidity::initialized == 2) { + if (cert != 0) { + now = PR_Now(); + certTimeValidity = CERT_CheckCertValidTimes (cert, now, PR_FALSE); + if (certTimeValidity == secCertTimeExpired) { + rc = 4; + } else if (certTimeValidity == secCertTimeNotValidYet) { + rc = 5; + } + CERT_DestroyCertificate (cert); + cert = 0; + } else if (nick_name != 0 && PL_strlen(nick_name) > 0) { + rc = TPSValidity::runSelfTest (nick_name); + } else { + rc = TPSValidity::runSelfTest (); + } } return rc; -- cgit