Ryujinx/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs
Mary 3fa7ef21b4
ssl: Implement SSL connectivity (#2961)
* implement certain servicessl functions

* ssl: Implement more of SSL connection and abstract it

This adds support to non blocking SSL operations and unlink the SSL
implementation from the IPC logic.

* Rename SslDefaultSocketConnection to SslManagedSocketConnection

* Fix regression on Pokemon TV

* Address gdkchan's comment

* Simplify value read from previous commit

* ssl: some changes

- Implement builtin certificates parsing and retrieving
- Fix issues with SSL version handling
- Improve managed SSL socket error handling
- Ensure to only return a certificate on DoHandshake when actually requested

* Add missing BuiltInCertificateManager initialization call

* Address gdkchan's comment

* Address Ack's comment

Co-authored-by: InvoxiPlayGames <webmaster@invoxiplaygames.uk>
2022-01-13 23:29:04 +01:00

84 lines
2.9 KiB
C#

using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd;
using Ryujinx.HLE.HOS.Services.Ssl.Types;
using System.Text;
namespace Ryujinx.HLE.HOS.Services.Ssl.SslService
{
class ISslContext : IpcService
{
private uint _connectionCount;
private readonly long _processId;
private readonly SslVersion _sslVersion;
private ulong _serverCertificateId;
private ulong _clientCertificateId;
public ISslContext(long processId, SslVersion sslVersion)
{
_processId = processId;
_sslVersion = sslVersion;
}
[CommandHipc(2)]
// CreateConnection() -> object<nn::ssl::sf::ISslConnection>
public ResultCode CreateConnection(ServiceCtx context)
{
MakeObject(context, new ISslConnection(_processId, _sslVersion));
_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 });
return ResultCode.Success;
}
[CommandHipc(4)]
// ImportServerPki(nn::ssl::sf::CertificateFormat certificateFormat, buffer<bytes, 5> certificate) -> u64 certificateId
public ResultCode ImportServerPki(ServiceCtx context)
{
CertificateFormat certificateFormat = (CertificateFormat)context.RequestData.ReadUInt32();
ulong certificateDataPosition = context.Request.SendBuff[0].Position;
ulong certificateDataSize = context.Request.SendBuff[0].Size;
context.ResponseData.Write(_serverCertificateId++);
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { certificateFormat });
return ResultCode.Success;
}
[CommandHipc(5)]
// ImportClientPki(buffer<bytes, 5> certificate, buffer<bytes, 5> ascii_password) -> u64 certificateId
public ResultCode ImportClientPki(ServiceCtx context)
{
ulong certificateDataPosition = context.Request.SendBuff[0].Position;
ulong certificateDataSize = context.Request.SendBuff[0].Size;
ulong asciiPasswordDataPosition = context.Request.SendBuff[1].Position;
ulong asciiPasswordDataSize = context.Request.SendBuff[1].Size;
byte[] asciiPasswordData = new byte[asciiPasswordDataSize];
context.Memory.Read(asciiPasswordDataPosition, asciiPasswordData);
string asciiPassword = Encoding.ASCII.GetString(asciiPasswordData).Trim('\0');
context.ResponseData.Write(_clientCertificateId++);
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { asciiPassword });
return ResultCode.Success;
}
}
}