MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / TestDecryption

Method TestDecryption

src/tw/filemanipulator.cpp:143–217  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

141// the entire file is read into memory. Returns true if decryption was
142// successful.
143bool 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 {

Callers 1

ExecuteMethod · 0.80

Calls 9

ePolyClass · 0.85
GetVerboseLevelMethod · 0.80
SetVerboseLevelMethod · 0.80
GetIDMethod · 0.80
c_strMethod · 0.80
LengthMethod · 0.80
GetMemoryMethod · 0.80
SeekMethod · 0.45
IsEqualMethod · 0.45

Tested by

no test coverage detected