summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Portable.BouncyCastle.nuspec3
-rw-r--r--crypto/BouncyCastle.Android.csproj1
-rw-r--r--crypto/BouncyCastle.csproj3
-rw-r--r--crypto/BouncyCastle.iOS.csproj1
-rw-r--r--crypto/crypto.csproj5
-rw-r--r--crypto/src/crypto/tls/DtlsRecordLayer.cs27
-rw-r--r--crypto/src/crypto/tls/DtlsTransport.cs38
-rw-r--r--crypto/src/crypto/tls/TlsException.cs10
-rw-r--r--crypto/src/crypto/tls/TlsTimeoutException.cs23
-rw-r--r--crypto/src/crypto/tls/TlsUtilities.cs11
-rw-r--r--crypto/test/UnitTests.csproj2
11 files changed, 93 insertions, 31 deletions
diff --git a/Portable.BouncyCastle.nuspec b/Portable.BouncyCastle.nuspec
index c58a23a80..ece85f9d1 100644
--- a/Portable.BouncyCastle.nuspec
+++ b/Portable.BouncyCastle.nuspec
@@ -42,6 +42,7 @@
         <dependency id="System.IO.FileSystem" version="4.0.0" />
         <dependency id="System.IO.FileSystem.Primitives" version="4.0.0" />
         <dependency id="System.Linq" version="4.0.0" />
+        <dependency id="System.Net.Primitives" version="4.0.10" />
         <dependency id="System.Reflection" version="4.0.10" />
         <dependency id="System.Reflection.Extensions" version="4.0.0" />
         <dependency id="System.Runtime" version="4.0.20" />
@@ -58,6 +59,7 @@
         <dependency id="System.IO.FileSystem" version="4.0.0" />
         <dependency id="System.IO.FileSystem.Primitives" version="4.0.0" />
         <dependency id="System.Linq" version="4.0.0" />
+        <dependency id="System.Net.Primitives" version="4.0.10" />
         <dependency id="System.Reflection" version="4.0.10" />
         <dependency id="System.Reflection.Extensions" version="4.0.0" />
         <dependency id="System.Runtime" version="4.0.20" />
@@ -74,6 +76,7 @@
         <dependency id="System.IO.FileSystem" version="4.0.0" />
         <dependency id="System.IO.FileSystem.Primitives" version="4.0.0" />
         <dependency id="System.Linq" version="4.0.0" />
+        <dependency id="System.Net.Primitives" version="4.0.10" />
         <dependency id="System.Reflection" version="4.0.10" />
         <dependency id="System.Reflection.Extensions" version="4.0.0" />
         <dependency id="System.Runtime" version="4.0.20" />
diff --git a/crypto/BouncyCastle.Android.csproj b/crypto/BouncyCastle.Android.csproj
index 0f15e30ab..592dcc977 100644
--- a/crypto/BouncyCastle.Android.csproj
+++ b/crypto/BouncyCastle.Android.csproj
@@ -1233,6 +1233,7 @@
     <Compile Include="src\crypto\tls\TlsSrtpUtilities.cs" />
     <Compile Include="src\crypto\tls\TlsStream.cs" />
     <Compile Include="src\crypto\tls\TlsStreamCipher.cs" />
+    <Compile Include="src\crypto\tls\TlsTimeoutException.cs" />
     <Compile Include="src\crypto\tls\TlsUtilities.cs" />
     <Compile Include="src\crypto\tls\UrlAndHash.cs" />
     <Compile Include="src\crypto\tls\UseSrtpData.cs" />
diff --git a/crypto/BouncyCastle.csproj b/crypto/BouncyCastle.csproj
index f7a15d49f..26db97e1b 100644
--- a/crypto/BouncyCastle.csproj
+++ b/crypto/BouncyCastle.csproj
@@ -1227,6 +1227,7 @@
     <Compile Include="src\crypto\tls\TlsSrtpUtilities.cs" />
     <Compile Include="src\crypto\tls\TlsStream.cs" />
     <Compile Include="src\crypto\tls\TlsStreamCipher.cs" />
+    <Compile Include="src\crypto\tls\TlsTimeoutException.cs" />
     <Compile Include="src\crypto\tls\TlsUtilities.cs" />
     <Compile Include="src\crypto\tls\UrlAndHash.cs" />
     <Compile Include="src\crypto\tls\UseSrtpData.cs" />
@@ -1683,4 +1684,4 @@
     <None Include="checklist.txt" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-</Project>
