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

#include <OTKeyCredential.hpp>

Inheritance diagram for opentxs::OTKeyCredential:
Collaboration diagram for opentxs::OTKeyCredential:

Public Member Functions

bool GenerateKeys (int32_t nBits=1024)
 
bool ReEncryptKeys (const OTPassword &theExportPassword, bool bImporting)
 
virtual bool VerifyInternally ()
 
bool VerifySignedBySelf ()
 
virtual void SetMetadata ()
 
 OTKeyCredential ()
 
 OTKeyCredential (OTCredential &theOwner)
 
bool Sign (OTContract &theContract, const OTPasswordData *pPWData=nullptr)
 
EXPORT int32_t GetPublicKeysBySignature (listOfAsymmetricKeys &listOutput, const OTSignature &theSignature, char cKeyType= '0') const
 
virtual ~OTKeyCredential ()
 
virtual void Release ()
 
void Release_Subkey ()
 
- Public Member Functions inherited from opentxs::OTSubcredential
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 EXPORT void CalculateContractID (OTIdentifier &newID) const
 
virtual bool VerifyContract ()
 
bool VerifyNymID () const
 
virtual bool VerifySignedByMaster ()
 
void SetOwner (OTCredential &theOwner)
 
 OTSubcredential ()
 
 OTSubcredential (OTCredential &theOwner)
 
virtual ~OTSubcredential ()
 
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
 

Public Attributes

OTKeypair m_SigningKey
 
OTKeypair m_AuthentKey
 
OTKeypair m_EncryptKey
 

Protected Member Functions

virtual bool SetPublicContents (const OTString::Map &mapPublic)
 
virtual bool SetPrivateContents (const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
 
- Protected Member Functions inherited from opentxs::OTSubcredential
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 ()
 
- Protected Member Functions inherited from opentxs::OTContract
bool LoadContractXML ()
 

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)
 
- Protected Types inherited from opentxs::OTSubcredential
enum  CredStoreAs { credPrivateInfo, credPublicInfo = 1, credMasterSigned = 2 }
 
- Protected Attributes inherited from opentxs::OTSubcredential
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
 

Detailed Description

OTKeyCredential A form of OTSubcredential that contains 3 key pairs: signing, authentication, and encryption. We won't use OTKeyCredential directly but only as a common base class for OTSubkey and OTMasterkey.

Definition at line 249 of file OTKeyCredential.hpp.

Constructor & Destructor Documentation

opentxs::OTKeyCredential::OTKeyCredential ( )

Definition at line 284 of file OTKeyCredential.cpp.

285  : ot_super()
286 {
287 }
opentxs::OTKeyCredential::OTKeyCredential ( OTCredential theOwner)

Definition at line 288 of file OTKeyCredential.cpp.

289  : ot_super(theOwner)
290 {
291 }
opentxs::OTKeyCredential::~OTKeyCredential ( )
virtual

Definition at line 293 of file OTKeyCredential.cpp.

294 {
295  Release_Subkey();
296 }

Member Function Documentation

bool opentxs::OTKeyCredential::GenerateKeys ( int32_t  nBits = 1024)

Definition at line 313 of file OTKeyCredential.cpp.

315 {
316  const bool bSign = m_SigningKey.MakeNewKeypair(nBits);
317  const bool bAuth = m_AuthentKey.MakeNewKeypair(nBits);
318  const bool bEncr = m_EncryptKey.MakeNewKeypair(nBits);
319 
320  OT_ASSERT(bSign && bAuth && bEncr);
321 
322  m_SigningKey.SaveAndReloadBothKeysFromTempFile(); // Keys won't be right
323  // until this happens.
324  m_AuthentKey.SaveAndReloadBothKeysFromTempFile(); // (Necessary evil until
325  // better fix.)
327 
328  // Since the keys were all generated successfully, we need to copy their
329  // certificate data into the m_mapPublicInfo and m_mapPrivateInfo (string
330  // maps.)
331  //
332  OTString strPublicKey, strPrivateCert;
333  OTString::Map mapPublic, mapPrivate;
334 
335  const OTString strReason("Generating keys for new credential...");
336 
337  const bool b1 = m_SigningKey.GetPublicKey(
338  strPublicKey, false); // bEscaped=true by default.
339  const bool b2 =
340  m_SigningKey.SaveCertAndPrivateKeyToString(strPrivateCert, &strReason);
341 
342  if (b1)
343  mapPublic.insert(
344  std::pair<std::string, std::string>("S", strPublicKey.Get()));
345  if (b2)
346  mapPrivate.insert(
347  std::pair<std::string, std::string>("S", strPrivateCert.Get()));
348 
349  strPublicKey.Release();
350  strPrivateCert.Release();
351  const bool b3 = m_AuthentKey.GetPublicKey(
352  strPublicKey, false); // bEscaped=true by default.
353  const bool b4 =
354  m_AuthentKey.SaveCertAndPrivateKeyToString(strPrivateCert, &strReason);
355 
356  if (b3)
357  mapPublic.insert(
358  std::pair<std::string, std::string>("A", strPublicKey.Get()));
359  if (b4)
360  mapPrivate.insert(
361  std::pair<std::string, std::string>("A", strPrivateCert.Get()));
362 
363  strPublicKey.Release();
364  strPrivateCert.Release();
365  const bool b5 = m_EncryptKey.GetPublicKey(
366  strPublicKey, false); // bEscaped=true by default.
367  const bool b6 =
368  m_EncryptKey.SaveCertAndPrivateKeyToString(strPrivateCert, &strReason);
369 
370  if (b5)
371  mapPublic.insert(
372  std::pair<std::string, std::string>("E", strPublicKey.Get()));
373  if (b6)
374  mapPrivate.insert(
375  std::pair<std::string, std::string>("E", strPrivateCert.Get()));
376 
377  if (3 != mapPublic.size()) {
378  otErr << "In " << __FILE__ << ", line " << __LINE__
379  << ": Failed getting public keys in "
380  "OTKeyCredential::GenerateKeys.\n";
381  return false;
382  }
383  else
384  ot_super::SetPublicContents(mapPublic);
385 
386  if (3 != mapPrivate.size()) {
387  otErr << "In " << __FILE__ << ", line " << __LINE__
388  << ": Failed getting private keys in "
389  "OTKeyCredential::GenerateKeys.\n";
390  return false;
391  }
392  else
393  ot_super::SetPrivateContents(mapPrivate);
394 
395  return true;
396 }
std::map< std::string, std::string > Map
Definition: OTString.hpp:162
EXPORT const OTAsymmetricKey & GetPublicKey() const
Definition: OTKeypair.cpp:229
EXPORT bool SaveAndReloadBothKeysFromTempFile(OTString *pstrOutputCert=nullptr, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTKeypair.cpp:333
virtual bool SetPrivateContents(const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
EXPORT bool SaveCertAndPrivateKeyToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTKeypair.cpp:277
virtual bool SetPublicContents(const OTString::Map &mapPublic)
EXPORT bool MakeNewKeypair(int32_t nBits=1024)
Definition: OTKeypair.cpp:430
int32_t opentxs::OTKeyCredential::GetPublicKeysBySignature ( listOfAsymmetricKeys listOutput,
const OTSignature theSignature,
char  cKeyType = '0' 
) const

Definition at line 190 of file OTKeyCredential.cpp.

194 {
195  // Key type was not specified, because we only want keys that match the
196  // metadata on theSignature.
197  // And if theSignature has no metadata, then we want to return 0 keys.
198  if (('0' == cKeyType) && !theSignature.getMetaData().HasMetadata())
199  return 0;
200 
201  // By this point, we know that EITHER exact metadata matches must occur, and
202  // the signature DOES have metadata, ('0')
203  // OR the search is only for 'A', 'E', or 'S' candidates, based on cKeyType,
204  // and that the signature's metadata
205  // can additionally narrow the search down, if it's present, which in this
206  // case it's not guaranteed to be.
207  int32_t nCount = 0;
208  switch (cKeyType) {
209  // Specific search only for signatures with metadata.
210  // FYI, theSignature.getMetaData().HasMetadata() is true, in this case.
211  case '0': {
212  // That's why I can just assume theSignature has a key type here:
213  switch (theSignature.getMetaData().GetKeyType()) {
214  case 'A':
215  nCount =
216  m_AuthentKey.GetPublicKeyBySignature(listOutput, theSignature);
217  break; // bInclusive=false by default
218  case 'E':
219  nCount =
220  m_EncryptKey.GetPublicKeyBySignature(listOutput, theSignature);
221  break; // bInclusive=false by default
222  case 'S':
223  nCount =
224  m_SigningKey.GetPublicKeyBySignature(listOutput, theSignature);
225  break; // bInclusive=false by default
226  default:
227  otErr << __FUNCTION__
228  << ": Unexpected keytype value in signature metadata: "
229  << theSignature.getMetaData().GetKeyType() << " (failure)\n";
230  return 0;
231  }
232  break;
233  }
234  // Generalized search which specifies key type and returns keys
235  // even for signatures with no metadata. (When metadata is present,
236  // it's still used to eliminate keys.)
237  case 'A':
238  nCount = m_AuthentKey.GetPublicKeyBySignature(listOutput, theSignature,
239  true);
240  break; // bInclusive=true
241  case 'E':
242  nCount = m_EncryptKey.GetPublicKeyBySignature(listOutput, theSignature,
243  true);
244  break; // bInclusive=true
245  case 'S':
246  nCount = m_SigningKey.GetPublicKeyBySignature(listOutput, theSignature,
247  true);
248  break; // bInclusive=true
249  default:
250  otErr << __FUNCTION__
251  << ": Unexpected value for cKeyType (should be 0, A, E, or S): "
252  << cKeyType << "\n";
253  return 0;
254  }
255  return nCount;
256 }
EXPORT int32_t GetPublicKeyBySignature(listOfAsymmetricKeys &listOutput, const OTSignature &theSignature, bool bInclusive=false) const
Definition: OTKeypair.cpp:650
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTKeyCredential::ReEncryptKeys ( const OTPassword theExportPassword,
bool  bImporting 
)

Definition at line 673 of file OTKeyCredential.cpp.

675 {
676  OTString strSign, strAuth, strEncr;
677 
678  const bool bSign =
679  m_SigningKey.ReEncrypt(theExportPassword, bImporting, strSign);
680  bool bAuth = false;
681  bool bEncr = false;
682 
683  if (bSign) {
684  bAuth = m_AuthentKey.ReEncrypt(theExportPassword, bImporting, strAuth);
685 
686  if (bAuth)
687  bEncr =
688  m_EncryptKey.ReEncrypt(theExportPassword, bImporting, strEncr);
689  }
690 
691  const bool bSuccessReEncrypting = (bSign && bAuth && bEncr);
692  bool bSuccess = false;
693 
694  // If success, we now have the updated versions of the private certs.
695  //
696  if (bSuccessReEncrypting) {
697  OTString::Map mapPrivate;
698 
699  for (auto& it : m_mapPrivateInfo) {
700  std::string str_key_type = it.first; // A, E, S.
701  std::string str_key_contents = it.second;
702 
703  if ("A" == str_key_type) {
704  mapPrivate.insert(
705  std::pair<std::string, std::string>("A", strAuth.Get()));
706  }
707  else if ("E" == str_key_type)
708  mapPrivate.insert(
709  std::pair<std::string, std::string>("E", strEncr.Get()));
710  else if ("S" == str_key_type)
711  mapPrivate.insert(
712  std::pair<std::string, std::string>("S", strSign.Get()));
713 
714  else // Should never happen, but if there are other keys here, we'll
715  // preserve 'em.
716  {
717  mapPrivate.insert(std::pair<std::string, std::string>(
718  str_key_type, str_key_contents));
719  OT_FAIL; // really this should never happen.
720  }
721  }
722 
723  if (3 != mapPrivate.size())
724  otErr << __FUNCTION__ << ": Unexpected, mapPrivate does not have "
725  "exactly a size of 3. \n";
726 
727  else {
728  // Logic: If I'm IMPORTING, bImporting is true, and that means the
729  // Nym WAS
730  // encrypted to its own external passphrase (whenever it was
731  // exported) and
732  // in order to IMPORT it, I re-encrypted all the keys from the
733  // exported passphrase,
734  // to the wallet master key (this was done above in ReEncrypt.)
735  // So now that I am loading up the private contents again based on
736  // those
737  // re-encrypted keys, I will want to use the normal wallet master
738  // key to load
739  // them. (So I pass nullptr.)
740  //
741  // But if I'm EXPORTING, bImporting is false, and that means the Nym
742  // WAS
743  // encrypted to the wallet's master passphrase, until just above
744  // when I ReEncrypted
745  // it to its own external passphrase. So now that I am attempting to
746  // reload the
747  // keys based on this new external passphrase, I need to pass it in
748  // so it can be
749  // used for that loading. (So I pass &theExportPassword.)
750  //
751  bSuccess = SetPrivateContents(
752  mapPrivate, bImporting ? nullptr : &theExportPassword);
753  }
754  }
755 
756  return bSuccess; // Note: Caller must re-sign credential after doing this,
757  // to keep these changes.
758 }
std::map< std::string, std::string > Map
Definition: OTString.hpp:162
EXPORT bool ReEncrypt(const OTPassword &theExportPassword, bool bImporting, OTString &strOutput)
Definition: OTKeypair.cpp:692
virtual bool SetPrivateContents(const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
void opentxs::OTKeyCredential::Release ( )
virtual

Reimplemented from opentxs::OTSubcredential.

Definition at line 299 of file OTKeyCredential.cpp.

300 {
301  Release_Subkey(); // My own cleanup is done here.
302 
303  // Next give the base class a chance to do the same...
304  ot_super::Release(); // since I've overridden the base class, I call it
305  // now...
306 }
void opentxs::OTKeyCredential::Release_Subkey ( )

Definition at line 308 of file OTKeyCredential.cpp.

309 {
310  // Release any dynamically allocated members here. (Normally.)
311 }
void opentxs::OTKeyCredential::SetMetadata ( )
virtual

Reimplemented from opentxs::OTSubcredential.

Definition at line 760 of file OTKeyCredential.cpp.

761 {
762  char cMetaKeyType; // Can be A, E, or S (authentication, encryption, or
763  // signing. Also, E would be unusual.)
764  char cMetaNymID = '0'; // Can be any letter from base62 alphabet. Represents
765  // first letter of a Nym's ID.
766  char cMetaMasterCredID = '0'; // Can be any letter from base62 alphabet.
767  // Represents first letter of a Master
768  // Credential ID (for that Nym.)
769  char cMetaSubCredID = '0'; // Can be any letter from base62 alphabet.
770  // Represents first letter of a SubCredential ID
771  // (signed by that Master.)
772 
773  OTString strSubcredID;
774  GetIdentifier(strSubcredID);
775 
776  const bool bNymID = GetNymID().At(0, cMetaNymID);
777  const bool bCredID = m_pOwner->GetMasterCredID().At(0, cMetaMasterCredID);
778  const bool bSubID =
779  strSubcredID.At(0, cMetaSubCredID); // In the case of the master
780  // credential, this will repeat the
781  // previous one.
782 
783  if (!bNymID || !bCredID || !bSubID) {
784  otWarn << __FUNCTION__ << ": No metadata available:\n "
785  << "bNymID"
786  << " is " << (bNymID ? "True" : "False") << ", "
787  << "bCredID"
788  << " is " << (bNymID ? "True" : "False") << ", "
789  << "bSubID"
790  << " is " << (bNymID ? "True" : "False") << "";
791  }
792 
793  OTSignatureMetadata theMetadata;
794 
795  cMetaKeyType = 'A';
796  theMetadata.SetMetadata(cMetaKeyType, cMetaNymID, cMetaMasterCredID,
797  cMetaSubCredID);
798  m_AuthentKey.SetMetadata(theMetadata);
799 
800  cMetaKeyType = 'E';
801  theMetadata.SetMetadata(cMetaKeyType, cMetaNymID, cMetaMasterCredID,
802  cMetaSubCredID);
803  m_EncryptKey.SetMetadata(theMetadata);
804 
805  cMetaKeyType = 'S';
806  theMetadata.SetMetadata(cMetaKeyType, cMetaNymID, cMetaMasterCredID,
807  cMetaSubCredID);
808  m_SigningKey.SetMetadata(theMetadata);
809 }
EXPORT void SetMetadata(const OTSignatureMetadata &theMetadata)
Definition: OTKeypair.cpp:200
EXPORT const OTString & GetMasterCredID() const
const OTString & GetNymID() const
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
EXPORT bool At(uint32_t index, char &c) const
Definition: OTString.cpp:1025
OTLOG_IMPORT OTLogStream otWarn
bool opentxs::OTKeyCredential::SetPrivateContents ( const OTString::Map mapPrivate,
const OTPassword pImportPassword = nullptr 
)
protectedvirtual

Reimplemented from opentxs::OTSubcredential.

Definition at line 488 of file OTKeyCredential.cpp.

492 {
493 
494  if (mapPrivate.size() != 3) {
495  otErr << __FILE__ << " line " << __LINE__
496  << ": Failure: Expected 3 in mapPrivate(), but the actual value "
497  "was: " << mapPrivate.size() << "\n";
498  return false;
499  }
500 
501  auto itAuth = mapPrivate.find("A"); // Authentication key
502  if (mapPrivate.end() == itAuth) {
503  otErr << __FILE__ << " line " << __LINE__
504  << ": Failure: Unable to find private authentication key.\n";
505  return false;
506  }
507 
508  auto itEncr = mapPrivate.find("E"); // Encryption key
509  if (mapPrivate.end() == itEncr) {
510  otErr << __FILE__ << " line " << __LINE__
511  << ": Failure: Unable to find private encryption key.\n";
512  return false;
513  }
514 
515  auto itSign = mapPrivate.find("S"); // Signing key
516  if (mapPrivate.end() == itSign) {
517  otErr << __FILE__ << " line " << __LINE__
518  << ": Failure: Unable to find private signing key.\n";
519  return false;
520  }
521 
522  if (ot_super::SetPrivateContents(mapPrivate, pImportPassword)) {
523  const OTString strReason("Loading private key from credential.");
524  OTString::Map mapPublic;
525 
526  OTString strPrivate;
527  strPrivate.Set(itAuth->second.c_str()); // strPrivate now contains the
528  // private Cert string.
529 
530  if (false ==
532  strPrivate, false /*bEscaped true by default*/, &strReason,
533  pImportPassword)) {
534  otErr << __FILE__ << " line " << __LINE__
535  << ": Failure: Unable to set private authentication key "
536  "based on string.\n";
537  // otErr << __FILE__ << " line " << __LINE__ <<
538  // ": Failure: Unable to set private authentication key
539  // based on string:\n" << strPrivate << "\n";
540  return false;
541  }
542  else // Success loading the private key. Let's grab the public key
543  // here.
544  {
545  OTString strPublic;
546 
547  if ((false ==
549  strPrivate, false /* bEscaped true by default */,
550  &strReason, pImportPassword)) ||
551  (false ==
553  strPublic, false /* bEscaped true by default */))) {
554  otErr << __FILE__ << " line " << __LINE__
555  << ": Failure: Unable to set public authentication key "
556  "based on private string.\n";
557  // otErr << __FILE__ << " line " << __LINE__ <<
558  // ": Failure: Unable to set public
559  // authentication key based on private string:\n" << strPrivate
560  // << "\n";
561  return false;
562  }
563  mapPublic.insert(
564  std::pair<std::string, std::string>("A", strPublic.Get()));
565  }
566 
567  strPrivate.Release();
568  strPrivate.Set(itEncr->second.c_str());
569 
570  if (false ==
572  strPrivate, false /*bEscaped true by default*/, &strReason,
573  pImportPassword)) {
574  otErr << __FILE__ << " line " << __LINE__
575  << ": Failure: Unable to set private encryption key based on "
576  "string.\n";
577  // otErr << __FILE__ << " line " << __LINE__ <<
578  // ": Failure: Unable to set private encryption key based
579  // on string:\n" << strPrivate << "\n";
580  return false;
581  }
582  else // Success loading the private key. Let's grab the public key
583  // here.
584  {
585  OTString strPublic;
586 
587  if ((false ==
589  strPrivate, false /* bEscaped true by default */,
590  &strReason, pImportPassword)) ||
591  (false ==
593  strPublic, false /* bEscaped true by default */))) {
594  otErr << __FILE__ << " line " << __LINE__
595  << ": Failure: Unable to set public encryption key based "
596  "on private string.\n";
597  // otErr << __FILE__ << " line " << __LINE__ <<
598  // ": Failure: Unable to set public encryption
599  // key based on private string:\n" << strPrivate << "\n";
600  return false;
601  }
602  mapPublic.insert(
603  std::pair<std::string, std::string>("E", strPublic.Get()));
604  }
605 
606  strPrivate.Release();
607  strPrivate.Set(itSign->second.c_str());
608 
609  if (false ==
611  strPrivate, false /*bEscaped true by default*/, &strReason,
612  pImportPassword)) {
613  otErr << __FILE__ << " line " << __LINE__
614  << ": Failure: Unable to set private signing key based on "
615  "string.\n";
616  // otErr << __FILE__ << " line " << __LINE__ <<
617  // ": Failure: Unable to set private signing key based on
618  // string:\n" << strPrivate << "\n";
619  return false;
620  }
621  else // Success loading the private key. Let's grab the public key
622  // here.
623  {
624  OTString strPublic;
625 
626  if ((false ==
628  strPrivate, false /* bEscaped true by default */,
629  &strReason, pImportPassword)) ||
630  (false ==
632  strPublic, false /* bEscaped true by default */))) {
633  otErr << __FILE__ << " line " << __LINE__
634  << ": Failure: Unable to set public signing key based on "
635  "private string.\n";
636  // otErr << __FILE__ << " line " << __LINE__ <<
637  // ": Failure: Unable to set public signing key
638  // based on private string:\n" << strPrivate << "\n";
639  return false;
640  }
641  mapPublic.insert(
642  std::pair<std::string, std::string>("S", strPublic.Get()));
643  }
644 
645  if (!ot_super::SetPublicContents(mapPublic)) {
646  otErr << __FILE__ << " line " << __LINE__
647  << ": Failure: While trying to call: "
648  "ot_super::SetPublicContents(mapPublic)\n"; // Should never
649  // happen (it
650  // always just
651  // returns
652  // true.)
653  return false;
654  }
655 
656  return true; // SUCCESS! This means the input, mapPrivate, actually
657  // contained an "A" key, an "E"
658  // key, and an "S" key (and nothing else) and that all three of those
659  // private keys actually loaded
660  // from string form into their respective key object members. We also
661  // set the public keys in here, FYI.
662  }
663 
664  return false;
665 }
std::map< std::string, std::string > Map
Definition: OTString.hpp:162
EXPORT const OTAsymmetricKey & GetPublicKey() const
Definition: OTKeypair.cpp:229
virtual bool SetPrivateContents(const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
EXPORT bool LoadPublicKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTKeypair.cpp:409
EXPORT bool LoadPrivateKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
Definition: OTKeypair.cpp:396
OTLOG_IMPORT OTLogStream otErr
virtual bool SetPublicContents(const OTString::Map &mapPublic)
bool opentxs::OTKeyCredential::SetPublicContents ( const OTString::Map mapPublic)
protectedvirtual

Reimplemented from opentxs::OTSubcredential.

Definition at line 399 of file OTKeyCredential.cpp.

400 {
401  // NOTE: We might use this on the server side, we'll see, but so far on the
402  // client
403  // side, we won't need to use this function, since SetPrivateContents
404  // already does
405  // the dirty work of extracting the public keys and setting them.
406  //
407 
408  if (mapPublic.size() != 3) {
409  otErr << __FILE__ << " line " << __LINE__
410  << ": Failure: Expected 3 in mapPublic.size(), but the actual "
411  "value was: " << mapPublic.size() << "\n";
412  return false;
413  }
414 
415  auto itAuth = mapPublic.find("A"); // Authentication key
416  if (mapPublic.end() == itAuth) {
417  otErr << __FILE__ << " line " << __LINE__
418  << ": Failure: Unable to find public authentication key.\n";
419  return false;
420  }
421 
422  auto itEncr = mapPublic.find("E"); // Encryption key
423  if (mapPublic.end() == itEncr) {
424  otErr << __FILE__ << " line " << __LINE__
425  << ": Failure: Unable to find public encryption key.\n";
426  return false;
427  }
428 
429  auto itSign = mapPublic.find("S"); // Signing key
430  if (mapPublic.end() == itSign) {
431  otErr << __FILE__ << " line " << __LINE__
432  << ": Failure: Unable to find public signing key.\n";
433  return false;
434  }
435 
436  if (ot_super::SetPublicContents(mapPublic)) {
437 
438  OTString strKey;
439  strKey.Set(itAuth->second.c_str());
440  if (!m_AuthentKey.SetPublicKey(strKey)) {
441  otErr << __FILE__ << " line " << __LINE__
442  << ": Failure: Unable to set public authentication key based "
443  "on string:\n" << strKey << "\n";
444  return false;
445  }
446 
447  strKey.Release();
448  strKey.Set(itEncr->second.c_str());
449  if (!m_EncryptKey.SetPublicKey(strKey)) {
450  otErr << __FILE__ << " line " << __LINE__
451  << ": Failure: Unable to set public encryption key based on "
452  "string:\n" << strKey << "\n";
453  return false;
454  }
455 
456  strKey.Release();
457  strKey.Set(itSign->second.c_str());
458  if (!m_SigningKey.SetPublicKey(strKey)) {
459  otErr << __FILE__ << " line " << __LINE__
460  << ": Failure: Unable to set public signing key based on "
461  "string:\n" << strKey << "\n";
462  return false;
463  }
464 
465  return true; // SUCCESS! This means the input, mapPublic, actually
466  // contained an "A" key, an "E"
467  // key, and an "S" key (and nothing else) and that all three of those
468  // public keys actually loaded
469  // from string form into their respective key object members.
470  }
471 
472  return false;
473 }
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
Definition: OTKeypair.cpp:526
OTLOG_IMPORT OTLogStream otErr
virtual bool SetPublicContents(const OTString::Map &mapPublic)
bool opentxs::OTKeyCredential::Sign ( OTContract theContract,
const OTPasswordData pPWData = nullptr 
)

Definition at line 667 of file OTKeyCredential.cpp.

669 {
670  return m_SigningKey.SignContract(theContract, pPWData);
671 }
EXPORT bool SignContract(OTContract &theContract, const OTPasswordData *pPWData=nullptr)
Definition: OTKeypair.cpp:494
bool opentxs::OTKeyCredential::VerifyInternally ( )
virtual

Reimplemented from opentxs::OTSubcredential.

Reimplemented in opentxs::OTMasterkey.

Definition at line 265 of file OTKeyCredential.cpp.

266 {
267  // Verify that m_strNymID is the same as the hash of m_strSourceForNymID.
268  if (!ot_super::VerifyInternally()) return false;
269 
270  // Any OTKeyCredential (both master and subkeys, but no other credentials)
271  // must ** sign itself.**
272  //
273  if (!VerifySignedBySelf()) {
274  otOut << __FUNCTION__ << ": Failed verifying key credential: it's not "
275  "signed by itself (its own signing key.)\n";
276  return false;
277  }
278 
279  return true;
280 }
OTLOG_IMPORT OTLogStream otOut
bool opentxs::OTKeyCredential::VerifySignedBySelf ( )

Definition at line 159 of file OTKeyCredential.cpp.

160 {
162 }
EXPORT const OTAsymmetricKey & GetPublicKey() const
Definition: OTKeypair.cpp:229
EXPORT bool VerifyWithKey(const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr) const
Definition: OTContract.cpp:848

Friends And Related Function Documentation

friend class OTCredential
friend

Definition at line 253 of file OTKeyCredential.hpp.

Member Data Documentation

OTKeypair opentxs::OTKeyCredential::m_AuthentKey

Definition at line 266 of file OTKeyCredential.hpp.

OTKeypair opentxs::OTKeyCredential::m_EncryptKey

Definition at line 268 of file OTKeyCredential.hpp.

OTKeypair opentxs::OTKeyCredential::m_SigningKey

Definition at line 264 of file OTKeyCredential.hpp.


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