2 // Open Service Platform
\r
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
5 // Licensed under the Apache License, Version 2.0 (the License);
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://www.apache.org/licenses/LICENSE-2.0
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an "AS IS" BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
19 * @file FIo_SecureIoUtil.h
\r
20 * @brief This is the header file for the %_SecureIoUilt class.
\r
22 * This header file contains the declarations of the %_SeureIoUtil class.
\r
25 #ifndef _FIO_INTERNAL_SECUREIOUTIL_H_
\r
26 #define _FIO_INTERNAL_SECUREIOUTIL_H_
\r
28 #include <FBaseByteBuffer.h>
\r
29 #include <FSecCryptoTypes.h>
\r
30 #include <FIo_NormalFile.h>
\r
32 namespace Tizen { namespace Io
\r
35 extern const char SECURE_FILE_HEADER_STRING[];
\r
36 extern const char SECURE_REG_HEADER_STRING[];
\r
38 const int FIO_LEN_4K = 4096;
\r
39 const int CIPHER_BLOCK_SIZE = 400*1024;
\r
40 const int CIPHER_BLOCK_HEADER_SIZE = 3;
\r
41 const int SECURE_FILE_HEADER_STRING_SIZE = 16;
\r
42 const int SECURE_REG_HEADER_STRING_SIZE = 20;
\r
43 const int SECURE_FILE_HEADER_SIZE_V1 = 34;
\r
44 const int SECURE_REG_HEADER_SIZE_V1 = 38;
\r
45 const int MAX_BLOCK_INDEX_LEN = 3;
\r
46 const int ONE_BLOCK_SIZE = 16;
\r
47 const int ENCRYPT_KEY_LEN = 16;
\r
48 const int SECURE_IO_STATIC_BIN_LEN = 8;
\r
49 const int SECURE_IO_FLAG_SIZE = 1;
\r
50 const int SECURE_IO_INDEX_SIZE = 1;
\r
51 const int SECURE_IO_LOF_SIZE = 4;
\r
52 const int SECURE_IO_2_BYTES = 2;
\r
53 const int SECURE_IO_10_BYTES = 10;
\r
54 const int SECURE_IO_12_BYTES = 12;
\r
55 const int SQLITE_HEADER_SIZE = 16;
\r
56 const int SQLITE_FORMAT_STR_SIZE = 15;
\r
57 const int SECURE_IO_HEX_64 = 0x64;
\r
58 const int SECURE_IO_MAGIC_NUMBER_SIZE = 4;
\r
63 DATA_FORMAT_UNDEFINED = 0,
\r
70 FLAG_STATE_NONE = 0,
\r
78 DATABASE_MODE_NONE = 0,
\r
79 DATABASE_MODE_NORMAL,
\r
80 DATABASE_MODE_SECURE,
\r
81 DATABASE_MODE_ERROR,
\r
89 static result SaveLengthOfFile(_NormalFile* pNormalFile);
\r
91 static result InsertSecureFileHeader(_NormalFile* pNormalFile);
\r
93 static result SelectCipherBlock(_NormalFile* pNormalFile, long virtualFilePointer, int* pPosition);
\r
95 static result MakeCipherBlock(byte* pData, int dataSize, byte** ppEncryptedData, int* pEncryptedDataSize, const Tizen::Base::ByteBuffer& key);
\r
97 static result WriteDataInCipherBlock(_NormalFile* pNormalFile, int dataPosition, bool eofSet, int dataSize, byte* pData, const Tizen::Base::ByteBuffer& key);
\r
99 static result ReadDataFromCipherBlock(_NormalFile* pNormalFile, int dataPosition, int bufferSize, byte* pData, _DataFormat dataMode, int* readItems, const Tizen::Base::ByteBuffer& key);
\r
101 static result GetDataLengh(_NormalFile* pNormalFile, long* dataLength);
\r
103 static result CheckSecureFileHeader(const Tizen::Base::String& filePath, const Tizen::Base::ByteBuffer* pSecretKey);
\r
105 static result CheckSecureRegistryHeader(byte** pSecureRegistryHeader, int* pHeaderLen, const Tizen::Base::String strFilePathPath, bool secureMode);
\r
107 static result MakeCipherBlockReplica(_NormalFile* pNormalFile, const Tizen::Base::String filePath, int dataPosition, int dataSize);
\r
109 static result RestoreCorruptBlock(_NormalFile* pNormalFile, const Tizen::Base::String filePath);
\r
111 static result DeleteBlockReplica(_NormalFile* pNormalFile, const Tizen::Base::String filePath);
\r
113 static result SetFlag(_NormalFile* pNormalFile, _FlagState flag);
\r
115 static result SetRegistryFlag(void* pFileSecure, _FlagState flag);
\r
117 static result CheckFlag(_NormalFile* pNormalFile, _FlagState* pFlag);
\r
119 static _FlagState CheckRegistryFlag(byte* pHeader);
\r
121 static const Tizen::Base::String MakeRegistryReplica(const Tizen::Base::String filePath, byte* pNameIndex);
\r
123 static result DeleteRegistryReplica(byte *pHeader, const Tizen::Base::String filePath);
\r
125 static result LoadRegistryReplica(byte** pHeader, int* pHeaderLen, const Tizen::Base::String filePath);
\r
127 static bool IsEmpty(char* pPath);
\r
129 static bool DetectNewLine(byte* pData, int readSize, int preReadSize, int* pTerminationCur, int* newLineSize);
\r
131 static bool IsNormalDatabase(_DatabaseMode mode);
\r
133 static bool IsSecureDatabase(_DatabaseMode mode);
\r
135 static bool IsEndOfFile(_NormalFile* pNormalFile);
\r
137 static _DatabaseMode GetDatabaseMode(char* pStrPhysicalDbPath);
\r
139 static byte* GenerateDatabaseKeyN(const Tizen::Base::ByteBuffer* pUserKey);
\r
141 static bool IsEmpty(const Tizen::Base::String& filePath);
\r
143 static Tizen::Base::ByteBuffer* GetSecureKeyN(const Tizen::Base::ByteBuffer* pKey = null);
\r
145 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
150 #endif //_FIO_INTERNAL_SECUREIOUTIL_H_
\r