Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTCredential Class Reference

#include <OTCredential.hpp>

Public Member Functions

EXPORT const OTPasswordGetImportPassword () const
 
EXPORT void SetImportPassword (const OTPassword *pImportPassword)
 
EXPORT bool Load_Master (const OTString &strNymID, const OTString &strMasterCredID, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool Load_MasterFromString (const OTString &strInput, const OTString &strNymID, const OTString &strMasterCredID, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool AddNewSubkey (int32_t nBits=1024, const OTString::Map *pmapPrivate=nullptr, const OTPasswordData *pPWData=nullptr, OTSubkey **ppSubkey=nullptr)
 
EXPORT bool AddNewSubcredential (const OTString::Map &mapPrivate, const OTString::Map &mapPublic, const OTPasswordData *pPWData=nullptr, OTSubcredential **ppSubcred=nullptr)
 
EXPORT bool ReEncryptPrivateCredentials (const OTPassword &theExportPassword, bool bImporting)
 
EXPORT bool LoadSubkey (const OTString &strSubID)
 
EXPORT bool LoadSubcredential (const OTString &strSubID)
 
EXPORT bool LoadSubkeyFromString (const OTString &strInput, const OTString &strSubID, const OTPassword *pImportPassword=nullptr)
 
EXPORT bool LoadSubcredentialFromString (const OTString &strInput, const OTString &strSubID, const OTPassword *pImportPassword=nullptr)
 
EXPORT size_t GetSubcredentialCount () const
 
EXPORT const OTSubcredentialGetSubcredential (const OTString &strSubID, const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT const OTSubcredentialGetSubcredentialByIndex (int32_t nIndex) const
 
EXPORT const std::string GetSubcredentialIDByIndex (size_t nIndex) const
 
EXPORT const OTStringGetPubCredential () const
 
EXPORT const OTStringGetPriCredential () const
 
EXPORT const OTStringGetMasterCredID () const
 
EXPORT const OTStringGetNymID () const
 
EXPORT const OTStringGetSourceForNymID () 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 VerifyInternally () const
 
EXPORT bool VerifyAgainstSource () const
 
EXPORT const OTMasterkeyGetMasterkey () const
 
EXPORT int32_t GetPublicKeysBySignature (listOfAsymmetricKeys &listOutput, const OTSignature &theSignature, char cKeyType= '0') const
 
EXPORT const OTAsymmetricKeyGetPublicAuthKey (const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT const OTAsymmetricKeyGetPublicEncrKey (const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT const OTAsymmetricKeyGetPublicSignKey (const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT const OTAsymmetricKeyGetPrivateSignKey (const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT const OTAsymmetricKeyGetPrivateEncrKey (const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT const OTAsymmetricKeyGetPrivateAuthKey (const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT const OTKeypairGetAuthKeypair (const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT const OTKeypairGetEncrKeypair (const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT const OTKeypairGetSignKeypair (const OTString::List *plistRevokedIDs=nullptr) const
 
EXPORT void ClearSubcredentials ()
 
EXPORT ~OTCredential ()
 

Static Public Member Functions

static OTCredentialCreateMaster (const OTString &strSourceForNymID, int32_t nBits=1024, const OTString::Map *pmapPrivate=nullptr, const OTString::Map *pmapPublic=nullptr, const OTPasswordData *pPWData=nullptr)
 
static OTCredentialLoadMaster (const OTString &strNymID, const OTString &strMasterCredID, const OTPasswordData *pPWData=nullptr)
 
static OTCredentialLoadMasterFromString (const OTString &strInput, const OTString &strNymID, const OTString &strMasterCredID, OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr)
 

Detailed Description

Definition at line 217 of file OTCredential.hpp.

Constructor & Destructor Documentation

opentxs::OTCredential::~OTCredential ( )

Definition at line 1523 of file OTCredential.cpp.

1524 {
1526 }
EXPORT void ClearSubcredentials()

Member Function Documentation

bool opentxs::OTCredential::AddNewSubcredential ( const OTString::Map mapPrivate,
const OTString::Map mapPublic,
const OTPasswordData pPWData = nullptr,
OTSubcredential **  ppSubcred = nullptr 
)

Definition at line 1110 of file OTCredential.cpp.

1115 {
1116  OTSubcredential* pSub = new OTSubcredential(*this);
1117  OT_ASSERT(nullptr != pSub);
1118 
1119  pSub->SetNymIDandSource(m_strNymID, m_strSourceForNymID); // Set NymID and
1120  // source string
1121  // that hashes to
1122  // it.
1123  pSub->SetMasterCredID(GetMasterCredID()); // Set master credential ID
1124  // (onto this new
1125  // subcredential...)
1126 
1127  if (!pSub->SetPublicContents(mapPublic)) {
1128  otErr << "In " << __FILE__ << ", line " << __LINE__
1129  << ": Failed while calling pSub->SetPublicContents.\n";
1130  delete pSub;
1131  pSub = nullptr;
1132  return false;
1133  }
1134  else if (!pSub->SetPrivateContents(mapPrivate)) {
1135  otErr << "In " << __FILE__ << ", line " << __LINE__
1136  << ": Failed while trying to pSub->SetPrivateContents.\n";
1137  delete pSub;
1138  pSub = nullptr;
1139  return false;
1140  }
1141  else // By this point we've set up the subcredential with its NymID, the
1142  // source string for that NymID,
1143  { // my master credential ID, and the public and private contents for the
1144  // subcredential. Let's sign
1145  // it...
1146  OTPasswordData thePWData(
1147  "Signing new subcredential... OTCredential::AddNewSubcredential");
1148  OTIdentifier theSubCredID;
1149 
1150  // SignNewSubcredential uses m_Masterkey's actual signing key to sign
1151  // "pSub the contract."
1152  //
1153  if (false ==
1154  SignNewSubcredential(*pSub, theSubCredID,
1155  nullptr == pPWData ? &thePWData : pPWData)) {
1156  otErr << "In " << __FILE__ << ", line " << __LINE__
1157  << ": Failed trying to call SignNewSubcredential\n";
1158  delete pSub;
1159  pSub = nullptr;
1160  return false;
1161  }
1162 
1163  const OTString strSubCredID(theSubCredID);
1164 
1165  // ADD IT TO THE MAP
1166  // Only after pSub is signed and saved can we then calculate its ID and
1167  // use that ID
1168  // as the key in m_mapSubcredentials (with pSub being the value.)
1169  //
1170  m_mapSubcredentials.insert(
1171  std::pair<std::string, OTSubcredential*>(strSubCredID.Get(), pSub));
1172  if (nullptr != ppSubcred) // output
1173  *ppSubcred = pSub;
1174  return true;
1175  }
1176 }
EXPORT const OTString & GetMasterCredID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTCredential::AddNewSubkey ( int32_t  nBits = 1024,
const OTString::Map pmapPrivate = nullptr,
const OTPasswordData pPWData = nullptr,
OTSubkey **  ppSubkey = nullptr 
)

Definition at line 1026 of file OTCredential.cpp.

1032 {
1033  OTSubkey* pSub = new OTSubkey(*this);
1034  OT_ASSERT(nullptr != pSub);
1035 
1036  pSub->SetNymIDandSource(GetNymID(),
1037  GetSourceForNymID()); // Set NymID and source
1038  // string that hashes to
1039  // it.
1040  pSub->SetMasterCredID(GetMasterCredID()); // Set master credential ID
1041  // (onto this new
1042  // subcredential...)
1043 
1044  // If a map of private certs was not passed in, we're expected to
1045  // generate the keys ourselves.
1046  //
1047  bool bContentsReady = false;
1048 
1049  if (nullptr !=
1050  pmapPrivate) // Pre-generated keys were passed in for us to use,
1051  bContentsReady = pSub->SetPrivateContents(
1052  *pmapPrivate); // so let's set them onto the sub key.
1053  else
1054  // No keys were provided, so let's generate them ourselves...
1055  bContentsReady = pSub->GenerateKeys(nBits);
1056 
1057  if (!bContentsReady) {
1058  otErr << "In " << __FILE__ << ", line " << __LINE__
1059  << ": Failed trying to SetPrivateContents or GenerateKeys\n";
1060  delete pSub;
1061  pSub = nullptr;
1062  return false;
1063  }
1064  else // By this point we've set up the subkey with its NymID, the source
1065  // string for that NymID,
1066  { // my master credential ID, and the public and private certs for the
1067  // subkey. Now let's
1068  // sign it...
1069  OTPasswordData thePWData(
1070  "Signing new subkey... OTCredential::AddNewSubkey");
1071  OTIdentifier theSubCredID;
1072 
1073  // SignNewSubcredential uses m_Masterkey's actual signing key to sign
1074  // "pSub the contract."
1075  //
1076  if (false ==
1077  SignNewSubcredential(*pSub, theSubCredID,
1078  nullptr == pPWData ? &thePWData : pPWData)) {
1079  otErr << "In " << __FILE__ << ", line " << __LINE__
1080  << ": Failed trying to call SignNewSubcredential\n";
1081  delete pSub;
1082  pSub = nullptr;
1083  return false;
1084  }
1085 
1086  const OTString strSubCredID(
1087  theSubCredID); // SignNewSubcredential also generates the ID.
1088 
1089  pSub->SetMetadata();
1090 
1091  // ADD IT TO THE MAP
1092  // Only after pSub is signed and saved can we then calculate its ID and
1093  // use that ID
1094  // as the key in m_mapSubcredentials (with pSub being the value.)
1095  //
1096  m_mapSubcredentials.insert(
1097  std::pair<std::string, OTSubcredential*>(strSubCredID.Get(), pSub));
1098 
1099  if (nullptr != ppSubkey) // output
1100  {
1101  *ppSubkey = pSub;
1102  }
1103 
1104  return true;
1105  }
1106 }
EXPORT const OTString & GetNymID() const
EXPORT const OTString & GetMasterCredID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
EXPORT const OTString & GetSourceForNymID() const
void opentxs::OTCredential::ClearSubcredentials ( )

Definition at line 1528 of file OTCredential.cpp.

1529 {
1530 
1531  while (!m_mapSubcredentials.empty()) {
1532  OTSubcredential* pSub = m_mapSubcredentials.begin()->second;
1533  OT_ASSERT(nullptr != pSub);
1534 
1535  delete pSub;
1536  pSub = nullptr;
1537 
1538  m_mapSubcredentials.erase(m_mapSubcredentials.begin());
1539  } // while
1540 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTCredential * opentxs::OTCredential::CreateMaster ( const OTString strSourceForNymID,
int32_t  nBits = 1024,
const OTString::Map pmapPrivate = nullptr,
const OTString::Map pmapPublic = nullptr,
const OTPasswordData pPWData = nullptr 
)
static

Definition at line 1183 of file OTCredential.cpp.

1194 {
1195  OTCredential* pCredential = new OTCredential;
1196  OT_ASSERT(nullptr != pCredential);
1197 
1198  pCredential->SetSourceForNymID(
1199  strSourceForNymID); // This also recalculates and sets ** m_strNymID **
1200 
1201  // OTKeyCredential::SetPrivateContents will already set the public keys,
1202  // which is why this argument is optional. But not all credentials are keys,
1203  // so we must still retain the ability to explicitly set the public info.
1204  // Even so, in the case of keys, private is below, so it will overwrite
1205  // this.
1206 
1207  if ((nullptr != pmapPublic) &&
1208  (nullptr != pmapPrivate)) // You cannot pass public
1209  // info in here unless
1210  // you also pass private
1211  // info.
1212  {
1213  if (!pCredential->SetPublicContents(*pmapPublic)) {
1214  otErr << "In " << __FILE__ << ", line " << __LINE__
1215  << ": Failed trying to call pCredential->SetPublicContents\n";
1216  delete pCredential;
1217  pCredential = nullptr;
1218  return nullptr;
1219  }
1220  }
1221 
1222  // Private info must be passed in to create a credential. This saves a copy
1223  // of the map, and for keys also loads the map all up into the OTKeypair
1224  // objects (in the case of OTKeyCredentials anyway -- not all credentials
1225  // are keys.)
1226  //
1227  bool bContentsReady = false;
1228 
1229  if (nullptr !=
1230  pmapPrivate) // Pre-generated keys were passed in for us to use.
1231  bContentsReady = pCredential->SetPrivateContents(
1232  *pmapPrivate); // So let's set them onto the master key.
1233  else
1234  // No keys were provided, so let's generate them ourselves...
1235  bContentsReady = pCredential->GenerateMasterkey(nBits);
1236 
1237  if (!bContentsReady) {
1238  otErr << "In " << __FILE__ << ", line " << __LINE__
1239  << ": Failed trying to SetPrivateContents or GenerateMasterkey\n";
1240  delete pCredential;
1241  pCredential = nullptr;
1242  return nullptr;
1243  }
1244  else {
1245  OTPasswordData thePWData(
1246  "Signing new master credential... OTCredential::CreateMaster");
1247 
1248  // Using m_Masterkey's actual signing key to sign "m_Masterkey the
1249  // contract."
1250  //
1251  if (false ==
1252  pCredential->SignNewMaster(nullptr == pPWData ? &thePWData
1253  : pPWData)) {
1254  otErr << "In " << __FILE__ << ", line " << __LINE__
1255  << ": Failed trying to call pCredential->SignNewMaster\n";
1256  delete pCredential;
1257  pCredential = nullptr;
1258  return nullptr;
1259  }
1260  }
1261 
1262  // By this point, we have instantiated a new OTCredential, set the source
1263  // string, hashed that
1264  // source string to get the NymID for this credential, and set the public
1265  // and private info for
1266  // this credential (each a map of strings.) Since pCredential->m_Masterkey
1267  // is derived from
1268  // OTKeyCredential, it also loaded up the 3 keypairs (authentication,
1269  // encryption, and signing.)
1270  // Then we signed that master key with itself, with its signing key. (It's
1271  // also an OTContract,
1272  // so it can be signed.) This also calculated the new master credential ID,
1273  // and called
1274  // pCredential->SetMasterCredID. That is, the OTCredential's "master
1275  // credential ID" is formed
1276  // as a hash of the signed contract that is its OTMasterkey.
1277  // BUT!!! We don't want to use a hash of the private key information, since
1278  // others cannot verify
1279  // the hash without seeing our private key. We want OTMasterkey to create an
1280  // 'official' signed
1281  // public version of itself, minus private keys, which is what can be sent
1282  // to servers and to
1283  // other users, and which can be hashed to form the master credential ID
1284  // (and verified later.)
1285  // ...Which is exactly what it does. Inside pCredential->SignNewMaster, a
1286  // public version is created
1287  // and signed, and set onto that masterkey as m_strContents. It's then
1288  // re-signed as the private
1289  // version, which contains m_strContents in encoded form, along with the
1290  // private keys.
1291  //
1292  return pCredential;
1293 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
const OTKeypair & opentxs::OTCredential::GetAuthKeypair ( const OTString::List plistRevokedIDs = nullptr) const

Definition at line 1369 of file OTCredential.cpp.

1371 {
1372  for (const auto& it : m_mapSubcredentials) {
1373  const std::string str_cred_id = it.first;
1374  const OTSubcredential* pSub = it.second;
1375  OT_ASSERT(nullptr != pSub);
1376 
1377  const OTSubkey* pKey = dynamic_cast<const OTSubkey*>(pSub);
1378  if (nullptr == pKey) continue;
1379 
1380  // See if pKey, with ID str_cred_id, is on plistRevokedIDs...
1381  //
1382  if (nullptr != plistRevokedIDs) {
1383  auto iter = std::find(plistRevokedIDs->begin(),
1384  plistRevokedIDs->end(), str_cred_id);
1385  if (iter != plistRevokedIDs->end()) // It was on the revoked list.
1386  continue; // Skip this revoked key.
1387  }
1388  // At this point we know it's a key credential, and we know it's not on
1389  // the revoked list. Therefore, let's return the key! (Any other future
1390  // smart criteria might go here before taking this final step...)
1391  //
1392  return pKey->m_AuthentKey;
1393  }
1394 
1395  // Didn't find any subcredentials we can use? For now, we'll return the
1396  // master key instead.
1397  // This is purely for backwards compatibility reasons and eventually should
1398  // be removed. That is,
1399  // masters should only be able to verify subkeys, and only subkeys should be
1400  // able to do actions.
1401  // Capiche?
1402  //
1403  return m_Masterkey.m_AuthentKey;
1404 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const OTKeypair & opentxs::OTCredential::GetEncrKeypair ( const OTString::List plistRevokedIDs = nullptr) const

Definition at line 1406 of file OTCredential.cpp.

1408 {
1409  for (const auto& it : m_mapSubcredentials) {
1410  const std::string str_cred_id = it.first;
1411  const OTSubcredential* pSub = it.second;
1412  OT_ASSERT(nullptr != pSub);
1413 
1414  const OTSubkey* pKey = dynamic_cast<const OTSubkey*>(pSub);
1415  if (nullptr == pKey) continue;
1416 
1417  // See if pKey, with ID str_cred_id, is on plistRevokedIDs...
1418  //
1419  if (nullptr != plistRevokedIDs) {
1420  auto iter = std::find(plistRevokedIDs->begin(),
1421  plistRevokedIDs->end(), str_cred_id);
1422  if (iter != plistRevokedIDs->end()) // It was on the revoked list.
1423  continue; // Skip this revoked key.
1424  }
1425  // At this point we know it's a key credential, and we know it's not on
1426  // the revoked list. Therefore, let's return the key! (Any other future
1427  // smart criteria might go here before taking this final step...)
1428  //
1429  return pKey->m_EncryptKey;
1430  }
1431 
1432  // Didn't find any subcredentials we can use? For now, we'll return the
1433  // master key instead.
1434  // This is purely for backwards compatibility reasons and eventually should
1435  // be removed. That is,
1436  // masters should only be able to verify subkeys, and only subkeys should be
1437  // able to do actions.
1438  // Capiche?
1439  //
1440  return m_Masterkey.m_EncryptKey;
1441 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const OTPassword* opentxs::OTCredential::GetImportPassword ( ) const
inline

Definition at line 273 of file OTCredential.hpp.

274  {
275  return m_pImportPassword;
276  }
const OTString & opentxs::OTCredential::GetMasterCredID ( ) const

Definition at line 343 of file OTCredential.cpp.

344 {
345  return m_strMasterCredID;
346 }
EXPORT const OTMasterkey& opentxs::OTCredential::GetMasterkey ( ) const
inline

Definition at line 371 of file OTCredential.hpp.

372  {
373  return m_Masterkey;
374  }
const OTString & opentxs::OTCredential::GetNymID ( ) const

Definition at line 278 of file OTCredential.cpp.

279 {
280  return m_strNymID;
281 }
const OTString & opentxs::OTCredential::GetPriCredential ( ) const

Definition at line 316 of file OTCredential.cpp.

317 {
318  return m_Masterkey.GetPriCredential();
319 }
const OTString & GetPriCredential() const
const OTAsymmetricKey & opentxs::OTCredential::GetPrivateAuthKey ( const OTString::List plistRevokedIDs = nullptr) const

Definition at line 1505 of file OTCredential.cpp.

1507 {
1508  return GetAuthKeypair(plistRevokedIDs).GetPrivateKey();
1509 }
EXPORT const OTKeypair & GetAuthKeypair(const OTString::List *plistRevokedIDs=nullptr) const
EXPORT const OTAsymmetricKey & GetPrivateKey() const
Definition: OTKeypair.cpp:236
const OTAsymmetricKey & opentxs::OTCredential::GetPrivateEncrKey ( const OTString::List plistRevokedIDs = nullptr) const

Definition at line 1511 of file OTCredential.cpp.

1513 {
1514  return GetEncrKeypair(plistRevokedIDs).GetPrivateKey();
1515 }
EXPORT const OTKeypair & GetEncrKeypair(const OTString::List *plistRevokedIDs=nullptr) const
EXPORT const OTAsymmetricKey & GetPrivateKey() const
Definition: OTKeypair.cpp:236
const OTAsymmetricKey & opentxs::OTCredential::GetPrivateSignKey ( const OTString::List plistRevokedIDs = nullptr) const

Definition at line 1517 of file OTCredential.cpp.

1519 {
1520  return GetSignKeypair(plistRevokedIDs).GetPrivateKey();
1521 }
EXPORT const OTKeypair & GetSignKeypair(const OTString::List *plistRevokedIDs=nullptr) const
EXPORT const OTAsymmetricKey & GetPrivateKey() const
Definition: OTKeypair.cpp:236
const OTString & opentxs::OTCredential::GetPubCredential ( ) const

Definition at line 311 of file OTCredential.cpp.

312 {
313  return m_Masterkey.GetPubCredential();
314 }
EXPORT const OTString & GetPubCredential() const
const OTAsymmetricKey & opentxs::OTCredential::GetPublicAuthKey ( const OTString::List plistRevokedIDs = nullptr) const

Definition at line 1487 of file OTCredential.cpp.

1489 {
1490  return GetAuthKeypair(plistRevokedIDs).GetPublicKey();
1491 }
EXPORT const OTAsymmetricKey & GetPublicKey() const
Definition: OTKeypair.cpp:229
EXPORT const OTKeypair & GetAuthKeypair(const OTString::List *plistRevokedIDs=nullptr) const
const OTAsymmetricKey & opentxs::OTCredential::GetPublicEncrKey ( const OTString::List plistRevokedIDs = nullptr) const

Definition at line 1493 of file OTCredential.cpp.

1495 {
1496  return GetEncrKeypair(plistRevokedIDs).GetPublicKey();
1497 }
EXPORT const OTAsymmetricKey & GetPublicKey() const
Definition: OTKeypair.cpp:229
EXPORT const OTKeypair & GetEncrKeypair(const OTString::List *plistRevokedIDs=nullptr) const
int32_t opentxs::OTCredential::GetPublicKeysBySignature ( listOfAsymmetricKeys listOutput,
const OTSignature theSignature,
char  cKeyType = '0' 
) const

Definition at line 172 of file OTCredential.cpp.

176 {
177  int32_t nCount = 0;
178  for (const auto& it : m_mapSubcredentials) {
179  const OTSubcredential* pSub = it.second;
180  OT_ASSERT(nullptr != pSub);
181 
182  const OTSubkey* pKey = dynamic_cast<const OTSubkey*>(pSub);
183  if (nullptr == pKey)
184  continue; // Skip all non-key credentials. We're looking for keys.
185 
186  const int32_t nTempCount =
187  pKey->GetPublicKeysBySignature(listOutput, theSignature, cKeyType);
188  nCount += nTempCount;
189  }
190  return nCount;
191 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const OTAsymmetricKey & opentxs::OTCredential::GetPublicSignKey ( const OTString::List plistRevokedIDs = nullptr) const

Definition at line 1499 of file OTCredential.cpp.

1501 {
1502  return GetSignKeypair(plistRevokedIDs).GetPublicKey();
1503 }
EXPORT const OTAsymmetricKey & GetPublicKey() const
Definition: OTKeypair.cpp:229
EXPORT const OTKeypair & GetSignKeypair(const OTString::List *plistRevokedIDs=nullptr) const
const OTKeypair & opentxs::OTCredential::GetSignKeypair ( const OTString::List plistRevokedIDs = nullptr) const

Definition at line 1443 of file OTCredential.cpp.

1445 {
1446  for (const auto& it : m_mapSubcredentials) {
1447  const std::string str_cred_id = it.first;
1448  const OTSubcredential* pSub = it.second;
1449  OT_ASSERT(nullptr != pSub);
1450 
1451  const OTSubkey* pKey = dynamic_cast<const OTSubkey*>(pSub);
1452  if (nullptr == pKey) continue;
1453 
1454  // See if pKey, with ID str_cred_id, is on plistRevokedIDs...
1455  //
1456  if (nullptr != plistRevokedIDs) {
1457  auto iter = std::find(plistRevokedIDs->begin(),
1458  plistRevokedIDs->end(), str_cred_id);
1459  if (iter != plistRevokedIDs->end()) // It was on the revoked list.
1460  continue; // Skip this revoked key.
1461  }
1462  // At this point we know it's a key credential, and we know it's not on
1463  // the revoked list. Therefore, let's return the key! (Any other future
1464  // smart criteria might go here before taking this final step...)
1465  //
1466  return pKey->m_SigningKey;
1467  }
1468 
1469  // Didn't find any subcredentials we can use? For now, we'll return the
1470  // master key instead.
1471  // This is purely for backwards compatibility reasons and eventually should
1472  // be removed. That is,
1473  // masters should only be able to verify subkeys, and only subkeys should be
1474  // able to do actions.
1475  // Capiche?
1476  //
1477  return m_Masterkey.m_SigningKey;
1478 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const OTString & opentxs::OTCredential::GetSourceForNymID ( ) const

Definition at line 283 of file OTCredential.cpp.

284 {
285  return m_strSourceForNymID;
286 }
const OTSubcredential * opentxs::OTCredential::GetSubcredential ( const OTString strSubID,
const OTString::List plistRevokedIDs = nullptr 
) const

Definition at line 1300 of file OTCredential.cpp.

1302 {
1303  for (const auto& it : m_mapSubcredentials) {
1304  const std::string str_cred_id = it.first;
1305  const OTSubcredential* pSub = it.second;
1306  OT_ASSERT(nullptr != pSub);
1307 
1308  // See if pSub, with ID str_cred_id, is on plistRevokedIDs...
1309  //
1310  if (nullptr != plistRevokedIDs) {
1311  auto iter = std::find(plistRevokedIDs->begin(),
1312  plistRevokedIDs->end(), str_cred_id);
1313  if (iter != plistRevokedIDs->end()) // It was on the revoked list.
1314  continue; // Skip this revoked credential.
1315  }
1316  // At this point we know it's not on the revoked list, if one was passed
1317  // in.
1318 
1319  if (strSubID.Compare(str_cred_id.c_str())) return pSub;
1320  }
1321  return nullptr;
1322 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const OTSubcredential * opentxs::OTCredential::GetSubcredentialByIndex ( int32_t  nIndex) const

Definition at line 1324 of file OTCredential.cpp.

1326 {
1327  if ((nIndex < 0) ||
1328  (nIndex >= static_cast<int64_t>(m_mapSubcredentials.size()))) {
1329  otErr << __FUNCTION__ << ": Index out of bounds: " << nIndex << "\n";
1330  }
1331  else {
1332  int32_t nLoopIndex = -1;
1333 
1334  for (const auto& it : m_mapSubcredentials) {
1335  const OTSubcredential* pSub = it.second;
1336  OT_ASSERT(nullptr != pSub);
1337 
1338  ++nLoopIndex; // 0 on first iteration.
1339 
1340  if (nIndex == nLoopIndex) return pSub;
1341  }
1342  }
1343 
1344  return nullptr;
1345 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
size_t opentxs::OTCredential::GetSubcredentialCount ( ) const

Definition at line 1295 of file OTCredential.cpp.

1296 {
1297  return m_mapSubcredentials.size();
1298 }
const std::string opentxs::OTCredential::GetSubcredentialIDByIndex ( size_t  nIndex) const

Definition at line 1347 of file OTCredential.cpp.

1348 {
1349  if (nIndex >= m_mapSubcredentials.size()) {
1350  otErr << __FUNCTION__ << ": Index out of bounds: " << nIndex << "\n";
1351  }
1352  else {
1353  int32_t nLoopIndex = -1;
1354 
1355  for (const auto& it : m_mapSubcredentials) {
1356  const std::string str_cred_id = it.first;
1357  const OTSubcredential* pSub = it.second;
1358  OT_ASSERT(nullptr != pSub);
1359 
1360  ++nLoopIndex; // 0 on first iteration.
1361 
1362  if (static_cast<int64_t>(nIndex) == nLoopIndex) return str_cred_id;
1363  }
1364  }
1365 
1366  return nullptr;
1367 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTCredential::Load_Master ( const OTString strNymID,
const OTString strMasterCredID,
const OTPasswordData pPWData = nullptr 
)

Definition at line 806 of file OTCredential.cpp.

809 {
810 
811  std::string str_Folder =
812  OTFolders::Credential().Get(); // Try private credential first. If that
813  // fails, then public.
814 
815  if (false ==
816  OTDB::Exists(str_Folder, strNymID.Get(), strMasterCredID.Get())) {
817  str_Folder = OTFolders::Pubcred().Get();
818 
819  if (false ==
820  OTDB::Exists(str_Folder, strNymID.Get(), strMasterCredID.Get())) {
821  otErr << __FUNCTION__ << ": Failure: Master Credential "
822  << strMasterCredID << " doesn't exist for Nym " << strNymID
823  << "\n";
824  return false;
825  }
826  }
827 
828  OTString strFileContents(OTDB::QueryPlainString(str_Folder, strNymID.Get(),
829  strMasterCredID.Get()));
830  if (!strFileContents.Exists()) {
831  otErr << __FUNCTION__ << ": Failed trying to load master credential "
832  "from local storage.\n";
833  return false;
834  }
835 
836  if (false ==
837  strFileContents.DecodeIfArmored()) // bEscapedIsAllowed=true by default.
838  {
839  otErr << __FUNCTION__ << ": File contents apparently were encoded and "
840  "then failed decoding. Contents: \n"
841  << strFileContents << "\n";
842  return false;
843  }
844 
845  return Load_MasterFromString(strFileContents, strNymID, strMasterCredID,
846  pPWData);
847 }
static EXPORT const OTString & Pubcred()
Definition: OTFolders.cpp:343
EXPORT bool Load_MasterFromString(const OTString &strInput, const OTString &strNymID, const OTString &strMasterCredID, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr)
static EXPORT const OTString & Credential()
Definition: OTFolders.cpp:307
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:728
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
bool opentxs::OTCredential::Load_MasterFromString ( const OTString strInput,
const OTString strNymID,
const OTString strMasterCredID,
const OTPasswordData pPWData = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 758 of file OTCredential.cpp.

763 {
764  m_strNymID = strNymID;
765  m_strMasterCredID = strMasterCredID;
766 
767  m_Masterkey.SetIdentifier(strMasterCredID);
768 
769  // m_Masterkey and the subkeys all have a pointer to "owner" (who is *this)
770  // and so I can set pImportPassword onto a member variable, perform the
771  // load,
772  // and then set that member nullptr again. During the call to
773  // LoadContractFromString,
774  // m_Masterkey can reference m_pOwner->GetImportPassword() and if it's not
775  // nullptr,
776  // use it instead of using the wallet's cached master key. After all, if
777  // it's not
778  // nullptr here, that's why it was passed in.
779  //
780 
781  SetImportPassword(pImportPassword); // might be nullptr.
782 
783  const bool bLoaded = m_Masterkey.LoadContractFromString(strInput);
784  if (!bLoaded) {
785  otErr << __FUNCTION__
786  << ": Failed trying to load master credential from string.\n";
787  return false;
788  }
789 
790  SetImportPassword(nullptr); // It was only set during the
791  // m_Masterkey.LoadContractFromString (which
792  // references it.)
793 
794  m_strNymID = m_Masterkey.GetNymID();
795  m_strSourceForNymID = m_Masterkey.GetNymIDSource();
796 
797  ClearSubcredentials(); // The master is loaded first, and then any
798  // subcredentials. So this is probably already
799  // empty. Just looking ahead.
800 
801  m_Masterkey.SetMetadata();
802 
803  return true;
804 }
EXPORT void ClearSubcredentials()
void SetIdentifier(const OTIdentifier &theID)
Definition: OTContract.hpp:268
const OTString & GetNymID() const
EXPORT void SetImportPassword(const OTPassword *pImportPassword)
const OTString & GetNymIDSource() const
OTLOG_IMPORT OTLogStream otErr
EXPORT bool LoadContractFromString(const OTString &theStr)
OTCredential * opentxs::OTCredential::LoadMaster ( const OTString strNymID,
const OTString strMasterCredID,
const OTPasswordData pPWData = nullptr 
)
static

Definition at line 349 of file OTCredential.cpp.

353 {
354  OTCredential* pCredential = new OTCredential;
355  std::unique_ptr<OTCredential> theCredentialAngel(pCredential);
356  OT_ASSERT(nullptr != pCredential);
357 
358  OTPasswordData thePWData("Loading master credential. (static 1.)");
359  const bool bLoaded = pCredential->Load_Master(
360  strNymID, strMasterCredID, (nullptr == pPWData) ? &thePWData : pPWData);
361  if (!bLoaded) {
362  otErr << __FUNCTION__ << ": Failed trying to load master credential "
363  "from local storage. 1\n";
364  return nullptr;
365  }
366 
367  return theCredentialAngel.release();
368 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
OTCredential * opentxs::OTCredential::LoadMasterFromString ( const OTString strInput,
const OTString strNymID,
const OTString strMasterCredID,
OTPasswordData pPWData = nullptr,
const OTPassword pImportPassword = nullptr 
)
static

Definition at line 371 of file OTCredential.cpp.

377 {
378  OTCredential* pCredential = new OTCredential;
379  std::unique_ptr<OTCredential> theCredentialAngel(pCredential);
380  OT_ASSERT(nullptr != pCredential);
381 
382  OTPasswordData thePWData(nullptr == pImportPassword
383  ? "Enter wallet master passphrase."
384  : "Enter passphrase for exported Nym.");
385  const bool bLoaded = pCredential->Load_MasterFromString(
386  strInput, strNymID, strMasterCredID,
387  (nullptr == pPWData) ? &thePWData : pPWData, pImportPassword);
388  if (!bLoaded) {
389  otErr << __FUNCTION__
390  << ": Failed trying to load master credential from string. 2\n";
391  return nullptr;
392  }
393 
394  return theCredentialAngel.release();
395 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTCredential::LoadSubcredential ( const OTString strSubID)

Definition at line 985 of file OTCredential.cpp.

986 {
987 
988  std::string str_Folder =
989  OTFolders::Credential().Get(); // Try private credential first. If that
990  // fails, then public.
991 
992  if (!OTDB::Exists(str_Folder, GetNymID().Get(), strSubID.Get())) {
993  str_Folder = OTFolders::Pubcred().Get();
994 
995  if (false ==
996  OTDB::Exists(str_Folder, GetNymID().Get(), strSubID.Get())) {
997  otErr << __FUNCTION__ << ": Failure: Credential " << strSubID
998  << " doesn't exist for Nym " << GetNymID() << "\n";
999  return false;
1000  }
1001  }
1002 
1003  OTString strFileContents(
1004  OTDB::QueryPlainString(str_Folder, GetNymID().Get(), strSubID.Get()));
1005  if (!strFileContents.Exists()) {
1006  otErr << __FUNCTION__
1007  << ": Failed trying to load subCredential from local storage.\n";
1008  return false;
1009  }
1010 
1011  if (false ==
1012  strFileContents.DecodeIfArmored()) // bEscapedIsAllowed=true by default.
1013  {
1014  otErr << __FUNCTION__ << ": File contents apparently were encoded and "
1015  "then failed decoding. Contents: \n"
1016  << strFileContents << "\n";
1017  return false;
1018  }
1019 
1020  return LoadSubcredentialFromString(strFileContents, strSubID);
1021 }
EXPORT const OTString & GetNymID() const
EXPORT bool LoadSubcredentialFromString(const OTString &strInput, const OTString &strSubID, const OTPassword *pImportPassword=nullptr)
static EXPORT const OTString & Pubcred()
Definition: OTFolders.cpp:343
static EXPORT const OTString & Credential()
Definition: OTFolders.cpp:307
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:728
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
bool opentxs::OTCredential::LoadSubcredentialFromString ( const OTString strInput,
const OTString strSubID,
const OTPassword pImportPassword = nullptr 
)

Definition at line 937 of file OTCredential.cpp.

940 {
941  // Make sure it's not already there.
942  //
943  auto it = m_mapSubcredentials.find(strSubID.Get());
944  if (it != m_mapSubcredentials.end()) // It was already there. (Reload it.)
945  {
946  otErr << __FUNCTION__ << ": Warning: Deleting and re-loading "
947  "subCredential that was already loaded.\n";
948  OTSubcredential* pSub = it->second;
949  OT_ASSERT(nullptr != pSub);
950  delete pSub;
951  m_mapSubcredentials.erase(it);
952  }
953 
954  OTSubcredential* pSub = new OTSubcredential(*this);
955  std::unique_ptr<OTSubcredential> theSubAngel(pSub);
956  OT_ASSERT(nullptr != pSub);
957 
958  pSub->SetIdentifier(strSubID);
959  pSub->SetNymIDandSource(GetNymID(),
960  GetSourceForNymID()); // Set NymID and source
961  // string that hashes to
962  // it.
963  pSub->SetMasterCredID(GetMasterCredID()); // Set master credential ID
964  // (onto this new
965  // subcredential...)
966 
967  SetImportPassword(pImportPassword); // might be nullptr.
968 
969  if (!pSub->LoadContractFromString(strInput)) {
970  otErr << __FUNCTION__
971  << ": Failed trying to load subCredential from string.\n";
972  return false;
973  }
974 
975  SetImportPassword(nullptr); // This is only set int64_t enough for
976  // LoadContractFromString to use it. (Then
977  // back to nullptr.)
978 
979  m_mapSubcredentials.insert(std::pair<std::string, OTSubcredential*>(
980  strSubID.Get(), theSubAngel.release()));
981 
982  return true;
983 }
EXPORT const OTString & GetNymID() const
EXPORT const OTString & GetMasterCredID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT void SetImportPassword(const OTPassword *pImportPassword)
OTLOG_IMPORT OTLogStream otErr
EXPORT const OTString & GetSourceForNymID() const
bool opentxs::OTCredential::LoadSubkey ( const OTString strSubID)

Definition at line 898 of file OTCredential.cpp.

899 {
900 
901  std::string str_Folder =
902  OTFolders::Credential().Get(); // Try private credential first. If that
903  // fails, then public.
904 
905  if (!OTDB::Exists(str_Folder, GetNymID().Get(), strSubID.Get())) {
906  str_Folder = OTFolders::Pubcred().Get();
907 
908  if (false ==
909  OTDB::Exists(str_Folder, GetNymID().Get(), strSubID.Get())) {
910  otErr << __FUNCTION__ << ": Failure: Key Credential " << strSubID
911  << " doesn't exist for Nym " << GetNymID() << "\n";
912  return false;
913  }
914  }
915 
916  OTString strFileContents(
917  OTDB::QueryPlainString(str_Folder, GetNymID().Get(), strSubID.Get()));
918 
919  if (!strFileContents.Exists()) {
920  otErr << __FUNCTION__
921  << ": Failed trying to load keyCredential from local storage.\n";
922  return false;
923  }
924 
925  if (false ==
926  strFileContents.DecodeIfArmored()) // bEscapedIsAllowed=true by default.
927  {
928  otErr << __FUNCTION__ << ": File contents apparently were encoded and "
929  "then failed decoding. Contents: \n"
930  << strFileContents << "\n";
931  return false;
932  }
933 
934  return LoadSubkeyFromString(strFileContents, strSubID);
935 }
EXPORT const OTString & GetNymID() const
static EXPORT const OTString & Pubcred()
Definition: OTFolders.cpp:343
static EXPORT const OTString & Credential()
Definition: OTFolders.cpp:307
EXPORT bool LoadSubkeyFromString(const OTString &strInput, const OTString &strSubID, const OTPassword *pImportPassword=nullptr)
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:728
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
bool opentxs::OTCredential::LoadSubkeyFromString ( const OTString strInput,
const OTString strSubID,
const OTPassword pImportPassword = nullptr 
)

Definition at line 849 of file OTCredential.cpp.

852 {
853  // Make sure it's not already there.
854  //
855  auto it = m_mapSubcredentials.find(strSubID.Get());
856  if (it != m_mapSubcredentials.end()) // It was already there. (Reload it.)
857  {
858  otErr << __FUNCTION__ << ": Warning: Deleting and re-loading "
859  "keyCredential that was already loaded.\n";
860  OTSubcredential* pSub = it->second;
861  OT_ASSERT(nullptr != pSub);
862  delete pSub;
863  m_mapSubcredentials.erase(it);
864  }
865 
866  OTSubkey* pSub = new OTSubkey(*this);
867  std::unique_ptr<OTSubkey> theSubAngel(pSub);
868  OT_ASSERT(nullptr != pSub);
869 
870  pSub->SetIdentifier(strSubID);
871  pSub->SetNymIDandSource(GetNymID(),
872  GetSourceForNymID()); // Set NymID and source
873  // string that hashes to
874  // it.
875  pSub->SetMasterCredID(GetMasterCredID()); // Set master credential ID
876  // (onto this new
877  // subcredential...)
878 
879  SetImportPassword(pImportPassword); // might be nullptr.
880 
881  if (!pSub->LoadContractFromString(strInput)) {
882  otErr << __FUNCTION__
883  << ": Failed trying to load keyCredential from string.\n";
884  return false;
885  }
886 
887  SetImportPassword(nullptr); // Only set int64_t enough for
888  // LoadContractFromString above to use it.
889 
890  pSub->SetMetadata();
891 
892  m_mapSubcredentials.insert(std::pair<std::string, OTSubcredential*>(
893  strSubID.Get(), theSubAngel.release()));
894 
895  return true;
896 }
EXPORT const OTString & GetNymID() const
EXPORT const OTString & GetMasterCredID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT void SetImportPassword(const OTPassword *pImportPassword)
OTLOG_IMPORT OTLogStream otErr
EXPORT const OTString & GetSourceForNymID() const
bool opentxs::OTCredential::ReEncryptPrivateCredentials ( const OTPassword theExportPassword,
bool  bImporting 
)

Definition at line 489 of file OTCredential.cpp.

491 {
492  if (m_Masterkey.GetPrivateMap().size() > 0) {
493  OTPasswordData thePWData(
494  bImporting ? "2 Enter passphrase for the Nym being imported."
495  : "2 Enter new passphrase for exported Nym.");
496 
497  // Re-encrypt the private keys in the masterkey. (THEN sign.)
498  //
499  const bool bReEncryptMaster =
500  m_Masterkey.ReEncryptKeys(theExportPassword, bImporting);
501  bool bSignedMaster = false;
502 
503  if (bReEncryptMaster) {
504  m_Masterkey.ReleaseSignatures(); // This time we'll sign it in
505  // private mode.
506  bSignedMaster = m_Masterkey.Sign(m_Masterkey, &thePWData);
507  }
508  else {
509  otErr << "In " << __FILE__ << ", line " << __LINE__
510  << ": Failed trying to re-encrypt the private masterkey.\n";
511  return false;
512  }
513 
514  if (bSignedMaster) {
515  m_Masterkey.SaveContract();
516  m_Masterkey.SetMetadata(); // todo: can probably remove this, since
517  // it was set based on public info when
518  // the key was first created.
519 
520  for (auto& it : m_mapSubcredentials) {
521  OTSubcredential* pSub = it.second;
522  OT_ASSERT(nullptr != pSub);
523 
524  OTSubkey* pKey = dynamic_cast<OTSubkey*>(pSub);
525  if (nullptr == pKey) continue;
526 
527  const bool bReEncryptSubkey =
528  pKey->ReEncryptKeys(theExportPassword, bImporting);
529  bool bSignedSubkey = false;
530 
531  if (bReEncryptSubkey) {
532  pKey->ReleaseSignatures();
533  bSignedSubkey = pKey->Sign(*pKey, &thePWData);
534  }
535  else {
536  otErr << "In " << __FILE__ << ", line " << __LINE__
537  << ": Failed trying to re-encrypt the private "
538  "subkey.\n";
539  return false;
540  }
541 
542  if (bSignedSubkey) {
543  pKey->SaveContract();
544  pKey->SetMetadata(); // todo: can probably remove this,
545  // since it was set based on public
546  // info when the key was first created.
547  }
548  else {
549  otErr << "In " << __FILE__ << ", line " << __LINE__
550  << ": Failed trying to re-sign the private subkey.\n";
551  return false;
552  }
553  }
554 
555  return true; // <=== Success.
556  }
557  else
558  otErr << "In " << __FILE__ << ", line " << __LINE__
559  << ": Failed trying to re-sign the master private "
560  "credential.\n";
561  }
562  else
563  otErr << "In " << __FILE__ << ", line " << __LINE__
564  << ": Failed: There is no private info on this master "
565  "credential.\n";
566 
567  return false;
568 }
const OTString::Map & GetPrivateMap() const
EXPORT bool SaveContract()
bool Sign(OTContract &theContract, const OTPasswordData *pPWData=nullptr)
EXPORT void ReleaseSignatures()
Definition: OTContract.cpp:989
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool ReEncryptKeys(const OTPassword &theExportPassword, bool bImporting)
OTLOG_IMPORT OTLogStream otErr
void opentxs::OTCredential::SerializeIDs ( OTString strOutput,
const OTString::List listRevokedIDs,
OTString::Map pmapPubInfo = nullptr,
OTString::Map pmapPriInfo = nullptr,
bool  bShowRevoked = false,
bool  bValid = true 
) const

Definition at line 1553 of file OTCredential.cpp.

1558 {
1559  if (bValid || bShowRevoked) {
1560  strOutput.Concatenate("<masterCredential\n"
1561  " ID=\"%s\"\n"
1562  " valid=\"%s\""
1563  "/>\n\n",
1564  GetMasterCredID().Get(),
1565  bValid ? "true" : "false");
1566 
1567  if (nullptr != pmapPubInfo) // optional out-param.
1568  pmapPubInfo->insert(std::pair<std::string, std::string>(
1569  GetMasterCredID().Get(), GetPubCredential().Get()));
1570 
1571  if (nullptr != pmapPriInfo) // optional out-param.
1572  pmapPriInfo->insert(std::pair<std::string, std::string>(
1573  GetMasterCredID().Get(), GetPriCredential().Get()));
1574  }
1575 
1576  for (const auto& it : m_mapSubcredentials) {
1577  const std::string str_cred_id = it.first;
1578  const OTSubcredential* pSub = it.second;
1579  OT_ASSERT(nullptr != pSub);
1580 
1581  // See if the current subcredential is on the Nym's list of "revoked"
1582  // subcredential IDs.
1583  // If so, we'll skip serializing it here.
1584  //
1585  auto iter = std::find(listRevokedIDs.begin(), listRevokedIDs.end(),
1586  str_cred_id);
1587 
1588  // Was it on the 'revoked' list?
1589  // If not, then the subcredential isn't revoked, so it's still valid.
1590  //
1591  const bool bSubcredValid =
1592  bValid ? (iter == listRevokedIDs.end()) : false;
1593 
1594  if (bSubcredValid || bShowRevoked) {
1595  const OTSubkey* pSubkey = dynamic_cast<const OTSubkey*>(pSub);
1596 
1597  if (nullptr != pSubkey)
1598  strOutput.Concatenate("<keyCredential\n"
1599  " ID=\"%s\"\n"
1600  " masterID=\"%s\"\n"
1601  " valid=\"%s\""
1602  "/>\n\n",
1603  str_cred_id.c_str(),
1604  pSubkey->GetMasterCredID().Get(),
1605  bSubcredValid ? "true" : "false");
1606  else
1607  strOutput.Concatenate("<subCredential\n"
1608  " ID=\"%s\"\n"
1609  " masterID=\"%s\"\n"
1610  " valid=\"%s\""
1611  "/>\n\n",
1612  str_cred_id.c_str(),
1613  pSub->GetMasterCredID().Get(),
1614  bSubcredValid ? "true" : "false");
1615 
1616  if (nullptr != pmapPubInfo) // optional out-param.
1617  pmapPubInfo->insert(std::pair<std::string, std::string>(
1618  str_cred_id.c_str(), pSub->GetPubCredential().Get()));
1619 
1620  if (nullptr != pmapPriInfo) // optional out-param.
1621  pmapPriInfo->insert(std::pair<std::string, std::string>(
1622  str_cred_id.c_str(), pSub->GetPriCredential().Get()));
1623 
1624  } // if (bSubcredValid)
1625  }
1626 }
EXPORT const OTString & GetPriCredential() const
EXPORT const OTString & GetMasterCredID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const OTString & GetPubCredential() const
EXPORT void opentxs::OTCredential::SetImportPassword ( const OTPassword pImportPassword)
inline

Definition at line 277 of file OTCredential.hpp.

278  {
279  m_pImportPassword = pImportPassword;
280  }
bool opentxs::OTCredential::VerifyAgainstSource ( ) const

Definition at line 242 of file OTCredential.cpp.

243 {
244  // * Any OTMasterkey must (at some point, and/or regularly) verify against
245  // its own source.
246  //
247  if (!m_Masterkey.VerifyAgainstSource()) {
248  otWarn
249  << __FUNCTION__
250  << ": Failed verifying master credential against its own source.\n";
251  return false;
252  }
253  // NOTE: This spot will have a significant delay, TODO OPTIMIZE. Performing
254  // a Freenet lookup, or DNS, etc,
255  // will introduce delay inside the call VerifyAgainstSource. Therefore in
256  // the int64_t term, we must have a
257  // separate server process which will verify identities for some specified
258  // period of time (specified in
259  // their credentials I suppose...) That way, when we call
260  // VerifyAgainstSource, we are verifying against
261  // some server-signed authorization, based on a lookup that some separate
262  // process did within the past
263  // X allowed time, such that the lookup is still considered valid (without
264  // having to lookup every single
265  // time, which is untenable.)
266 
267  return true;
268 }
bool VerifyAgainstSource() const
OTLOG_IMPORT OTLogStream otWarn
bool opentxs::OTCredential::VerifyInternally ( ) const

Definition at line 193 of file OTCredential.cpp.

194 {
195 
196  OTIdentifier theActualMasterCredID;
197  theActualMasterCredID.CalculateDigest(m_Masterkey.GetPubCredential());
198  const OTString strActualMasterCredID(theActualMasterCredID);
199 
200  if (!m_strNymID.Compare(m_Masterkey.GetNymID())) {
201  otOut << __FUNCTION__
202  << ": NymID did not match its "
203  "counterpart in m_Masterkey (failed to verify): " << GetNymID()
204  << "\n";
205  return false;
206  }
207 
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: "
212  << GetMasterCredID()
213  << "\n "
214  "Hash of m_Masterkey contents: " << strActualMasterCredID
215  << "\nContents:\n" << m_Masterkey.GetPubCredential() << "\n";
216  return false;
217  }
218 
219  if (!const_cast<OTMasterkey&>(m_Masterkey).VerifyContract()) {
220  otOut << __FUNCTION__
221  << ": Master Credential failed to verify: " << GetMasterCredID()
222  << "\nNymID: " << GetNymID() << "\n";
223  return false;
224  }
225 
226  for (const auto& it : m_mapSubcredentials) {
227  std::string str_sub_id = it.first;
228  OTSubcredential* pSub = it.second;
229  OT_ASSERT(nullptr != pSub);
230 
231  if (!pSub->VerifyContract()) {
232  otOut << __FUNCTION__
233  << ": Subcredential failed to verify: " << str_sub_id
234  << "\nNymID: " << GetNymID() << "\n";
235  return false;
236  }
237  }
238 
239  return true;
240 }
EXPORT const OTString & GetNymID() const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool Compare(const char *compare) const
Definition: OTString.cpp:1102
EXPORT const OTString & GetMasterCredID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const OTString & GetNymID() const
EXPORT const OTString & GetPubCredential() const

The documentation for this class was generated from the following files: