198 if ((
'0' == cKeyType) && !theSignature.getMetaData().HasMetadata())
213 switch (theSignature.getMetaData().GetKeyType()) {
216 m_AuthentKey.GetPublicKeyBySignature(listOutput, theSignature);
220 m_EncryptKey.GetPublicKeyBySignature(listOutput, theSignature);
224 m_SigningKey.GetPublicKeyBySignature(listOutput, theSignature);
227 otErr << __FUNCTION__
228 <<
": Unexpected keytype value in signature metadata: "
229 << theSignature.getMetaData().GetKeyType() <<
" (failure)\n";
238 nCount = m_AuthentKey.GetPublicKeyBySignature(listOutput, theSignature,
242 nCount = m_EncryptKey.GetPublicKeyBySignature(listOutput, theSignature,
246 nCount = m_SigningKey.GetPublicKeyBySignature(listOutput, theSignature,
250 otErr << __FUNCTION__
251 <<
": Unexpected value for cKeyType (should be 0, A, E, or S): "
274 otOut << __FUNCTION__ <<
": Failed verifying key credential: it's not "
275 "signed by itself (its own signing key.)\n";
332 OTString strPublicKey, strPrivateCert;
335 const OTString strReason(
"Generating keys for new credential...");
338 strPublicKey,
false);
344 std::pair<std::string, std::string>(
"S", strPublicKey.
Get()));
347 std::pair<std::string, std::string>(
"S", strPrivateCert.
Get()));
352 strPublicKey,
false);
358 std::pair<std::string, std::string>(
"A", strPublicKey.
Get()));
361 std::pair<std::string, std::string>(
"A", strPrivateCert.
Get()));
366 strPublicKey,
false);
372 std::pair<std::string, std::string>(
"E", strPublicKey.
Get()));
375 std::pair<std::string, std::string>(
"E", strPrivateCert.
Get()));
377 if (3 != mapPublic.size()) {
378 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
379 <<
": Failed getting public keys in "
380 "OTKeyCredential::GenerateKeys.\n";
386 if (3 != mapPrivate.size()) {
387 otErr <<
"In " << __FILE__ <<
", line " << __LINE__
388 <<
": Failed getting private keys in "
389 "OTKeyCredential::GenerateKeys.\n";
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";
415 auto itAuth = mapPublic.find(
"A");
416 if (mapPublic.end() == itAuth) {
417 otErr << __FILE__ <<
" line " << __LINE__
418 <<
": Failure: Unable to find public authentication key.\n";
422 auto itEncr = mapPublic.find(
"E");
423 if (mapPublic.end() == itEncr) {
424 otErr << __FILE__ <<
" line " << __LINE__
425 <<
": Failure: Unable to find public encryption key.\n";
429 auto itSign = mapPublic.find(
"S");
430 if (mapPublic.end() == itSign) {
431 otErr << __FILE__ <<
" line " << __LINE__
432 <<
": Failure: Unable to find public signing key.\n";
439 strKey.
Set(itAuth->second.c_str());
441 otErr << __FILE__ <<
" line " << __LINE__
442 <<
": Failure: Unable to set public authentication key based "
443 "on string:\n" << strKey <<
"\n";
448 strKey.
Set(itEncr->second.c_str());
450 otErr << __FILE__ <<
" line " << __LINE__
451 <<
": Failure: Unable to set public encryption key based on "
452 "string:\n" << strKey <<
"\n";
457 strKey.
Set(itSign->second.c_str());
459 otErr << __FILE__ <<
" line " << __LINE__
460 <<
": Failure: Unable to set public signing key based on "
461 "string:\n" << strKey <<
"\n";
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";
501 auto itAuth = mapPrivate.find(
"A");
502 if (mapPrivate.end() == itAuth) {
503 otErr << __FILE__ <<
" line " << __LINE__
504 <<
": Failure: Unable to find private authentication key.\n";
508 auto itEncr = mapPrivate.find(
"E");
509 if (mapPrivate.end() == itEncr) {
510 otErr << __FILE__ <<
" line " << __LINE__
511 <<
": Failure: Unable to find private encryption key.\n";
515 auto itSign = mapPrivate.find(
"S");
516 if (mapPrivate.end() == itSign) {
517 otErr << __FILE__ <<
" line " << __LINE__
518 <<
": Failure: Unable to find private signing key.\n";
523 const OTString strReason(
"Loading private key from credential.");
527 strPrivate.
Set(itAuth->second.c_str());
532 strPrivate,
false , &strReason,
534 otErr << __FILE__ <<
" line " << __LINE__
535 <<
": Failure: Unable to set private authentication key "
536 "based on string.\n";
550 &strReason, pImportPassword)) ||
553 strPublic,
false ))) {
554 otErr << __FILE__ <<
" line " << __LINE__
555 <<
": Failure: Unable to set public authentication key "
556 "based on private string.\n";
564 std::pair<std::string, std::string>(
"A", strPublic.
Get()));
568 strPrivate.
Set(itEncr->second.c_str());
572 strPrivate,
false , &strReason,
574 otErr << __FILE__ <<
" line " << __LINE__
575 <<
": Failure: Unable to set private encryption key based on "
590 &strReason, pImportPassword)) ||
593 strPublic,
false ))) {
594 otErr << __FILE__ <<
" line " << __LINE__
595 <<
": Failure: Unable to set public encryption key based "
596 "on private string.\n";
603 std::pair<std::string, std::string>(
"E", strPublic.
Get()));
607 strPrivate.
Set(itSign->second.c_str());
611 strPrivate,
false , &strReason,
613 otErr << __FILE__ <<
" line " << __LINE__
614 <<
": Failure: Unable to set private signing key based on "
629 &strReason, pImportPassword)) ||
632 strPublic,
false ))) {
633 otErr << __FILE__ <<
" line " << __LINE__
634 <<
": Failure: Unable to set public signing key based on "
642 std::pair<std::string, std::string>(
"S", strPublic.
Get()));
646 otErr << __FILE__ <<
" line " << __LINE__
647 <<
": Failure: While trying to call: "
648 "ot_super::SetPublicContents(mapPublic)\n";
691 const bool bSuccessReEncrypting = (bSign && bAuth && bEncr);
692 bool bSuccess =
false;
696 if (bSuccessReEncrypting) {
700 std::string str_key_type = it.first;
701 std::string str_key_contents = it.second;
703 if (
"A" == str_key_type) {
705 std::pair<std::string, std::string>(
"A", strAuth.
Get()));
707 else if (
"E" == str_key_type)
709 std::pair<std::string, std::string>(
"E", strEncr.
Get()));
710 else if (
"S" == str_key_type)
712 std::pair<std::string, std::string>(
"S", strSign.
Get()));
717 mapPrivate.insert(std::pair<std::string, std::string>(
718 str_key_type, str_key_contents));
723 if (3 != mapPrivate.size())
724 otErr << __FUNCTION__ <<
": Unexpected, mapPrivate does not have "
725 "exactly a size of 3. \n";
752 mapPrivate, bImporting ?
nullptr : &theExportPassword);
764 char cMetaNymID =
'0';
766 char cMetaMasterCredID =
'0';
769 char cMetaSubCredID =
'0';
776 const bool bNymID =
GetNymID().
At(0, cMetaNymID);
779 strSubcredID.
At(0, cMetaSubCredID);
783 if (!bNymID || !bCredID || !bSubID) {
784 otWarn << __FUNCTION__ <<
": No metadata available:\n "
786 <<
" is " << (bNymID ?
"True" :
"False") <<
", "
788 <<
" is " << (bNymID ?
"True" :
"False") <<
", "
790 <<
" is " << (bNymID ?
"True" :
"False") <<
"";
796 theMetadata.
SetMetadata(cMetaKeyType, cMetaNymID, cMetaMasterCredID,
801 theMetadata.
SetMetadata(cMetaKeyType, cMetaNymID, cMetaMasterCredID,
806 theMetadata.
SetMetadata(cMetaKeyType, cMetaNymID, cMetaMasterCredID,
std::map< std::string, std::string > Map
EXPORT bool ReEncrypt(const OTPassword &theExportPassword, bool bImporting, OTString &strOutput)
std::list< OTAsymmetricKey * > listOfAsymmetricKeys
EXPORT const OTAsymmetricKey & GetPublicKey() const
EXPORT int32_t GetPublicKeysBySignature(listOfAsymmetricKeys &listOutput, const OTSignature &theSignature, char cKeyType= '0') const
virtual bool VerifyInternally()
bool Sign(OTContract &theContract, const OTPasswordData *pPWData=nullptr)
EXPORT bool SaveAndReloadBothKeysFromTempFile(OTString *pstrOutputCert=nullptr, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
virtual void SetMetadata()
OTLOG_IMPORT OTLogStream otOut
EXPORT void SetMetadata(const OTSignatureMetadata &theMetadata)
virtual bool SetPrivateContents(const OTString::Map &mapPrivate, const OTPassword *pImportPassword=nullptr)
OTString::Map m_mapPrivateInfo
EXPORT bool VerifyWithKey(const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr) const
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
EXPORT const OTString & GetMasterCredID() const
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
virtual bool VerifyInternally()
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)
const OTString & GetNymID() const
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
EXPORT bool At(uint32_t index, char &c) const
EXPORT bool LoadPrivateKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
virtual bool SetPublicContents(const OTString::Map &mapPublic)
OTLOG_IMPORT OTLogStream otWarn
EXPORT const char * Get() const
bool ReEncryptKeys(const OTPassword &theExportPassword, bool bImporting)
OTLOG_IMPORT OTLogStream otErr
bool VerifySignedBySelf()
EXPORT bool SaveCertAndPrivateKeyToString(OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
virtual bool SetPublicContents(const OTString::Map &mapPublic)
virtual ~OTKeyCredential()
EXPORT bool MakeNewKeypair(int32_t nBits=1024)
EXPORT bool SignContract(OTContract &theContract, const OTPasswordData *pPWData=nullptr)
bool GenerateKeys(int32_t nBits=1024)
virtual EXPORT void Release()