ssl.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. class ISslConnection final : public ServiceFramework<ISslConnection> {
  11. public:
  12. ISslConnection() : ServiceFramework("ISslConnection") {
  13. static const FunctionInfo functions[] = {
  14. {0, nullptr, "SetSocketDescriptor"},
  15. {1, nullptr, "SetHostName"},
  16. {2, nullptr, "SetVerifyOption"},
  17. {3, nullptr, "SetIoMode"},
  18. {4, nullptr, "GetSocketDescriptor"},
  19. {5, nullptr, "GetHostName"},
  20. {6, nullptr, "GetVerifyOption"},
  21. {7, nullptr, "GetIoMode"},
  22. {8, nullptr, "DoHandshake"},
  23. {9, nullptr, "DoHandshakeGetServerCert"},
  24. {10, nullptr, "Read"},
  25. {11, nullptr, "Write"},
  26. {12, nullptr, "Pending"},
  27. {13, nullptr, "Peek"},
  28. {14, nullptr, "Poll"},
  29. {15, nullptr, "GetVerifyCertError"},
  30. {16, nullptr, "GetNeededServerCertBufferSize"},
  31. {17, nullptr, "SetSessionCacheMode"},
  32. {18, nullptr, "GetSessionCacheMode"},
  33. {19, nullptr, "FlushSessionCache"},
  34. {20, nullptr, "SetRenegotiationMode"},
  35. {21, nullptr, "GetRenegotiationMode"},
  36. {22, nullptr, "SetOption"},
  37. {23, nullptr, "GetOption"},
  38. {24, nullptr, "GetVerifyCertErrors"},
  39. {25, nullptr, "GetCipherInfo"},
  40. };
  41. RegisterHandlers(functions);
  42. }
  43. };
  44. class ISslContext final : public ServiceFramework<ISslContext> {
  45. public:
  46. ISslContext() : ServiceFramework("ISslContext") {
  47. static const FunctionInfo functions[] = {
  48. {0, &ISslContext::SetOption, "SetOption"},
  49. {1, nullptr, "GetOption"},
  50. {2, &ISslContext::CreateConnection, "CreateConnection"},
  51. {3, nullptr, "GetConnectionCount"},
  52. {4, nullptr, "ImportServerPki"},
  53. {5, nullptr, "ImportClientPki"},
  54. {6, nullptr, "RemoveServerPki"},
  55. {7, nullptr, "RemoveClientPki"},
  56. {8, nullptr, "RegisterInternalPki"},
  57. {9, nullptr, "AddPolicyOid"},
  58. {10, nullptr, "ImportCrl"},
  59. {11, nullptr, "RemoveCrl"},
  60. };
  61. RegisterHandlers(functions);
  62. }
  63. private:
  64. void SetOption(Kernel::HLERequestContext& ctx) {
  65. struct Parameters {
  66. u8 enable;
  67. u32 option;
  68. };
  69. IPC::RequestParser rp{ctx};
  70. const auto parameters = rp.PopRaw<Parameters>();
  71. LOG_WARNING(Service_SSL, "(STUBBED) called. enable={}, option={}", parameters.enable,
  72. parameters.option);
  73. IPC::ResponseBuilder rb{ctx, 2};
  74. rb.Push(RESULT_SUCCESS);
  75. }
  76. void CreateConnection(Kernel::HLERequestContext& ctx) {
  77. LOG_WARNING(Service_SSL, "(STUBBED) called");
  78. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  79. rb.Push(RESULT_SUCCESS);
  80. rb.PushIpcInterface<ISslConnection>();
  81. }
  82. };
  83. class SSL final : public ServiceFramework<SSL> {
  84. public:
  85. explicit SSL() : ServiceFramework{"ssl"} {
  86. // clang-format off
  87. static const FunctionInfo functions[] = {
  88. {0, &SSL::CreateContext, "CreateContext"},
  89. {1, nullptr, "GetContextCount"},
  90. {2, nullptr, "GetCertificates"},
  91. {3, nullptr, "GetCertificateBufSize"},
  92. {4, nullptr, "DebugIoctl"},
  93. {5, &SSL::SetInterfaceVersion, "SetInterfaceVersion"},
  94. {6, nullptr, "FlushSessionCache"},
  95. };
  96. // clang-format on
  97. RegisterHandlers(functions);
  98. }
  99. private:
  100. u32 ssl_version{};
  101. void CreateContext(Kernel::HLERequestContext& ctx) {
  102. LOG_WARNING(Service_SSL, "(STUBBED) called");
  103. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  104. rb.Push(RESULT_SUCCESS);
  105. rb.PushIpcInterface<ISslContext>();
  106. }
  107. void SetInterfaceVersion(Kernel::HLERequestContext& ctx) {
  108. LOG_DEBUG(Service_SSL, "called");
  109. IPC::RequestParser rp{ctx};
  110. ssl_version = rp.Pop<u32>();
  111. IPC::ResponseBuilder rb{ctx, 2};
  112. rb.Push(RESULT_SUCCESS);
  113. }
  114. };
  115. void InstallInterfaces(SM::ServiceManager& service_manager) {
  116. std::make_shared<SSL>()->InstallAsService(service_manager);
  117. }
  118. } // namespace Service::SSL