OSDN Git Service

Change UI to enter a new master password.
authors_kawamoto <s_kawamoto@users.sourceforge.jp>
Tue, 11 Oct 2011 15:36:43 +0000 (00:36 +0900)
committers_kawamoto <s_kawamoto@users.sourceforge.jp>
Tue, 11 Oct 2011 15:36:43 +0000 (00:36 +0900)
Fix improper error handling of WinVerifyTrust.

14 files changed:
FFFTP.vc90.vcproj
FFFTP.vcproj
FFFTP_Eng_Release/FFFTP.exe
FFFTP_English.vc90.vcproj
FFFTP_English.vcproj
Release/FFFTP.exe
Resource/FFFTP.rc
Resource_eng/FFFTP-eng.rc
main.c
mesg-eng.h
mesg-eng.old.h
mesg-jpn.h
mesg-jpn.old.h
protectprocess.c

index d421ce2..5b2cba9 100644 (file)
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions="/MACHINE:I386"
-                               AdditionalDependencies="comctl32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"
+                               AdditionalDependencies="comctl32.lib crypt32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"
                                OutputFile=".\Debug\FFFTP.exe"
                                LinkIncremental="2"
                                SuppressStartupBanner="true"
                                GenerateManifest="false"
-                               DelayLoadDLLs="advapi32.dll;comctl32.dll;comdlg32.dll;gdi32.dll;imagehlp.dll;ole32.dll;sfc.dll;shell32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"
+                               DelayLoadDLLs="advapi32.dll;comctl32.dll;crypt32.dll;comdlg32.dll;gdi32.dll;imagehlp.dll;ole32.dll;sfc.dll;shell32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"
                                GenerateDebugInformation="true"
                                ProgramDatabaseFile=".\Debug\FFFTP.pdb"
                                SubSystem="2"
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions="/MACHINE:I386"
-                               AdditionalDependencies="comctl32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"
+                               AdditionalDependencies="comctl32.lib crypt32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"
                                OutputFile=".\Release\FFFTP.exe"
                                LinkIncremental="1"
                                SuppressStartupBanner="true"
                                GenerateManifest="false"
-                               DelayLoadDLLs="advapi32.dll;comctl32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"
+                               DelayLoadDLLs="advapi32.dll;comctl32.dll;crypt32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"
                                ProgramDatabaseFile=".\Release\FFFTP.pdb"
                                SubSystem="2"
                                RandomizedBaseAddress="1"
index 70d12b9..7aa2fed 100644 (file)
                        <Tool\r
                                Name="VCLinkerTool"\r
                                AdditionalOptions="/MACHINE:I386"\r
-                               AdditionalDependencies="comctl32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"\r
+                               AdditionalDependencies="comctl32.lib crypt32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"\r
                                OutputFile=".\Debug\FFFTP.exe"\r
                                LinkIncremental="2"\r
                                SuppressStartupBanner="true"\r
                                GenerateManifest="false"\r
-                               DelayLoadDLLs="advapi32.dll;comctl32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"\r
+                               DelayLoadDLLs="advapi32.dll;comctl32.dll;crypt32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"\r
                                GenerateDebugInformation="true"\r
                                ProgramDatabaseFile=".\Debug\FFFTP.pdb"\r
                                SubSystem="2"\r
                        <Tool\r
                                Name="VCLinkerTool"\r
                                AdditionalOptions="/MACHINE:I386"\r
-                               AdditionalDependencies="comctl32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"\r
+                               AdditionalDependencies="comctl32.lib crypt32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"\r
                                OutputFile=".\Release\FFFTP.exe"\r
                                LinkIncremental="1"\r
                                SuppressStartupBanner="true"\r
                                GenerateManifest="false"\r
-                               DelayLoadDLLs="advapi32.dll;comctl32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"\r
+                               DelayLoadDLLs="advapi32.dll;comctl32.dll;crypt32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"\r
                                ProgramDatabaseFile=".\Release\FFFTP.pdb"\r
                                SubSystem="2"\r
                        />\r
