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