diff --git a/Common/BaseSock.cpp b/Common/BaseSock.cpp index dcb49b6..8c29ae0 100644 --- a/Common/BaseSock.cpp +++ b/Common/BaseSock.cpp @@ -370,7 +370,7 @@ bool CBaseSock::Connect(LPCWSTR HostName, USHORT PortNumber) Timeout.tv_sec = GetSendTimeoutSeconds(); - _itot_s(PortNumber, PortName, _countof(PortName), 10); + _itow_s(PortNumber, PortName, _countof(PortName), 10); ActualSocket = socket(AF_INET, SOCK_STREAM, 0); if (ActualSocket == INVALID_SOCKET) { diff --git a/Common/CertHelper.cpp b/Common/CertHelper.cpp index 5c6757f..2e448ea 100644 --- a/Common/CertHelper.cpp +++ b/Common/CertHelper.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #pragma comment(lib, "Cryptui.lib") #pragma comment(lib, "Dnsapi.lib") @@ -104,13 +105,13 @@ bool MatchCertificateName(PCCERT_CONTEXT pCertContext, LPCWSTR pszRequiredName) // Select, and return a handle to a server certificate located by name // Usually used for a best guess at a certificate to be used as the SSL certificate for a server -SECURITY_STATUS CertFindServerCertificateByName(PCCERT_CONTEXT & pCertContext, LPCTSTR pszSubjectName, bool fUserStore) +SECURITY_STATUS CertFindServerCertificateByName(PCCERT_CONTEXT & pCertContext, LPCWSTR pszSubjectName, bool fUserStore) { HCERTSTORE hCertStore{}; WCHAR pszFriendlyNameString[128]; WCHAR pszNameString[128]; - if (pszSubjectName == nullptr || _tcslen(pszSubjectName) == 0) + if (pszSubjectName == nullptr || wcsnlen(pszSubjectName, 1) == 0) { DebugMsg("**** No subject name specified!"); return E_POINTER; @@ -208,7 +209,7 @@ SECURITY_STATUS CertFindServerCertificateByName(PCCERT_CONTEXT & pCertContext, L // Select, and return a handle to a client certificate // We take a best guess at a certificate to be used as the SSL certificate for this client -SECURITY_STATUS CertFindClientCertificate(PCCERT_CONTEXT & pCertContext, const LPCTSTR pszSubjectName, bool fUserStore) +SECURITY_STATUS CertFindClientCertificate(PCCERT_CONTEXT & pCertContext, const LPCWSTR pszSubjectName, bool fUserStore) { HCERTSTORE hCertStore; WCHAR pszFriendlyNameString[128]; @@ -271,7 +272,7 @@ SECURITY_STATUS CertFindClientCertificate(PCCERT_CONTEXT & pCertContext, const L if (pCertContext) // We have a saved certificate context we no longer need, so free it CertFreeCertificateContext(pCertContext); pCertContext = CertDuplicateCertificateContext(pCertContextCurrent); - if (pszSubjectName && _tcscmp(pszNameString, pszSubjectName)) + if (pszSubjectName && wcsncmp(pszNameString, pszSubjectName, _countof(pszNameString))) DebugMsg(" Subject name does not match."); else { @@ -519,7 +520,7 @@ BOOL WINAPI ValidServerCert( CryptUIDlgSelectCertificate SelectCertificate = nullptr; -SECURITY_STATUS CertFindServerCertificateUI(PCCERT_CONTEXT & pCertContext, LPCTSTR pszSubjectName, bool fUserStore) +SECURITY_STATUS CertFindServerCertificateUI(PCCERT_CONTEXT & pCertContext, LPCWSTR pszSubjectName, bool fUserStore) { // Open a certificate store. HCERTSTORE hCertStore; @@ -610,7 +611,7 @@ SECURITY_STATUS CertFindCertificateBySignature(PCCERT_CONTEXT & pCertContext, ch DebugMsg("CertGetNameString failed getting friendly name."); return HRESULT_FROM_WIN32(GetLastError()); } - DebugMsg("CertFindCertificateBySignature found certificate '%S' is allowed to be used for server authentication.", (LPWSTR)ATL::CT2W(pszFriendlyNameString)); + DebugMsg("CertFindCertificateBySignature found certificate '%S' is allowed to be used for server authentication.", (LPWSTR)pszFriendlyNameString); if (CertCompareCertificateName(X509_ASN_ENCODING, &pCertContext->pCertInfo->Subject, &pCertContext->pCertInfo->Issuer)) DebugMsg("A self-signed certificate was found."); } diff --git a/Common/Include/CertHelper.h b/Common/Include/CertHelper.h index a6cc69b..ac437b6 100644 --- a/Common/Include/CertHelper.h +++ b/Common/Include/CertHelper.h @@ -5,13 +5,13 @@ bool MatchCertificateName(PCCERT_CONTEXT pCertContext, LPCWSTR pszRequiredName); HRESULT ShowCertInfo(PCCERT_CONTEXT pCertContext, std::wstring Title); HRESULT CertTrusted(PCCERT_CONTEXT pCertContext, const bool isClientCert); std::wstring GetCertName(PCCERT_CONTEXT pCertContext); -SECURITY_STATUS CertFindClientCertificate(PCCERT_CONTEXT & pCertContext, const LPCTSTR pszSubjectName = nullptr, bool fUserStore = true); +SECURITY_STATUS CertFindClientCertificate(PCCERT_CONTEXT & pCertContext, const LPCWSTR pszSubjectName = nullptr, bool fUserStore = true); SECURITY_STATUS CertFindFromIssuerList(PCCERT_CONTEXT & pCertContext, SecPkgContext_IssuerListInfoEx & IssuerListInfo, bool fUserStore = false); -SECURITY_STATUS CertFindServerCertificateUI(PCCERT_CONTEXT & pCertContext, LPCTSTR pszSubjectName, bool fUserStore = false); -SECURITY_STATUS CertFindServerCertificateByName(PCCERT_CONTEXT & pCertContext, LPCTSTR pszSubjectName, bool fUserStore = false); +SECURITY_STATUS CertFindServerCertificateUI(PCCERT_CONTEXT & pCertContext, LPCWSTR pszSubjectName, bool fUserStore = false); +SECURITY_STATUS CertFindServerCertificateByName(PCCERT_CONTEXT & pCertContext, LPCWSTR pszSubjectName, bool fUserStore = false); SECURITY_STATUS CertFindCertificateBySignature(PCCERT_CONTEXT & pCertContext, char const * const signature, bool fUserStore = false); -HRESULT CertFindByName(PCCERT_CONTEXT & pCertContext, const LPCTSTR pszSubjectName, bool fUserStore = false); +HRESULT CertFindByName(PCCERT_CONTEXT & pCertContext, const LPCWSTR pszSubjectName, bool fUserStore = false); // defined in source file CreateCertificate.cpp PCCERT_CONTEXT CreateCertificate(bool MachineCert = false, LPCWSTR Subject = nullptr, LPCWSTR FriendlyName = nullptr, LPCWSTR Description = nullptr, bool forClient = false); diff --git a/Common/Include/Utilities.h b/Common/Include/Utilities.h index f91fb33..440d98f 100644 --- a/Common/Include/Utilities.h +++ b/Common/Include/Utilities.h @@ -18,5 +18,5 @@ void DebugMsg(const WCHAR* pszFormat, ...); void DebugMsg(const CHAR* pszFormat, ...); bool IsUserAdmin(); std::wstring GetHostName(COMPUTER_NAME_FORMAT WhichName = ComputerNameDnsHostname); -std::wstring GetUserName(); +std::wstring GetCurrentUserName(); const char* const GetVersionText(); diff --git a/Common/Utilities.cpp b/Common/Utilities.cpp index bcaf7e5..5323256 100644 --- a/Common/Utilities.cpp +++ b/Common/Utilities.cpp @@ -50,8 +50,8 @@ std::wstring GetHostName(COMPUTER_NAME_FORMAT WhichName) return std::wstring(); } -// Utility function to return the user name I'm runing under -std::wstring GetUserName() +// Utility function to return the user name I'm running under +std::wstring GetCurrentUserName() { DWORD NameLength = 0; if (ERROR_SUCCESS == ::GetUserName(nullptr, &NameLength)) diff --git a/SSLClient/Include/SSLClient.h b/SSLClient/Include/SSLClient.h index eeef8cf..cb79a62 100644 --- a/SSLClient/Include/SSLClient.h +++ b/SSLClient/Include/SSLClient.h @@ -22,7 +22,7 @@ class CSSLClient void StartRecvTimer(); void StartSendTimer(); // Regular class interface - static PSecurityFunctionTable SSPI(); + static PSecurityFunctionTableW SSPI(); // Set up state for this connection HRESULT Initialize(LPCWSTR ServerName, const void * const lpBuf = nullptr, const int Len = 0); // Attributes @@ -32,13 +32,13 @@ class CSSLClient bool getServerCertTrusted() const; private: - static PSecurityFunctionTable g_pSSPI; + static PSecurityFunctionTableW g_pSSPI; CredentialHandle m_ClientCreds; CActiveSock * m_SocketStream; int m_LastError{ 0 }; bool m_encrypting = false; static HRESULT InitializeClass(); - SECURITY_STATUS SSPINegotiateLoop(WCHAR* ServerName); + SECURITY_STATUS SSPINegotiateLoop(LPCWCHAR ServerName); static const int MaxMsgSize = 16000; // Arbitrary but less than 16384 limit, including MaxExtraSize static const int MaxExtraSize = 50; // Also arbitrary, current header is 5 bytes, trailer 36 CHAR writeBuffer[MaxMsgSize + MaxExtraSize]{}; // Enough for a whole encrypted message diff --git a/SSLClient/SSLClient.cpp b/SSLClient/SSLClient.cpp index e864be3..39c8c53 100644 --- a/SSLClient/SSLClient.cpp +++ b/SSLClient/SSLClient.cpp @@ -32,7 +32,7 @@ CSSLClient::CSSLClient(CActiveSock * SocketStream) // Avoid using (or exporting) g_pSSPI directly to give us some flexibility in case we want // to change implementation later -PSecurityFunctionTable CSSLClient::SSPI() { return g_pSSPI; } +PSecurityFunctionTableW CSSLClient::SSPI() { return g_pSSPI; } // Set up the connection, including SSL handshake, certificate selection/validation // lpBuf and Len let you provide any data that's already been read @@ -69,7 +69,7 @@ HRESULT CSSLClient::Initialize(LPCWSTR ServerName, const void * const lpBuf, con else readBufferBytes = 0; // Perform SSL handshake - hr = SSPINegotiateLoop(ATL::CW2T(ServerName)); + hr = SSPINegotiateLoop(ServerName); if (FAILED(hr)) { DebugMsg("Couldn't connect"); @@ -418,7 +418,7 @@ int CSSLClient::Send(LPCVOID lpBuf, const size_t Len) // Negotiate a connection with the server, sending and receiving messages until the // negotiation succeeds or fails -SECURITY_STATUS CSSLClient::SSPINegotiateLoop(WCHAR* ServerName) +SECURITY_STATUS CSSLClient::SSPINegotiateLoop(LPCWCHAR ServerName) { int cbData; TimeStamp tsExpiry; @@ -453,7 +453,7 @@ SECURITY_STATUS CSSLClient::SSPINegotiateLoop(WCHAR* ServerName) #pragma warning (suppress: 4238) &m_ClientCreds.get(), nullptr, - ServerName, + const_cast(ServerName), dwSSPIFlags, 0, SECURITY_NATIVE_DREP, @@ -632,7 +632,7 @@ SECURITY_STATUS CSSLClient::SSPINegotiateLoop(WCHAR* ServerName) else { DebugMsg("Server Certificate returned"); - ServerCertNameMatches = MatchCertificateName(hServerCertContext.get(), ATL::CW2T(ServerName)); + ServerCertNameMatches = MatchCertificateName(hServerCertContext.get(), ServerName); hr = CertTrusted(hServerCertContext.get(), false); ServerCertTrusted = hr == S_OK; bool IsServerCertAcceptable = ServerCertAcceptable == nullptr; @@ -808,9 +808,12 @@ SECURITY_STATUS CSSLClient::SSPINegotiateLoop(WCHAR* ServerName) HRESULT CSSLClient::Disconnect(bool closeUnderlyingSocket) { - HRESULT hr = DisconnectSSL(); - if FAILED(hr) - return hr; + if (m_hContext) + { + HRESULT hr = DisconnectSSL(); + if FAILED(hr) + return hr; + } return closeUnderlyingSocket ? m_SocketStream->Disconnect() : S_OK; } diff --git a/SSLClient/SSLClient.vcxproj b/SSLClient/SSLClient.vcxproj index 10bc599..5861266 100644 --- a/SSLClient/SSLClient.vcxproj +++ b/SSLClient/SSLClient.vcxproj @@ -31,14 +31,14 @@ true Unicode v142 - Dynamic + false StaticLibrary true Unicode v142 - Dynamic + false StaticLibrary @@ -46,7 +46,7 @@ v142 true Unicode - Dynamic + false StaticLibrary @@ -54,7 +54,7 @@ v142 true Unicode - Dynamic + false diff --git a/SSLClient/framework.h b/SSLClient/framework.h index d2ec495..002f3e7 100644 --- a/SSLClient/framework.h +++ b/SSLClient/framework.h @@ -31,14 +31,16 @@ const bool debug = false; #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif -#include -#include // MFC core and standard components -#include +#include +#include #include +#pragma comment(lib, "Ws2_32.lib") + #define SECURITY_WIN32 #include #include // Standard C++ #include +typedef unsigned char byte; \ No newline at end of file diff --git a/SSLServer/Include/Listener.h b/SSLServer/Include/Listener.h index 4473b0b..f7294b8 100644 --- a/SSLServer/Include/Listener.h +++ b/SSLServer/Include/Listener.h @@ -7,7 +7,7 @@ class ISocketStream; class CListener { public: - enum ErrorType { + enum class ErrorType { NoError, UnknownError, SocketInuse, @@ -20,19 +20,19 @@ class CListener HANDLE m_hSocketEvents[FD_SETSIZE]{}; int m_iNumListenSockets{ 0 }; CCriticalSection m_WorkerCountLock; - CWinThread * m_ListenerThread{ nullptr }; - static UINT __cdecl Worker(LPVOID); - static UINT __cdecl ListenerWorker(LPVOID); + uintptr_t m_ListenerThread { 0 }; + static void __cdecl Worker(LPVOID); + static void __cdecl ListenerWorker(LPVOID); void Listen(); std::function m_actualwork; public: static void LogWarning(const WCHAR* const); static void LogWarning(const CHAR* const); int m_WorkerCount{ 0 }; - CEvent m_StopEvent{ FALSE, TRUE }; + CEvent m_StopEvent{ TRUE, FALSE }; // Initialize the listener ErrorType Initialize(int TCPSocket); - std::function SelectServerCert; + std::function SelectServerCert; std::function ClientCertAcceptable; void EndListening(); void BeginListening(std::function actualwork); diff --git a/SSLServer/Listener.cpp b/SSLServer/Listener.cpp index 6ff9de1..99aad66 100644 --- a/SSLServer/Listener.cpp +++ b/SSLServer/Listener.cpp @@ -29,24 +29,22 @@ CListener::~CListener() // This is the individual worker process, all it does is start, change its name to something useful, // then call the Lambda function passed in via the BeginListening method -UINT __cdecl CListener::Worker(void * v) +void __cdecl CListener::Worker(LPVOID v) { std::unique_ptr SSLServer(reinterpret_cast(v)); SetThreadName("Connection Worker"); // Invoke the caller provided function defining the work to do, passing an interface which // allows the user code to send and receive messages and so on. (SSLServer->GetListener()->m_actualwork)(SSLServer->GetSocketStream()); - return 0; } // Worker process for connection listening -UINT __cdecl CListener::ListenerWorker(LPVOID v) +void __cdecl CListener::ListenerWorker(LPVOID v) { auto * Listener = static_cast(v); // See _beginthread call for parameter definition SetThreadName("Listener"); Listener->Listen(); - return 0; } // Initialize the listener, set up the socket to listen on, or return an error @@ -56,7 +54,7 @@ CListener::ErrorType CListener::Initialize(int TCPSocket) WSADATA wsadata; if (WSAStartup(MAKEWORD(1, 1), &wsadata)) - return UnknownError; + return CListener::ErrorType::UnknownError; // Get list of addresses to listen on ADDRINFOT Hints, *AddrInfo, *AI; @@ -69,7 +67,7 @@ CListener::ErrorType CListener::Initialize(int TCPSocket) WCHAR MsgText[100]; StringCchPrintf(MsgText, _countof(MsgText), L"getaddressinfo error: %i", GetLastError()); LogWarning(MsgText); - return UnknownError; + return CListener::ErrorType::UnknownError; } // Create one or more passive sockets to listen on @@ -92,14 +90,14 @@ CListener::ErrorType CListener::Initialize(int TCPSocket) nullptr); // no name if (!(m_hSocketEvents[i])) - return UnknownError; + return CListener::ErrorType::UnknownError; // StringCchPrintf(MsgText, _countof(MsgText), L"::OnInit Created m_hSocketEvents[%d], handle=%d"), i, m_hSocketEvents[i]; // LogWarning(MsgText); m_iListenSockets[i] = WSASocket(AI->ai_family, SOCK_STREAM, 0, nullptr, 0, WSA_FLAG_OVERLAPPED); if (m_iListenSockets[i] == INVALID_SOCKET) - return SocketUnusable; + return CListener::ErrorType::SocketUnusable; // StringCchPrintf(MsgText, _countof(MsgText), L"::OnInit binding m_iListenSockets[%d] to sa_family=%u sa_data=%s len=%d"), i, AI->ai_addr->sa_family, AI->ai_addr->sa_data, AI->ai_addrlen; // LogWarning(MsgText); @@ -108,15 +106,15 @@ CListener::ErrorType CListener::Initialize(int TCPSocket) if (rc) { if (WSAGetLastError() == WSAEADDRINUSE) - return SocketInuse; + return CListener::ErrorType::SocketInuse; else - return SocketUnusable; + return CListener::ErrorType::SocketUnusable; } if (listen(m_iListenSockets[i], 10)) - return SocketUnusable; + return CListener::ErrorType::SocketUnusable; if (WSAEventSelect(m_iListenSockets[i], m_hSocketEvents[i], FD_ACCEPT)) - return SocketUnusable; + return CListener::ErrorType::SocketUnusable; i++; } @@ -125,32 +123,32 @@ CListener::ErrorType CListener::Initialize(int TCPSocket) // StringCchPrintf(MsgText, _countof(MsgText), L"::OnInit no errors, m_iNumListenSockets = %d"), m_iNumListenSockets; // LogWarning(MsgText); - return NoError; + return CListener::ErrorType::NoError; } // Start listening for connections, if a timeout is specified keep listening until then void CListener::BeginListening(std::function actualwork) { m_actualwork = actualwork; - m_ListenerThread = AfxBeginThread(ListenerWorker, this); + m_ListenerThread = _beginthread(ListenerWorker, 0, this); } void CListener::IncrementWorkerCount(int i) { - m_WorkerCountLock.Lock(); + m_WorkerCountLock.Enter(); m_WorkerCount += i; - m_WorkerCountLock.Unlock(); + m_WorkerCountLock.Leave(); } // Stop listening, tells the listener thread it can stop, then waits for it to terminate void CListener::EndListening() { - m_StopEvent.SetEvent(); + m_StopEvent.Set(); if (m_ListenerThread) { - WaitForSingleObject(m_ListenerThread->m_hThread, INFINITE); // Will auto delete + WaitForSingleObject((HANDLE)m_ListenerThread, INFINITE); // Will auto delete } - m_ListenerThread = nullptr; + m_ListenerThread = 0; } // Log a warning @@ -220,22 +218,22 @@ void CListener::Listen() auto SSLServer = CSSLServer::Create(iReadSocket, this); if (SSLServer && SSLServer->IsConnected) - AfxBeginThread(Worker, SSLServer); + _beginthread(Worker, 0, SSLServer); else delete SSLServer; iReadSocket = INVALID_SOCKET; } // Either we're done, or there has been a problem, wait for all the worker threads to terminate Sleep(500); - m_WorkerCountLock.Lock(); + m_WorkerCountLock.Enter(); while (m_WorkerCount) { - m_WorkerCountLock.Unlock(); + m_WorkerCountLock.Leave(); Sleep(1000); DebugMsg("Waiting for all workers to terminate: worker thread count = %i", m_WorkerCount); - m_WorkerCountLock.Lock(); + m_WorkerCountLock.Enter(); }; - m_WorkerCountLock.Unlock(); + m_WorkerCountLock.Leave(); if ((iReadSocket != NULL) && (iReadSocket != INVALID_SOCKET)) closesocket(iReadSocket); DebugMsg("End Listen method"); diff --git a/SSLServer/SSLServer.cpp b/SSLServer/SSLServer.cpp index 33e9b95..f040b18 100644 --- a/SSLServer/SSLServer.cpp +++ b/SSLServer/SSLServer.cpp @@ -42,7 +42,7 @@ CSSLServer::~CSSLServer() // Avoid using (or exporting) g_pSSPI directly to give us some flexibility in case we want // to change implementation later -PSecurityFunctionTable CSSLServer::SSPI() { return g_pSSPI; } +PSecurityFunctionTableW CSSLServer::SSPI() { return g_pSSPI; } // Creates an SSLServer in response to an incoming connection (a socket) detected by a CListener CSSLServer* CSSLServer::Create(SOCKET s, CListener* Listener) diff --git a/SSLServer/SSLServer.h b/SSLServer/SSLServer.h index f193406..b6a778e 100644 --- a/SSLServer/SSLServer.h +++ b/SSLServer/SSLServer.h @@ -26,7 +26,7 @@ class CSSLServer : public ISocketStream void StartSendTimer() override; ISocketStream* GetSocketStream(); - static PSecurityFunctionTable SSPI(); + static PSecurityFunctionTableW SSPI(); // Set up state for this connection HRESULT Initialize(const void * const lpBuf = nullptr, const size_t Len = 0); std::function SelectServerCert; @@ -40,7 +40,7 @@ class CSSLServer : public ISocketStream HRESULT ShutDownSSL(); CListener* m_Listener{ nullptr }; CredHandle hServerCreds{}; - static PSecurityFunctionTable g_pSSPI; + static PSecurityFunctionTableW g_pSSPI; std::unique_ptr m_SocketStream; int m_LastError{ 0 }; static HRESULT InitializeClass(); diff --git a/SSLServer/SSLServer.vcxproj b/SSLServer/SSLServer.vcxproj index 059e205..4b046f6 100644 --- a/SSLServer/SSLServer.vcxproj +++ b/SSLServer/SSLServer.vcxproj @@ -31,14 +31,14 @@ true v142 Unicode - Dynamic + false StaticLibrary true v142 Unicode - Dynamic + false StaticLibrary @@ -46,7 +46,7 @@ v142 true Unicode - Dynamic + false StaticLibrary @@ -54,7 +54,7 @@ v142 true Unicode - Dynamic + false diff --git a/SSLServer/framework.h b/SSLServer/framework.h index d2ec495..2c5c300 100644 --- a/SSLServer/framework.h +++ b/SSLServer/framework.h @@ -31,11 +31,12 @@ const bool debug = false; #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif -#include -#include // MFC core and standard components -#include +#include +#include +#include #include +#pragma comment(lib, "Ws2_32.lib") #define SECURITY_WIN32 #include #include diff --git a/Samples/SimpleClient/SimpleClient.cpp b/Samples/SimpleClient/SimpleClient.cpp index 1a3fc0a..6d35712 100644 --- a/Samples/SimpleClient/SimpleClient.cpp +++ b/Samples/SimpleClient/SimpleClient.cpp @@ -48,11 +48,13 @@ int main() cout << "Wrong number of characters sent" << endl; cout << "Listening for message from server" << endl; int len = 0; - char Msg[100]; + char Msg[22]; if (0 < (len = pSSLClient->Recv(Msg, sizeof(Msg)))) { - cout << "Received '" << string(Msg, len) << "'" << endl; - cout << "Shutting down" << endl; + cout << "Received '" << string(Msg, len); + if (len == sizeof(Msg)) // probably truncated + cout << "..."; + cout << "'" << endl << "Shutting down" << endl; } else cout << "Recv reported an error" << endl; diff --git a/Samples/SimpleClient/SimpleClient.vcxproj b/Samples/SimpleClient/SimpleClient.vcxproj index ce227a4..b53b2d5 100644 --- a/Samples/SimpleClient/SimpleClient.vcxproj +++ b/Samples/SimpleClient/SimpleClient.vcxproj @@ -1,6 +1,14 @@ + + Debug Ansi + Win32 + + + Debug Ansi + x64 + Debug Win32 @@ -32,6 +40,12 @@ v142 MultiByte + + Application + true + v142 + Unicode + Application false @@ -45,6 +59,12 @@ v142 MultiByte + + Application + true + v142 + Unicode + Application false @@ -60,12 +80,18 @@ + + + + + + @@ -73,9 +99,15 @@ true + + true + true + + true + false @@ -98,6 +130,22 @@ true + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\..\SSLClient\Include;..\..\Common\Include + + + Console + true + + @@ -114,6 +162,22 @@ true + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\..\SSLClient\Include;..\..\Common\Include + + + Console + true + + diff --git a/Samples/StreamClient/StreamClient.cpp b/Samples/StreamClient/StreamClient.cpp index ac26460..2324cd8 100644 --- a/Samples/StreamClient/StreamClient.cpp +++ b/Samples/StreamClient/StreamClient.cpp @@ -66,7 +66,7 @@ SECURITY_STATUS SelectClientCertificate(PCCERT_CONTEXT & pCertContext, SecPkgCon if (!pCertContext) { cout << ", none found, creating one"; - pCertContext = CreateCertificate(false, (GetUserName() + L" at " + GetHostName()).c_str(), L"StreamSSL client", nullptr, true); + pCertContext = CreateCertificate(false, (GetCurrentUserName() + L" at " + GetHostName()).c_str(), L"StreamSSL client", nullptr, true); if (pCertContext) Status = S_OK; else diff --git a/Samples/StreamClient/StreamClient.vcxproj b/Samples/StreamClient/StreamClient.vcxproj index aa0b17b..0bfd964 100644 --- a/Samples/StreamClient/StreamClient.vcxproj +++ b/Samples/StreamClient/StreamClient.vcxproj @@ -1,6 +1,14 @@ + + Debug Ansi + Win32 + + + Debug Ansi + x64 + Debug Win32 @@ -34,6 +42,13 @@ Unicode Dynamic + + Application + true + v142 + MultiByte + Dynamic + Application false @@ -49,6 +64,13 @@ Unicode Dynamic + + Application + true + v142 + MultiByte + Dynamic + Application false @@ -65,12 +87,18 @@ + + + + + + @@ -78,9 +106,15 @@ true + + true + true + + true + false @@ -109,6 +143,28 @@ ..\..\Common\Include + + + Use + Level4 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + ..\..\SSLClient\Include;..\..\Common\Include + stdcpplatest + true + true + + + Console + true + + + ..\..\Common\Include + + Use @@ -131,6 +187,28 @@ ..\..\Common\Include + + + Use + Level4 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + ..\..\SSLClient\Include;..\..\Common\Include + stdcpplatest + true + true + + + Console + true + + + ..\..\Common\Include + + Use @@ -198,7 +276,9 @@ Create + Create Create + Create Create Create diff --git a/Samples/StreamServer/StreamServer.cpp b/Samples/StreamServer/StreamServer.cpp index 6f205d0..bb97c76 100644 --- a/Samples/StreamServer/StreamServer.cpp +++ b/Samples/StreamServer/StreamServer.cpp @@ -14,7 +14,7 @@ using namespace std; // This method is called when the first client tries to connect in order to allow a certificate to be selected to send to the client // It has to wait for the client connect request because the client tells the server what identity it expects it to present // This is called SNI (Server Name Indication) and it is a relatively new (it began to become available about 2005) SSL/TLS feature -SECURITY_STATUS SelectServerCert(PCCERT_CONTEXT & pCertContext, LPCTSTR pszSubjectName) +SECURITY_STATUS SelectServerCert(PCCERT_CONTEXT & pCertContext, LPCWSTR pszSubjectName) { SECURITY_STATUS status = SEC_E_INVALID_HANDLE; @@ -48,11 +48,11 @@ bool ClientCertAcceptable(PCCERT_CONTEXT pCertContext, const bool trusted) // This function simply runs arbitrary code and returns process information to the caller, it's just a handy utility function bool RunApp(std::wstring app, PROCESS_INFORMATION& pi) { // Not strictly needed but it makes testing easier - STARTUPINFO si = {}; + STARTUPINFOW si = {}; si.cb = sizeof si; ZeroMemory(&pi, sizeof(pi)); #pragma warning(suppress:6335) - if (CreateProcess(nullptr, &app[0], nullptr, FALSE, 0, CREATE_NEW_CONSOLE, nullptr, nullptr, &si, &pi)) + if (CreateProcessW(nullptr, &app[0], nullptr, FALSE, 0, CREATE_NEW_CONSOLE, nullptr, nullptr, &si, &pi)) return true; else { @@ -65,7 +65,7 @@ void RunClient(std::wstring toHost = L"", PROCESS_INFORMATION * ppi = nullptr) { cout << "Initiating a client instance for testing.\n" << endl; WCHAR acPathName[MAX_PATH + 1]; - GetModuleFileName(nullptr, acPathName, _countof(acPathName)); + GetModuleFileNameW(nullptr, acPathName, _countof(acPathName)); std::wstring appName(acPathName); const auto len = appName.find_last_of(L'\\'); appName = appName.substr(0, len + 1) + L"StreamClient.exe " + toHost; diff --git a/Samples/StreamServer/StreamServer.vcxproj b/Samples/StreamServer/StreamServer.vcxproj index 25f75c1..f056774 100644 --- a/Samples/StreamServer/StreamServer.vcxproj +++ b/Samples/StreamServer/StreamServer.vcxproj @@ -1,6 +1,14 @@ + + Debug Ansi + Win32 + + + Debug Ansi + x64 + Debug Win32 @@ -34,6 +42,13 @@ Unicode Dynamic + + Application + true + v142 + MultiByte + Dynamic + Application false @@ -49,6 +64,13 @@ Unicode Dynamic + + Application + true + v142 + MultiByte + Dynamic + Application false @@ -65,12 +87,18 @@ + + + + + + @@ -78,9 +106,15 @@ true + + true + true + + true + false @@ -109,6 +143,28 @@ ..\..\Common\Include + + + Use + Level4 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + ..\..\SSLServer\Include;..\..\Common\Include + stdcpplatest + true + true + + + Console + true + + + ..\..\Common\Include + + Use @@ -131,6 +187,28 @@ ..\..\Common\Include + + + Use + Level4 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + ..\..\SSLServer\Include;..\..\Common\Include + stdcpplatest + true + true + + + Console + true + + + ..\..\Common\Include + + Use @@ -197,7 +275,9 @@ Create + Create Create + Create Create Create diff --git a/StreamSSL.sln b/StreamSSL.sln index 6926013..30a28c8 100644 --- a/StreamSSL.sln +++ b/StreamSSL.sln @@ -22,12 +22,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleClient", "Samples\Sim EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug Ansi|Win32 = Debug Ansi|Win32 + Debug Ansi|x64 = Debug Ansi|x64 Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Debug Ansi|Win32.ActiveCfg = Debug|Win32 + {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Debug Ansi|Win32.Build.0 = Debug|Win32 + {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Debug Ansi|x64.ActiveCfg = Debug|x64 + {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Debug Ansi|x64.Build.0 = Debug|x64 {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Debug|Win32.ActiveCfg = Debug|Win32 {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Debug|Win32.Build.0 = Debug|Win32 {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Debug|x64.ActiveCfg = Debug|x64 @@ -36,6 +42,10 @@ Global {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Release|Win32.Build.0 = Release|Win32 {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Release|x64.ActiveCfg = Release|x64 {71D079B7-91C6-4CA2-8BFE-E369835DA8F3}.Release|x64.Build.0 = Release|x64 + {287B68D2-7381-4E78-AC72-79A49738228D}.Debug Ansi|Win32.ActiveCfg = Debug|Win32 + {287B68D2-7381-4E78-AC72-79A49738228D}.Debug Ansi|Win32.Build.0 = Debug|Win32 + {287B68D2-7381-4E78-AC72-79A49738228D}.Debug Ansi|x64.ActiveCfg = Debug|x64 + {287B68D2-7381-4E78-AC72-79A49738228D}.Debug Ansi|x64.Build.0 = Debug|x64 {287B68D2-7381-4E78-AC72-79A49738228D}.Debug|Win32.ActiveCfg = Debug|Win32 {287B68D2-7381-4E78-AC72-79A49738228D}.Debug|Win32.Build.0 = Debug|Win32 {287B68D2-7381-4E78-AC72-79A49738228D}.Debug|x64.ActiveCfg = Debug|x64 @@ -44,6 +54,10 @@ Global {287B68D2-7381-4E78-AC72-79A49738228D}.Release|Win32.Build.0 = Release|Win32 {287B68D2-7381-4E78-AC72-79A49738228D}.Release|x64.ActiveCfg = Release|x64 {287B68D2-7381-4E78-AC72-79A49738228D}.Release|x64.Build.0 = Release|x64 + {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Debug Ansi|Win32.ActiveCfg = Debug Ansi|Win32 + {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Debug Ansi|Win32.Build.0 = Debug Ansi|Win32 + {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Debug Ansi|x64.ActiveCfg = Debug Ansi|x64 + {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Debug Ansi|x64.Build.0 = Debug Ansi|x64 {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Debug|Win32.ActiveCfg = Debug|Win32 {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Debug|Win32.Build.0 = Debug|Win32 {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Debug|x64.ActiveCfg = Debug|x64 @@ -52,6 +66,10 @@ Global {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Release|Win32.Build.0 = Release|Win32 {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Release|x64.ActiveCfg = Release|x64 {144CCC0E-0CE9-42D2-887B-4210DEAA2BC6}.Release|x64.Build.0 = Release|x64 + {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Debug Ansi|Win32.ActiveCfg = Debug Ansi|Win32 + {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Debug Ansi|Win32.Build.0 = Debug Ansi|Win32 + {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Debug Ansi|x64.ActiveCfg = Debug Ansi|x64 + {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Debug Ansi|x64.Build.0 = Debug Ansi|x64 {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Debug|Win32.ActiveCfg = Debug|Win32 {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Debug|Win32.Build.0 = Debug|Win32 {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Debug|x64.ActiveCfg = Debug|x64 @@ -60,6 +78,10 @@ Global {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Release|Win32.Build.0 = Release|Win32 {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Release|x64.ActiveCfg = Release|x64 {6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Release|x64.Build.0 = Release|x64 + {A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug Ansi|Win32.ActiveCfg = Debug Ansi|Win32 + {A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug Ansi|Win32.Build.0 = Debug Ansi|Win32 + {A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug Ansi|x64.ActiveCfg = Debug Ansi|x64 + {A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug Ansi|x64.Build.0 = Debug Ansi|x64 {A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug|Win32.ActiveCfg = Debug|Win32 {A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug|Win32.Build.0 = Debug|Win32 {A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug|x64.ActiveCfg = Debug|x64