index c143e3b..d4dea80 100644 (file)
Binary files a/FFFTP_Eng_Release/FFFTP.exe and b/FFFTP_Eng_Release/FFFTP.exe differ
index 88b7cc7..b4e6f3c 100644 (file)
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions="/MACHINE:I386"
-                               AdditionalDependencies="comctl32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"
+                               AdditionalDependencies="comctl32.lib crypt32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"
                                OutputFile=".\FFFTP_Eng_Debug\FFFTP.exe"
                                LinkIncremental="2"
                                SuppressStartupBanner="true"
                                GenerateManifest="false"
-                               DelayLoadDLLs="advapi32.dll;comctl32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"
+                               DelayLoadDLLs="advapi32.dll;comctl32.dll;crypt32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"
                                GenerateDebugInformation="true"
                                ProgramDatabaseFile=".\FFFTP_Eng_Debug\FFFTP.pdb"
                                SubSystem="2"
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions="/MACHINE:I386"
-                               AdditionalDependencies="comctl32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"
+                               AdditionalDependencies="comctl32.lib crypt32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"
                                OutputFile=".\FFFTP_Eng_Release\FFFTP.exe"
                                LinkIncremental="1"
                                SuppressStartupBanner="true"
                                GenerateManifest="false"
-                               DelayLoadDLLs="advapi32.dll;comctl32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"
+                               DelayLoadDLLs="advapi32.dll;comctl32.dll;crypt32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"
                                ProgramDatabaseFile=".\FFFTP_Eng_Release\FFFTP.pdb"
                                SubSystem="2"
                                RandomizedBaseAddress="1"
index 332b721..588ee1e 100644 (file)
                        <Tool\r
                                Name="VCLinkerTool"\r
                                AdditionalOptions="/MACHINE:I386"\r
-                               AdditionalDependencies="comctl32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"\r
+                               AdditionalDependencies="comctl32.lib crypt32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"\r
                                OutputFile=".\FFFTP_Eng_Debug\FFFTP.exe"\r
                                LinkIncremental="2"\r
                                SuppressStartupBanner="true"\r
                                GenerateManifest="false"\r
-                               DelayLoadDLLs="advapi32.dll;comctl32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"\r
+                               DelayLoadDLLs="advapi32.dll;comctl32.dll;crypt32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"\r
                                GenerateDebugInformation="true"\r
                                ProgramDatabaseFile=".\FFFTP_Eng_Debug\FFFTP.pdb"\r
                                SubSystem="2"\r
                        <Tool\r
                                Name="VCLinkerTool"\r
                                AdditionalOptions="/MACHINE:I386"\r
-                               AdditionalDependencies="comctl32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"\r
+                               AdditionalDependencies="comctl32.lib crypt32.lib htmlhelp.lib imagehlp.lib rasapi32.lib sfc.lib winmm.lib wintrust.lib wsock32.lib"\r
                                OutputFile=".\FFFTP_Eng_Release\FFFTP.exe"\r
                                LinkIncremental="1"\r
                                SuppressStartupBanner="true"\r
                                GenerateManifest="false"\r
-                               DelayLoadDLLs="advapi32.dll;comctl32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"\r
+                               DelayLoadDLLs="advapi32.dll;comctl32.dll;crypt32.dll;comdlg32.dll;gdi32.dll;sfc.dll;shell32.dll;ole32.dll;user32.dll;winmm.dll;wintrust.dll;wsock32.dll"\r
                                ProgramDatabaseFile=".\FFFTP_Eng_Release\FFFTP.pdb"\r
                                SubSystem="2"\r
                        />\r
index 5c4620c..cc7fa88 100644 (file)
Binary files a/Release/FFFTP.exe and b/Release/FFFTP.exe differ
index d9a7363..34bbc1d 100644 (file)
@@ -495,10 +495,10 @@ END
 \r
 newmasterpasswd_dlg DIALOGEX 0, 0, 187, 43\r
 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION\r
