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
|
|
|
|
2023-02-19 14:42:12 -05:00
|
|
|
#include "core/hle/service/ipc_helpers.h"
|
2023-02-18 16:26:48 -05:00
|
|
|
#include "core/hle/service/server_manager.h"
|
2018-09-02 11:36:43 -04:00
|
|
|
#include "core/hle/service/service.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
|
|
|
|
2023-02-27 20:05:08 -05:00
|
|
|
// This is nn::ssl::sf::CertificateFormat
|
2021-05-11 08:31:16 -04:00
|
|
|
enum class CertificateFormat : u32 {
|
|
|
|
Pem = 1,
|
|
|
|
Der = 2,
|
|
|
|
};
|
|
|
|
|
2023-02-27 20:05:08 -05:00
|
|
|
// This is nn::ssl::sf::ContextOption
|
|
|
|
enum class ContextOption : u32 {
|
|
|
|
None = 0,
|
|
|
|
CrlImportDateCheckEnable = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
// This is nn::ssl::sf::SslVersion
|
|
|
|
struct SslVersion {
|
|
|
|
union {
|
|
|
|
u32 raw{};
|
|
|
|
|
|
|
|
BitField<0, 1, u32> tls_auto;
|
|
|
|
BitField<3, 1, u32> tls_v10;
|
|
|
|
BitField<4, 1, u32> tls_v11;
|
|
|
|
BitField<5, 1, u32> tls_v12;
|
|
|
|
BitField<6, 1, u32> tls_v13;
|
|
|
|
BitField<24, 7, u32> api_version;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-04-10 14:40:53 -04:00
|
|
|
class ISslConnection final : public ServiceFramework<ISslConnection> {
|
|
|
|
public:
|
2023-02-27 20:05:08 -05:00
|
|
|
explicit ISslConnection(Core::System& system_, SslVersion version)
|
|
|
|
: ServiceFramework{system_, "ISslConnection"}, ssl_version{version} {
|
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"},
|
2023-02-24 13:52:32 -05:00
|
|
|
{28, nullptr, "SetDtlsSocketDescriptor"},
|
|
|
|
{29, nullptr, "GetDtlsHandshakeTimeout"},
|
|
|
|
{30, nullptr, "SetPrivateOption"},
|
|
|
|
{31, nullptr, "SetSrtpCiphers"},
|
|
|
|
{32, nullptr, "GetSrtpCipher"},
|
|
|
|
{33, nullptr, "ExportKeyingMaterial"},
|
|
|
|
{34, nullptr, "SetIoTimeout"},
|
|
|
|
{35, nullptr, "GetIoTimeout"},
|
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);
|
|
|
|
}
|
2023-02-27 20:05:08 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
SslVersion ssl_version;
|
2018-04-10 14:40:53 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ISslContext final : public ServiceFramework<ISslContext> {
|
|
|
|
public:
|
2023-02-27 20:05:08 -05:00
|
|
|
explicit ISslContext(Core::System& system_, SslVersion version)
|
|
|
|
: ServiceFramework{system_, "ISslContext"}, ssl_version{version} {
|
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"},
|
2023-02-24 13:52:32 -05:00
|
|
|
{12, nullptr, "ImportClientCertKeyPki"},
|
|
|
|
{13, nullptr, "GeneratePrivateKeyAndCert"},
|
2018-04-10 14:40:53 -04:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-02-27 20:05:08 -05:00
|
|
|
SslVersion ssl_version;
|
|
|
|
|
2023-02-19 14:42:12 -05:00
|
|
|
void SetOption(HLERequestContext& ctx) {
|
2019-04-04 12:56:04 -04:00
|
|
|
struct Parameters {
|
2023-02-27 20:05:08 -05:00
|
|
|
ContextOption option;
|
|
|
|
s32 value;
|
2019-04-04 12:56:04 -04:00
|
|
|
};
|
2023-02-27 20:05:08 -05:00
|
|
|
static_assert(sizeof(Parameters) == 0x8, "Parameters is an invalid size");
|
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>();
|
|
|
|
|
2023-02-27 20:05:08 -05:00
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called. option={}, value={}", parameters.option,
|
|
|
|
parameters.value);
|
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
|
|
|
}
|
|
|
|
|
2023-02-19 14:42:12 -05:00
|
|
|
void CreateConnection(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);
|
2023-02-27 20:05:08 -05:00
|
|
|
rb.PushIpcInterface<ISslConnection>(system, ssl_version);
|
2018-04-10 14:40:53 -04:00
|
|
|
}
|
2021-05-11 08:31:16 -04:00
|
|
|
|
2023-02-19 14:42:12 -05:00
|
|
|
void ImportServerPki(HLERequestContext& ctx) {
|
2021-05-11 08:31:16 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto certificate_format = rp.PopEnum<CertificateFormat>();
|
2023-02-03 00:08:45 -05:00
|
|
|
[[maybe_unused]] const auto pkcs_12_certificates = ctx.ReadBuffer(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);
|
|
|
|
}
|
|
|
|
|
2023-02-19 14:42:12 -05:00
|
|
|
void ImportClientPki(HLERequestContext& ctx) {
|
2023-02-03 00:08:45 -05:00
|
|
|
[[maybe_unused]] const auto pkcs_12_certificate = ctx.ReadBuffer(0);
|
|
|
|
[[maybe_unused]] const auto ascii_password = [&ctx] {
|
2021-05-11 08:31:16 -04:00
|
|
|
if (ctx.CanReadBuffer(1)) {
|
2022-12-25 14:31:53 -05:00
|
|
|
return ctx.ReadBuffer(1);
|
2021-05-11 08:31:16 -04:00
|
|
|
}
|
|
|
|
|
2023-02-03 00:08:45 -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
|
|
|
};
|
|
|
|
|
2023-02-27 20:05:08 -05:00
|
|
|
class ISslService final : public ServiceFramework<ISslService> {
|
2018-09-02 11:36:43 -04:00
|
|
|
public:
|
2023-02-27 20:05:08 -05:00
|
|
|
explicit ISslService(Core::System& system_) : ServiceFramework{system_, "ssl"} {
|
2018-09-02 11:36:43 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2023-02-27 20:05:08 -05:00
|
|
|
{0, &ISslService::CreateContext, "CreateContext"},
|
2018-09-02 11:36:43 -04:00
|
|
|
{1, nullptr, "GetContextCount"},
|
|
|
|
{2, nullptr, "GetCertificates"},
|
|
|
|
{3, nullptr, "GetCertificateBufSize"},
|
|
|
|
{4, nullptr, "DebugIoctl"},
|
2023-02-27 20:05:08 -05:00
|
|
|
{5, &ISslService::SetInterfaceVersion, "SetInterfaceVersion"},
|
2018-09-02 11:36:43 -04:00
|
|
|
{6, nullptr, "FlushSessionCache"},
|
2019-04-10 14:48:37 -04:00
|
|
|
{7, nullptr, "SetDebugOption"},
|
|
|
|
{8, nullptr, "GetDebugOption"},
|
2023-02-27 20:05:08 -05:00
|
|
|
{8, nullptr, "ClearTls12FallbackFlag"},
|
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:
|
2023-02-19 14:42:12 -05:00
|
|
|
void CreateContext(HLERequestContext& ctx) {
|
2023-02-27 20:05:08 -05:00
|
|
|
struct Parameters {
|
|
|
|
SslVersion ssl_version;
|
|
|
|
INSERT_PADDING_BYTES(0x4);
|
|
|
|
u64 pid_placeholder;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(Parameters) == 0x10, "Parameters is an invalid size");
|
|
|
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto parameters = rp.PopRaw<Parameters>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_SSL, "(STUBBED) called, api_version={}, pid_placeholder={}",
|
|
|
|
parameters.ssl_version.api_version, parameters.pid_placeholder);
|
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);
|
2023-02-27 20:05:08 -05:00
|
|
|
rb.PushIpcInterface<ISslContext>(system, parameters.ssl_version);
|
2018-09-02 11:36:43 -04:00
|
|
|
}
|
2018-04-22 01:04:24 -04:00
|
|
|
|
2023-02-19 14:42:12 -05:00
|
|
|
void SetInterfaceVersion(HLERequestContext& ctx) {
|
2018-09-02 11:36:43 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
2023-02-27 20:05:08 -05:00
|
|
|
u32 ssl_version = rp.Pop<u32>();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_SSL, "called, ssl_version={}", ssl_version);
|
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
|
|
|
|
2023-02-18 16:26:48 -05:00
|
|
|
void LoopProcess(Core::System& system) {
|
|
|
|
auto server_manager = std::make_unique<ServerManager>(system);
|
|
|
|
|
2023-02-27 20:05:08 -05:00
|
|
|
server_manager->RegisterNamedService("ssl", std::make_shared<ISslService>(system));
|
2023-02-18 16:26:48 -05:00
|
|
|
ServerManager::RunServer(std::move(server_manager));
|
2018-03-23 02:32:50 -04:00
|
|
|
}
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::SSL
|