Try to decrypt the file using the given key. If thorough is true then the entire file is read into memory. Returns true if decryption was successful.
| 141 | // the entire file is read into memory. Returns true if decryption was |
| 142 | // successful. |
| 143 | bool cFileManipulator::TestDecryption(const cElGamalSigPublicKey& key, bool thorough) |
| 144 | { |
| 145 | // TODO: pay attention to thorough flag. For now we will just always act thoroughly. |
| 146 | |
| 147 | ASSERT(mbInit); |
| 148 | if (!mbInit) |
| 149 | { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | bool fError = false; |
| 154 | |
| 155 | // "turn down" the verbosity of iUserNotify to V_NORMAL it it is V_VERBOSE to make output a little cleaner |
| 156 | bool fChangedVerbosity = false; |
| 157 | int savedVerbosity = iUserNotify::GetInstance()->GetVerboseLevel(); |
| 158 | if (savedVerbosity == iUserNotify::V_VERBOSE) |
| 159 | { |
| 160 | iUserNotify::GetInstance()->SetVerboseLevel(iUserNotify::V_NORMAL); |
| 161 | fChangedVerbosity = true; |
| 162 | } |
| 163 | |
| 164 | try |
| 165 | { |
| 166 | if (mFileHeader.GetID() == cFCODatabaseFile::GetFileHeaderID()) |
| 167 | { |
| 168 | cFCODatabaseFile db; |
| 169 | bool encrypted; |
| 170 | cTWUtil::ReadDatabase(mFileName.c_str(), db, &key, encrypted); |
| 171 | } |
| 172 | else if (mFileHeader.GetID() == cFCOReport::GetFileHeaderID()) |
| 173 | { |
| 174 | cFCOReport rep; |
| 175 | cFCOReportHeader reph; |
| 176 | bool encrypted; |
| 177 | cTWUtil::ReadReport(mFileName.c_str(), reph, rep, &key, true, encrypted); |
| 178 | } |
| 179 | else if (mFileHeader.GetID() == cConfigFile::GetFileHeaderID()) |
| 180 | { |
| 181 | // read the embedded key from config file and see if it is the same |
| 182 | // as the public key passed in. |
| 183 | cMemoryArchive memArch; |
| 184 | TSTRING configText; //not used |
| 185 | cTWUtil::ReadConfigText(mFileName.c_str(), configText, &memArch); |
| 186 | memArch.Seek(0, cBidirArchive::BEGINNING); |
| 187 | |
| 188 | // only do the test if there is baggage (indicating the cfg file is encrypted) |
| 189 | if (memArch.Length() > 0) |
| 190 | { |
| 191 | // create the two public keys... |
| 192 | cElGamalSigPublicKey pubKey(memArch.GetMemory()); |
| 193 | |
| 194 | // compare the two .... |
| 195 | if (!pubKey.IsEqual(key)) |
| 196 | throw ePoly(); |
| 197 | } |
| 198 | } |
| 199 | else if (mFileHeader.GetID() == cPolicyFile::GetFileHeaderID()) |
| 200 | { |
no test coverage detected