Mercurial > hg > orthanc-object-storage
annotate Common/EncryptionConfigurator.cpp @ 174:c390539996f4
integration 0.9.3: back to mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 25 Jun 2024 12:09:22 +0200 |
parents | d62f52be1943 |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Cloud storage plugins for Orthanc | |
145
3c7e0374f28e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium |
3c7e0374f28e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
3c7e0374f28e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include <orthanc/OrthancCPlugin.h> | |
23 #include <OrthancPluginCppWrapper.h> | |
24 | |
25 #include "EncryptionConfigurator.h" | |
26 | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
27 #include <Logging.h> |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
28 |
1 | 29 bool ReadMasterKey(uint32_t& id, std::string& keyPath, const Json::Value& node) |
30 { | |
31 if (!node.isArray() || node.size() != 2 || !node[0].isUInt() || !node[1].isString()) | |
32 { | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
33 LOG(WARNING) << "Encryption: Invalid master key configuration"; |
1 | 34 return false; |
35 } | |
36 | |
37 id = node[0].asUInt(); | |
38 keyPath = node[1].asString(); | |
39 | |
40 return true; | |
41 } | |
42 | |
43 | |
44 EncryptionHelpers* EncryptionConfigurator::CreateEncryptionHelpers(const OrthancPlugins::OrthancConfiguration& cryptoSection) | |
45 { | |
46 bool enabled = cryptoSection.GetBooleanValue("Enable", true); | |
47 | |
48 if (!enabled) | |
49 { | |
50 return nullptr; | |
51 } | |
52 | |
53 Json::Value cryptoJson = cryptoSection.GetJson(); | |
54 | |
55 if (!cryptoJson.isMember("MasterKey") || !cryptoJson["MasterKey"].isArray()) | |
56 { | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
57 LOG(WARNING) << "Encryption: MasterKey missing. Unable to initialize encryption"; |
1 | 58 return nullptr; |
59 } | |
60 | |
61 unsigned int maxConcurrentInputSizeInMb = cryptoSection.GetUnsignedIntegerValue("MaxConcurrentInputSize", 1024); | |
62 | |
63 std::unique_ptr<EncryptionHelpers> crypto(new EncryptionHelpers(maxConcurrentInputSizeInMb * 1024*1024)); | |
64 | |
65 uint32_t masterKeyId; | |
66 std::string masterKeyPath; | |
67 | |
68 if (!ReadMasterKey(masterKeyId, masterKeyPath, cryptoJson["MasterKey"])) | |
69 { | |
70 return nullptr; | |
71 } | |
72 crypto->SetCurrentMasterKey(masterKeyId, masterKeyPath); | |
73 | |
74 if (cryptoJson.isMember("PreviousMasterKeys") && cryptoJson["PreviousMasterKeys"].isArray()) | |
75 { | |
76 for (size_t i = 0; i < cryptoJson["PreviousMasterKeys"].size(); i++) | |
77 { | |
78 uint32_t keyId; | |
79 std::string keyPath; | |
80 if (!ReadMasterKey(keyId, keyPath, cryptoJson["PreviousMasterKeys"][(unsigned int)i])) | |
81 { | |
82 return nullptr; | |
83 } | |
84 crypto->AddPreviousMasterKey(keyId, keyPath); | |
85 } | |
86 } | |
87 | |
88 return crypto.release(); | |
89 } |