diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2017-06-07 14:40:24 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2017-06-07 14:40:24 +0700 |
commit | 4589defc7197db8d49edc67a354a34ce2ce5928b (patch) | |
tree | b8ab75548954efddcde4a406ecec360566934214 /crypto/src | |
parent | Fix paths for previous commit (diff) | |
download | BouncyCastle.NET-ed25519-4589defc7197db8d49edc67a354a34ce2ce5928b.tar.xz |
Specific exception TlsFatalAlertReceived for peer fatal alerts
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/crypto/tls/TlsException.cs | 14 | ||||
-rw-r--r-- | crypto/src/crypto/tls/TlsFatalAlert.cs | 3 | ||||
-rw-r--r-- | crypto/src/crypto/tls/TlsFatalAlertReceived.cs | 21 | ||||
-rw-r--r-- | crypto/src/crypto/tls/TlsProtocol.cs | 32 |
4 files changed, 51 insertions, 19 deletions
diff --git a/crypto/src/crypto/tls/TlsException.cs b/crypto/src/crypto/tls/TlsException.cs new file mode 100644 index 000000000..cea9e3e77 --- /dev/null +++ b/crypto/src/crypto/tls/TlsException.cs @@ -0,0 +1,14 @@ +using System; +using System.IO; + +namespace Org.BouncyCastle.Crypto.Tls +{ + public class TlsException + : IOException + { + public TlsException(string message, Exception cause) + : base(message, cause) + { + } + } +} diff --git a/crypto/src/crypto/tls/TlsFatalAlert.cs b/crypto/src/crypto/tls/TlsFatalAlert.cs index 55d784dd9..6f1898179 100644 --- a/crypto/src/crypto/tls/TlsFatalAlert.cs +++ b/crypto/src/crypto/tls/TlsFatalAlert.cs @@ -1,10 +1,9 @@ using System; -using System.IO; namespace Org.BouncyCastle.Crypto.Tls { public class TlsFatalAlert - : IOException + : TlsException { private readonly byte alertDescription; diff --git a/crypto/src/crypto/tls/TlsFatalAlertReceived.cs b/crypto/src/crypto/tls/TlsFatalAlertReceived.cs new file mode 100644 index 000000000..044fc8027 --- /dev/null +++ b/crypto/src/crypto/tls/TlsFatalAlertReceived.cs @@ -0,0 +1,21 @@ +using System; + +namespace Org.BouncyCastle.Crypto.Tls +{ + public class TlsFatalAlertReceived + : TlsException + { + private readonly byte alertDescription; + + public TlsFatalAlertReceived(byte alertDescription) + : base(Tls.AlertDescription.GetText(alertDescription), null) + { + this.alertDescription = alertDescription; + } + + public virtual byte AlertDescription + { + get { return alertDescription; } + } + } +} diff --git a/crypto/src/crypto/tls/TlsProtocol.cs b/crypto/src/crypto/tls/TlsProtocol.cs index 5a1c08616..20ea3ede6 100644 --- a/crypto/src/crypto/tls/TlsProtocol.cs +++ b/crypto/src/crypto/tls/TlsProtocol.cs @@ -389,28 +389,26 @@ namespace Org.BouncyCastle.Crypto.Tls CleanupHandshake(); } - throw new IOException("Fatal alert received from TLS peer: " + AlertDescription.GetText(description)); + throw new TlsFatalAlertReceived(description); } - else + + /* + * RFC 5246 7.2.1. The other party MUST respond with a close_notify alert of its own + * and close down the connection immediately, discarding any pending writes. + */ + if (description == AlertDescription.close_notify) { - /* - * RFC 5246 7.2.1. The other party MUST respond with a close_notify alert of its own - * and close down the connection immediately, discarding any pending writes. - */ - if (description == AlertDescription.close_notify) + if (!mAppDataReady) { - if (!mAppDataReady) - { - throw new TlsFatalAlert(AlertDescription.handshake_failure); - } - HandleClose(false); + throw new TlsFatalAlert(AlertDescription.handshake_failure); } - - /* - * If it is just a warning, we continue. - */ - HandleWarningMessage(description); + HandleClose(false); } + + /* + * If it is just a warning, we continue. + */ + HandleWarningMessage(description); } } |