2020-06-06 07:04:30 -04:00
|
|
|
using Ryujinx.Common.Logging;
|
2021-04-12 21:04:18 -04:00
|
|
|
using Ryujinx.HLE.HOS.Services.Ssl.Types;
|
|
|
|
using System.Text;
|
2020-06-06 07:04:30 -04:00
|
|
|
|
2019-09-18 20:45:11 -04:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Ssl.SslService
|
2018-10-06 18:16:42 -04:00
|
|
|
{
|
|
|
|
class ISslContext : IpcService
|
|
|
|
{
|
2021-04-14 08:47:19 -04:00
|
|
|
private uint _connectionCount;
|
|
|
|
|
2021-04-12 21:04:18 -04:00
|
|
|
private ulong _serverCertificateId;
|
|
|
|
private ulong _clientCertificateId;
|
|
|
|
|
2020-06-06 07:04:30 -04:00
|
|
|
public ISslContext(ServiceCtx context) { }
|
2021-04-12 21:04:18 -04:00
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(2)]
|
2021-04-12 21:04:18 -04:00
|
|
|
// CreateConnection() -> object<nn::ssl::sf::ISslConnection>
|
|
|
|
public ResultCode CreateConnection(ServiceCtx context)
|
|
|
|
{
|
|
|
|
MakeObject(context, new ISslConnection());
|
|
|
|
|
2021-04-14 08:47:19 -04:00
|
|
|
_connectionCount++;
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandHipc(3)]
|
|
|
|
// GetConnectionCount() -> u32 count
|
|
|
|
public ResultCode GetConnectionCount(ServiceCtx context)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(_connectionCount);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _connectionCount });
|
|
|
|
|
2021-04-12 21:04:18 -04:00
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(4)]
|
2020-06-06 07:04:30 -04:00
|
|
|
// ImportServerPki(nn::ssl::sf::CertificateFormat certificateFormat, buffer<bytes, 5> certificate) -> u64 certificateId
|
|
|
|
public ResultCode ImportServerPki(ServiceCtx context)
|
|
|
|
{
|
2021-04-12 21:04:18 -04:00
|
|
|
CertificateFormat certificateFormat = (CertificateFormat)context.RequestData.ReadUInt32();
|
2020-06-06 07:04:30 -04:00
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
ulong certificateDataPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong certificateDataSize = context.Request.SendBuff[0].Size;
|
2020-06-06 07:04:30 -04:00
|
|
|
|
2021-04-12 21:04:18 -04:00
|
|
|
context.ResponseData.Write(_serverCertificateId++);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { certificateFormat });
|
2020-06-06 07:04:30 -04:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(5)]
|
2021-04-12 21:04:18 -04:00
|
|
|
// ImportClientPki(buffer<bytes, 5> certificate, buffer<bytes, 5> ascii_password) -> u64 certificateId
|
|
|
|
public ResultCode ImportClientPki(ServiceCtx context)
|
|
|
|
{
|
2021-04-24 06:16:01 -04:00
|
|
|
ulong certificateDataPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong certificateDataSize = context.Request.SendBuff[0].Size;
|
2021-04-12 21:04:18 -04:00
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
ulong asciiPasswordDataPosition = context.Request.SendBuff[1].Position;
|
|
|
|
ulong asciiPasswordDataSize = context.Request.SendBuff[1].Size;
|
2021-04-12 21:04:18 -04:00
|
|
|
|
|
|
|
byte[] asciiPasswordData = new byte[asciiPasswordDataSize];
|
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
context.Memory.Read(asciiPasswordDataPosition, asciiPasswordData);
|
2021-04-12 21:04:18 -04:00
|
|
|
|
|
|
|
string asciiPassword = Encoding.ASCII.GetString(asciiPasswordData).Trim('\0');
|
|
|
|
|
|
|
|
context.ResponseData.Write(_clientCertificateId++);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { asciiPassword });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
2018-10-06 18:16:42 -04:00
|
|
|
}
|
2021-04-12 21:04:18 -04:00
|
|
|
}
|