Mercurial > hg > orthanc-gcp
comparison Plugin/GoogleUpdater.cpp @ 16:25292488ff8f
using option HttpsVerifyPeers from Orthanc configuration
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 26 Jun 2019 11:29:25 +0200 |
parents | 520cba9a0d42 |
children | 2514880d4f0b |
comparison
equal
deleted
inserted
replaced
15:11368fbbce2a | 16:25292488ff8f |
---|---|
52 | 52 |
53 const GoogleConfiguration& configuration = GoogleConfiguration::GetInstance(); | 53 const GoogleConfiguration& configuration = GoogleConfiguration::GetInstance(); |
54 | 54 |
55 long timeout = static_cast<long>(configuration.GetTimeoutSeconds()); | 55 long timeout = static_cast<long>(configuration.GetTimeoutSeconds()); |
56 | 56 |
57 if ((!configuration.GetCaInfo().empty() && | 57 if (!configuration.GetCaInfo().empty() && |
58 curl_easy_setopt(handle.get(), CURLOPT_CAINFO, configuration.GetCaInfo().c_str()) != CURLE_OK) || | 58 curl_easy_setopt(handle.get(), CURLOPT_CAINFO, configuration.GetCaInfo().c_str()) != CURLE_OK) |
59 curl_easy_setopt(handle.get(), CURLOPT_SSL_VERIFYHOST, 2) != CURLE_OK || | 59 { |
60 curl_easy_setopt(handle.get(), CURLOPT_SSL_VERIFYPEER, 1) != CURLE_OK || | 60 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, |
61 curl_easy_setopt(handle.get(), CURLOPT_TIMEOUT, timeout) != CURLE_OK) | 61 "Cannot set the trusted Certificate Authorities"); |
62 } | |
63 | |
64 bool ok; | |
65 | |
66 if (configuration.IsHttpsVerifyPeers()) | |
67 { | |
68 ok = (curl_easy_setopt(handle.get(), CURLOPT_SSL_VERIFYHOST, 2) == CURLE_OK && | |
69 curl_easy_setopt(handle.get(), CURLOPT_SSL_VERIFYPEER, 1) == CURLE_OK && | |
70 curl_easy_setopt(handle.get(), CURLOPT_TIMEOUT, timeout) == CURLE_OK); | |
71 } | |
72 else | |
73 { | |
74 ok = (curl_easy_setopt(handle.get(), CURLOPT_SSL_VERIFYHOST, 0) == CURLE_OK && | |
75 curl_easy_setopt(handle.get(), CURLOPT_SSL_VERIFYPEER, 0) == CURLE_OK); | |
76 } | |
77 | |
78 if (!ok) | |
62 { | 79 { |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, | 80 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, |
64 "Cannot initialize a libcurl handle"); | 81 "Cannot initialize a libcurl handle"); |
65 } | 82 } |
66 | 83 |
94 const GoogleAccount* account, | 111 const GoogleAccount* account, |
95 long refreshIntervalSeconds) | 112 long refreshIntervalSeconds) |
96 { | 113 { |
97 std::shared_ptr<google::cloud::storage::oauth2::Credentials> credentials; | 114 std::shared_ptr<google::cloud::storage::oauth2::Credentials> credentials; |
98 | 115 |
99 switch (account->GetType()) | 116 try |
100 { | 117 { |
101 case GoogleAccount::Type_ServiceAccount: | 118 switch (account->GetType()) |
102 credentials = std::make_shared<google::cloud::storage::oauth2::ServiceAccountCredentials | 119 { |
103 <CurlBuilder>>(account->GetServiceAccount()); | 120 case GoogleAccount::Type_ServiceAccount: |
104 break; | 121 credentials = std::make_shared<google::cloud::storage::oauth2::ServiceAccountCredentials |
105 | 122 <CurlBuilder>>(account->GetServiceAccount()); |
106 case GoogleAccount::Type_AuthorizedUser: | 123 break; |
107 credentials = std::make_shared<google::cloud::storage::oauth2::AuthorizedUserCredentials | 124 |
108 <CurlBuilder>>(account->GetAuthorizedUser()); | 125 case GoogleAccount::Type_AuthorizedUser: |
109 break; | 126 credentials = std::make_shared<google::cloud::storage::oauth2::AuthorizedUserCredentials |
110 | 127 <CurlBuilder>>(account->GetAuthorizedUser()); |
111 default: | 128 break; |
112 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 129 |
130 default: | |
131 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
132 } | |
133 } | |
134 catch (Orthanc::OrthancException& e) | |
135 { | |
136 credentials.reset(); | |
113 } | 137 } |
114 | 138 |
115 if (credentials.get() == NULL) | 139 if (credentials.get() == NULL) |
116 { | 140 { |
117 LOG(ERROR) << "Cannot initialize the token updater for Google Cloud Platform account: " | 141 LOG(ERROR) << "Cannot initialize the token updater for Google Cloud Platform account: " |