diff --git a/utils/drmprocessorclientimpl.cpp b/utils/drmprocessorclientimpl.cpp index 58a9f97..a4b5038 100644 --- a/utils/drmprocessorclientimpl.cpp +++ b/utils/drmprocessorclientimpl.cpp @@ -49,17 +49,27 @@ #include #include "drmprocessorclientimpl.h" +static int error_cb(const char *str, size_t len, void *u) +{ + std::cout << str << std::endl; + return 0; +} + DRMProcessorClientImpl::DRMProcessorClientImpl(): legacy(0), deflt(0) { #if OPENSSL_VERSION_MAJOR >= 3 legacy = OSSL_PROVIDER_load(NULL, "legacy"); if (!legacy) + { + ERR_print_errors_cb(error_cb, NULL); 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"); + OSSL_PROVIDER_load(NULL, "base"); #endif #ifdef WIN32 @@ -333,11 +343,39 @@ void DRMProcessorClientImpl::padWithPKCS1(unsigned char* out, unsigned int outLe 0x00 0x01 0xff * n 0x00 dataIn */ - memset(out, 0xFF, outLength); + memset(out, 0xFF, outLength - inLength - 1); out[0] = 0x0; out[1] = 0x1; out[outLength - inLength - 1] = 0x00; + + memcpy(&out[outLength - inLength], in, inLength); +} + +void DRMProcessorClientImpl::padWithPKCS1Type2(unsigned char* out, unsigned int outLength, + const unsigned char* in, unsigned int inLength) +{ + if (outLength < (inLength + 3)) + EXCEPTION(gourou::CLIENT_RSA_ERROR, "Not enough space for PKCS1 padding"); + + /* + PKCS1v5 type 2 Padding is : + 0x00 0x02 0xXX * n 0x00 dataIn + XX is random non zero data + */ + + RAND_bytes(&out[2], outLength - inLength - 1); + + for(unsigned int i=2; i= 3 OSSL_PROVIDER *legacy, *deflt;