-CAPTION "\90V\82µ\82¢\83}\83X\83^\81[\83p\83X\83\8f\81[\83h\82ð\93ü\82ê\82Ä\82­\82¾\82³\82¢"\r
+CAPTION "\90V\82µ\82¢\83}\83X\83^\81[\83p\83X\83\8f\81[\83h\82ð2\89ñ\93ü\82ê\82Ä\82­\82¾\82³\82¢"\r
 FONT 9, "\82l\82\82o\83S\83V\83b\83N", 0, 0, 0x0\r
 BEGIN\r
-    EDITTEXT        INP_INPSTR,7,7,173,12,ES_AUTOHSCROLL\r
+    EDITTEXT        INP_INPSTR,7,7,173,12,ES_PASSWORD | ES_AUTOHSCROLL\r
     DEFPUSHBUTTON   "OK",IDOK,16,25,50,14\r
     PUSHBUTTON      "\83L\83\83\83\93\83Z\83\8b",IDCANCEL,68,25,50,14\r
     CONTROL         "",INP_ANONYMOUS,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_DISABLED | WS_TABSTOP,172,31,8,8\r
index 701765a..e82bebf 100644 (file)
@@ -498,10 +498,10 @@ END
 \r
 newmasterpasswd_dlg DIALOGEX 0, 0, 187, 43\r
 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION\r
-CAPTION "Enter new master password"\r
+CAPTION "Enter new master password twice"\r
 FONT 9, "MS Sans Serif", 0, 0, 0x0\r
 BEGIN\r
-    EDITTEXT        INP_INPSTR,7,7,173,12,ES_AUTOHSCROLL\r
+    EDITTEXT        INP_INPSTR,7,7,173,12,ES_PASSWORD | ES_AUTOHSCROLL\r
     DEFPUSHBUTTON   "OK",IDOK,25,25,43,14\r
     PUSHBUTTON      "Cancel",IDCANCEL,72,25,43,14\r
     CONTROL         "",INP_ANONYMOUS,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_DISABLED | WS_TABSTOP,172,31,8,8\r
diff --git a/main.c b/main.c
index 3f949c9..6ea14fc 100644 (file)
--- a/main.c
+++ b/main.c
@@ -499,7 +499,7 @@ static int InitApp(LPSTR lpszCmdLine, int cmdShow)
                                        DispWindowTitle();\r
                                        // SourceForge.JPによるフォーク\r
 //                                     SetTaskMsg("FFFTP Ver." VER_STR " Copyright(C) 1997-2010 Sota & cooperators.");\r
-                                       SetTaskMsg("FFFTP Ver." VER_STR " Copyright(C) 1997-2010 Sota & cooperators.\r\nCopyright (C) 2011 Hiromichi Matsushima, Suguru Kawamoto.");\r
+                                       SetTaskMsg("FFFTP Ver." VER_STR " Copyright(C) 1997-2010 Sota & cooperators.\r\nCopyright (C) 2011 FFFTP Project (Hiromichi Matsushima, Suguru Kawamoto).");\r
 \r
                                        if(ForceIni)\r
                                                SetTaskMsg("%s%s", MSGJPN283, IniPath);\r
