Skip to content

Commit ab87208

Browse files
committed
Add option to verify integrity & authenticity of server-returned XML(XMLDsig)
Add "-chkCert4InfoXML" & "-chkCertKeyId4XML=" options to verify the integrity & authenticity of XML responses (XMLDsig) returned by server, preventing them from being altered or hijacked. Close #102
1 parent 14b6a1a commit ab87208

File tree

4 files changed

+620
-5
lines changed

4 files changed

+620
-5
lines changed

src/Common.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,43 @@
1818

1919
#include <string>
2020

21+
class ScopedCOMInit final // never use this in DllMain
22+
{
23+
public:
24+
ScopedCOMInit() {
25+
HRESULT hr = ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); // attempt STA init 1st (older CoInitialize(NULL))
26+
27+
if (hr == RPC_E_CHANGED_MODE)
28+
{
29+
hr = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED); // STA init failed, switch to MTA
30+
}
31+
32+
if (SUCCEEDED(hr))
33+
{
34+
// S_OK or S_FALSE, both needs subsequent CoUninitialize()
35+
_bInitialized = true;
36+
}
37+
}
38+
39+
~ScopedCOMInit() {
40+
if (_bInitialized)
41+
{
42+
_bInitialized = false;
43+
::CoUninitialize();
44+
}
45+
}
46+
47+
bool isInitialized() const {
48+
return _bInitialized;
49+
}
50+
51+
private:
52+
bool _bInitialized = false;
53+
54+
ScopedCOMInit(const ScopedCOMInit&) = delete;
55+
ScopedCOMInit& operator=(const ScopedCOMInit&) = delete;
56+
};
57+
2158
void expandEnv(std::wstring& s);
2259
std::wstring getDateTimeStrFrom(const std::wstring& dateTimeFormat, const SYSTEMTIME& st);
2360
void writeLog(const wchar_t* logFileName, const wchar_t* logSuffix, const wchar_t* log2write);
@@ -27,4 +64,4 @@ std::string getFileContentA(const char* file2read);
2764
std::wstring GetLastErrorAsString(DWORD errorCode);
2865
std::wstring stringToUpper(std::wstring strToConvert);
2966
std::wstring stringToLower(std::wstring strToConvert);
30-
std::wstring stringReplace(std::wstring subject, const std::wstring& search, const std::wstring& replace);
67+
std::wstring stringReplace(std::wstring subject, const std::wstring& search, const std::wstring& replace);

0 commit comments

Comments
 (0)