diff --git a/PowerEditor/src/MISC/Common/verifySignedfile.cpp b/PowerEditor/src/MISC/Common/verifySignedfile.cpp index 5e4107bac..2553d9718 100644 --- a/PowerEditor/src/MISC/Common/verifySignedfile.cpp +++ b/PowerEditor/src/MISC/Common/verifySignedfile.cpp @@ -46,7 +46,8 @@ bool VerifySignedLibrary(const wstring& filepath, const wstring& cert_subject, const wstring& cert_display_name, bool doCheckRevocation, - bool doCheckChainOfTrust) + bool doCheckChainOfTrust, + bool displayErrorMessage) { wstring display_name; wstring key_id_hex; @@ -228,15 +229,19 @@ bool VerifySignedLibrary(const wstring& filepath, display_name = display_name_buffer.get(); } catch (const wstring& s) { - ::MessageBox(NULL, s.c_str(), TEXT("DLL signature verification failed"), MB_ICONERROR); + if (displayErrorMessage) + ::MessageBox(NULL, s.c_str(), TEXT("DLL signature verification failed"), MB_ICONERROR); OutputDebugString(TEXT("VerifyLibrary: error while getting certificate informations\n")); status = false; } catch (...) { // Unknown error OutputDebugString(TEXT("VerifyLibrary: error while getting certificate informations\n")); - wstring errMsg(TEXT("Unknown exception occurred. ")); - errMsg += GetLastErrorAsString(GetLastError()); - ::MessageBox(NULL, errMsg.c_str(), TEXT("DLL signature verification failed"), MB_ICONERROR); + if (displayErrorMessage) + { + wstring errMsg(TEXT("Unknown exception occurred. ")); + errMsg += GetLastErrorAsString(GetLastError()); + ::MessageBox(NULL, errMsg.c_str(), TEXT("DLL signature verification failed"), MB_ICONERROR); + } status = false; } diff --git a/PowerEditor/src/MISC/Common/verifySignedfile.h b/PowerEditor/src/MISC/Common/verifySignedfile.h index d9d10d042..74db47eee 100644 --- a/PowerEditor/src/MISC/Common/verifySignedfile.h +++ b/PowerEditor/src/MISC/Common/verifySignedfile.h @@ -60,9 +60,14 @@ #include +#define NPP_COMPONENT_SIGNER_DISPLAY_NAME TEXT("Notepad++") +#define NPP_COMPONENT_SIGNER_SUBJECT TEXT("C=FR, S=Ile-de-France, L=Saint Cloud, O=\"Notepad++\", CN=\"Notepad++\"") +#define NPP_COMPONENT_SIGNER_KEY_ID TEXT("42C4C5846BB675C74E2B2C90C69AB44366401093") + bool VerifySignedLibrary(const std::wstring& filepath, const std::wstring& key_id_hex, const std::wstring& cert_subject, const std::wstring& display_name, bool doCheckRevocation, - bool doCheckChainOfTrust); + bool doCheckChainOfTrust, + bool displayErrorMessage = true); diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index 6eb878087..7ebb69120 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -500,7 +500,7 @@ void PluginsManager::addInMenuFromPMIndex(int i) HMENU PluginsManager::setMenu(HMENU hMenu, const TCHAR *menuName, bool enablePluginAdmin) { - if (hasPlugins()) + if (hasPlugins() || enablePluginAdmin) { const TCHAR *nom_menu = (menuName && menuName[0])?menuName:TEXT("&Plugins"); size_t nbPlugin = _pluginInfos.size(); diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 2c842f911..1dc606937 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -536,7 +536,7 @@ LRESULT Notepad_plus::init(HWND hwnd) } //Plugin menu - bool enablePluginAdmin = _pluginsAdminDlg.listExist(); + bool enablePluginAdmin = _pluginsAdminDlg.isListValide(); _pluginsAdminDlg.setPluginsManager(&_pluginsManager); _pluginsManager.setMenu(_mainMenuHandle, NULL, enablePluginAdmin); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 3baa5d17b..46586a1d9 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -173,10 +173,6 @@ LanguageName ScintillaEditView::langNames[L_EXTERNAL+1] = { //const int MASK_GREEN = 0x00FF00; //const int MASK_BLUE = 0x0000FF; -#define SCINTILLA_SIGNER_DISPLAY_NAME TEXT("Notepad++") -#define SCINTILLA_SIGNER_SUBJECT TEXT("C=FR, S=Ile-de-France, L=Saint Cloud, O=\"Notepad++\", CN=\"Notepad++\"") -#define SCINTILLA_SIGNER_KEY_ID TEXT("42C4C5846BB675C74E2B2C90C69AB44366401093") - int getNbDigits(int aNum, int base) { @@ -210,7 +206,7 @@ HMODULE loadSciLexerDll() // This is helpful for developers to skip signature checking // while analyzing issue or modifying the lexer dll #ifndef _DEBUG - bool isOK = VerifySignedLibrary(sciLexerPath, SCINTILLA_SIGNER_KEY_ID, SCINTILLA_SIGNER_SUBJECT, SCINTILLA_SIGNER_DISPLAY_NAME, false, false); + bool isOK = VerifySignedLibrary(sciLexerPath, NPP_COMPONENT_SIGNER_KEY_ID, NPP_COMPONENT_SIGNER_SUBJECT, NPP_COMPONENT_SIGNER_DISPLAY_NAME, false, false); if (!isOK) { diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp index 4a2467a15..5fef02b92 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp @@ -40,6 +40,7 @@ #include "Processus.h" #include "PluginsManager.h" #include "md5.h" +#include "verifySignedFile.h" using namespace std; using nlohmann::json; @@ -582,55 +583,45 @@ PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const gen typedef const char * (__cdecl * PFUNCGETPLUGINLIST)(); -bool PluginsAdminDlg::listExist() -{ -#ifdef DEBUG // if not debug, then it's release - // load from nppPluginList.json instead of nppPluginList.dll - generic_string nppPluginListPath = TEXT("C:\\tmp\\nppPluginList.json"); +bool PluginsAdminDlg::isListValide() +{ + if (!::PathFileExists(NPP_PLUGIN_LIST_PATH)) + { + return false; + } + +#ifdef DEBUG // if not debug, then it's release + + return true; #else //RELEASE -#ifdef _WIN64 - generic_string nppPluginListPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\x64\\Debug\\nppPluginList.dll"); -#else - generic_string nppPluginListPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\Debug\\nppPluginList.dll"); -#endif + // check the signature on default location : %APPDATA%\Notepad++\plugins\config\pl\nppPluginList.dll or NPP_INST_DIR\plugins\config\pl\nppPluginList.dll + + bool isOK = VerifySignedLibrary(NPP_PLUGIN_LIST_PATH, NPP_COMPONENT_SIGNER_KEY_ID, NPP_COMPONENT_SIGNER_SUBJECT, NPP_COMPONENT_SIGNER_DISPLAY_NAME, false, false, false); + return isOK; #endif - return ::PathFileExists(nppPluginListPath.c_str()) == TRUE; } bool PluginsAdminDlg::updateListAndLoadFromJson() { try { + if (!isListValide()) + return false; + json j; #ifdef DEBUG // if not debug, then it's release // load from nppPluginList.json instead of nppPluginList.dll - generic_string nppPluginListJsonPath = TEXT("C:\\tmp\\nppPluginList.json"); - - if (!::PathFileExists(nppPluginListJsonPath.c_str())) - { - ::MessageBox(NULL, TEXT("The file doesn't exist"), nppPluginListJsonPath.c_str(), MB_OK); - return false; - } - - ifstream nppPluginListJson(nppPluginListJsonPath); + ifstream nppPluginListJson(NPP_PLUGIN_LIST_PATH); nppPluginListJson >> j; #else //RELEASE -#ifdef _WIN64 - generic_string nppPluginListDllPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\x64\\Debug\\nppPluginList.dll"); -#else - generic_string nppPluginListDllPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\Debug\\nppPluginList.dll"); -#endif - - // check the signature on default location : %APPDATA%\Notepad++\plugins\config\pl\nppPluginList.dll or NPP_INST_DIR\plugins\config\pl\nppPluginList.dll - - HINSTANCE hLib = ::LoadLibrary(nppPluginListDllPath.c_str()); + HINSTANCE hLib = ::LoadLibrary(NPP_PLUGIN_LIST_PATH); if (!hLib) { // Error treatment diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h index c0b90d3a4..9978ff8ab 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h @@ -28,6 +28,21 @@ #pragma once +#ifdef DEBUG // if not debug, then it's release + +// load from nppPluginList.json instead of nppPluginList.dll +#define NPP_PLUGIN_LIST_PATH TEXT("C:\\tmp\\nppPluginList.json") + +#else //RELEASE + +#ifdef _WIN64 +#define NPP_PLUGIN_LIST_PATH TEXT("C:\\sources\\nppPluginList\\vcxproj\\x64\\Debug\\nppPluginList.dll") +#else +#define NPP_PLUGIN_LIST_PATH TEXT("C:\\sources\\nppPluginList\\vcxproj\\Debug\\nppPluginList.dll") +#endif + +#endif + #include "StaticDialog.h" #include "pluginsAdminRes.h" #include "TabBar.h" @@ -148,7 +163,7 @@ public : display(); }; - bool listExist(); + bool isListValide(); void switchDialog(int indexToSwitch); void setPluginsManager(PluginsManager *pluginsManager) { _pPluginsManager = pluginsManager; };