mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@841 385bec56-5757-e545-9c3a-d8741f4650f1
175 lines
6.0 KiB
C++
175 lines
6.0 KiB
C++
/*---------------------------------------------------------------------------*
|
|
Project: Horizon
|
|
File: NinjaCommunicator.cpp
|
|
|
|
Copyright 2009-2011 Nintendo. All rights reserved.
|
|
|
|
These coded instructions, statements, and computer programs contain
|
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
|
Company Ltd., and are protected by Federal copyright law. They may
|
|
not be disclosed to third parties or copied or duplicated in any form,
|
|
in whole or in part, without the prior written consent of Nintendo.
|
|
|
|
$Rev$
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#include "NinjaCommunicator.h"
|
|
#include "Util.h"
|
|
#include "CommonLogger.h"
|
|
|
|
#include <nn/ac.h>
|
|
#include <nn/http.h>
|
|
#include <nn/http/http_Connection.h>
|
|
#include <nn/ssl.h>
|
|
#include <nn/fnd.h>
|
|
|
|
namespace ConsoleRestore
|
|
{
|
|
|
|
namespace
|
|
{
|
|
static unsigned char s_Buffer[4096] NN_ATTRIBUTE_ALIGN(4096);
|
|
}
|
|
|
|
NinjaCommunicator::NinjaCommunicator()
|
|
{
|
|
}
|
|
|
|
NinjaCommunicator::~NinjaCommunicator()
|
|
{
|
|
// TODO Auto-generated destructor stub
|
|
}
|
|
|
|
nn::Result NinjaCommunicator::GetNsUid(const char* baseUrl, nn::ProgramId programId)
|
|
{
|
|
if(!nn::ac::IsConnected())
|
|
{
|
|
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(
|
|
common::InitializeNetwork());
|
|
}
|
|
|
|
std::string url(baseUrl);
|
|
GenerateUrlForNsUid(url, programId);
|
|
|
|
return HttpCommunicationCore(url);
|
|
}
|
|
|
|
nn::Result NinjaCommunicator::GetEcInfo(const char* baseUrl, const char* nsUid, const char* countryCode)
|
|
{
|
|
if(!nn::ac::IsConnected())
|
|
{
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
common::InitializeNetwork());
|
|
}
|
|
|
|
std::string url(baseUrl);
|
|
GenerateUrlForEcInfo(url, nsUid, countryCode);
|
|
|
|
return HttpCommunicationCore(url);
|
|
}
|
|
|
|
nn::Result NinjaCommunicator::HttpCommunicationCore(std::string url)
|
|
{
|
|
/* ------------------------------------------------------------------------
|
|
ライブラリの初期化(HTTPライブラリ使用前に、各プロセスで一度だけ実行する。)
|
|
------------------------------------------------------------------------ */
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
nn::http::Initialize(reinterpret_cast<uptr>(s_Buffer), sizeof(s_Buffer)));
|
|
|
|
/* ------------------------------------------------------------------------
|
|
通信準備
|
|
------------------------------------------------------------------------ */
|
|
|
|
//通信先の設定
|
|
//<<HTTPS特有コード>>URLの先頭文字はhttpsとなります
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.Initialize(url.c_str()));
|
|
|
|
/* ------------------------------------------------------------------------
|
|
<<HTTPS特有コード>>SSL処理用設定
|
|
------------------------------------------------------------------------ */
|
|
//ルート証明書の設定
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.SetRootCa(nn::ssl::CACERT_NINTENDO_CA));
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.SetRootCa(nn::ssl::CACERT_NINTENDO_CA_G2));
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.SetRootCa(nn::ssl::CACERT_NINTENDO_CA_G3));
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.SetRootCa(nn::ssl::CACERT_NINTENDO_CLASS2_CA));
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.SetRootCa(nn::ssl::CACERT_NINTENDO_CLASS2_CA_G2));
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.SetRootCa(nn::ssl::CACERT_NINTENDO_CLASS2_CA_G3));
|
|
|
|
// クライアント証明書の設定
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.SetClientCert(nn::ssl::CLIENTCERT_DEFAULT));
|
|
|
|
|
|
#ifndef USE_PROD_KEY
|
|
// 開発用サーバは自己署名証明書なので検証項目を減らす
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.DisableVerifyOptionForDebug(
|
|
nn::ssl::VERIFY_COMMON_NAME | nn::ssl::VERIFY_SUBJECT_ALT_NAME | nn::ssl::VERIFY_ROOT_CA));
|
|
#endif
|
|
|
|
/* ------------------------------------------------------------------------
|
|
通信実行
|
|
------------------------------------------------------------------------ */
|
|
//通信の開始
|
|
COMMON_LOGGER_RESULT_IF_FAILED(
|
|
m_HttpCon.Connect()); //リクエストの送信を開始する。機器が同時実行可能な最大個数のHTTP通信がすでに実行中の場合は、空きができるまでブロック
|
|
|
|
return nn::ResultSuccess();
|
|
}
|
|
|
|
void NinjaCommunicator::GenerateUrlForNsUid(std::string& url, nn::ProgramId programId)
|
|
{
|
|
url.append("titles/id_pair?title_id%5B%5D=");
|
|
char programIdStr[32];
|
|
std::snprintf(programIdStr, sizeof(programIdStr), "%016llX", programId);
|
|
url.append(programIdStr);
|
|
NN_LOG("URL=%s\n", url.c_str());
|
|
}
|
|
|
|
void NinjaCommunicator::GenerateUrlForEcInfo(std::string& url, const char* nsUid, const char* countryCode)
|
|
{
|
|
url.append(countryCode);
|
|
url.append("/title/");
|
|
url.append(nsUid);
|
|
url.append("/ec_info?countryCode=");
|
|
url.append(countryCode);
|
|
NN_LOG("URL=%s\n", url.c_str());
|
|
}
|
|
|
|
nn::Result NinjaCommunicator::GetBody(u8 *buf, size_t size)
|
|
{
|
|
//HTTPレスポンスの取得
|
|
nn::fnd::TimeSpan timeOut = nn::fnd::TimeSpan::FromSeconds(90);
|
|
std::memset(buf, 0, size);
|
|
//読み取りが完了するまでブロック。Bodyの最後までの読み込みが成功した場合は、Successを表すResultが返る。バッファサイズが足りない場合は、エラー(Description==ER_RES_BODYBUF_SHORTAGEのResult)が返る*/
|
|
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(
|
|
m_HttpCon.Read(buf, size, timeOut));
|
|
|
|
return nn::ResultSuccess();
|
|
}
|
|
|
|
nn::Result NinjaCommunicator::GetSslError(s32* pResultCode)
|
|
{
|
|
return m_HttpCon.GetSslError(pResultCode);
|
|
}
|
|
|
|
nn::Result NinjaCommunicator::Finalize()
|
|
{
|
|
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(
|
|
m_HttpCon.Finalize());
|
|
|
|
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(
|
|
nn::http::Finalize());
|
|
|
|
return nn::ResultSuccess();
|
|
}
|
|
|
|
} /* namespace ConsoleRestore */
|