// This version base64-DECODES the ascii-armored string passed in, // and then sets the decoded plaintext string onto this object. OTString::OTString(const OTASCIIArmor & strValue) : m_lLength(0), m_lPosition(0), m_strBuffer(NULL) { // Initialize(); if (strValue.Exists()) strValue.GetString(*this); }
// This version base64-DECODES the ascii-armored string passed in, // and then sets the decoded plaintext string onto this object. OTString::OTString(const OTASCIIArmor & strValue) { Initialize(); if (strValue.Exists()) strValue.GetString(*this); }
// This version base64-DECODES the ascii-armored string passed in, // and then sets the decoded plaintext string onto this object. String::String(const OTASCIIArmor& strValue) : length_(0) , position_(0) , data_(nullptr) { // Initialize(); if (strValue.Exists()) strValue.GetString(*this); }
OTCachedKey::OTCachedKey(const OTASCIIArmor & ascCachedKey) : m_pThread(NULL), m_nTimeoutSeconds(OTCachedKey::It()->GetTimeoutSeconds()), m_pMasterPassword(NULL), // This is created in GetMasterPassword, and destroyed by a timer thread sometime soon after. m_bUse_System_Keyring(OTCachedKey::It()->IsUsingSystemKeyring()), // this master key instance will decide to use the system keyring based on what the global master key instance is set to do. (So we get the same settings from config file, etc.) m_pSymmetricKey(NULL), // OTServer OR OTWallet owns this key, and sets this pointer. It's the encrypted form of s_pMasterPassword. m_bPaused(false) { OT_ASSERT(ascCachedKey.Exists()); this->SetCachedKey(ascCachedKey); }
int OTPurse::ProcessXMLNode(irr::io::IrrXMLReader*& xml) { if (!strcmp("purse", xml->getNodeName())) { OTString strServerID, strUserID, strAssetID, strTotalValue; m_strVersion = xml->getAttributeValue("version"); strUserID = xml->getAttributeValue("userID"); strServerID = xml->getAttributeValue("serverID"); strAssetID = xml->getAttributeValue("assetTypeID"); strTotalValue = xml->getAttributeValue("totalValue"); m_AssetID.SetString(strAssetID); m_UserID.SetString(strUserID); m_ServerID.SetString(strServerID); m_lTotalValue = 0; if (strTotalValue.Exists() && (atol(strTotalValue.Get()) > 0)) m_lTotalValue = atol(strTotalValue.Get()); OTLog::vOutput(4, "Loaded purse...\n ServerID: %s\n UserID: %s\n Asset ID: %s\n----------\n", strServerID.Get(), strUserID.Get(), strAssetID.Get()); return 1; } else if (!strcmp("token", xml->getNodeName())) { OTASCIIArmor * pArmor = new OTASCIIArmor; OT_ASSERT(NULL != pArmor); if (!LoadEncodedTextField(xml, *pArmor) || !pArmor->Exists()) { OTLog::Error("Error in OTPurse::ProcessXMLNode: token field without value.\n"); delete pArmor; pArmor = NULL; return (-1); // error condition } else { m_dequeTokens.push_front(pArmor); } return 1; } return 0; }
// Called by OTServer or OTWallet, or whatever instantiates those. // void OTCachedKey::SetCachedKey(const OTASCIIArmor & ascCachedKey) { tthread::lock_guard<tthread::mutex> lock(m_Mutex); // Multiple threads can't get inside here at the same time. OT_ASSERT(ascCachedKey.Exists()); // ---------------------------------------- if (NULL != m_pSymmetricKey) { OTLog::Error("OTCachedKey::SetCachedKey: Warning: This was already set. (Re-setting.)\n"); delete m_pSymmetricKey; m_pSymmetricKey = NULL; } // ----------------------------------------- m_pSymmetricKey = new OTSymmetricKey; OT_ASSERT(NULL != m_pSymmetricKey); // ---------------------------------- //const bool bSerialized = m_pSymmetricKey->SerializeFrom(ascCachedKey); }
// static bool OTKeyring::Windows_RetrieveSecret(const OTString& strUser, OTPassword& thePassword, const std::string& str_display) { OT_ASSERT(strUser.Exists()); OTString strFoldername("win32_data"); // todo hardcoding. OTASCIIArmor ascFileContents; bool bLoaded = (strFoldername.Exists() && ascFileContents.LoadFromFile(strFoldername, strUser) && ascFileContents.Exists()); if (!bLoaded) { otWarn << "%s: No cached ciphertext of master key loaded during " "attempted retrieval. " "(However, once one is available, it WILL be cached using " "DPAPI.) \n"; return false; } // Below this point, we know for sure the ciphertext of the master // key loaded, and exists. // const OTData theCipherblob(ascFileContents); // if (theCipherblob.IsEmpty()) { otErr << __FUNCTION__ << ": Error: OTData is empty after decoding " "OTASCIIArmor (that wasn't empty.)\n"; } else { DATA_BLOB input; input.pbData = const_cast<BYTE*>( reinterpret_cast<const BYTE*>(theCipherblob.GetPayloadPointer())); input.cbData = static_cast<DWORD>(theCipherblob.GetSize()); // CRYPTPROTECT_PROMPTSTRUCT PromptStruct; // ZeroMemory(&PromptStruct, sizeof(PromptStruct)); // PromptStruct.cbSize = sizeof(PromptStruct); // PromptStruct.dwPromptFlags = CRYPTPROTECT_PROMPT_ON_PROTECT; // PromptStruct.szPrompt = L"This is a user prompt."; // LPWSTR pDescrOut = nullptr; DATA_BLOB output; BOOL result = CryptUnprotectData(&input, nullptr, // &pDescrOut nullptr, // optional entropy nullptr, // reserved nullptr, //&PromptStruct 0, &output); if (!result) { otErr << __FUNCTION__ << ": Error: Output of Win32 CryptUnprotectData was empty.\n"; } else { thePassword.setMemory(reinterpret_cast<void*>(output.pbData), static_cast<uint32_t>(output.cbData)); SecureZeroMemory(output.pbData, output.cbData); LocalFree(output.pbData); // LocalFree(pDescrOut); return true; } } return false; }
OTData::OTData(const OTASCIIArmor &theSource) : m_pData(NULL), m_lPosition(0), m_lSize(0) { if (theSource.Exists()) theSource.GetData(*this); // *********** }
bool MainFile::LoadMainFile(bool bReadOnly) { if (!OTDB::Exists(".", server_->m_strWalletFilename.Get())) { Log::vError("%s: Error finding file: %s\n", __FUNCTION__, server_->m_strWalletFilename.Get()); return false; } String strFileContents(OTDB::QueryPlainString( ".", server_->m_strWalletFilename.Get())); // <=== LOADING FROM DATA STORE. if (!strFileContents.Exists()) { Log::vError("%s: Unable to read main file: %s\n", __FUNCTION__, server_->m_strWalletFilename.Get()); return false; } bool bNeedToSaveAgain = false; bool bFailure = false; { OTStringXML xmlFileContents(strFileContents); if (false == xmlFileContents.DecodeIfArmored()) // bEscapedIsAllowed=true by // default. { Log::vError("%s: Notary server file apparently was encoded and " "then failed decoding. Filename: %s \n" "Contents: \n%s\n", __FUNCTION__, server_->m_strWalletFilename.Get(), strFileContents.Get()); return false; } irr::io::IrrXMLReader* xml = irr::io::createIrrXMLReader(xmlFileContents); std::unique_ptr<irr::io::IrrXMLReader> theXMLGuardian(xml); while (xml && xml->read()) { // strings for storing the data that we want to read out of the file String AssetName; String InstrumentDefinitionID; const String strNodeName(xml->getNodeName()); switch (xml->getNodeType()) { case irr::io::EXN_TEXT: // in this xml file, the only text which occurs is the // messageText // messageText = xml->getNodeData(); break; case irr::io::EXN_ELEMENT: { if (strNodeName.Compare("notaryServer")) { version_ = xml->getAttributeValue("version"); server_->m_strNotaryID = xml->getAttributeValue("notaryID"); server_->m_strServerNymID = xml->getAttributeValue("serverNymID"); String strTransactionNumber; // The server issues // transaction numbers and // stores the counter here // for the latest one. strTransactionNumber = xml->getAttributeValue("transactionNum"); server_->transactor_.transactionNumber( strTransactionNumber.ToLong()); Log::vOutput( 0, "\nLoading Open Transactions server. File version: %s\n" " Last Issued Transaction Number: %" PRId64 "\n Notary ID: " " %s\n Server Nym ID: %s\n", version_.c_str(), server_->transactor_.transactionNumber(), server_->m_strNotaryID.Get(), server_->m_strServerNymID.Get()); } // todo in the future just remove masterkey. I'm leaving it for // now so people's // data files can get converted over. After a while just remove // it. // else if (strNodeName.Compare("masterKey") || strNodeName.Compare("cachedKey")) { OTASCIIArmor ascCachedKey; if (Contract::LoadEncodedTextField(xml, ascCachedKey)) { // We successfully loaded the masterKey from file, so // let's SET it // as the master key globally... // OTCachedKey::It()->SetCachedKey(ascCachedKey); if (!OTCachedKey::It()->HasHashCheck()) { OTPassword tempPassword; tempPassword.zeroMemory(); std::shared_ptr<OTCachedKey> sharedPtr( OTCachedKey::It()); bNeedToSaveAgain = sharedPtr->GetMasterPassword( sharedPtr, tempPassword, "We do not have a check hash yet for this " "password, " "please enter your password", true); } } Log::vOutput(0, "\nLoading cachedKey:\n%s\n", ascCachedKey.Get()); // // It's only here, AFTER the master key has been loaded, // that we can // go ahead and load the server user, the server contract, // cron, etc. // (It wasn't that way in version 1, before we had master // keys.) // // This is, for example, 2.0 if (version_ != "1.0") { if (!LoadServerUserAndContract()) { Log::vError("%s: Failed calling " "LoadServerUserAndContract.\n", __FUNCTION__); bFailure = true; } } } else if (strNodeName.Compare("accountList")) // the voucher // reserve // account IDs. { const String strAcctType = xml->getAttributeValue("type"); const String strAcctCount = xml->getAttributeValue("count"); if ((-1) == server_->transactor_.voucherAccounts_.ReadFromXMLNode( xml, strAcctType, strAcctCount)) Log::vError("%s: Error loading voucher accountList.\n", __FUNCTION__); } else if (strNodeName.Compare("basketInfo")) { String strBasketID = xml->getAttributeValue("basketID"); String strBasketAcctID = xml->getAttributeValue("basketAcctID"); String strBasketContractID = xml->getAttributeValue("basketContractID"); const Identifier BASKET_ID(strBasketID), BASKET_ACCT_ID(strBasketAcctID), BASKET_CONTRACT_ID(strBasketContractID); if (server_->transactor_.addBasketAccountID( BASKET_ID, BASKET_ACCT_ID, BASKET_CONTRACT_ID)) Log::vOutput(0, "Loading basket currency info...\n " "Basket ID: %s\n Basket Acct ID: " "%s\n Basket Contract ID: %s\n", strBasketID.Get(), strBasketAcctID.Get(), strBasketContractID.Get()); else Log::vError("Error adding basket currency info...\n " "Basket ID: %s\n Basket Acct ID: %s\n", strBasketID.Get(), strBasketAcctID.Get()); } // Create an OTAssetContract and load them from file, (for each // instrument definition), // and add them to the internal map. else if (strNodeName.Compare("assetType")) { OTASCIIArmor ascAssetName = xml->getAttributeValue("name"); if (ascAssetName.Exists()) ascAssetName.GetString(AssetName, false); // linebreaks == false InstrumentDefinitionID = xml->getAttributeValue( "instrumentDefinitionID"); // hash of contract itself Log::vOutput(0, "\n\n****Asset Contract**** (server " "listing)\n Name: %s\n Contract ID: %s\n", AssetName.Get(), InstrumentDefinitionID.Get()); String strContractPath; strContractPath = OTFolders::Contract().Get(); AssetContract* pContract = new AssetContract( AssetName, strContractPath, InstrumentDefinitionID, InstrumentDefinitionID); OT_ASSERT_MSG(nullptr != pContract, "ASSERT: allocating memory for Asset " "Contract in MainFile::LoadMainFile\n"); if (pContract->LoadContract()) { if (pContract->VerifyContract()) { Log::Output(0, "** Asset Contract Verified **\n"); pContract->SetName(AssetName); server_->transactor_ .contractsMap_[InstrumentDefinitionID.Get()] = pContract; App::Me().DHT().Insert( InstrumentDefinitionID.Get(), *pContract); } else { delete pContract; pContract = nullptr; Log::Output(0, "Asset Contract FAILED to verify.\n"); } } else { delete pContract; pContract = nullptr; Log::vOutput( 0, "%s: Failed reading file for Asset Contract.\n", __FUNCTION__); } } else { // unknown element type Log::vError("%s: Unknown element type: %s\n", __FUNCTION__, xml->getNodeName()); } } break; default: break; } } } if (!bReadOnly) { { if (bNeedToSaveAgain) SaveMainFile(); } } return !bFailure; }
// return -1 if error, 0 if nothing, and 1 if the node was processed. int OTToken::ProcessXMLNode(IrrXMLReader*& xml) { static int nPublicTokenCount = 0; static int nPrivateTokenCount = 0; int nReturnVal = 0; // Here we call the parent class first. // If the node is found there, or there is some error, // then we just return either way. But if it comes back // as '0', then nothing happened, and we'll continue executing. // // -- Note you can choose not to call the parent if // you don't want to use any of those xml tags. // As I do below, in the case of OTAccount. //if (nReturnVal = OTContract::ProcessXMLNode(xml)) // return nReturnVal; if (!strcmp("token", xml->getNodeName())) { OTString strState; m_strVersion = xml->getAttributeValue("version"); strState = xml->getAttributeValue("state"); m_nSeries = atoi(xml->getAttributeValue("series")); m_VALID_FROM = atol(xml->getAttributeValue("validFrom")); m_VALID_TO = atol(xml->getAttributeValue("validTo")); SetDenomination(atol(xml->getAttributeValue("denomination"))); if (strState.Compare("blankToken")) m_State = OTToken::blankToken; else if (strState.Compare("protoToken")) m_State = OTToken::protoToken; else if (strState.Compare("signedToken")) m_State = OTToken::signedToken; else if (strState.Compare("spendableToken")) m_State = OTToken::spendableToken; else if (strState.Compare("verifiedToken")) m_State = OTToken::verifiedToken; else m_State = OTToken::errorToken; if (m_State == OTToken::spendableToken) m_strContractType.Set("CASH"); OTString strAssetTypeID(xml->getAttributeValue("assetTypeID")), strServerID(xml->getAttributeValue("serverID")); m_AssetTypeID.SetString(strAssetTypeID); m_ServerID.SetString(strServerID); OTLog::vOutput(4, // "\n===> Loading XML for token into memory structures..." "\n\nToken State: %s\n Denomination: %ld\n" " AssetTypeID: %s\nServerID: %s\n", strState.Get(), GetDenomination(), strAssetTypeID.Get(), strServerID.Get()); nReturnVal = 1; } else if (!strcmp("tokenID", xml->getNodeName())) { if (false == LoadEncodedTextField(xml, m_ascSpendable)) { OTLog::Error("Error in OTToken::ProcessXMLNode: token ID without value.\n"); return (-1); // error condition } return 1; } else if (!strcmp("tokenSignature", xml->getNodeName())) { if (false == LoadEncodedTextField(xml, m_Signature)) { OTLog::Error("Error in OTToken::ProcessXMLNode: token Signature without value.\n"); return (-1); // error condition } return 1; } else if (!strcmp("protopurse", xml->getNodeName())) { // TODO for security, if the count here doesn't match what's loaded up, that should be part of // what is verified in each token when it's verified.. m_nTokenCount = atoi(xml->getAttributeValue("count")); m_nChosenIndex = atoi(xml->getAttributeValue("chosenIndex")); nPublicTokenCount = 0; return 1; } else if (!strcmp("prototoken", xml->getNodeName())) { OTASCIIArmor * pArmoredPrototoken = new OTASCIIArmor; OT_ASSERT(NULL != pArmoredPrototoken); if (!LoadEncodedTextField(xml, *pArmoredPrototoken) || !pArmoredPrototoken->Exists()) { OTLog::Error("Error in OTToken::ProcessXMLNode: prototoken field without value.\n"); delete pArmoredPrototoken; pArmoredPrototoken = NULL; return (-1); // error condition } else { m_mapPublic[nPublicTokenCount] = pArmoredPrototoken; nPublicTokenCount++; } return 1; } else if (!strcmp("privateProtopurse", xml->getNodeName())) { nPrivateTokenCount = 0; return 1; } else if (!strcmp("privatePrototoken", xml->getNodeName())) { OTASCIIArmor * pArmoredPrototoken = new OTASCIIArmor; OT_ASSERT(NULL != pArmoredPrototoken); if (!LoadEncodedTextField(xml, *pArmoredPrototoken) || !pArmoredPrototoken->Exists()) { OTLog::Error("Error in OTToken::ProcessXMLNode: privatePrototoken field without value.\n"); delete pArmoredPrototoken; pArmoredPrototoken = NULL; return (-1); // error condition } else { m_mapPrivate[nPrivateTokenCount] = pArmoredPrototoken; nPrivateTokenCount++; OTLog::vOutput(4, "Loaded prototoken and adding to m_mapPrivate at index: %d\n", nPrivateTokenCount-1); } return 1; } return nReturnVal; }
OTData::OTData(const OTASCIIArmor& source) { if (source.Exists()) { source.GetData(*this); } }