178 for (
const auto& it : m_mapSubcredentials) {
186 const int32_t nTempCount =
188 nCount += nTempCount;
198 const OTString strActualMasterCredID(theActualMasterCredID);
201 otOut << __FUNCTION__
202 <<
": NymID did not match its "
203 "counterpart in m_Masterkey (failed to verify): " <<
GetNymID()
208 if (!m_strMasterCredID.
Compare(strActualMasterCredID)) {
209 otOut << __FUNCTION__
210 <<
": Master Credential ID did not match its "
211 "counterpart in m_Masterkey:\nExpected Master Credential ID: "
214 "Hash of m_Masterkey contents: " << strActualMasterCredID
219 if (!const_cast<OTMasterkey&>(m_Masterkey).VerifyContract()) {
220 otOut << __FUNCTION__
222 <<
"\nNymID: " <<
GetNymID() <<
"\n";
226 for (
const auto& it : m_mapSubcredentials) {
227 std::string str_sub_id = it.first;
232 otOut << __FUNCTION__
233 <<
": Subcredential failed to verify: " << str_sub_id
234 <<
"\nNymID: " <<
GetNymID() <<
"\n";
250 <<
": Failed verifying master credential against its own source.\n";
285 return m_strSourceForNymID;
291 void OTCredential::SetSourceForNymID(
const OTString& strSourceForNymID)
293 m_strSourceForNymID = strSourceForNymID;
299 const bool bCalculate = theTempID.
CalculateDigest(m_strSourceForNymID);
304 m_strNymID, m_strSourceForNymID);
321 bool OTCredential::SetPublicContents(
const OTString::Map& mapPublic)
326 bool OTCredential::SetPrivateContents(
const OTString::Map& mapPrivate)
332 OTCredential::OTCredential()
334 , m_pImportPassword(nullptr)
338 void OTCredential::SetMasterCredID(
const OTString& strID)
340 m_strMasterCredID = strID;
345 return m_strMasterCredID;
355 std::unique_ptr<OTCredential> theCredentialAngel(pCredential);
358 OTPasswordData thePWData(
"Loading master credential. (static 1.)");
360 strNymID, strMasterCredID, (
nullptr == pPWData) ? &thePWData : pPWData);
362 otErr << __FUNCTION__ <<
": Failed trying to load master credential "
363 "from local storage. 1\n";
367 return theCredentialAngel.release();
379 std::unique_ptr<OTCredential> theCredentialAngel(pCredential);
383 ?
"Enter wallet master passphrase."
384 :
"Enter passphrase for exported Nym.");
386 strInput, strNymID, strMasterCredID,
387 (
nullptr == pPWData) ? &thePWData : pPWData, pImportPassword);
389 otErr << __FUNCTION__
390 <<
": Failed trying to load master credential from string. 2\n";
394 return theCredentialAngel.release();
401 "Signing new master credential... OTCredential::SignNewMaster");
405 const bool bSignedPublic = m_Masterkey.
Sign(
406 m_Masterkey,
nullptr == pPWData ? &thePWData : pPWData);
436 const OTString strMasterCredID(theNewID);
441 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
442 <<
": Failed calling m_Masterkey.SaveContractRaw 1.\n";
455 const bool bSignedPrivate = m_Masterkey.
Sign(
456 m_Masterkey,
nullptr == pPWData ? &thePWData : pPWData);
457 if (bSignedPrivate) {
463 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
464 <<
": Failed trying to sign the master private credential.\n";
469 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
470 <<
": Failed trying to sign the master public credential.\n";
490 const OTPassword& theExportPassword,
bool bImporting)
494 bImporting ?
"2 Enter passphrase for the Nym being imported."
495 :
"2 Enter new passphrase for exported Nym.");
499 const bool bReEncryptMaster =
501 bool bSignedMaster =
false;
503 if (bReEncryptMaster) {
506 bSignedMaster = m_Masterkey.
Sign(m_Masterkey, &thePWData);
509 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
510 <<
": Failed trying to re-encrypt the private masterkey.\n";
520 for (
auto& it : m_mapSubcredentials) {
525 if (
nullptr == pKey)
continue;
527 const bool bReEncryptSubkey =
529 bool bSignedSubkey =
false;
531 if (bReEncryptSubkey) {
533 bSignedSubkey = pKey->
Sign(*pKey, &thePWData);
536 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
537 <<
": Failed trying to re-encrypt the private "
549 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
550 <<
": Failed trying to re-sign the private subkey.\n";
558 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
559 <<
": Failed trying to re-sign the master private "
563 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
564 <<
": Failed: There is no private info on this master "
575 "Signing new subcredential... OTCredential::SignNewSubcredential");
593 const bool bIsSubkey = (
nullptr != pSubkey);
613 const bool bMasterSigned = m_Masterkey.
Sign(
614 *pSubkey,
nullptr == pPWData ? &thePWData : pPWData);
615 if (!bMasterSigned) {
616 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
617 <<
": Failed calling m_Masterkey.Sign(*pSubkey) "
618 "after StoreAsMasterSigned.\n";
627 OTString strMasterSigned;
641 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
642 <<
": Failed calling pSubkey->SaveContractRaw 1.\n";
666 bool bSignedPublic =
false;
671 bSignedPublic = pSubkey->
Sign(
672 theSubCred,
nullptr == pPWData ? &thePWData : pPWData);
675 bSignedPublic = m_Masterkey.
Sign(
676 theSubCred,
nullptr == pPWData ? &thePWData : pPWData);
678 if (!bSignedPublic) {
680 <<
"In " << __FILE__ <<
", line " << __LINE__
681 <<
": Failed trying to sign the public subcredential or subkey.\n";
691 OTString strPublicCredential;
710 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
711 <<
": Failed calling theSubCred.SaveContractRaw.\n";
723 bool bSignedPrivate =
false;
728 bSignedPrivate = pSubkey->
Sign(
729 theSubCred,
nullptr == pPWData ? &thePWData : pPWData);
733 bSignedPrivate = m_Masterkey.
Sign(
734 theSubCred,
nullptr == pPWData ? &thePWData : pPWData);
739 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
740 <<
": Failed trying to sign the private subcredential.\n";
748 bool OTCredential::GenerateMasterkey(int32_t nBits)
764 m_strNymID = strNymID;
765 m_strMasterCredID = strMasterCredID;
785 otErr << __FUNCTION__
786 <<
": Failed trying to load master credential from string.\n";
794 m_strNymID = m_Masterkey.
GetNymID();
811 std::string str_Folder =
821 otErr << __FUNCTION__ <<
": Failure: Master Credential "
822 << strMasterCredID <<
" doesn't exist for Nym " << strNymID
829 strMasterCredID.
Get()));
830 if (!strFileContents.
Exists()) {
831 otErr << __FUNCTION__ <<
": Failed trying to load master credential "
832 "from local storage.\n";
839 otErr << __FUNCTION__ <<
": File contents apparently were encoded and "
840 "then failed decoding. Contents: \n"
841 << strFileContents <<
"\n";
855 auto it = m_mapSubcredentials.find(strSubID.
Get());
856 if (it != m_mapSubcredentials.end())
858 otErr << __FUNCTION__ <<
": Warning: Deleting and re-loading "
859 "keyCredential that was already loaded.\n";
863 m_mapSubcredentials.erase(it);
867 std::unique_ptr<OTSubkey> theSubAngel(pSub);
882 otErr << __FUNCTION__
883 <<
": Failed trying to load keyCredential from string.\n";
892 m_mapSubcredentials.insert(std::pair<std::string, OTSubcredential*>(
893 strSubID.
Get(), theSubAngel.release()));
901 std::string str_Folder =
910 otErr << __FUNCTION__ <<
": Failure: Key Credential " << strSubID
911 <<
" doesn't exist for Nym " <<
GetNymID() <<
"\n";
919 if (!strFileContents.
Exists()) {
920 otErr << __FUNCTION__
921 <<
": Failed trying to load keyCredential from local storage.\n";
928 otErr << __FUNCTION__ <<
": File contents apparently were encoded and "
929 "then failed decoding. Contents: \n"
930 << strFileContents <<
"\n";
943 auto it = m_mapSubcredentials.find(strSubID.
Get());
944 if (it != m_mapSubcredentials.end())
946 otErr << __FUNCTION__ <<
": Warning: Deleting and re-loading "
947 "subCredential that was already loaded.\n";
951 m_mapSubcredentials.erase(it);
955 std::unique_ptr<OTSubcredential> theSubAngel(pSub);
970 otErr << __FUNCTION__
971 <<
": Failed trying to load subCredential from string.\n";
979 m_mapSubcredentials.insert(std::pair<std::string, OTSubcredential*>(
980 strSubID.
Get(), theSubAngel.release()));
988 std::string str_Folder =
997 otErr << __FUNCTION__ <<
": Failure: Credential " << strSubID
998 <<
" doesn't exist for Nym " <<
GetNymID() <<
"\n";
1005 if (!strFileContents.
Exists()) {
1006 otErr << __FUNCTION__
1007 <<
": Failed trying to load subCredential from local storage.\n";
1014 otErr << __FUNCTION__ <<
": File contents apparently were encoded and "
1015 "then failed decoding. Contents: \n"
1016 << strFileContents <<
"\n";
1047 bool bContentsReady =
false;
1057 if (!bContentsReady) {
1058 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
1059 <<
": Failed trying to SetPrivateContents or GenerateKeys\n";
1070 "Signing new subkey... OTCredential::AddNewSubkey");
1077 SignNewSubcredential(*pSub, theSubCredID,
1078 nullptr == pPWData ? &thePWData : pPWData)) {
1079 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
1080 <<
": Failed trying to call SignNewSubcredential\n";
1096 m_mapSubcredentials.insert(
1097 std::pair<std::string, OTSubcredential*>(strSubCredID.
Get(), pSub));
1099 if (
nullptr != ppSubkey)
1128 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
1129 <<
": Failed while calling pSub->SetPublicContents.\n";
1135 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
1136 <<
": Failed while trying to pSub->SetPrivateContents.\n";
1147 "Signing new subcredential... OTCredential::AddNewSubcredential");
1154 SignNewSubcredential(*pSub, theSubCredID,
1155 nullptr == pPWData ? &thePWData : pPWData)) {
1156 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
1157 <<
": Failed trying to call SignNewSubcredential\n";
1163 const OTString strSubCredID(theSubCredID);
1170 m_mapSubcredentials.insert(
1171 std::pair<std::string, OTSubcredential*>(strSubCredID.
Get(), pSub));
1172 if (
nullptr != ppSubcred)
1198 pCredential->SetSourceForNymID(
1207 if ((
nullptr != pmapPublic) &&
1208 (
nullptr != pmapPrivate))
1213 if (!pCredential->SetPublicContents(*pmapPublic)) {
1214 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
1215 <<
": Failed trying to call pCredential->SetPublicContents\n";
1217 pCredential =
nullptr;
1227 bool bContentsReady =
false;
1231 bContentsReady = pCredential->SetPrivateContents(
1235 bContentsReady = pCredential->GenerateMasterkey(nBits);
1237 if (!bContentsReady) {
1238 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
1239 <<
": Failed trying to SetPrivateContents or GenerateMasterkey\n";
1241 pCredential =
nullptr;
1246 "Signing new master credential... OTCredential::CreateMaster");
1252 pCredential->SignNewMaster(
nullptr == pPWData ? &thePWData
1254 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
1255 <<
": Failed trying to call pCredential->SignNewMaster\n";
1257 pCredential =
nullptr;
1297 return m_mapSubcredentials.size();
1303 for (
const auto& it : m_mapSubcredentials) {
1304 const std::string str_cred_id = it.first;
1310 if (
nullptr != plistRevokedIDs) {
1311 auto iter = std::find(plistRevokedIDs->begin(),
1312 plistRevokedIDs->end(), str_cred_id);
1313 if (iter != plistRevokedIDs->end())
1319 if (strSubID.
Compare(str_cred_id.c_str()))
return pSub;
1325 int32_t nIndex)
const
1328 (nIndex >= static_cast<int64_t>(m_mapSubcredentials.size()))) {
1329 otErr << __FUNCTION__ <<
": Index out of bounds: " << nIndex <<
"\n";
1332 int32_t nLoopIndex = -1;
1334 for (
const auto& it : m_mapSubcredentials) {
1340 if (nIndex == nLoopIndex)
return pSub;
1349 if (nIndex >= m_mapSubcredentials.size()) {
1350 otErr << __FUNCTION__ <<
": Index out of bounds: " << nIndex <<
"\n";
1353 int32_t nLoopIndex = -1;
1355 for (
const auto& it : m_mapSubcredentials) {
1356 const std::string str_cred_id = it.first;
1362 if (static_cast<int64_t>(nIndex) == nLoopIndex)
return str_cred_id;
1372 for (
const auto& it : m_mapSubcredentials) {
1373 const std::string str_cred_id = it.first;
1378 if (
nullptr == pKey)
continue;
1382 if (
nullptr != plistRevokedIDs) {
1383 auto iter = std::find(plistRevokedIDs->begin(),
1384 plistRevokedIDs->end(), str_cred_id);
1385 if (iter != plistRevokedIDs->end())
1409 for (
const auto& it : m_mapSubcredentials) {
1410 const std::string str_cred_id = it.first;
1415 if (
nullptr == pKey)
continue;
1419 if (
nullptr != plistRevokedIDs) {
1420 auto iter = std::find(plistRevokedIDs->begin(),
1421 plistRevokedIDs->end(), str_cred_id);
1422 if (iter != plistRevokedIDs->end())
1446 for (
const auto& it : m_mapSubcredentials) {
1447 const std::string str_cred_id = it.first;
1452 if (
nullptr == pKey)
continue;
1456 if (
nullptr != plistRevokedIDs) {
1457 auto iter = std::find(plistRevokedIDs->begin(),
1458 plistRevokedIDs->end(), str_cred_id);
1459 if (iter != plistRevokedIDs->end())
1531 while (!m_mapSubcredentials.empty()) {
1538 m_mapSubcredentials.erase(m_mapSubcredentials.begin());
1559 if (bValid || bShowRevoked) {
1565 bValid ?
"true" :
"false");
1567 if (
nullptr != pmapPubInfo)
1568 pmapPubInfo->insert(std::pair<std::string, std::string>(
1571 if (
nullptr != pmapPriInfo)
1572 pmapPriInfo->insert(std::pair<std::string, std::string>(
1576 for (
const auto& it : m_mapSubcredentials) {
1577 const std::string str_cred_id = it.first;
1585 auto iter = std::find(listRevokedIDs.begin(), listRevokedIDs.end(),
1591 const bool bSubcredValid =
1592 bValid ? (iter == listRevokedIDs.end()) :
false;
1594 if (bSubcredValid || bShowRevoked) {
1597 if (
nullptr != pSubkey)
1600 " masterID=\"%s\"\n"
1603 str_cred_id.c_str(),
1605 bSubcredValid ?
"true" :
"false");
1609 " masterID=\"%s\"\n"
1612 str_cred_id.c_str(),
1614 bSubcredValid ?
"true" :
"false");
1616 if (
nullptr != pmapPubInfo)
1617 pmapPubInfo->insert(std::pair<std::string, std::string>(
1620 if (
nullptr != pmapPriInfo)
1621 pmapPriInfo->insert(std::pair<std::string, std::string>(
std::map< std::string, std::string > Map
EXPORT const OTAsymmetricKey & GetPublicSignKey(const OTString::List *plistRevokedIDs=nullptr) const
std::list< OTAsymmetricKey * > listOfAsymmetricKeys
EXPORT const OTAsymmetricKey & GetPublicKey() const
EXPORT const OTSubcredential * GetSubcredential(const OTString &strSubID, const OTString::List *plistRevokedIDs=nullptr) const
EXPORT int32_t GetPublicKeysBySignature(listOfAsymmetricKeys &listOutput, const OTSignature &theSignature, char cKeyType= '0') const
EXPORT const OTString & GetNymID() const
EXPORT bool CalculateDigest(const OTData &dataInput)
EXPORT bool LoadSubcredentialFromString(const OTString &strInput, const OTString &strSubID, const OTPassword *pImportPassword=nullptr)
void StoreAsMasterSigned()
static EXPORT const OTString & Pubcred()
const OTString & GetMasterCredID() const
void SetMasterCredID(const OTString &strMasterCredID)
EXPORT bool LoadSubcredential(const OTString &strSubID)
const OTString::Map & GetPrivateMap() const
EXPORT bool SaveContract()
EXPORT const OTAsymmetricKey & GetPrivateAuthKey(const OTString::List *plistRevokedIDs=nullptr) const
EXPORT bool AddNewSubkey(int32_t nBits=1024, const OTString::Map *pmapPrivate=nullptr, const OTPasswordData *pPWData=nullptr, OTSubkey **ppSubkey=nullptr)
bool Sign(OTContract &theContract, const OTPasswordData *pPWData=nullptr)
bool VerifyAgainstSource() const
EXPORT bool Load_MasterFromString(const OTString &strInput, const OTString &strNymID, const OTString &strMasterCredID, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr)
virtual void SetMetadata()
EXPORT const OTKeypair & GetEncrKeypair(const OTString::List *plistRevokedIDs=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT void ClearSubcredentials()
EXPORT bool SaveContractRaw(OTString &strOutput) const
EXPORT const OTKeypair & GetSignKeypair(const OTString::List *plistRevokedIDs=nullptr) const
virtual bool SetPrivateContents(const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
virtual EXPORT void CalculateContractID(OTIdentifier &newID) const
EXPORT void Concatenate(const char *arg,...)
static OTCredential * CreateMaster(const OTString &strSourceForNymID, int32_t nBits=1024, const OTString::Map *pmapPrivate=nullptr, const OTString::Map *pmapPublic=nullptr, const OTPasswordData *pPWData=nullptr)
EXPORT bool ReEncryptPrivateCredentials(const OTPassword &theExportPassword, bool bImporting)
static OTCredential * LoadMaster(const OTString &strNymID, const OTString &strMasterCredID, const OTPasswordData *pPWData=nullptr)
EXPORT bool DecodeIfArmored(bool escapedIsAllowed=true)
EXPORT void ReleaseSignatures()
EXPORT bool Exists() const
const OTString & GetPriCredential() const
EXPORT bool AddNewSubcredential(const OTString::Map &mapPrivate, const OTString::Map &mapPublic, const OTPasswordData *pPWData=nullptr, OTSubcredential **ppSubcred=nullptr)
void SetMasterSigned(const OTString &strMasterSigned)
static EXPORT const OTString & Credential()
EXPORT bool Compare(const char *compare) const
EXPORT const OTString & GetPriCredential() const
EXPORT const OTString & GetMasterCredID() const
void SetIdentifier(const OTIdentifier &theID)
EXPORT bool LoadSubkeyFromString(const OTString &strInput, const OTString &strSubID, const OTPassword *pImportPassword=nullptr)
void SetNymIDandSource(const OTString &strNymID, const OTString &strSourceForNymID)
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
static OTCredential * LoadMasterFromString(const OTString &strInput, const OTString &strNymID, const OTString &strMasterCredID, OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr)
virtual bool SetPrivateContents(const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
EXPORT const OTKeypair & GetAuthKeypair(const OTString::List *plistRevokedIDs=nullptr) const
EXPORT const OTString & GetPubCredential() const
EXPORT const OTAsymmetricKey & GetPrivateKey() const
const OTString & GetNymID() const
EXPORT const OTAsymmetricKey & GetPublicAuthKey(const OTString::List *plistRevokedIDs=nullptr) const
std::list< std::string > List
void SetContents(const OTString &strContents)
virtual bool VerifyContract()
virtual bool SetPublicContents(const OTString::Map &mapPublic)
EXPORT size_t GetSubcredentialCount() const
OTLOG_IMPORT OTLogStream otWarn
EXPORT void SetImportPassword(const OTPassword *pImportPassword)
const OTString & GetNymIDSource() const
EXPORT const char * Get() const
EXPORT bool Load_Master(const OTString &strNymID, const OTString &strMasterCredID, const OTPasswordData *pPWData=nullptr)
EXPORT const OTAsymmetricKey & GetPublicEncrKey(const OTString::List *plistRevokedIDs=nullptr) const
bool ReEncryptKeys(const OTPassword &theExportPassword, bool bImporting)
OTLOG_IMPORT OTLogStream otErr
EXPORT const OTString & GetSourceForNymID() const
EXPORT const OTString & GetPubCredential() const
virtual bool SetPublicContents(const OTString::Map &mapPublic)
EXPORT void GetString(OTString &theStr) const
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
EXPORT bool LoadSubkey(const OTString &strSubID)
EXPORT const OTSubcredential * GetSubcredentialByIndex(int32_t nIndex) const
EXPORT bool LoadContractFromString(const OTString &theStr)
EXPORT const OTAsymmetricKey & GetPrivateEncrKey(const OTString::List *plistRevokedIDs=nullptr) const
EXPORT const OTAsymmetricKey & GetPrivateSignKey(const OTString::List *plistRevokedIDs=nullptr) const
EXPORT void SerializeIDs(OTString &strOutput, const OTString::List &listRevokedIDs, OTString::Map *pmapPubInfo=nullptr, OTString::Map *pmapPriInfo=nullptr, bool bShowRevoked=false, bool bValid=true) const
EXPORT bool VerifyAgainstSource() const
EXPORT bool VerifyInternally() const
bool GenerateKeys(int32_t nBits=1024)
virtual EXPORT void Release()
EXPORT const std::string GetSubcredentialIDByIndex(size_t nIndex) const
EXPORT int32_t GetPublicKeysBySignature(listOfAsymmetricKeys &listOutput, const OTSignature &theSignature, char cKeyType= '0') const