7 Commits
v0.7 ... v0.7.2

Author SHA1 Message Date
Grégory Soutadé
5e018ddbd8 Update version 2022-06-08 12:24:38 +02:00
Grégory Soutadé
81563056e0 Update README 2022-06-08 12:24:38 +02:00
Grégory Soutadé
22880c71c6 Update Makefile to support separated OpenSSL3 compilation 2022-06-08 12:24:38 +02:00
Grégory Soutadé
4f288f4e24 Add support for OpenSSL 3 2022-06-05 15:29:20 +02:00
Grégory Soutadé
3d4e6e3918 Look for <loan> element in <permissions> node in addition to <loanToken> one 2022-06-05 13:51:57 +02:00
Grégory Soutadé
7b6b1471fe Update version 2022-04-23 17:51:19 +02:00
Grégory Soutadé
4f9b2de5a5 Remove use of tempnam function and fix bug (bad check of rename return) 2022-04-23 17:41:54 +02:00
9 changed files with 93 additions and 13 deletions

View File

@@ -60,7 +60,7 @@ libgourou.so: $(OBJECTS) $(UPDFPARSERLIB)
$(CXX) obj/*.o $(LDFLAGS) -o $@ -shared $(CXX) obj/*.o $(LDFLAGS) -o $@ -shared
build_utils: build_utils:
make -C utils ROOT=$(PWD) CXX=$(CXX) AR=$(AR) DEBUG=$(DEBUG) STATIC_UTILS=$(STATIC_UTILS) make -C utils ROOT=$(PWD) CXX=$(CXX) AR=$(AR) DEBUG=$(DEBUG) STATIC_UTILS=$(STATIC_UTILS) OPENSSL3=$(OPENSSL3)
clean: clean:
rm -rf libgourou.a libgourou.so obj rm -rf libgourou.a libgourou.so obj

View File

@@ -104,6 +104,11 @@ To return a loaned book :
You can get utils full options description with -h or --help switch You can get utils full options description with -h or --help switch
Docker
------
A docker image (by bcliang) is available at [https://github.com/bcliang/docker-libgourou/](https://github.com/bcliang/docker-libgourou/)
Copyright Copyright
--------- ---------

View File

@@ -40,7 +40,7 @@
#define ACS_SERVER "http://adeactivate.adobe.com/adept" #define ACS_SERVER "http://adeactivate.adobe.com/adept"
#endif #endif
#define LIBGOUROU_VERSION "0.7" #define LIBGOUROU_VERSION "0.7.2"
namespace gourou namespace gourou
{ {

View File

@@ -114,7 +114,8 @@ namespace gourou
CLIENT_GENERIC_EXCEPTION, CLIENT_GENERIC_EXCEPTION,
CLIENT_NETWORK_ERROR, CLIENT_NETWORK_ERROR,
CLIENT_INVALID_PKCS8, CLIENT_INVALID_PKCS8,
CLIENT_FILE_ERROR CLIENT_FILE_ERROR,
CLIENT_OSSL_ERROR,
}; };
enum DRM_REMOVAL_ERROR { enum DRM_REMOVAL_ERROR {

View File

@@ -31,10 +31,23 @@ namespace gourou
node = doc.select_node("/envelope/loanToken/loan").node(); node = doc.select_node("/envelope/loanToken/loan").node();
if (!node) if (node)
EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/loan element in document"); properties["id"] = node.first_child().value();
else
{
node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/display/loan").node();
properties["id"] = node.first_child().value(); if (node)
properties["id"] = node.first_child().value();
else
{
node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/play/loan").node();
if (node)
properties["id"] = node.first_child().value();
else
EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/loan element in document");
}
}
node = doc.select_node("/envelope/loanToken/operatorURL").node(); node = doc.select_node("/envelope/loanToken/operatorURL").node();
@@ -50,6 +63,7 @@ namespace gourou
else else
{ {
node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/play/until").node(); node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/play/until").node();
if (node) if (node)
properties["validity"] = node.first_child().value(); properties["validity"] = node.first_child().value();
else else

View File

@@ -3,8 +3,18 @@ TARGETS=acsmdownloader adept_activate adept_remove adept_loan_mgt
CXXFLAGS=-Wall -fPIC -I$(ROOT)/include -I$(ROOT)/lib/pugixml/src/ CXXFLAGS=-Wall -fPIC -I$(ROOT)/include -I$(ROOT)/lib/pugixml/src/
LDFLAGS=
ifneq ($(OPENSSL3),)
# OpenSSL 1.1.0 compat
CXXFLAGS += -DOPENSSL_API_COMPAT=0x10100000L
CXXFLAGS += -I/tmp/openssl3/usr/include/ -I/tmp/openssl3/usr/include/x86_64-linux-gnu
LDFLAGS += -L/tmp/openssl3/usr/lib/x86_64-linux-gnu -L/tmp/openssl3/usr/lib/x86_64-linux-gnu/ossl-modules
endif
STATIC_DEP= STATIC_DEP=
LDFLAGS=-L$(ROOT) -lcrypto -lzip -lz -lcurl LDFLAGS += -L$(ROOT) -lcrypto -lzip -lz -lcurl
ifneq ($(STATIC_UTILS),) ifneq ($(STATIC_UTILS),)
STATIC_DEP = $(ROOT)/libgourou.a STATIC_DEP = $(ROOT)/libgourou.a
@@ -18,6 +28,7 @@ else
CXXFLAGS += -O2 CXXFLAGS += -O2
endif endif
COMMON_DEPS = drmprocessorclientimpl.cpp utils_common.cpp COMMON_DEPS = drmprocessorclientimpl.cpp utils_common.cpp
COMMON_OBJECTS = $(COMMON_DEPS:.cpp=.o) COMMON_OBJECTS = $(COMMON_DEPS:.cpp=.o)
COMMON_LIB = utils.a COMMON_LIB = utils.a

View File

@@ -114,16 +114,16 @@ public:
// Use temp file for PDF // Use temp file for PDF
if (type == gourou::DRMProcessor::ITEM_TYPE::PDF) if (type == gourou::DRMProcessor::ITEM_TYPE::PDF)
{ {
char* tempFile = tempnam("/tmp", NULL); std::string tempFile = filename + ".tmp";
processor.removeDRM(inputFile, tempFile, type, encryptionKey, encryptionKeySize); /* Be sure there is not already a temp file */
unlink(tempFile.c_str());
processor.removeDRM(filename, tempFile, type, encryptionKey, encryptionKeySize);
/* Original file must be removed before doing a copy... */ /* Original file must be removed before doing a copy... */
unlink(inputFile); unlink(filename.c_str());
if (!rename(tempFile, filename.c_str())) if (rename(tempFile.c_str(), filename.c_str()))
{ {
free(tempFile);
EXCEPTION(gourou::DRM_FILE_ERROR, "Unable to copy " << tempFile << " into " << filename); EXCEPTION(gourou::DRM_FILE_ERROR, "Unable to copy " << tempFile << " into " << filename);
} }
free(tempFile);
} }
else else
processor.removeDRM(inputFile, filename, type, encryptionKey, encryptionKeySize); processor.removeDRM(inputFile, filename, type, encryptionKey, encryptionKeySize);

