summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2017-06-07 14:40:24 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2017-06-07 14:40:24 +0700
commit4589defc7197db8d49edc67a354a34ce2ce5928b (patch)
treeb8ab75548954efddcde4a406ecec360566934214 /crypto
parentFix paths for previous commit (diff)
downloadBouncyCastle.NET-ed25519-4589defc7197db8d49edc67a354a34ce2ce5928b.tar.xz
Specific exception TlsFatalAlertReceived for peer fatal alerts
Diffstat (limited to 'crypto')
-rw-r--r--crypto/BouncyCastle.Android.csproj2
-rw-r--r--crypto/BouncyCastle.csproj2
-rw-r--r--crypto/BouncyCastle.iOS.csproj2
-rw-r--r--crypto/crypto.csproj10
-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
8 files changed, 67 insertions, 19 deletions
diff --git a/crypto/BouncyCastle.Android.csproj b/crypto/BouncyCastle.Android.csproj
index ca279bf25..921331f9a 100644
--- a/crypto/BouncyCastle.Android.csproj
+++ b/crypto/BouncyCastle.Android.csproj
@@ -1064,8 +1064,10 @@
     <Compile Include="src\crypto\tls\TlsECDsaSigner.cs" />
     <Compile Include="src\crypto\tls\TlsEccUtilities.cs" />
     <Compile Include="src\crypto\tls\TlsEncryptionCredentials.cs" />
+    <Compile Include="src\crypto\tls\TlsException.cs" />
     <Compile Include="src\crypto\tls\TlsExtensionsUtilities.cs" />
     <Compile Include="src\crypto\tls\TlsFatalAlert.cs" />
+    <Compile Include="src\crypto\tls\TlsFatalAlertReceived.cs" />
     <Compile Include="src\crypto\tls\TlsHandshakeHash.cs" />
     <Compile Include="src\crypto\tls\TlsKeyExchange.cs" />
     <Compile Include="src\crypto\tls\TlsMac.cs" />
diff --git a/crypto/BouncyCastle.csproj b/crypto/BouncyCastle.csproj
index 387dd0835..ed2ce50ad 100644
--- a/crypto/BouncyCastle.csproj
+++ b/crypto/BouncyCastle.csproj
@@ -1058,8 +1058,10 @@
     <Compile Include="src\crypto\tls\TlsECDsaSigner.cs" />
     <Compile Include="src\crypto\tls\TlsEccUtilities.cs" />
     <Compile Include="src\crypto\tls\TlsEncryptionCredentials.cs" />
+    <Compile Include="src\crypto\tls\TlsException.cs" />
     <Compile Include="src\crypto\tls\TlsExtensionsUtilities.cs" />
     <Compile Include="src\crypto\tls\TlsFatalAlert.cs" />
+    <Compile Include="src\crypto\tls\TlsFatalAlertReceived.cs" />
     <Compile Include="src\crypto\tls\TlsHandshakeHash.cs" />
     <Compile Include="src\crypto\tls\TlsKeyExchange.cs" />
     <Compile Include="src\crypto\tls\TlsMac.cs" />
diff --git a/crypto/BouncyCastle.iOS.csproj b/crypto/BouncyCastle.iOS.csproj
index fb15014e3..8d5d3032f 100644
--- a/crypto/BouncyCastle.iOS.csproj
+++ b/crypto/BouncyCastle.iOS.csproj
@@ -1059,8 +1059,10 @@
     <Compile Include="src\crypto\tls\TlsECDsaSigner.cs" />
     <Compile Include="src\crypto\tls\TlsEccUtilities.cs" />
     <Compile Include="src\crypto\tls\TlsEncryptionCredentials.cs" />
+    <Compile Include="src\crypto\tls\TlsException.cs" />
     <Compile Include="src\crypto\tls\TlsExtensionsUtilities.cs" />
     <Compile Include="src\crypto\tls\TlsFatalAlert.cs" />
+    <Compile Include="src\crypto\tls\TlsFatalAlertReceived.cs" />
     <Compile Include="src\crypto\tls\TlsHandshakeHash.cs" />
     <Compile Include="src\crypto\tls\TlsKeyExchange.cs" />
     <Compile Include="src\crypto\tls\TlsMac.cs" />
diff --git a/crypto/crypto.csproj b/crypto/crypto.csproj
index ab7413788..026a2fe1b 100644
--- a/crypto/crypto.csproj
+++ b/crypto/crypto.csproj
@@ -5179,6 +5179,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "src\crypto\tls\TlsException.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "src\crypto\tls\TlsExtensionsUtilities.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
@@ -5189,6 +5194,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "src\crypto\tls\TlsFatalAlertReceived.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "src\crypto\tls\TlsHandshakeHash.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
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);
             }
         }