627 std::lock_guard<std::mutex> lock(m_Mutex);
629 std::string str_display(
630 nullptr != szDisplay ? szDisplay :
"(Display string was blank.)");
632 const char* szFunc =
"OTCachedKey::GetMasterPassword";
639 if (
nullptr != m_pMasterPassword) {
641 <<
": Master password was available. (Returning it now.)\n";
643 theOutput = *m_pMasterPassword;
647 otInfo << szFunc <<
": Master password wasn't loaded. Instantiating...\n";
699 bool bReturnVal =
false;
718 OTPassword* pDerivedKey =
nullptr;
719 std::unique_ptr<OTPassword> theDerivedAngel;
721 if (
nullptr == m_pSymmetricKey) {
722 m_pSymmetricKey =
new OTSymmetricKey;
728 otWarn << szFunc <<
": Master key didn't exist. Need to collect a "
729 "passphrase from the user, "
730 "so we can generate a master key...\n ";
741 const OTIdentifier idCachedKey(
743 const OTString strCachedKeyHash(
762 const bool bFoundOnKeyring =
772 *pDerivedKey, *m_pMasterPassword);
815 otWarn << szFunc <<
": Finished calling "
816 "m_pSymmetricKey->GetRawKeyFromDerivedKey "
818 theOutput = *m_pMasterPassword;
819 theDerivedAngel.reset(
826 otOut << szFunc <<
": Unable to unlock master key using "
827 "derived key found on system keyring.\n";
829 pDerivedKey =
nullptr;
838 <<
": Unable to find derived key on system keyring.\n";
849 if (
nullptr == pDerivedKey)
865 OTPassword passwordDefault;
866 passwordDefault.zeroMemory();
867 passwordDefault.setPassword(
868 default_password.c_str(),
869 static_cast<int32_t
>(default_password.length()));
871 OTPassword passUserInput;
872 passUserInput.zeroMemory();
873 OTPasswordData thePWData(str_display.c_str(), &passUserInput,
890 nullptr, 0, bVerifyTwice ? 1 : 0,
891 static_cast<void*>(&thePWData))) {
892 otErr << __FUNCTION__ <<
": Failed to get password from user!";
898 bool bUsingDefaultPassword =
false;
900 if (4 > std::string(passUserInput.getPassword()).length()) {
901 otOut <<
"\n Password entered was less than 4 characters "
902 "int64_t! This is NOT secure!!\n"
903 "... Assuming password is for testing only... "
904 "setting to default password: "
906 bUsingDefaultPassword =
true;
914 bUsingDefaultPassword ? passwordDefault : passUserInput,
921 if (
nullptr != pDerivedKey)
922 theDerivedAngel.reset(pDerivedKey);
924 otErr << __FUNCTION__ <<
": FYI: Derived key is still nullptr "
926 "OTSymmetricKey::GenerateKey.\n";
958 if (
nullptr == pDerivedKey) {
959 otOut <<
"\n\n" << __FUNCTION__
960 <<
": Please enter your password.\n\n";
967 static_cast<void*>(&thePWData))) {
968 otErr <<
"\n\n" << __FUNCTION__
969 <<
": Failed to get password from user!\n\n";
975 if (
nullptr != pDerivedKey)
break;
977 otOut <<
"\n\n" << __FUNCTION__
978 <<
": Wrong Password, Please Try Again.\n\n";
983 otOut <<
"\n Please enter your current password twice, (not a "
984 "new password!!) \n";
987 nullptr, 0,
true, static_cast<void*>(&thePWData))) {
988 otErr << __FUNCTION__
989 <<
": Failed to get password from user!";
998 theDerivedAngel.reset(pDerivedKey);
1000 otWarn << szFunc <<
": FYI, symmetric key was already generated. "
1001 "Proceeding to try and use it...\n";
1021 <<
": Calling m_pSymmetricKey->GetRawKeyFromPassphrase()...\n";
1045 passUserInput, *m_pMasterPassword, pDerivedKey);
1047 otInfo << szFunc <<
": Finished calling "
1048 "m_pSymmetricKey->GetRawKeyFromPassphrase "
1050 theOutput = *m_pMasterPassword;
1055 const std::string str_display(
1056 nullptr != szDisplay ? szDisplay
1057 :
"(Display string was blank.)");
1059 const OTIdentifier idCachedKey(*m_pSymmetricKey);
1060 const OTString strCachedKeyHash(
1070 otWarn << szFunc <<
": Strange: Problem with either: "
1071 "IsUsingSystemKeyring"
1075 "or: (nullptr != pDerivedKey) ("
1076 << ((
nullptr != pDerivedKey) ?
"true" :
"false")
1084 <<
": m_pSymmetricKey->GetRawKeyFromPassphrase() failed.\n";
1087 otErr << szFunc <<
": bGenerated is still false, even after trying "
1088 "to generate it, yadda yadda yadda.\n";
1097 #if defined(OT_CRYPTO_USING_OPENSSL)
1099 #if defined(OPENSSL_THREADS)
1102 otInfo << szFunc <<
": Starting thread for Master Key...\n";
1104 std::shared_ptr<OTCachedKey>* pthreadSharedPtr =
1105 new std::shared_ptr<OTCachedKey>(mySharedPtr);
1108 static_cast<void*>(pthreadSharedPtr));
1114 <<
": WARNING: OpenSSL was NOT compiled with thread support. "
1115 "(Master Key will not expire.)\n";
1119 #elif defined(OT_CRYPTO_USING_GPG)
1121 otErr << szFunc <<
": WARNING: OT was compiled for GPG, which is not "
1123 "(Master Key will not expire.)\n";
1125 #else // OT_CRYPTO_USING_ ... nothing?
1128 <<
": WARNING: OT wasn't compiled for any crypto library "
1129 "(such as OpenSSL or GPG). Which is very strange, and I doubt "
1130 "things will even work, with it in this condition. (Plus, "
1132 "Key will not expire.)\n";
1134 #endif // if defined(OT_CRYPTO_USING_OPENSSL), elif
1138 else if (m_nTimeoutSeconds != (-1)) {
1139 if (
nullptr != m_pMasterPassword) {
1140 OTPassword* pMasterPassword = m_pMasterPassword;
1142 m_pMasterPassword =
nullptr;
1144 delete pMasterPassword;
1145 pMasterPassword =
nullptr;
static EXPORT OTCrypto * It()
EXPORT OTPassword * CalculateNewDerivedKeyFromPassphrase(const OTPassword &thePassphrase)
virtual OTPassword * InstantiateBinarySecret() const =0
#define OT_DEFAULT_PASSWORD
EXPORT void LowLevelReleaseThread()
EXPORT bool IsUsingSystemKeyring() const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool GetRawKeyFromPassphrase(const OTPassword &thePassphrase, OTPassword &theRawKeyOutput, OTPassword *pDerivedKey=nullptr) const
EXPORT bool GetRawKeyFromDerivedKey(const OTPassword &theDerivedKey, OTPassword &theRawKeyOutput) const
EXPORT bool GenerateKey(const OTPassword &thePassphrase, OTPassword **ppDerivedKey=nullptr)
OTLOG_IMPORT OTLogStream otInfo
EXPORT OTPassword * CalculateDerivedKeyFromPassphrase(const OTPassword &thePassphrase, bool bCheckForHashCheck=true) const
static EXPORT void ThreadTimeout(void *pArg)
OTLOG_IMPORT OTLogStream otWarn
OTLOG_IMPORT OTLogStream otErr
static EXPORT OT_OPENSSL_CALLBACK * GetPasswordCallback()
static EXPORT bool RetrieveSecret(const OTString &strUser, OTPassword &thePassword, const std::string &str_display)
bool HasHashCheck() const
static EXPORT bool StoreSecret(const OTString &strUser, const OTPassword &thePassword, const std::string &str_display)