////////////////////////////////////////////////////////////////////////// CreatePrivateKey we will attempt to get the correct passphrase three times before we give up. //////////////////////////////////////////////////////////////////////////
| 748 | // give up. |
| 749 | /////////////////////////////////////////////////////////////////////////////// |
| 750 | const cElGamalSigPrivateKey* |
| 751 | cTWUtil::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 |