Libgourou

Libgourou Git Source Tree

Root/include/libgourou.h

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 _LIBGOUROU_H_
21#define _LIBGOUROU_H_
22
23#include "bytearray.h"
24#include "device.h"
25#include "user.h"
26#include "fulfillment_item.h"
27#include "drmprocessorclient.h"
28
29#include <pugixml.hpp>
30
31#ifndef HOBBES_DEFAULT_VERSION
32#define HOBBES_DEFAULT_VERSION "10.0.4"
33#endif
34
35#ifndef DEFAULT_ADEPT_DIR
36#define DEFAULT_ADEPT_DIR "./.adept"
37#endif
38
39#ifndef ACS_SERVER
40#define ACS_SERVER "http://adeactivate.adobe.com/adept"
41#endif
42
43#define LIBGOUROU_VERSION "0.4.1"
44
45namespace gourou
46{
47 /**
48 * @brief Main class that handle all ADEPTS functions (fulfill, download, signIn, activate)
49 */
50 class DRMProcessor
51 {
52 public:
53
54static const std::string VERSION;
55
56enum ITEM_TYPE { EPUB=0, PDF };
57/**
58 * @brief Main constructor. To be used once all is configured (user has signedIn, device is activated)
59 *
60 * @param client Client processor
61 * @param deviceFile Path of device.xml
62 * @param activationFile Path of activation.xml
63 * @param deviceKeyFile Path of devicesalt
64 */
65 DRMProcessor(DRMProcessorClient* client, const std::string& deviceFile, const std::string& activationFile, const std::string& deviceKeyFile);
66
67~DRMProcessor();
68
69/**
70 * @brief Fulfill ACSM file to server in order to retrieve ePub fulfillment item
71 *
72 * @param ACSMFile Path of ACSMFile
73 *
74 * @return a FulfillmentItem if all is OK
75 */
76FulfillmentItem* fulfill(const std::string& ACSMFile);
77
78/**
79 * @brief Once fulfilled, ePub file needs to be downloaded.
80 * During this operation, DRM information is added into downloaded file
81 *
82 * @param item Item from fulfill() method
83 * @param path Output file path
84 *
85 * @return Type of downloaded item
86 */
87ITEM_TYPE download(FulfillmentItem* item, std::string path);
88
89/**
90 * @brief SignIn into ACS Server (required to activate device)
91 *
92 * @param adobeID AdobeID username
93 * @param adobePassword Adobe password
94 */
95void signIn(const std::string& adobeID, const std::string& adobePassword);
96
97/**
98 * @brief Activate newly created device (user must have successfuly signedIn before)
99 */
100void activateDevice();
101
102/**
103 * @brief Create a new ADEPT environment (device.xml, devicesalt and activation.xml).
104 *
105 * @param client Client processor
106 * @param randomSerial Always generate a new device (or not)
107 * @param dirName Directory where to put generated files (.adept)
108 * @param hobbes Override hobbes default version
109 * @param ACSServer Override main ACS server (default adeactivate.adobe.com)
110 */
111 static DRMProcessor* createDRMProcessor(DRMProcessorClient* client,
112bool randomSerial=false, const std::string& dirName=std::string(DEFAULT_ADEPT_DIR),
113const std::string& hobbes=std::string(HOBBES_DEFAULT_VERSION),
114const std::string& ACSServer=ACS_SERVER);
115
116/**
117 * @brief Get current log level
118 */
119static int getLogLevel();
120
121/**
122 * @brief Set log level (higher number for verbose output)
123 */
124static void setLogLevel(int logLevel);
125
126/**
127 * Functions used internally, should not be called by user
128 */
129
130/**
131 * @brief Send HTTP (GET or POST) request
132 *
133 * @param URL HTTP URL
134 * @param POSTData POST data if needed, if not set, a GET request is done
135 * @param contentType Optional content type of POST Data
136 * @param responseHeaders Optional Response headers of HTTP request
137 *
138 * @return data of HTTP response
139 */
140ByteArray sendRequest(const std::string& URL, const std::string& POSTData=std::string(), const char* contentType=0, std::map<std::string, std::string>* responseHeaders=0);
141
142/**
143 * @brief Send HTTP POST request to URL with document as POSTData
144 */
145ByteArray sendRequest(const pugi::xml_document& document, const std::string& url);
146
147/**
148 * @brief In place encrypt data with private device key
149 */
150ByteArray encryptWithDeviceKey(const unsigned char* data, unsigned int len);
151
152/**
153 * @brief In place decrypt data with private device key
154 */
155ByteArray decryptWithDeviceKey(const unsigned char* data, unsigned int len);
156
157/**
158 * @brief Return base64 encoded value of RSA public key
159 */
160std::string serializeRSAPublicKey(void* rsa);
161
162/**
163 * @brief Return base64 encoded value of RSA private key encrypted with private device key
164 */
165std::string serializeRSAPrivateKey(void* rsa);
166
167void exportPrivateLicenseKey(std::string path);
168
169/**
170 * @brief Get current user
171 */
172User* getUser() { return user; }
173
174/**
175 * @brief Get current device
176 */
177Device* getDevice() { return device; }
178
179/**
180 * @brief Get current client
181 */
182DRMProcessorClient* getClient() { return client; }
183
184 private:
185gourou::DRMProcessorClient* client;
186 gourou::Device* device;
187 gourou::User* user;
188
189 DRMProcessor(DRMProcessorClient* client);
190
191void pushString(void* sha_ctx, const std::string& string);
192void pushTag(void* sha_ctx, uint8_t tag);
193void hashNode(const pugi::xml_node& root, void *sha_ctx, std::map<std::string,std::string> nsHash);
194void hashNode(const pugi::xml_node& root, unsigned char* sha_out);
195std::string signNode(const pugi::xml_node& rootNode);
196void addNonce(pugi::xml_node& root);
197void buildAuthRequest(pugi::xml_document& authReq);
198void buildInitLicenseServiceRequest(pugi::xml_document& initLicReq, std::string operatorURL);
199void doOperatorAuth(std::string operatorURL);
200void operatorAuth(std::string operatorURL);
201void buildFulfillRequest(pugi::xml_document& acsmDoc, pugi::xml_document& fulfillReq);
202void buildActivateReq(pugi::xml_document& activateReq);
203ByteArray sendFulfillRequest(const pugi::xml_document& document, const std::string& url);
204void buildSignInRequest(pugi::xml_document& signInRequest, const std::string& adobeID, const std::string& adobePassword, const std::string& authenticationCertificate);
205void fetchLicenseServiceCertificate(const std::string& licenseURL,
206 const std::string& operatorURL);
207 };
208}
209
210#endif

Archive Download this file