ISslContext.cs 2.8 KB

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