diff OrthancFramework/Sources/DicomNetworking/DicomAssociation.cpp @ 4432:fcbac3e8ac1c

dicom tls for scu
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Jan 2021 15:59:32 +0100
parents 5b254bd435d3
children 4f92f2b3a3ae
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomNetworking/DicomAssociation.cpp	Mon Jan 04 14:34:44 2021 +0100
+++ b/OrthancFramework/Sources/DicomNetworking/DicomAssociation.cpp	Mon Jan 04 15:59:32 2021 +0100
@@ -116,6 +116,10 @@
     
   void DicomAssociation::CloseInternal()
   {
+#if ORTHANC_ENABLE_SSL == 1
+    tls_.reset(NULL);  // Transport layer must be destroyed before the association itself
+#endif
+    
     if (assoc_ != NULL)
     {
       ASC_releaseAssociation(assoc_);
@@ -249,7 +253,8 @@
 
     assert(net_ == NULL &&
            params_ == NULL &&
-           assoc_ == NULL);
+           assoc_ == NULL &&
+           tls_.get() == NULL);
 
     if (proposed_.empty())
     {
@@ -267,6 +272,26 @@
     CheckConnecting(parameters, ASC_initializeNetwork(NET_REQUESTOR, 0, /*opt_acse_timeout*/ acseTimeout, &net_));
     CheckConnecting(parameters, ASC_createAssociationParameters(&params_, /*opt_maxReceivePDULength*/ ASC_DEFAULTMAXPDU));
 
+#if ORTHANC_ENABLE_SSL == 1
+    if (false)   // TODO - Configuration option
+    {
+      try
+      {
+        assert(net_ != NULL &&
+               params_ != NULL);
+        
+        // TODO - Configuration options
+        tls_.reset(Internals::InitializeDicomTls(net_, NET_REQUESTOR,
+                                                 "/tmp/j/Client.key", "/tmp/j/Client.crt", "/tmp/j/Server.crt"));
+      }
+      catch (OrthancException&)
+      {
+        CloseInternal();
+        throw;
+      }
+    }
+#endif
+
     // Set this application's title and the called application's title in the params
     CheckConnecting(parameters, ASC_setAPTitles(
                       params_, parameters.GetLocalApplicationEntityTitle().c_str(),
@@ -290,7 +315,7 @@
     CheckConnecting(parameters, ASC_setPresentationAddresses(params_, localHost, remoteHostAndPort));
 
     // Set various options
-    CheckConnecting(parameters, ASC_setTransportLayerType(params_, /*opt_secureConnection*/ false));
+    CheckConnecting(parameters, ASC_setTransportLayerType(params_, (tls_.get() != NULL) /*opt_secureConnection*/));
 
     // Setup the list of proposed presentation contexts
     unsigned int presentationContextId = 1;