ISslContext.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Services.Sockets.Bsd;
  3. using Ryujinx.HLE.HOS.Services.Ssl.Types;
  4. using System.Text;
  5. namespace Ryujinx.HLE.HOS.Services.Ssl.SslService
  6. {
  7. class ISslContext : IpcService
  8. {
  9. private uint _connectionCount;
  10. private readonly long _processId;
  11. private readonly SslVersion _sslVersion;
  12. private ulong _serverCertificateId;
  13. private ulong _clientCertificateId;
  14. public ISslContext(long processId, SslVersion sslVersion)
  15. {
  16. _processId = processId;
  17. _sslVersion = sslVersion;
  18. }
  19. [CommandHipc(2)]
  20. // CreateConnection() -> object<nn::ssl::sf::ISslConnection>
  21. public ResultCode CreateConnection(ServiceCtx context)
  22. {
  23. MakeObject(context, new ISslConnection(_processId, _sslVersion));
  24. _connectionCount++;
  25. return ResultCode.Success;
  26. }
  27. [CommandHipc(3)]
  28. // GetConnectionCount() -> u32 count
  29. public ResultCode GetConnectionCount(ServiceCtx context)
  30. {
  31. context.ResponseData.Write(_connectionCount);
  32. Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _connectionCount });
  33. return ResultCode.Success;
  34. }
  35. [CommandHipc(4)]
  36. // ImportServerPki(nn::ssl::sf::CertificateFormat certificateFormat, buffer<bytes, 5> certificate) -> u64 certificateId
  37. public ResultCode ImportServerPki(ServiceCtx context)
  38. {
  39. CertificateFormat certificateFormat = (CertificateFormat)context.RequestData.ReadUInt32();
  40. ulong certificateDataPosition = context.Request.SendBuff[0].Position;
  41. ulong certificateDataSize = context.Request.SendBuff[0].Size;
  42. context.ResponseData.Write(_serverCertificateId++);
  43. Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { certificateFormat });
  44. return ResultCode.Success;
  45. }
  46. [CommandHipc(5)]
  47. // ImportClientPki(buffer<bytes, 5> certificate, buffer<bytes, 5> ascii_password) -> u64 certificateId
  48. public ResultCode ImportClientPki(ServiceCtx context)
  49. {
  50. ulong certificateDataPosition = context.Request.SendBuff[0].Position;
  51. ulong certificateDataSize = context.Request.SendBuff[0].Size;
  52. ulong asciiPasswordDataPosition = context.Request.SendBuff[1].Position;
  53. ulong asciiPasswordDataSize = context.Request.SendBuff[1].Size;
  54. byte[] asciiPasswordData = new byte[asciiPasswordDataSize];
  55. context.Memory.Read(asciiPasswordDataPosition, asciiPasswordData);
  56. string asciiPassword = Encoding.ASCII.GetString(asciiPasswordData).Trim('\0');
  57. context.ResponseData.Write(_clientCertificateId++);
  58. Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { asciiPassword });
  59. return ResultCode.Success;
  60. }
  61. }
  62. }