1 | /*␊ |
2 | Copyright 2021 Grégory Soutadé␊ |
3 | ␊ |
4 | This file is part of libgourou.␊ |
5 | ␊ |
6 | libgourou is free software: you can redistribute it and/or modify␊ |
7 | it under the terms of the GNU Lesser General Public License as published by␊ |
8 | the Free Software Foundation, either version 3 of the License, or␊ |
9 | (at your option) any later version.␊ |
10 | ␊ |
11 | libgourou is distributed in the hope that it will be useful,␊ |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of␊ |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the␊ |
14 | GNU Lesser General Public License for more details.␊ |
15 | ␊ |
16 | You should have received a copy of the GNU Lesser General Public License␊ |
17 | along with libgourou. If not, see <http://www.gnu.org/licenses/>.␊ |
18 | */␊ |
19 | ␊ |
20 | #ifndef _DEVICE_H_␊ |
21 | #define _DEVICE_H_␊ |
22 | ␊ |
23 | namespace gourou␊ |
24 | {␊ |
25 | class DRMProcessor;␊ |
26 | ␊ |
27 | /**␊ |
28 | * @brief This class is a container for device.xml (device info) and devicesalt (device private key). It should not be used by user.␊ |
29 | */␊ |
30 | class Device␊ |
31 | {␊ |
32 | public:␊ |
33 | ␉static const int DEVICE_KEY_SIZE = 16;␊ |
34 | ␉static const int DEVICE_SERIAL_LEN = 10;␊ |
35 | ␊ |
36 | ␉/**␊ |
37 | ␉ * @brief Main Device constructor␊ |
38 | ␉ *␊ |
39 | ␉ * @param processor Instance of DRMProcessor␊ |
40 | ␉ * @param deviceFile Path of device.xml␊ |
41 | ␉ * @param deviceKeyFile Path of devicesalt␊ |
42 | ␉ */␊ |
43 | ␉Device(DRMProcessor* processor, const std::string& deviceFile, const std::string& deviceKeyFile);␊ |
44 | ␊ |
45 | ␉/**␊ |
46 | ␉ * @brief Return value of devicesalt file (DEVICE_KEY_SIZE len)␊ |
47 | ␉ */␊ |
48 | ␉const unsigned char* getDeviceKey();␊ |
49 | ␊ |
50 | ␉/**␊ |
51 | ␉ * @brief Get one value of device.xml (deviceClass, deviceSerial, deviceName, deviceType, hobbes, clientOS, clientLocale)␊ |
52 | ␉ */␊ |
53 | ␉std::string getProperty(const std::string& property, const std::string& _default=std::string(""));␊ |
54 | ␉std::string operator[](const std::string& property);␊ |
55 | ␊ |
56 | ␉/**␊ |
57 | ␉ * @brief Create device.xml and devicesalt files when they did not exists␊ |
58 | ␉ *␊ |
59 | ␉ * @param processor Instance of DRMProcessor␊ |
60 | ␉ * @param dirName Directory where to put files (.adept)␊ |
61 | ␉ * @param hobbes Hobbes (client version) to set␊ |
62 | ␉ * @param randomSerial Create a random serial (new device each time) or not (serial computed from machine specs)␊ |
63 | ␉ */␊ |
64 | ␉static Device* createDevice(DRMProcessor* processor, const std::string& dirName, const std::string& hobbes, bool randomSerial);␊ |
65 | ␉␊ |
66 | private:␊ |
67 | ␉DRMProcessor* processor;␊ |
68 | std::string deviceFile;␊ |
69 | std::string deviceKeyFile;␊ |
70 | ␉unsigned char deviceKey[DEVICE_KEY_SIZE];␊ |
71 | ␉std::map<std::string, std::string> properties;␊ |
72 | ␊ |
73 | ␉Device(DRMProcessor* processor);␊ |
74 | ␉␊ |
75 | ␉std::string makeFingerprint(const std::string& serial);␊ |
76 | ␉std::string makeSerial(bool random);␊ |
77 | ␉void parseDeviceFile();␊ |
78 | ␉void parseDeviceKeyFile();␊ |
79 | ␉void createDeviceFile(const std::string& hobbes, bool randomSerial);␊ |
80 | ␉void createDeviceKeyFile();␊ |
81 | };␊ |
82 | }␊ |
83 | ␊ |
84 | #endif␊ |