Make DRMProcessorClient API more consistent
This commit is contained in:
parent
7b8c7acbad
commit
e28dc39a68
|
@ -47,20 +47,16 @@ namespace gourou
|
||||||
* @param handler Digest handler
|
* @param handler Digest handler
|
||||||
* @param data Data to digest
|
* @param data Data to digest
|
||||||
* @param length Length of data
|
* @param length Length of data
|
||||||
*
|
|
||||||
* @return OK/KO
|
|
||||||
*/
|
*/
|
||||||
virtual int digestUpdate(void* handler, unsigned char* data, unsigned int length) = 0;
|
virtual void digestUpdate(void* handler, unsigned char* data, unsigned int length) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Finalize digest with remained buffered data and destroy handler
|
* @brief Finalize digest with remained buffered data and destroy handler
|
||||||
*
|
*
|
||||||
* @param handler Digest handler
|
* @param handler Digest handler
|
||||||
* @param digestOut Digest result (buffer must be pre allocated with right size)
|
* @param digestOut Digest result (buffer must be pre allocated with right size)
|
||||||
*
|
|
||||||
* @return OK/KO
|
|
||||||
*/
|
*/
|
||||||
virtual int digestFinalize(void* handler, unsigned char* digestOut) = 0;
|
virtual void digestFinalize(void* handler, unsigned char* digestOut) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Global digest function
|
* @brief Global digest function
|
||||||
|
@ -69,10 +65,8 @@ namespace gourou
|
||||||
* @param data Data to digest
|
* @param data Data to digest
|
||||||
* @param length Length of data
|
* @param length Length of data
|
||||||
* @param digestOut Digest result (buffer must be pre allocated with right size)
|
* @param digestOut Digest result (buffer must be pre allocated with right size)
|
||||||
*
|
|
||||||
* @return OK/KO
|
|
||||||
*/
|
*/
|
||||||
virtual int digest(const std::string& digestName, unsigned char* data, unsigned int length, unsigned char* digestOut) = 0;
|
virtual void digest(const std::string& digestName, unsigned char* data, unsigned int length, unsigned char* digestOut) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RandomInterface
|
class RandomInterface
|
||||||
|
@ -239,7 +233,7 @@ namespace gourou
|
||||||
* @param dataOut Encrypted data
|
* @param dataOut Encrypted data
|
||||||
* @param dataOutLength Length of encrypted data
|
* @param dataOutLength Length of encrypted data
|
||||||
*/
|
*/
|
||||||
virtual void Encrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
virtual void encrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv, unsigned int ivLength,
|
const unsigned char* iv, unsigned int ivLength,
|
||||||
const unsigned char* dataIn, unsigned int dataInLength,
|
const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
|
@ -256,7 +250,7 @@ namespace gourou
|
||||||
*
|
*
|
||||||
* @return AES handler
|
* @return AES handler
|
||||||
*/
|
*/
|
||||||
virtual void* EncryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
virtual void* encryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv=0, unsigned int ivLength=0) = 0;
|
const unsigned char* iv=0, unsigned int ivLength=0) = 0;
|
||||||
|
|
||||||
|
@ -269,7 +263,7 @@ namespace gourou
|
||||||
* @param dataOut Encrypted data
|
* @param dataOut Encrypted data
|
||||||
* @param dataOutLength Length of encrypted data
|
* @param dataOutLength Length of encrypted data
|
||||||
*/
|
*/
|
||||||
virtual void EncryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
virtual void encryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength) = 0;
|
unsigned char* dataOut, unsigned int* dataOutLength) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -280,7 +274,7 @@ namespace gourou
|
||||||
* @param dataOut Last block of encrypted data
|
* @param dataOut Last block of encrypted data
|
||||||
* @param dataOutLength Length of encrypted data
|
* @param dataOutLength Length of encrypted data
|
||||||
*/
|
*/
|
||||||
virtual void EncryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength) = 0;
|
virtual void encryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Do decryption. If length of data is not multiple of block size, PKCS#5 padding is done
|
* @brief Do decryption. If length of data is not multiple of block size, PKCS#5 padding is done
|
||||||
|
@ -296,7 +290,7 @@ namespace gourou
|
||||||
* @param dataOut Encrypted data
|
* @param dataOut Encrypted data
|
||||||
* @param dataOutLength Length of encrypted data
|
* @param dataOutLength Length of encrypted data
|
||||||
*/
|
*/
|
||||||
virtual void Decrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
virtual void decrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv, unsigned int ivLength,
|
const unsigned char* iv, unsigned int ivLength,
|
||||||
const unsigned char* dataIn, unsigned int dataInLength,
|
const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
|
@ -313,7 +307,7 @@ namespace gourou
|
||||||
*
|
*
|
||||||
* @return AES handler
|
* @return AES handler
|
||||||
*/
|
*/
|
||||||
virtual void* DecryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
virtual void* decryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv=0, unsigned int ivLength=0) = 0;
|
const unsigned char* iv=0, unsigned int ivLength=0) = 0;
|
||||||
|
|
||||||
|
@ -326,7 +320,7 @@ namespace gourou
|
||||||
* @param dataOut Decrypted data
|
* @param dataOut Decrypted data
|
||||||
* @param dataOutLength Length of decrypted data
|
* @param dataOutLength Length of decrypted data
|
||||||
*/
|
*/
|
||||||
virtual void DecryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
virtual void decryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength) = 0;
|
unsigned char* dataOut, unsigned int* dataOutLength) = 0;
|
||||||
/**
|
/**
|
||||||
* @brief Finalize decryption (decrypt last block and remove padding if it is set).
|
* @brief Finalize decryption (decrypt last block and remove padding if it is set).
|
||||||
|
@ -336,7 +330,7 @@ namespace gourou
|
||||||
* @param dataOut Last block decrypted data
|
* @param dataOut Last block decrypted data
|
||||||
* @param dataOutLength Length of decrypted data
|
* @param dataOutLength Length of decrypted data
|
||||||
*/
|
*/
|
||||||
virtual void DecryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength) = 0;
|
virtual void decryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,8 @@ namespace gourou
|
||||||
CLIENT_INVALID_PKCS8,
|
CLIENT_INVALID_PKCS8,
|
||||||
CLIENT_FILE_ERROR,
|
CLIENT_FILE_ERROR,
|
||||||
CLIENT_OSSL_ERROR,
|
CLIENT_OSSL_ERROR,
|
||||||
|
CLIENT_CRYPT_ERROR,
|
||||||
|
CLIENT_DIGEST_ERROR,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DRM_REMOVAL_ERROR {
|
enum DRM_REMOVAL_ERROR {
|
||||||
|
|
|
@ -869,7 +869,7 @@ namespace gourou
|
||||||
// Generate IV in front
|
// Generate IV in front
|
||||||
client->randBytes(encrypted_data, 16);
|
client->randBytes(encrypted_data, 16);
|
||||||
|
|
||||||
client->Encrypt(CryptoInterface::ALGO_AES, CryptoInterface::CHAIN_CBC,
|
client->encrypt(CryptoInterface::ALGO_AES, CryptoInterface::CHAIN_CBC,
|
||||||
deviceKey, 16, encrypted_data, 16,
|
deviceKey, 16, encrypted_data, 16,
|
||||||
data, len,
|
data, len,
|
||||||
encrypted_data+16, &outLen);
|
encrypted_data+16, &outLen);
|
||||||
|
@ -888,7 +888,7 @@ namespace gourou
|
||||||
const unsigned char* deviceKey = device->getDeviceKey();
|
const unsigned char* deviceKey = device->getDeviceKey();
|
||||||
unsigned char* decrypted_data = new unsigned char[len-16];
|
unsigned char* decrypted_data = new unsigned char[len-16];
|
||||||
|
|
||||||
client->Decrypt(CryptoInterface::ALGO_AES, CryptoInterface::CHAIN_CBC,
|
client->decrypt(CryptoInterface::ALGO_AES, CryptoInterface::CHAIN_CBC,
|
||||||
deviceKey, 16, data, 16,
|
deviceKey, 16, data, 16,
|
||||||
data+16, len-16,
|
data+16, len-16,
|
||||||
decrypted_data, &outLen);
|
decrypted_data, &outLen);
|
||||||
|
@ -1009,7 +1009,7 @@ namespace gourou
|
||||||
|
|
||||||
unsigned char* clearRSAKey = new unsigned char[arrayEncryptedKey.size()];
|
unsigned char* clearRSAKey = new unsigned char[arrayEncryptedKey.size()];
|
||||||
|
|
||||||
client->Decrypt(CryptoInterface::ALGO_AES, CryptoInterface::CHAIN_CBC,
|
client->decrypt(CryptoInterface::ALGO_AES, CryptoInterface::CHAIN_CBC,
|
||||||
(const unsigned char*)key, (unsigned int)sizeof(key),
|
(const unsigned char*)key, (unsigned int)sizeof(key),
|
||||||
(const unsigned char*)iv, (unsigned int)sizeof(iv),
|
(const unsigned char*)iv, (unsigned int)sizeof(iv),
|
||||||
(const unsigned char*)arrayEncryptedKey.data(), arrayEncryptedKey.size(),
|
(const unsigned char*)arrayEncryptedKey.data(), arrayEncryptedKey.size(),
|
||||||
|
@ -1109,7 +1109,7 @@ namespace gourou
|
||||||
gourou::ByteArray inflateData(true);
|
gourou::ByteArray inflateData(true);
|
||||||
unsigned int dataOutLength;
|
unsigned int dataOutLength;
|
||||||
|
|
||||||
client->Decrypt(CryptoInterface::ALGO_AES, CryptoInterface::CHAIN_CBC,
|
client->decrypt(CryptoInterface::ALGO_AES, CryptoInterface::CHAIN_CBC,
|
||||||
decryptedKey+sizeof(decryptedKey)-16, 16, /* Key */
|
decryptedKey+sizeof(decryptedKey)-16, 16, /* Key */
|
||||||
_data, 16, /* IV */
|
_data, 16, /* IV */
|
||||||
&_data[16], zipData.length()-16,
|
&_data[16], zipData.length()-16,
|
||||||
|
@ -1313,7 +1313,7 @@ namespace gourou
|
||||||
|
|
||||||
GOUROU_LOG(DEBUG, "Decrypt string " << dictIt->first << " " << dataLength);
|
GOUROU_LOG(DEBUG, "Decrypt string " << dictIt->first << " " << dataLength);
|
||||||
|
|
||||||
client->Decrypt(CryptoInterface::ALGO_RC4, CryptoInterface::CHAIN_ECB,
|
client->decrypt(CryptoInterface::ALGO_RC4, CryptoInterface::CHAIN_ECB,
|
||||||
tmpKey, 16, /* Key */
|
tmpKey, 16, /* Key */
|
||||||
NULL, 0, /* IV */
|
NULL, 0, /* IV */
|
||||||
encryptedData, dataLength,
|
encryptedData, dataLength,
|
||||||
|
@ -1346,7 +1346,7 @@ namespace gourou
|
||||||
|
|
||||||
GOUROU_LOG(DEBUG, "Decrypt stream id " << object->objectId() << ", size " << stream->dataLength());
|
GOUROU_LOG(DEBUG, "Decrypt stream id " << object->objectId() << ", size " << stream->dataLength());
|
||||||
|
|
||||||
client->Decrypt(CryptoInterface::ALGO_RC4, CryptoInterface::CHAIN_ECB,
|
client->decrypt(CryptoInterface::ALGO_RC4, CryptoInterface::CHAIN_ECB,
|
||||||
tmpKey, 16, /* Key */
|
tmpKey, 16, /* Key */
|
||||||
NULL, 0, /* IV */
|
NULL, 0, /* IV */
|
||||||
encryptedData, dataLength,
|
encryptedData, dataLength,
|
||||||
|
|
|
@ -82,32 +82,32 @@ void* DRMProcessorClientImpl::createDigest(const std::string& digestName)
|
||||||
if (EVP_DigestInit(md_ctx, md) != 1)
|
if (EVP_DigestInit(md_ctx, md) != 1)
|
||||||
{
|
{
|
||||||
EVP_MD_CTX_free(md_ctx);
|
EVP_MD_CTX_free(md_ctx);
|
||||||
return 0;
|
EXCEPTION(gourou::CLIENT_DIGEST_ERROR, ERR_error_string(ERR_get_error(), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
return md_ctx;
|
return md_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DRMProcessorClientImpl::digestUpdate(void* handler, unsigned char* data, unsigned int length)
|
void DRMProcessorClientImpl::digestUpdate(void* handler, unsigned char* data, unsigned int length)
|
||||||
{
|
{
|
||||||
return (EVP_DigestUpdate((EVP_MD_CTX *)handler, data, length)) ? 0 : -1;
|
if (EVP_DigestUpdate((EVP_MD_CTX *)handler, data, length) != 1)
|
||||||
|
EXCEPTION(gourou::CLIENT_DIGEST_ERROR, ERR_error_string(ERR_get_error(), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
int DRMProcessorClientImpl::digestFinalize(void* handler, unsigned char* digestOut)
|
void DRMProcessorClientImpl::digestFinalize(void* handler, unsigned char* digestOut)
|
||||||
{
|
{
|
||||||
int res = EVP_DigestFinal((EVP_MD_CTX *)handler, digestOut, NULL);
|
int res = EVP_DigestFinal((EVP_MD_CTX *)handler, digestOut, NULL);
|
||||||
EVP_MD_CTX_free((EVP_MD_CTX *)handler);
|
EVP_MD_CTX_free((EVP_MD_CTX *)handler);
|
||||||
return (res == 1) ? 0 : -1;
|
|
||||||
|
if (res <= 0)
|
||||||
|
EXCEPTION(gourou::CLIENT_DIGEST_ERROR, ERR_error_string(ERR_get_error(), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
int DRMProcessorClientImpl::digest(const std::string& digestName, unsigned char* data, unsigned int length, unsigned char* digestOut)
|
void DRMProcessorClientImpl::digest(const std::string& digestName, unsigned char* data, unsigned int length, unsigned char* digestOut)
|
||||||
{
|
{
|
||||||
void* handler = createDigest(digestName);
|
void* handler = createDigest(digestName);
|
||||||
if (!handler)
|
digestUpdate(handler, data, length);
|
||||||
return -1;
|
digestFinalize(handler, digestOut);
|
||||||
if (digestUpdate(handler, data, length))
|
|
||||||
return -1;
|
|
||||||
return digestFinalize(handler, digestOut);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Random interface */
|
/* Random interface */
|
||||||
|
@ -506,24 +506,27 @@ void DRMProcessorClientImpl::extractCertificate(const unsigned char* RSAKey, uns
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Crypto interface */
|
/* Crypto interface */
|
||||||
void DRMProcessorClientImpl::Encrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
void DRMProcessorClientImpl::encrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv, unsigned int ivLength,
|
const unsigned char* iv, unsigned int ivLength,
|
||||||
const unsigned char* dataIn, unsigned int dataInLength,
|
const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength)
|
unsigned char* dataOut, unsigned int* dataOutLength)
|
||||||
{
|
{
|
||||||
void* handler = EncryptInit(algo, chaining, key, keyLength, iv, ivLength);
|
void* handler = encryptInit(algo, chaining, key, keyLength, iv, ivLength);
|
||||||
EncryptUpdate(handler, dataIn, dataInLength, dataOut, dataOutLength);
|
encryptUpdate(handler, dataIn, dataInLength, dataOut, dataOutLength);
|
||||||
EncryptFinalize(handler, dataOut+*dataOutLength, dataOutLength);
|
encryptFinalize(handler, dataOut+*dataOutLength, dataOutLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* DRMProcessorClientImpl::EncryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
void* DRMProcessorClientImpl::encryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv, unsigned int ivLength)
|
const unsigned char* iv, unsigned int ivLength)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (algo == ALGO_AES)
|
switch (algo)
|
||||||
|
{
|
||||||
|
case ALGO_AES:
|
||||||
{
|
{
|
||||||
switch(keyLength)
|
switch(keyLength)
|
||||||
{
|
{
|
||||||
|
@ -531,10 +534,10 @@ void* DRMProcessorClientImpl::EncryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaini
|
||||||
switch(chaining)
|
switch(chaining)
|
||||||
{
|
{
|
||||||
case CHAIN_ECB:
|
case CHAIN_ECB:
|
||||||
EVP_EncryptInit(ctx, EVP_aes_128_ecb(), key, iv);
|
ret = EVP_EncryptInit(ctx, EVP_aes_128_ecb(), key, iv);
|
||||||
break;
|
break;
|
||||||
case CHAIN_CBC:
|
case CHAIN_CBC:
|
||||||
EVP_EncryptInit(ctx, EVP_aes_128_cbc(), key, iv);
|
ret = EVP_EncryptInit(ctx, EVP_aes_128_cbc(), key, iv);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
EXCEPTION(gourou::CLIENT_BAD_CHAINING, "Unknown chaining mode " << chaining);
|
EXCEPTION(gourou::CLIENT_BAD_CHAINING, "Unknown chaining mode " << chaining);
|
||||||
|
@ -544,26 +547,39 @@ void* DRMProcessorClientImpl::EncryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaini
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
EXCEPTION(gourou::CLIENT_BAD_KEY_SIZE, "Invalid key size " << keyLength);
|
EXCEPTION(gourou::CLIENT_BAD_KEY_SIZE, "Invalid key size " << keyLength);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (algo == ALGO_RC4)
|
case ALGO_RC4:
|
||||||
{
|
{
|
||||||
if (keyLength != 16)
|
if (keyLength != 16)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
EXCEPTION(gourou::CLIENT_BAD_KEY_SIZE, "Invalid key size " << keyLength);
|
EXCEPTION(gourou::CLIENT_BAD_KEY_SIZE, "Invalid key size " << keyLength);
|
||||||
}
|
}
|
||||||
EVP_DecryptInit(ctx, EVP_rc4(), key, iv);
|
ret = EVP_DecryptInit(ctx, EVP_rc4(), key, iv);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret <= 0)
|
||||||
|
{
|
||||||
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
|
EXCEPTION(gourou::CLIENT_CRYPT_ERROR, ERR_error_string(ERR_get_error(), NULL));
|
||||||
|
}
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* DRMProcessorClientImpl::DecryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
void* DRMProcessorClientImpl::decryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv, unsigned int ivLength)
|
const unsigned char* iv, unsigned int ivLength)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (algo == ALGO_AES)
|
switch(algo)
|
||||||
|
{
|
||||||
|
case ALGO_AES:
|
||||||
{
|
{
|
||||||
switch(keyLength)
|
switch(keyLength)
|
||||||
{
|
{
|
||||||
|
@ -571,10 +587,10 @@ void* DRMProcessorClientImpl::DecryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaini
|
||||||
switch(chaining)
|
switch(chaining)
|
||||||
{
|
{
|
||||||
case CHAIN_ECB:
|
case CHAIN_ECB:
|
||||||
EVP_DecryptInit(ctx, EVP_aes_128_ecb(), key, iv);
|
ret = EVP_DecryptInit(ctx, EVP_aes_128_ecb(), key, iv);
|
||||||
break;
|
break;
|
||||||
case CHAIN_CBC:
|
case CHAIN_CBC:
|
||||||
EVP_DecryptInit(ctx, EVP_aes_128_cbc(), key, iv);
|
ret = EVP_DecryptInit(ctx, EVP_aes_128_cbc(), key, iv);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
EXCEPTION(gourou::CLIENT_BAD_CHAINING, "Unknown chaining mode " << chaining);
|
EXCEPTION(gourou::CLIENT_BAD_CHAINING, "Unknown chaining mode " << chaining);
|
||||||
|
@ -584,58 +600,81 @@ void* DRMProcessorClientImpl::DecryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaini
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
EXCEPTION(gourou::CLIENT_BAD_KEY_SIZE, "Invalid key size " << keyLength);
|
EXCEPTION(gourou::CLIENT_BAD_KEY_SIZE, "Invalid key size " << keyLength);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (algo == ALGO_RC4)
|
case ALGO_RC4:
|
||||||
{
|
{
|
||||||
if (keyLength != 16)
|
if (keyLength != 16)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_free(ctx);
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
EXCEPTION(gourou::CLIENT_BAD_KEY_SIZE, "Invalid key size " << keyLength);
|
EXCEPTION(gourou::CLIENT_BAD_KEY_SIZE, "Invalid key size " << keyLength);
|
||||||
}
|
}
|
||||||
EVP_DecryptInit(ctx, EVP_rc4(), key, iv);
|
ret = EVP_DecryptInit(ctx, EVP_rc4(), key, iv);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret <= 0)
|
||||||
|
{
|
||||||
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
|
EXCEPTION(gourou::CLIENT_CRYPT_ERROR, ERR_error_string(ERR_get_error(), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRMProcessorClientImpl::EncryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
void DRMProcessorClientImpl::encryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength)
|
unsigned char* dataOut, unsigned int* dataOutLength)
|
||||||
{
|
{
|
||||||
EVP_EncryptUpdate((EVP_CIPHER_CTX*)handler, dataOut, (int*)dataOutLength, dataIn, dataInLength);
|
int ret = EVP_EncryptUpdate((EVP_CIPHER_CTX*)handler, dataOut, (int*)dataOutLength, dataIn, dataInLength);
|
||||||
|
|
||||||
|
if (ret <= 0)
|
||||||
|
EXCEPTION(gourou::CLIENT_CRYPT_ERROR, ERR_error_string(ERR_get_error(), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRMProcessorClientImpl::EncryptFinalize(void* handler,
|
void DRMProcessorClientImpl::encryptFinalize(void* handler,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength)
|
unsigned char* dataOut, unsigned int* dataOutLength)
|
||||||
{
|
{
|
||||||
int len;
|
int len, ret;
|
||||||
EVP_EncryptFinal_ex((EVP_CIPHER_CTX*)handler, dataOut, &len);
|
|
||||||
|
ret = EVP_EncryptFinal_ex((EVP_CIPHER_CTX*)handler, dataOut, &len);
|
||||||
*dataOutLength += len;
|
*dataOutLength += len;
|
||||||
EVP_CIPHER_CTX_free((EVP_CIPHER_CTX*)handler);
|
EVP_CIPHER_CTX_free((EVP_CIPHER_CTX*)handler);
|
||||||
|
|
||||||
|
if (ret <= 0)
|
||||||
|
EXCEPTION(gourou::CLIENT_CRYPT_ERROR, ERR_error_string(ERR_get_error(), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRMProcessorClientImpl::Decrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
void DRMProcessorClientImpl::decrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv, unsigned int ivLength,
|
const unsigned char* iv, unsigned int ivLength,
|
||||||
const unsigned char* dataIn, unsigned int dataInLength,
|
const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength)
|
unsigned char* dataOut, unsigned int* dataOutLength)
|
||||||
{
|
{
|
||||||
void* handler = DecryptInit(algo, chaining, key, keyLength, iv, ivLength);
|
void* handler = decryptInit(algo, chaining, key, keyLength, iv, ivLength);
|
||||||
DecryptUpdate(handler, dataIn, dataInLength, dataOut, dataOutLength);
|
decryptUpdate(handler, dataIn, dataInLength, dataOut, dataOutLength);
|
||||||
DecryptFinalize(handler, dataOut+*dataOutLength, dataOutLength);
|
decryptFinalize(handler, dataOut+*dataOutLength, dataOutLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRMProcessorClientImpl::DecryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
void DRMProcessorClientImpl::decryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength)
|
unsigned char* dataOut, unsigned int* dataOutLength)
|
||||||
{
|
{
|
||||||
EVP_DecryptUpdate((EVP_CIPHER_CTX*)handler, dataOut, (int*)dataOutLength, dataIn, dataInLength);
|
int ret = EVP_DecryptUpdate((EVP_CIPHER_CTX*)handler, dataOut, (int*)dataOutLength, dataIn, dataInLength);
|
||||||
|
|
||||||
|
if (ret <= 0)
|
||||||
|
EXCEPTION(gourou::CLIENT_CRYPT_ERROR, ERR_error_string(ERR_get_error(), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRMProcessorClientImpl::DecryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength)
|
void DRMProcessorClientImpl::decryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength)
|
||||||
{
|
{
|
||||||
int len;
|
int len, ret;
|
||||||
EVP_DecryptFinal_ex((EVP_CIPHER_CTX*)handler, dataOut, &len);
|
|
||||||
|
ret = EVP_DecryptFinal_ex((EVP_CIPHER_CTX*)handler, dataOut, &len);
|
||||||
*dataOutLength += len;
|
*dataOutLength += len;
|
||||||
EVP_CIPHER_CTX_free((EVP_CIPHER_CTX*)handler);
|
EVP_CIPHER_CTX_free((EVP_CIPHER_CTX*)handler);
|
||||||
|
|
||||||
|
if (ret <= 0)
|
||||||
|
EXCEPTION(gourou::CLIENT_CRYPT_ERROR, ERR_error_string(ERR_get_error(), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void* DRMProcessorClientImpl::zipOpen(const std::string& path)
|
void* DRMProcessorClientImpl::zipOpen(const std::string& path)
|
||||||
|
|
|
@ -45,9 +45,9 @@ public:
|
||||||
|
|
||||||
/* 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 void digestUpdate(void* handler, unsigned char* data, unsigned int length);
|
||||||
virtual int digestFinalize(void* handler,unsigned char* digestOut);
|
virtual void digestFinalize(void* handler,unsigned char* digestOut);
|
||||||
virtual int digest(const std::string& digestName, unsigned char* data, unsigned int length, unsigned char* digestOut);
|
virtual void digest(const std::string& digestName, unsigned char* data, unsigned int length, unsigned char* digestOut);
|
||||||
|
|
||||||
/* Random interface */
|
/* Random interface */
|
||||||
virtual void randBytes(unsigned char* bytesOut, unsigned int length);
|
virtual void randBytes(unsigned char* bytesOut, unsigned int length);
|
||||||
|
@ -80,34 +80,34 @@ public:
|
||||||
unsigned char** certOut, unsigned int* certOutLength);
|
unsigned char** certOut, unsigned int* certOutLength);
|
||||||
|
|
||||||
/* Crypto interface */
|
/* Crypto interface */
|
||||||
virtual void Encrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
virtual void encrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv, unsigned int ivLength,
|
const unsigned char* iv, unsigned int ivLength,
|
||||||
const unsigned char* dataIn, unsigned int dataInLength,
|
const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength);
|
unsigned char* dataOut, unsigned int* dataOutLength);
|
||||||
|
|
||||||
virtual void* EncryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
virtual void* encryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv=0, unsigned int ivLength=0);
|
const unsigned char* iv=0, unsigned int ivLength=0);
|
||||||
|
|
||||||
|
|
||||||
virtual void EncryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
virtual void encryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength);
|
unsigned char* dataOut, unsigned int* dataOutLength);
|
||||||
virtual void EncryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength);
|
virtual void encryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength);
|
||||||
|
|
||||||
virtual void Decrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
virtual void decrypt(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv, unsigned int ivLength,
|
const unsigned char* iv, unsigned int ivLength,
|
||||||
const unsigned char* dataIn, unsigned int dataInLength,
|
const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength);
|
unsigned char* dataOut, unsigned int* dataOutLength);
|
||||||
|
|
||||||
virtual void* DecryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
virtual void* decryptInit(CRYPTO_ALGO algo, CHAINING_MODE chaining,
|
||||||
const unsigned char* key, unsigned int keyLength,
|
const unsigned char* key, unsigned int keyLength,
|
||||||
const unsigned char* iv=0, unsigned int ivLength=0);
|
const unsigned char* iv=0, unsigned int ivLength=0);
|
||||||
|
|
||||||
virtual void DecryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
virtual void decryptUpdate(void* handler, const unsigned char* dataIn, unsigned int dataInLength,
|
||||||
unsigned char* dataOut, unsigned int* dataOutLength);
|
unsigned char* dataOut, unsigned int* dataOutLength);
|
||||||
virtual void DecryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength);
|
virtual void decryptFinalize(void* handler, unsigned char* dataOut, unsigned int* dataOutLength);
|
||||||
|
|
||||||
/* ZIP Interface */
|
/* ZIP Interface */
|
||||||
virtual void* zipOpen(const std::string& path);
|
virtual void* zipOpen(const std::string& path);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user