mirror of
https://github.com/PabloMK7/citra.git
synced 2025-10-11 20:10:03 +00:00
http/soc: Various implementations and fixes (#6828)
This commit is contained in:
parent
baf3ea4beb
commit
970f2284d8
17 changed files with 322 additions and 202 deletions
99
src/core/hle/service/ssl/ssl_c.cpp
Normal file
99
src/core/hle/service/ssl/ssl_c.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "common/archives.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/ipc.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/service/ssl/ssl_c.h"
|
||||
|
||||
SERIALIZE_EXPORT_IMPL(Service::SSL::SSL_C)
|
||||
namespace Service::SSL {
|
||||
|
||||
void SSL_C::Initialize(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp(ctx);
|
||||
rp.PopPID();
|
||||
|
||||
// Seed random number generator when the SSL service is initialized
|
||||
std::random_device rand_device;
|
||||
rand_gen.seed(rand_device());
|
||||
|
||||
// Stub, return success
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
void SSL_C::GenerateRandomData(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp(ctx);
|
||||
u32 size = rp.Pop<u32>();
|
||||
auto buffer = rp.PopMappedBuffer();
|
||||
|
||||
// Fill the output buffer with random data.
|
||||
u32 data = 0;
|
||||
u32 i = 0;
|
||||
while (i < size) {
|
||||
if ((i % 4) == 0) {
|
||||
// The random number generator returns 4 bytes worth of data, so generate new random
|
||||
// data when i == 0 and when i is divisible by 4
|
||||
data = rand_gen();
|
||||
}
|
||||
|
||||
if (size > 4) {
|
||||
// Use up the entire 4 bytes of the random data for as long as possible
|
||||
buffer.Write(&data, i, 4);
|
||||
i += 4;
|
||||
} else if (size == 2) {
|
||||
buffer.Write(&data, i, 2);
|
||||
i += 2;
|
||||
} else {
|
||||
buffer.Write(&data, i, 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Stub, return success
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushMappedBuffer(buffer);
|
||||
}
|
||||
|
||||
SSL_C::SSL_C() : ServiceFramework("ssl:C") {
|
||||
static const FunctionInfo functions[] = {
|
||||
// clang-format off
|
||||
{0x0001, &SSL_C::Initialize, "Initialize"},
|
||||
{0x0002, nullptr, "CreateContext"},
|
||||
{0x0003, nullptr, "CreateRootCertChain"},
|
||||
{0x0004, nullptr, "DestroyRootCertChain"},
|
||||
{0x0005, nullptr, "AddTrustedRootCA"},
|
||||
{0x0006, nullptr, "RootCertChainAddDefaultCert"},
|
||||
{0x0007, nullptr, "RootCertChainRemoveCert"},
|
||||
{0x000D, nullptr, "OpenClientCertContext"},
|
||||
{0x000E, nullptr, "OpenDefaultClientCertContext"},
|
||||
{0x000F, nullptr, "CloseClientCertContext"},
|
||||
{0x0011, &SSL_C::GenerateRandomData, "GenerateRandomData"},
|
||||
{0x0012, nullptr, "InitializeConnectionSession"},
|
||||
{0x0013, nullptr, "StartConnection"},
|
||||
{0x0014, nullptr, "StartConnectionGetOut"},
|
||||
{0x0015, nullptr, "Read"},
|
||||
{0x0016, nullptr, "ReadPeek"},
|
||||
{0x0017, nullptr, "Write"},
|
||||
{0x0018, nullptr, "ContextSetRootCertChain"},
|
||||
{0x0019, nullptr, "ContextSetClientCert"},
|
||||
{0x001B, nullptr, "ContextClearOpt"},
|
||||
{0x001C, nullptr, "ContextGetProtocolCipher"},
|
||||
{0x001E, nullptr, "DestroyContext"},
|
||||
{0x001F, nullptr, "ContextInitSharedmem"},
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
RegisterHandlers(functions);
|
||||
}
|
||||
|
||||
void InstallInterfaces(Core::System& system) {
|
||||
auto& service_manager = system.ServiceManager();
|
||||
std::make_shared<SSL_C>()->InstallAsService(service_manager);
|
||||
}
|
||||
|
||||
} // namespace Service::SSL
|
34
src/core/hle/service/ssl/ssl_c.h
Normal file
34
src/core/hle/service/ssl/ssl_c.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <random>
|
||||
#include "core/hle/service/service.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace Service::SSL {
|
||||
|
||||
class SSL_C final : public ServiceFramework<SSL_C> {
|
||||
public:
|
||||
SSL_C();
|
||||
|
||||
private:
|
||||
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;
|
||||
|
||||
SERVICE_SERIALIZATION_SIMPLE
|
||||
};
|
||||
|
||||
void InstallInterfaces(Core::System& system);
|
||||
|
||||
} // namespace Service::SSL
|
||||
|
||||
BOOST_CLASS_EXPORT_KEY(Service::SSL::SSL_C)
|
Loading…
Add table
Add a link
Reference in a new issue