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