1 /* Transport Security Layer (TLS)
2 * Copyright (c) 2003-2004 Carlos Guzman Alvarez
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
27 namespace Mono.Security.Protocol.Tls.Handshake
29 internal abstract class HandshakeMessage : TlsStream
33 private Context context;
34 private HandshakeType handshakeType;
35 private ContentType contentType;
41 public Context Context
43 get { return this.context; }
46 public HandshakeType HandshakeType
48 get { return this.handshakeType; }
51 public ContentType ContentType
53 get { return this.contentType; }
60 public HandshakeMessage(
62 HandshakeType handshakeType)
63 : this(context, handshakeType, ContentType.Handshake)
67 public HandshakeMessage(
69 HandshakeType handshakeType,
70 ContentType contentType) : base()
72 this.context = context;
73 this.handshakeType = handshakeType;
74 this.contentType = contentType;
77 public HandshakeMessage(
79 HandshakeType handshakeType,
80 byte[] data) : base(data)
82 this.context = context;
83 this.handshakeType = handshakeType;
88 #region Abstract Methods
90 protected abstract void ProcessAsTls1();
92 protected abstract void ProcessAsSsl3();
100 switch (this.Context.SecurityProtocol)
102 case SecurityProtocolType.Tls:
103 case SecurityProtocolType.Default:
104 this.ProcessAsTls1();
107 case SecurityProtocolType.Ssl3:
108 this.ProcessAsSsl3();
111 case SecurityProtocolType.Ssl2:
113 throw new NotSupportedException("Unsupported security protocol type");
117 public virtual void Update()
121 this.context.HandshakeMessages.Write(this.EncodeMessage());
126 public virtual byte[] EncodeMessage()
128 byte[] result = null;
132 TlsStream c = new TlsStream();
134 c.Write((byte)HandshakeType);
135 c.WriteInt24((int)this.Length);
136 c.Write(this.ToArray());
138 result = c.ToArray();