Mercurial > hg > orthanc-object-storage
annotate Common/EncryptionConfigurator.cpp @ 145:3c7e0374f28e
updated copyright, as Orthanc Team now replaces Osimis
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 22:35:35 +0200 |
parents | b922ae86bbe1 |
children | d62f52be1943 |
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 | |
27 bool ReadMasterKey(uint32_t& id, std::string& keyPath, const Json::Value& node) | |
28 { | |
29 if (!node.isArray() || node.size() != 2 || !node[0].isUInt() || !node[1].isString()) | |
30 { | |
31 OrthancPlugins::LogWarning("Encryption: Invalid master key configuration"); | |
32 return false; | |
33 } | |
34 | |
35 id = node[0].asUInt(); | |
36 keyPath = node[1].asString(); | |
37 | |
38 return true; | |
39 } | |
40 | |
41 | |
42 EncryptionHelpers* EncryptionConfigurator::CreateEncryptionHelpers(const OrthancPlugins::OrthancConfiguration& cryptoSection) | |
43 { | |
44 bool enabled = cryptoSection.GetBooleanValue("Enable", true); | |
45 | |
46 if (!enabled) | |
47 { | |
48 return nullptr; | |
49 } | |
50 | |
51 Json::Value cryptoJson = cryptoSection.GetJson(); | |
52 | |
53 if (!cryptoJson.isMember("MasterKey") || !cryptoJson["MasterKey"].isArray()) | |
54 { | |
55 OrthancPlugins::LogWarning("Encryption: MasterKey missing. Unable to initialize encryption"); | |
56 return nullptr; | |
57 } | |
58 | |
59 unsigned int maxConcurrentInputSizeInMb = cryptoSection.GetUnsignedIntegerValue("MaxConcurrentInputSize", 1024); | |
60 | |
61 std::unique_ptr<EncryptionHelpers> crypto(new EncryptionHelpers(maxConcurrentInputSizeInMb * 1024*1024)); | |
62 | |
63 uint32_t masterKeyId; | |
64 std::string masterKeyPath; | |
65 | |
66 if (!ReadMasterKey(masterKeyId, masterKeyPath, cryptoJson["MasterKey"])) | |
67 { | |
68 return nullptr; | |
69 } | |
70 crypto->SetCurrentMasterKey(masterKeyId, masterKeyPath); | |
71 | |
72 if (cryptoJson.isMember("PreviousMasterKeys") && cryptoJson["PreviousMasterKeys"].isArray()) | |
73 { | |
74 for (size_t i = 0; i < cryptoJson["PreviousMasterKeys"].size(); i++) | |
75 { | |
76 uint32_t keyId; | |
77 std::string keyPath; | |
78 if (!ReadMasterKey(keyId, keyPath, cryptoJson["PreviousMasterKeys"][(unsigned int)i])) | |
79 { | |
80 return nullptr; | |
81 } | |
82 crypto->AddPreviousMasterKey(keyId, keyPath); | |
83 } | |
84 } | |
85 | |
86 return crypto.release(); | |
87 } |