2021-04-13 03:04:18 +02:00
|
|
|
using Ryujinx.Common.Logging;
|
2022-01-13 23:29:04 +01:00
|
|
|
using Ryujinx.HLE.Exceptions;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Sockets.Bsd;
|
2021-04-13 03:04:18 +02:00
|
|
|
using Ryujinx.HLE.HOS.Services.Ssl.Types;
|
2022-01-13 23:29:04 +01:00
|
|
|
using Ryujinx.Memory;
|
|
|
|
using System;
|
2021-04-13 03:04:18 +02:00
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Ssl.SslService
|
|
|
|
{
|
2022-01-13 23:29:04 +01:00
|
|
|
class ISslConnection : IpcService, IDisposable
|
2021-04-13 03:04:18 +02:00
|
|
|
{
|
2022-01-13 23:29:04 +01:00
|
|
|
private bool _doNotClockSocket;
|
|
|
|
private bool _getServerCertChain;
|
|
|
|
private bool _skipDefaultVerify;
|
|
|
|
private bool _enableAlpn;
|
|
|
|
|
|
|
|
private SslVersion _sslVersion;
|
|
|
|
private IoMode _ioMode;
|
|
|
|
private VerifyOption _verifyOption;
|
|
|
|
private SessionCacheMode _sessionCacheMode;
|
|
|
|
private string _hostName;
|
|
|
|
|
|
|
|
private ISslConnectionBase _connection;
|
|
|
|
private BsdContext _bsdContext;
|
2022-02-09 21:18:07 +01:00
|
|
|
private readonly ulong _processId;
|
2022-01-13 23:29:04 +01:00
|
|
|
|
|
|
|
private byte[] _nextAplnProto;
|
|
|
|
|
2022-02-09 21:18:07 +01:00
|
|
|
public ISslConnection(ulong processId, SslVersion sslVersion)
|
2022-01-13 23:29:04 +01:00
|
|
|
{
|
|
|
|
_processId = processId;
|
|
|
|
_sslVersion = sslVersion;
|
|
|
|
_ioMode = IoMode.Blocking;
|
|
|
|
_sessionCacheMode = SessionCacheMode.None;
|
|
|
|
_verifyOption = VerifyOption.PeerCa | VerifyOption.HostName;
|
|
|
|
}
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(0)]
|
2021-04-13 03:04:18 +02:00
|
|
|
// SetSocketDescriptor(u32) -> u32
|
|
|
|
public ResultCode SetSocketDescriptor(ServiceCtx context)
|
|
|
|
{
|
2022-01-13 23:29:04 +01:00
|
|
|
if (_connection != null)
|
|
|
|
{
|
|
|
|
return ResultCode.AlreadyInUse;
|
|
|
|
}
|
|
|
|
|
|
|
|
_bsdContext = BsdContext.GetContext(_processId);
|
|
|
|
|
|
|
|
if (_bsdContext == null)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
int inputFd = context.RequestData.ReadInt32();
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
int internalFd = _bsdContext.DuplicateFileDescriptor(inputFd);
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
if (internalFd == -1)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeConnection(internalFd);
|
|
|
|
|
|
|
|
int outputFd = inputFd;
|
|
|
|
|
|
|
|
if (_doNotClockSocket)
|
|
|
|
{
|
|
|
|
outputFd = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.ResponseData.Write(outputFd);
|
2021-04-13 03:04:18 +02:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
private void InitializeConnection(int socketFd)
|
|
|
|
{
|
|
|
|
ISocket bsdSocket = _bsdContext.RetrieveSocket(socketFd);
|
|
|
|
|
|
|
|
_connection = new SslManagedSocketConnection(_bsdContext, _sslVersion, socketFd, bsdSocket);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(1)]
|
2021-04-13 03:04:18 +02:00
|
|
|
// SetHostName(buffer<bytes, 5>)
|
|
|
|
public ResultCode SetHostName(ServiceCtx context)
|
|
|
|
{
|
2021-04-24 12:16:01 +02:00
|
|
|
ulong hostNameDataPosition = context.Request.SendBuff[0].Position;
|
2022-01-13 23:29:04 +01:00
|
|
|
ulong hostNameDataSize = context.Request.SendBuff[0].Size;
|
2021-04-13 03:04:18 +02:00
|
|
|
|
|
|
|
byte[] hostNameData = new byte[hostNameDataSize];
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
context.Memory.Read(hostNameDataPosition, hostNameData);
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
_hostName = Encoding.ASCII.GetString(hostNameData).Trim('\0');
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
Logger.Info?.Print(LogClass.ServiceSsl, _hostName);
|
2021-04-13 03:04:18 +02:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(2)]
|
2021-04-13 03:04:18 +02:00
|
|
|
// SetVerifyOption(nn::ssl::sf::VerifyOption)
|
|
|
|
public ResultCode SetVerifyOption(ServiceCtx context)
|
|
|
|
{
|
2022-01-13 23:29:04 +01:00
|
|
|
_verifyOption = (VerifyOption)context.RequestData.ReadUInt32();
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _verifyOption });
|
2021-04-13 03:04:18 +02:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(3)]
|
2021-04-13 03:04:18 +02:00
|
|
|
// SetIoMode(nn::ssl::sf::IoMode)
|
|
|
|
public ResultCode SetIoMode(ServiceCtx context)
|
|
|
|
{
|
2022-01-13 23:29:04 +01:00
|
|
|
if (_connection == null)
|
|
|
|
{
|
|
|
|
return ResultCode.NoSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ioMode = (IoMode)context.RequestData.ReadUInt32();
|
|
|
|
|
|
|
|
_connection.Socket.Blocking = _ioMode == IoMode.Blocking;
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _ioMode });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(4)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetSocketDescriptor() -> u32
|
|
|
|
public ResultCode GetSocketDescriptor(ServiceCtx context)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(_connection.SocketFd);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(5)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetHostName(buffer<bytes, 6>) -> u32
|
|
|
|
public ResultCode GetHostName(ServiceCtx context)
|
|
|
|
{
|
2022-10-05 01:12:54 +02:00
|
|
|
ulong bufferAddress = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong bufferLen = context.Request.ReceiveBuff[0].Size;
|
2022-01-13 23:29:04 +01:00
|
|
|
|
2022-10-05 01:12:54 +02:00
|
|
|
using (var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true))
|
|
|
|
{
|
|
|
|
Encoding.ASCII.GetBytes(_hostName, region.Memory.Span);
|
|
|
|
}
|
2022-01-13 23:29:04 +01:00
|
|
|
|
|
|
|
context.ResponseData.Write((uint)_hostName.Length);
|
|
|
|
|
|
|
|
Logger.Info?.Print(LogClass.ServiceSsl, _hostName);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(6)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetVerifyOption() -> nn::ssl::sf::VerifyOption
|
|
|
|
public ResultCode GetVerifyOption(ServiceCtx context)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write((uint)_verifyOption);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _verifyOption });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(7)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetIoMode() -> nn::ssl::sf::IoMode
|
|
|
|
public ResultCode GetIoMode(ServiceCtx context)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write((uint)_ioMode);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _ioMode });
|
2021-04-13 03:04:18 +02:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(8)]
|
2021-04-13 03:04:18 +02:00
|
|
|
// DoHandshake()
|
|
|
|
public ResultCode DoHandshake(ServiceCtx context)
|
|
|
|
{
|
2022-01-13 23:29:04 +01:00
|
|
|
if (_connection == null)
|
|
|
|
{
|
|
|
|
return ResultCode.NoSocket;
|
|
|
|
}
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
return _connection.Handshake(_hostName);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(9)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// DoHandshakeGetServerCert() -> (u32, u32, buffer<bytes, 6>)
|
|
|
|
public ResultCode DoHandshakeGetServerCert(ServiceCtx context)
|
|
|
|
{
|
|
|
|
if (_connection == null)
|
|
|
|
{
|
|
|
|
return ResultCode.NoSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode result = _connection.Handshake(_hostName);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
if (_getServerCertChain)
|
|
|
|
{
|
|
|
|
using (WritableRegion region = context.Memory.GetWritableRegion(context.Request.ReceiveBuff[0].Position, (int)context.Request.ReceiveBuff[0].Size))
|
|
|
|
{
|
|
|
|
result = _connection.GetServerCertificate(_hostName, region.Memory.Span, out uint bufferSize, out uint certificateCount);
|
|
|
|
|
|
|
|
context.ResponseData.Write(bufferSize);
|
|
|
|
context.ResponseData.Write(certificateCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(0);
|
|
|
|
context.ResponseData.Write(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(10)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// Read() -> (u32, buffer<bytes, 6>)
|
|
|
|
public ResultCode Read(ServiceCtx context)
|
|
|
|
{
|
|
|
|
if (_connection == null)
|
|
|
|
{
|
|
|
|
return ResultCode.NoSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode result;
|
|
|
|
|
|
|
|
using (WritableRegion region = context.Memory.GetWritableRegion(context.Request.ReceiveBuff[0].Position, (int)context.Request.ReceiveBuff[0].Size))
|
|
|
|
{
|
|
|
|
// TODO: Better error management.
|
|
|
|
result = _connection.Read(out int readCount, region.Memory);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(readCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2021-04-13 03:04:18 +02:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(11)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// Write(buffer<bytes, 5>) -> s32
|
2021-04-13 03:04:18 +02:00
|
|
|
public ResultCode Write(ServiceCtx context)
|
|
|
|
{
|
2022-01-13 23:29:04 +01:00
|
|
|
if (_connection == null)
|
|
|
|
{
|
|
|
|
return ResultCode.NoSocket;
|
|
|
|
}
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
// We don't dispose as this isn't supposed to be modified
|
|
|
|
WritableRegion region = context.Memory.GetWritableRegion(context.Request.SendBuff[0].Position, (int)context.Request.SendBuff[0].Size);
|
2021-04-14 14:47:19 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
// TODO: Better error management.
|
|
|
|
ResultCode result = _connection.Write(out int writtenCount, region.Memory);
|
2021-04-14 14:47:19 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(writtenCount);
|
|
|
|
}
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(12)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// Pending() -> s32
|
|
|
|
public ResultCode Pending(ServiceCtx context)
|
|
|
|
{
|
|
|
|
if (_connection == null)
|
|
|
|
{
|
|
|
|
return ResultCode.NoSocket;
|
|
|
|
}
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
context.ResponseData.Write(_connection.Pending());
|
2021-04-13 03:04:18 +02:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(13)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// Peek() -> (s32, buffer<bytes, 6>)
|
|
|
|
public ResultCode Peek(ServiceCtx context)
|
|
|
|
{
|
|
|
|
if (_connection == null)
|
|
|
|
{
|
|
|
|
return ResultCode.NoSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode result;
|
|
|
|
|
|
|
|
using (WritableRegion region = context.Memory.GetWritableRegion(context.Request.ReceiveBuff[0].Position, (int)context.Request.ReceiveBuff[0].Size))
|
|
|
|
{
|
|
|
|
// TODO: Better error management.
|
|
|
|
result = _connection.Peek(out int peekCount, region.Memory);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(peekCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(14)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// Poll(nn::ssl::sf::PollEvent poll_event, u32 timeout) -> nn::ssl::sf::PollEvent
|
|
|
|
public ResultCode Poll(ServiceCtx context)
|
|
|
|
{
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(15)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetVerifyCertError()
|
|
|
|
public ResultCode GetVerifyCertError(ServiceCtx context)
|
|
|
|
{
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(16)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetNeededServerCertBufferSize() -> u32
|
|
|
|
public ResultCode GetNeededServerCertBufferSize(ServiceCtx context)
|
|
|
|
{
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(17)]
|
2021-04-13 03:04:18 +02:00
|
|
|
// SetSessionCacheMode(nn::ssl::sf::SessionCacheMode)
|
|
|
|
public ResultCode SetSessionCacheMode(ServiceCtx context)
|
|
|
|
{
|
|
|
|
SessionCacheMode sessionCacheMode = (SessionCacheMode)context.RequestData.ReadUInt32();
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { sessionCacheMode });
|
|
|
|
|
2022-01-13 23:29:04 +01:00
|
|
|
_sessionCacheMode = sessionCacheMode;
|
|
|
|
|
2021-04-13 03:04:18 +02:00
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(18)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetSessionCacheMode() -> nn::ssl::sf::SessionCacheMode
|
|
|
|
public ResultCode GetSessionCacheMode(ServiceCtx context)
|
|
|
|
{
|
2022-10-19 03:27:11 +02:00
|
|
|
context.ResponseData.Write((uint)_sessionCacheMode);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _sessionCacheMode });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
2022-01-13 23:29:04 +01:00
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(19)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// FlushSessionCache()
|
|
|
|
public ResultCode FlushSessionCache(ServiceCtx context)
|
|
|
|
{
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(20)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// SetRenegotiationMode(nn::ssl::sf::RenegotiationMode)
|
|
|
|
public ResultCode SetRenegotiationMode(ServiceCtx context)
|
|
|
|
{
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(21)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetRenegotiationMode() -> nn::ssl::sf::RenegotiationMode
|
|
|
|
public ResultCode GetRenegotiationMode(ServiceCtx context)
|
|
|
|
{
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(22)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// SetOption(b8 value, nn::ssl::sf::OptionType option)
|
2021-04-13 03:04:18 +02:00
|
|
|
public ResultCode SetOption(ServiceCtx context)
|
|
|
|
{
|
2022-01-13 23:29:04 +01:00
|
|
|
bool value = context.RequestData.ReadUInt32() != 0;
|
|
|
|
OptionType option = (OptionType)context.RequestData.ReadUInt32();
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { option, value });
|
|
|
|
|
|
|
|
return SetOption(option, value);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(23)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetOption(nn::ssl::sf::OptionType) -> b8
|
|
|
|
public ResultCode GetOption(ServiceCtx context)
|
|
|
|
{
|
|
|
|
OptionType option = (OptionType)context.RequestData.ReadUInt32();
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { option });
|
|
|
|
|
|
|
|
ResultCode result = GetOption(option, out bool value);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(24)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetVerifyCertErrors() -> (u32, u32, buffer<bytes, 6>)
|
|
|
|
public ResultCode GetVerifyCertErrors(ServiceCtx context)
|
|
|
|
{
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
|
|
|
}
|
2021-04-13 03:04:18 +02:00
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(25)] // 4.0.0+
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetCipherInfo(u32) -> buffer<bytes, 6>
|
|
|
|
public ResultCode GetCipherInfo(ServiceCtx context)
|
|
|
|
{
|
|
|
|
throw new ServiceNotImplementedException(this, context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(26)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// SetNextAlpnProto(buffer<bytes, 5>) -> u32
|
|
|
|
public ResultCode SetNextAlpnProto(ServiceCtx context)
|
|
|
|
{
|
|
|
|
ulong inputDataPosition = context.Request.SendBuff[0].Position;
|
|
|
|
ulong inputDataSize = context.Request.SendBuff[0].Size;
|
|
|
|
|
|
|
|
_nextAplnProto = new byte[inputDataSize];
|
|
|
|
|
|
|
|
context.Memory.Read(inputDataPosition, _nextAplnProto);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { inputDataSize });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-15 01:00:34 +02:00
|
|
|
[CommandCmif(27)]
|
2022-01-13 23:29:04 +01:00
|
|
|
// GetNextAlpnProto(buffer<bytes, 6>) -> u32
|
|
|
|
public ResultCode GetNextAlpnProto(ServiceCtx context)
|
|
|
|
{
|
|
|
|
ulong outputDataPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong outputDataSize = context.Request.ReceiveBuff[0].Size;
|
|
|
|
|
|
|
|
context.Memory.Write(outputDataPosition, _nextAplnProto);
|
|
|
|
|
|
|
|
context.ResponseData.Write(_nextAplnProto.Length);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { outputDataSize });
|
2021-04-13 03:04:18 +02:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
2022-01-13 23:29:04 +01:00
|
|
|
|
|
|
|
private ResultCode SetOption(OptionType option, bool value)
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case OptionType.DoNotCloseSocket:
|
|
|
|
_doNotClockSocket = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OptionType.GetServerCertChain:
|
|
|
|
_getServerCertChain = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OptionType.SkipDefaultVerify:
|
|
|
|
_skipDefaultVerify = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OptionType.EnableAlpn:
|
|
|
|
_enableAlpn = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Logger.Warning?.Print(LogClass.ServiceSsl, $"Unsupported option {option}");
|
|
|
|
return ResultCode.InvalidOption;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResultCode GetOption(OptionType option, out bool value)
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case OptionType.DoNotCloseSocket:
|
|
|
|
value = _doNotClockSocket;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OptionType.GetServerCertChain:
|
|
|
|
value = _getServerCertChain;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OptionType.SkipDefaultVerify:
|
|
|
|
value = _skipDefaultVerify;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OptionType.EnableAlpn:
|
|
|
|
value = _enableAlpn;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Logger.Warning?.Print(LogClass.ServiceSsl, $"Unsupported option {option}");
|
|
|
|
|
|
|
|
value = false;
|
|
|
|
return ResultCode.InvalidOption;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
_connection?.Dispose();
|
|
|
|
}
|
2021-04-13 03:04:18 +02:00
|
|
|
}
|
|
|
|
}
|