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

Method CreatePrivateKey

src/tw/twutil.cpp:750–827  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// CreatePrivateKey we will attempt to get the correct passphrase three times before we give up. //////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

748// give up.
749///////////////////////////////////////////////////////////////////////////////
750const cElGamalSigPrivateKey*
751cTWUtil::CreatePrivateKey(cKeyFile& keyFile, const WCHAR16* usePassphrase, KeyType keyType, int nSecs)
752{
753 ASSERT(keyType == KEY_SITE || keyType == KEY_LOCAL || keyType == KEY_PROVIDED);
754
755 const cElGamalSigPrivateKey* pPrivateKey = NULL;
756 wc16_string passphrase;
757
758 if (usePassphrase)
759 {
760 // sleep to hinder brute force (dictionary, etc.) attacks
761 iFSServices::GetInstance()->Sleep(nSecs);
762
763 passphrase = usePassphrase;
764
765#ifndef WORDS_BIGENDIAN
766 passphrase.swapbytes();
767#endif
768
769 pPrivateKey = keyFile.GetPrivateKey((int8*)passphrase.data(), passphrase.length() * sizeof(WCHAR16));
770
771 if (pPrivateKey)
772 return pPrivateKey;
773
774 // if we got here, then a passphrase was provided on the command line that
775 // was not correct; this is an error condition.
776 //
777 if (keyType == KEY_LOCAL)
778 throw eTWUtilBadPassLocal();
779 else
780 throw eTWUtilBadPassSite();
781 }
782
783 int count = 0;
784 while (count < 3)
785 {
786 cTWUtil::NoEcho noEcho;
787 switch (keyType)
788 {
789 case KEY_LOCAL:
790 TCOUT << TSS_GetString(cTW, tw::STR_ENTER_LOCAL_PASSPHRASE);
791 break;
792 case KEY_SITE:
793 TCOUT << TSS_GetString(cTW, tw::STR_ENTER_SITE_PASSPHRASE);
794 break;
795 case KEY_PROVIDED:
796 default:
797 TCOUT << TSS_GetString(cTW, tw::STR_ENTER_PROVIDED_PASSPHRASE);
798 break;
799 }
800
801 cTWUtil::GetString(passphrase);
802 TCOUT << std::endl;
803
804 // sleep to hinder brute force (dictionary, etc.) attacks
805 iFSServices::GetInstance()->Sleep(nSecs);
806
807#ifndef WORDS_BIGENDIAN

Callers

nothing calls this directly

Calls 8

ePolyClass · 0.85
SleepMethod · 0.80
swapbytesMethod · 0.80
GetPrivateKeyMethod · 0.80
dataMethod · 0.80
AquireKeyMethod · 0.80
lengthMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected