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

#include <OTAsymmetricKey.hpp>

Inheritance diagram for opentxs::OTAsymmetricKey:
Collaboration diagram for opentxs::OTAsymmetricKey:

Public Member Functions

virtual OTAsymmetricKeyClonePubKey () const
 
virtual EXPORT ~OTAsymmetricKey ()
 
virtual void Release ()
 
void Release_AsymmetricKey ()
 
void ReleaseKey ()
 
bool IsEmpty () const
 
bool IsPublic () const
 
bool IsPrivate () const
 
void SetAsPublic ()
 
void SetAsPrivate ()
 
virtual bool CalculateID (OTIdentifier &theOutput) const
 
bool LoadPrivateKey (const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
bool LoadPublicKey (const OTString &strFoldername, const OTString &strFilename)
 
virtual bool LoadPublicKeyFromPGPKey (const OTASCIIArmor &strKey)=0
 
virtual bool LoadPrivateKeyFromCertString (const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
 
virtual bool LoadPublicKeyFromCertString (const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
 
bool LoadPublicKeyFromCertFile (const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
 
virtual bool SaveCertToString (OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const =0
 
virtual bool SavePrivateKeyToString (OTString &strOutput, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr) const =0
 
virtual bool ReEncryptPrivateKey (const OTPassword &theExportPassword, bool bImporting) const =0
 
EXPORT bool GetPublicKey (OTASCIIArmor &strKey) const
 
EXPORT bool GetPublicKey (OTString &strKey, bool bEscaped=true) const
 
EXPORT bool SetPublicKey (const OTASCIIArmor &strKey)
 
EXPORT bool SetPublicKey (const OTString &strKey, bool bEscaped=false)
 
bool GetPrivateKey (OTString &strKey, bool bEscaped=true) const
 
bool GetPrivateKey (OTASCIIArmor &strKey) const
 
bool SetPrivateKey (const OTString &strKey, bool bEscaped=false)
 
bool SetPrivateKey (const OTASCIIArmor &strKey)
 

Static Public Member Functions

static EXPORT OTAsymmetricKeyKeyFactory ()
 
static void SetPasswordCallback (OT_OPENSSL_CALLBACK *pCallback)
 
static EXPORT OT_OPENSSL_CALLBACKGetPasswordCallback ()
 
static bool IsPasswordCallbackSet ()
 
static bool SetPasswordCaller (OTCaller &theCaller)
 
static OTCallerGetPasswordCaller ()
 

Public Attributes

OTSignatureMetadatam_pMetadata
 

Protected Member Functions

void ReleaseKeyLowLevel ()
 
virtual void ReleaseKeyLowLevel_Hook () const =0
 
EXPORT OTAsymmetricKey ()
 

Protected Attributes

OTASCIIArmorm_p_ascKey
 
bool m_bIsPublicKey
 
bool m_bIsPrivateKey
 
Timer m_timer
 

Static Protected Attributes

static OT_OPENSSL_CALLBACKs_pwCallback = nullptr
 
static OTCallers_pCaller = nullptr
 

Detailed Description

Definition at line 203 of file OTAsymmetricKey.hpp.

Constructor & Destructor Documentation

opentxs::OTAsymmetricKey::OTAsymmetricKey ( )
protected

Definition at line 994 of file OTAsymmetricKey.cpp.

995  : m_p_ascKey(nullptr)
996  , m_bIsPublicKey(false)
997  , m_bIsPrivateKey(false)
998  , m_pMetadata(new OTSignatureMetadata)
999 {
1000  // if (nullptr == m_p_ascKey)
1001  // {
1002  // m_p_ascKey = new OTASCIIArmor;
1003  // OT_ASSERT(nullptr != m_p_ascKey);
1004  // }
1005 }
OTSignatureMetadata * m_pMetadata
opentxs::OTAsymmetricKey::~OTAsymmetricKey ( )
virtual

Definition at line 1007 of file OTAsymmetricKey.cpp.

1008 {
1009  // Release_AsymmetricKey(); // ******
1010 
1011  m_timer.clear(); // Since ReleaseKeyLowLevel is no longer called here (via
1012  // Release_AsymmetricKey) then
1013  // m_timer.clear() was no longer getting called, so I added it here to
1014  // rectify that. See below NOTE for
1015  // more details.
1016  //
1017  // NOTE: It's very unusual that the above is commented out, since my normal
1018  // convention is to
1019  // call this function both in the destructor, as well as in the Release()
1020  // method for any given
1021  // class.
1022  // Here's why it's commented out, in this case. Because all it does is call
1023  // ReleaseKeyLowLevel,
1024  // which calls ReleaseKeyLowLevel_Hook, which is pure virtual and is what
1025  // allows the
1026  // OTAsymmetricKey_OpenSSL class to clean up its OpenSSL-specific private
1027  // members.
1028  // We CANNOT call a pure virtual method from a destructor (which is where we
1029  // currently are)
1030  // and so we cannot call Release_AsymmetricKey without removing that pure
1031  // virtual call. The
1032  // problem is, ReleaseKeyLowLevel USES that pure virtual call all over this
1033  // file (i.e. in many
1034  // other places BESIDES the destructor) and so we cannot just remove the
1035  // pure virtual call it
1036  // uses which is, in fact, the entire purpose it's being called in the first
1037  // place. So what I
1038  // did was, I changed OTAsymmetricKey_OpenSSL to directly clean up its
1039  // OpenSSL-specific key data,
1040  // and it just ALSO has the hook override doing the same thing. This way
1041  // Release_AsymmetricKey
1042  // can continue to be used by ReleaseKeyLowLevel all over this file, as it
1043  // was designed, using
1044  // the hook and the override, yet also this destructor will continue to work
1045  // perfectly... because
1046  // Release_AsymmetricKey() is commented out above, we won't have any runtime
1047  // errors from trying to
1048  // run a pure virtual method from a destructor. And because
1049  // OTAsymmetricKey_OpenSSL now cleans itself
1050  // up in its own destructor automatically, we have no need whatsoever to
1051  // call a virtual function here
1052  // to clean it up. So it's commented out.
1053  // Makes sense? Of course we didn't have any virtuality before
1054  // OTAsymmetricKey_OpenSSL was added,
1055  // since OTAsymmetricKey previously had no subclasses at all. But that has
1056  // changed recently, so that
1057  // it is now an abstract interface, so that someday a GPG implementation, or
1058  // NaCl implementation can
1059  // someday be added.
1060 
1061  // Release the ascii-armored version of the key (safe to store in this
1062  // form.)
1063  //
1064  if (nullptr != m_p_ascKey) delete m_p_ascKey;
1065  m_p_ascKey = nullptr;
1066 
1067  if (nullptr != m_pMetadata) delete m_pMetadata;
1068  m_pMetadata = nullptr;
1069 }
OTSignatureMetadata * m_pMetadata
void clear()
Definition: Timer.cpp:69

Member Function Documentation

bool opentxs::OTAsymmetricKey::CalculateID ( OTIdentifier theOutput) const
virtual

Definition at line 763 of file OTAsymmetricKey.cpp.

766 {
767  const char* szFunc = "OTAsymmetricKey::CalculateID";
768 
769  theOutput.Release();
770 
771  if (!IsPublic()) {
772  otErr << szFunc << ": Error: !IsPublic() (This function should only be "
773  "called on a public key.)\n";
774  return false;
775  }
776 
777  OTString strPublicKey;
778  bool bGotPublicKey = GetPublicKey(strPublicKey);
779 
780  if (!bGotPublicKey) {
781  otErr << szFunc << ": Error getting public key.\n";
782  return false;
783  }
784 
785  bool bSuccessCalculateDigest = theOutput.CalculateDigest(strPublicKey);
786 
787  if (!bSuccessCalculateDigest) {
788  theOutput.Release();
789  otErr << szFunc << ": Error calculating digest of public key.\n";
790  return false;
791  }
792 
793  return true;
794 }
EXPORT bool GetPublicKey(OTASCIIArmor &strKey) const
OTLOG_IMPORT OTLogStream otErr
OTAsymmetricKey * opentxs::OTAsymmetricKey::ClonePubKey ( ) const
virtual

Definition at line 173 of file OTAsymmetricKey.cpp.

175 {
177  OT_ASSERT(nullptr != pKey);
178  OT_ASSERT(nullptr != m_pMetadata);
179  OT_ASSERT(nullptr != pKey->m_pMetadata);
180 
181  OTASCIIArmor ascTransfer;
182  GetPublicKey(ascTransfer); // Get this's public key in ASCII-armored format
183  pKey->SetPublicKey(
184  ascTransfer); // Decodes that public key from ASCII armor into pKey
185 
186  *(pKey->m_pMetadata) = *(m_pMetadata); // Metadata will be attached to
187  // signatures, if set.
188 
189  return pKey;
190 }
static EXPORT OTAsymmetricKey * KeyFactory()
OTSignatureMetadata * m_pMetadata
EXPORT bool GetPublicKey(OTASCIIArmor &strKey) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OT_OPENSSL_CALLBACK * opentxs::OTAsymmetricKey::GetPasswordCallback ( )
static

Definition at line 224 of file OTAsymmetricKey.cpp.

225 {
226  // cppcheck-suppress variableScope
227  const char* szFunc = "OTAsymmetricKey::GetPasswordCallback";
228 
229 #if defined(OT_TEST_PASSWORD)
230  otInfo << szFunc << ": WARNING, OT_TEST_PASSWORD *is* defined. The "
231  "internal 'C'-based password callback was just "
232  "requested by OT (to pass to OpenSSL). So, returning "
233  "the default_pass_cb password callback, which will "
234  "automatically return "
235  "the 'test' password to OpenSSL, if/when it calls that "
236  "callback function.\n";
237  return &default_pass_cb;
238 #else
239  if (IsPasswordCallbackSet()) {
240  otLog5 << szFunc
241  << ": FYI, the internal 'C'-based password callback is now "
242  "being returning to OT, "
243  "which is passing it to OpenSSL "
244  "during a crypto operation. (If OpenSSL invokes it, then we "
245  "should see other logs after this from when it triggers "
246  "whatever password-collection dialog is provided at startup "
247  "by the (probably Java) OTAPI client.)\n";
248  return s_pwCallback;
249  }
250  else {
251  // otInfo << "OTAsymmetricKey::GetPasswordCallback: FYI, the
252  // internal 'C'-based password callback was requested by OT (to pass to
253  // OpenSSL), "
254  // "but the callback hasn't been set yet.
255  // (Returning nullptr CALLBACK to OpenSSL!! Thus causing it to instead
256  // ask
257  // for the passphrase on the CONSOLE, "
258  // "since no Java password dialog was apparently
259  // available.)\n");
260 
261  // return static_cast<OT_OPENSSL_CALLBACK *>(nullptr);
262 
263  // We have our own "console" password-gathering function, which allows
264  // us to use our master key.
265  // Since the souped-up cb uses it, I'm just returning that here as a
266  // default, for now.
268  return s_pwCallback;
269  }
270 #endif
271 }
EXPORT OT_OPENSSL_CALLBACK souped_up_pass_cb
EXPORT OT_OPENSSL_CALLBACK default_pass_cb
static OT_OPENSSL_CALLBACK * s_pwCallback
static void SetPasswordCallback(OT_OPENSSL_CALLBACK *pCallback)
OTLOG_IMPORT OTLogStream otInfo
static bool IsPasswordCallbackSet()
OTLOG_IMPORT OTLogStream otLog5
OTCaller * opentxs::OTAsymmetricKey::GetPasswordCaller ( )
static

Definition at line 321 of file OTAsymmetricKey.cpp.

322 {
323  const char* szFunc = "OTAsymmetricKey::GetPasswordCaller";
324 
325  otLog4 << szFunc << ": FYI, this was just called by souped_up_pass_cb "
326  "(which must have just been called by OpenSSL.) "
327  "Returning s_pCaller == "
328  << ((nullptr == s_pCaller) ? "nullptr" : "VALID POINTER")
329  << " (Hopefully NOT nullptr, so the "
330  "custom password dialog can be triggered.)\n";
331 
332  return s_pCaller;
333 }
OTLOG_IMPORT OTLogStream otLog4
static OTCaller * s_pCaller
bool opentxs::OTAsymmetricKey::GetPrivateKey ( OTString strKey,
bool  bEscaped = true 
) const

Definition at line 908 of file OTAsymmetricKey.cpp.

909 {
910  OTASCIIArmor theArmor;
911 
912  if (GetPrivateKey(theArmor)) {
913  if (bEscaped) {
914  strKey.Concatenate("- -----BEGIN ENCRYPTED PRIVATE KEY-----\n"
915  "%s"
916  "- -----END ENCRYPTED PRIVATE KEY-----\n",
917  theArmor.Get());
918  }
919  else {
920  strKey.Concatenate("-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
921  "%s"
922  "-----END ENCRYPTED PRIVATE KEY-----\n",
923  theArmor.Get());
924  }
925  return true;
926  }
927  else
928  otErr << "OTAsymmetricKey::GetPrivateKey: Error: "
929  "GetPrivateKey(armored) returned false. (Returning false.)\n";
930 
931  return false;
932 }
bool GetPrivateKey(OTString &strKey, bool bEscaped=true) const
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAsymmetricKey::GetPrivateKey ( OTASCIIArmor strKey) const

Definition at line 935 of file OTAsymmetricKey.cpp.

937 {
938  OT_ASSERT(IsPrivate());
939 
940  ascKey.Release();
941 
942  if (nullptr == m_p_ascKey) return false;
943 
944  ascKey.Set(*m_p_ascKey);
945 
946  return true;
947 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTAsymmetricKey::GetPublicKey ( OTASCIIArmor strKey) const

Definition at line 840 of file OTAsymmetricKey.cpp.

841 {
843  "OTAsymmetricKey::GetPublicKey: ASSERT: IsPublic()\n");
844 
845  ascKey.Release();
846 
847  if (nullptr == m_p_ascKey) return false;
848 
849  ascKey.Set(*m_p_ascKey);
850 
851  return true;
852 }
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
bool opentxs::OTAsymmetricKey::GetPublicKey ( OTString strKey,
bool  bEscaped = true 
) const

Definition at line 800 of file OTAsymmetricKey.cpp.

801 {
802  OTASCIIArmor theArmor;
803 
804  // TODO: optimization: When optimizing for CPU cycles, and willing to
805  // sacrifice a little RAM, we
806  // can save this value the first time it's computed, and then as long as the
807  // armored version (without
808  // bookends) doesn't change, we can save the computed version and pass it
809  // back here, instead of re-generating
810  // it here each time this is called. This implies a need for the armored
811  // version to be able to be flagged
812  // as "dirty" when it is changed.
813 
814  if (GetPublicKey(theArmor)) {
815  if (bEscaped) {
816  strKey.Concatenate(
817  "- -----BEGIN PUBLIC KEY-----\n" // ESCAPED VERSION
818  "%s"
819  "- -----END PUBLIC KEY-----\n",
820  theArmor.Get());
821  }
822  else {
823  strKey.Concatenate(
824  "-----BEGIN PUBLIC KEY-----\n" // UN-ESCAPED VERSION
825  "%s"
826  "-----END PUBLIC KEY-----\n",
827  theArmor.Get());
828  }
829  return true;
830  }
831  else
832  otErr << "OTAsymmetricKey::GetPublicKey: Error: GetPublicKey(armored) "
833  "returned false. (Returning false.)\n";
834 
835  return false;
836 }
EXPORT bool GetPublicKey(OTASCIIArmor &strKey) const
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAsymmetricKey::IsEmpty ( ) const
inline

Definition at line 279 of file OTAsymmetricKey.hpp.

280  {
281  return (nullptr == m_p_ascKey);
282  } // m_p_ascKey is the most basic value. m_pKey is derived from it, for
static bool opentxs::OTAsymmetricKey::IsPasswordCallbackSet ( )
inlinestatic

Definition at line 217 of file OTAsymmetricKey.hpp.

218  {
219  return (nullptr == s_pwCallback) ? false : true;
220  }
static OT_OPENSSL_CALLBACK * s_pwCallback
bool opentxs::OTAsymmetricKey::IsPrivate ( ) const
inline

Definition at line 288 of file OTAsymmetricKey.hpp.

289  {
290  return m_bIsPrivateKey;
291  }
bool opentxs::OTAsymmetricKey::IsPublic ( ) const
inline

Definition at line 284 of file OTAsymmetricKey.hpp.

285  {
286  return m_bIsPublicKey;
287  }
OTAsymmetricKey * opentxs::OTAsymmetricKey::KeyFactory ( )
static

Definition at line 154 of file OTAsymmetricKey.cpp.

156 {
157  OTAsymmetricKey* pKey = nullptr;
158 #if defined(OT_CRYPTO_USING_OPENSSL)
159  pKey = new OTAsymmetricKey_OpenSSL;
160 #elif defined(OT_CRYPTO_USING_GPG)
161  // pKey = new OTAsymmetricKey_GPG;
162  otErr << __FUNCTION__ << ": Open-Transactions doesn't support GPG (yet), "
163  "so it's impossible to instantiate a key.\n";
164 #else
165  otErr << __FUNCTION__
166  << ": Open-Transactions isn't built with any crypto engine, "
167  "so it's impossible to instantiate a key.\n";
168 #endif
169  return pKey;
170 }
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAsymmetricKey::LoadPrivateKey ( const OTString strFoldername,
const OTString strFilename,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 1174 of file OTAsymmetricKey.cpp.

1181 {
1182  Release();
1183 
1184  m_bIsPublicKey = false;
1185  m_bIsPrivateKey = true;
1186 
1187  const char* szFoldername = strFoldername.Get();
1188  const char* szFilename = strFilename.Get();
1189 
1190  OT_ASSERT(strFoldername.Exists());
1191  OT_ASSERT(strFilename.Exists());
1192 
1193  if (!OTDB::Exists(szFoldername, szFilename)) {
1194  otOut << "OTAsymmetricKey::LoadPrivateKey: Unable to find private key "
1195  "file: " << szFoldername << OTLog::PathSeparator()
1196  << szFilename << "\n";
1197  return false;
1198  }
1199 
1200  // The private key is stored in an encrypted form, which is how it stays
1201  // until the
1202  // password callback is passed into some OpenSSL call that attempts to use
1203  // it.
1204  //
1205  std::string strFileContents(OTDB::QueryPlainString(
1206  szFoldername, szFilename)); // <=== LOADING "AS-IS" FROM DATA STORE.
1207 
1208  if (strFileContents.length() < 2) {
1209  otErr << "OTAsymmetricKey::LoadPrivateKey: Error reading file: "
1210  << szFoldername << OTLog::PathSeparator() << szFilename << "\n";
1211  return false;
1212  }
1213 
1214  const OTString strCert(strFileContents),
1215  strReason(nullptr == pstrReason ? "OTAsymmetricKey::LoadPrivateKey"
1216  : *pstrReason);
1217 
1218  return LoadPrivateKeyFromCertString(strCert, false, &strReason,
1219  pImportPassword); // bEscaped=false;
1220  // "escaped" means pre-pended with "- " as in: - -----BEGIN CER....
1221 }
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
OTLOG_IMPORT OTLogStream otOut
virtual bool LoadPrivateKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:728
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
virtual bool opentxs::OTAsymmetricKey::LoadPrivateKeyFromCertString ( const OTString strCert,
bool  bEscaped = true,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)
pure virtual
bool opentxs::OTAsymmetricKey::LoadPublicKey ( const OTString strFoldername,
const OTString strFilename 
)

Definition at line 1224 of file OTAsymmetricKey.cpp.

1226 {
1227  // Already done in SetPublicKey()
1228  // m_bIsPublicKey = true;
1229  // m_bIsPrivateKey = false;
1230 
1231  Release();
1232 
1233  // This doesn't use assert on the arguments, but theArmor.LoadFromFile DOES.
1234 
1235  OTASCIIArmor theArmor;
1236 
1237  if (theArmor.LoadFromFile(strFoldername, strFilename)) {
1238  if (SetPublicKey(theArmor)) {
1239  otLog4 << "Success setting public key from OTASCIIArmor in "
1240  "OTAsymmetricKey::LoadPublicKey.\n";
1241  return true;
1242  }
1243  else {
1244  otErr << "Unable to convert from OTASCIIArmor to public key in "
1245  "OTAsymmetricKey::LoadPublicKey: " << strFilename << "\n";
1246  return false;
1247  }
1248  }
1249  else {
1250  otErr
1251  << "Unable to read pubkey file in OTAsymmetricKey::LoadPublicKey: "
1252  << strFilename << "\n";
1253  return false;
1254  }
1255 }
OTLOG_IMPORT OTLogStream otLog4
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAsymmetricKey::LoadPublicKeyFromCertFile ( const OTString strFoldername,
const OTString strFilename,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)

Definition at line 1258 of file OTAsymmetricKey.cpp.

1261 {
1262  Release();
1263 
1264  m_bIsPublicKey = true;
1265  m_bIsPrivateKey = false;
1266 
1267  const char* szFoldername = strFoldername.Get();
1268  const char* szFilename = strFilename.Get();
1269 
1270  OT_ASSERT(strFoldername.Exists());
1271  OT_ASSERT(strFilename.Exists());
1272 
1273  if (!OTDB::Exists(szFoldername, szFilename)) {
1274  otErr << __FUNCTION__ << ": File does not exist: " << szFoldername
1275  << OTLog::PathSeparator() << szFilename << "\n";
1276  return false;
1277  }
1278 
1279  //
1280  std::string strFileContents(OTDB::QueryPlainString(
1281  szFoldername, szFilename)); // <=== LOADING FROM DATA STORE.
1282 
1283  if (strFileContents.length() < 2) {
1284  otErr << __FUNCTION__ << ": Error reading file: " << szFoldername
1285  << OTLog::PathSeparator() << szFilename << "\n";
1286  return false;
1287  }
1288 
1289  const OTString strCert(strFileContents);
1290 
1292  strCert, false, pstrReason,
1293  pImportPassword); // bEscaped=false; "escaped" means pre-pended with "-
1294  // " as in: - -----BEGIN CER....
1295 }
virtual bool LoadPublicKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:728
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
virtual bool opentxs::OTAsymmetricKey::LoadPublicKeyFromCertString ( const OTString strCert,
bool  bEscaped = true,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
)
pure virtual
virtual bool opentxs::OTAsymmetricKey::LoadPublicKeyFromPGPKey ( const OTASCIIArmor strKey)
pure virtual
virtual bool opentxs::OTAsymmetricKey::ReEncryptPrivateKey ( const OTPassword theExportPassword,
bool  bImporting 
) const
pure virtual
void opentxs::OTAsymmetricKey::Release ( )
virtual

Reimplemented in opentxs::OTAsymmetricKey_OpenSSL.

Definition at line 1164 of file OTAsymmetricKey.cpp.

1165 {
1166  Release_AsymmetricKey(); // My own cleanup is done here.
1167 
1168  // Next give the base class a chance to do the same...
1169  // ot_super::Release(); // THERE IS NO base class in this case. But
1170  // normally this would be here for most classes.
1171 }
void opentxs::OTAsymmetricKey::Release_AsymmetricKey ( )

Definition at line 1071 of file OTAsymmetricKey.cpp.

1072 {
1073 
1074  // Release the ascii-armored version of the key (safe to store in this
1075  // form.)
1076  //
1077  // Moving this to the destructor. Shouldn't be going nullptr here IMO.
1078  // if (nullptr != m_p_ascKey)
1079  // delete m_p_ascKey;
1080  // m_p_ascKey = nullptr;
1081 
1082  // Release the instantiated OpenSSL key (unsafe to store in this form.)
1083  //
1085 
1086  // m_bIsPrivateKey = false; // Every time this Releases, I don't want to
1087  // lose what kind of key it was. (Once we know, we know.)
1088 }
void opentxs::OTAsymmetricKey::ReleaseKey ( )

Definition at line 1101 of file OTAsymmetricKey.cpp.

1102 {
1103  // Todo: someday put a timer inside this class, so it doesn't REALLY release
1104  // the
1105  // key until the Timer has expired.
1106  // NOTE: marking this as "todo" because I won't necessarily want it done
1107  // this way. This
1108  // solution would keep the actual private key loaded in OpenSSL, meaning I'd
1109  // have to take
1110  // over the OpenSSL memory management to make it into a safe solution
1111  // (though I probably
1112  // have to do that anyway.)
1113  // A better solution might be to have a random session key used for
1114  // protecting a hashed
1115  // version of the passphrase, and then ALWAYS destroying the key as fast as
1116  // possible,
1117  // instead using the hashed passphrase within the bounds of a timer, with
1118  // the hashed passphrase
1119  // being decrypted JUST before use and then destroyed, just as the private
1120  // key is destroyed.
1121  // I might also wish such a thing was stored not just in OT protected
1122  // memory, but in a standard
1123  // *API* for protected memory, such as ssh-agent or the Mac Keychain.
1124  // However, that can easily
1125  // be just an option to be added later, meaning I can go ahead and code my
1126  // hashed password solution
1127  // in the meantime. But will that be coded here at the OTAsymmetricKey
1128  // level? Or at the Nym level,
1129  // or at the static Nym level, or the app level? Hmm...
1130  //
1131  // Security:
1132  // UPDATE: Since the above solution is coming at some point anyway, I'm
1133  // going ahead and adding a
1134  // Timer version that works at this level (OTAsymmetricKey.) The reason is
1135  // because it will be quick
1136  // and easy, and will give me the functionality I need for now, until I code
1137  // all the stuff above.
1138  // Just keep in mind: This is good enough for now, but it WILL result in the
1139  // private key staying
1140  // loaded in memory until the timer runs out, meaning if an attacker has
1141  // access to the RAM on the
1142  // local machine, if I haven't replaced the OpenSSL memory management, then
1143  // that is a security issue.
1144  //
1145  // TODO (remove theTimer entirely. OTCachedKey replaces already.)
1146  // I set this timer because the above required a password. But now that
1147  // master key is working,
1148  // the above would flow through even WITHOUT the user typing his passphrase
1149  // (since master key still
1150  // not timed out.) Resulting in THIS timer being reset! Todo: I already
1151  // shortened this timer to 30
1152  // seconds, but need to phase it down to 0 and then remove it entirely!
1153  // Master key takes over now!
1154  //
1155 
1156  // if (m_timer.getElapsedTimeInSec() > OT_KEY_TIMER)
1158 
1159  // Programmatic user (developer) may call ReleaseKey, but then we don't
1160  // actually release it until it's
1161  // been at least X minutes.
1162 }
void opentxs::OTAsymmetricKey::ReleaseKeyLowLevel ( )
protected

Definition at line 1090 of file OTAsymmetricKey.cpp.

1091 {
1093 
1094  m_timer.clear();
1095 
1096  // m_bIsPrivateKey = false; // Every time this Releases, I don't want to
1097  // lose what kind of key it was. (Once we know, we know.)
1098 }
void clear()
Definition: Timer.cpp:69
virtual void ReleaseKeyLowLevel_Hook() const =0
virtual void opentxs::OTAsymmetricKey::ReleaseKeyLowLevel_Hook ( ) const
protectedpure virtual
virtual bool opentxs::OTAsymmetricKey::SaveCertToString ( OTString strOutput,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
) const
pure virtual
virtual bool opentxs::OTAsymmetricKey::SavePrivateKeyToString ( OTString strOutput,
const OTString pstrReason = nullptr,
const OTPassword pImportPassword = nullptr 
) const
pure virtual
void opentxs::OTAsymmetricKey::SetAsPrivate ( )
inline

Definition at line 297 of file OTAsymmetricKey.hpp.

298  {
299  m_bIsPublicKey = false;
300  m_bIsPrivateKey = true;
301  } // (Only if you really know what you are doing.)
void opentxs::OTAsymmetricKey::SetAsPublic ( )
inline

Definition at line 292 of file OTAsymmetricKey.hpp.

293  {
294  m_bIsPublicKey = true;
295  m_bIsPrivateKey = false;
296  } // Don't use this, normally it's not necessary.
void opentxs::OTAsymmetricKey::SetPasswordCallback ( OT_OPENSSL_CALLBACK pCallback)
static

Definition at line 201 of file OTAsymmetricKey.cpp.

202 {
203  const char* szFunc = "OTAsymmetricKey::SetPasswordCallback";
204 
205  if (nullptr != s_pwCallback)
206  otOut << szFunc << ": WARNING: re-setting the password callback (one "
207  "was already there)...\n";
208  else
209  otWarn << szFunc << ": FYI, setting the password callback to a "
210  "non-nullptr pointer (which is what we want.)\n";
211 
212  if (nullptr == pCallback)
213  otErr << szFunc
214  << ": WARNING, setting the password callback to nullptr! "
215  "(OpenSSL will thus "
216  "be forced to ask for the passphase on the console, "
217  "until this is called "
218  "again and set properly.)\n";
219 
220  s_pwCallback = pCallback; // no need to delete function pointer that came
221  // before this function pointer.
222 }
OTLOG_IMPORT OTLogStream otOut
static OT_OPENSSL_CALLBACK * s_pwCallback
OTLOG_IMPORT OTLogStream otWarn
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAsymmetricKey::SetPasswordCaller ( OTCaller theCaller)
static

Definition at line 280 of file OTAsymmetricKey.cpp.

281 {
282  const char* szFunc = "OTAsymmetricKey::SetPasswordCaller";
283 
284  otLog3 << szFunc
285  << ": Attempting to set the password caller... "
286  "(the Java code has passed us its custom password dialog object "
287  "for later use if/when the "
288  "OT 'C'-based password callback is triggered by openssl.)\n";
289 
290  if (!theCaller.isCallbackSet()) {
291  otErr << szFunc << ": ERROR: OTCaller::setCallback() "
292  "MUST be called first, with an OTCallback-extended "
293  "object passed to it,\n"
294  "BEFORE calling this function with that OTCaller. "
295  "(Returning false.)\n";
296  return false;
297  }
298 
299  if (nullptr != s_pCaller) {
300  otErr << szFunc
301  << ": WARNING: Setting the password caller again, even though "
302  "it was apparently ALREADY set... (Meaning Java has probably "
303  "erroneously called this twice, "
304  "possibly passing the same OTCaller both times.)\n";
305  // delete s_pCaller; // Let Java delete it.
306  }
307 
308  s_pCaller = &theCaller;
309 
311 
312  otWarn << szFunc
313  << ": FYI, Successfully set the password caller object from "
314  "Java, and set the souped_up_pass_cb in C for OpenSSL (which "
315  "triggers "
316  "that Java object when the time is right.) Returning true.\n";
317 
318  return true;
319 }
static OTCaller * s_pCaller
EXPORT OT_OPENSSL_CALLBACK souped_up_pass_cb
OTLOG_IMPORT OTLogStream otLog3
static void SetPasswordCallback(OT_OPENSSL_CALLBACK *pCallback)
OTLOG_IMPORT OTLogStream otWarn
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAsymmetricKey::SetPrivateKey ( const OTString strKey,
bool  bEscaped = false 
)

Definition at line 953 of file OTAsymmetricKey.cpp.

954 {
955  m_bIsPublicKey = false;
956  m_bIsPrivateKey = true;
957 
958  // This reads the string into the Armor and removes the bookends. (-----
959  // BEGIN ...)
960  //
961  OTASCIIArmor theArmor;
962  const char* szPrivateKeyStarts = "-----BEGIN ENCRYPTED PRIVATE KEY-----";
963  if (theArmor.LoadFromString(const_cast<OTString&>(strKey), bEscaped,
964  szPrivateKeyStarts)) // This last param causes
965  // OTASCIIArmor to only
966  // "start loading" when it
967  // reaches the private key.
968  {
969  return SetPrivateKey(theArmor);
970  }
971 
972  return false;
973 }
bool SetPrivateKey(const OTString &strKey, bool bEscaped=false)
bool opentxs::OTAsymmetricKey::SetPrivateKey ( const OTASCIIArmor strKey)

Definition at line 977 of file OTAsymmetricKey.cpp.

978 {
980 
981  m_bIsPublicKey = false;
982  m_bIsPrivateKey = true; // PRIVATE KEY
983 
984  if (nullptr == m_p_ascKey) {
985  m_p_ascKey = new OTASCIIArmor;
986  OT_ASSERT(nullptr != m_p_ascKey);
987  }
988 
989  m_p_ascKey->Set(ascKey);
990 
991  return true;
992 }
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTAsymmetricKey::SetPublicKey ( const OTASCIIArmor strKey)

Definition at line 884 of file OTAsymmetricKey.cpp.

885 {
886  ReleaseKeyLowLevel(); // In case the key is already loaded, we release it
887  // here. (Since it's being replaced, it's now the
888  // wrong key anyway.)
889 
890  m_bIsPublicKey = true;
891  m_bIsPrivateKey = false;
892 
893  if (nullptr == m_p_ascKey) {
894  m_p_ascKey = new OTASCIIArmor;
895  OT_ASSERT(nullptr != m_p_ascKey);
896  }
897 
898  m_p_ascKey->Set(ascKey);
899 
900  return true;
901 }
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTAsymmetricKey::SetPublicKey ( const OTString strKey,
bool  bEscaped = false 
)

Definition at line 861 of file OTAsymmetricKey.cpp.

862 {
863  m_bIsPublicKey = true;
864  m_bIsPrivateKey = false;
865 
866  // This reads the string into the Armor and removes the bookends. (-----
867  // BEGIN ...)
868  OTASCIIArmor theArmor;
869 
870  if (theArmor.LoadFromString(const_cast<OTString&>(strKey), bEscaped)) {
871  return SetPublicKey(theArmor);
872  }
873  else
874  otErr << "OTAsymmetricKey::SetPublicKey: Error: failed loading "
875  "ascii-armored contents from bookended string:\n\n" << strKey
876  << "\n\n";
877 
878  return false;
879 }
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
OTLOG_IMPORT OTLogStream otErr

Member Data Documentation

bool opentxs::OTAsymmetricKey::m_bIsPrivateKey
protected

Definition at line 233 of file OTAsymmetricKey.hpp.

bool opentxs::OTAsymmetricKey::m_bIsPublicKey
protected

Definition at line 232 of file OTAsymmetricKey.hpp.

OTASCIIArmor* opentxs::OTAsymmetricKey::m_p_ascKey
protected

Definition at line 229 of file OTAsymmetricKey.hpp.

OTSignatureMetadata* opentxs::OTAsymmetricKey::m_pMetadata

Definition at line 237 of file OTAsymmetricKey.hpp.

Timer opentxs::OTAsymmetricKey::m_timer
protected

Definition at line 234 of file OTAsymmetricKey.hpp.

OTCaller * opentxs::OTAsymmetricKey::s_pCaller = nullptr
staticprotected

Definition at line 226 of file OTAsymmetricKey.hpp.

OT_OPENSSL_CALLBACK * opentxs::OTAsymmetricKey::s_pwCallback = nullptr
staticprotected

Definition at line 225 of file OTAsymmetricKey.hpp.


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