ISslContext.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 ulong _serverCertificateId;
  10. private ulong _clientCertificateId;
  11. public ISslContext(ServiceCtx context) { }
  12. [CommandHipc(2)]
  13. // CreateConnection() -> object<nn::ssl::sf::ISslConnection>
  14. public ResultCode CreateConnection(ServiceCtx context)
  15. {
  16. MakeObject(context, new ISslConnection());
  17. _connectionCount++;
  18. return ResultCode.Success;
  19. }
  20. [CommandHipc(3)]
  21. // GetConnectionCount() -> u32 count
  22. public ResultCode GetConnectionCount(ServiceCtx context)
  23. {
  24. context.ResponseData.Write(_connectionCount);
  25. Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _connectionCount });
  26. return ResultCode.Success;
  27. }
  28. [CommandHipc(4)]
  29. // ImportServerPki(nn::ssl::sf::CertificateFormat certificateFormat, buffer<bytes, 5> certificate) -> u64 certificateId
  30. public ResultCode ImportServerPki(ServiceCtx context)
  31. {
  32. CertificateFormat certificateFormat = (CertificateFormat)context.RequestData.ReadUInt32();
  33. ulong certificateDataPosition = context.Request.SendBuff[0].Position;
  34. ulong certificateDataSize = context.Request.SendBuff[0].Size;
  35. context.ResponseData.Write(_serverCertificateId++);
  36. Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { certificateFormat });
  37. return ResultCode.Success;
  38. }
  39. [CommandHipc(5)]
  40. // ImportClientPki(buffer<bytes, 5> certificate, buffer<bytes, 5> ascii_password) -> u64 certificateId
  41. public ResultCode ImportClientPki(ServiceCtx context)
  42. {
  43. ulong certificateDataPosition = context.Request.SendBuff[0].Position;
  44. ulong certificateDataSize = context.Request.SendBuff[0].Size;
  45. ulong asciiPasswordDataPosition = context.Request.SendBuff[1].Position;
  46. ulong asciiPasswordDataSize = context.Request.SendBuff[1].Size;
  47. byte[] asciiPasswordData = new byte[asciiPasswordDataSize];
  48. context.Memory.Read(asciiPasswordDataPosition, asciiPasswordData);
  49. string asciiPassword = Encoding.ASCII.GetString(asciiPasswordData).Trim('\0');
  50. context.ResponseData.Write(_clientCertificateId++);
  51. Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { asciiPassword });
  52. return ResultCode.Success;
  53. }
  54. }
  55. }