ssl.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "core/hle/ipc_helpers.h"
  5. #include "core/hle/kernel/hle_ipc.h"
  6. #include "core/hle/service/service.h"
  7. #include "core/hle/service/sm/sm.h"
  8. #include "core/hle/service/ssl/ssl.h"
  9. namespace Service::SSL {
  10. enum class CertificateFormat : u32 {
  11. Pem = 1,
  12. Der = 2,
  13. };
  14. class ISslConnection final : public ServiceFramework<ISslConnection> {
  15. public:
  16. explicit ISslConnection(Core::System& system_) : ServiceFramework{system_, "ISslConnection"} {
  17. // clang-format off
  18. static const FunctionInfo functions[] = {
  19. {0, nullptr, "SetSocketDescriptor"},
  20. {1, nullptr, "SetHostName"},
  21. {2, nullptr, "SetVerifyOption"},
  22. {3, nullptr, "SetIoMode"},
  23. {4, nullptr, "GetSocketDescriptor"},
  24. {5, nullptr, "GetHostName"},
  25. {6, nullptr, "GetVerifyOption"},
  26. {7, nullptr, "GetIoMode"},
  27. {8, nullptr, "DoHandshake"},
  28. {9, nullptr, "DoHandshakeGetServerCert"},
  29. {10, nullptr, "Read"},
  30. {11, nullptr, "Write"},
  31. {12, nullptr, "Pending"},
  32. {13, nullptr, "Peek"},
  33. {14, nullptr, "Poll"},
  34. {15, nullptr, "GetVerifyCertError"},
  35. {16, nullptr, "GetNeededServerCertBufferSize"},
  36. {17, nullptr, "SetSessionCacheMode"},
  37. {18, nullptr, "GetSessionCacheMode"},
  38. {19, nullptr, "FlushSessionCache"},
  39. {20, nullptr, "SetRenegotiationMode"},
  40. {21, nullptr, "GetRenegotiationMode"},
  41. {22, nullptr, "SetOption"},
  42. {23, nullptr, "GetOption"},
  43. {24, nullptr, "GetVerifyCertErrors"},
  44. {25, nullptr, "GetCipherInfo"},
  45. {26, nullptr, "SetNextAlpnProto"},
  46. {27, nullptr, "GetNextAlpnProto"},
  47. };
  48. // clang-format on
  49. RegisterHandlers(functions);
  50. }
  51. };
  52. class ISslContext final : public ServiceFramework<ISslContext> {
  53. public:
  54. explicit ISslContext(Core::System& system_) : ServiceFramework{system_, "ISslContext"} {
  55. static const FunctionInfo functions[] = {
  56. {0, &ISslContext::SetOption, "SetOption"},
  57. {1, nullptr, "GetOption"},
  58. {2, &ISslContext::CreateConnection, "CreateConnection"},
  59. {3, nullptr, "GetConnectionCount"},
  60. {4, &ISslContext::ImportServerPki, "ImportServerPki"},
  61. {5, &ISslContext::ImportClientPki, "ImportClientPki"},
  62. {6, nullptr, "RemoveServerPki"},
  63. {7, nullptr, "RemoveClientPki"},
  64. {8, nullptr, "RegisterInternalPki"},
  65. {9, nullptr, "AddPolicyOid"},
  66. {10, nullptr, "ImportCrl"},
  67. {11, nullptr, "RemoveCrl"},
  68. };
  69. RegisterHandlers(functions);
  70. }
  71. private:
  72. void SetOption(Kernel::HLERequestContext& ctx) {
  73. struct Parameters {
  74. u8 enable;
  75. u32 option;
  76. };
  77. IPC::RequestParser rp{ctx};
  78. const auto parameters = rp.PopRaw<Parameters>();
  79. LOG_WARNING(Service_SSL, "(STUBBED) called. enable={}, option={}", parameters.enable,
  80. parameters.option);
  81. IPC::ResponseBuilder rb{ctx, 2};
  82. rb.Push(RESULT_SUCCESS);
  83. }
  84. void CreateConnection(Kernel::HLERequestContext& ctx) {
  85. LOG_WARNING(Service_SSL, "(STUBBED) called");
  86. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  87. rb.Push(RESULT_SUCCESS);
  88. rb.PushIpcInterface<ISslConnection>(system);
  89. }
  90. void ImportServerPki(Kernel::HLERequestContext& ctx) {
  91. IPC::RequestParser rp{ctx};
  92. const auto certificate_format = rp.PopEnum<CertificateFormat>();
  93. const auto pkcs_12_certificates = ctx.ReadBuffer(0);
  94. constexpr u64 server_id = 0;
  95. LOG_WARNING(Service_SSL, "(STUBBED) called, certificate_format={}", certificate_format);
  96. IPC::ResponseBuilder rb{ctx, 4};
  97. rb.Push(RESULT_SUCCESS);
  98. rb.Push(server_id);
  99. }
  100. void ImportClientPki(Kernel::HLERequestContext& ctx) {
  101. const auto pkcs_12_certificate = ctx.ReadBuffer(0);
  102. const auto ascii_password = [&ctx] {
  103. if (ctx.CanReadBuffer(1)) {
  104. return ctx.ReadBuffer(1);
  105. }
  106. return std::vector<u8>{};
  107. }();
  108. constexpr u64 client_id = 0;
  109. LOG_WARNING(Service_SSL, "(STUBBED) called");
  110. IPC::ResponseBuilder rb{ctx, 4};
  111. rb.Push(RESULT_SUCCESS);
  112. rb.Push(client_id);
  113. }
  114. };
  115. class SSL final : public ServiceFramework<SSL> {
  116. public:
  117. explicit SSL(Core::System& system_) : ServiceFramework{system_, "ssl"} {
  118. // clang-format off
  119. static const FunctionInfo functions[] = {
  120. {0, &SSL::CreateContext, "CreateContext"},
  121. {1, nullptr, "GetContextCount"},
  122. {2, nullptr, "GetCertificates"},
  123. {3, nullptr, "GetCertificateBufSize"},
  124. {4, nullptr, "DebugIoctl"},
  125. {5, &SSL::SetInterfaceVersion, "SetInterfaceVersion"},
  126. {6, nullptr, "FlushSessionCache"},
  127. {7, nullptr, "SetDebugOption"},
  128. {8, nullptr, "GetDebugOption"},
  129. };
  130. // clang-format on
  131. RegisterHandlers(functions);
  132. }
  133. private:
  134. u32 ssl_version{};
  135. void CreateContext(Kernel::HLERequestContext& ctx) {
  136. LOG_WARNING(Service_SSL, "(STUBBED) called");
  137. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  138. rb.Push(RESULT_SUCCESS);
  139. rb.PushIpcInterface<ISslContext>(system);
  140. }
  141. void SetInterfaceVersion(Kernel::HLERequestContext& ctx) {
  142. LOG_DEBUG(Service_SSL, "called");
  143. IPC::RequestParser rp{ctx};
  144. ssl_version = rp.Pop<u32>();
  145. IPC::ResponseBuilder rb{ctx, 2};
  146. rb.Push(RESULT_SUCCESS);
  147. }
  148. };
  149. void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
  150. std::make_shared<SSL>(system)->InstallAsService(service_manager);
  151. }
  152. } // namespace Service::SSL