diff --git a/appleauth/auth.cpp b/appleauth/auth.cpp index 8b13789..0e3e7bf 100644 --- a/appleauth/auth.cpp +++ b/appleauth/auth.cpp @@ -1 +1,75 @@ +#include "appleauth/iauth.h" +#include "tier2/fileformats/xml.h" +#include "http/http.h" +IHTTPClientManager *g_pHttpClientMgr = NULL; + +class CAppleAuth: public IAppleAuth +{ +public: + virtual void Init() override; + virtual void Shutdown() override; + virtual EAppleAuthStatus SubmitLoginData( const char *szEmail, const char *szPassword ) override; + virtual EAppleAuthStatus Submit2FA( const char *szCode ) override; + + IHTTPClient *m_pANIClient; + IHTTPClient *m_pGrandSlamClient; + + CUtlString m_szProvisionStart = "/"; + CUtlString m_szProvisionFinish = "/"; +}; + +void CAppleAuth::Init() +{ + CreateInterfaceFn fnHttpFactory = Sys_GetFactory("funnyhttp"); + g_pHttpClientMgr = (IHTTPClientManager*)fnHttpFactory(HTTP_CLIENT_INTERFACE_VERSION, NULL); + + + m_pANIClient = g_pHttpClientMgr->Connect("ani.sidestore.io", true, NULL); + m_pGrandSlamClient = g_pHttpClientMgr->Connect("gsa.apple.com", true, NULL); + + { + HTTPHeaderParam_t params[] = { + {"X-Apple-I-Client-Time", "2026-1-1T12:00:00"}, + {"X-Apple-Locale", "en_US"}, + {"X-Apple-I-TimeZone", "Europe/Kyiv"}, + {"X-Mme-Client-Info", " "}, + {"User-Agent", "akd/1.0 CFNetwork/808.1.4"}, + {"X-Apple-I-MD-LU", "user"}, + {"X-Apple-I-MD-M", "0"}, + {"X-Apple-I-SRL-NO", "0"}, + {"X-Mme-Device-Id", "0"}, + {"Content-Type", "text/x-xml-plist"}, + {"Accept", "*/*"}, + }; + HTTPHeader_t header = { + sizeof(params)/sizeof(HTTPHeaderParam_t), + params, + }; + m_pGrandSlamClient->Get("/grandslam/GsService2/lookup", &header); + HTTPResponse_t r = m_pGrandSlamClient->GetResponse(); + if (r.m_uCode == 200) + { + V_printf("%s\n",r.m_message.GetMemory()); + } + } +} + +void CAppleAuth::Shutdown() +{ + +} + +EAppleAuthStatus CAppleAuth::SubmitLoginData( const char *szEmail, const char *szPassword ) +{ + +} + +EAppleAuthStatus CAppleAuth::Submit2FA( const char *szCode ) +{ + +} + + +static CAppleAuth s_appleAuth; +EXPOSE_INTERFACE_GLOBALVAR(CAppleAuth, IAppleAuth, APPLE_AUTH_INTERFACE_VERSION, s_appleAuth); diff --git a/appleauth/build.cpp b/appleauth/build.cpp index 4034d01..4a08be5 100644 --- a/appleauth/build.cpp +++ b/appleauth/build.cpp @@ -32,43 +32,3 @@ DECLARE_BUILD_STAGE(appleauth) return 0; }; -DECLARE_BUILD_STAGE(appleauth_test) -{ - - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - filesystem2->MakeDirectory("build"); - filesystem2->CopyFile("build",GET_PROJECT_LIBRARY(funnyhttp, "funnyhttp")); - filesystem2->CopyFile("build",GET_PROJECT_LIBRARY(appleauth, "appleauth")); - filesystem2->CopyFile("build",GET_PROJECT_LIBRARY(tier0, "tier0")); - - compileProject.m_szName = "appleauth"; - compileProject.files = { - "test.cpp" - }; - compileProject.includeDirectories = {"../public"}; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - ldProject.libraryObjects = { - GET_PROJECT_LIBRARY(tier1, "tier1"), - GET_PROJECT_LIBRARY(tier2, "tier2"), - }; - ldProject.libraries = { - "tier0", - }; - ldProject.libraryDirectories = { - "build", - }; - ldProject.linkType = ELINK_EXECUTABLE; - CUtlString szOutputDir = linker->Link(&ldProject); - - filesystem2->CopyFile("build",szOutputDir); - - - CUtlVector args = {}; - runner->Run("build/appleauth", args); - runner->Wait(); - - return 0; -}; diff --git a/appleauth/test.cpp b/appleauth/test.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/build.cpp b/fpc/build.cpp index 23eab5c..2b45ba2 100644 --- a/fpc/build.cpp +++ b/fpc/build.cpp @@ -139,9 +139,13 @@ DECLARE_BUILD_STAGE(install) CUtlString szTier0 = GET_PROJECT_LIBRARY(tier0, "tier0"); CUtlString szTier1 = GET_PROJECT_LIBRARY(tier1, "tier1"); CUtlString szTier2 = GET_PROJECT_LIBRARY(tier2, "tier2"); + CUtlString szHttp = GET_PROJECT_LIBRARY(funnyhttp, "funnyhttp"); + CUtlString szAppleAuth = GET_PROJECT_LIBRARY(appleauth, "appleauth"); filesystem2->CopyFile("build/fpc_temp", szExe); filesystem2->CopyFile("build/libfpc_temp.so", szLibFpc); + filesystem2->CopyFile("build", szHttp); + filesystem2->CopyFile("build", szAppleAuth); /* filesystem2->CopyFile("build/libtier1.a", szTier1); diff --git a/fpc/library/apple/appletool.cpp b/fpc/library/apple/appletool.cpp index a29445e..fe78323 100644 --- a/fpc/library/apple/appletool.cpp +++ b/fpc/library/apple/appletool.cpp @@ -1,6 +1,7 @@ #include "appletool.h" #include "helper.h" #include "runner.h" +#include "appleauth/iauth.h" void AppleManifest_t::SetPackageID( CUtlString szPackageID ) { @@ -79,14 +80,14 @@ CUtlString CAppleTool::BuildPackage( AppleManifest_t manifest, CUtlString szMani return CUtlString("../%s.ipa", manifest.m_szPackageName.GetString()); } -static IAppleDaemon *appledaemon; +static IAppleAuth *g_pAppleAuth; CUtlString CAppleTool::SignPackage( const char *szIpa, const char *szPassword ) { - CreateInterfaceFn fnFactory = Sys_GetFactory("xtool"); + CreateInterfaceFn fnFactory = Sys_GetFactory("appleauth"); if (fnFactory == NULL) Plat_FatalErrorFunc("Couldn't get xtool\n"); - appledaemon = (IAppleDaemon*)fnFactory(APPLE_DAEMON_INTERFACE_VERSION, NULL); - appledaemon->SignPackage(szIpa); + g_pAppleAuth = (IAppleAuth*)fnFactory(APPLE_AUTH_INTERFACE_VERSION, NULL); + g_pAppleAuth->Init(); return szIpa; } diff --git a/fpc/public/appletool.h b/fpc/public/appletool.h index 7233d48..18f0040 100644 --- a/fpc/public/appletool.h +++ b/fpc/public/appletool.h @@ -26,13 +26,6 @@ public: virtual CUtlString SignPackage( const char *szIpa, const char *szPassword ) = 0; }; -abstract_class IAppleDaemon -{ -public: - virtual void SignPackage( const char *szIpa ) = 0; -}; - -#define APPLE_DAEMON_INTERFACE_VERSION "AppleDaemon001" IAppleTool *AppleTool(); diff --git a/http/client.cpp b/http/client.cpp index b19c38a..e9d217a 100644 --- a/http/client.cpp +++ b/http/client.cpp @@ -122,7 +122,6 @@ readSocket: szCharBuffer.Resize(nPreviousSize+n); V_memcpy((char*)szCharBuffer.GetMemory()+nPreviousSize, response, n); nPreviousSize += n; - V_printf("%s\n",response); // HTTP 1.0 reacts either to socket being closed or Content-Lenght // HTTP 1.1 has Transfer-Encoding: chunked, which we need to respect @@ -152,6 +151,9 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData HTTPResponse_t response = {}; CUtlVector headers = {}; CUtlBuffer data = {}; + + if (!szMessage) + return {}; // Parse header while (*pcCurrentCharacter) { @@ -201,19 +203,21 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData } bool bParseInChunks = false; - uint64_t uBodySize; + uint64_t uBodySize = 0; // check content lenght - for ( int i = 0; i < response.m_params.GetSize(); i++ ) + for ( int i = 0; i < headers.GetSize(); i++ ) { - if ( !V_stricmp( response.m_params[i].m_szParamName, "Content-Length" ) ) + if ( !V_stricmp( headers[i].m_szParamName, "Content-Length" ) ) { - uBodySize = atoll(response.m_params[i].m_szValue); + V_printf("%s\n",headers[i].m_szValue.GetString()); + uBodySize = atoll(headers[i].m_szValue); + bParseInChunks = false; }; - if ( !V_stricmp( response.m_params[i].m_szParamName, "Transfer-Encoding" ) ) + if ( !V_stricmp( headers[i].m_szParamName, "Transfer-Encoding" ) ) { - if ( !V_stricmp( response.m_params[i].m_szValue, "Chunked" ) ) + if ( !V_stricmp( headers[i].m_szValue, "Chunked" ) ) { bParseInChunks = true; }; @@ -223,6 +227,11 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData if ( !bParseInChunks ) { uint32_t nDataLen = uDataSize-(pcCurrentCharacter-szMessage); + if (nDataLen < uBodySize) + { + response.m_bIsComplete = false; + return response; + } data = CUtlBuffer(nDataLen+1); V_memcpy(data.GetMemory(), pcCurrentCharacter, nDataLen); data[nDataLen] = 0; @@ -232,6 +241,7 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData response.m_params[i] = headers[i]; } response.m_message = data; + response.m_bIsComplete = true; } else { szBuffer = ""; diff --git a/public/appleauth/iauth.h b/public/appleauth/iauth.h index 6bc5f9b..628746e 100644 --- a/public/appleauth/iauth.h +++ b/public/appleauth/iauth.h @@ -4,13 +4,21 @@ #include "tier0/platform.h" #include "tier2/iappsystem.h" + +enum EAppleAuthStatus +{ + APPLE_AUTH_SUCCESS, + APPLE_AUTH_NEED_2FA, + APPLE_AUTH_NEED_SMS_2FA, +}; + abstract_class IAppleAuth: public IAppSystem { public: - virtual void SubmitLoginData( const char *szEmail, const char *szPassword ) = 0; - virtual void Submit2FA( const char *szCode ) = 0; + virtual EAppleAuthStatus SubmitLoginData( const char *szEmail, const char *szPassword ) = 0; + virtual EAppleAuthStatus Submit2FA( const char *szCode ) = 0; }; -IAppleAuth *AppleAuth(); +#define APPLE_AUTH_INTERFACE_VERSION "AppleAuth001" #endif