Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5463beab4a |
8
TestClient/ClientForm.Designer.cs
generated
8
TestClient/ClientForm.Designer.cs
generated
@@ -148,7 +148,6 @@
|
||||
this.sendTextbox.Location = new System.Drawing.Point(6, 19);
|
||||
this.sendTextbox.Multiline = true;
|
||||
this.sendTextbox.Name = "sendTextbox";
|
||||
this.sendTextbox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||
this.sendTextbox.Size = new System.Drawing.Size(302, 298);
|
||||
this.sendTextbox.TabIndex = 7;
|
||||
//
|
||||
@@ -191,7 +190,6 @@
|
||||
this.receiveTextbox.Location = new System.Drawing.Point(3, 16);
|
||||
this.receiveTextbox.Multiline = true;
|
||||
this.receiveTextbox.Name = "receiveTextbox";
|
||||
this.receiveTextbox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||
this.receiveTextbox.Size = new System.Drawing.Size(308, 338);
|
||||
this.receiveTextbox.TabIndex = 10;
|
||||
//
|
||||
@@ -233,7 +231,7 @@
|
||||
this.disconnectButton.Text = "Disconnect";
|
||||
this.disconnectButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// ClientForm
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
@@ -246,8 +244,8 @@
|
||||
this.Controls.Add(this.serverTextBox);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "ClientForm";
|
||||
this.Text = "Client - SSPI Demo";
|
||||
this.Name = "Form1";
|
||||
this.Text = "Form1";
|
||||
((System.ComponentModel.ISupportInitialize)(this.portNumeric)).EndInit();
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
|
||||
@@ -112,10 +112,7 @@ namespace TestProtocol
|
||||
byte[] readBuffer = new byte[65536];
|
||||
|
||||
ProtocolOp operation;
|
||||
int messageLength;
|
||||
int remaining;
|
||||
int chunkLength;
|
||||
int position;
|
||||
int length;
|
||||
|
||||
while( this.running )
|
||||
{
|
||||
@@ -135,24 +132,10 @@ namespace TestProtocol
|
||||
|
||||
// Read the length
|
||||
this.socket.Receive( readBuffer, 4, SocketFlags.None );
|
||||
messageLength = ByteWriter.ReadInt32_BE( readBuffer, 0 );
|
||||
|
||||
if( readBuffer.Length < messageLength )
|
||||
{
|
||||
readBuffer = new byte[messageLength];
|
||||
}
|
||||
length = ByteWriter.ReadInt32_BE( readBuffer, 0 );
|
||||
|
||||
// Read the data
|
||||
// Keep in mind that Socket.Receive may return less data than asked for.
|
||||
remaining = messageLength;
|
||||
chunkLength = 0;
|
||||
position = 0;
|
||||
while( remaining > 0 )
|
||||
{
|
||||
chunkLength = this.socket.Receive( readBuffer, position, remaining, SocketFlags.None );
|
||||
remaining -= chunkLength;
|
||||
position += chunkLength;
|
||||
}
|
||||
this.socket.Receive( readBuffer, length, SocketFlags.None );
|
||||
|
||||
}
|
||||
catch( SocketException e )
|
||||
@@ -160,8 +143,7 @@ namespace TestProtocol
|
||||
if( e.SocketErrorCode == SocketError.ConnectionAborted ||
|
||||
e.SocketErrorCode == SocketError.Interrupted ||
|
||||
e.SocketErrorCode == SocketError.OperationAborted ||
|
||||
e.SocketErrorCode == SocketError.Shutdown ||
|
||||
e.SocketErrorCode == SocketError.ConnectionReset )
|
||||
e.SocketErrorCode == SocketError.Shutdown )
|
||||
{
|
||||
// Shutting down.
|
||||
break;
|
||||
@@ -176,8 +158,8 @@ namespace TestProtocol
|
||||
|
||||
if( this.Received != null )
|
||||
{
|
||||
byte[] dataCopy = new byte[messageLength];
|
||||
Array.Copy( readBuffer, 0, dataCopy, 0, messageLength );
|
||||
byte[] dataCopy = new byte[length];
|
||||
Array.Copy( readBuffer, 0, dataCopy, 0, length );
|
||||
Message message = new Message( operation, dataCopy );
|
||||
|
||||
try
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using NSspi;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TestProtocol
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using NSspi;
|
||||
|
||||
public class CustomServer
|
||||
{
|
||||
private Thread receiveThread;
|
||||
@@ -139,9 +149,7 @@ namespace TestProtocol
|
||||
byte[] readBuffer = new byte[65536];
|
||||
|
||||
ProtocolOp operation;
|
||||
int messageLength;
|
||||
int position;
|
||||
int remaining;
|
||||
int length;
|
||||
|
||||
while( this.running )
|
||||
{
|
||||
@@ -149,7 +157,7 @@ namespace TestProtocol
|
||||
{
|
||||
// |--4 bytes--|--4 bytes--|---N--|
|
||||
// Every command is a TLV - | Operation | Length | Data |
|
||||
int chunkLength;
|
||||
|
||||
|
||||
// Read the operation.
|
||||
this.readSocket.Receive( readBuffer, 4, SocketFlags.None );
|
||||
@@ -161,24 +169,11 @@ namespace TestProtocol
|
||||
|
||||
// Read the length
|
||||
this.readSocket.Receive( readBuffer, 4, SocketFlags.None );
|
||||
messageLength = ByteWriter.ReadInt32_BE( readBuffer, 0 );
|
||||
|
||||
if( readBuffer.Length < messageLength )
|
||||
{
|
||||
readBuffer = new byte[messageLength];
|
||||
}
|
||||
length = ByteWriter.ReadInt32_BE( readBuffer, 0 );
|
||||
|
||||
// Read the data
|
||||
// Keep in mind that Socket.Receive may return less data than asked for.
|
||||
remaining = messageLength;
|
||||
chunkLength = 0;
|
||||
position = 0;
|
||||
while( remaining > 0 )
|
||||
{
|
||||
chunkLength = this.readSocket.Receive( readBuffer, position, remaining, SocketFlags.None );
|
||||
remaining -= chunkLength;
|
||||
position += chunkLength;
|
||||
}
|
||||
this.readSocket.Receive( readBuffer, length, SocketFlags.None );
|
||||
|
||||
}
|
||||
catch( SocketException e )
|
||||
{
|
||||
@@ -201,8 +196,8 @@ namespace TestProtocol
|
||||
|
||||
if( this.Received != null )
|
||||
{
|
||||
byte[] dataCopy = new byte[messageLength];
|
||||
Array.Copy( readBuffer, 0, dataCopy, 0, messageLength );
|
||||
byte[] dataCopy = new byte[length];
|
||||
Array.Copy( readBuffer, 0, dataCopy, 0, length );
|
||||
Message message = new Message( operation, dataCopy );
|
||||
|
||||
try
|
||||
|
||||
22
TestServer/ServerForm.Designer.cs
generated
22
TestServer/ServerForm.Designer.cs
generated
@@ -38,13 +38,13 @@
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.serverUsernameTextbox = new System.Windows.Forms.TextBox();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.impersonateButton = new System.Windows.Forms.Button();
|
||||
this.signButton = new System.Windows.Forms.Button();
|
||||
this.encryptButton = new System.Windows.Forms.Button();
|
||||
this.sendTextbox = new System.Windows.Forms.TextBox();
|
||||
this.groupBox3 = new System.Windows.Forms.GroupBox();
|
||||
this.receivedTextbox = new System.Windows.Forms.TextBox();
|
||||
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.impersonateButton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.portNumeric)).BeginInit();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
@@ -168,15 +168,6 @@
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Send a message to the client";
|
||||
//
|
||||
// impersonateButton
|
||||
//
|
||||
this.impersonateButton.Location = new System.Drawing.Point(262, 350);
|
||||
this.impersonateButton.Name = "impersonateButton";
|
||||
this.impersonateButton.Size = new System.Drawing.Size(116, 23);
|
||||
this.impersonateButton.TabIndex = 4;
|
||||
this.impersonateButton.Text = "Test impersonation";
|
||||
this.impersonateButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// signButton
|
||||
//
|
||||
this.signButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
@@ -205,7 +196,6 @@
|
||||
this.sendTextbox.Location = new System.Drawing.Point(6, 19);
|
||||
this.sendTextbox.Multiline = true;
|
||||
this.sendTextbox.Name = "sendTextbox";
|
||||
this.sendTextbox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||
this.sendTextbox.Size = new System.Drawing.Size(400, 323);
|
||||
this.sendTextbox.TabIndex = 0;
|
||||
//
|
||||
@@ -226,7 +216,6 @@
|
||||
this.receivedTextbox.Location = new System.Drawing.Point(3, 16);
|
||||
this.receivedTextbox.Multiline = true;
|
||||
this.receivedTextbox.Name = "receivedTextbox";
|
||||
this.receivedTextbox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||
this.receivedTextbox.Size = new System.Drawing.Size(407, 370);
|
||||
this.receivedTextbox.TabIndex = 0;
|
||||
//
|
||||
@@ -247,6 +236,15 @@
|
||||
this.tableLayoutPanel1.Size = new System.Drawing.Size(838, 395);
|
||||
this.tableLayoutPanel1.TabIndex = 7;
|
||||
//
|
||||
// impersonateButton
|
||||
//
|
||||
this.impersonateButton.Location = new System.Drawing.Point(262, 350);
|
||||
this.impersonateButton.Name = "impersonateButton";
|
||||
this.impersonateButton.Size = new System.Drawing.Size(116, 23);
|
||||
this.impersonateButton.TabIndex = 4;
|
||||
this.impersonateButton.Text = "Test impersonation";
|
||||
this.impersonateButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// ServerForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace TestServer
|
||||
|
||||
private void server_Disconnected()
|
||||
{
|
||||
this.running = true;
|
||||
this.running = false;
|
||||
this.initializing = true;
|
||||
this.connected = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user