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 ); }
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"; } ); }
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 ); }
private void HandleUnknown( Message message ) { this.Invoke( (Action)delegate() { MessageBox.Show( "Received unexpected message from server. Message type: " + message.Operation ); } ); }
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 ); } }
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 ); } ); } } }
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"; } } ); }
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 ); }
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"; } }
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"; }
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(); } }
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 ); } } ); }