Пример #1
0
        private void encryptButton_Click( object sender, EventArgs e )
        {
            Message message;

            byte[] plainText = Encoding.UTF8.GetBytes( this.sendTextbox.Text );
            byte[] cipherText = this.serverContext.Encrypt( plainText );

            message = new Message( ProtocolOp.EncryptedMessage, cipherText );

            this.server.Send( message );
        }
Пример #2
0
        private void HandleEncrypted( Message message )
        {
            this.Invoke( (Action)delegate()
            {
                byte[] plainText = this.serverContext.Decrypt( message.Data );
                string text = Encoding.UTF8.GetString( plainText );

                this.receivedTextbox.Text += "Received encrypted message from client:\r\n" + text + "\r\n";
            } );
        }
Пример #3
0
        private void signButton_Click( object sender, EventArgs e )
        {
            byte[] plainText = Encoding.UTF8.GetBytes( this.sendTextbox.Text );
            byte[] signedData;
            Message message;

            signedData = this.serverContext.MakeSignature( plainText );

            message = new Message( ProtocolOp.SignedMessage, signedData );

            this.server.Send( message );
        }
Пример #4
0
 private void HandleUnknown( Message message )
 {
     this.Invoke( (Action)delegate()
     {
         MessageBox.Show( "Received unexpected message from server. Message type: " + message.Operation );
     } );
 }
Пример #5
0
 private void server_Received( Message message )
 {
     if( message.Operation == ProtocolOp.ClientToken )
     {
         HandleInit( message );
     }
     else if( message.Operation == ProtocolOp.EncryptedMessage )
     {
         HandleEncrypted( message );
     }
     else if( message.Operation == ProtocolOp.SignedMessage )
     {
         HandleSigned( message );
     }
     else
     {
         HandleUnknown( message );
     }
 }
Пример #6
0
        private void HandleInit( Message message )
        {
            byte[] nextToken;
            SecurityStatus status;

            if( initializing )
            {
                status = this.serverContext.AcceptToken( message.Data, out nextToken );

                if( status == SecurityStatus.OK || status == SecurityStatus.ContinueNeeded )
                {
                    if( nextToken != null )
                    {
                        this.server.Send( new Message( ProtocolOp.ServerToken, nextToken ) );
                    }

                    if( status == SecurityStatus.OK )
                    {
                        this.initializing = false;
                        this.connected = true;

                        this.Invoke( (Action)delegate()
                        {
                            UpdateButtons();
                            this.clientUsernameTextBox.Text = serverContext.ContextUserName;
                        } );
                    }
                }
                else
                {
                    this.Invoke( (Action)delegate()
                    {
                        MessageBox.Show( "Failed to accept token from client. Sspi error code: " + status );
                    } );
                }

            }
        }
Пример #7
0
        private void HandleSigned( Message message )
        {
            this.Invoke( (Action)delegate()
            {
                byte[] plainText;

                if( this.serverContext.VerifySignature( message.Data, out plainText ) )
                {
                    string text = Encoding.UTF8.GetString( plainText );

                    this.receivedTextbox.Text += "Received valid signed message from client:\r\n" + text + "\r\n";
                }
                else
                {
                    this.receivedTextbox.Text += "Received *** invalid *** signed message from client.\r\n";
                }
            } );
        }
Пример #8
0
        private void signButton_Click( object sender, EventArgs e )
        {
            byte[] plaintext;
            byte[] cipherText;
            Message message;

            plaintext = Encoding.UTF8.GetBytes( this.sendTextbox.Text );

            cipherText = this.context.MakeSignature( plaintext );

            message = new Message( ProtocolOp.SignedMessage, cipherText );

            this.connection.Send( message );
        }
Пример #9
0
        private void HandleSigned( Message message )
        {
            byte[] plaintext;
            string text;

            if( this.context.VerifySignature( message.Data, out plaintext ) )
            {
                text = Encoding.UTF8.GetString( plaintext );
                this.receiveTextbox.Text += "Received valid signed message from server:\r\n" + text + "\r\n";
            }
            else
            {
                this.receiveTextbox.Text += "Received *** invalid *** signed message from server.\r\n";
            }
        }
Пример #10
0
        private void HandleEncrypted( Message message )
        {
            byte[] plainText = this.context.Decrypt( message.Data );

            string text = Encoding.UTF8.GetString( plainText );

            this.receiveTextbox.Text += "Received encrypted message from server:\r\n" + text + "\r\n";
        }
Пример #11
0
        private void DoInit()
        {
            SecurityStatus status;
            byte[] outToken;

            status = this.context.Init( this.lastServerToken, out outToken );

            if( status == SecurityStatus.ContinueNeeded )
            {
                Message message = new Message( ProtocolOp.ClientToken, outToken );
                this.connection.Send( message );
            }
            else if( status == SecurityStatus.OK )
            {
                this.lastServerToken = null;
                this.initializing = false;
                this.connected = true;
                UpdateButtons();
            }
        }
Пример #12
0
 private void connection_Received( Message message )
 {
     this.Invoke( (Action)delegate()
     {
         if( message.Operation == ProtocolOp.ServerToken )
         {
             if( initializing )
             {
                 this.lastServerToken = message.Data;
                 DoInit();
             }
             else
             {
                 MessageBox.Show( "Read unexpected operation from server: " + message.Operation );
             }
         }
         else if( message.Operation == ProtocolOp.EncryptedMessage )
         {
             HandleEncrypted( message );
         }
         else if( message.Operation == ProtocolOp.SignedMessage )
         {
             HandleSigned( message );
         }
     } );
 }