changeset 125:7a3f4d580625

SSL is enabled by default for HTTPS transfers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Feb 2018 17:34:35 +0100
parents 24bd36849c56
children e7c049a61e9a
files Applications/ApplicationToolbox.cpp Applications/ApplicationToolbox.h Applications/CMakeLists.txt Applications/DicomToTiff.cpp Applications/Dicomizer.cpp NEWS
diffstat 6 files changed, 82 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/ApplicationToolbox.cpp	Mon Jan 15 09:36:39 2018 +0100
+++ b/Applications/ApplicationToolbox.cpp	Fri Feb 02 17:34:35 2018 +0100
@@ -235,5 +235,64 @@
 
       LOG(WARNING) << "Orthanc WSI version: " << version;
     }
+
+
+  
+    void AddRestApiOptions(boost::program_options::options_description& section)
+    {
+      section.add_options()
+        ("username", boost::program_options::value<std::string>(), "Username for the target Orthanc server")
+        ("password", boost::program_options::value<std::string>(), "Password for the target Orthanc server")
+        ("proxy", boost::program_options::value<std::string>(), "HTTP proxy to be used")
+        ("timeout", boost::program_options::value<int>()->default_value(0), "HTTP timeout (in seconds, 0 means no timeout)")
+        ("verify-peers", boost::program_options::value<bool>()->default_value(true), "Enable the verification of the peers during HTTPS requests")
+        ("ca-certificates", boost::program_options::value<std::string>()->default_value(""), "Path to the CA (certification authority) certificates to validate peers in HTTPS requests")
+        ;
+    }
+
+
+    void SetupRestApi(Orthanc::WebServiceParameters& parameters,
+                      const boost::program_options::variables_map& options)
+    {
+      if (options.count("orthanc"))
+      {
+        parameters.SetUrl(options["orthanc"].as<std::string>());
+      }
+
+      if (options.count("username") &&
+          options.count("password"))
+      {
+        parameters.SetUsername(options["username"].as<std::string>());
+        parameters.SetPassword(options["password"].as<std::string>());
+      }
+
+      if (options.count("timeout"))
+      {
+        int timeout = options["timeout"].as<int>();
+        if (timeout < 0)
+        {
+          LOG(ERROR) << "Timeouts cannot be negative: " << timeout;
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+        }
+        else
+        {
+          Orthanc::HttpClient::SetDefaultTimeout(timeout);
+        }
+
+        if (options.count("proxy"))
+        {
+          Orthanc::HttpClient::SetDefaultProxy(options["proxy"].as<std::string>());
+        }
+      }
+
+#if ORTHANC_ENABLE_SSL == 1
+      if (options.count("verify-peers") ||
+          options.count("ca-certificates"))
+      {
+        Orthanc::HttpClient::ConfigureSsl(options["verify-peers"].as<bool>(),
+                                          options["ca-certificates"].as<std::string>());
+      }
+#endif
+    }
   }
 }
--- a/Applications/ApplicationToolbox.h	Mon Jan 15 09:36:39 2018 +0100
+++ b/Applications/ApplicationToolbox.h	Fri Feb 02 17:34:35 2018 +0100
@@ -22,9 +22,11 @@
 #pragma once
 
 #include "../Resources/Orthanc/Core/MultiThreading/BagOfTasks.h"
+#include "../Resources/Orthanc/Core/WebServiceParameters.h"
 
 #include <string>
 #include <stdint.h>
+#include <boost/program_options.hpp>
 
 namespace OrthancWSI
 {
@@ -45,5 +47,10 @@
     void PrintVersion(const char* path);
 
     void ShowVersionInLog(const char* path);
+
+    void AddRestApiOptions(boost::program_options::options_description& section);
+
+    void SetupRestApi(Orthanc::WebServiceParameters& parameters,
+                      const boost::program_options::variables_map& options);
   }
 }
--- a/Applications/CMakeLists.txt	Mon Jan 15 09:36:39 2018 +0100
+++ b/Applications/CMakeLists.txt	Fri Feb 02 17:34:35 2018 +0100
@@ -12,7 +12,7 @@
 SET(ENABLE_PROFILING OFF CACHE BOOL "Whether to enable the generation of profiling information with gprof")
 
 # Optional components
-SET(ENABLE_SSL OFF CACHE BOOL "Include support for SSL")
+SET(ENABLE_SSL ON CACHE BOOL "Include support for SSL")
 SET(USE_DCMTK_361 OFF CACHE BOOL "Use forthcoming DCMTK version 3.6.1 in static builds (instead of 3.6.0)")
 
 if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
--- a/Applications/DicomToTiff.cpp	Mon Jan 15 09:36:39 2018 +0100
+++ b/Applications/DicomToTiff.cpp	Fri Feb 02 17:34:35 2018 +0100
@@ -31,8 +31,6 @@
 
 #include "ApplicationToolbox.h"
 
-#include <boost/program_options.hpp>
-
 
 static bool ParseParameters(int& exitStatus,
                             boost::program_options::variables_map& options,
@@ -51,9 +49,8 @@
   source.add_options()
     ("orthanc", boost::program_options::value<std::string>()->default_value("http://localhost:8042/"),
      "URL to the REST API of the target Orthanc server")
-    ("username", boost::program_options::value<std::string>(), "Username for the target Orthanc server")
-    ("password", boost::program_options::value<std::string>(), "Password for the target Orthanc server")
     ;
+  OrthancWSI::ApplicationToolbox::AddRestApiOptions(source);
 
   boost::program_options::options_description target("Options for the target TIFF image");
   target.add_options()
@@ -286,20 +283,7 @@
     {
       Orthanc::WebServiceParameters params;
 
-      if (options.count("orthanc"))
-      {
-        params.SetUrl(options["orthanc"].as<std::string>());
-      }
-
-      if (options.count("username"))
-      {
-        params.SetUsername(options["username"].as<std::string>());
-      }
-
-      if (options.count("password"))
-      {
-        params.SetPassword(options["password"].as<std::string>());
-      }
+      OrthancWSI::ApplicationToolbox::SetupRestApi(params, options);
 
       OrthancPlugins::OrthancHttpConnection orthanc(params);
       OrthancWSI::DicomPyramid source(orthanc, options["input"].as<std::string>(), 
--- a/Applications/Dicomizer.cpp	Mon Jan 15 09:36:39 2018 +0100
+++ b/Applications/Dicomizer.cpp	Fri Feb 02 17:34:35 2018 +0100
@@ -33,7 +33,6 @@
 #include "../Framework/Outputs/TruncatedPyramidWriter.h"
 
 #include "../Resources/Orthanc/Core/DicomParsing/FromDcmtkBridge.h"
-#include "../Resources/Orthanc/Core/HttpClient.h"
 #include "../Resources/Orthanc/Core/Logging.h"
 #include "../Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.h"
 #include "../Resources/Orthanc/Core/OrthancException.h"
@@ -43,8 +42,6 @@
 
 #include <EmbeddedResources.h>
 
-#include <boost/program_options.hpp>
-
 #include <dcmtk/dcmdata/dcdeftag.h>
 #include <dcmtk/dcmdata/dcuid.h>
 #include <dcmtk/dcmdata/dcvrobow.h>
@@ -513,8 +510,6 @@
      "Pattern for the files in the output folder")
     ("orthanc", boost::program_options::value<std::string>()->default_value("http://localhost:8042/"),
      "URL to the REST API of the target Orthanc server")
-    ("username", boost::program_options::value<std::string>(), "Username for the target Orthanc server")
-    ("password", boost::program_options::value<std::string>(), "Password for the target Orthanc server")
     ;
 
   boost::program_options::options_description volumeOptions("Description of the imaged volume");
@@ -528,6 +523,9 @@
      "Y offset the specimen, wrt. slide coordinates origin (in mm)")
     ;
 
+  boost::program_options::options_description restOptions("HTTP/HTTPS client configuration to access the Orthanc REST API");
+  OrthancWSI::ApplicationToolbox::AddRestApiOptions(restOptions);
+
   boost::program_options::options_description advancedOptions("Advanced options");
   advancedOptions.add_options()
     ("optical-path", boost::program_options::value<std::string>()->default_value("brightfield"), 
@@ -546,7 +544,14 @@
   ;
 
   boost::program_options::options_description allWithoutHidden;
-  allWithoutHidden.add(generic).add(source).add(pyramid).add(target).add(volumeOptions).add(advancedOptions);
+  allWithoutHidden
+    .add(generic)
+    .add(source)
+    .add(pyramid)
+    .add(target)
+    .add(volumeOptions)
+    .add(restOptions)
+    .add(advancedOptions);
 
   boost::program_options::options_description all = allWithoutHidden;
   all.add(hidden);
@@ -745,17 +750,7 @@
     parameters.SetTargetFolderPattern(options["folder-pattern"].as<std::string>());
   }
 
-  if (options.count("orthanc"))
-  {
-    parameters.GetOrthancParameters().SetUrl(options["orthanc"].as<std::string>());
-
-    if (options.count("username") &&
-        options.count("password"))
-    {
-      parameters.GetOrthancParameters().SetUsername(options["username"].as<std::string>());
-      parameters.GetOrthancParameters().SetPassword(options["password"].as<std::string>());
-    }
-  }
+  OrthancWSI::ApplicationToolbox::SetupRestApi(parameters.GetOrthancParameters(), options);
 
   if (options.count("dataset"))
   {
--- a/NEWS	Mon Jan 15 09:36:39 2018 +0100
+++ b/NEWS	Fri Feb 02 17:34:35 2018 +0100
@@ -3,6 +3,7 @@
 
 * "--max-size=0" allowed to create a single instance per pyramid level
 * Support more colorspaces with JPEG2k
+* SSL is enabled by default for HTTPS transfers
 * Fix Debian #876807 (orthanc-wsi FTBFS with libopenjp2-7-dev 2.2.0-1)
 * Support of OpenBSD and FreeBSD
 * Support of Linux Standard Base