I'm trying to implement an SSL handshake in C++ x64 unicode in Windows using winsock, schannel, security etc. Example host is google.com.
I created a SOCKET and could connect via WSAConnectByNameW.
I'm setting my SCHANNEL parameters as followed:
SCHANNEL_CRED *cred = new SCHANNEL_CRED;
cred->dwVersion = SCHANNEL_CRED_VERSION;
cred->dwFlags = SCH_USE_STRONG_CRYPTO | SCH_CRED_AUTO_CRED_VALIDATION| SCH_CRED_NO_DEFAULT_CREDS;
cred->grbitEnabledProtocols = SP_PROT_TLS1_2;
I want to get the handle using AcquireCredentialsHandleW (passing UNISP_NAME):
SECURITY_STATUS secstatus = AcquireCredentialsHandleW(NULL, UNISP_NAME, SECPKG_CRED_OUTBOUND, NULL, &cred, NULL, NULL, &handle, NULL);
Which fails for some reason due to incompatible data types:
""const wchar_t *"" --> ""LPWSTR""
Btw. Handle is just a CredHandle here.
I'm using unicode so I thought I could use UNISP_NAME since it's a 0 terminated string. I tried converting the string into an LPWSTR. Which is just an pointer to a 0 terminated string, right?
std::wstring service = L"Microsoft Unified Security Protocol Provider";
LPWSTR servicePtr = &service[0];
And pass it to the function:
SECURITY_STATUS secstatus = AcquireCredentialsHandleW(NULL, servicePtr, SECPKG_CRED_OUTBOUND, NULL, &cred, NULL, NULL, &handle, NULL);
But it doesn't seem to work. I don't get it. What's my problem here? Why can't I get the handle? Why does the function (AcquireCredentialsHandleW) does not accept its own pre-coded parameters even in the correct encoding?
Thanks in advance.
PS.: I want to try it without openssl or curl as far as I can make it ^^
Tried switching to multibyte. Same problem but not for wchar but chars. Tried converting the string to a pointer tried switching schannel parameter with differently encoded parameter.