forked from soutade/libgourou
Add "export private key" feature
This commit is contained in:
parent
3d9e343734
commit
2ac917619e
|
@ -164,6 +164,8 @@ namespace gourou
|
||||||
*/
|
*/
|
||||||
std::string serializeRSAPrivateKey(void* rsa);
|
std::string serializeRSAPrivateKey(void* rsa);
|
||||||
|
|
||||||
|
void exportPrivateLicenseKey(std::string path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get current user
|
* @brief Get current user
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -899,6 +899,19 @@ namespace gourou
|
||||||
return res.toBase64();
|
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;}
|
int DRMProcessor::getLogLevel() {return (int)gourou::logLevel;}
|
||||||
void DRMProcessor::setLogLevel(int logLevel) {gourou::logLevel = (GOUROU_LOG_LEVEL)logLevel;}
|
void DRMProcessor::setLogLevel(int logLevel) {gourou::logLevel = (GOUROU_LOG_LEVEL)logLevel;}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ static const char* deviceFile = "device.xml";
|
||||||
static const char* activationFile = "activation.xml";
|
static const char* activationFile = "activation.xml";
|
||||||
static const char* devicekeyFile = "devicesalt";
|
static const char* devicekeyFile = "devicesalt";
|
||||||
static const char* acsmFile = 0;
|
static const char* acsmFile = 0;
|
||||||
|
static bool exportPrivateKey = false;
|
||||||
static const char* outputFile = 0;
|
static const char* outputFile = 0;
|
||||||
static const char* outputDir = 0;
|
static const char* outputDir = 0;
|
||||||
static const char* defaultDirs[] = {
|
static const char* defaultDirs[] = {
|
||||||
|
@ -71,7 +72,29 @@ public:
|
||||||
{
|
{
|
||||||
DRMProcessorClientImpl client;
|
DRMProcessorClientImpl client;
|
||||||
gourou::DRMProcessor processor(&client, deviceFile, activationFile, devicekeyFile);
|
gourou::DRMProcessor processor(&client, deviceFile, activationFile, devicekeyFile);
|
||||||
|
gourou::User* user = processor.getUser();
|
||||||
|
|
||||||
|
if (exportPrivateKey)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
gourou::FulfillmentItem* item = processor.fulfill(acsmFile);
|
gourou::FulfillmentItem* item = processor.fulfill(acsmFile);
|
||||||
|
|
||||||
std::string filename;
|
std::string filename;
|
||||||
|
@ -107,6 +130,7 @@ public:
|
||||||
filename = finalName;
|
filename = finalName;
|
||||||
}
|
}
|
||||||
std::cout << "Created " << filename << std::endl;
|
std::cout << "Created " << filename << std::endl;
|
||||||
|
}
|
||||||
} catch(std::exception& e)
|
} catch(std::exception& e)
|
||||||
{
|
{
|
||||||
std::cout << e.what() << std::endl;
|
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 << "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 << " " << "-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 << " " << "-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 << " " << "-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-dir" << "\t" << "Optional output directory were to put result (default ./)" << std::endl;
|
||||||
std::cout << " " << "-o|--output-file" << "\t" << "Optional output epub filename (default <title.epub>)" << std::endl;
|
std::cout << " " << "-o|--output-file" << "\t" << "Optional output filename (default <title.(epub|pdf|der)>)" << std::endl;
|
||||||
std::cout << " " << "-f|--acsm-file" << "\t" << "ACSM request file for epub download" << std::endl;
|
std::cout << " " << "-f|--acsm-file" << "\t" << "ACSM request file for epub download" << std::endl;
|
||||||
|
std::cout << " " << "-e|--export-private-key"<< "\t" << "Export private key in DER format" << std::endl;
|
||||||
std::cout << " " << "-v|--verbose" << "\t\t" << "Increase verbosity, can be set multiple times" << std::endl;
|
std::cout << " " << "-v|--verbose" << "\t\t" << "Increase verbosity, can be set multiple times" << std::endl;
|
||||||
std::cout << " " << "-V|--version" << "\t\t" << "Display libgourou version" << std::endl;
|
std::cout << " " << "-V|--version" << "\t\t" << "Display libgourou version" << std::endl;
|
||||||
std::cout << " " << "-h|--help" << "\t\t" << "This help" << std::endl;
|
std::cout << " " << "-h|--help" << "\t\t" << "This help" << std::endl;
|
||||||
|
@ -185,13 +210,14 @@ int main(int argc, char** argv)
|
||||||
{"output-dir", required_argument, 0, 'O' },
|
{"output-dir", required_argument, 0, 'O' },
|
||||||
{"output-file", required_argument, 0, 'o' },
|
{"output-file", required_argument, 0, 'o' },
|
||||||
{"acsm-file", required_argument, 0, 'f' },
|
{"acsm-file", required_argument, 0, 'f' },
|
||||||
|
{"export-private-key",no_argument, 0, 'e' },
|
||||||
{"verbose", no_argument, 0, 'v' },
|
{"verbose", no_argument, 0, 'v' },
|
||||||
{"version", no_argument, 0, 'V' },
|
{"version", no_argument, 0, 'V' },
|
||||||
{"help", no_argument, 0, 'h' },
|
{"help", no_argument, 0, 'h' },
|
||||||
{0, 0, 0, 0 }
|
{0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "d:a:k:O:o:f:vVh",
|
c = getopt_long(argc, argv, "d:a:k:O:o:f:evVh",
|
||||||
long_options, &option_index);
|
long_options, &option_index);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
@ -215,6 +241,9 @@ int main(int argc, char** argv)
|
||||||
case 'o':
|
case 'o':
|
||||||
outputFile = optarg;
|
outputFile = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'e':
|
||||||
|
exportPrivateKey = true;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose++;
|
verbose++;
|
||||||
break;
|
break;
|
||||||
|
@ -232,7 +261,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
gourou::DRMProcessor::setLogLevel(verbose);
|
gourou::DRMProcessor::setLogLevel(verbose);
|
||||||
|
|
||||||
if (!acsmFile || (outputDir && !outputDir[0]) ||
|
if ((!acsmFile && !exportPrivateKey) || (outputDir && !outputDir[0]) ||
|
||||||
(outputFile && !outputFile[0]))
|
(outputFile && !outputFile[0]))
|
||||||
{
|
{
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
@ -254,6 +283,16 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exportPrivateKey)
|
||||||
|
{
|
||||||
|
if (acsmFile)
|
||||||
|
{
|
||||||
|
usage(argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
QFile file(acsmFile);
|
QFile file(acsmFile);
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
{
|
{
|
||||||
|
@ -261,6 +300,7 @@ int main(int argc, char** argv)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QThreadPool::globalInstance()->start(&downloader);
|
QThreadPool::globalInstance()->start(&downloader);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user