+</Project>
\ No newline at end of file
diff --git a/crypto/BouncyCastle.iOS.csproj b/crypto/BouncyCastle.iOS.csproj
index 64bb4fdf9..17fe3dda5 100644
--- a/crypto/BouncyCastle.iOS.csproj
+++ b/crypto/BouncyCastle.iOS.csproj
@@ -1228,6 +1228,7 @@
     <Compile Include="src\crypto\tls\TlsSrtpUtilities.cs" />
     <Compile Include="src\crypto\tls\TlsStream.cs" />
     <Compile Include="src\crypto\tls\TlsStreamCipher.cs" />
+    <Compile Include="src\crypto\tls\TlsTimeoutException.cs" />
     <Compile Include="src\crypto\tls\TlsUtilities.cs" />
     <Compile Include="src\crypto\tls\UrlAndHash.cs" />
     <Compile Include="src\crypto\tls\UseSrtpData.cs" />
diff --git a/crypto/crypto.csproj b/crypto/crypto.csproj
index ca67f3487..1ba78a83c 100644
--- a/crypto/crypto.csproj
+++ b/crypto/crypto.csproj
@@ -6024,6 +6024,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "src\crypto\tls\TlsTimeoutException.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "src\crypto\tls\TlsUtilities.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
diff --git a/crypto/src/crypto/tls/DtlsRecordLayer.cs b/crypto/src/crypto/tls/DtlsRecordLayer.cs
index 5f3ec9e9c..69870dd91 100644
--- a/crypto/src/crypto/tls/DtlsRecordLayer.cs
+++ b/crypto/src/crypto/tls/DtlsRecordLayer.cs
@@ -1,6 +1,8 @@
 using System;
 using System.IO;
+#if !PORTABLE || DOTNET
 using System.Net.Sockets;
+#endif
 
 using Org.BouncyCastle.Utilities.Date;
 
@@ -312,24 +314,15 @@ namespace Org.BouncyCastle.Crypto.Tls
 
         private int ReceiveDatagram(byte[] buf, int off, int len, int waitMillis)
         {
-            //try
-            //{
-            //    return mTransport.Receive(buf, off, len, waitMillis);
-            //}
-            //catch (SocketTimeoutException e)
-            //{
-            //    return -1;
-            //}
-            //catch (InterruptedIOException e)
-            //{
-            //    e.bytesTransferred = 0;
-            //    throw e;
-            //}
-
             try
             {
                 return mTransport.Receive(buf, off, len, waitMillis);
             }
+            catch (TlsTimeoutException)
+            {
+                return -1;
+            }
+#if !PORTABLE || DOTNET
             catch (SocketException e)
             {
                 if (TlsUtilities.IsTimeout(e))
@@ -337,6 +330,12 @@ namespace Org.BouncyCastle.Crypto.Tls
 
                 throw e;
             }
+#endif
+            //catch (InterruptedIOException e)
+            //{
+            //    e.bytesTransferred = 0;
+            //    throw e;
+            //}
         }
 
         private int ProcessRecord(int received, byte[] record, byte[] buf, int off)
diff --git a/crypto/src/crypto/tls/DtlsTransport.cs b/crypto/src/crypto/tls/DtlsTransport.cs
index bc09707c1..f2f716561 100644
--- a/crypto/src/crypto/tls/DtlsTransport.cs
+++ b/crypto/src/crypto/tls/DtlsTransport.cs
@@ -1,6 +1,8 @@
 using System;
 using System.IO;
+#if !PORTABLE || DOTNET
 using System.Net.Sockets;
+#endif
 
 namespace Org.BouncyCastle.Crypto.Tls
 {
@@ -44,15 +46,11 @@ namespace Org.BouncyCastle.Crypto.Tls
                 mRecordLayer.Fail(fatalAlert.AlertDescription);
                 throw fatalAlert;
             }
-            //catch (InterruptedIOException e)
-            //{
-            //    throw e;
-            //}
-            catch (IOException e)
+            catch (TlsTimeoutException e)
             {
-                mRecordLayer.Fail(AlertDescription.internal_error);
                 throw e;
             }
+#if !PORTABLE || DOTNET
             catch (SocketException e)
             {
                 if (TlsUtilities.IsTimeout(e))
@@ -61,6 +59,16 @@ namespace Org.BouncyCastle.Crypto.Tls
                 mRecordLayer.Fail(AlertDescription.internal_error);
                 throw new TlsFatalAlert(AlertDescription.internal_error, e);
             }
