2020-06-06 11:04:30 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2022-01-13 22:29:04 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Sockets.Bsd;
|
2021-04-13 01:04:18 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Ssl.Types;
|
|
|
|
using System.Text;
|
2020-06-06 11:04:30 +00:00
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Ssl.SslService
|
2018-10-06 22:16:42 +00:00
|
|
|
{
|
|
|
|
class ISslContext : IpcService
|
|
|
|
{
|
2021-04-14 12:47:19 +00:00
|
|
|
private uint _connectionCount;
|
|
|
|
|
2022-01-13 22:29:04 +00:00
|
|
|
private readonly long _processId;
|
|
|
|
private readonly SslVersion _sslVersion;
|
2021-04-13 01:04:18 +00:00
|
|
|
private ulong _serverCertificateId;
|
|
|
|
private ulong _clientCertificateId;
|
|
|
|
|
2022-01-13 22:29:04 +00:00
|
|
|
public ISslContext(long processId, SslVersion sslVersion)
|
|
|
|
{
|
|
|
|
_processId = processId;
|
|
|
|
_sslVersion = sslVersion;
|
|
|
|
}
|
2021-04-13 01:04:18 +00:00
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(2)]
|
2021-04-13 01:04:18 +00:00
|
|
|
// CreateConnection() -> object<nn::ssl::sf::ISslConnection>
|
|
|
|
public ResultCode CreateConnection(ServiceCtx context)
|
|
|
|
{
|
2022-01-13 22:29:04 +00:00
|
|
|
MakeObject(context, new ISslConnection(_processId, _sslVersion));
|
2021-04-13 01:04:18 +00:00
|
|
|
|
2021-04-14 12:47:19 +00: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-13 01:04:18 +00:00
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(4)]
|
2020-06-06 11:04:30 +00:00
|
|
|
// ImportServerPki(nn::ssl::sf::CertificateFormat certificateFormat, buffer<bytes, 5> certificate) -> u64 certificateId
|
|
|
|
public ResultCode ImportServerPki(ServiceCtx context)
|
|
|
|
{
|
2021-04-13 01:04:18 +00:00
|
|
|
CertificateFormat certificateFormat = (CertificateFormat)context.RequestData.ReadUInt32();
|
2020-06-06 11:04:30 +00:00
|
|
|
|
2021-04-24 10:16:01 +00:00
|
|
|
ulong certificateDataPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong certificateDataSize = context.Request.SendBuff[0].Size;
|
2020-06-06 11:04:30 +00:00
|
|
|
|
2021-04-13 01:04:18 +00:00
|
|
|
context.ResponseData.Write(_serverCertificateId++);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { certificateFormat });
|
2020-06-06 11:04:30 +00:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(5)]
|
2021-04-13 01:04:18 +00:00
|
|
|
// ImportClientPki(buffer<bytes, 5> certificate, buffer<bytes, 5> ascii_password) -> u64 certificateId
|
|
|
|
public ResultCode ImportClientPki(ServiceCtx context)
|
|
|
|
{
|
2021-04-24 10:16:01 +00:00
|
|
|
ulong certificateDataPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong certificateDataSize = context.Request.SendBuff[0].Size;
|
2021-04-13 01:04:18 +00:00
|
|
|
|
2021-04-24 10:16:01 +00:00
|
|
|
ulong asciiPasswordDataPosition = context.Request.SendBuff[1].Position;
|
|
|
|
ulong asciiPasswordDataSize = context.Request.SendBuff[1].Size;
|
2021-04-13 01:04:18 +00:00
|
|
|
|
|
|
|
byte[] asciiPasswordData = new byte[asciiPasswordDataSize];
|
|
|
|
|
2021-04-24 10:16:01 +00:00
|
|
|
context.Memory.Read(asciiPasswordDataPosition, asciiPasswordData);
|
2021-04-13 01:04:18 +00: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 22:16:42 +00:00
|
|
|
}
|
2021-04-13 01:04:18 +00:00
|
|
|
}
|