Files
eden/src/core/hle/service/ssl/ssl.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

776 lines
27 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
2025-09-21 21:58:59 +02:00
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2018-03-23 09:32:50 +03:00
2023-06-19 18:17:43 -07:00
#include "common/string_util.h"
#include "core/core.h"
2023-07-16 18:55:27 -04:00
#include "core/hle/result.h"
2024-02-24 12:49:08 -05:00
#include "core/hle/service/cmif_serialization.h"
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"
2023-06-19 18:17:43 -07:00
#include "core/hle/service/sm/sm.h"
#include "core/hle/service/sockets/bsd.h"
2024-02-24 12:49:08 -05:00
#include "core/hle/service/ssl/cert_store.h"
2018-03-23 09:32:50 +03:00
#include "core/hle/service/ssl/ssl.h"
2023-06-19 18:17:43 -07:00
#include "core/hle/service/ssl/ssl_backend.h"
#include "core/internal_network/network.h"
#include "core/internal_network/sockets.h"
2018-03-23 09:32:50 +03:00
namespace Service::SSL {
2018-03-23 09:32:50 +03:00
// This is nn::ssl::sf::CertificateFormat
2021-05-11 08:31:16 -04:00
enum class CertificateFormat : u32 {
Pem = 1,
Der = 2,
};
// This is nn::ssl::sf::ContextOption
enum class ContextOption : u32 {
None = 0,
CrlImportDateCheckEnable = 1,
};
2023-06-19 18:17:43 -07:00
// This is nn::ssl::Connection::IoMode
enum class IoMode : u32 {
Blocking = 1,
NonBlocking = 2,
};
// This is nn::ssl::sf::OptionType
enum class OptionType : u32 {
DoNotCloseSocket = 0,
GetServerCertChain = 1,
SkipDefaultVerify = 2,
EnableAlpn = 3,
2023-06-19 18:17:43 -07:00
};
2026-09-14 17:06:28 +00:00
// This is nn::ssl::sf::RenegotiationMode
enum RenegotiationMode : u32 {
None = 0, ///< None
Secure = 1, ///< Secure
};
// 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;
};
};
2023-06-19 18:17:43 -07:00
struct SslContextSharedData {
u32 connection_count = 0;
};
class ISslConnection final : public ServiceFramework<ISslConnection> {
public:
explicit ISslConnection(Core::System& system_in, SslVersion ssl_version_in,
std::shared_ptr<SslContextSharedData>& shared_data_in,
std::unique_ptr<SSLConnectionBackend>&& backend_in)
: ServiceFramework{system_in, "ISslConnection"}, ssl_version{ssl_version_in},
shared_data{shared_data_in}, backend{std::move(backend_in)} {
2019-11-12 08:54:58 -05:00
// clang-format off
static const FunctionInfo functions[] = {
2026-09-14 17:06:28 +00:00
{0, D<&ISslConnection::SetSocketDescriptor>, "SetSocketDescriptor"},
{1, D<&ISslConnection::SetHostName>, "SetHostName"},
{2, D<&ISslConnection::SetVerifyOption>, "SetVerifyOption"},
{3, D<&ISslConnection::SetIoMode>, "SetIoMode"},
{4, D<&ISslConnection::GetSocketDescriptor>, "GetSocketDescriptor"},
{5, D<&ISslConnection::GetHostName>, "GetHostName"},
{6, nullptr, "GetVerifyOption"},
2026-09-14 17:06:28 +00:00
{7, D<&ISslConnection::GetIoMode>, "GetIoMode"},
{8, D<&ISslConnection::DoHandshake>, "DoHandshake"},
2023-06-19 18:17:43 -07:00
{9, &ISslConnection::DoHandshakeGetServerCert, "DoHandshakeGetServerCert"},
2026-09-14 17:06:28 +00:00
{10, D<&ISslConnection::Read>, "Read"},
{11, D<&ISslConnection::Write>, "Write"},
{12, D<&ISslConnection::Pending>, "Pending"},
{13, D<&ISslConnection::Peek>, "Peek"},
{14, D<&ISslConnection::Poll>, "Poll"},
{15, D<&ISslConnection::GetVerifyCertError>, "GetVerifyCertError"},
{16, D<&ISslConnection::GetNeededServerCertBufferSize>, "GetNeededServerCertBufferSize"},
{17, D<&ISslConnection::SetSessionCacheMode>, "SetSessionCacheMode"},
{18, D<&ISslConnection::GetSessionCacheMode>, "GetSessionCacheMode"},
{19, D<&ISslConnection::FlushSessionCache>, "FlushSessionCache"},
{20, D<&ISslConnection::SetRenegotiationMode>, "SetRenegotiationMode"},
{21, D<&ISslConnection::GetRenegotiationMode>, "GetRenegotiationMode"},
{22, D<&ISslConnection::SetOption>, "SetOption"},
{23, D<&ISslConnection::GetOption>, "GetOption"},
{24, nullptr, "GetVerifyCertErrors"},
{25, nullptr, "GetCipherInfo"},
2026-09-14 17:06:28 +00:00
{26, D<&ISslConnection::SetNextAlpnProto>, "SetNextAlpnProto"},
{27, D<&ISslConnection::GetNextAlpnProto>, "GetNextAlpnProto"},
{28, nullptr, "SetDtlsSocketDescriptor"},
{29, nullptr, "GetDtlsHandshakeTimeout"},
{30, nullptr, "SetPrivateOption"},
{31, nullptr, "SetSrtpCiphers"},
{32, nullptr, "GetSrtpCipher"},
{33, nullptr, "ExportKeyingMaterial"},
{34, nullptr, "SetIoTimeout"},
{35, nullptr, "GetIoTimeout"},
};
2019-11-12 08:54:58 -05:00
// clang-format on
RegisterHandlers(functions);
2023-06-19 18:17:43 -07:00
backend->SetVerifyOption(verify_option);
2023-06-19 18:17:43 -07:00
shared_data->connection_count++;
}
~ISslConnection() {
2023-07-01 15:02:25 -07:00
shared_data->connection_count--;
if (fd_to_close.has_value()) {
const s32 fd = *fd_to_close;
if (!do_not_close_socket) {
2023-06-19 18:17:43 -07:00
LOG_ERROR(Service_SSL,
"do_not_close_socket was changed after setting socket; is this right?");
} else {
auto bsd = system.ServiceManager().GetService<Service::Sockets::BSD_USA>("bsd:u");
2023-06-19 18:17:43 -07:00
if (bsd) {
auto err = bsd->CloseImpl(fd);
if (err != Service::Sockets::Errno::SUCCESS) {
2023-06-25 19:23:23 -07:00
LOG_ERROR(Service_SSL, "Failed to close duplicated socket: {}", err);
2023-06-19 18:17:43 -07:00
}
}
}
}
}
private:
2023-06-19 18:17:43 -07:00
Result DoHandshakeImpl() {
2023-07-01 15:02:25 -07:00
ASSERT_OR_EXECUTE(!did_handshake && socket, { return ResultNoSocket; });
Result res = backend->DoHandshake();
did_handshake = res.IsSuccess();
2023-06-19 18:17:43 -07:00
return res;
}
std::vector<u8> SerializeServerCerts(const std::vector<std::vector<u8>>& certs) {
struct Header {
u64 magic;
u32 count;
u32 pad;
};
struct EntryHeader {
u32 size;
u32 offset;
};
2023-07-01 15:02:25 -07:00
if (!get_server_cert_chain) {
2023-06-19 18:17:43 -07:00
// Just return the first one, unencoded.
2026-09-14 17:06:28 +00:00
ASSERT_OR_EXECUTE_MSG(!certs.empty(), { return {}; }, "Should be at least one server cert");
2023-06-19 18:17:43 -07:00
return certs[0];
}
std::vector<u8> ret;
2026-09-14 17:06:28 +00:00
Header header{0x4E4D684374726543, u32(certs.size()), 0};
2023-06-19 18:17:43 -07:00
ret.insert(ret.end(), reinterpret_cast<u8*>(&header), reinterpret_cast<u8*>(&header + 1));
size_t data_offset = sizeof(Header) + certs.size() * sizeof(EntryHeader);
for (auto& cert : certs) {
2026-09-14 17:06:28 +00:00
EntryHeader entry_header{u32(cert.size()), u32(data_offset)};
2023-06-19 18:17:43 -07:00
data_offset += cert.size();
2026-09-14 17:06:28 +00:00
ret.insert(ret.end(), reinterpret_cast<u8*>(&entry_header), reinterpret_cast<u8*>(&entry_header + 1));
2023-06-19 18:17:43 -07:00
}
for (auto& cert : certs) {
ret.insert(ret.end(), cert.begin(), cert.end());
}
return ret;
}
2026-09-14 17:06:28 +00:00
Result SetSocketDescriptor(s32 in_fd, Out<s32> out_fd) {
LOG_DEBUG(Service_SSL, "called, fd={}", in_fd);
ASSERT(!did_handshake);
auto bsd = system.ServiceManager().GetService<Service::Sockets::BSD_USA>("bsd:u");
ASSERT_OR_EXECUTE(bsd, { return ResultInternalError; });
auto const res_v = bsd->DuplicateSocketImpl(in_fd);
if (auto *res = std::get_if<s32>(&res_v)) {
const s32 dup_fd = *res;
*out_fd = do_not_close_socket ? dup_fd : -1;
if (!do_not_close_socket)
fd_to_close = dup_fd;
auto const sock = bsd->GetSocket(dup_fd);
if (!sock.has_value()) {
LOG_ERROR(Service_SSL, "invalid socket fd {} after duplication", dup_fd);
return ResultInvalidSocket;
}
socket = std::move(*sock);
backend->SetSocket(std::move(socket));
return ResultSuccess;
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
LOG_ERROR(Service_SSL, "Failed to duplicate socket with fd {}", in_fd);
return ResultInvalidSocket;
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result SetHostName(InBuffer<BufferAttr_HipcMapAlias> buf) {
auto const hostname = Common::StringFromBuffer(buf);
LOG_DEBUG(Service_SSL, "called. hostname={}", hostname);
ASSERT(!did_handshake);
return backend->SetHostName(hostname.c_str());
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result SetVerifyOption(u32 option) {
LOG_DEBUG(Service_SSL, "called. option={} (forcing 0)", option);
ASSERT(!did_handshake);
verify_option = 0;
backend->SetVerifyOption(0);
R_SUCCEED();
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result SetIoMode(u32 input_mode) {
auto mode = IoMode(input_mode);
ASSERT(mode == IoMode::Blocking || mode == IoMode::NonBlocking);
R_UNLESS(socket, ResultNoSocket);
const bool non_block = mode == IoMode::NonBlocking;
const Network::Errno error = socket->SetNonBlock(non_block);
if (error != Network::Errno::SUCCESS) {
LOG_ERROR(Service_SSL, "Failed to set native socket non-block flag to {}", non_block);
}
R_SUCCEED();
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result GetSocketDescriptor(Out<u32> out_fd) {
LOG_WARNING(Service_SSL, "(STUBBED)");
*out_fd = socket->GetFD();
R_SUCCEED();
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result GetHostName(OutBuffer<BufferAttr_HipcMapAlias> data, Out<u32> out_size) {
LOG_WARNING(Service_SSL, "(STUBBED)");
ASSERT(!did_handshake);
return backend->GetHostName(std::span<u8>{data.begin(), data.end()}, out_size);
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result GetIoMode(Out<u32> out_mode) {
LOG_WARNING(Service_SSL, "(STUBBED)");
R_SUCCEED();
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result DoHandshake() {
return DoHandshakeImpl();
2023-06-19 18:17:43 -07:00
}
void DoHandshakeGetServerCert(HLERequestContext& ctx) {
2023-07-01 15:02:25 -07:00
struct OutputParameters {
u32 certs_size;
u32 certs_count;
};
static_assert(sizeof(OutputParameters) == 0x8);
2023-07-16 18:55:27 -04:00
Result res = DoHandshakeImpl();
2023-07-01 15:02:25 -07:00
OutputParameters out{};
2023-06-19 18:17:43 -07:00
if (res == ResultSuccess) {
2023-07-16 18:55:27 -04:00
std::vector<std::vector<u8>> certs;
res = backend->GetServerCerts(&certs);
if (res == ResultSuccess) {
const std::vector<u8> certs_buf = SerializeServerCerts(certs);
if (ctx.CanWriteBuffer()) {
const size_t buffer_size = ctx.GetWriteBufferSize();
if (certs_buf.size() <= buffer_size) {
ctx.WriteBuffer(certs_buf);
} else {
LOG_WARNING(Service_SSL, "Certificate buffer too small: {} bytes needed, {} bytes available",
certs_buf.size(), buffer_size);
ctx.WriteBuffer(std::span<const u8>(certs_buf.data(), buffer_size));
}
} else {
LOG_DEBUG(Service_SSL, "No output buffer provided for certificates ({} bytes)", certs_buf.size());
}
2023-07-16 18:55:27 -04:00
out.certs_count = static_cast<u32>(certs.size());
2023-07-01 15:02:25 -07:00
out.certs_size = static_cast<u32>(certs_buf.size());
2023-06-19 18:17:43 -07:00
}
}
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(res);
2023-07-01 15:02:25 -07:00
rb.PushRaw(out);
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result Read(OutBuffer<BufferAttr_HipcMapAlias> data, Out<u32> out_size) {
R_UNLESS(did_handshake, ResultInternalError);
size_t tmp{};
auto const res = backend->Read(&tmp, data);
*out_size = u32(tmp);
return res;
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result Write(InBuffer<BufferAttr_HipcMapAlias> data, Out<u32> out_size) {
R_UNLESS(did_handshake, ResultInternalError);
size_t tmp{};
auto const res = backend->Write(&tmp, data);
*out_size = u32(tmp);
return res;
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result Pending(Out<s32> out_pending_size) {
LOG_WARNING(Service_SSL, "(STUBBED)");
*out_pending_size = s32(backend->Pending());
R_SUCCEED();
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result Peek(OutBuffer<BufferAttr_HipcMapAlias> data, Out<u32> out_size) {
LOG_WARNING(Service_SSL, "(STUBBED)");
size_t tmp{};
auto const res = backend->Peek(&tmp, data);
*out_size = u32(tmp);
return res;
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result Poll(u32 in_pollevent, u32 timer, Out<u32> out_pollevent) {
LOG_WARNING(Service_SSL, "(STUBBED)");
R_SUCCEED();
}
Result GetVerifyCertError() {
LOG_WARNING(Service_SSL, "(STUBBED)");
R_SUCCEED();
}
Result GetNeededServerCertBufferSize(Out<u32> out_needed_buffer_size) {
LOG_WARNING(Service_SSL, "(STUBBED)");
R_SUCCEED();
}
Result SetSessionCacheMode(u32 mode) {
LOG_WARNING(Service_SSL, "(STUBBED) called. value={}", mode);
R_UNLESS(!did_handshake, ResultInternalError);
R_SUCCEED();
}
2023-06-19 18:17:43 -07:00
2026-09-14 17:06:28 +00:00
Result GetSessionCacheMode(Out<u32> mode) {
LOG_WARNING(Service_SSL, "(STUBBED)");
R_UNLESS(!did_handshake, ResultInternalError);
R_SUCCEED();
}
Result FlushSessionCache() {
LOG_WARNING(Service_SSL, "(STUBBED)");
R_UNLESS(!did_handshake, ResultInternalError);
R_SUCCEED();
}
Result SetRenegotiationMode(RenegotiationMode mode) {
LOG_WARNING(Service_SSL, "(STUBBED)");
backend->SetRenegotiationMode(u32(mode));
R_SUCCEED();
}
2023-06-19 18:17:43 -07:00
2026-09-14 17:06:28 +00:00
Result GetRenegotiationMode(Out<RenegotiationMode> mode) {
LOG_WARNING(Service_SSL, "(STUBBED)");
u32 tmp{};
auto const res = backend->GetRenegotiationMode(&tmp);
*mode = RenegotiationMode(tmp);
return res;
}
Result SetOption(OptionType option, s32 value) {
switch (option) {
2023-06-19 18:17:43 -07:00
case OptionType::DoNotCloseSocket:
2026-09-14 17:06:28 +00:00
do_not_close_socket = bool(value);
2023-06-19 18:17:43 -07:00
break;
case OptionType::GetServerCertChain:
2026-09-14 17:06:28 +00:00
get_server_cert_chain = bool(value);
2023-06-19 18:17:43 -07:00
break;
case OptionType::SkipDefaultVerify:
2026-09-14 17:06:28 +00:00
skip_default_verify = bool(value);
break;
case OptionType::EnableAlpn:
2026-09-14 17:06:28 +00:00
enable_alpn = bool(value);
break;
2023-06-19 18:17:43 -07:00
default:
2026-09-14 17:06:28 +00:00
LOG_WARNING(Service_SSL, "Unknown option={}, value={}", option, value);
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
R_SUCCEED();
2023-06-19 18:17:43 -07:00
}
2026-09-14 17:06:28 +00:00
Result GetOption(OptionType option, Out<u8> value) {
switch (option) {
case OptionType::DoNotCloseSocket:
2026-09-14 17:06:28 +00:00
*value = u8(do_not_close_socket);
break;
case OptionType::GetServerCertChain:
2026-09-14 17:06:28 +00:00
*value = u8(get_server_cert_chain);
break;
case OptionType::SkipDefaultVerify:
2026-09-14 17:06:28 +00:00
*value = u8(skip_default_verify);
break;
case OptionType::EnableAlpn:
2026-09-14 17:06:28 +00:00
*value = u8(enable_alpn);
break;
default:
LOG_WARNING(Service_SSL, "Unknown option={}", option);
2026-09-14 17:06:28 +00:00
*value = 0;
break;
}
LOG_DEBUG(Service_SSL, "GetOption called, option={}, ret value={}", option, value);
2026-09-14 17:06:28 +00:00
R_SUCCEED();
}
2026-09-14 17:06:28 +00:00
Result SetNextAlpnProto(InBuffer<BufferAttr_HipcMapAlias> data) {
auto const to_write = u32((std::min)(next_alpn_proto.size(), data.size()));
next_alpn_proto.assign(data.begin(), data.begin() + to_write);
LOG_DEBUG(Service_SSL, "SetNextAlpnProto called, size={}", next_alpn_proto.size());
2026-09-14 17:06:28 +00:00
R_SUCCEED();
}
2026-09-14 17:06:28 +00:00
Result GetNextAlpnProto(OutBuffer<BufferAttr_HipcMapAlias> data, Out<u32> to_write) {
*to_write = u32((std::min)(next_alpn_proto.size(), data.size()));
next_alpn_proto.assign(data.begin(), data.begin() + *to_write);
LOG_DEBUG(Service_SSL, "GetNextAlpnProto called, size={}", to_write);
2026-09-14 17:06:28 +00:00
R_SUCCEED();
}
2026-09-14 17:06:28 +00:00
Result GetVerifyCertErrors(OutBuffer<BufferAttr_HipcMapAlias> unk0, Out<u32> unk1, Out<u32> unk2) {
LOG_WARNING(Service_SSL, "(STUBBED)");
R_SUCCEED();
}
2026-09-14 17:06:28 +00:00
SslVersion ssl_version;
std::shared_ptr<SslContextSharedData> shared_data;
std::unique_ptr<SSLConnectionBackend> backend;
std::optional<int> fd_to_close;
std::shared_ptr<Network::SocketBase> socket;
std::vector<u8> next_alpn_proto;
u32 verify_option = 0;
bool do_not_close_socket = false;
bool get_server_cert_chain = false;
bool skip_default_verify = false;
bool enable_alpn = false;
bool did_handshake = false;
};
class ISslContext final : public ServiceFramework<ISslContext> {
public:
explicit ISslContext(Core::System& system_, SslVersion version)
2023-06-19 18:17:43 -07:00
: ServiceFramework{system_, "ISslContext"}, ssl_version{version},
2023-07-01 15:02:25 -07:00
shared_data{std::make_shared<SslContextSharedData>()} {
static const FunctionInfo functions[] = {
{0, &ISslContext::SetOption, "SetOption"},
{1, &ISslContext::GetOption, "GetOption"},
{2, &ISslContext::CreateConnection, "CreateConnection"},
2023-06-19 18:17:43 -07:00
{3, &ISslContext::GetConnectionCount, "GetConnectionCount"},
2021-05-11 08:31:16 -04:00
{4, &ISslContext::ImportServerPki, "ImportServerPki"},
{5, &ISslContext::ImportClientPki, "ImportClientPki"},
{6, nullptr, "RemoveServerPki"},
{7, nullptr, "RemoveClientPki"},
{8, nullptr, "RegisterInternalPki"},
{9, nullptr, "AddPolicyOid"},
{10, nullptr, "ImportCrl"},
{11, nullptr, "RemoveCrl"},
{12, nullptr, "ImportClientCertKeyPki"},
{13, nullptr, "GeneratePrivateKeyAndCert"},
};
RegisterHandlers(functions);
}
private:
SslVersion ssl_version;
2023-07-01 15:02:25 -07:00
std::shared_ptr<SslContextSharedData> shared_data;
2023-02-19 14:42:12 -05:00
void SetOption(HLERequestContext& ctx) {
struct Parameters {
ContextOption option;
s32 value;
};
static_assert(sizeof(Parameters) == 0x8, "Parameters is an invalid size");
IPC::RequestParser rp{ctx};
const auto parameters = rp.PopRaw<Parameters>();
LOG_WARNING(Service_SSL, "(STUBBED) called. option={}, value={}", parameters.option,
parameters.value);
2018-09-19 15:09:59 +10:00
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
}
void GetOption(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto parameters = rp.PopRaw<OptionType>();
LOG_WARNING(Service_SSL, "(STUBBED) called. option={}", parameters);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
}
2023-02-19 14:42:12 -05:00
void CreateConnection(HLERequestContext& ctx) {
2023-06-19 18:17:43 -07:00
LOG_WARNING(Service_SSL, "called");
2023-07-16 18:55:27 -04:00
std::unique_ptr<SSLConnectionBackend> backend;
const Result res = CreateSSLConnectionBackend(&backend);
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
2023-07-16 18:55:27 -04:00
rb.Push(res);
if (res == ResultSuccess) {
rb.PushIpcInterface<ISslConnection>(ctx, system, ssl_version, shared_data, std::move(backend));
2023-06-19 18:17:43 -07:00
}
}
void GetConnectionCount(HLERequestContext& ctx) {
2023-07-01 15:02:25 -07:00
LOG_DEBUG(Service_SSL, "connection_count={}", shared_data->connection_count);
2023-06-19 18:17:43 -07:00
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(ResultSuccess);
2023-07-01 15:02:25 -07:00
rb.Push(shared_data->connection_count);
}
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>();
[[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};
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) {
[[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)) {
return ctx.ReadBuffer(1);
2021-05-11 08:31:16 -04: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};
rb.Push(ResultSuccess);
2021-05-11 08:31:16 -04:00
rb.Push(client_id);
}
};
class ISslService final : public ServiceFramework<ISslService> {
2018-09-02 11:36:43 -04:00
public:
2024-02-24 12:49:08 -05:00
explicit ISslService(Core::System& system_)
: ServiceFramework{system_, "ssl"}, cert_store{system} {
2018-09-02 11:36:43 -04:00
// clang-format off
static const FunctionInfo functions[] = {
{0, &ISslService::CreateContext, "CreateContext"},
2018-09-02 11:36:43 -04:00
{1, nullptr, "GetContextCount"},
2024-02-24 12:49:08 -05:00
{2, D<&ISslService::GetCertificates>, "GetCertificates"},
{3, D<&ISslService::GetCertificateBufSize>, "GetCertificateBufSize"},
2018-09-02 11:36:43 -04:00
{4, nullptr, "DebugIoctl"},
{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"},
{8, nullptr, "ClearTls12FallbackFlag"},
2018-09-02 11:36:43 -04:00
};
// clang-format on
2018-09-02 11:36:43 -04:00
RegisterHandlers(functions);
}
2018-09-02 11:36:43 -04:00
private:
2023-02-19 14:42:12 -05:00
void CreateContext(HLERequestContext& ctx) {
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 09:32:50 +03:00
2018-09-02 11:36:43 -04:00
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ISslContext>(ctx, system, parameters.ssl_version);
2018-09-02 11:36:43 -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};
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};
rb.Push(ResultSuccess);
2018-09-02 11:36:43 -04:00
}
2024-02-24 12:49:08 -05:00
Result GetCertificateBufSize(
Out<u32> out_size, InArray<CaCertificateId, BufferAttr_HipcMapAlias> certificate_ids) {
LOG_INFO(Service_SSL, "called");
u32 num_entries;
R_RETURN(cert_store.GetCertificateBufSize(out_size, &num_entries, certificate_ids));
}
Result GetCertificates(Out<u32> out_num_entries, OutBuffer<BufferAttr_HipcMapAlias> out_buffer,
InArray<CaCertificateId, BufferAttr_HipcMapAlias> certificate_ids) {
LOG_INFO(Service_SSL, "called");
R_RETURN(cert_store.GetCertificates(out_num_entries, out_buffer, certificate_ids));
}
private:
CertStore cert_store;
2018-09-02 11:36:43 -04:00
};
class ISslServiceForSystem final : public ServiceFramework<ISslServiceForSystem> {
public:
explicit ISslServiceForSystem(Core::System& system_) : ServiceFramework{system_, "ssl:s"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&ISslServiceForSystem::CreateContext>, "CreateContext"},
{1, D<&ISslServiceForSystem::GetContextCount>, "GetContextCount"},
{2, D<&ISslServiceForSystem::GetCertificates>, "GetCertificates"},
{3, D<&ISslServiceForSystem::GetCertificateBufSize>, "GetCertificateBufSize"},
{4, D<&ISslServiceForSystem::DebugIoctl>, "DebugIoctl"},
{5, D<&ISslServiceForSystem::SetInterfaceVersion>, "SetInterfaceVersion"},
{6, D<&ISslServiceForSystem::FlushSessionCache>, "FlushSessionCache"},
{7, D<&ISslServiceForSystem::SetDebugOption>, "SetDebugOption"},
{8, D<&ISslServiceForSystem::GetDebugOption>, "GetDebugOption"},
{9, D<&ISslServiceForSystem::ClearTls12FallbackFlag>, "ClearTls12FallbackFlag"},
{100, D<&ISslServiceForSystem::CreateContextForSystem>, "CreateContextForSystem"},
{101, D<&ISslServiceForSystem::SetThreadCoreMask>, "SetThreadCoreMask"},
{102, D<&ISslServiceForSystem::GetThreadCoreMask>, "GetThreadCoreMask"},
{103, D<&ISslServiceForSystem::VerifySignature>, "VerifySignature"}
};
// clang-format on
RegisterHandlers(functions);
};
Result CreateContext() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result GetContextCount() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result GetCertificates() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result GetCertificateBufSize() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result DebugIoctl() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result SetInterfaceVersion() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result FlushSessionCache() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result SetDebugOption() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result GetDebugOption() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result ClearTls12FallbackFlag() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result CreateContextForSystem() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result SetThreadCoreMask() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result GetThreadCoreMask() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
Result VerifySignature() {
LOG_DEBUG(Service_SSL, "(STUBBED) called.");
// TODO (jarrodnorwell)
return ResultSuccess;
};
};
2023-02-18 16:26:48 -05:00
void LoopProcess(Core::System& system) {
auto server_manager = std::make_unique<ServerManager>(system);
server_manager->RegisterNamedService("ssl", std::make_shared<ISslService>(system));
server_manager->RegisterNamedService("ssl:s", std::make_shared<ISslServiceForSystem>(system));
2023-02-18 16:26:48 -05:00
ServerManager::RunServer(std::move(server_manager));
2018-03-23 09:32:50 +03:00
}
} // namespace Service::SSL