* Makefile: Added new targets for running the tests. Now the generated
[mono.git] / mcs / class / Mono.Security / Mono.Security.Protocol.Tls / RecordProtocol.cs
index f32317868a18882ef3017d9aa56d223d677707a8..dd8feeac677e84c627c8a23c026c0483d8c51c5f 100644 (file)
@@ -42,12 +42,6 @@ namespace Mono.Security.Protocol.Tls
 
                #region Properties
 
-               public Stream InnerStream
-               {
-                       get { return this.innerStream; }
-                       set { this.innerStream = value; }
-               }
-
                public Context Context
                {
                        get { return this.context; }
@@ -108,6 +102,12 @@ namespace Mono.Security.Protocol.Tls
                                        buffer, received, buffer.Length - received);
                        }
 
+                       DebugHelper.WriteLine(
+                               ">>>> Read record ({0}|{1})", 
+                               this.context.DecodeProtocolCode(protocol),
+                               contentType);
+                       DebugHelper.WriteLine("Record data", buffer);
+
                        TlsStream message = new TlsStream(buffer);
                
                        // Check that the message has a valid protocol version
@@ -131,6 +131,8 @@ namespace Mono.Security.Protocol.Tls
                                        message = this.decryptRecordFragment(
                                                contentType, 
                                                message.ToArray());
+
+                                       DebugHelper.WriteLine("Decrypted record data", message.ToArray());
                                }
                        }
 
@@ -222,7 +224,9 @@ namespace Mono.Security.Protocol.Tls
                }
 
                public void SendAlert(Alert alert)
-               {                       
+               {
+                       DebugHelper.WriteLine(">>>> Write Alert ({0}|{1})", alert.Description, alert.Message);
+
                        // Write record
                        this.SendRecord(
                                ContentType.Alert, 
@@ -240,6 +244,8 @@ namespace Mono.Security.Protocol.Tls
 
                public void SendChangeCipherSpec()
                {
+                       DebugHelper.WriteLine(">>>> Write Change Cipher Spec");
+
                        // Send Change Cipher Spec message as a plain message
                        this.context.IsActual = false;
 
@@ -326,6 +332,8 @@ namespace Mono.Security.Protocol.Tls
                                record.Write((short)fragment.Length);
                                record.Write(fragment);
 
+                               DebugHelper.WriteLine("Record data", fragment);
+
                                // Update buffer position
                                position += fragmentLength;
                        }
@@ -353,6 +361,8 @@ namespace Mono.Security.Protocol.Tls
                                mac     = this.context.Cipher.ComputeServerRecordMAC(contentType, fragment);
                        }
 
+                       DebugHelper.WriteLine(">>>> Record MAC", mac);
+
                        // Encrypt the message
                        byte[] ecr = this.context.Cipher.EncryptRecord(fragment, mac);
 
@@ -405,6 +415,8 @@ namespace Mono.Security.Protocol.Tls
                                mac = this.context.Cipher.ComputeClientRecordMAC(contentType, dcrFragment);
                        }
 
+                       DebugHelper.WriteLine(">>>> Record MAC", mac);
+
                        // Check record MAC
                        if (mac.Length != dcrMAC.Length)
                        {
@@ -424,12 +436,7 @@ namespace Mono.Security.Protocol.Tls
 
                        if (badRecordMac)
                        {
-                               if (this.context is ServerContext)
-                               {
-                                       this.Context.RecordProtocol.SendAlert(AlertDescription.BadRecordMAC);
-                               }
-
-                               throw new TlsException("Bad record MAC");
+                               throw new TlsException(AlertDescription.BadRecordMAC, "Bad record MAC");
                        }
 
                        // Update sequence number