1 // Transport Security Layer (TLS)
2 // Copyright (c) 2003-2004 Carlos Guzman Alvarez
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER 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();