forked from soutade/libgourou
Send a warning when libgourou can't handle encryption algorithm during a DRM removal attempt (+ keep encryption.xml in output)
This commit is contained in:
parent
f33891ef1c
commit
e4c05bd6b3
|
@ -117,7 +117,8 @@ namespace gourou
|
|||
DRM_VERSION_NOT_SUPPORTED,
|
||||
DRM_FILE_ERROR,
|
||||
DRM_FORMAT_NOT_SUPPORTED,
|
||||
DRM_IN_OUT_EQUALS
|
||||
DRM_IN_OUT_EQUALS,
|
||||
DRM_MISSING_PARAMETER
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -948,6 +948,7 @@ namespace gourou
|
|||
void DRMProcessor::removeEPubDRM(const std::string& filenameIn, const std::string& filenameOut)
|
||||
{
|
||||
ByteArray zipData;
|
||||
bool removeEncryptionXML = true;
|
||||
void* zipHandler = client->zipOpen(filenameOut);
|
||||
|
||||
client->zipReadFile(zipHandler, "META-INF/rights.xml", zipData);
|
||||
|
@ -963,12 +964,27 @@ namespace gourou
|
|||
pugi::xml_document encryptionDoc;
|
||||
encryptionDoc.load_string((const char*)zipData.data());
|
||||
|
||||
pugi::xpath_node_set nodeSet = encryptionDoc.select_nodes("//CipherReference");
|
||||
pugi::xpath_node_set nodeSet = encryptionDoc.select_nodes("//EncryptedData");
|
||||
|
||||
for (pugi::xpath_node_set::const_iterator it = nodeSet.begin();
|
||||
it != nodeSet.end(); ++it)
|
||||
{
|
||||
std::string encryptedFile = it->node().attribute("URI").value();
|
||||
pugi::xml_node encryptionMethod = it->node().child("EncryptionMethod");
|
||||
pugi::xml_node cipherReference = it->node().child("CipherData").child("CipherReference");
|
||||
|
||||
std::string encryptionType = encryptionMethod.attribute("Algorithm").value();
|
||||
std::string encryptedFile = cipherReference.attribute("URI").value();
|
||||
|
||||
if (encryptionType == "")
|
||||
{
|
||||
EXCEPTION(DRM_MISSING_PARAMETER, "Missing Algorithm attribute in encryption.xml");
|
||||
}
|
||||
else if (encryptionType == "http://www.w3.org/2001/04/xmlenc#aes128-cbc")
|
||||
{
|
||||
if (encryptedFile == "")
|
||||
{
|
||||
EXCEPTION(DRM_MISSING_PARAMETER, "Missing URI attribute in encryption.xml");
|
||||
}
|
||||
|
||||
GOUROU_LOG(DEBUG, "Encrypted file " << encryptedFile);
|
||||
|
||||
|
@ -988,14 +1004,32 @@ namespace gourou
|
|||
|
||||
// Add 'Z' at the end, done in ineptepub.py
|
||||
_clearData[dataOutLength] = 'Z';
|
||||
clearData.resize(dataOutLength+1);
|
||||
|
||||
client->inflate(clearData, inflateData);
|
||||
|
||||
client->zipWriteFile(zipHandler, encryptedFile, inflateData);
|
||||
|
||||
it->node().parent().remove_child(it->node());
|
||||
}
|
||||
else
|
||||
{
|
||||
GOUROU_LOG(WARN, "Unsupported encryption algorithm " << encryptionType << ", for file " << encryptedFile);
|
||||
removeEncryptionXML = false;
|
||||
}
|
||||
}
|
||||
|
||||
client->zipDeleteFile(zipHandler, "META-INF/rights.xml");
|
||||
if (removeEncryptionXML)
|
||||
client->zipDeleteFile(zipHandler, "META-INF/encryption.xml");
|
||||
else
|
||||
{
|
||||
StringXMLWriter xmlWriter;
|
||||
encryptionDoc.save(xmlWriter, " ");
|
||||
std::string xmlStr = xmlWriter.getResult();
|
||||
ByteArray ba(xmlStr);
|
||||
client->zipWriteFile(zipHandler, "META-INF/encryption.xml", ba);
|
||||
}
|
||||
|
||||
client->zipClose(zipHandler);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user