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