-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcertview.cpp
205 lines (166 loc) · 6.18 KB
/
certview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//****************************************************************************
//
// Copyright (c) ALTAP, spol. s r.o. All rights reserved.
//
// This is a part of the Altap Salamander SDK library.
//
// The SDK is provided "AS IS" and without warranty of any kind and
// ALTAP EXPRESSLY DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE and NON-INFRINGEMENT.
//
//****************************************************************************
#include "precomp.h"
#include "viewer.h"
#include <openssl/opensslv.h>
// plugin interface instance, its methods are invoked from Salamander
CPluginInterface PluginInterface;
// plugin extension interface for CPluginInterface
CPluginInterfaceForViewer InterfaceForViewer;
// global data
const char *PluginNameEN = "CertView"; // not translated plugin name, used before loading language module + for debug stuff
const char *PluginNameShort = "CERTVIEW"; // plugin name (short form, no spaces)
// ConfigVersion: 0 - no configuration read from Registry (plugin was just installed),
// 1 - the first version of configuration
int ConfigVersion = 0; // version of read configuration from registry (version description see above)
#define CURRENT_CONFIG_VERSION 1 // current version of configuration (saved to registry upon plugin unload)
const char *CONFIG_VERSION = "Version";
HINSTANCE DLLInstance = NULL; // handle to SPL - language independent resources
HINSTANCE HLanguage = NULL; // handle to SLG - language dependent resources
// Salamander general interface - valid from plugin start to end
CSalamanderGeneralAbstract *SalamanderGeneral = NULL;
// debugging extensions "dbg.h"
CSalamanderDebugAbstract *SalamanderDebug = NULL;
// definition of a variable from "spl_com.h"
int SalamanderVersion = 0;
// interface for modified Windows controls, used in Salamander
CSalamanderGUIAbstract *SalamanderGUI = NULL;
// DLL entry point
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
DLLInstance = hinstDLL;
INITCOMMONCONTROLSEX initCtrls;
initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
initCtrls.dwICC = ICC_BAR_CLASSES;
if (!InitCommonControlsEx(&initCtrls))
{
MessageBox(NULL, "InitCommonControlsEx failed!", "Error", MB_OK | MB_ICONERROR);
return FALSE; // DLL won't start
}
}
return TRUE; // DLL can be loaded
}
// ****************************************************************************
char *LoadStr(int resID)
{
return SalamanderGeneral->LoadStr(HLanguage, resID);
}
void OnAbout(HWND hParent)
{
char buf[1000];
_snprintf_s(buf, _TRUNCATE,
"%s " VERSINFO_VERSION "\n\n"
VERSINFO_COPYRIGHT "\n"
VERSINFO_COPYRIGHT_OPENSSL "\n\n"
"%s",
LoadStr(IDS_PLUGINNAME),
OPENSSL_VERSION_STR,
LoadStr(IDS_PLUGIN_DESCRIPTION));
SalamanderGeneral->SalMessageBox(hParent, buf, LoadStr(IDS_ABOUT), MB_OK | MB_ICONINFORMATION);
}
//
// ****************************************************************************
// SalamanderPluginGetReqVer
//
int WINAPI SalamanderPluginGetReqVer()
{
return LAST_VERSION_OF_SALAMANDER;
}
//
// ****************************************************************************
// SalamanderPluginEntry
//
CPluginInterfaceAbstract * WINAPI SalamanderPluginEntry(CSalamanderPluginEntryAbstract *salamander)
{
// setup SalamanderDebug for "dbg.h"
SalamanderDebug = salamander->GetSalamanderDebug();
// setup SalamanderVersion for "spl_com.h"
SalamanderVersion = salamander->GetVersion();
HANDLES_CAN_USE_TRACE();
CALL_STACK_MESSAGE1("SalamanderPluginEntry()");
// this plugin was made for current version of Salamander or higher
if (SalamanderVersion < LAST_VERSION_OF_SALAMANDER)
{ // refuse older version
MessageBox(salamander->GetParentWindow(),
REQUIRE_LAST_VERSION_OF_SALAMANDER,
PluginNameEN, MB_OK | MB_ICONERROR);
return NULL;
}
// load language module (.slg)
HLanguage = salamander->LoadLanguageModule(salamander->GetParentWindow(), PluginNameEN);
if (HLanguage == NULL)
return NULL;
// get general interface of Salamander
SalamanderGeneral = salamander->GetSalamanderGeneral();
// get interface with modified Windows controls used in Salamander
SalamanderGUI = salamander->GetSalamanderGUI();
// setup help file name
SalamanderGeneral->SetHelpFileName("certview.chm");
if (!InitViewer())
return NULL; // error
// setup basic info about the plugin
salamander->SetBasicPluginData(LoadStr(IDS_PLUGINNAME), FUNCTION_VIEWER,
VERSINFO_VERSION_NO_PLATFORM, VERSINFO_COPYRIGHT, LoadStr(IDS_PLUGIN_DESCRIPTION),
PluginNameShort, NULL, NULL);
// setup plugin home-page URL
salamander->SetPluginHomePageURL(LoadStr(IDS_PLUGIN_HOME));
// test SetPluginBugReportInfo
SalamanderGeneral->SetPluginBugReportInfo(LoadStr(IDS_PLUGIN_BUGREP), LoadStr(IDS_PLUGIN_EMAIL));
return &PluginInterface;
}
//
// ****************************************************************************
// CPluginInterface
//
void WINAPI
CPluginInterface::About(HWND parent)
{
OnAbout(parent);
}
BOOL WINAPI
CPluginInterface::Release(HWND parent, BOOL force)
{
CALL_STACK_MESSAGE2("CPluginInterface::Release(, %d)", force);
ReleaseViewer();
return TRUE;
}
void WINAPI
CPluginInterface::Connect(HWND parent, CSalamanderConnectAbstract *salamander)
{
CALL_STACK_MESSAGE1("CPluginInterface::Connect(,)");
// supported file extensions:
salamander->AddViewer("*.pem;*.key;*.pub;*.crl;*.csr;" // common PEM certificates
"*.der;" // DER certificates
"*.crt;*.cer;*.cert;" // common certificates, can be both PEM or DER
"*.tsq;*.tsr;" // timestamping authority - query and response
"*.req;*.res;*.ors;" // OCSP - request and response
"*.p7b;*.p7s;*.p7r;*.spc;" // PKCS#7
"*.p8;*.pk8;" // PKCS#8
"*.p12;*.pfx", // PKCS#12
FALSE);
}
void WINAPI
CPluginInterface::ClearHistory(HWND parent)
{
// ViewerWindowQueue.BroadcastMessage(WM_USER_CLEARHISTORY, 0, 0);
}
void CPluginInterface::Event(int event, DWORD param)
{
}
CPluginInterfaceForViewerAbstract * WINAPI
CPluginInterface::GetInterfaceForViewer()
{
return &InterfaceForViewer;
}