2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
4 // Licensed under the Apache License, Version 2.0 (the License);
\r
5 // you may not use this file except in compliance with the License.
\r
6 // You may obtain a copy of the License at
\r
8 // http://www.apache.org/licenses/LICENSE-2.0
\r
10 // Unless required by applicable law or agreed to in writing, software
\r
11 // distributed under the License is distributed on an "AS IS" BASIS,
\r
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 // See the License for the specific language governing permissions and
\r
14 // limitations under the License.
\r
18 * @file FIo_SecureIoUtil.h
\r
19 * @brief This is the header file for the %_SecureIoUilt class.
\r
21 * This header file contains the declarations of the %_SeureIoUtil class.
\r
24 #ifndef _FIO_INTERNAL_SECUREIOUTIL_H_
\r
25 #define _FIO_INTERNAL_SECUREIOUTIL_H_
\r
27 #include <FBaseByteBuffer.h>
\r
28 #include <FSecCryptoTypes.h>
\r
29 #include <FIo_NormalFile.h>
\r
31 namespace Tizen { namespace Io
\r
34 extern const char SECURE_FILE_HEADER_STRING[];
\r
35 extern const char SECURE_REG_HEADER_STRING[];
\r
37 const int FIO_LEN_4K = 4096;
\r
38 const int CIPHER_BLOCK_SIZE = 400*1024;
\r
39 const int CIPHER_BLOCK_HEADER_SIZE = 3;
\r
40 const int SECURE_FILE_HEADER_STRING_SIZE = 16;
\r
41 const int SECURE_REG_HEADER_STRING_SIZE = 20;
\r
42 const int SECURE_FILE_HEADER_SIZE_V1 = 34;
\r
43 const int SECURE_REG_HEADER_SIZE_V1 = 38;
\r
44 const int MAX_BLOCK_INDEX_LEN = 3;
\r
45 const int ONE_BLOCK_SIZE = 16;
\r
46 const int ENCRYPT_KEY_LEN = 16;
\r
47 const int SECURE_IO_STATIC_BIN_LEN = 8;
\r
48 const int SECURE_IO_FLAG_SIZE = 1;
\r
49 const int SECURE_IO_INDEX_SIZE = 1;
\r
50 const int SECURE_IO_LOF_SIZE = 4;
\r
51 const int SECURE_IO_2_BYTES = 2;
\r
52 const int SECURE_IO_10_BYTES = 10;
\r
53 const int SECURE_IO_12_BYTES = 12;
\r
54 const int SQLITE_HEADER_SIZE = 16;
\r
55 const int SQLITE_FORMAT_STR_SIZE = 15;
\r
56 const int SECURE_IO_HEX_64 = 0x64;
\r
57 const int SECURE_IO_MAGIC_NUMBER_SIZE = 4;
\r
62 DATA_FORMAT_UNDEFINED = 0,
\r
69 FLAG_STATE_NONE = 0,
\r
77 DATABASE_MODE_NONE = 0,
\r
78 DATABASE_MODE_NORMAL,
\r
79 DATABASE_MODE_SECURE,
\r
80 DATABASE_MODE_ERROR,
\r
88 static result SaveLengthOfFile(_NormalFile* pNormalFile);
\r
90 static result InsertSecureFileHeader(_NormalFile* pNormalFile);
\r
92 static result SelectCipherBlock(_NormalFile* pNormalFile, long virtualFilePointer, int* pPosition);
\r
94 static result MakeCipherBlock(byte* pData, int dataSize, byte** ppEncryptedData, int* pEncryptedDataSize, const Tizen::Base::ByteBuffer& key);
\r
96 static result WriteDataInCipherBlock(_NormalFile* pNormalFile, int dataPosition, bool eofSet, int dataSize, byte* pData, const Tizen::Base::ByteBuffer& key);
\r
98 static result ReadDataFromCipherBlock(_NormalFile* pNormalFile, int dataPosition, int bufferSize, byte* pData, _DataFormat dataMode, int* readItems, const Tizen::Base::ByteBuffer& key);
\r
100 static result GetDataLengh(_NormalFile* pNormalFile, long* dataLength);
\r
102 static result CheckSecureFileHeader(const Tizen::Base::String& filePath, const Tizen::Base::ByteBuffer* pSecretKey);
\r
104 static result CheckSecureRegistryHeader(byte** pSecureRegistryHeader, int* pHeaderLen, const Tizen::Base::String strFilePathPath, bool secureMode);
\r
106 static result MakeCipherBlockReplica(_NormalFile* pNormalFile, const Tizen::Base::String filePath, int dataPosition, int dataSize);
\r
108 static result RestoreCorruptBlock(_NormalFile* pNormalFile, const Tizen::Base::String filePath);
\r
110 static result DeleteBlockReplica(_NormalFile* pNormalFile, const Tizen::Base::String filePath);
\r
112 static result SetFlag(_NormalFile* pNormalFile, _FlagState flag);
\r
114 static result SetRegistryFlag(void* pFileSecure, _FlagState flag);
\r
116 static result CheckFlag(_NormalFile* pNormalFile, _FlagState* pFlag);
\r
118 static _FlagState CheckRegistryFlag(byte* pHeader);
\r
120 static const Tizen::Base::String MakeRegistryReplica(const Tizen::Base::String filePath, byte* pNameIndex);
\r
122 static result DeleteRegistryReplica(byte *pHeader, const Tizen::Base::String filePath);
\r
124 static result LoadRegistryReplica(byte** pHeader, int* pHeaderLen, const Tizen::Base::String filePath);
\r
126 static bool IsEmpty(char* pPath);
\r
128 static bool DetectNewLine(byte* pData, int readSize, int preReadSize, int* pTerminationCur, int* newLineSize);
\r
130 static bool IsNormalDatabase(_DatabaseMode mode);
\r
132 static bool IsSecureDatabase(_DatabaseMode mode);
\r
134 static bool IsEndOfFile(_NormalFile* pNormalFile);
\r
136 static _DatabaseMode GetDatabaseMode(char* pStrPhysicalDbPath);
\r
138 static byte* GenerateDatabaseKeyN(const Tizen::Base::ByteBuffer* pUserKey);
\r
140 static bool IsEmpty(const Tizen::Base::String& filePath);
\r
142 static Tizen::Base::ByteBuffer* GetSecureKeyN(const Tizen::Base::ByteBuffer* pKey = null);
\r
144 static Tizen::Base::ByteBuffer* DoCipherAesN(const Tizen::Base::String transformation, const Tizen::Base::ByteBuffer& input,const Tizen::Base::ByteBuffer& key, Tizen::Security::Crypto::CipherOperation encMode);
\r
149 #endif //_FIO_INTERNAL_SECUREIOUTIL_H_
\r