Remove duplicate code for checking certificate

Closes #3076
pull/707/merge
SinghRajenM 2017-03-14 00:31:26 +05:30 committed by Don Ho
parent 6947bf3909
commit fe45f2e9b1
1 changed files with 17 additions and 16 deletions

View File

@ -978,6 +978,7 @@ HWND CreateToolTip(int toolID, HWND hDlg, HINSTANCE hInst, const PTSTR pszText)
bool isCertificateValidated(const generic_string & fullFilePath, const generic_string & subjectName2check) bool isCertificateValidated(const generic_string & fullFilePath, const generic_string & subjectName2check)
{ {
bool isOK = false;
HCERTSTORE hStore = NULL; HCERTSTORE hStore = NULL;
HCRYPTMSG hMsg = NULL; HCRYPTMSG hMsg = NULL;
PCCERT_CONTEXT pCertContext = NULL; PCCERT_CONTEXT pCertContext = NULL;
@ -1080,27 +1081,27 @@ bool isCertificateValidated(const generic_string & fullFilePath, const generic_s
throw generic_string(TEXT("Certificate checking error: the certificate is not matched.")); throw generic_string(TEXT("Certificate checking error: the certificate is not matched."));
} }
// Clean up. isOK = true;
if (pSignerInfo != NULL) LocalFree(pSignerInfo);
if (pCertContext != NULL) CertFreeCertificateContext(pCertContext);
if (hStore != NULL) CertCloseStore(hStore, 0);
if (hMsg != NULL) CryptMsgClose(hMsg);
if (szName != NULL) LocalFree(szName);
} }
catch (generic_string s) catch (generic_string s)
{ {
// display error message // display error message
MessageBox(NULL, s.c_str(), TEXT("Certificate checking"), MB_OK); MessageBox(NULL, s.c_str(), TEXT("Certificate checking"), MB_OK);
}
// Clean up. catch (...)
if (pSignerInfo != NULL) LocalFree(pSignerInfo); {
if (pCertContext != NULL) CertFreeCertificateContext(pCertContext); // Unknown error
if (hStore != NULL) CertCloseStore(hStore, 0); generic_string errorMessage = TEXT("Unknown exception occured. ");
if (hMsg != NULL) CryptMsgClose(hMsg); errorMessage += GetLastErrorAsString(GetLastError());
if (szName != NULL) LocalFree(szName); MessageBox(NULL, errorMessage.c_str(), TEXT("Certificate checking"), MB_OK);
return false;
} }
return true; // Clean up.
if (pSignerInfo != NULL) LocalFree(pSignerInfo);
if (pCertContext != NULL) CertFreeCertificateContext(pCertContext);
if (hStore != NULL) CertCloseStore(hStore, 0);
if (hMsg != NULL) CryptMsgClose(hMsg);
if (szName != NULL) LocalFree(szName);
return isOK;
} }