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