summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/tls/AbstractTlsPeer.cs4
-rw-r--r--crypto/src/tls/TlsPeer.cs4
-rw-r--r--crypto/src/tls/TlsProtocol.cs2
-rw-r--r--crypto/src/tls/TlsUtilities.cs9
4 files changed, 19 insertions, 0 deletions
diff --git a/crypto/src/tls/AbstractTlsPeer.cs b/crypto/src/tls/AbstractTlsPeer.cs
index 82f8dd1e5..b69acf404 100644
--- a/crypto/src/tls/AbstractTlsPeer.cs
+++ b/crypto/src/tls/AbstractTlsPeer.cs
@@ -148,6 +148,10 @@ namespace Org.BouncyCastle.Tls
         {
         }
 
+        public virtual void NotifyConnectionClosed()
+        {
+        }
+
         /// <exception cref="IOException"/>
         public virtual void NotifyHandshakeComplete()
         {
diff --git a/crypto/src/tls/TlsPeer.cs b/crypto/src/tls/TlsPeer.cs
index 4f16978d9..4d7225aee 100644
--- a/crypto/src/tls/TlsPeer.cs
+++ b/crypto/src/tls/TlsPeer.cs
@@ -109,6 +109,10 @@ namespace Org.BouncyCastle.Tls
         /// <param name="alertDescription"><see cref="AlertDescription"/></param>
         void NotifyAlertReceived(short alertLevel, short alertDescription);
 
+        /// <summary>Notifies the peer that the connection has been closed.</summary>
+        // TODO[api]
+        //void NotifyConnectionClosed();
+
         /// <summary>Notifies the peer that the handshake has been successfully completed.</summary>
         /// <exception cref="IOException"/>
         void NotifyHandshakeComplete();
diff --git a/crypto/src/tls/TlsProtocol.cs b/crypto/src/tls/TlsProtocol.cs
index 55fb9f745..e093ff07a 100644
--- a/crypto/src/tls/TlsProtocol.cs
+++ b/crypto/src/tls/TlsProtocol.cs
@@ -273,6 +273,8 @@ namespace Org.BouncyCastle.Tls
                 RaiseAlertWarning(AlertDescription.close_notify, "Connection closed");
 
                 CloseConnection();
+
+                TlsUtilities.NotifyConnectionClosed(Peer);
             }
         }
 
diff --git a/crypto/src/tls/TlsUtilities.cs b/crypto/src/tls/TlsUtilities.cs
index 69a458a5a..92102e826 100644
--- a/crypto/src/tls/TlsUtilities.cs
+++ b/crypto/src/tls/TlsUtilities.cs
@@ -5730,5 +5730,14 @@ namespace Org.BouncyCastle.Tls
 
             return 1000;
         }
+
+        // TODO[api] Not needed once NotifyConnectionClosed() has been added to TlsPeer
+        internal static void NotifyConnectionClosed(TlsPeer tlsPeer)
+        {
+            if (tlsPeer is AbstractTlsPeer abstractTlsPeer)
+            {
+                abstractTlsPeer.NotifyConnectionClosed();
+            }
+        }
     }
 }