@@ -2767,12 +2767,29 @@ int AskAutoExit(void)
 int EnterMasterPasswordAndSet( int Res, HWND hWnd )\r
 {\r
        char buf[MAX_PASSWORD_LEN + 1];\r
+       // パスワードの入力欄を非表示\r
+       // 非表示にしたため新しいパスワードを2回入力させる\r
+       char buf1[MAX_PASSWORD_LEN + 1];\r
        char *p;\r
        int Flag;\r
 \r
        buf[0] = NUL;\r
        if( InputDialogBox(Res, hWnd, NULL, buf, MAX_PASSWORD_LEN + 1,\r
                &Flag, IDH_HELP_TOPIC_0000064) == YES){\r
+               // パスワードの入力欄を非表示\r
+               if(Res == newmasterpasswd_dlg)\r
+               {\r
+                       buf1[0] = NUL;\r
+                       if( InputDialogBox(Res, hWnd, NULL, buf1, MAX_PASSWORD_LEN + 1,\r
+                               &Flag, IDH_HELP_TOPIC_0000064) != YES){\r
+                               return 0;\r
+                       }\r
+                       if(strcmp(buf, buf1) != 0)\r
+                       {\r
+                               MessageBox(hWnd, MSGJPN325, "FFFTP", MB_OK | MB_ICONERROR);\r
+                               return 0;\r
+                       }\r
+               }\r
                /* 末尾の空白を削除 */\r
                RemoveTailingSpaces(buf);\r
                /* 先頭の空白を削除 */\r
index 59386b6..ff0fa7d 100644 (file)
 #define MSGJPN322              "Debugger was detected."\r
 #define MSGJPN323              "Failed to unload untrustworthy DLLs."\r
 #define MSGJPN324              "Failed to hook required functions to protect the process."\r
+#define MSGJPN325              "New master passwords are not identical."\r
index 405dfd8..4853403 100644 (file)
 #define MSGJPN322              "Debugger was detected."
 #define MSGJPN323              "Failed to unload untrustworthy DLLs."
 #define MSGJPN324              "Failed to hook required functions to protect the process."
+#define MSGJPN325              "New master passwords are not identical."
index b9345d8..53be6c7 100644 (file)
 #define MSGJPN322              "\xE3\x83\x87\xE3\x83\x90\xE3\x83\x83\xE3\x82\xAC\xE3\x81\x8C\xE6\xA4\x9C\xE5\x87\xBA\xE3\x81\x95\xE3\x82\x8C\xE3\x81\xBE\xE3\x81\x97\xE3\x81\x9F."\r
 #define MSGJPN323              "\xE4\xBF\xA1\xE9\xA0\xBC\xE3\x81\xA7\xE3\x81\x8D\xE3\x81\xAA\xE3\x81\x84\x44LL\xE3\x82\x92\xE3\x82\xA2\xE3\x83\xB3\xE3\x83\xAD\xE3\x83\xBC\xE3\x83\x89\xE3\x81\xA7\xE3\x81\x8D\xE3\x81\xBE\xE3\x81\x9B\xE3\x82\x93\xE3\x81\xA7\xE3\x81\x97\xE3\x81\x9F."\r
 #define MSGJPN324              "\xE3\x83\x97\xE3\x83\xAD\xE3\x82\xBB\xE3\x82\xB9\xE3\x81\xAE\xE4\xBF\x9D\xE8\xAD\xB7\xE3\x81\xAB\xE5\xBF\x85\xE8\xA6\x81\xE3\x81\xAA\xE9\x96\xA2\xE6\x95\xB0\xE3\x82\x92\xE3\x83\x95\xE3\x83\x83\xE3\x82\xAF\xE3\x81\xA7\xE3\x81\x8D\xE3\x81\xBE\xE3\x81\x9B\xE3\x82\x93\xE3\x81\xA7\xE3\x81\x97\xE3\x81\x9F."\r
+#define MSGJPN325              "\xE6\x96\xB0\xE3\x81\x97\xE3\x81\x84\xE3\x83\x9E\xE3\x82\xB9\xE3\x82\xBF\xE3\x83\xBC\xE3\x83\x91\xE3\x82\xB9\xE3\x83\xAF\xE3\x83\xBC\xE3\x83\x89\xE3\x81\x8C\xE4\xB8\x80\xE8\x87\xB4\xE3\x81\x97\xE3\x81\xBE\xE3\x81\x9B\xE3\x82\x93."\r
index 49442f5..8757091 100644 (file)
 #define MSGJPN322              "\83f\83o\83b\83K\82ª\8c\9f\8fo\82³\82ê\82Ü\82µ\82½."
 #define MSGJPN323              "\90M\97\8a\82Å\82«\82È\82¢DLL\82ð\83A\83\93\83\8d\81[\83h\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½."
 #define MSGJPN324              "\83v\83\8d\83Z\83X\82Ì\95Û\8cì\82É\95K\97v\82È\8aÖ\90\94\82ð\83t\83b\83N\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½."
+#define MSGJPN325              "\90V\82µ\82¢\83}\83X\83^\81[\83p\83X\83\8f\81[\83h\82ª\88ê\92v\82µ\82Ü\82¹\82ñ."
index 928f1b5..7c7c60f 100644 (file)
@@ -388,27 +388,69 @@ BOOL FindTrustedModuleSHA1Hash(void* pHash)
 // \83t\83@\83C\83\8b\82Ì\8f\90\96¼\82ð\8am\94F
 BOOL VerifyFileSignature(LPCWSTR Filename)
 {
+//     BOOL bResult;
+//     GUID g = WINTRUST_ACTION_GENERIC_VERIFY_V2;
+//     WINTRUST_FILE_INFO wfi;
+//     WINTRUST_DATA wd;
+//     LONG Error;
+//     bResult = FALSE;
+//     ZeroMemory(&wfi, sizeof(WINTRUST_FILE_INFO));
+//     wfi.cbStruct = sizeof(WINTRUST_FILE_INFO);
+//     wfi.pcwszFilePath = Filename;
+//     ZeroMemory(&wd, sizeof(WINTRUST_DATA));
+//     wd.cbStruct = sizeof(WINTRUST_DATA);
+//     wd.dwUIChoice = WTD_UI_NONE;
+//     wd.dwUnionChoice = WTD_CHOICE_FILE;
+//     wd.pFile = &wfi;
+//     Error = WinVerifyTrust((HWND)INVALID_HANDLE_VALUE, &g, &wd);
+//     if(Error == ERROR_SUCCESS)
+//             bResult = TRUE;
+//     else if((g_ProcessProtectionLevel & PROCESS_PROTECTION_EXPIRED) && Error == CERT_E_EXPIRED)
+//             bResult = TRUE;
+//     else if((g_ProcessProtectionLevel & PROCESS_PROTECTION_UNAUTHORIZED) && (Error == CERT_E_UNTRUSTEDROOT || Error == CERT_E_UNTRUSTEDCA))
+//             bResult = TRUE;
+//     return bResult;
        BOOL bResult;
-       GUID g = WINTRUST_ACTION_GENERIC_VERIFY_V2;
-       WINTRUST_FILE_INFO wfi;
-       WINTRUST_DATA wd;
-       LONG Error;
+       HCERTSTORE hStore;
+       PCCERT_CONTEXT pcc;
+       CERT_CHAIN_PARA ccp;
+       CERT_CHAIN_CONTEXT* pccc;
+       CERT_CHAIN_POLICY_PARA ccpp;
+       CERT_CHAIN_POLICY_STATUS ccps;
        bResult = FALSE;
-       ZeroMemory(&wfi, sizeof(WINTRUST_FILE_INFO));
-       wfi.cbStruct = sizeof(WINTRUST_FILE_INFO);
-       wfi.pcwszFilePath = Filename;
-       ZeroMemory(&wd, sizeof(WINTRUST_DATA));
-       wd.cbStruct = sizeof(WINTRUST_DATA);
-       wd.dwUIChoice = WTD_UI_NONE;
-       wd.dwUnionChoice = WTD_CHOICE_FILE;
-       wd.pFile = &wfi;
-       Error = WinVerifyTrust((HWND)INVALID_HANDLE_VALUE, &g, &wd);
-       if(Error == ERROR_SUCCESS)
-               bResult = TRUE;
-       else if((g_ProcessProtectionLevel & PROCESS_PROTECTION_EXPIRED) && Error == CERT_E_EXPIRED)
-               bResult = TRUE;
-       else if((g_ProcessProtectionLevel & PROCESS_PROTECTION_UNAUTHORIZED) && (Error == CERT_E_UNTRUSTEDROOT || Error == CERT_E_UNTRUSTEDCA))
-               bResult = TRUE;
+       if(CryptQueryObject(CERT_QUERY_OBJECT_FILE, Filename, CERT_QUERY_CONTENT_FLAG_ALL, CERT_QUERY_FORMAT_FLAG_ALL, 0, NULL, NULL, NULL, &hStore, NULL, NULL))
+       {
+               pcc = NULL;
+               while(!bResult && (pcc = CertEnumCertificatesInStore(hStore, pcc)))
+               {
+                       ZeroMemory(&ccp, sizeof(CERT_CHAIN_PARA));
+                       ccp.cbSize = sizeof(CERT_CHAIN_PARA);
+                       if(CertGetCertificateChain(NULL, pcc, NULL, NULL, &ccp, 0, NULL, &pccc))
+                       {
+                               ZeroMemory(&ccpp, sizeof(CERT_CHAIN_POLICY_PARA));
+                               ccpp.cbSize = sizeof(CERT_CHAIN_POLICY_PARA);
+                               if(g_ProcessProtectionLevel & PROCESS_PROTECTION_EXPIRED)
+                                       ccpp.dwFlags |= CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG;
+                               else if(g_ProcessProtectionLevel & PROCESS_PROTECTION_UNAUTHORIZED)
+                                       ccpp.dwFlags |= CERT_CHAIN_POLICY_ALLOW_UNKNOWN_CA_FLAG;
+                               ZeroMemory(&ccps, sizeof(CERT_CHAIN_POLICY_STATUS));
+                               ccps.cbSize = sizeof(CERT_CHAIN_POLICY_STATUS);
+                               if(CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_AUTHENTICODE, pccc, &ccpp, &ccps))
+                               {
+                                       if(ccps.dwError == ERROR_SUCCESS)
+                                       {
+                                               bResult = TRUE;
+                                               break;
+                                       }
+                               }
+                               CertFreeCertificateChain(pccc);
+                       }
+               }
+               while(pcc = CertEnumCertificatesInStore(hStore, pcc))
+               {
+               }
+               CertCloseStore(hStore, 0);
+       }
        return bResult;
 }
 
@@ -419,7 +461,6 @@ BOOL VerifyFileSignatureInCatalog(LPCWSTR Catalog, LPCWSTR Filename)
        GUID g = WINTRUST_ACTION_GENERIC_VERIFY_V2;
        WINTRUST_CATALOG_INFO wci;
        WINTRUST_DATA wd;
-       LONG Error;
        bResult = FALSE;
        if(VerifyFileSignature(Catalog))
        {
@@ -439,12 +480,7 @@ BOOL VerifyFileSignatureInCatalog(LPCWSTR Catalog, LPCWSTR Filename)
                                        wd.dwUIChoice = WTD_UI_NONE;
                                        wd.dwUnionChoice = WTD_CHOICE_CATALOG;
                                        wd.pCatalog = &wci;
-                                       Error = WinVerifyTrust((HWND)INVALID_HANDLE_VALUE, &g, &wd);
-                                       if(Error == ERROR_SUCCESS)
-                                               bResult = TRUE;
-                                       else if((g_ProcessProtectionLevel & PROCESS_PROTECTION_EXPIRED) && Error == CERT_E_EXPIRED)
-                                               bResult = TRUE;
-                                       else if((g_ProcessProtectionLevel & PROCESS_PROTECTION_UNAUTHORIZED) && (Error == CERT_E_UNTRUSTEDROOT || Error == CERT_E_UNTRUSTEDCA))
+                                       if(WinVerifyTrust((HWND)INVALID_HANDLE_VALUE, &g, &wd) == ERROR_SUCCESS)
                                                bResult = TRUE;
                                }
                                free(wci.pbCalculatedFileHash);