service/SSL: convert to ServiceFramework
This commit is contained in:
parent
f50e505a5a
commit
b06f468049
3 changed files with 58 additions and 49 deletions
|
@ -262,7 +262,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm) {
|
||||||
AddService(new HTTP::HTTP_C);
|
AddService(new HTTP::HTTP_C);
|
||||||
AddService(new PM::PM_APP);
|
AddService(new PM::PM_APP);
|
||||||
AddService(new SOC::SOC_U);
|
AddService(new SOC::SOC_U);
|
||||||
AddService(new SSL::SSL_C);
|
SSL::InstallInterfaces(*sm);
|
||||||
Y2R::InstallInterfaces(*sm);
|
Y2R::InstallInterfaces(*sm);
|
||||||
|
|
||||||
NGLOG_DEBUG(Service, "initialized OK");
|
NGLOG_DEBUG(Service, "initialized OK");
|
||||||
|
|
|
@ -2,34 +2,31 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <random>
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/ipc.h"
|
#include "core/hle/ipc.h"
|
||||||
|
#include "core/hle/ipc_helpers.h"
|
||||||
#include "core/hle/service/ssl_c.h"
|
#include "core/hle/service/ssl_c.h"
|
||||||
#include "core/memory.h"
|
|
||||||
|
|
||||||
namespace Service {
|
namespace Service {
|
||||||
namespace SSL {
|
namespace SSL {
|
||||||
|
|
||||||
// TODO: Implement a proper CSPRNG in the future when actual security is needed
|
void SSL_C::Initialize(Kernel::HLERequestContext& ctx) {
|
||||||
static std::mt19937 rand_gen;
|
IPC::RequestParser rp(ctx, 0x01, 0, 2);
|
||||||
|
rp.PopPID();
|
||||||
static void Initialize(Interface* self) {
|
|
||||||
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
||||||
|
|
||||||
// Seed random number generator when the SSL service is initialized
|
// Seed random number generator when the SSL service is initialized
|
||||||
std::random_device rand_device;
|
std::random_device rand_device;
|
||||||
rand_gen.seed(rand_device());
|
rand_gen.seed(rand_device());
|
||||||
|
|
||||||
// Stub, return success
|
// Stub, return success
|
||||||
cmd_buff[1] = RESULT_SUCCESS.raw;
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
|
rb.Push(RESULT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GenerateRandomData(Interface* self) {
|
void SSL_C::GenerateRandomData(Kernel::HLERequestContext& ctx) {
|
||||||
u32* cmd_buff = Kernel::GetCommandBuffer();
|
IPC::RequestParser rp(ctx, 0x11, 1, 2);
|
||||||
|
u32 size = rp.Pop<u32>();
|
||||||
u32 size = cmd_buff[1];
|
auto buffer = rp.PopMappedBuffer();
|
||||||
VAddr address = cmd_buff[3];
|
|
||||||
|
|
||||||
// Fill the output buffer with random data.
|
// Fill the output buffer with random data.
|
||||||
u32 data = 0;
|
u32 data = 0;
|
||||||
|
@ -43,23 +40,26 @@ static void GenerateRandomData(Interface* self) {
|
||||||
|
|
||||||
if (size > 4) {
|
if (size > 4) {
|
||||||
// Use up the entire 4 bytes of the random data for as long as possible
|
// Use up the entire 4 bytes of the random data for as long as possible
|
||||||
Memory::Write32(address + i, data);
|
buffer.Write(&data, i, 4);
|
||||||
i += 4;
|
i += 4;
|
||||||
} else if (size == 2) {
|
} else if (size == 2) {
|
||||||
Memory::Write16(address + i, static_cast<u16>(data & 0xffff));
|
buffer.Write(&data, i, 2);
|
||||||
i += 2;
|
i += 2;
|
||||||
} else {
|
} else {
|
||||||
Memory::Write8(address + i, static_cast<u8>(data & 0xff));
|
buffer.Write(&data, i, 1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stub, return success
|
// Stub, return success
|
||||||
cmd_buff[1] = RESULT_SUCCESS.raw;
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
rb.PushMappedBuffer(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Interface::FunctionInfo FunctionTable[] = {
|
SSL_C::SSL_C() : ServiceFramework("ssl:C") {
|
||||||
{0x00010002, Initialize, "Initialize"},
|
static const FunctionInfo functions[] = {
|
||||||
|
{0x00010002, &SSL_C::Initialize, "Initialize"},
|
||||||
{0x000200C2, nullptr, "CreateContext"},
|
{0x000200C2, nullptr, "CreateContext"},
|
||||||
{0x00030000, nullptr, "CreateRootCertChain"},
|
{0x00030000, nullptr, "CreateRootCertChain"},
|
||||||
{0x00040040, nullptr, "DestroyRootCertChain"},
|
{0x00040040, nullptr, "DestroyRootCertChain"},
|
||||||
|
@ -69,7 +69,7 @@ const Interface::FunctionInfo FunctionTable[] = {
|
||||||
{0x000D0084, nullptr, "OpenClientCertContext"},
|
{0x000D0084, nullptr, "OpenClientCertContext"},
|
||||||
{0x000E0040, nullptr, "OpenDefaultClientCertContext"},
|
{0x000E0040, nullptr, "OpenDefaultClientCertContext"},
|
||||||
{0x000F0040, nullptr, "CloseClientCertContext"},
|
{0x000F0040, nullptr, "CloseClientCertContext"},
|
||||||
{0x00110042, GenerateRandomData, "GenerateRandomData"},
|
{0x00110042, &SSL_C::GenerateRandomData, "GenerateRandomData"},
|
||||||
{0x00120042, nullptr, "InitializeConnectionSession"},
|
{0x00120042, nullptr, "InitializeConnectionSession"},
|
||||||
{0x00130040, nullptr, "StartConnection"},
|
{0x00130040, nullptr, "StartConnection"},
|
||||||
{0x00140040, nullptr, "StartConnectionGetOut"},
|
{0x00140040, nullptr, "StartConnectionGetOut"},
|
||||||
|
@ -82,10 +82,13 @@ const Interface::FunctionInfo FunctionTable[] = {
|
||||||
{0x001C00C4, nullptr, "ContextGetProtocolCipher"},
|
{0x001C00C4, nullptr, "ContextGetProtocolCipher"},
|
||||||
{0x001E0040, nullptr, "DestroyContext"},
|
{0x001E0040, nullptr, "DestroyContext"},
|
||||||
{0x001F0082, nullptr, "ContextInitSharedmem"},
|
{0x001F0082, nullptr, "ContextInitSharedmem"},
|
||||||
};
|
};
|
||||||
|
|
||||||
SSL_C::SSL_C() {
|
RegisterHandlers(functions);
|
||||||
Register(FunctionTable);
|
}
|
||||||
|
|
||||||
|
void InstallInterfaces(SM::ServiceManager& service_manager) {
|
||||||
|
std::make_shared<SSL_C>()->InstallAsService(service_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace SSL
|
} // namespace SSL
|
||||||
|
|
|
@ -4,19 +4,25 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <random>
|
||||||
#include "core/hle/service/service.h"
|
#include "core/hle/service/service.h"
|
||||||
|
|
||||||
namespace Service {
|
namespace Service {
|
||||||
namespace SSL {
|
namespace SSL {
|
||||||
|
|
||||||
class SSL_C final : public Interface {
|
class SSL_C final : public ServiceFramework<SSL_C> {
|
||||||
public:
|
public:
|
||||||
SSL_C();
|
SSL_C();
|
||||||
|
|
||||||
std::string GetPortName() const override {
|
private:
|
||||||
return "ssl:C";
|
void Initialize(Kernel::HLERequestContext& ctx);
|
||||||
}
|
void GenerateRandomData(Kernel::HLERequestContext& ctx);
|
||||||
|
|
||||||
|
// TODO: Implement a proper CSPRNG in the future when actual security is needed
|
||||||
|
std::mt19937 rand_gen;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void InstallInterfaces(SM::ServiceManager& service_manager);
|
||||||
|
|
||||||
} // namespace SSL
|
} // namespace SSL
|
||||||
} // namespace Service
|
} // namespace Service
|
||||||
|
|
Loading…
Reference in a new issue