2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-03-23 02:32:50 -04:00
|
|
|
|
2018-04-10 14:40:53 -04:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2018-09-02 11:36:43 -04:00
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
#include "core/hle/service/sm/sm.h"
|
2018-03-23 02:32:50 -04:00
|
|
|
#include "core/hle/service/ssl/ssl.h"
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
namespace Service::SSL {
|
2018-03-23 02:32:50 -04:00
|
|
|
|
2021-05-11 08:31:16 -04:00
|
|
|
enum class CertificateFormat : u32 {
|
|
|
|
Pem = 1,
|
|
|
|
Der = 2,
|
|
|
|
};
|
|
|
|
|
2018-04-10 14:40:53 -04:00
|
|
|
class ISslConnection final : public ServiceFramework<ISslConnection> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit ISslConnection(Core::System& system_) : ServiceFramework{system_, "ISslConnection"} {
|
2019-11-12 08:54:58 -05:00
|
|
|
// clang-format off
|
2018-04-10 14:40:53 -04: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 08:54:58 -05:00
|
|
|
{26, nullptr, "SetNextAlpnProto"},
|
|
|
|
{27, nullptr, "GetNextAlpnProto"},
|
2018-04-10 14:40:53 -04:00
|
|
|
};
|
2019-11-12 08:54:58 -05:00
|
|
|
// clang-format on
|
|
|
|
|
2018-04-10 14:40:53 -04:00
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ISslContext final : public ServiceFramework<ISslContext> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit ISslContext(Core::System& system_) : ServiceFramework{system_, "ISslContext"} {
|
2018-04-10 14:40:53 -04:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &ISslContext::SetOption, "SetOption"},
|
|
|
|
{1, nullptr, "GetOption"},
|
|
|
|
{2, &ISslContext::CreateConnection, "CreateConnection"},
|
|
|
|
{3, nullptr, "GetConnectionCount"},
|
2021-05-11 08:31:16 -04:00
|
|
|
{4, &ISslContext::ImportServerPki, "ImportServerPki"},
|
|
|
|
{5, &ISslContext::ImportClientPki, "ImportClientPki"},
|
2018-04-10 14:40:53 -04: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 12:56:04 -04:00
|
|
|
struct Parameters {
|
|
|
|
u8 enable;
|
|
|
|
u32 option;
|
|
|
|
};
|
2018-11-26 01:06:13 -05:00
|
|
|
|
2018-04-10 14:40:53 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
2019-04-04 12:56:04 -04:00
|
|
|
const auto parameters = rp.PopRaw<Parameters>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called. enable={}, option={}", parameters.enable,
|
|
|
|
parameters.option);
|
2018-04-10 14:40:53 -04:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-04-10 14:40:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateConnection(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called");
|
2018-04-10 14:40:53 -04:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 15:19:08 -05:00
|
|
|
rb.PushIpcInterface<ISslConnection>(system);
|
2018-04-10 14:40:53 -04:00
|
|
|
}
|
2021-05-11 08:31:16 -04:00
|
|
|
|
|
|
|
void ImportServerPki(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto certificate_format = rp.PopEnum<CertificateFormat>();
|
2022-12-25 13:42:32 -05:00
|
|
|
[[maybe_unused]] const auto pkcs_12_certificates = ctx.ReadBufferSpan(0);
|
2021-05-11 08:31:16 -04:00
|
|
|
|
|
|
|
constexpr u64 server_id = 0;
|
|
|
|
|
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called, certificate_format={}", certificate_format);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-05-11 08:31:16 -04:00
|
|
|
rb.Push(server_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportClientPki(Kernel::HLERequestContext& ctx) {
|
2022-12-25 13:42:32 -05:00
|
|
|
[[maybe_unused]] const auto pkcs_12_certificate = ctx.ReadBufferSpan(0);
|
|
|
|
[[maybe_unused]] const auto ascii_password = [&ctx] {
|
2021-05-11 08:31:16 -04:00
|
|
|
if (ctx.CanReadBuffer(1)) {
|
2022-12-25 13:42:32 -05:00
|
|
|
return ctx.ReadBufferSpan(1);
|
2021-05-11 08:31:16 -04:00
|
|
|
}
|
|
|
|
|
2022-12-25 13:42:32 -05:00
|
|
|
return std::span<const u8>{};
|
2021-05-11 08:31:16 -04:00
|
|
|
}();
|
|
|
|
|
|
|
|
constexpr u64 client_id = 0;
|
|
|
|
|
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called");
|
|
|
|
|
2021-05-13 09:00:46 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-05-11 08:31:16 -04:00
|
|
|
rb.Push(client_id);
|
|
|
|
}
|
2018-04-10 14:40:53 -04:00
|
|
|
};
|
|
|
|
|
2018-09-02 11:36:43 -04:00
|
|
|
class SSL final : public ServiceFramework<SSL> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit SSL(Core::System& system_) : ServiceFramework{system_, "ssl"} {
|
2018-09-02 11:36:43 -04: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 14:48:37 -04:00
|
|
|
{7, nullptr, "SetDebugOption"},
|
|
|
|
{8, nullptr, "GetDebugOption"},
|
2018-09-02 11:36:43 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
2018-04-10 14:40:53 -04:00
|
|
|
|
2018-09-02 11:36:43 -04:00
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-04-10 14:40:53 -04:00
|
|
|
|
2018-09-02 11:36:43 -04:00
|
|
|
private:
|
2018-09-19 02:46:11 -04:00
|
|
|
u32 ssl_version{};
|
2018-09-02 11:36:43 -04:00
|
|
|
void CreateContext(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called");
|
2018-03-23 02:32:50 -04:00
|
|
|
|
2018-09-02 11:36:43 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 15:19:08 -05:00
|
|
|
rb.PushIpcInterface<ISslContext>(system);
|
2018-09-02 11:36:43 -04:00
|
|
|
}
|
2018-04-22 01:04:24 -04:00
|
|
|
|
2018-09-02 11:36:43 -04:00
|
|
|
void SetInterfaceVersion(Kernel::HLERequestContext& ctx) {
|
2018-09-19 02:46:11 -04:00
|
|
|
LOG_DEBUG(Service_SSL, "called");
|
2018-11-26 01:06:13 -05:00
|
|
|
|
2018-09-02 11:36:43 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
2018-09-19 02:46:11 -04:00
|
|
|
ssl_version = rp.Pop<u32>();
|
2018-09-02 11:36:43 -04:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-09-02 11:36:43 -04:00
|
|
|
}
|
|
|
|
};
|
2018-04-22 01:04:24 -04:00
|
|
|
|
2020-11-26 15:19:08 -05:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
|
|
|
|
std::make_shared<SSL>(system)->InstallAsService(service_manager);
|
2018-03-23 02:32:50 -04:00
|
|
|
}
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::SSL
|