Add DRM removal for ePub only

This commit is contained in:
2021-11-26 15:01:26 +01:00
parent 55ab41613e
commit a751327dab
8 changed files with 262 additions and 56 deletions

View File

@@ -32,6 +32,7 @@ namespace gourou
*
* Data handled is first copied in a newly allocated buffer
* and then shared between all copies until last object is destroyed
* (internal reference counter == 0)
*/
class ByteArray
{
@@ -39,8 +40,18 @@ namespace gourou
/**
* @brief Create an empty byte array
*
* @param useMalloc If true, use malloc() instead of new[] for allocation
*/
ByteArray();
ByteArray(bool useMalloc=false);
/**
* @brief Create an empty byte array of length bytes
*
* @param length Length of data
* @param useMalloc If true, use malloc() instead of new[] for allocation
*/
ByteArray(unsigned int length, bool useMalloc=false);
/**
* @brief Initialize ByteArray with a copy of data
@@ -119,14 +130,36 @@ namespace gourou
void append(const std::string& str);
/**
* @brief Get internal data. Must bot be modified nor freed
* @brief Get internal data. Must bot be freed
*/
const unsigned char* data() {return _data;}
unsigned char* data() {return _data;}
/**
* @brief Get internal data and increment internal reference counter.
* Must bot be freed
*/
unsigned char* takeShadowData() {addRef() ; return _data;}
/**
* @brief Release shadow data. It can now be freed by ByteArray
*/
void releaseShadowData() {delRef();}
/**
* @brief Get internal data length
*/
unsigned int length() {return _length;}
unsigned int length() const {return _length;}
/**
* @brief Get internal data length
*/
unsigned int size() const {return length();}
/**
* @brief Create a new internal buffer of length bytes
* All previous data is lost
*/
void resize(unsigned int length);
ByteArray& operator=(const ByteArray& other);
@@ -134,10 +167,11 @@ namespace gourou
void initData(const unsigned char* data, unsigned int length);
void addRef();
void delRef();
const unsigned char* _data;
bool _useMalloc;
unsigned char* _data;
unsigned int _length;
static std::map<const unsigned char*, int> refCounter;
static std::map<unsigned char*, int> refCounter;
};
}
#endif

View File

@@ -128,6 +128,22 @@ namespace gourou
const unsigned char* data, unsigned dataLength,
unsigned char* res) = 0;
/**
* @brief Decrypt data with RSA private key. Data is padded using PKCS1.5
*
* @param RSAKey RSA key in binary form
* @param RSAKeyLength RSA key length
* @param keyType Key type
* @param password Optional password for RSA PKCS12 certificate
* @param data Data to encrypt
* @param dataLength Data length
* @param res Encryption result (pre allocated buffer)
*/
virtual void RSAPrivateDecrypt(const unsigned char* RSAKey, unsigned int RSAKeyLength,
const RSA_KEY_TYPE keyType, const std::string& password,
const unsigned char* data, unsigned dataLength,
unsigned char* res) = 0;
/**
* @brief Encrypt data with RSA public key. Data is padded using PKCS1.5
*
@@ -331,19 +347,19 @@ namespace gourou
*
* @param handler ZIP file handler
* @param path Internal path inside zip file
*
* @return File content
* @param result Result buffer
* @param decompress If false, don't decompress read data
*/
virtual std::string zipReadFile(void* handler, const std::string& path) = 0;
virtual void zipReadFile(void* handler, const std::string& path, ByteArray& result, bool decompress=true) = 0;
/**
* @brief Write zip internal file
*
* @param handler ZIP file handler
* @param path Internal path inside zip file
* @param content Internal file content
* @param content File content
*/
virtual void zipWriteFile(void* handler, const std::string& path, const std::string& content) = 0;
virtual void zipWriteFile(void* handler, const std::string& path, ByteArray& content) = 0;
/**
* @brief Delete zip internal file
@@ -367,7 +383,7 @@ namespace gourou
* @param result Zipped data
* @param wbits Window bits value for libz
*/
virtual void inflate(std::string data, gourou::ByteArray& result,
virtual void inflate(gourou::ByteArray& data, gourou::ByteArray& result,
int wbits=-15) = 0;
/**
@@ -378,7 +394,7 @@ namespace gourou
* @param wbits Window bits value for libz
* @param compressionLevel Compression level for libz
*/
virtual void deflate(std::string data, gourou::ByteArray& result,
virtual void deflate(gourou::ByteArray& data, gourou::ByteArray& result,
int wbits=-15, int compressionLevel=8) = 0;
};

View File

@@ -40,7 +40,7 @@
#define ACS_SERVER "http://adeactivate.adobe.com/adept"
#endif
#define LIBGOUROU_VERSION "0.4.4"
#define LIBGOUROU_VERSION "0.5"
namespace gourou
{
@@ -181,6 +181,8 @@ namespace gourou
*/
DRMProcessorClient* getClient() { return client; }
void removeDRM(const std::string& ePubFile, ITEM_TYPE type);
private:
gourou::DRMProcessorClient* client;
gourou::Device* device;
@@ -204,6 +206,7 @@ namespace gourou
void buildSignInRequest(pugi::xml_document& signInRequest, const std::string& adobeID, const std::string& adobePassword, const std::string& authenticationCertificate);
void fetchLicenseServiceCertificate(const std::string& licenseURL,
const std::string& operatorURL);
void removeEPubDRM(const std::string& ePubFile);
};
}

View File

@@ -112,6 +112,11 @@ namespace gourou
CLIENT_NETWORK_ERROR,
};
enum DRM_REMOVAL_ERROR {
CLIENT_DRM_ERR_ENCRYPTION_KEY = 0x6000,
CLIENT_DRM_FORMAT_NOT_SUPPORTED,
};
/**
* Generic exception class
*/