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

Function ChangePassphrase

src/twadmin/twadmincl.cpp:2059–2094  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2057// cTWAModeChangePassphrases
2058
2059static bool ChangePassphrase(const TCHAR* keyPath, wc16_string passphraseOld, wc16_string passphrase)
2060{
2061 // in order to leave original password data intact upon return,
2062 // we must allocate a BIGENDIAN copy
2063 // and delete it before we return.
2064 // auto_ptr does not help (won't work with arrays).
2065 size_t passphraseLenOld = passphraseOld.length() * sizeof(WCHAR16);
2066 size_t passphraseLen = passphrase.length() * sizeof(WCHAR16);
2067 int8* passphraseCopyOld = new int8[passphraseLenOld];
2068 int8* passphraseCopy = new int8[passphraseLen];
2069#ifdef WORDS_BIGENDIAN
2070 memcpy(passphraseCopyOld, passphraseOld.data(), passphraseLenOld);
2071 memcpy(passphraseCopy, passphrase.data(), passphraseLen);
2072#else
2073 swab(passphraseOld.data(), passphraseCopyOld, passphraseLenOld);
2074 swab(passphrase.data(), passphraseCopy, passphraseLen);
2075#endif
2076
2077 bool result;
2078 try
2079 {
2080 cKeyFile keyfile;
2081 keyfile.ReadFile(keyPath);
2082 keyfile.ChangePassphrase(passphraseCopyOld, passphraseLenOld, passphraseCopy, passphraseLen);
2083 keyfile.WriteFile(keyPath);
2084 result = true;
2085 }
2086 catch (eKeyFile& e)
2087 {
2088 cTWUtil::PrintErrorMsg(e);
2089 result = false;
2090 }
2091 delete [] passphraseCopyOld;
2092 delete [] passphraseCopy;
2093 return result;
2094}
2095
2096class cTWAModeChangePassphrases : public cTWAModeCommon
2097{

Callers 1

ExecuteMethod · 0.85

Calls 6

swabFunction · 0.85
dataMethod · 0.80
ReadFileMethod · 0.80
ChangePassphraseMethod · 0.80
WriteFileMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected