comparison OrthancFramework/Sources/DicomNetworking/DicomAssociationParameters.cpp @ 4656:82a314325351

New configuration option: "DicomTlsRemoteCertificateRequired"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 May 2021 18:39:19 +0200
parents cb8fcecf1b02
children 7053502fbf97
comparison
equal deleted inserted replaced
4655:9f7eef20bc7d 4656:82a314325351
39 static uint32_t defaultTimeout_ = 10; 39 static uint32_t defaultTimeout_ = 10;
40 static std::string defaultOwnPrivateKeyPath_; 40 static std::string defaultOwnPrivateKeyPath_;
41 static std::string defaultOwnCertificatePath_; 41 static std::string defaultOwnCertificatePath_;
42 static std::string defaultTrustedCertificatesPath_; 42 static std::string defaultTrustedCertificatesPath_;
43 static unsigned int defaultMaximumPduLength_ = ASC_DEFAULTMAXPDU; 43 static unsigned int defaultMaximumPduLength_ = ASC_DEFAULTMAXPDU;
44 static bool defaultRemoteCertificateRequired_ = true;
44 45
45 46
46 namespace Orthanc 47 namespace Orthanc
47 { 48 {
48 void DicomAssociationParameters::CheckHost(const std::string& host) 49 void DicomAssociationParameters::CheckHost(const std::string& host)
68 timeout_ = defaultTimeout_; 69 timeout_ = defaultTimeout_;
69 ownPrivateKeyPath_ = defaultOwnPrivateKeyPath_; 70 ownPrivateKeyPath_ = defaultOwnPrivateKeyPath_;
70 ownCertificatePath_ = defaultOwnCertificatePath_; 71 ownCertificatePath_ = defaultOwnCertificatePath_;
71 trustedCertificatesPath_ = defaultTrustedCertificatesPath_; 72 trustedCertificatesPath_ = defaultTrustedCertificatesPath_;
72 maximumPduLength_ = defaultMaximumPduLength_; 73 maximumPduLength_ = defaultMaximumPduLength_;
74 remoteCertificateRequired_ = defaultRemoteCertificateRequired_;
73 } 75 }
74 76
75 77
76 DicomAssociationParameters::DicomAssociationParameters() : 78 DicomAssociationParameters::DicomAssociationParameters() :
77 localAet_("ORTHANC"), 79 localAet_("ORTHANC"),
235 void DicomAssociationParameters::SetMaximumPduLength(unsigned int pdu) 237 void DicomAssociationParameters::SetMaximumPduLength(unsigned int pdu)
236 { 238 {
237 CheckMaximumPduLength(pdu); 239 CheckMaximumPduLength(pdu);
238 maximumPduLength_ = pdu; 240 maximumPduLength_ = pdu;
239 } 241 }
240 242
243 void DicomAssociationParameters::SetRemoteCertificateRequired(bool required)
244 {
245 remoteCertificateRequired_ = required;
246 }
247
248 bool DicomAssociationParameters::IsRemoteCertificateRequired() const
249 {
250 return remoteCertificateRequired_;
251 }
252
241 253
242 254
243 static const char* const LOCAL_AET = "LocalAet"; 255 static const char* const LOCAL_AET = "LocalAet";
244 static const char* const REMOTE = "Remote"; 256 static const char* const REMOTE = "Remote";
245 static const char* const TIMEOUT = "Timeout"; // New in Orthanc in 1.7.0 257 static const char* const TIMEOUT = "Timeout"; // New in Orthanc in 1.7.0
246 static const char* const OWN_PRIVATE_KEY = "OwnPrivateKey"; // New in Orthanc 1.9.0 258 static const char* const OWN_PRIVATE_KEY = "OwnPrivateKey"; // New in Orthanc 1.9.0
247 static const char* const OWN_CERTIFICATE = "OwnCertificate"; // New in Orthanc 1.9.0 259 static const char* const OWN_CERTIFICATE = "OwnCertificate"; // New in Orthanc 1.9.0
248 static const char* const TRUSTED_CERTIFICATES = "TrustedCertificates"; // New in Orthanc 1.9.0 260 static const char* const TRUSTED_CERTIFICATES = "TrustedCertificates"; // New in Orthanc 1.9.0
249 static const char* const MAXIMUM_PDU_LENGTH = "MaximumPduLength"; // New in Orthanc 1.9.0 261 static const char* const MAXIMUM_PDU_LENGTH = "MaximumPduLength"; // New in Orthanc 1.9.0
262 static const char* const REMOTE_CERTIFICATE_REQUIRED = "RemoteCertificateRequired"; // New in Orthanc 1.9.3
250 263
251 264
252 void DicomAssociationParameters::SerializeJob(Json::Value& target) const 265 void DicomAssociationParameters::SerializeJob(Json::Value& target) const
253 { 266 {
254 if (target.type() != Json::objectValue) 267 if (target.type() != Json::objectValue)
259 { 272 {
260 target[LOCAL_AET] = localAet_; 273 target[LOCAL_AET] = localAet_;
261 remote_.Serialize(target[REMOTE], true /* force advanced format */); 274 remote_.Serialize(target[REMOTE], true /* force advanced format */);
262 target[TIMEOUT] = timeout_; 275 target[TIMEOUT] = timeout_;
263 target[MAXIMUM_PDU_LENGTH] = maximumPduLength_; 276 target[MAXIMUM_PDU_LENGTH] = maximumPduLength_;
277 target[REMOTE_CERTIFICATE_REQUIRED] = remoteCertificateRequired_;
264 278
265 // Don't write the DICOM TLS parameters if they are not required 279 // Don't write the DICOM TLS parameters if they are not required
266 if (ownPrivateKeyPath_.empty()) 280 if (ownPrivateKeyPath_.empty())
267 { 281 {
268 target.removeMember(OWN_PRIVATE_KEY); 282 target.removeMember(OWN_PRIVATE_KEY);
339 } 353 }
340 else 354 else
341 { 355 {
342 result.trustedCertificatesPath_.clear(); 356 result.trustedCertificatesPath_.clear();
343 } 357 }
358
359 if (serialized.isMember(REMOTE_CERTIFICATE_REQUIRED))
360 {
361 result.remoteCertificateRequired_ = SerializationToolbox::ReadBoolean(serialized, REMOTE_CERTIFICATE_REQUIRED);
362 }
344 363
345 return result; 364 return result;
346 } 365 }
347 else 366 else
348 { 367 {
462 unsigned int DicomAssociationParameters::GetDefaultMaximumPduLength() 481 unsigned int DicomAssociationParameters::GetDefaultMaximumPduLength()
463 { 482 {
464 boost::mutex::scoped_lock lock(defaultConfigurationMutex_); 483 boost::mutex::scoped_lock lock(defaultConfigurationMutex_);
465 return defaultMaximumPduLength_; 484 return defaultMaximumPduLength_;
466 } 485 }
486
487
488 void DicomAssociationParameters::SetDefaultRemoteCertificateRequired(bool required)
489 {
490 boost::mutex::scoped_lock lock(defaultConfigurationMutex_);
491 defaultRemoteCertificateRequired_ = required;
492 }
493
494
495 bool DicomAssociationParameters::GetDefaultRemoteCertificateRequired()
496 {
497 boost::mutex::scoped_lock lock(defaultConfigurationMutex_);
498 return defaultRemoteCertificateRequired_;
499 }
467 } 500 }