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

Function GenerateKey

src/twadmin/keygeneration.cpp:131–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131bool GenerateKey(const TCHAR* keyPath, wc16_string passphrase, const cElGamalSig::KeySize key_size)
132{
133#ifndef WORDS_BIGENDIAN
134 passphrase.swapbytes();
135#endif
136
137#ifdef DEBUG
138 // test reading in the keys
139 wc16_string passphrase_copy = passphrase.c_str();
140 wc16_string passphrase_copy2 = passphrase.c_str();
141#endif
142
143 iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL,
144 TSS_GetString(cTWAdmin, twadmin::STR_GENERATING_KEYS).c_str());
145
146 fflush(stdout);
147
148 tGK gk;
149 gk.passphrase = (int8*)passphrase.data();
150 gk.passphraseLen = passphrase.length() * sizeof(WCHAR16);
151 gk.keyPath = keyPath;
152
153 GeneratePublicPrivateKeys(&gk, key_size);
154
155 if (gk.retValue != tGK::OK)
156 {
157 switch (gk.retValue)
158 {
159 case tGK::FILE_WRITE_ERROR:
160 TCERR << std::endl
161 << TSS_GetString(cTWAdmin, twadmin::STR_ERR2_KEYGEN_FILEWRITE) << gk.keyPath << std::endl;
162 break;
163
164 default:
165 TCERR << std::endl
166 << TSS_GetString(cTWAdmin, twadmin::STR_ERR2_KEYGEN) << gk.keyPath
167 << TSS_GetString(cTWAdmin, twadmin::STR_ERR2_KEYGEN2) << std::endl;
168 break;
169 }
170
171 return false;
172 }
173
174#ifdef DEBUG
175 // test reading in the keys
176 cKeyFile keyfile;
177
178 keyfile.ReadFile(keyPath);
179
180 ASSERT(keyfile.GetPrivateKey((int8*)passphrase_copy.data(), passphrase_copy.length() * sizeof(WCHAR16)) != 0);
181 keyfile.ReleasePrivateKey();
182
183 //keyfile.WriteFile(_T("tripwire2.key"));
184
185 // test memory writing
186 int8 mem[4000];
187 ASSERT(4000 > keyfile.GetWriteLen());
188

Callers 1

ExecuteMethod · 0.85

Calls 12

swapbytesMethod · 0.80
c_strMethod · 0.80
NotifyMethod · 0.80
dataMethod · 0.80
ReadFileMethod · 0.80
GetPrivateKeyMethod · 0.80
ReleasePrivateKeyMethod · 0.80
WriteMemMethod · 0.80
ReadMemMethod · 0.80
lengthMethod · 0.45
GetWriteLenMethod · 0.45

Tested by

no test coverage detected