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

#include <OTSubcredential.hpp>

Inheritance diagram for opentxs::OTSubcredential:
Collaboration diagram for opentxs::OTSubcredential:

Public Member Functions

const OTString::MapGetPublicMap () const
 
const OTString::MapGetPrivateMap () const
 
const OTStringGetMasterCredID () const
 
const OTStringGetNymID () const
 
const OTStringGetNymIDSource () const
 
const OTStringGetContents () const
 
EXPORT const OTStringGetPubCredential () const
 
const OTStringGetPriCredential () const
 
const OTStringGetMasterSigned () const
 
virtual bool VerifyInternally ()
 
virtual EXPORT void CalculateContractID (OTIdentifier &newID) const
 
virtual bool VerifyContract ()
 
bool VerifyNymID () const
 
virtual bool VerifySignedByMaster ()
 
void SetOwner (OTCredential &theOwner)
 
virtual void SetMetadata ()
 
 OTSubcredential ()
 
 OTSubcredential (OTCredential &theOwner)
 
virtual ~OTSubcredential ()
 
virtual void Release ()
 
void Release_Subcredential ()
 
virtual void UpdateContents ()
 
virtual int32_t ProcessXMLNode (irr::io::IrrXMLReader *&xml)
 
virtual bool SaveContractWallet (std::ofstream &) const
 
- Public Member Functions inherited from opentxs::OTContract
const char * GetHashType () const
 
void SetIdentifier (const OTIdentifier &theID)
 
EXPORT OTContract ()
 
EXPORT OTContract (const OTString &name, const OTString &foldername, const OTString &filename, const OTString &strID)
 
EXPORT OTContract (const OTString &strID)
 
EXPORT OTContract (const OTIdentifier &theID)
 
void Initialize ()
 
virtual EXPORT ~OTContract ()
 
EXPORT void Release_Contract ()
 
EXPORT void ReleaseSignatures ()
 
virtual EXPORT bool CreateContract (const OTString &strContract, const OTPseudonym &theSigner)
 
EXPORT bool InsertNym (const OTString &strKeyName, const OTString &strKeyValue)
 
EXPORT void GetName (OTString &strName) const
 
EXPORT void SetName (const OTString &strName)
 
virtual EXPORT void GetIdentifier (OTIdentifier &theIdentifier) const
 
virtual EXPORT void GetIdentifier (OTString &theIdentifier) const
 
EXPORT void GetFilename (OTString &strFilename) const
 
EXPORT void GetFoldername (OTString &strFoldername) const
 
virtual EXPORT bool LoadContract ()
 
EXPORT bool LoadContract (const char *szFoldername, const char *szFilename)
 
EXPORT bool LoadContractFromString (const OTString &theStr)
 
bool LoadContractRawFile ()
 
EXPORT bool ParseRawFile ()
 
EXPORT bool SaveToContractFolder ()
 
EXPORT bool SaveContractRaw (OTString &strOutput) const
 
EXPORT bool RewriteContract (OTString &strOutput) const
 
EXPORT bool SaveContract ()
 
EXPORT bool SaveContract (const char *szFoldername, const char *szFilename)
 
virtual EXPORT void CreateContents ()
 
EXPORT void CreateInnerContents ()
 
virtual EXPORT bool SaveContents (std::ofstream &ofs) const
 
virtual EXPORT bool SaveContractWallet (OTString &strContents) const
 
virtual EXPORT bool DisplayStatistics (OTString &strContents) const
 
virtual EXPORT bool SaveContents (OTString &strContents) const
 
virtual EXPORT bool SignContract (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContractAuthent (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignWithKey (const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const OTPseudonym &theNym, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContractAuthent (const OTPseudonym &theNym, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const OTAsymmetricKey &theKey, OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const char *szFoldername, const char *szFilename, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
virtual EXPORT bool VerifyContractID () const
 
virtual EXPORT bool VerifySignature (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
 
virtual EXPORT bool VerifySigAuthent (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifyWithKey (const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const OTPseudonym &theNym, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySigAuthent (const OTPseudonym &theNym, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const OTAsymmetricKey &theKey, const OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const char *szFoldername, const char *szFilename, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT const OTAsymmetricKeyGetContractPublicKey () const
 
EXPORT const OTPseudonymGetContractPublicNym () const
 

Protected Types

enum  CredStoreAs { credPrivateInfo, credPublicInfo = 1, credMasterSigned = 2 }
 

Protected Member Functions

void UpdateMasterPublicToString (OTString &strAppendTo)
 
void UpdatePublicContentsToString (OTString &strAppendTo)
 
void UpdatePublicCredentialToString (OTString &strAppendTo)
 
void UpdatePrivateContentsToString (OTString &strAppendTo)
 
void SetMasterSigned (const OTString &strMasterSigned)
 
void SetContents (const OTString &strContents)
 
void SetNymIDandSource (const OTString &strNymID, const OTString &strSourceForNymID)
 
void SetMasterCredID (const OTString &strMasterCredID)
 
void StoreAsMasterSigned ()
 
void StoreAsPublic ()
 
virtual bool SetPublicContents (const OTString::Map &mapPublic)
 
virtual bool SetPrivateContents (const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
 
- Protected Member Functions inherited from opentxs::OTContract
bool LoadContractXML ()
 

Protected Attributes

CredStoreAs m_StoreAs
 
OTCredentialm_pOwner
 
OTString m_strMasterCredID
 
OTString m_strNymID
 
OTString m_strSourceForNymID
 
OTString::Map m_mapPublicInfo
 
OTString::Map m_mapPrivateInfo
 
OTString m_strMasterSigned
 
OTString m_strContents
 
- Protected Attributes inherited from opentxs::OTContract
OTString m_strName
 
OTString m_strFoldername
 
OTString m_strFilename
 
OTIdentifier m_ID
 
OTStringXML m_xmlUnsigned
 
OTString m_strRawFile
 
OTString m_strSigHashType
 
OTString m_strContractType
 
mapOfNyms m_mapNyms
 
listOfSignatures m_listSignatures
 
OTString m_strVersion
 
OTString m_strEntityShortName
 
OTString m_strEntityLongName
 
OTString m_strEntityEmail
 
OTString::Map m_mapConditions
 

Friends

class OTCredential
 

Additional Inherited Members

- Static Public Member Functions inherited from opentxs::OTContract
static EXPORT bool DearmorAndTrim (const OTString &strInput, OTString &strOutput, OTString &strFirstLine)
 
static bool AddBookendsAroundContent (OTString &strOutput, const OTString &strContents, const OTString &strContractType, const OTString &strHashType, const listOfSignatures &listSignatures)
 
static EXPORT bool LoadEncodedTextField (irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
 
static EXPORT bool LoadEncodedTextField (irr::io::IrrXMLReader *&xml, OTString &strOutput)
 
static bool LoadEncodedTextFieldByName (irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)
 
static bool LoadEncodedTextFieldByName (irr::io::IrrXMLReader *&xml, OTString &strOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)
 
static bool SkipToElement (irr::io::IrrXMLReader *&xml)
 
static bool SkipToTextField (irr::io::IrrXMLReader *&xml)
 
static bool SkipAfterLoadingField (irr::io::IrrXMLReader *&xml)
 
static EXPORT bool SignFlatText (OTString &strFlatText, const OTString &strContractType, const OTPseudonym &theSigner, OTString &strOutput)
 

Detailed Description

Definition at line 185 of file OTSubcredential.hpp.

Member Enumeration Documentation

Enumerator
credPrivateInfo 
credPublicInfo 
credMasterSigned 

Definition at line 192 of file OTSubcredential.hpp.

192  {
194  0, // For saving the private keys, too. Default behavior.
195  credPublicInfo = 1, // For saving a version with public keys only.
196  credMasterSigned = 2 // For saving a version with the master signature
197  // included, so the subkey can then countersign on
198  // top of that. (To prove that the subkey
199  // authorizes the master key's signature.) Only
200  // used by subkeys.
201  };

Constructor & Destructor Documentation

opentxs::OTSubcredential::OTSubcredential ( )

Definition at line 171 of file OTSubcredential.cpp.

172  : ot_super()
174  , m_pOwner(nullptr)
175 {
176  m_strContractType = "CREDENTIAL";
177 }
OTString m_strContractType
Definition: OTContract.hpp:178
opentxs::OTSubcredential::OTSubcredential ( OTCredential theOwner)

Definition at line 179 of file OTSubcredential.cpp.

180  : ot_super()
182  , m_pOwner(&theOwner)
183 {
184  m_strContractType = "CREDENTIAL";
185 }
OTString m_strContractType
Definition: OTContract.hpp:178
opentxs::OTSubcredential::~OTSubcredential ( )
virtual

Definition at line 187 of file OTSubcredential.cpp.

188 {
190 }

Member Function Documentation

void opentxs::OTSubcredential::CalculateContractID ( OTIdentifier newID) const
virtual

Reimplemented from opentxs::OTContract.

Definition at line 759 of file OTSubcredential.cpp.

760 {
761  if (!newID.CalculateDigest(GetPubCredential()))
762  otErr << __FUNCTION__ << ": Error calculating credential digest.\n";
763 }
OTLOG_IMPORT OTLogStream otErr
EXPORT const OTString & GetPubCredential() const
const OTString& opentxs::OTSubcredential::GetContents ( ) const
inline

Definition at line 292 of file OTSubcredential.hpp.

293  {
294  return m_strContents;
295  } // The actual, final, signed public credential. Public keys only.
const OTString& opentxs::OTSubcredential::GetMasterCredID ( ) const
inline

Definition at line 280 of file OTSubcredential.hpp.

281  {
282  return m_strMasterCredID;
283  } // MasterCredentialID (usually applicable.) OTMasterkey doesn't use this.
const OTString& opentxs::OTSubcredential::GetMasterSigned ( ) const
inline

Definition at line 304 of file OTSubcredential.hpp.

305  {
306  return m_strMasterSigned;
307  } // For subkeys, the master credential signs first, then the subkey signs a
const OTString& opentxs::OTSubcredential::GetNymID ( ) const
inline

Definition at line 284 of file OTSubcredential.hpp.

285  {
286  return m_strNymID;
287  } // NymID for this credential.
const OTString& opentxs::OTSubcredential::GetNymIDSource ( ) const
inline

Definition at line 288 of file OTSubcredential.hpp.

289  {
290  return m_strSourceForNymID;
291  } // Source for NymID for this credential. (Hash it to get ID.)
const OTString & opentxs::OTSubcredential::GetPriCredential ( ) const

Definition at line 766 of file OTSubcredential.cpp.

767 {
768  OT_ASSERT_MSG(!m_mapPrivateInfo.empty(), "ASSERT: GetPriCredential can "
769  "only be called on private "
770  "subcredentials.");
771 
772  return m_strRawFile;
773 }
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
const OTString::Map& opentxs::OTSubcredential::GetPrivateMap ( ) const
inline

Definition at line 276 of file OTSubcredential.hpp.

277  {
278  return m_mapPrivateInfo;
279  }
const OTString & opentxs::OTSubcredential::GetPubCredential ( ) const

Definition at line 779 of file OTSubcredential.cpp.

783 {
784  // If this is a private (client-side) credential containing private keys,
785  // then the public version is stored in GetContents(), and return that.
786  if ((!m_mapPrivateInfo.empty()) && GetContents().Exists())
787  return GetContents();
788 
789  // Otherwise this is a server-side copy of a Nym's credential, with no
790  // private keys inside it.
791  // In which case public info that would have been in GetContents (making
792  // room so we can have
793  // the private keys in m_strRawFile) is now directly found in m_strRawFile,
794  // since that's all the
795  // server ever loads up. There is only public info and nothing else, so it's
796  // found in the main
797  // normal location, m_strRawFile.
798  //
799  return m_strRawFile;
800 }
const OTString & GetContents() const
EXPORT bool Exists() const
Definition: OTString.cpp:1035
const OTString::Map& opentxs::OTSubcredential::GetPublicMap ( ) const
inline

Definition at line 272 of file OTSubcredential.hpp.

273  {
274  return m_mapPublicInfo;
275  }
int32_t opentxs::OTSubcredential::ProcessXMLNode ( irr::io::IrrXMLReader *&  xml)
virtual

Reimplemented from opentxs::OTContract.

Reimplemented in opentxs::OTMasterkey, and opentxs::OTSubkey.

Definition at line 344 of file OTSubcredential.cpp.

345 {
346  int32_t nReturnVal = 0;
347 
348  const OTString strNodeName(xml->getNodeName());
349 
350  // Here we call the parent class first.
351  // If the node is found there, or there is some error,
352  // then we just return either way. But if it comes back
353  // as '0', then nothing happened, and we'll continue executing.
354  //
355  // -- Note you can choose not to call the parent if
356  // you don't want to use any of those xml tags.
357  // As I do in the case of OTAccount.
358  //
359  // if (nReturnVal = OTContract::ProcessXMLNode(xml))
360  // return nReturnVal;
361 
362  if (strNodeName.Compare("subCredential")) {
363  m_strNymID = xml->getAttributeValue("nymID");
364  m_strMasterCredID = xml->getAttributeValue("masterCredentialID");
365 
366  otWarn << "Loading subcredential...\n";
367 
368  nReturnVal = 1;
369  }
370  else if (strNodeName.Compare("nymIDSource")) {
371  otWarn << "Loading nymIDSource...\n";
372 
373  OTASCIIArmor ascTemp;
374  if (!OTContract::LoadEncodedTextField(xml, ascTemp)) {
375  otErr << "Error in " << __FILE__ << " line " << __LINE__
376  << ": failed loading expected nymIDSource field.\n";
377  return (-1); // error condition
378  }
379  if (ascTemp.Exists()) ascTemp.GetString(m_strSourceForNymID);
380 
381  nReturnVal = 1;
382  }
383  else if (strNodeName.Compare("masterPublic")) {
384  OTString strMasterPublicCredential;
385 
386  if (false ==
387  OTContract::LoadEncodedTextField(xml, strMasterPublicCredential)) {
388  otErr << "Error in " << __FILE__ << " line " << __LINE__
389  << ": failed loading expected master public credential while "
390  "loading subcredential.\n";
391  return (-1); // error condition
392  }
393  // Verify the master public credential we loaded against the one we
394  // expected to get, according
395  // to the OTCredential that is m_pOwner.
396  //
397  else if ((nullptr != m_pOwner) &&
398  false == (m_pOwner->GetPubCredential().Compare(
399  strMasterPublicCredential))) {
400  otErr << "Failure in " << __FILE__ << " line " << __LINE__
401  << ": while loading subcredential: master public "
402  "credential loaded just now, doesn't match the actual "
403  "master public credential, "
404  "according to the current owner object.\n";
405  return (-1); // error condition
406  }
407 
408  nReturnVal = 1;
409  }
410  else if (strNodeName.Compare("publicContents")) {
411  OTString strCount;
412  strCount = xml->getAttributeValue("count");
413  const int32_t nCount = strCount.Exists() ? atoi(strCount.Get()) : 0;
414  if (nCount > 0) {
415  int32_t nTempCount = nCount;
416  OTString::Map mapPublic;
417 
418  while (nTempCount-- > 0) {
419 
420  const char* pElementExpected = "publicInfo";
421  OTString strPublicInfo;
422 
423  // This map contains values we will also want, when we read the
424  // info...
425  // (The OTContract::LoadEncodedTextField call below will read
426  // all the values
427  // as specified in this map.)
428  //
429  OTString::Map temp_MapAttributes;
430  temp_MapAttributes.insert(std::pair<std::string, std::string>(
431  "key",
432  "")); // Value should be "A" or "E" or "S" after reading.
433 
435  xml, strPublicInfo, pElementExpected,
436  &temp_MapAttributes)) // </publicInfo>
437  {
438  otErr << __FUNCTION__ << ": Error: Expected "
439  << pElementExpected << " element with text field.\n";
440  return (-1); // error condition
441  }
442 
443  auto it = temp_MapAttributes.find("key");
444  if ((it != temp_MapAttributes.end())) // We expected this much.
445  {
446  std::string& str_key = it->second;
447 
448  if (str_key.size() >
449  0) // Success finding key type ('A' 'E' or 'S')
450  {
451 
452  mapPublic.insert(std::pair<std::string, std::string>(
453  str_key, strPublicInfo.Get()));
454 
455  }
456  // else it's empty, which is expected if nothing was there,
457  // since that's the default value
458  // that we set above for "name" in temp_MapAttributes.
459  else {
460  otErr << __FUNCTION__
461  << ": Expected key type of 'A' or 'E' or 'S'.\n";
462  return (-1); // error condition
463  }
464  }
465  else {
466  otErr << __FUNCTION__
467  << ": Strange error: couldn't find key type AT "
468  "ALL.\n"; // should never happen.
469  return (-1); // error condition
470  }
471  } // while
472 
473  if (static_cast<int64_t>(mapPublic.size()) != nCount) {
474  otErr << __FUNCTION__ << ", " << __FILE__ << ", " << __LINE__
475  << ": Subcredential expected to load " << nCount
476  << " publicInfo objects, "
477  "but actually loaded " << mapPublic.size()
478  << ". (Mismatch, failure loading.)\n";
479  return (-1); // error condition
480  }
481 
482  if (false ==
483  SetPublicContents(mapPublic)) // <============== Success.
484  {
485  otErr << __FUNCTION__ << ", " << __FILE__ << ", " << __LINE__
486  << ": Subcredential failed setting public contents while "
487  "loading.\n";
488  return (-1); // error condition
489  }
490 
491  } // if strCount.Exists() && nCount > 0
492 
493  otInfo << "Loaded publicContents for subcredential.\n";
494 
495  nReturnVal = 1;
496  }
497  else if (strNodeName.Compare("publicCredential")) {
499  xml, m_strContents)) // <========= m_strContents.
500  {
501  otErr << "Error in " << __FILE__ << " line " << __LINE__
502  << ": failed loading expected public credential while "
503  "loading private subcredential.\n";
504  return (-1); // error condition
505  }
506 
507  nReturnVal = 1;
508  }
509  else if (strNodeName.Compare("privateContents")) {
510  OTString strCount;
511  strCount = xml->getAttributeValue("count");
512  const int32_t nCount = strCount.Exists() ? atoi(strCount.Get()) : 0;
513  if (nCount > 0) {
514  int32_t nTempCount = nCount;
515  OTString::Map mapPrivate;
516 
517  while (nTempCount-- > 0) {
518 
519  const char* pElementExpected = "privateInfo";
520  OTString strPrivateInfo;
521 
522  // This map contains values we will also want, when we read the
523  // info...
524  // (The OTContract::LoadEncodedTextField call below will read
525  // all the values
526  // as specified in this map.)
527  //
528  OTString::Map temp_MapAttributes;
529  temp_MapAttributes.insert(std::pair<std::string, std::string>(
530  "key",
531  "")); // Value should be "A" or "E" or "S" after reading.
532 
534  xml, strPrivateInfo, pElementExpected,
535  &temp_MapAttributes)) // </privateInfo>
536  {
537  otErr << __FUNCTION__ << ": Error: Expected "
538  << pElementExpected << " element with text field.\n";
539  return (-1); // error condition
540  }
541 
542  auto it = temp_MapAttributes.find("key");
543  if ((it != temp_MapAttributes.end())) // We expected this much.
544  {
545  std::string& str_key = it->second;
546 
547  if (str_key.size() >
548  0) // Success finding key type ('A' 'E' or 'S')
549  {
550 
551  mapPrivate.insert(std::pair<std::string, std::string>(
552  str_key, strPrivateInfo.Get()));
553 
554  }
555  // else it's empty, which is expected if nothing was there,
556  // since that's the default value
557  // that we set above for "name" in temp_MapAttributes.
558  else {
559  otErr << __FUNCTION__
560  << ": Expected key type of 'A' or 'E' or 'S'.\n";
561  return (-1); // error condition
562  }
563  }
564  else {
565  otErr << __FUNCTION__
566  << ": Strange error: couldn't find key type AT "
567  "ALL.\n"; // should never happen.
568  return (-1); // error condition
569  }
570  } // while
571 
572  if (static_cast<int64_t>(mapPrivate.size()) != nCount) {
573  otErr << __FUNCTION__ << ", " << __FILE__ << ", " << __LINE__
574  << ": Subcredential expected to load " << nCount
575  << " privateInfo objects, "
576  "but actually loaded " << mapPrivate.size()
577  << ". (Mismatch, failure loading.)\n";
578  return (-1); // error condition
579  }
580 
581  OT_ASSERT(nullptr != m_pOwner);
582 
583  // Sometimes we are supposed to use a specific, pre-specified
584  // password (versus just
585  // blindly asking the user to type a password when it's not cached
586  // alrady.) For example,
587  // when importing a Nym, the exported version of the Nym is not
588  // encrypted to the cached
589  // wallet key. It's got its own exported passphrase. So it won't be
590  // cached, and we will have
591  // the wallet's cached key disabled while loading it. This means we
592  // have to enter the same
593  // passphrase many times in a row, while OT loads up all the
594  // credentials and keys for that
595  // Nym. Therefore, instead, we ask the user up front to enter the
596  // special passphrase for that
597  // exported Nym. Then we just pass it in to all the functions that
598  // need it, so none of them have
599  // to ask the user to type it.
600  //
601  // That's what brings us here now... when that happens,
602  // m_pOwner->GetImportPassword() will be set
603  // with the appropriate pointer to the passphrase. Otherwise it will
604  // be nullptr. Meanwhile SetPrivateContents
605  // below accepts an import passphrase, which it defaults to nullptr.
606  //
607  // So we just pass it in either way (sometimes it's nullptr and the
608  // wallet cached master key is used, and
609  // sometimes an actual passphrase is passed in, so we use it.)
610 
611  if (false ==
613  otErr << __FUNCTION__ << ", " << __FILE__ << ", " << __LINE__
614  << ": Subcredential failed setting private contents "
615  "while loading.\n";
616  return (-1); // error condition
617  }
618 
619  } // if strCount.Exists() && nCount > 0
620 
621  otInfo << "Loaded privateContents for subcredential.\n";
622 
623  nReturnVal = 1;
624  }
625 
626  return nReturnVal;
627 }
std::map< std::string, std::string > Map
Definition: OTString.hpp:162
virtual bool SetPrivateContents(const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
EXPORT bool Compare(const char *compare) const
Definition: OTString.cpp:1102
static EXPORT bool LoadEncodedTextField(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otInfo
EXPORT const OTString & GetPubCredential() const
OTLOG_IMPORT OTLogStream otWarn
OTLOG_IMPORT OTLogStream otErr
EXPORT const OTPassword * GetImportPassword() const
virtual bool SetPublicContents(const OTString::Map &mapPublic)
static bool LoadEncodedTextFieldByName(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)
void opentxs::OTSubcredential::Release ( )
virtual

Reimplemented from opentxs::OTContract.

Reimplemented in opentxs::OTKeyCredential.

Definition at line 193 of file OTSubcredential.cpp.

194 {
195  Release_Subcredential(); // My own cleanup is done here.
196 
197  // Next give the base class a chance to do the same...
198  ot_super::Release(); // since I've overridden the base class, I call it
199  // now...
200 }
virtual EXPORT void Release()
Definition: OTContract.cpp:277
void opentxs::OTSubcredential::Release_Subcredential ( )

Definition at line 202 of file OTSubcredential.cpp.

203 {
204  // Release any dynamically allocated members here. (Normally.)
205 }
bool opentxs::OTSubcredential::SaveContractWallet ( std::ofstream &  ) const
virtual

Implements opentxs::OTContract.

Definition at line 629 of file OTSubcredential.cpp.

630 {
631  return false;
632 }
void opentxs::OTSubcredential::SetContents ( const OTString strContents)
inlineprotected

Definition at line 239 of file OTSubcredential.hpp.

240  {
241  m_strContents = strContents;
242  }
void opentxs::OTSubcredential::SetMasterCredID ( const OTString strMasterCredID)
protected

Definition at line 226 of file OTSubcredential.cpp.

227 {
228  m_strMasterCredID = strMasterCredID;
229 }
void opentxs::OTSubcredential::SetMasterSigned ( const OTString strMasterSigned)
inlineprotected

Definition at line 235 of file OTSubcredential.hpp.

236  {
237  m_strMasterSigned = strMasterSigned;
238  }
virtual void opentxs::OTSubcredential::SetMetadata ( )
inlinevirtual

Reimplemented in opentxs::OTKeyCredential.

Definition at line 368 of file OTSubcredential.hpp.

369  {
370  } // Only key-based subclasses will use this.
void opentxs::OTSubcredential::SetNymIDandSource ( const OTString strNymID,
const OTString strSourceForNymID 
)
protected

Definition at line 231 of file OTSubcredential.cpp.

233 {
234  m_strNymID = strNymID;
235  m_strSourceForNymID = strSourceForNymID;
236 }
void opentxs::OTSubcredential::SetOwner ( OTCredential theOwner)

Definition at line 166 of file OTSubcredential.cpp.

167 {
168  m_pOwner = &theOwner;
169 }
bool opentxs::OTSubcredential::SetPrivateContents ( const OTString::Map mapPrivate,
const OTPassword pImportPassword = nullptr 
)
protectedvirtual

Reimplemented in opentxs::OTKeyCredential.

Definition at line 215 of file OTSubcredential.cpp.

221 {
222  m_mapPrivateInfo = mapPrivate;
223  return true;
224 }
bool opentxs::OTSubcredential::SetPublicContents ( const OTString::Map mapPublic)
protectedvirtual

Reimplemented in opentxs::OTKeyCredential.

Definition at line 208 of file OTSubcredential.cpp.

209 {
210  m_mapPublicInfo = mapPublic;
211  return true;
212 }
void opentxs::OTSubcredential::StoreAsMasterSigned ( )
inlineprotected

Definition at line 256 of file OTSubcredential.hpp.

257  {
259  } // Upon signing, the credential reverts to credPrivateInfo again.
void opentxs::OTSubcredential::StoreAsPublic ( )
inlineprotected

Definition at line 260 of file OTSubcredential.hpp.

261  {
263  } // Upon signing, the credential reverts to credPrivateInfo again.
void opentxs::OTSubcredential::UpdateContents ( )
virtual

Reimplemented from opentxs::OTContract.

Reimplemented in opentxs::OTMasterkey, and opentxs::OTSubkey.

Definition at line 296 of file OTSubcredential.cpp.

297 {
299 
301  "<subCredential nymID=\"%s\"\n" // a hash of the nymIDSource
302  " masterCredentialID=\"%s\" >\n\n", // Hash of the master credential
303  // that signed this subcredential.
304  GetNymID().Get(),
305  GetMasterCredID().Get());
306 
307  if (GetNymIDSource().Exists()) {
308  OTASCIIArmor ascSource;
309  ascSource.SetString(GetNymIDSource()); // A nym should always
310  // verify through its own
311  // source. (Whatever that
312  // may be.)
313  m_xmlUnsigned.Concatenate("<nymIDSource>\n%s</nymIDSource>\n\n",
314  ascSource.Get());
315  }
316 
317  // if (OTSubcredential::credPublicInfo == m_StoreAs) // (Always saving
318  // public info.)
319  {
320  // PUBLIC INFO
322 
324  }
325 
326  // If we're saving the private credential info...
327  //
330 
332  }
333  // -------------------------------------------------
334  m_xmlUnsigned.Concatenate("</subCredential>\n");
335 
336  m_StoreAs = OTSubcredential::credPrivateInfo; // <=== SET IT BACK TO DEFAULT
337  // BEHAVIOR. Any other state
338  // processes ONCE, and then
339  // goes back to this again.
340 }
void UpdatePublicCredentialToString(OTString &strAppendTo)
const OTString & GetMasterCredID() const
void UpdatePublicContentsToString(OTString &strAppendTo)
void UpdateMasterPublicToString(OTString &strAppendTo)
EXPORT void Concatenate(const char *arg,...)
Definition: OTString.cpp:1334
const OTString & GetNymID() const
OTStringXML m_xmlUnsigned
Definition: OTContract.hpp:174
const OTString & GetNymIDSource() const
void UpdatePrivateContentsToString(OTString &strAppendTo)
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
virtual EXPORT void Release()
Definition: OTString.cpp:765
void opentxs::OTSubcredential::UpdateMasterPublicToString ( OTString strAppendTo)
protected

Definition at line 238 of file OTSubcredential.cpp.

240 {
241  OT_ASSERT(nullptr != m_pOwner);
242  OTASCIIArmor ascMaster(m_pOwner->GetPubCredential());
243  strAppendTo.Concatenate("<masterPublic>\n%s</masterPublic>\n\n",
244  ascMaster.Get());
245 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const OTString & GetPubCredential() const
void opentxs::OTSubcredential::UpdatePrivateContentsToString ( OTString strAppendTo)
protected

Definition at line 278 of file OTSubcredential.cpp.

280 {
281  if (!m_mapPrivateInfo.empty()) {
282  strAppendTo.Concatenate("<privateContents count=\"%d\">\n\n",
283  m_mapPrivateInfo.size());
284 
285  for (auto& it : m_mapPrivateInfo) {
286  OTString strInfo(it.second);
287  OTASCIIArmor ascInfo(strInfo);
288  strAppendTo.Concatenate(
289  "<privateInfo key=\"%s\">\n%s</privateInfo>\n\n",
290  it.first.c_str(), ascInfo.Get());
291  }
292  strAppendTo.Concatenate("</privateContents>\n\n");
293  }
294 }
void opentxs::OTSubcredential::UpdatePublicContentsToString ( OTString strAppendTo)
protected

Definition at line 247 of file OTSubcredential.cpp.

249 {
250  if (!m_mapPublicInfo.empty()) {
251  strAppendTo.Concatenate("<publicContents count=\"%d\">\n\n",
252  m_mapPublicInfo.size());
253 
254  for (auto& it : m_mapPublicInfo) {
255  OTString strInfo(it.second);
256  OTASCIIArmor ascInfo(strInfo);
257  strAppendTo.Concatenate(
258  "<publicInfo key=\"%s\">\n%s</publicInfo>\n\n",
259  it.first.c_str(), ascInfo.Get());
260  }
261 
262  strAppendTo.Concatenate("</publicContents>\n\n");
263  }
264 }
void opentxs::OTSubcredential::UpdatePublicCredentialToString ( OTString strAppendTo)
protected

Definition at line 266 of file OTSubcredential.cpp.

268 {
269  if (GetContents().Exists()) {
270  OTASCIIArmor ascContents(GetContents());
271  if (ascContents.Exists())
272  strAppendTo.Concatenate(
273  "<publicCredential>\n%s</publicCredential>\n\n",
274  ascContents.Get());
275  }
276 }
const OTString & GetContents() const
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
bool opentxs::OTSubcredential::VerifyContract ( )
virtual

Reimplemented from opentxs::OTContract.

Definition at line 744 of file OTSubcredential.cpp.

745 {
746  if (!VerifyContractID()) {
747  otWarn << __FUNCTION__ << ": Failed verifying credential ID against "
748  "whatever it was expected to be.\n";
749  return false;
750  }
751 
752  if (!VerifyInternally()) // Logs copiously.
753  return false;
754 
755  return true;
756 }
virtual EXPORT bool VerifyContractID() const
Definition: OTContract.cpp:379
OTLOG_IMPORT OTLogStream otWarn
bool opentxs::OTSubcredential::VerifyInternally ( )
virtual

Reimplemented in opentxs::OTKeyCredential, and opentxs::OTMasterkey.

Definition at line 666 of file OTSubcredential.cpp.

667 {
668  OT_ASSERT(nullptr != m_pOwner);
669 
670  // Verify that m_strNymID is the same as the hash of m_strSourceForNymID.
671  //
672  if (!VerifyNymID()) return false;
673 
674  // Verify that m_pOwner->GetMasterkey() and *this have the same NymID.
675  //
677  otOut << __FUNCTION__
678  << ": Failure: The actual master credential's NymID doesn't "
679  "match the NymID on this subcredential.\n"
680  " This NymID: " << m_strNymID
681  << "\nMaster's NymID: " << m_pOwner->GetMasterkey().GetNymID()
682  << "\n My Master Cred ID: " << m_strMasterCredID << "\n";
683  return false;
684  }
685 
686  // Verify m_strMasterCredID against the hash of
687  // m_pOwner->GetMasterkey().GetPubCredential()
688  // (the master credentialID is a hash of the master credential.)
689  //
690  OTIdentifier theActualMasterID;
691  const bool bCalcMasterCredID =
692  theActualMasterID.CalculateDigest(m_pOwner->GetPubCredential());
693  OT_ASSERT(bCalcMasterCredID);
694  const OTString strActualMasterID(theActualMasterID);
695 
696  if (!m_strMasterCredID.Compare(strActualMasterID)) {
697  otOut << __FUNCTION__
698  << ": Failure: When the actual Master Credential is hashed, the "
699  "result doesn't match the expected Master Credential ID.\n"
700  "Expected: " << m_strMasterCredID
701  << "\n Found: " << strActualMasterID << "\nMaster Cred:\n"
702  << m_pOwner->GetPubCredential() << "\n";
703  return false;
704  }
705 
706  // Then verify the signature of m_pOwner->GetMasterkey()...
707  // Let's get a few things straight:
708  // * OTMasterkey is a key (derived from OTKeyCredential, derived from
709  // OTSubcredential) and it can only sign itself.
710  // * The only further verification a Masterkey can get is if its hash is
711  // posted at the source. Or, if the source
712  // is a public key, then the master key must be signed by the
713  // corresponding private key. (Again: itself.)
714  // * Conversely to a master key which can ONLY sign itself, all subkeys must
715  // ALSO sign themselves.
716  //
717  // * Thus: Any OTKeyCredential (both master and subkeys, but no other
718  // credentials) must ** sign itself.**
719  // * Whereas m_strMasterSigned is only used by OTSubkey, and thus only must
720  // be verified there.
721  // * Any OTSubcredential must also be signed by its master. (Except masters,
722  // which already sign themselves.)
723  // * Any OTMasterkey must (at some point, and/or regularly) verify against
724  // its own source.
725 
726  // * Any OTSubcredential must also be signed by its master. (Except masters,
727  // which already sign themselves.)
728  //
729  if (!VerifySignedByMaster()) {
730  otOut << __FUNCTION__ << ": Failure: This subcredential hasn't been "
731  "signed by its master credential.\n";
732  return false;
733  }
734 
735  return true;
736 }
virtual bool VerifySignedByMaster()
OTLOG_IMPORT OTLogStream otOut
EXPORT bool Compare(const char *compare) const
Definition: OTString.cpp:1102
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const OTString & GetPubCredential() const
const OTString & GetNymID() const
EXPORT const OTMasterkey & GetMasterkey() const
bool opentxs::OTSubcredential::VerifyNymID ( ) const

Definition at line 638 of file OTSubcredential.cpp.

639 {
640 
641  // Verify that m_strNymID is the same as the hash of m_strSourceForNymID.
642  //
643  OTIdentifier theTempID;
644  const bool bCalculate = theTempID.CalculateDigest(m_strSourceForNymID);
645  OT_ASSERT(bCalculate);
646 
647  const OTString strNymID(theTempID);
648  if (!m_strNymID.Compare(strNymID)) {
649  otOut << __FUNCTION__
650  << ": Failure: When the NymID's source is hashed, the result "
651  "doesn't match the expected NymID.\n"
652  "Expected: " << m_strNymID << "\n Found: " << strNymID
653  << "\n Source: " << m_strSourceForNymID << "\n";
654  return false;
655  }
656 
657  return true;
658 }
OTLOG_IMPORT OTLogStream otOut
EXPORT bool Compare(const char *compare) const
Definition: OTString.cpp:1102
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTSubcredential::VerifySignedByMaster ( )
virtual

Reimplemented in opentxs::OTSubkey.

Definition at line 738 of file OTSubcredential.cpp.

739 {
740  OT_ASSERT(nullptr != m_pOwner);
742 }
EXPORT const OTAsymmetricKey & GetPublicKey() const
Definition: OTKeypair.cpp:229
EXPORT bool VerifyWithKey(const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr) const
Definition: OTContract.cpp:848
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const OTMasterkey & GetMasterkey() const

Friends And Related Function Documentation

friend class OTCredential
friend

Definition at line 189 of file OTSubcredential.hpp.

Member Data Documentation

OTString::Map opentxs::OTSubcredential::m_mapPrivateInfo
protected

Definition at line 216 of file OTSubcredential.hpp.

OTString::Map opentxs::OTSubcredential::m_mapPublicInfo
protected

Definition at line 212 of file OTSubcredential.hpp.

OTCredential* opentxs::OTSubcredential::m_pOwner
protected

Definition at line 204 of file OTSubcredential.hpp.

CredStoreAs opentxs::OTSubcredential::m_StoreAs
protected

Definition at line 202 of file OTSubcredential.hpp.

OTString opentxs::OTSubcredential::m_strContents
protected

Definition at line 224 of file OTSubcredential.hpp.

OTString opentxs::OTSubcredential::m_strMasterCredID
protected

Definition at line 205 of file OTSubcredential.hpp.

OTString opentxs::OTSubcredential::m_strMasterSigned
protected

Definition at line 220 of file OTSubcredential.hpp.

OTString opentxs::OTSubcredential::m_strNymID
protected

Definition at line 209 of file OTSubcredential.hpp.

OTString opentxs::OTSubcredential::m_strSourceForNymID
protected

Definition at line 211 of file OTSubcredential.hpp.


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