public override void SendAsync(ServerAsyncEventArgs e) { try { Server <C> .Connection <C> tcpConnection = base.GetTcpConnection(e.RemoteEndPoint); base.OnBeforeSend(tcpConnection, e); if (tcpConnection == null) { e.Completed = new ServerAsyncEventArgs.CompletedEventHandler(base.Send_Completed); e.SocketError = SocketError.NotConnected; e.OnCompleted(null); } else { SspiContext sspiContext = tcpConnection.SspiContext; SecPkgContext_StreamSizes streamSizes = sspiContext.StreamSizes; int count = e.Count; if (e.OffsetOffset < streamSizes.cbHeader) { throw new NotImplementedException("Ineffective way not implemented. Need to move buffer for SECBUFFER_STREAM_HEADER."); } e.OffsetOffset -= streamSizes.cbHeader; e.Count = streamSizes.cbHeader + count + streamSizes.cbTrailer; e.ReAllocateBuffer(true); SecBufferDescEx secBufferDescEx = new SecBufferDescEx(new SecBufferEx[] { new SecBufferEx { BufferType = BufferType.SECBUFFER_STREAM_HEADER, Buffer = e.Buffer, Size = streamSizes.cbHeader, Offset = e.Offset }, new SecBufferEx { BufferType = BufferType.SECBUFFER_DATA, Buffer = e.Buffer, Size = count, Offset = e.Offset + streamSizes.cbHeader }, new SecBufferEx { BufferType = BufferType.SECBUFFER_STREAM_TRAILER, Buffer = e.Buffer, Size = streamSizes.cbTrailer, Offset = e.Offset + streamSizes.cbHeader + count }, new SecBufferEx { BufferType = BufferType.SECBUFFER_VERSION } }); Sspi.EncryptMessage(ref sspiContext.Handle, ref secBufferDescEx, 0u, null); e.Count = secBufferDescEx.Buffers[0].Size + secBufferDescEx.Buffers[1].Size + secBufferDescEx.Buffers[2].Size; e.ReAllocateBuffer(true); base.SendAsync(tcpConnection, e); } } catch (SspiException error) { e.SocketError = SocketError.Fault; this.OnFailed(new ServerInfoEventArgs(this.realEndPoint, error)); } }
public override unsafe void SendAsync(ServerAsyncEventArgs e) { try { var connection = GetTcpConnection(e.RemoteEndPoint); OnBeforeSend(connection, e); if (connection == null) { e.Completed = Send_Completed; e.SocketError = SocketError.NotConnected; e.OnCompleted(null); return; } var context = connection.SspiContext; var sizes = context.StreamSizes; var dataCount = e.Count; if (e.OffsetOffset >= sizes.cbHeader) { e.OffsetOffset -= sizes.cbHeader; e.Count = sizes.cbHeader + dataCount + sizes.cbTrailer; e.ReAllocateBuffer(true); } else { throw new NotImplementedException("Ineffective way not implemented. Need to move buffer for SECBUFFER_STREAM_HEADER."); } var message = new SecBufferDescEx( new SecBufferEx[] { new SecBufferEx() { BufferType = BufferType.SECBUFFER_STREAM_HEADER, Buffer = e.Buffer, Size = sizes.cbHeader, Offset = e.Offset, }, new SecBufferEx() { BufferType = BufferType.SECBUFFER_DATA, Buffer = e.Buffer, Size = dataCount, Offset = e.Offset + sizes.cbHeader, }, new SecBufferEx() { BufferType = BufferType.SECBUFFER_STREAM_TRAILER, Buffer = e.Buffer, Size = sizes.cbTrailer, Offset = e.Offset + sizes.cbHeader + dataCount, }, new SecBufferEx() { BufferType = BufferType.SECBUFFER_EMPTY, }, }); Sspi.EncryptMessage( ref context.Handle, ref message, 0, null); e.Count = message.Buffers[0].Size + message.Buffers[1].Size + message.Buffers[2].Size; e.ReAllocateBuffer(true); base.SendAsync(connection, e); } catch (SspiException ex) { e.SocketError = SocketError.Fault; OnFailed(new ServerInfoEventArgs(realEndPoint, ex)); } }