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.description = description;
128 this.level = inferAlertLevel(description);
133 AlertDescription description)
136 this.description = description;
141 #region Private Methods
143 private static AlertLevel inferAlertLevel(AlertDescription description)
147 case AlertDescription.CloseNotify:
148 case AlertDescription.NoRenegotiation:
149 case AlertDescription.UserCancelled:
150 return AlertLevel.Warning;
152 case AlertDescription.AccessDenied:
153 case AlertDescription.BadCertificate:
154 case AlertDescription.BadRecordMAC:
155 case AlertDescription.CertificateExpired:
156 case AlertDescription.CertificateRevoked:
157 case AlertDescription.CertificateUnknown:
158 case AlertDescription.DecodeError:
159 case AlertDescription.DecompressionFailiure:
160 case AlertDescription.DecryptError:
161 case AlertDescription.DecryptionFailed:
162 case AlertDescription.ExportRestriction:
163 case AlertDescription.HandshakeFailiure:
164 case AlertDescription.IlegalParameter:
165 case AlertDescription.InsuficientSecurity:
166 case AlertDescription.InternalError:
167 case AlertDescription.ProtocolVersion:
168 case AlertDescription.RecordOverflow:
169 case AlertDescription.UnexpectedMessage:
170 case AlertDescription.UnknownCA:
171 case AlertDescription.UnsupportedCertificate:
173 return AlertLevel.Fatal;
179 #region Static Methods
181 public static string GetAlertMessage(AlertDescription description)
186 case AlertDescription.AccessDenied:
187 return "An inappropriate message was received.";
189 case AlertDescription.BadCertificate:
190 return "TLSCiphertext decrypted in an invalid way.";
192 case AlertDescription.BadRecordMAC:
193 return "Record with an incorrect MAC.";
195 case AlertDescription.CertificateExpired:
196 return "Certificate has expired or is not currently valid";
198 case AlertDescription.CertificateRevoked:
199 return "Certificate was revoked by its signer.";
201 case AlertDescription.CertificateUnknown:
202 return "Certificate Unknown.";
204 case AlertDescription.CloseNotify:
205 return "Connection closed";
207 case AlertDescription.DecodeError:
208 return "A message could not be decoded because some field was out of the specified range or the length of the message was incorrect.";
210 case AlertDescription.DecompressionFailiure:
211 return "The decompression function received improper input (e.g. data that would expand to excessive length).";
213 case AlertDescription.DecryptError:
214 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.";
216 case AlertDescription.DecryptionFailed:
217 return "Handshake cryptographic operation failed, including being unable to correctly verify a signature, decrypt a key exchange, or validate finished message.";
219 case AlertDescription.ExportRestriction:
220 return "Negotiation not in compliance with export restrictions was detected.";
222 case AlertDescription.HandshakeFailiure:
223 return "Unable to negotiate an acceptable set of security parameters given the options available.";
225 case AlertDescription.IlegalParameter:
226 return "A field in the handshake was out of range or inconsistent with other fields.";
228 case AlertDescription.InsuficientSecurity:
229 return "Negotiation has failed specifically because the server requires ciphers more secure than those supported by the client.";
231 case AlertDescription.InternalError:
232 return "Internal error unrelated to the peer or the correctness of the protocol makes it impossible to continue.";
234 case AlertDescription.NoRenegotiation:
235 return "Invalid renegotiation.";
237 case AlertDescription.ProtocolVersion:
238 return "Unsupported protocol version.";
240 case AlertDescription.RecordOverflow:
241 return "Invalid length on TLSCiphertext record or TLSCompressed record.";
243 case AlertDescription.UnexpectedMessage:
244 return "Invalid message received.";
246 case AlertDescription.UnknownCA:
247 return "CA can't be identified as a trusted CA.";
249 case AlertDescription.UnsupportedCertificate:
250 return "Certificate was of an unsupported type.";
252 case AlertDescription.UserCancelled:
253 return "Handshake cancelled by user.";
259 return "The authentication or decryption has failed.";