Remove LTCG and platform toolset, fix code style.

This commit is contained in:
Matthew Parlane 2013-08-15 21:43:43 +12:00
parent fede38985e
commit b93d62dcb8
3 changed files with 393 additions and 400 deletions

View File

@ -63,7 +63,6 @@
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>Windows7.1SDK</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
@ -212,9 +211,6 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
</Link> </Link>
<Lib>
<LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\include\polarssl\aes.h" /> <ClInclude Include="..\..\include\polarssl\aes.h" />

View File

@ -151,7 +151,6 @@
<Lib> <Lib>
<AdditionalLibraryDirectories> <AdditionalLibraryDirectories>
</AdditionalLibraryDirectories> </AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
</Lib> </Lib>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'">
@ -181,7 +180,6 @@
<Lib> <Lib>
<AdditionalLibraryDirectories> <AdditionalLibraryDirectories>
</AdditionalLibraryDirectories> </AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
</Lib> </Lib>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'">

View File

@ -27,7 +27,7 @@
CWII_IPC_HLE_Device_net_ssl::CWII_IPC_HLE_Device_net_ssl(u32 _DeviceID, const std::string& _rDeviceName) CWII_IPC_HLE_Device_net_ssl::CWII_IPC_HLE_Device_net_ssl(u32 _DeviceID, const std::string& _rDeviceName)
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName) : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
{ {
for(int i = 0; i < NET_SSL_MAXINSTANCES; ++i) for (int i = 0; i < NET_SSL_MAXINSTANCES; ++i)
{ {
memset(&_SSL[i], 0, sizeof(struct _SSL)); memset(&_SSL[i], 0, sizeof(struct _SSL));
} }
@ -38,7 +38,7 @@ CWII_IPC_HLE_Device_net_ssl::~CWII_IPC_HLE_Device_net_ssl()
// Cleanup sessions // Cleanup sessions
for (int i = 0; i < NET_SSL_MAXINSTANCES; i++) for (int i = 0; i < NET_SSL_MAXINSTANCES; i++)
{ {
if(_SSL[i].active) if (_SSL[i].active)
{ {
ssl_close_notify(&_SSL[i].ctx); ssl_close_notify(&_SSL[i].ctx);
ssl_session_free(&_SSL[i].session); ssl_session_free(&_SSL[i].session);
@ -62,7 +62,9 @@ int CWII_IPC_HLE_Device_net_ssl::getSSLFreeID()
for (int i = 0; i < NET_SSL_MAXINSTANCES; i++) for (int i = 0; i < NET_SSL_MAXINSTANCES; i++)
{ {
if (!_SSL[i].active) if (!_SSL[i].active)
{
return i + 1; return i + 1;
}
} }
return 0; return 0;
} }
@ -77,7 +79,9 @@ bool CWII_IPC_HLE_Device_net_ssl::Open(u32 _CommandAddress, u32 _Mode)
bool CWII_IPC_HLE_Device_net_ssl::Close(u32 _CommandAddress, bool _bForce) bool CWII_IPC_HLE_Device_net_ssl::Close(u32 _CommandAddress, bool _bForce)
{ {
if (!_bForce) if (!_bForce)
{
Memory::Write_U32(0, _CommandAddress + 4); Memory::Write_U32(0, _CommandAddress + 4);
}
m_Active = false; m_Active = false;
return true; return true;
} }
@ -111,33 +115,30 @@ _verify_certificate_callback (void *data, x509_cert *crt, int depth, int *flags)
{ {
char buf[1024]; char buf[1024];
((void) data); ((void) data);
std::string verify_info = "Verify requested for (Depth "; std::string verify_info = StringFromFormat("Verify requested for (Depth %d):\n");
sprintf(buf, "%d", depth);
verify_info += buf;
verify_info += "):\n";
x509parse_cert_info( buf, sizeof( buf ) - 1, "", crt ); x509parse_cert_info( buf, sizeof( buf ) - 1, "", crt );
verify_info += buf; verify_info += buf;
if( ( (*flags) & BADCERT_EXPIRED ) != 0 ) if ( ( (*flags) & BADCERT_EXPIRED ) != 0 )
verify_info += " ! server certificate has expired"; verify_info += " ! server certificate has expired";
if( ( (*flags) & BADCERT_REVOKED ) != 0 ) if ( ( (*flags) & BADCERT_REVOKED ) != 0 )
verify_info += " ! server certificate has been revoked"; verify_info += " ! server certificate has been revoked";
if( ( (*flags) & BADCERT_CN_MISMATCH ) != 0 ) if ( ( (*flags) & BADCERT_CN_MISMATCH ) != 0 )
verify_info += " ! CN mismatch\n"; verify_info += " ! CN mismatch\n";
if( ( (*flags) & BADCERT_NOT_TRUSTED ) != 0 ) if ( ( (*flags) & BADCERT_NOT_TRUSTED ) != 0 )
verify_info += " ! self-signed or not signed by a trusted CA\n"; verify_info += " ! self-signed or not signed by a trusted CA\n";
if( ( (*flags) & BADCRL_NOT_TRUSTED ) != 0 ) if ( ( (*flags) & BADCRL_NOT_TRUSTED ) != 0 )
verify_info += " ! CRL not trusted\n"; verify_info += " ! CRL not trusted\n";
if( ( (*flags) & BADCRL_EXPIRED ) != 0 ) if ( ( (*flags) & BADCRL_EXPIRED ) != 0 )
verify_info += " ! CRL expired\n"; verify_info += " ! CRL expired\n";
if( ( (*flags) & BADCERT_OTHER ) != 0 ) if ( ( (*flags) & BADCERT_OTHER ) != 0 )
verify_info += " ! other (unknown) flag\n"; verify_info += " ! other (unknown) flag\n";
if ( ( *flags ) == 0 ) if ( ( *flags ) == 0 )
@ -192,437 +193,435 @@ u32 CWII_IPC_HLE_Device_net_ssl::ExecuteCommandV(u32 _Parameter, SIOCtlVBuffer C
switch (_Parameter) switch (_Parameter)
{ {
case IOCTLV_NET_SSL_NEW: case IOCTLV_NET_SSL_NEW:
{ {
int verifyOption = Memory::Read_U32(_BufferOut); int verifyOption = Memory::Read_U32(_BufferOut);
const char * hostname = (const char*) Memory::GetPointer(_BufferOut2); const char * hostname = (const char*) Memory::GetPointer(_BufferOut2);
int freeSSL = this->getSSLFreeID(); int freeSSL = this->getSSLFreeID();
if (freeSSL) if (freeSSL)
{
int sslID = freeSSL - 1;
int ret = ssl_init(&_SSL[sslID].ctx);
if (ret)
{ {
int sslID = freeSSL - 1; // Cleanup possibly dirty ctx
int ret = ssl_init(&_SSL[sslID].ctx); memset(&_SSL[sslID].ctx, 0, sizeof(ssl_context));
if(ret) goto _SSL_NEW_ERROR;
{
// Cleanup possibly dirty ctx
memset(&_SSL[sslID].ctx, 0, sizeof(ssl_context));
goto _SSL_NEW_ERROR;
}
havege_init(&_SSL[sslID].hs);
ssl_set_rng(&_SSL[sslID].ctx, havege_random, &_SSL[sslID].hs);
// For some reason we can't use TLSv1.2, v1.1 and below are fine!
ssl_set_max_version(&_SSL[sslID].ctx, SSL_MAJOR_VERSION_3, SSL_MINOR_VERSION_2);
ssl_set_ciphersuites(&_SSL[sslID].ctx, ssl_default_ciphersuites);
ssl_set_session(&_SSL[sslID].ctx, &_SSL[sslID].session);
ssl_set_verify(&_SSL[sslID].ctx, _verify_certificate_callback, NULL);
ssl_set_endpoint(&_SSL[sslID].ctx, SSL_IS_CLIENT);
ssl_set_authmode(&_SSL[sslID].ctx, SSL_VERIFY_OPTIONAL);
ssl_set_renegotiation(&_SSL[sslID].ctx, SSL_RENEGOTIATION_ENABLED);
memcpy(_SSL[sslID].hostname, hostname, min((int)BufferOutSize2, MAX_HOSTNAME_LEN));
_SSL[sslID].hostname[MAX_HOSTNAME_LEN-1] = '\0';
ssl_set_hostname(&_SSL[sslID].ctx, _SSL[sslID].hostname);
_SSL[sslID].active = true;
Memory::Write_U32(freeSSL, _BufferIn);
} }
else
{ havege_init(&_SSL[sslID].hs);
ssl_set_rng(&_SSL[sslID].ctx, havege_random, &_SSL[sslID].hs);
// For some reason we can't use TLSv1.2, v1.1 and below are fine!
ssl_set_max_version(&_SSL[sslID].ctx, SSL_MAJOR_VERSION_3, SSL_MINOR_VERSION_2);
ssl_set_ciphersuites(&_SSL[sslID].ctx, ssl_default_ciphersuites);
ssl_set_session(&_SSL[sslID].ctx, &_SSL[sslID].session);
ssl_set_verify(&_SSL[sslID].ctx, _verify_certificate_callback, NULL);
ssl_set_endpoint(&_SSL[sslID].ctx, SSL_IS_CLIENT);
ssl_set_authmode(&_SSL[sslID].ctx, SSL_VERIFY_OPTIONAL);
ssl_set_renegotiation(&_SSL[sslID].ctx, SSL_RENEGOTIATION_ENABLED);
memcpy(_SSL[sslID].hostname, hostname, min((int)BufferOutSize2, MAX_HOSTNAME_LEN));
_SSL[sslID].hostname[MAX_HOSTNAME_LEN-1] = '\0';
ssl_set_hostname(&_SSL[sslID].ctx, _SSL[sslID].hostname);
_SSL[sslID].active = true;
Memory::Write_U32(freeSSL, _BufferIn);
}
else
{
_SSL_NEW_ERROR: _SSL_NEW_ERROR:
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_NEW (%d, %s) "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
verifyOption, hostname,
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_SHUTDOWN:
{
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{
ssl_close_notify(&_SSL[sslID].ctx);
ssl_session_free(&_SSL[sslID].session);
ssl_free(&_SSL[sslID].ctx);
x509_free(&_SSL[sslID].cacert);
x509_free(&_SSL[sslID].clicert);
memset(&_SSL[sslID].ctx, 0, sizeof(ssl_context));
memset(&_SSL[sslID].session, 0, sizeof(ssl_session));
memset(&_SSL[sslID].hs, 0, sizeof(havege_state));
memset(_SSL[sslID].hostname, 0, MAX_HOSTNAME_LEN);
_SSL[sslID].active = false;
Memory::Write_U32(SSL_OK, _BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SHUTDOWN "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_SETROOTCA:
{
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETROOTCA "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{
int ret = x509parse_crt_der(
&_SSL[sslID].cacert,
Memory::GetPointer(_BufferOut2),
BufferOutSize2);
if (ret)
{
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn); Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
} }
else
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_NEW (%d, %s) "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
verifyOption, hostname,
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_SHUTDOWN:
{
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{ {
ssl_close_notify(&_SSL[sslID].ctx); ssl_set_ca_chain(&_SSL[sslID].ctx, &_SSL[sslID].cacert, NULL, _SSL[sslID].hostname);
ssl_session_free(&_SSL[sslID].session);
ssl_free(&_SSL[sslID].ctx);
x509_free(&_SSL[sslID].cacert);
x509_free(&_SSL[sslID].clicert);
memset(&_SSL[sslID].ctx, 0, sizeof(ssl_context));
memset(&_SSL[sslID].session, 0, sizeof(ssl_session));
memset(&_SSL[sslID].hs, 0, sizeof(havege_state));
memset(_SSL[sslID].hostname, 0, MAX_HOSTNAME_LEN);
_SSL[sslID].active = false;
Memory::Write_U32(SSL_OK, _BufferIn); Memory::Write_U32(SSL_OK, _BufferIn);
} }
else
{ WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETROOTCA = %d", ret);
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SHUTDOWN "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
} }
case IOCTLV_NET_SSL_SETROOTCA: else
{ {
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETROOTCA " Memory::Write_U32(SSL_ERR_ID, _BufferIn);
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{
int ret = x509parse_crt_der(
&_SSL[sslID].cacert,
Memory::GetPointer(_BufferOut2),
BufferOutSize2);
if(ret)
{
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
}
else
{
ssl_set_ca_chain(&_SSL[sslID].ctx, &_SSL[sslID].cacert, NULL, _SSL[sslID].hostname);
Memory::Write_U32(SSL_OK, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETROOTCA = %d", ret);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
break;
} }
case IOCTLV_NET_SSL_SETBUILTINCLIENTCERT: break;
{ }
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT " case IOCTLV_NET_SSL_SETBUILTINCLIENTCERT:
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), " {
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), " WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)", "BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, "BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize, "BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3); _BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(_BufferOut) - 1; int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID)) if (SSLID_VALID(sslID))
{
std::string cert_base_path(File::GetUserPath(D_WIIUSER_IDX));
int ret = x509parse_crtfile(&_SSL[sslID].clicert, (cert_base_path + "clientca.pem").c_str());
int rsa_ret = x509parse_keyfile(&_SSL[sslID].rsa, (cert_base_path + "clientcakey.pem").c_str(), NULL);
if(ret || rsa_ret)
{
x509_free(&_SSL[sslID].clicert);
rsa_free(&_SSL[sslID].rsa);
memset(&_SSL[sslID].clicert, 0, sizeof(x509_cert));
memset(&_SSL[sslID].rsa, 0, sizeof(rsa_context));
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
}
else
{
ssl_set_own_cert(&_SSL[sslID].ctx, &_SSL[sslID].clicert, &_SSL[sslID].rsa);
Memory::Write_U32(SSL_OK, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT = (%d, %d)", ret, rsa_ret);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = %d", sslID);
}
break;
}
case IOCTLV_NET_SSL_REMOVECLIENTCERT:
{ {
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_REMOVECLIENTCERT " std::string cert_base_path(File::GetUserPath(D_WIIUSER_IDX));
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), " int ret = x509parse_crtfile(&_SSL[sslID].clicert, (cert_base_path + "clientca.pem").c_str());
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), " int rsa_ret = x509parse_keyfile(&_SSL[sslID].rsa, (cert_base_path + "clientcakey.pem").c_str(), NULL);
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)", if (ret || rsa_ret)
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{ {
x509_free(&_SSL[sslID].clicert); x509_free(&_SSL[sslID].clicert);
rsa_free(&_SSL[sslID].rsa); rsa_free(&_SSL[sslID].rsa);
memset(&_SSL[sslID].clicert, 0, sizeof(x509_cert)); memset(&_SSL[sslID].clicert, 0, sizeof(x509_cert));
memset(&_SSL[sslID].rsa, 0, sizeof(rsa_context)); memset(&_SSL[sslID].rsa, 0, sizeof(rsa_context));
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
}
else
{
ssl_set_own_cert(&_SSL[sslID].ctx, &_SSL[sslID].clicert, &_SSL[sslID].rsa);
Memory::Write_U32(SSL_OK, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT = (%d, %d)", ret, rsa_ret);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = %d", sslID);
}
break;
}
case IOCTLV_NET_SSL_REMOVECLIENTCERT:
{
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_REMOVECLIENTCERT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
ssl_set_own_cert(&_SSL[sslID].ctx, NULL, NULL); int sslID = Memory::Read_U32(_BufferOut) - 1;
Memory::Write_U32(SSL_OK, _BufferIn); if (SSLID_VALID(sslID))
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = %d", sslID);
}
break;
}
case IOCTLV_NET_SSL_SETBUILTINROOTCA:
{ {
int sslID = Memory::Read_U32(_BufferOut) - 1; x509_free(&_SSL[sslID].clicert);
if (SSLID_VALID(sslID)) rsa_free(&_SSL[sslID].rsa);
{ memset(&_SSL[sslID].clicert, 0, sizeof(x509_cert));
std::string cert_base_path(File::GetUserPath(D_WIIUSER_IDX)); memset(&_SSL[sslID].rsa, 0, sizeof(rsa_context));
ssl_set_own_cert(&_SSL[sslID].ctx, NULL, NULL);
Memory::Write_U32(SSL_OK, _BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = %d", sslID);
}
break;
}
case IOCTLV_NET_SSL_SETBUILTINROOTCA:
{
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{
std::string cert_base_path(File::GetUserPath(D_WIIUSER_IDX));
int ret = x509parse_crtfile(&_SSL[sslID].cacert, (cert_base_path + "rootca.pem").c_str()); int ret = x509parse_crtfile(&_SSL[sslID].cacert, (cert_base_path + "rootca.pem").c_str());
if(ret) if (ret)
{ {
x509_free(&_SSL[sslID].clicert); x509_free(&_SSL[sslID].clicert);
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn); Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
}
else
{
ssl_set_ca_chain(&_SSL[sslID].ctx, &_SSL[sslID].cacert, NULL, _SSL[sslID].hostname);
Memory::Write_U32(SSL_OK, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA = %d", ret);
} }
else else
{ {
Memory::Write_U32(SSL_ERR_ID, _BufferIn); ssl_set_ca_chain(&_SSL[sslID].ctx, &_SSL[sslID].cacert, NULL, _SSL[sslID].hostname);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_CONNECT:
{
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{
_SSL[sslID].sockfd = Memory::Read_U32(_BufferOut2);
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_CONNECT socket = %d", _SSL[sslID].sockfd);
ssl_set_bio(&_SSL[sslID].ctx, net_recv, &_SSL[sslID].sockfd, net_send, &_SSL[sslID].sockfd);
Memory::Write_U32(SSL_OK, _BufferIn); Memory::Write_U32(SSL_OK, _BufferIn);
} }
else WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA = %d", ret);
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_CONNECT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
} }
case IOCTLV_NET_SSL_DOHANDSHAKE: else
{ {
int ret = 0; Memory::Write_U32(SSL_ERR_ID, _BufferIn);
int sslID = Memory::Read_U32(_BufferOut) - 1; }
if (SSLID_VALID(sslID)) WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_CONNECT:
{
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{
_SSL[sslID].sockfd = Memory::Read_U32(_BufferOut2);
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_CONNECT socket = %d", _SSL[sslID].sockfd);
ssl_set_bio(&_SSL[sslID].ctx, net_recv, &_SSL[sslID].sockfd, net_send, &_SSL[sslID].sockfd);
Memory::Write_U32(SSL_OK, _BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_CONNECT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_DOHANDSHAKE:
{
int ret = 0;
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{
ret = ssl_handshake(&_SSL[sslID].ctx);
switch (ret)
{
case 0:
Memory::Write_U32(SSL_OK, _BufferIn);
break;
case POLARSSL_ERR_NET_WANT_READ:
Memory::Write_U32(SSL_ERR_RAGAIN, _BufferIn);
break;
case POLARSSL_ERR_NET_WANT_WRITE:
Memory::Write_U32(SSL_ERR_WAGAIN, _BufferIn);
break;
default:
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
break;
}
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_DOHANDSHAKE = (%d) "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
ret,
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_WRITE:
{
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{
int ret = ssl_write( &_SSL[sslID].ctx, Memory::GetPointer(_BufferOut2), BufferOutSize2);
File::IOFile("ssl_write.bin", "ab").WriteBytes(Memory::GetPointer(_BufferOut2), BufferOutSize2);
if (ret >= 0)
{
// Return bytes written or SSL_ERR_ZERO if none
Memory::Write_U32((ret == 0) ? SSL_ERR_ZERO : ret, _BufferIn);
}
else
{ {
ret = ssl_handshake(&_SSL[sslID].ctx);
switch (ret) switch (ret)
{ {
case 0: case POLARSSL_ERR_NET_WANT_READ:
Memory::Write_U32(SSL_OK, _BufferIn); Memory::Write_U32(SSL_ERR_RAGAIN, _BufferIn);
break; break;
case POLARSSL_ERR_NET_WANT_READ: case POLARSSL_ERR_NET_WANT_WRITE:
Memory::Write_U32(SSL_ERR_RAGAIN, _BufferIn); Memory::Write_U32(SSL_ERR_WAGAIN, _BufferIn);
break; break;
case POLARSSL_ERR_NET_WANT_WRITE: default:
Memory::Write_U32(SSL_ERR_WAGAIN, _BufferIn); Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
break; break;
default:
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
break;
} }
} }
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_DOHANDSHAKE = (%d) "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
ret,
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
} }
case IOCTLV_NET_SSL_WRITE: else
{ {
int sslID = Memory::Read_U32(_BufferOut) - 1; Memory::Write_U32(SSL_ERR_ID, _BufferIn);
if (SSLID_VALID(sslID))
{
int ret = ssl_write( &_SSL[sslID].ctx, Memory::GetPointer(_BufferOut2), BufferOutSize2);
File::IOFile("ssl_write.bin", "ab").WriteBytes(Memory::GetPointer(_BufferOut2), BufferOutSize2);
if(ret >= 0)
{
// Return bytes written or SSL_ERR_ZERO if none
Memory::Write_U32((ret == 0) ? SSL_ERR_ZERO : ret, _BufferIn);
}
else
{
switch (ret)
{
case POLARSSL_ERR_NET_WANT_READ:
Memory::Write_U32(SSL_ERR_RAGAIN, _BufferIn);
break;
case POLARSSL_ERR_NET_WANT_WRITE:
Memory::Write_U32(SSL_ERR_WAGAIN, _BufferIn);
break;
default:
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
break;
}
}
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_WRITE "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
WARN_LOG(WII_IPC_SSL, "%s", Memory::GetPointer(_BufferOut2));
break;
} }
case IOCTLV_NET_SSL_READ: WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_WRITE "
{ "BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
WARN_LOG(WII_IPC_SSL, "%s", Memory::GetPointer(_BufferOut2));
break;
}
case IOCTLV_NET_SSL_READ:
{
int ret = 0; int ret = 0;
int sslID = Memory::Read_U32(_BufferOut) - 1; int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID)) if (SSLID_VALID(sslID))
{
ret = ssl_read( &_SSL[sslID].ctx, Memory::GetPointer(_BufferIn2), BufferInSize2);
if (ret > 0)
{ {
ret = ssl_read( &_SSL[sslID].ctx, Memory::GetPointer(_BufferIn2), BufferInSize2); File::IOFile("ssl_read.bin", "ab").WriteBytes(Memory::GetPointer(_BufferIn2), ret);
if (ret > 0)
{
File::IOFile("ssl_read.bin", "ab").WriteBytes(Memory::GetPointer(_BufferIn2), ret);
}
if(ret >= 0)
{
// Return bytes read or SSL_ERR_ZERO if none
Memory::Write_U32((ret == 0) ? SSL_ERR_ZERO : ret, _BufferIn);
}
else
{
switch (ret)
{
case POLARSSL_ERR_NET_WANT_READ:
Memory::Write_U32(SSL_ERR_RAGAIN, _BufferIn);
break;
case POLARSSL_ERR_NET_WANT_WRITE:
Memory::Write_U32(SSL_ERR_WAGAIN, _BufferIn);
break;
default:
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
break;
}
}
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
} }
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_READ(%d)" if (ret >= 0)
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
ret,
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_SETROOTCADEFAULT:
{
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{ {
Memory::Write_U32(SSL_OK, _BufferIn); // Return bytes read or SSL_ERR_ZERO if none
Memory::Write_U32((ret == 0) ? SSL_ERR_ZERO : ret, _BufferIn);
} }
else else
{ {
Memory::Write_U32(SSL_ERR_ID, _BufferIn); switch (ret)
{
case POLARSSL_ERR_NET_WANT_READ:
Memory::Write_U32(SSL_ERR_RAGAIN, _BufferIn);
break;
case POLARSSL_ERR_NET_WANT_WRITE:
Memory::Write_U32(SSL_ERR_WAGAIN, _BufferIn);
break;
default:
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
break;
}
} }
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETROOTCADEFAULT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
} }
case IOCTLV_NET_SSL_SETCLIENTCERTDEFAULT: else
{ {
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETCLIENTCERTDEFAULT " Memory::Write_U32(SSL_ERR_ID, _BufferIn);
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), " }
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(_BufferOut) - 1; WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_READ(%d)"
if (SSLID_VALID(sslID)) "BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
{ "BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
Memory::Write_U32(SSL_OK, _BufferIn); "BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
} ret,
else _BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
{ _BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
Memory::Write_U32(SSL_ERR_ID, _BufferIn); _BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
} break;
break; }
} case IOCTLV_NET_SSL_SETROOTCADEFAULT:
default: {
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{ {
ERROR_LOG(WII_IPC_SSL, "%i " Memory::Write_U32(SSL_OK, _BufferIn);
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_Parameter,
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
} }
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETROOTCADEFAULT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_SETCLIENTCERTDEFAULT:
{
WARN_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETCLIENTCERTDEFAULT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(_BufferOut) - 1;
if (SSLID_VALID(sslID))
{
Memory::Write_U32(SSL_OK, _BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
}
break;
}
default:
ERROR_LOG(WII_IPC_SSL, "%i "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_Parameter,
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, _BufferOut, BufferOutSize,
_BufferOut2, BufferOutSize2, _BufferOut3, BufferOutSize3);
break;
} }
return returnValue; return returnValue;
} }