This commit is contained in:
2026-01-05 14:34:34 +02:00
parent f886350eb1
commit 2b91057589
8 changed files with 111 additions and 61 deletions

View File

@@ -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", "<MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)>"},
{"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);

View File

@@ -32,43 +32,3 @@ DECLARE_BUILD_STAGE(appleauth)
return 0; 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<CUtlString> args = {};
runner->Run("build/appleauth", args);
runner->Wait();
return 0;
};

View File

View File

@@ -139,9 +139,13 @@ DECLARE_BUILD_STAGE(install)
CUtlString szTier0 = GET_PROJECT_LIBRARY(tier0, "tier0"); CUtlString szTier0 = GET_PROJECT_LIBRARY(tier0, "tier0");
CUtlString szTier1 = GET_PROJECT_LIBRARY(tier1, "tier1"); CUtlString szTier1 = GET_PROJECT_LIBRARY(tier1, "tier1");
CUtlString szTier2 = GET_PROJECT_LIBRARY(tier2, "tier2"); 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/fpc_temp", szExe);
filesystem2->CopyFile("build/libfpc_temp.so", szLibFpc); filesystem2->CopyFile("build/libfpc_temp.so", szLibFpc);
filesystem2->CopyFile("build", szHttp);
filesystem2->CopyFile("build", szAppleAuth);
/* /*
filesystem2->CopyFile("build/libtier1.a", szTier1); filesystem2->CopyFile("build/libtier1.a", szTier1);

View File

@@ -1,6 +1,7 @@
#include "appletool.h" #include "appletool.h"
#include "helper.h" #include "helper.h"
#include "runner.h" #include "runner.h"
#include "appleauth/iauth.h"
void AppleManifest_t::SetPackageID( CUtlString szPackageID ) 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()); return CUtlString("../%s.ipa", manifest.m_szPackageName.GetString());
} }
static IAppleDaemon *appledaemon; static IAppleAuth *g_pAppleAuth;
CUtlString CAppleTool::SignPackage( const char *szIpa, const char *szPassword ) CUtlString CAppleTool::SignPackage( const char *szIpa, const char *szPassword )
{ {
CreateInterfaceFn fnFactory = Sys_GetFactory("xtool"); CreateInterfaceFn fnFactory = Sys_GetFactory("appleauth");
if (fnFactory == NULL) if (fnFactory == NULL)
Plat_FatalErrorFunc("Couldn't get xtool\n"); Plat_FatalErrorFunc("Couldn't get xtool\n");
appledaemon = (IAppleDaemon*)fnFactory(APPLE_DAEMON_INTERFACE_VERSION, NULL); g_pAppleAuth = (IAppleAuth*)fnFactory(APPLE_AUTH_INTERFACE_VERSION, NULL);
appledaemon->SignPackage(szIpa); g_pAppleAuth->Init();
return szIpa; return szIpa;
} }

View File

@@ -26,13 +26,6 @@ public:
virtual CUtlString SignPackage( const char *szIpa, const char *szPassword ) = 0; 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(); IAppleTool *AppleTool();

View File

@@ -122,7 +122,6 @@ readSocket:
szCharBuffer.Resize(nPreviousSize+n); szCharBuffer.Resize(nPreviousSize+n);
V_memcpy((char*)szCharBuffer.GetMemory()+nPreviousSize, response, n); V_memcpy((char*)szCharBuffer.GetMemory()+nPreviousSize, response, n);
nPreviousSize += n; nPreviousSize += n;
V_printf("%s\n",response);
// HTTP 1.0 reacts either to socket being closed or Content-Lenght // HTTP 1.0 reacts either to socket being closed or Content-Lenght
// HTTP 1.1 has Transfer-Encoding: chunked, which we need to respect // 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 = {}; HTTPResponse_t response = {};
CUtlVector<HTTPHeaderParam_t> headers = {}; CUtlVector<HTTPHeaderParam_t> headers = {};
CUtlBuffer<char> data = {}; CUtlBuffer<char> data = {};
if (!szMessage)
return {};
// Parse header // Parse header
while (*pcCurrentCharacter) while (*pcCurrentCharacter)
{ {
@@ -201,19 +203,21 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData
} }
bool bParseInChunks = false; bool bParseInChunks = false;
uint64_t uBodySize; uint64_t uBodySize = 0;
// check content lenght // 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; bParseInChunks = true;
}; };
@@ -223,6 +227,11 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData
if ( !bParseInChunks ) if ( !bParseInChunks )
{ {
uint32_t nDataLen = uDataSize-(pcCurrentCharacter-szMessage); uint32_t nDataLen = uDataSize-(pcCurrentCharacter-szMessage);
if (nDataLen < uBodySize)
{
response.m_bIsComplete = false;
return response;
}
data = CUtlBuffer<char>(nDataLen+1); data = CUtlBuffer<char>(nDataLen+1);
V_memcpy(data.GetMemory(), pcCurrentCharacter, nDataLen); V_memcpy(data.GetMemory(), pcCurrentCharacter, nDataLen);
data[nDataLen] = 0; 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_params[i] = headers[i];
} }
response.m_message = data; response.m_message = data;
response.m_bIsComplete = true;
} else { } else {
szBuffer = ""; szBuffer = "";

View File

@@ -4,13 +4,21 @@
#include "tier0/platform.h" #include "tier0/platform.h"
#include "tier2/iappsystem.h" #include "tier2/iappsystem.h"
enum EAppleAuthStatus
{
APPLE_AUTH_SUCCESS,
APPLE_AUTH_NEED_2FA,
APPLE_AUTH_NEED_SMS_2FA,
};
abstract_class IAppleAuth: public IAppSystem abstract_class IAppleAuth: public IAppSystem
{ {
public: public:
virtual void SubmitLoginData( const char *szEmail, const char *szPassword ) = 0; virtual EAppleAuthStatus SubmitLoginData( const char *szEmail, const char *szPassword ) = 0;
virtual void Submit2FA( const char *szCode ) = 0; virtual EAppleAuthStatus Submit2FA( const char *szCode ) = 0;
}; };
IAppleAuth *AppleAuth(); #define APPLE_AUTH_INTERFACE_VERSION "AppleAuth001"
#endif #endif