2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-03-23 07:32:50 +01:00
|
|
|
|
2018-04-10 20:40:53 +02:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2018-09-02 17:36:43 +02:00
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
#include "core/hle/service/sm/sm.h"
|
2018-03-23 07:32:50 +01:00
|
|
|
#include "core/hle/service/ssl/ssl.h"
|
|
|
|
|
2018-04-20 03:41:44 +02:00
|
|
|
namespace Service::SSL {
|
2018-03-23 07:32:50 +01:00
|
|
|
|
2021-05-11 14:31:16 +02:00
|
|
|
enum class CertificateFormat : u32 {
|
|
|
|
Pem = 1,
|
|
|
|
Der = 2,
|
|
|
|
};
|
|
|
|
|
2018-04-10 20:40:53 +02:00
|
|
|
class ISslConnection final : public ServiceFramework<ISslConnection> {
|
|
|
|
public:
|
2020-11-26 21:19:08 +01:00
|
|
|
explicit ISslConnection(Core::System& system_) : ServiceFramework{system_, "ISslConnection"} {
|
2019-11-12 14:54:58 +01:00
|
|
|
// clang-format off
|
2018-04-10 20:40:53 +02:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, nullptr, "SetSocketDescriptor"},
|
|
|
|
{1, nullptr, "SetHostName"},
|
|
|
|
{2, nullptr, "SetVerifyOption"},
|
|
|
|
{3, nullptr, "SetIoMode"},
|
|
|
|
{4, nullptr, "GetSocketDescriptor"},
|
|
|
|
{5, nullptr, "GetHostName"},
|
|
|
|
{6, nullptr, "GetVerifyOption"},
|
|
|
|
{7, nullptr, "GetIoMode"},
|
|
|
|
{8, nullptr, "DoHandshake"},
|
|
|
|
{9, nullptr, "DoHandshakeGetServerCert"},
|
|
|
|
{10, nullptr, "Read"},
|
|
|
|
{11, nullptr, "Write"},
|
|
|
|
{12, nullptr, "Pending"},
|
|
|
|
{13, nullptr, "Peek"},
|
|
|
|
{14, nullptr, "Poll"},
|
|
|
|
{15, nullptr, "GetVerifyCertError"},
|
|
|
|
{16, nullptr, "GetNeededServerCertBufferSize"},
|
|
|
|
{17, nullptr, "SetSessionCacheMode"},
|
|
|
|
{18, nullptr, "GetSessionCacheMode"},
|
|
|
|
{19, nullptr, "FlushSessionCache"},
|
|
|
|
{20, nullptr, "SetRenegotiationMode"},
|
|
|
|
{21, nullptr, "GetRenegotiationMode"},
|
|
|
|
{22, nullptr, "SetOption"},
|
|
|
|
{23, nullptr, "GetOption"},
|
|
|
|
{24, nullptr, "GetVerifyCertErrors"},
|
|
|
|
{25, nullptr, "GetCipherInfo"},
|
2019-11-12 14:54:58 +01:00
|
|
|
{26, nullptr, "SetNextAlpnProto"},
|
|
|
|
{27, nullptr, "GetNextAlpnProto"},
|
2018-04-10 20:40:53 +02:00
|
|
|
};
|
2019-11-12 14:54:58 +01:00
|
|
|
// clang-format on
|
|
|
|
|
2018-04-10 20:40:53 +02:00
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ISslContext final : public ServiceFramework<ISslContext> {
|
|
|
|
public:
|
2020-11-26 21:19:08 +01:00
|
|
|
explicit ISslContext(Core::System& system_) : ServiceFramework{system_, "ISslContext"} {
|
2018-04-10 20:40:53 +02:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &ISslContext::SetOption, "SetOption"},
|
|
|
|
{1, nullptr, "GetOption"},
|
|
|
|
{2, &ISslContext::CreateConnection, "CreateConnection"},
|
|
|
|
{3, nullptr, "GetConnectionCount"},
|
2021-05-11 14:31:16 +02:00
|
|
|
{4, &ISslContext::ImportServerPki, "ImportServerPki"},
|
|
|
|
{5, &ISslContext::ImportClientPki, "ImportClientPki"},
|
2018-04-10 20:40:53 +02:00
|
|
|
{6, nullptr, "RemoveServerPki"},
|
|
|
|
{7, nullptr, "RemoveClientPki"},
|
|
|
|
{8, nullptr, "RegisterInternalPki"},
|
|
|
|
{9, nullptr, "AddPolicyOid"},
|
|
|
|
{10, nullptr, "ImportCrl"},
|
|
|
|
{11, nullptr, "RemoveCrl"},
|
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetOption(Kernel::HLERequestContext& ctx) {
|
2019-04-04 18:56:04 +02:00
|
|
|
struct Parameters {
|
|
|
|
u8 enable;
|
|
|
|
u32 option;
|
|
|
|
};
|
2018-11-26 07:06:13 +01:00
|
|
|
|
2018-04-10 20:40:53 +02:00
|
|
|
IPC::RequestParser rp{ctx};
|
2019-04-04 18:56:04 +02:00
|
|
|
const auto parameters = rp.PopRaw<Parameters>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called. enable={}, option={}", parameters.enable,
|
|
|
|
parameters.option);
|
2018-04-10 20:40:53 +02:00
|
|
|
|
2018-09-19 07:09:59 +02:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 07:05:04 +02:00
|
|
|
rb.Push(ResultSuccess);
|
2018-04-10 20:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateConnection(Kernel::HLERequestContext& ctx) {
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called");
|
2018-04-10 20:40:53 +02:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 07:05:04 +02:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 21:19:08 +01:00
|
|
|
rb.PushIpcInterface<ISslConnection>(system);
|
2018-04-10 20:40:53 +02:00
|
|
|
}
|
2021-05-11 14:31:16 +02:00
|
|
|
|
|
|
|
void ImportServerPki(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto certificate_format = rp.PopEnum<CertificateFormat>();
|
|
|
|
const auto pkcs_12_certificates = ctx.ReadBuffer(0);
|
|
|
|
|
|
|
|
constexpr u64 server_id = 0;
|
|
|
|
|
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called, certificate_format={}", certificate_format);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 07:05:04 +02:00
|
|
|
rb.Push(ResultSuccess);
|
2021-05-11 14:31:16 +02:00
|
|
|
rb.Push(server_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportClientPki(Kernel::HLERequestContext& ctx) {
|
|
|
|
const auto pkcs_12_certificate = ctx.ReadBuffer(0);
|
|
|
|
const auto ascii_password = [&ctx] {
|
|
|
|
if (ctx.CanReadBuffer(1)) {
|
|
|
|
return ctx.ReadBuffer(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::vector<u8>{};
|
|
|
|
}();
|
|
|
|
|
|
|
|
constexpr u64 client_id = 0;
|
|
|
|
|
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called");
|
|
|
|
|
2021-05-13 15:00:46 +02:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 07:05:04 +02:00
|
|
|
rb.Push(ResultSuccess);
|
2021-05-11 14:31:16 +02:00
|
|
|
rb.Push(client_id);
|
|
|
|
}
|
2018-04-10 20:40:53 +02:00
|
|
|
};
|
|
|
|
|
2018-09-02 17:36:43 +02:00
|
|
|
class SSL final : public ServiceFramework<SSL> {
|
|
|
|
public:
|
2020-11-26 21:19:08 +01:00
|
|
|
explicit SSL(Core::System& system_) : ServiceFramework{system_, "ssl"} {
|
2018-09-02 17:36:43 +02:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &SSL::CreateContext, "CreateContext"},
|
|
|
|
{1, nullptr, "GetContextCount"},
|
|
|
|
{2, nullptr, "GetCertificates"},
|
|
|
|
{3, nullptr, "GetCertificateBufSize"},
|
|
|
|
{4, nullptr, "DebugIoctl"},
|
|
|
|
{5, &SSL::SetInterfaceVersion, "SetInterfaceVersion"},
|
|
|
|
{6, nullptr, "FlushSessionCache"},
|
2019-04-10 20:48:37 +02:00
|
|
|
{7, nullptr, "SetDebugOption"},
|
|
|
|
{8, nullptr, "GetDebugOption"},
|
2018-09-02 17:36:43 +02:00
|
|
|
};
|
|
|
|
// clang-format on
|
2018-04-10 20:40:53 +02:00
|
|
|
|
2018-09-02 17:36:43 +02:00
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-04-10 20:40:53 +02:00
|
|
|
|
2018-09-02 17:36:43 +02:00
|
|
|
private:
|
2018-09-19 08:46:11 +02:00
|
|
|
u32 ssl_version{};
|
2018-09-02 17:36:43 +02:00
|
|
|
void CreateContext(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called");
|
2018-03-23 07:32:50 +01:00
|
|
|
|
2018-09-02 17:36:43 +02:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 07:05:04 +02:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 21:19:08 +01:00
|
|
|
rb.PushIpcInterface<ISslContext>(system);
|
2018-09-02 17:36:43 +02:00
|
|
|
}
|
2018-04-22 07:04:24 +02:00
|
|
|
|
2018-09-02 17:36:43 +02:00
|
|
|
void SetInterfaceVersion(Kernel::HLERequestContext& ctx) {
|
2018-09-19 08:46:11 +02:00
|
|
|
LOG_DEBUG(Service_SSL, "called");
|
2018-11-26 07:06:13 +01:00
|
|
|
|
2018-09-02 17:36:43 +02:00
|
|
|
IPC::RequestParser rp{ctx};
|
2018-09-19 08:46:11 +02:00
|
|
|
ssl_version = rp.Pop<u32>();
|
2018-09-02 17:36:43 +02:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 07:05:04 +02:00
|
|
|
rb.Push(ResultSuccess);
|
2018-09-02 17:36:43 +02:00
|
|
|
}
|
|
|
|
};
|
2018-04-22 07:04:24 +02:00
|
|
|
|
2020-11-26 21:19:08 +01:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
|
|
|
|
std::make_shared<SSL>(system)->InstallAsService(service_manager);
|
2018-03-23 07:32:50 +01:00
|
|
|
}
|
|
|
|
|
2018-04-20 03:41:44 +02:00
|
|
|
} // namespace Service::SSL
|