Skip to content

Commit 47a6fae

Browse files
committed
ee/wcp: switch to using LSA
1 parent c1c1a9a commit 47a6fae

5 files changed

Lines changed: 17 additions & 37 deletions

File tree

ee/wcp/ak_cred_provider/Credential.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ LRESULT APIENTRY Credential::WndProc(_In_ HWND hWnd, _In_ UINT uMsg, _In_ WPARAM
247247
.c_str());
248248
if ((m_oCefAppData.pCefApp)) {
249249
spdlog::debug("WndProc:: CEFLaunch");
250-
pData->strUsername = "";
250+
pData->strUserToken = "";
251251
try {
252252
CEFLaunch(pData, m_oCefAppData.pCefApp);
253253
} catch (const std::exception& e) {
254254
spdlog::warn("Failed to CEFLaunch", e.what());
255255
}
256-
spdlog::debug(std::string("User logged in: " + pData->strUsername).c_str());
256+
spdlog::debug(std::string("User logged in: " + pData->strUserToken).c_str());
257257
spdlog::debug("WndProc:: CEFLaunched");
258258
} else {
259259
::MessageBox(hWnd,
@@ -545,25 +545,7 @@ IFACEMETHODIMP Credential::Connect(IQueryContinueWithStatus* pqcws) {
545545
} else {
546546
strCredUser = std::wstring(m_pszQualifiedUserName);
547547
}
548-
std::wstring strAuthUser =
549-
std::wstring(m_oHookData.strUsername.begin(), m_oHookData.strUsername.end());
550-
if ((strAuthUser == strCredUser) && (strCredUser != L"")) {
551-
// Reset password
552-
USER_INFO_1003 oUserInfo1003;
553-
DWORD dwParamErr = 0;
554-
m_strPass = GetRandomWStr(WIN_PASS_LEN);
555-
oUserInfo1003.usri1003_password = (LPWSTR)(m_strPass.c_str());
556-
if (NetUserSetInfo(NULL, strCredUser.c_str(), 1003, (LPBYTE)(&oUserInfo1003), &dwParamErr) !=
557-
NERR_Success) {
558-
hr = E_FAIL;
559-
}
560-
} else {
561-
if (strAuthUser != L"") {
562-
MessageBox(hwndOwner, std::wstring(L"Username mismatch.").c_str(),
563-
(LPCWSTR)L"Login Failure", MB_OK | MB_TASKMODAL);
564-
}
565-
hr = E_FAIL;
566-
}
548+
m_strPass = utf8_decode(m_oHookData.strUserToken);
567549
} else {
568550
hr = E_POINTER;
569551
}

ee/wcp/ak_cred_provider/Helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ HRESULT RetrieveNegotiateAuthPackage(_Out_ ULONG* pulAuthPackage) {
303303
if (SUCCEEDED(HRESULT_FROM_NT(status))) {
304304
ULONG ulAuthPackage;
305305
LSA_STRING lsaszKerberosName;
306-
_LsaInitString(&lsaszKerberosName, NEGOSSP_NAME_A);
306+
_LsaInitString(&lsaszKerberosName, "ak_lsa");
307307

308308
status = LsaLookupAuthenticationPackage(hLsa, &lsaszKerberosName, &ulAuthPackage);
309309
if (SUCCEEDED(HRESULT_FROM_NT(status))) {

ee/wcp/ak_cred_provider/include/Credential.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ struct sHookData {
2222
hInstance = phInstance;
2323
oMutex.unlock();
2424
}
25-
void UpdateUser(const std::string& strUser) {
25+
void UpdateUserToken(const std::string& strUser) {
2626
oMutex.lock();
27-
strUsername = strUser;
27+
strUserToken = strUser;
2828
oMutex.unlock();
2929
}
3030
void UpdateHeaderToken(const std::string& headerToken) {
@@ -97,7 +97,7 @@ struct sHookData {
9797
}
9898
PWSTR UserSid = NULL;
9999
HINSTANCE hInstance = NULL;
100-
std::string strUsername = "";
100+
std::string strUserToken = "";
101101
std::string strHeaderToken = "";
102102
bool bExit = false; // flag to exit the custom loop
103103
bool bComplete = false; // UI call complete

ee/wcp/cefsimple/cefsimple_win.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "cefsimple/simple_handler.h"
1111
#include "cefsimple/cefsimple_win.h"
1212
#include "ak_common/include/ak_log.h"
13-
#include "ak_common/include/ak_sentry.h"
14-
#include "ak_common/include/crypt.h"
13+
#include <ak_common/include/ak_sentry.h>
14+
#include "crypt.h"
1515
#include "Credential.h"
1616

1717
extern std::string g_strPath;
@@ -87,7 +87,7 @@ int CEFLaunch(sHookData* pData, CefRefPtr<SimpleApp> pCefApp) {
8787
{
8888
spdlog::debug("Sub-loop");
8989
pHandler->CloseAllBrowsers(true);
90-
pData->UpdateUser("");
90+
pData->UpdateUserToken("");
9191
// pData->SetCancel(true);
9292
// // perform (at max) 10 precautionary loops even though 1 `CefDoMessageLoopWork()`
9393
// // seems to be sufficient
@@ -117,7 +117,7 @@ int CEFLaunch(sHookData* pData, CefRefPtr<SimpleApp> pCefApp) {
117117
Sleep(5); // as precaution to relieve the CPU (though unlikely that its needed)
118118
}
119119
pHandler = nullptr; // Release for the destructor to be called subsequently
120-
if (pData->strUsername == "") // User clicked the close button or cancel
120+
if (pData->strUserToken == "") // User clicked the close button or cancel
121121
{
122122
spdlog::debug("Token empty");
123123
pData->SetCancel(true);

ee/wcp/cefsimple/simple_handler.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,14 @@ class SimpleHandler : public CefClient,
9696
", ThreadID: ", std::to_string(GetCurrentThreadId()));
9797
Hide();
9898
m_pData->UpdateStatus(L"Authenticating, please wait...");
99-
TokenResponse validatedToken;
99+
std::string extractedToken;
100100
try {
101-
if (!ak_sys_auth_url(strURL, validatedToken)) {
102-
spdlog::warn("failed to validate token");
103-
} else {
104-
spdlog::debug("successfully validated token");
105-
m_pData->UpdateUser(validatedToken.username.c_str());
106-
}
101+
ak_sys_auth_url_extract_token(strURL, extractedToken);
102+
spdlog::debug("successfully extracted token");
103+
m_pData->UpdateUserToken(extractedToken);
107104
} catch (const rust::Error& ex) {
108-
spdlog::warn("Exception in ak_sys_auth_url: {}", ex.what());
105+
spdlog::warn("failed to extract token");
106+
spdlog::warn("Exception in ak_sys_auth_url_extract_token: {}", ex.what());
109107
}
110108
CloseAllBrowsers(false);
111109

0 commit comments

Comments
 (0)