diff --git a/include/libgourou.h b/include/libgourou.h index f949215..ce9892e 100644 --- a/include/libgourou.h +++ b/include/libgourou.h @@ -164,6 +164,8 @@ namespace gourou */ std::string serializeRSAPrivateKey(void* rsa); + void exportPrivateLicenseKey(std::string path); + /** * @brief Get current user */ diff --git a/src/libgourou.cpp b/src/libgourou.cpp index 97cd166..4d41649 100644 --- a/src/libgourou.cpp +++ b/src/libgourou.cpp @@ -899,6 +899,19 @@ namespace gourou return res.toBase64(); } + void DRMProcessor::exportPrivateLicenseKey(std::string path) + { + int fd = open(path.c_str(), O_CREAT|O_TRUNC|O_WRONLY, S_IRWXU); + if (fd <= 0) + EXCEPTION(GOUROU_FILE_ERROR, "Unable to open " << path); + + ByteArray privateLicenseKey = ByteArray::fromBase64(user->getPrivateLicenseKey()); + /* In adobekey.py, we get base64 decoded data [26:] */ + write(fd, privateLicenseKey.data()+26, privateLicenseKey.length()-1-26); + + close(fd); + } + int DRMProcessor::getLogLevel() {return (int)gourou::logLevel;} void DRMProcessor::setLogLevel(int logLevel) {gourou::logLevel = (GOUROU_LOG_LEVEL)logLevel;} } diff --git a/utils/acsmdownloader.cpp b/utils/acsmdownloader.cpp index 3c67567..c6e6ff3 100644 --- a/utils/acsmdownloader.cpp +++ b/utils/acsmdownloader.cpp @@ -46,6 +46,7 @@ static const char* deviceFile = "device.xml"; static const char* activationFile = "activation.xml"; static const char* devicekeyFile = "devicesalt"; static const char* acsmFile = 0; +static bool exportPrivateKey = false; static const char* outputFile = 0; static const char* outputDir = 0; static const char* defaultDirs[] = { @@ -71,42 +72,65 @@ public: { DRMProcessorClientImpl client; gourou::DRMProcessor processor(&client, deviceFile, activationFile, devicekeyFile); - - gourou::FulfillmentItem* item = processor.fulfill(acsmFile); - - std::string filename; - if (!outputFile) + gourou::User* user = processor.getUser(); + + if (exportPrivateKey) { - filename = item->getMetadata("title"); - if (filename == "") - filename = "output"; + std::string filename; + if (!outputFile) + filename = std::string("Adobe_PrivateLicenseKey--") + user->getUsername() + ".der"; + + if (outputDir) + { + QDir dir(outputDir); + if (!dir.exists(outputDir)) + dir.mkpath(outputDir); + + filename = std::string(outputDir) + "/" + filename; + } + + processor.exportPrivateLicenseKey(filename); + + std::cout << "Private license key exported to " << filename << std::endl; } else - filename = outputFile; - - if (outputDir) { - QDir dir(outputDir); - if (!dir.exists(outputDir)) - dir.mkpath(outputDir); + gourou::FulfillmentItem* item = processor.fulfill(acsmFile); - filename = std::string(outputDir) + "/" + filename; - } - - gourou::DRMProcessor::ITEM_TYPE type = processor.download(item, filename); - - if (!outputFile) - { - std::string finalName = filename; - if (type == gourou::DRMProcessor::ITEM_TYPE::PDF) - finalName += ".pdf"; + std::string filename; + if (!outputFile) + { + filename = item->getMetadata("title"); + if (filename == "") + filename = "output"; + } else - finalName += ".epub"; - QDir dir; - dir.rename(filename.c_str(), finalName.c_str()); - filename = finalName; + filename = outputFile; + + if (outputDir) + { + QDir dir(outputDir); + if (!dir.exists(outputDir)) + dir.mkpath(outputDir); + + filename = std::string(outputDir) + "/" + filename; + } + + gourou::DRMProcessor::ITEM_TYPE type = processor.download(item, filename); + + if (!outputFile) + { + std::string finalName = filename; + if (type == gourou::DRMProcessor::ITEM_TYPE::PDF) + finalName += ".pdf"; + else + finalName += ".epub"; + QDir dir; + dir.rename(filename.c_str(), finalName.c_str()); + filename = finalName; + } + std::cout << "Created " << filename << std::endl; } - std::cout << "Created " << filename << std::endl; } catch(std::exception& e) { std::cout << e.what() << std::endl; @@ -149,14 +173,15 @@ static void usage(const char* cmd) { std::cout << "Download EPUB file from ACSM request file" << std::endl; - std::cout << "Usage: " << cmd << " [(-d|--device-file) device.xml] [(-a|--activation-file) activation.xml] [(-s|--device-key-file) devicesalt] [(-O|--output-dir) dir] [(-o|--output-file) output.epub] [(-v|--verbose)] [(-h|--help)] (-f|--acsm-file) file.acsm" << std::endl << std::endl; + std::cout << "Usage: " << cmd << " [(-d|--device-file) device.xml] [(-a|--activation-file) activation.xml] [(-s|--device-key-file) devicesalt] [(-O|--output-dir) dir] [(-o|--output-file) output(.epub|.pdf|.der)] [(-v|--verbose)] [(-h|--help)] (-f|--acsm-file) file.acsm|(-e|--export-private-key)" << std::endl << std::endl; std::cout << " " << "-d|--device-file" << "\t" << "device.xml file from eReader" << std::endl; std::cout << " " << "-a|--activation-file" << "\t" << "activation.xml file from eReader" << std::endl; std::cout << " " << "-k|--device-key-file" << "\t" << "private device key file (eg devicesalt/devkey.bin) from eReader" << std::endl; std::cout << " " << "-O|--output-dir" << "\t" << "Optional output directory were to put result (default ./)" << std::endl; - std::cout << " " << "-o|--output-file" << "\t" << "Optional output epub filename (default