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
32 internal enum AlertLevel
: byte
39 internal enum AlertDescription
: byte
42 UnexpectedMessage
= 10,
44 DecryptionFailed
= 21,
46 DecompressionFailiure
= 30,
47 HandshakeFailiure
= 40,
48 NoCertificate
= 41, // should be used in SSL3
50 UnsupportedCertificate
= 43,
51 CertificateRevoked
= 44,
52 CertificateExpired
= 45,
53 CertificateUnknown
= 46,
59 ExportRestriction
= 60,
61 InsuficientSecurity
= 71,
73 private AlertLevel level
;
74 private AlertDescription description
;
80 public AlertLevel Level
82 get { return this.level; }
85 public AlertDescription Description
87 get { return this.description; }
92 get { return Alert.GetAlertMessage(this.description); }
97 get { return this.level == AlertLevel.Warning ? true : false; }
103 get { return this.level == AlertLevel.Fatal ? true : false; }
107 public bool IsCloseNotify
111 if (this.IsWarning
&&
112 this.description
== AlertDescription
.CloseNotify
)
125 public Alert(AlertDescription description
)
127 this.inferAlertLevel();
128 this.description
= description
;
133 AlertDescription description
)
136 this.description
= description
;
141 #region Private Methods
143 private void inferAlertLevel()
147 case AlertDescription
.CloseNotify
:
148 case AlertDescription
.NoRenegotiation
:
149 case AlertDescription
.UserCancelled
:
150 this.level
= AlertLevel
.Warning
;
153 case AlertDescription
.AccessDenied
:
154 case AlertDescription
.BadCertificate
:
155 case AlertDescription
.BadRecordMAC
:
156 case AlertDescription
.CertificateExpired
:
157 case AlertDescription
.CertificateRevoked
:
158 case AlertDescription
.CertificateUnknown
:
159 case AlertDescription
.DecodeError
:
160 case AlertDescription
.DecompressionFailiure
:
161 case AlertDescription
.DecryptError
:
162 case AlertDescription
.DecryptionFailed
:
163 case AlertDescription
.ExportRestriction
:
164 case AlertDescription
.HandshakeFailiure
:
165 case AlertDescription
.IlegalParameter
:
166 case AlertDescription
.InsuficientSecurity
:
167 case AlertDescription
.InternalError
:
168 case AlertDescription
.ProtocolVersion
:
169 case AlertDescription
.RecordOverflow
:
170 case AlertDescription
.UnexpectedMessage
:
171 case AlertDescription
.UnknownCA
:
172 case AlertDescription
.UnsupportedCertificate
:
174 this.level
= AlertLevel
.Fatal
;
181 #region Static Methods
183 public static string GetAlertMessage(AlertDescription description
)
188 case AlertDescription
.AccessDenied
:
189 return "An inappropriate message was received.";
191 case AlertDescription
.BadCertificate
:
192 return "TLSCiphertext decrypted in an invalid way.";
194 case AlertDescription
.BadRecordMAC
:
195 return "Record with an incorrect MAC.";
197 case AlertDescription
.CertificateExpired
:
198 return "Certificate has expired or is not currently valid";
200 case AlertDescription
.CertificateRevoked
:
201 return "Certificate was revoked by its signer.";
203 case AlertDescription
.CertificateUnknown
:
204 return "Certificate Unknown.";
206 case AlertDescription
.CloseNotify
:
207 return "Connection closed";
209 case AlertDescription
.DecodeError
:
210 return "A message could not be decoded because some field was out of the specified range or the length of the message was incorrect.";
212 case AlertDescription
.DecompressionFailiure
:
213 return "The decompression function received improper input (e.g. data that would expand to excessive length).";
215 case AlertDescription
.DecryptError
:
216 return "TLSCiphertext decrypted in an invalid way: either it wasn`t an even multiple of the block length or its padding values, when checked, weren`t correct.";
218 case AlertDescription
.DecryptionFailed
:
219 return "Handshake cryptographic operation failed, including being unable to correctly verify a signature, decrypt a key exchange, or validate finished message.";
221 case AlertDescription
.ExportRestriction
:
222 return "Negotiation not in compliance with export restrictions was detected.";
224 case AlertDescription
.HandshakeFailiure
:
225 return "Unable to negotiate an acceptable set of security parameters given the options available.";
227 case AlertDescription
.IlegalParameter
:
228 return "A field in the handshake was out of range or inconsistent with other fields.";
230 case AlertDescription
.InsuficientSecurity
:
231 return "Negotiation has failed specifically because the server requires ciphers more secure than those supported by the client.";
233 case AlertDescription
.InternalError
:
234 return "Internal error unrelated to the peer or the correctness of the protocol makes it impossible to continue.";
236 case AlertDescription
.NoRenegotiation
:
237 return "Invalid renegotiation.";
239 case AlertDescription
.ProtocolVersion
:
240 return "Unsupported protocol version.";
242 case AlertDescription
.RecordOverflow
:
243 return "Invalid length on TLSCiphertext record or TLSCompressed record.";
245 case AlertDescription
.UnexpectedMessage
:
246 return "Invalid message received.";
248 case AlertDescription
.UnknownCA
:
249 return "CA can't be identified as a trusted CA.";
251 case AlertDescription
.UnsupportedCertificate
:
252 return "Certificate was of an unsupported type.";
254 case AlertDescription
.UserCancelled
:
255 return "Handshake cancelled by user.";
261 return "The authentication or decryption has failed.";