comparison OrthancFramework/Sources/DicomNetworking/Internals/DicomTls.cpp @ 4997:1f93dc290628

fix compatibility with dcmtk 3.6.7
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 May 2022 17:29:58 +0200
parents 43e613a7756b
children 0ea402b4d901
comparison
equal deleted inserted replaced
4996:0f0ada196993 4997:1f93dc290628
43 43
44 namespace Orthanc 44 namespace Orthanc
45 { 45 {
46 namespace Internals 46 namespace Internals
47 { 47 {
48 #if DCMTK_VERSION_NUMBER >= 367
49 static bool IsFailure(OFCondition cond)
50 {
51 return !cond.good();
52 }
53 #else
54 static bool IsFailure(DcmTransportLayerStatus status)
55 {
56 return (status != TCS_ok);
57 }
58 #endif
59
60
48 DcmTLSTransportLayer* InitializeDicomTls(T_ASC_Network *network, 61 DcmTLSTransportLayer* InitializeDicomTls(T_ASC_Network *network,
49 T_ASC_NetworkRole role, 62 T_ASC_NetworkRole role,
50 const std::string& ownPrivateKeyPath, 63 const std::string& ownPrivateKeyPath,
51 const std::string& ownCertificatePath, 64 const std::string& ownCertificatePath,
52 const std::string& trustedCertificatesPath, 65 const std::string& trustedCertificatesPath,
105 118
106 std::unique_ptr<DcmTLSTransportLayer> tls( 119 std::unique_ptr<DcmTLSTransportLayer> tls(
107 new DcmTLSTransportLayer(tmpRole /*opt_networkRole*/, NULL /*opt_readSeedFile*/, 120 new DcmTLSTransportLayer(tmpRole /*opt_networkRole*/, NULL /*opt_readSeedFile*/,
108 OFFalse /*initializeOpenSSL, done by Orthanc::Toolbox::InitializeOpenSsl()*/)); 121 OFFalse /*initializeOpenSSL, done by Orthanc::Toolbox::InitializeOpenSsl()*/));
109 122
110 if (tls->addTrustedCertificateFile(trustedCertificatesPath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/) != TCS_ok) 123 if (IsFailure(tls->addTrustedCertificateFile(trustedCertificatesPath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/)))
111 { 124 {
112 throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse PEM file with trusted certificates for DICOM TLS: " + 125 throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse PEM file with trusted certificates for DICOM TLS: " +
113 trustedCertificatesPath); 126 trustedCertificatesPath);
114 } 127 }
115 128
116 if (tls->setPrivateKeyFile(ownPrivateKeyPath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/) != TCS_ok) 129 if (IsFailure(tls->setPrivateKeyFile(ownPrivateKeyPath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/)))
117 { 130 {
118 throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse PEM file with private key for DICOM TLS: " + 131 throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse PEM file with private key for DICOM TLS: " +
119 ownPrivateKeyPath); 132 ownPrivateKeyPath);
120 } 133 }
121 134
122 if (tls->setCertificateFile(ownCertificatePath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/) != TCS_ok) 135 if (IsFailure(tls->setCertificateFile(ownCertificatePath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/)))
123 { 136 {
124 throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse PEM file with own certificate for DICOM TLS: " + 137 throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse PEM file with own certificate for DICOM TLS: " +
125 ownCertificatePath); 138 ownCertificatePath);
126 } 139 }
127 140
130 throw OrthancException(ErrorCode_BadFileFormat, "The private key doesn't match the own certificate: " + 143 throw OrthancException(ErrorCode_BadFileFormat, "The private key doesn't match the own certificate: " +
131 ownPrivateKeyPath + " vs. " + ownCertificatePath); 144 ownPrivateKeyPath + " vs. " + ownCertificatePath);
132 } 145 }
133 146
134 #if DCMTK_VERSION_NUMBER >= 364 147 #if DCMTK_VERSION_NUMBER >= 364
135 if (tls->setTLSProfile(TSP_Profile_BCP195 /*opt_tlsProfile*/) != TCS_ok) 148 if (IsFailure(tls->setTLSProfile(TSP_Profile_BCP195 /*opt_tlsProfile*/)))
136 { 149 {
137 throw OrthancException(ErrorCode_InternalError, "Cannot set the DICOM TLS profile"); 150 throw OrthancException(ErrorCode_InternalError, "Cannot set the DICOM TLS profile");
138 } 151 }
139 152
140 if (tls->activateCipherSuites()) 153 if (IsFailure(tls->activateCipherSuites()))
141 { 154 {
142 throw OrthancException(ErrorCode_InternalError, "Cannot activate the cipher suites for DICOM TLS"); 155 throw OrthancException(ErrorCode_InternalError, "Cannot activate the cipher suites for DICOM TLS");
143 } 156 }
144 #else 157 #else
145 CLOG(INFO, DICOM) << "Using the following cipher suites for DICOM TLS: " << opt_ciphersuites; 158 CLOG(INFO, DICOM) << "Using the following cipher suites for DICOM TLS: " << opt_ciphersuites;
146 if (tls->setCipherSuites(opt_ciphersuites.c_str()) != TCS_ok) 159 if (IsFailure(tls->setCipherSuites(opt_ciphersuites.c_str())))
147 { 160 {
148 throw OrthancException(ErrorCode_InternalError, "Unable to set cipher suites to: " + opt_ciphersuites); 161 throw OrthancException(ErrorCode_InternalError, "Unable to set cipher suites to: " + opt_ciphersuites);
149 } 162 }
150 #endif 163 #endif
151 164