summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/crypto/tls/TlsException.cs14
-rw-r--r--crypto/src/crypto/tls/TlsFatalAlert.cs3
-rw-r--r--crypto/src/crypto/tls/TlsFatalAlertReceived.cs21
-rw-r--r--crypto/src/crypto/tls/TlsProtocol.cs32
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); } }