[Release] wrt-commons_0.2.139
[framework/web/wrt-commons.git] / modules / encryption / src / resource_decryption.cpp
index 6b9f8e8..c599e64 100644 (file)
  */
 #include <stddef.h>
 #include <dpl/encryption/resource_decryption.h>
-#ifdef Try
-#undef Try
-#endif
-#include <FSecSecretKey.h>
-#include <security/FSec_DeviceKeyGenerator.h>
 
 #include <fcntl.h>
 #include <string>
 #include <dpl/log/log.h>
 #include <dpl/exception.h>
+#include <dukgen.h>
 
 namespace {
 #define BITS_SIZE 128
 #define KEY_SIZE 16
 }
-
-namespace WRTDecryptor{
+namespace WRTDecryptor {
 ResourceDecryptor::ResourceDecryptor()
 {
     LogDebug("Started Decryption");
@@ -50,40 +45,23 @@ ResourceDecryptor::ResourceDecryptor(std::string userKey)
 }
 
 ResourceDecryptor::~ResourceDecryptor()
-{
-}
+{}
 
 void ResourceDecryptor::SetDecryptionKey(std::string userKey)
 {
     if (userKey.empty()) {
         return;
     }
-    using namespace Tizen;
-    using namespace Tizen::Base;
 
-    Tizen::Base::String appId;
-    appId.Format(userKey.size(), L"%s", userKey.c_str());
-    Tizen::Security::ISecretKey* pSecretKey =
-        Tizen::Security::_DeviceKeyGenerator::GenerateDeviceKeyN(appId, KEY_SIZE);
+    char* pKey = GetDeviceUniqueKey(const_cast<char*>(userKey.c_str()),
+            userKey.size(), KEY_SIZE);
 
-    Tizen::Base::ByteBuffer* bf = pSecretKey->GetEncodedN();
-    unsigned char *key = new unsigned char[KEY_SIZE+1];
+    unsigned char *key = reinterpret_cast<unsigned char*>(pKey);
 
-    int i=0;
-    while(bf->HasRemaining()) {
-        byte b;
-        bf->GetByte(b);
-        key[i] = b;
-        i++;
-    }
-    key[KEY_SIZE] = '\n';
-
-    if ( 0 > AES_set_decrypt_key(key, BITS_SIZE, &m_decKey)) {
-        delete key;
+    if (0 > AES_set_decrypt_key(key, BITS_SIZE, &m_decKey)) {
         ThrowMsg(ResourceDecryptor::Exception::GetDecKeyFailed,
-                "Failed to create decryption key");
+                 "Failed to create decryption key");
     }
-    delete key;
 }
 
 AES_KEY* ResourceDecryptor::GetDecryptionKey()
@@ -92,17 +70,18 @@ AES_KEY* ResourceDecryptor::GetDecryptionKey()
 }
 
 void ResourceDecryptor::GetDecryptedChunk(unsigned char*
-        inBuf, unsigned char* decBuf, size_t inBufSize)
+                                          inBuf,
+                                          unsigned char* decBuf,
+                                          size_t inBufSize)
 {
     Assert(decBuf);
     if (decBuf == NULL) {
         ThrowMsg(ResourceDecryptor::Exception::EncryptionFailed,
-                "Failed to Get Decryption Chunk");
+                 "Failed to Get Decryption Chunk");
     }
-    unsigned char ivec[16] = {0, };
+    unsigned char ivec[16] = { 0, };
 
     AES_cbc_encrypt(inBuf, decBuf, inBufSize, &m_decKey, ivec, AES_DECRYPT);
     LogDebug("Success decryption");
 }
-
 } //namespace WRTDecryptor