+#endif
+            //catch (InterruptedIOException e)
+            //{
+            //    throw e;
+            //}
+            catch (IOException e)
+            {
+                mRecordLayer.Fail(AlertDescription.internal_error);
+                throw e;
+            }
             catch (Exception e)
             {
                 mRecordLayer.Fail(AlertDescription.internal_error);
@@ -86,15 +94,11 @@ namespace Org.BouncyCastle.Crypto.Tls
                 mRecordLayer.Fail(fatalAlert.AlertDescription);
                 throw fatalAlert;
             }
-            //catch (InterruptedIOException e)
-            //{
-            //    throw e;
-            //}
-            catch (IOException e)
+            catch (TlsTimeoutException e)
             {
-                mRecordLayer.Fail(AlertDescription.internal_error);
                 throw e;
             }
+#if !PORTABLE || DOTNET
             catch (SocketException e)
             {
                 if (TlsUtilities.IsTimeout(e))
@@ -103,6 +107,16 @@ namespace Org.BouncyCastle.Crypto.Tls
                 mRecordLayer.Fail(AlertDescription.internal_error);
                 throw new TlsFatalAlert(AlertDescription.internal_error, e);
             }
+#endif
+            //catch (InterruptedIOException e)
+            //{
+            //    throw e;
+            //}
+            catch (IOException e)
+            {
+                mRecordLayer.Fail(AlertDescription.internal_error);
+                throw e;
+            }
             catch (Exception e)
             {
                 mRecordLayer.Fail(AlertDescription.internal_error);
diff --git a/crypto/src/crypto/tls/TlsException.cs b/crypto/src/crypto/tls/TlsException.cs
index cea9e3e77..18ca22a58 100644
--- a/crypto/src/crypto/tls/TlsException.cs
+++ b/crypto/src/crypto/tls/TlsException.cs
@@ -6,6 +6,16 @@ namespace Org.BouncyCastle.Crypto.Tls
     public class TlsException
         : IOException
     {
+        public TlsException()
+            : base()
+        {
+        }
+
+        public TlsException(string message)
+            : base(message)
+        {
+        }
+
         public TlsException(string message, Exception cause)
             : base(message, cause)
         {
diff --git a/crypto/src/crypto/tls/TlsTimeoutException.cs b/crypto/src/crypto/tls/TlsTimeoutException.cs
new file mode 100644
index 000000000..71931e43d
--- /dev/null
+++ b/crypto/src/crypto/tls/TlsTimeoutException.cs
@@ -0,0 +1,23 @@
+using System;
+
+namespace Org.BouncyCastle.Crypto.Tls
+{
+    public class TlsTimeoutException
+        : TlsException
+    {
+        public TlsTimeoutException()
+            : base()
+        {
+        }
+
+        public TlsTimeoutException(string message)
+            : base(message)
+        {
+        }
+
+        public TlsTimeoutException(string message, Exception cause)
+            : base(message, cause)
+        {
+        }
+    }
+}
diff --git a/crypto/src/crypto/tls/TlsUtilities.cs b/crypto/src/crypto/tls/TlsUtilities.cs
index 5aad6b0a1..2fb631edd 100644
--- a/crypto/src/crypto/tls/TlsUtilities.cs
+++ b/crypto/src/crypto/tls/TlsUtilities.cs
@@ -1,8 +1,9 @@
 using System;
 using System.Collections;
+#if !PORTABLE || DOTNET
 using System.Net.Sockets;
+#endif
 using System.IO;
-using System.Text;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Nist;
@@ -2347,11 +2348,15 @@ namespace Org.BouncyCastle.Crypto.Tls
             return v;
         }
 
+#if !PORTABLE || DOTNET
         public static bool IsTimeout(SocketException e)
         {
-            // TODO Net 2.0+
-            //return SocketError.TimedOut == e.SocketErrorCode;
+#if NET_1_1
             return 10060 == e.ErrorCode;
+#else
+            return SocketError.TimedOut == e.SocketErrorCode;
+#endif
         }
+#endif
     }
 }
diff --git a/crypto/test/UnitTests.csproj b/crypto/test/UnitTests.csproj
index 404eb6ca1..0c0184d42 100644
--- a/crypto/test/UnitTests.csproj
+++ b/crypto/test/UnitTests.csproj
@@ -1397,4 +1397,4 @@
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file