View File

@@ -35,6 +35,8 @@
#include <openssl/pkcs12.h> #include <openssl/pkcs12.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/rsa.h>
#include <openssl/bn.h>
#include <curl/curl.h> #include <curl/curl.h>
@@ -45,6 +47,31 @@
#include <libgourou_log.h> #include <libgourou_log.h>
#include "drmprocessorclientimpl.h" #include "drmprocessorclientimpl.h"
DRMProcessorClientImpl::DRMProcessorClientImpl():
legacy(0), deflt(0)
{
#if OPENSSL_VERSION_MAJOR >= 3
legacy = OSSL_PROVIDER_load(NULL, "legacy");
if (!legacy)
EXCEPTION(gourou::CLIENT_OSSL_ERROR, "Error, OpenSSL legacy provider not available");
deflt = OSSL_PROVIDER_load(NULL, "default");
if (!deflt)
EXCEPTION(gourou::CLIENT_OSSL_ERROR, "Error, OpenSSL default provider not available");
#endif
}
DRMProcessorClientImpl::~DRMProcessorClientImpl()
{
#if OPENSSL_VERSION_MAJOR >= 3
if (legacy)
OSSL_PROVIDER_unload(legacy);
if (deflt)
OSSL_PROVIDER_unload(deflt);
#endif
}
/* Digest interface */ /* Digest interface */
void* DRMProcessorClientImpl::createDigest(const std::string& digestName) void* DRMProcessorClientImpl::createDigest(const std::string& digestName)
{ {
@@ -289,7 +316,12 @@ void DRMProcessorClientImpl::RSAPrivateEncrypt(const unsigned char* RSAKey, unsi
pkcs12 = d2i_PKCS12(NULL, &RSAKey, RSAKeyLength); pkcs12 = d2i_PKCS12(NULL, &RSAKey, RSAKeyLength);
if (!pkcs12) if (!pkcs12)
EXCEPTION(gourou::CLIENT_INVALID_PKCS12, ERR_error_string(ERR_get_error(), NULL)); EXCEPTION(gourou::CLIENT_INVALID_PKCS12, ERR_error_string(ERR_get_error(), NULL));
PKCS12_parse(pkcs12, password.c_str(), &pkey, &cert, &ca); PKCS12_parse(pkcs12, password.c_str(), &pkey, &cert, &ca);
if (!pkey)
EXCEPTION(gourou::CLIENT_INVALID_PKCS12, ERR_error_string(ERR_get_error(), NULL));
rsa = EVP_PKEY_get1_RSA(pkey); rsa = EVP_PKEY_get1_RSA(pkey);
int ret = RSA_private_encrypt(dataLength, data, res, rsa, RSA_PKCS1_PADDING); int ret = RSA_private_encrypt(dataLength, data, res, rsa, RSA_PKCS1_PADDING);
@@ -413,6 +445,9 @@ void DRMProcessorClientImpl::extractCertificate(const unsigned char* RSAKey, uns
EXCEPTION(gourou::CLIENT_INVALID_PKCS12, ERR_error_string(ERR_get_error(), NULL)); EXCEPTION(gourou::CLIENT_INVALID_PKCS12, ERR_error_string(ERR_get_error(), NULL));
PKCS12_parse(pkcs12, password.c_str(), &pkey, &cert, &ca); PKCS12_parse(pkcs12, password.c_str(), &pkey, &cert, &ca);
if (!cert)
EXCEPTION(gourou::CLIENT_INVALID_PKCS12, ERR_error_string(ERR_get_error(), NULL));
*certOutLength = i2d_X509(cert, certOut); *certOutLength = i2d_X509(cert, certOut);
EVP_PKEY_free(pkey); EVP_PKEY_free(pkey);

View File

@@ -31,11 +31,18 @@
#include <string> #include <string>
#if OPENSSL_VERSION_MAJOR >= 3
#include <openssl/provider.h>
#endif
#include <drmprocessorclient.h> #include <drmprocessorclient.h>
class DRMProcessorClientImpl : public gourou::DRMProcessorClient class DRMProcessorClientImpl : public gourou::DRMProcessorClient
{ {
public: public:
DRMProcessorClientImpl();
~DRMProcessorClientImpl();
/* Digest interface */ /* Digest interface */
virtual void* createDigest(const std::string& digestName); virtual void* createDigest(const std::string& digestName);
virtual int digestUpdate(void* handler, unsigned char* data, unsigned int length); virtual int digestUpdate(void* handler, unsigned char* data, unsigned int length);
@@ -118,6 +125,13 @@ public:
virtual void deflate(gourou::ByteArray& data, gourou::ByteArray& result, virtual void deflate(gourou::ByteArray& data, gourou::ByteArray& result,
int wbits=-15, int compressionLevel=8); int wbits=-15, int compressionLevel=8);
private:
#if OPENSSL_VERSION_MAJOR >= 3
OSSL_PROVIDER *legacy, *deflt;
#else
void *legacy, *deflt;
#endif
}; };
#endif #endif