void ServerAuthModule::OnMessageVerifyClient(RawMessage& rawMessage) { if (m_bIsVerifiedClient) throw AuthException(AuthException::authInternalError, _T("client already verified"), __FILE__, __LINE__); if (m_spServer == NULL) throw AuthException(AuthException::authInternalError, _T("server == NULL"), __FILE__, __LINE__); SRPAuthVerifyClientMessage verifyClientMessage; ConstVectorRefStream stream(rawMessage.Data()); verifyClientMessage.Deserialize(stream); HighResolutionTimer timer; timer.Start(); // check client; when failed, client doesn't know password TByteArray Ms; try { Ms = m_spServer->VerifyClient(verifyClientMessage.GetHc()); } catch(std::runtime_error& ex) { throw AuthException( AuthException::authFailed, _T("couldn't verify client") + CString(ex.what()), __FILE__, __LINE__); } m_bIsVerifiedClient = true; // log CString cszText; cszText.Format(_T("verifying client took %u ms"), unsigned(timer.Elapsed()*1000.0)); LOG_INFO(cszText, Log::Server::AuthSRP); // send server our hash SRPAuthVerifyServerMessage verifyServerMessage(Ms); SendMessage(verifyServerMessage); // get server session key TByteArray K = m_spServer->GetK(); m_spServer.reset(); // no longer needed // set up RC4 encryption m_spEncryptModule.reset(new RC4::EncryptModule(K)); }
bool RenderCore::Render() { HighResolutionTimer timer; timer.Start(); BeginScene(0.0f, 0.125f, 0.3f, 1.0f); // Scene::UpdateVertexBuffer allows us to position the Scene if (!g_Scene->UpdateVertexBuffer(0, 0, 1280, 720)) { // || !g_Scene2->UpdateVertexBuffer(100, 100, 640, 360)) { DebugOut("Scene::UpdateVertexBuffer failed!\n"); return false; } // Get Desktop Duplication frame if (g_DesktopDuplication->GetFrame()) { // && g_DesktopDuplication2->GetFrame()) { // Render Desktop Duplication frame onto our Scene g_Scene->Render(g_DesktopDuplication->GetTexture(), m_WorldMatrix, m_OrthoMatrix); //g_Scene2->Render(g_DesktopDuplication2->GetTexture(), m_WorldMatrix, m_OrthoMatrix); g_MFEncoder->WriteFrame(g_DesktopDuplication->GetTexture()); g_DesktopDuplication->FinishFrame(); //g_DesktopDuplication2->FinishFrame(); } // limit frame rate double frameTime = timer.AsMilliseconds(); while (frameTime < (MAX_FRAME_TIME)) { frameTime += 0.001f; } DebugOut("frame time: %f\n", frameTime); EndScene(); /* const vec3f eyePosition(0.f, 0.f, 0.f); const vec3f lookAt(0.f, 0.f, 1.f); const vec3f upDir(0.f, 1.f, 0.f); DirectX::XMMATRIX viewMatrix = DirectX::XMMatrixLookAtLH( DirectX::XMLoadFloat3((const DirectX::XMFLOAT3 *)&eyePosition), DirectX::XMLoadFloat3((const DirectX::XMFLOAT3 *)&lookAt), DirectX::XMLoadFloat3((const DirectX::XMFLOAT3 *)&upDir)); */ //ZBufferState(1); return true; };
void ServerAuthModule::OnMessageAuthRequest(RawMessage& rawMessage) { if (m_bIsVerifiedClient) throw AuthException(AuthException::authInternalError, _T("client already verified"), __FILE__, __LINE__); if (m_spServer != NULL) throw AuthException(AuthException::authInternalError, _T("server == NULL"), __FILE__, __LINE__); AuthRequestMessage authMessage; ConstVectorRefStream stream(rawMessage.Data()); authMessage.Deserialize(stream); // get server infos ATLASSERT(m_fnGetServerAuthInfo != NULL); TByteArray vecPasswordKey, vecSalt; try { m_fnGetServerAuthInfo(authMessage.GetUsername(), vecPasswordKey, vecSalt, m_iAccountId); } catch(const Exception& ex) { LOG_WARN(_T("caught exception during GetServerAuthInfo(): ") + ex.Message(), Log::Server::AuthSRP); throw AuthException( AuthException::authFailed, _T("couldn't get auth info: ") + ex.Message(), __FILE__, __LINE__); } catch(...) { throw AuthException( AuthException::authFailed, _T("couldn't get auth info"), __FILE__, __LINE__); } HighResolutionTimer timer; timer.Start(); SRP::GroupParameter gp = SRP::Helper::GetPresetGroupParameter(c_uiDefaultPresetGroupParameter); m_spServer.reset(new SRP::Server(gp)); // generate b BigInteger b = SRP::Helper::GenerateRandomBits(1024); BigInteger PassVerifier = SRP::Helper::ToInteger<BigInteger>(vecPasswordKey); // calculate B BigInteger B = m_spServer->GetB(PassVerifier, b); TByteArray Bbin; SRP::Helper::ToBinaryData(B, Bbin); // calculate session key TByteArray Abin = authMessage.GetA(); BigInteger A = SRP::Helper::ToInteger<BigInteger>(Abin); BigInteger s = SRP::Helper::ToInteger<BigInteger>(vecSalt); USES_CONVERSION; std::string strUsername(T2CA(authMessage.GetUsername())); m_spServer->CalcSessionKey(A, s, strUsername, PassVerifier); // log CString cszText; cszText.Format(_T("calculating session key took %u ms"), unsigned(timer.Elapsed()*1000.0)); LOG_INFO(cszText, Log::Server::AuthSRP); // send response SRPAuthResponseMessage authResponseMessage(vecSalt, Bbin); SendMessage(authResponseMessage); }