Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTAsymmetricKey.cpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTAsymmetricKey.cpp
4  *
5  */
6 
7 /************************************************************
8  -----BEGIN PGP SIGNED MESSAGE-----
9  Hash: SHA1
10 
11  * OPEN TRANSACTIONS
12  *
13  * Financial Cryptography and Digital Cash
14  * Library, Protocol, API, Server, CLI, GUI
15  *
16  * -- Anonymous Numbered Accounts.
17  * -- Untraceable Digital Cash.
18  * -- Triple-Signed Receipts.
19  * -- Cheques, Vouchers, Transfers, Inboxes.
20  * -- Basket Currencies, Markets, Payment Plans.
21  * -- Signed, XML, Ricardian-style Contracts.
22  * -- Scripted smart contracts.
23  *
24  * Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
25  *
26  * EMAIL:
28  *
29  * BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
30  *
31  * KEY FINGERPRINT (PGP Key in license file):
32  * 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
33  *
34  * OFFICIAL PROJECT WIKI(s):
35  * https://github.com/FellowTraveler/Moneychanger
36  * https://github.com/FellowTraveler/Open-Transactions/wiki
37  *
38  * WEBSITE:
39  * http://www.OpenTransactions.org/
40  *
41  * Components and licensing:
42  * -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
43  * -- otlib.........A class library.......LICENSE:...LAGPLv3
44  * -- otapi.........A client API..........LICENSE:...LAGPLv3
45  * -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
46  * -- otserver......Server Application....LICENSE:....AGPLv3
47  * Github.com/FellowTraveler/Open-Transactions/wiki/Components
48  *
49  * All of the above OT components were designed and written by
50  * Fellow Traveler, with the exception of Moneychanger, which
51  * was contracted out to Vicky C ([email protected]).
52  * The open-source community has since actively contributed.
53  *
54  * -----------------------------------------------------
55  *
56  * LICENSE:
57  * This program is free software: you can redistribute it
58  * and/or modify it under the terms of the GNU Affero
59  * General Public License as published by the Free Software
60  * Foundation, either version 3 of the License, or (at your
61  * option) any later version.
62  *
63  * ADDITIONAL PERMISSION under the GNU Affero GPL version 3
64  * section 7: (This paragraph applies only to the LAGPLv3
65  * components listed above.) If you modify this Program, or
66  * any covered work, by linking or combining it with other
67  * code, such other code is not for that reason alone subject
68  * to any of the requirements of the GNU Affero GPL version 3.
69  * (==> This means if you are only using the OT API, then you
70  * don't have to open-source your code--only your changes to
71  * Open-Transactions itself must be open source. Similar to
72  * LGPLv3, except it applies to software-as-a-service, not
73  * just to distributing binaries.)
74  *
75  * Extra WAIVER for OpenSSL, Lucre, and all other libraries
76  * used by Open Transactions: This program is released under
77  * the AGPL with the additional exemption that compiling,
78  * linking, and/or using OpenSSL is allowed. The same is true
79  * for any other open source libraries included in this
80  * project: complete waiver from the AGPL is hereby granted to
81  * compile, link, and/or use them with Open-Transactions,
82  * according to their own terms, as long as the rest of the
83  * Open-Transactions terms remain respected, with regard to
84  * the Open-Transactions code itself.
85  *
86  * Lucre License:
87  * This code is also "dual-license", meaning that Ben Lau-
88  * rie's license must also be included and respected, since
89  * the code for Lucre is also included with Open Transactions.
90  * See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
91  * The Laurie requirements are light, but if there is any
92  * problem with his license, simply remove the Lucre code.
93  * Although there are no other blind token algorithms in Open
94  * Transactions (yet. credlib is coming), the other functions
95  * will continue to operate.
96  * See Lucre on Github: https://github.com/benlaurie/lucre
97  * -----------------------------------------------------
98  * You should have received a copy of the GNU Affero General
99  * Public License along with this program. If not, see:
100  * http://www.gnu.org/licenses/
101  *
102  * If you would like to use this software outside of the free
103  * software license, please contact FellowTraveler.
104  * (Unfortunately many will run anonymously and untraceably,
105  * so who could really stop them?)
106  *
107  * DISCLAIMER:
108  * This program is distributed in the hope that it will be
109  * useful, but WITHOUT ANY WARRANTY; without even the implied
110  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
111  * PURPOSE. See the GNU Affero General Public License for
112  * more details.
113 
114  -----BEGIN PGP SIGNATURE-----
115  Version: GnuPG v1.4.9 (Darwin)
116 
117  iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
118  vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
119  KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
120  aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
121  LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
122  sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
123  oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
124  TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
125  x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
126  nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
127  M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
128  kamH0Y/n11lCvo1oQxM+
129  =uSzz
130  -----END PGP SIGNATURE-----
131  **************************************************************/
132 
133 #include "stdafx.hpp"
134 
136 #include "crypto/OTASCIIArmor.hpp"
137 #include "crypto/OTCachedKey.hpp"
138 #include "crypto/OTCaller.hpp"
139 #include "crypto/OTCrypto.hpp"
140 #include "OTIdentifier.hpp"
141 #include "OTLog.hpp"
142 #include "crypto/OTPasswordData.hpp"
144 #include "OTStorage.hpp"
145 
146 #if defined(OT_CRYPTO_USING_OPENSSL)
148 #endif
149 
150 namespace opentxs
151 {
152 
153 // static
154 OTAsymmetricKey* OTAsymmetricKey::KeyFactory() // Caller IS responsible to
155  // delete!
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 }
171 
172 // virtual
173 OTAsymmetricKey* OTAsymmetricKey::ClonePubKey() const // Caller IS responsible
174  // to delete!
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 }
191 
192 // static
194 
195 // static void SetPasswordCallback(p_OT_OPENSSL_CALLBACK pCallback);
196 // static p_OT_OPENSSL_CALLBACK GetPasswordCallback();
197 // static bool IsPasswordCallbackSet() { (nullptr == s_pwCallback) ? false :
198 // true;
199 // }
200 
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 }
223 
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 }
272 
273 // static
275 
276 // Takes ownership. UPDATE: doesn't, since he assumes the Java side
277 // created it and will therefore delete it when the time comes.
278 // I keep a pointer, but I don't delete the thing. Let Java do it.
279 //
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 }
320 
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 }
334 
335 bool OT_API_Set_PasswordCallback(OTCaller& theCaller) // Caller must have
336  // Callback attached
337  // already.
338 {
339  if (!theCaller.isCallbackSet()) {
340  otErr << __FUNCTION__ << ": ERROR:\nOTCaller::setCallback() "
341  "MUST be called first, with an "
342  "OTCallback-extended class passed to it,\n"
343  "before then invoking this function (and "
344  "passing that OTCaller as a parameter "
345  "into this function.)\n";
346  return false;
347  }
348 
349  otWarn << __FUNCTION__
350  << ": FYI, calling OTAsymmetricKey::SetPasswordCaller(theCaller) "
351  "now... (which is where "
352  "OT internally sets its pointer to the Java caller object, which "
353  "must have been passed in as a "
354  "parameter to this function. "
355  "This is also where OT either sets its internal 'C'-based "
356  "password callback to the souped_up "
357  "version which uses that Java caller object, "
358  "OR where OT sets its internal callback to nullptr--which causes "
359  "OpenSSL to ask for the passphrase "
360  "on the CONSOLE instead.)\n";
361 
362  const bool bSuccess = OTAsymmetricKey::SetPasswordCaller(theCaller);
363 
364  otWarn << __FUNCTION__
365  << ": RESULT of call to OTAsymmetricKey::SetPasswordCaller: "
366  << (bSuccess ? "SUCCESS" : "FAILURE") << "\n";
367 
368  return bSuccess;
369 }
370 
371 /*
372  extern "C"
373  {
374  typedef int32_t OT_OPENSSL_CALLBACK(char* buf, int32_t size, int32_t rwflag,
375  void* u); // <== Callback type, used for declaring.
376  }
377 */
378 
379 // If the password callback isn't set, then it uses the default ("test")
380 // password.
381 //
382 extern "C" int32_t default_pass_cb(char* buf, int32_t size, int32_t,
383  void* userdata)
384 {
385  int32_t len = 0;
386  const uint32_t theSize = uint32_t(size);
387 
388  // We'd probably do something else if 'rwflag' is 1
389 
390  const OTPasswordData* pPWData = nullptr;
391  std::string str_userdata;
392 
393  if (nullptr != userdata) {
394  pPWData = static_cast<OTPasswordData*>(userdata);
395 
396  if (nullptr != pPWData) {
397  str_userdata = pPWData->GetDisplayString();
398  }
399  }
400  else
401  str_userdata = "";
402 
403  // otWarn << "OPENSSL_CALLBACK: (Password callback hasn't been set
404  // yet...) Using 'test' pass phrase for \"%s\"\n", (char *)u);
405 
406  otWarn << __FUNCTION__ << ": Using DEFAULT TEST PASSWORD: "
407  "'test' (for \"" << str_userdata << "\")\n";
408 
409  // get pass phrase, length 'len' into 'tmp'
410  //
411  // std::string str_Password;
412  // std::getline (std::cin, str_Password);
413 
414  // const char *tmp_passwd = ""; // For now removing any possibility that
415  // "test" password can slip through.
416  const char* tmp_passwd = "test";
417  // const char *tmp_passwd = str_Password.c_str();
418 
419  len = static_cast<int32_t>(strlen(tmp_passwd));
420  // len = str_Password.size();
421 
422  if (len <= 0) {
423  otOut << __FUNCTION__ << ": Problem? Returning 0...\n";
424  return 0;
425  }
426 
427  // if too int64_t, truncate
428  if (len > size) len = size;
429 
430  const uint32_t theLength = static_cast<const uint32_t>(len);
431 
432  // void * pv =
433  OTPassword::safe_memcpy(buf, // destination
434  theSize, // size of destination buffer.
435  tmp_passwd, // source
436  theLength); // length of source.
437  // bool bZeroSource=false); // if true, sets the source buffer to zero after
438  // copying is done.
439  return len;
440 }
441 
442 //#ifdef _WIN32
443 // memcpy_s(buf,
444 // theSize,
445 // tmp_passwd, // source
446 // theLength); // length of source.
447 //#else
448 // memcpy(buf, tmp_passwd, len);
449 //#endif
450 
451 #ifndef _PASSWORD_LEN
452 #define _PASSWORD_LEN 128
453 #endif
454 
455 // This is the function that OpenSSL calls when it wants to ask the user for his
456 // password.
457 // If we return 0, that's bad, that means the password caller and callback
458 // failed somehow.
459 //
460 extern "C" int32_t souped_up_pass_cb(char* buf, int32_t size, int32_t rwflag,
461  void* userdata)
462 {
463  // OT_ASSERT(nullptr != buf); // apparently it CAN be nullptr sometimes.
464  OT_ASSERT(nullptr != userdata);
465  const OTPasswordData* pPWData = static_cast<OTPasswordData*>(userdata);
466  const std::string str_userdata = pPWData->GetDisplayString();
467 
468  OTPassword thePassword;
469  bool bGotPassword = false;
470 
471  // Sometimes it's passed in, otherwise we use the global one.
472  std::shared_ptr<OTCachedKey> pCachedKey(pPWData->GetCachedKey());
473 
474  if (!pCachedKey) {
475  // Global one.
476  pCachedKey =
477  OTCachedKey::It(); // Used to only use this one (global one) but now
478  // I allow pPWData to contain a pointer to the
479  // exact instance. (To enable multiple
480  // instances...) If that's not found then here we
481  // set it to the global one.
482  }
483  if (!pCachedKey) OT_FAIL;
484 
485  const bool b1 = pPWData->isForNormalNym();
486  const bool b3 = !(pCachedKey->isPaused());
487 
488  // For example, perhaps we need to collect a password for a symmetric key.
489  // In that case, it has nothing to do with any master key, or any
490  // public/private
491  // keys. It ONLY wants to do a simple password collect.
492  //
493  const bool bOldSystem = pPWData->isUsingOldSystem();
494 
495  // otLog5 <<
496  // "--------------------------------------------------------------------------------\n"
497  // "TOP OF SOUPED-UP PASS CB:\n pPWData->isForNormalNym():
498  // %s \n "
500  // "!(pCachedKey->isPaused()): %s \n",
501  // b1 ? "NORMAL" : "NOT normal",
503  // b3 ? "NOT paused" : "PAUSED"
504  // );
505 
506  //
507  // It's for one of the normal Nyms.
508  // (NOT the master key.)
509  // If it was for the master key, we'd just pop up the dialog and get the
510  // master passphrase.
511  // But since it's for a NORMAL Nym, we have to call
512  // OTCachedKey::GetMasterPassword. IT will pop
513  // up the dialog if it needs to, by recursively calling this in master mode,
514  // and then it'll use
515  // the user passphrase from that dialog to derive a key, and use THAT key to
516  // unlock the actual
517  // "passphrase" (a random value) which is then passed back to OpenSSL to use
518  // for the Nyms.
519  //
520  if (b1 && // Normal Nyms, unlike Master passwords, have to look up the
521  // master password first.
522  !bOldSystem && b3) // ...Unless they are still using the old system, in
523  // which case they do NOT look up the master
524  // password...
525  {
526 
527  // Therefore we need to provide the password from an OTSymmetricKey
528  // stored here.
529  // (the "actual key" in the OTSymmetricKey IS the password that we are
530  // passing back!)
531 
532  // So either the "actual key" is cached on a timer, from some previous
533  // request like
534  // this, OR we have to pop up the passphrase dialog, ask for the
535  // passphrase for the
536  // OTSymmetricKey, and then use it to GET the actual key from that
537  // OTSymmetricKey.
538  // The OTSymmetricKey should be stored in the OTWallet or OTServer,
539  // which sets a pointer
540  // to itself inside the OTPasswordData class statically, on
541  // initialization.
542  // That way, OTPasswordData can use that pointer to get a pointer to the
543  // relevant
544  // OTSymmetricKey being used as the MASTER key.
545  //
546  otLog3 << __FUNCTION__ << ": Using GetMasterPassword() call. \n";
547 
548  bGotPassword = pCachedKey->GetMasterPassword(
549  pCachedKey, thePassword,
550  str_userdata.c_str()); // bool bVerifyTwice=false
551 
552  // NOTE: shouldn't the above call to GetMasterPassword be passing the
553  // rwflag as the final parameter?
554  // Just as we see below with the call to GetPasswordFromConsole. Right?
555  // Of course, it DOES generate internally,
556  // if necessary, and thus it forces an "ask twice" in that situation
557  // anyway. (It's that smart.)
558  // Actually that's it. The master already asks twice when it's
559  // generating.
560 
561  // bool GetMasterPassword(OTPassword& theOutput,
562  // const char * szDisplay=nullptr,
563  // bool bVerifyTwice=false);
564 
565  // otOut << "OPENSSL_CALLBACK (souped_up_pass_cb): Finished calling
566  // GetMasterPassword(). Result: %s\n",
567  // bGotPassword ? "SUCCESS" : "FAILURE");
568  }
569  else {
570  otLog3 << __FUNCTION__ << ": Using OT Password Callback. \n";
571 
572  OTCaller* pCaller =
573  OTAsymmetricKey::GetPasswordCaller(); // See if the developer
574  // registered one via the OT
575  // API.
576 
577  // if (nullptr == pCaller)
578  // {
579  // otErr << "OPENSSL_CALLBACK (souped_up_pass_cb): OTCaller is
580  // nullptr. Try calling OT_API_Set_PasswordCallback() first.\n";
581  // OT_ASSERT(0); // This will never actually happen, since
582  // SetPasswordCaller() and souped_up_pass_cb are activated in same
583  // place.
584  // }
585 
586  if (nullptr == pCaller) // We'll just grab it from the console then.
587  {
588  otOut << "Passphrase request for: \"" << str_userdata << "\"\n";
589 
590  bGotPassword = OTCrypto::It()->GetPasswordFromConsole(
591  thePassword, (1 == rwflag) ? true : false);
592  }
593  else // Okay, we have a callback, so let's pop up the dialog!
594  {
595 
596  // The dialog should display this string (so the user knows what he
597  // is authorizing.)
598  //
599  pCaller->SetDisplay(str_userdata.c_str(),
600  static_cast<int32_t>(str_userdata.size()));
601 
602  if (1 == rwflag) {
603  otLog4 << __FUNCTION__
604  << ": Using OT Password Callback (asks twice) for \""
605  << str_userdata << "\"...\n";
606  pCaller->callTwo(); // This is where Java pops up a modal dialog
607  // and asks for password twice...
608  }
609  else {
610  otLog4 << __FUNCTION__
611  << ": Using OT Password Callback (asks once) for \""
612  << str_userdata << "\"...\n";
613  pCaller->callOne(); // This is where Java pops up a modal dialog
614  // and asks for password once...
615  }
616 
617  /*
618  NOTICE: (For security...)
619 
620  We are using an OTPassword object to collect the password from the
621  caller.
622  (We're not passing strings back and forth.) The OTPassword object
623  is where we
624  can centralize our efforts to scrub the memory clean as soon as
625  we're done with
626  the password. It's also designed to be light (no baggage) and to be
627  passed around
628  easily, with a set-size array for the data.
629 
630  Notice I am copying the password directly from the OTPassword
631  object into the buffer
632  provided to me by OpenSSL. When the OTPassword object goes out of
633  scope, then it cleans
634  up automatically.
635  */
636 
637  bGotPassword = pCaller->GetPassword(thePassword);
638  }
639  }
640 
641  if (!bGotPassword) {
642  otOut << __FUNCTION__
643  << ": Failure: (false == bGotPassword.) (Returning 0.)\n";
644  return 0;
645  }
646  // --------------------------------------
647  otInfo << __FUNCTION__ << ": Success!\n";
648  /*
649  http://openssl.org/docs/crypto/pem.html#
650  "The callback must return the number of characters in the passphrase or 0
651  if an error occurred."
652  */
653  int32_t len = thePassword.isPassword() ? thePassword.getPasswordSize()
654  : thePassword.getMemorySize();
655 
656  if (len < 0) {
657  otOut << __FUNCTION__ << ": <0 length password was "
658  "returned from the API password callback. "
659  "Returning 0.\n";
660  return 0;
661  }
662  // --------------------------------------
663  else if (len == 0) {
664  const char* szDefault = "test";
665 
666  otOut << __FUNCTION__
667  << ": 0 length password was "
668  "returned from the API password callback. "
669  "Substituting default password 'test'.\n"; // todo: security:
670  // is this safe?
671  // Here's what's
672  // driving this: We
673  // can't return 0
674  // length string,
675  // but users wanted
676  // to be able to
677  // "just hit enter"
678  // and use an empty
679  // passphrase. So
680  // for cases where
681  // the user has
682  // explicitly "hit
683  // enter" we will
684  // substitute "test"
685  // as their
686  // passphrase
687  // instead. They
688  // still have to do
689  // this
690  // explicitly--it
691  // only happens when
692  // they use an empty
693  // one.
694 
695  if (thePassword.isPassword())
696  thePassword.setPassword(szDefault,
697  static_cast<int32_t>(OTString::safe_strlen(
698  szDefault, _PASSWORD_LEN)));
699  else
700  thePassword.setMemory(static_cast<const void*>(szDefault),
701  static_cast<uint32_t>(OTString::safe_strlen(
702  szDefault, _PASSWORD_LEN)) +
703  1); // setMemory doesn't assume the null
704  // terminator like setPassword does.
705 
706  len = thePassword.isPassword() ? thePassword.getPasswordSize()
707  : thePassword.getMemorySize();
708  }
709 
710  OTPassword* pMasterPW = pPWData->GetMasterPW();
711 
712  if (pPWData->isForCachedKey() && (nullptr != pMasterPW)) {
713  *pMasterPW = thePassword;
714  }
715  // --------------------------------------
716  else if (nullptr != buf) {
717  // if too int64_t, truncate
718  if (len > size) len = size;
719 
720  const uint32_t theSize = static_cast<uint32_t>(size);
721  const uint32_t theLength = static_cast<uint32_t>(len);
722 
723  if (thePassword.isPassword()) {
724  // otErr << "%s: BEFORE TEXT PASSWORD: %s LENGTH: %d\n",
725  // __FUNCTION__, thePassword.getPassword(), theLength);
726 
727  OTPassword::safe_memcpy(buf, // destination
728  theSize, // size of destination buffer.
729  thePassword.getPassword_uint8(), // source
730  theLength); // length of source.
731  // bool bZeroSource=false); // No need to set this true, since
732  // OTPassword (source) already zeros its memory automatically.
733  buf[theLength] = '\0'; // null terminator.
734 
735  // int32_t nSize =
736  // static_cast<int32_t>(thePassword.getPasswordSize());
737  // otErr << "%s: AFTER TEXT PASSWORD: %s LENGTH: %d\n",
738  // __FUNCTION__, buf, nSize);
739  }
740  else {
741  OTPassword::safe_memcpy(buf, // destination
742  theSize, // size of destination buffer.
743  thePassword.getMemory_uint8(), // source
744  theLength); // length of source.
745  // bool bZeroSource=false); // No need to set this true, since
746  // OTPassword (source) already zeros its memory automatically.
747 
748  // int32_t nSize =
749  // static_cast<int32_t>(thePassword.getMemorySize());
750  // otErr << "%s: (BINARY PASSWORD) LENGTH: %d\n",
751  // __FUNCTION__, nSize);
752  }
753 
754  }
755  // --------------------------------------
756  else // should never happen
757  {
758  // OT_FAIL_MSG("This should never happen. (souped_up_pass_cb");
759  }
760  return len;
761 }
762 
763 bool OTAsymmetricKey::CalculateID(OTIdentifier& theOutput) const // Only works
764  // for public
765  // keys.
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 }
795 
796 // Get the public key in ASCII-armored format with bookends - ------- BEGIN
797 // PUBLIC KEY --------
798 // This version, so far, is escaped-only. Notice the "- " before the rest of the
799 // bookend starts.
800 bool OTAsymmetricKey::GetPublicKey(OTString& strKey, bool bEscaped) const
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 }
837 
838 // Get the public key in ASCII-armored format.
839 //
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 }
853 
854 // High-level.
855 // This is the version that will handle the bookends ( --------- BEGIN PUBLIC
856 // KEY -------)
857 // You can pass it an OTString, and it will then call the lower-level version of
858 // SetPublicKey
859 // (the one that takes an OTASCIIArmor object.)
860 //
861 bool OTAsymmetricKey::SetPublicKey(const OTString& strKey, bool bEscaped)
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 }
880 
881 // Copies to internal ascii-armored string, and wipes any key if
882 // one is already loaded.
883 //
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 }
902 
903 // Get the private key in ASCII-armored format with bookends - ------- BEGIN
904 // ENCRYPTED PRIVATE KEY --------
905 // This version, so far, is escaped-only. Notice the "- " before the rest of the
906 // bookend starts.
907 //
908 bool OTAsymmetricKey::GetPrivateKey(OTString& strKey, bool bEscaped) const
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 }
933 
934 // Get the private key in ASCII-armored format
935 bool OTAsymmetricKey::GetPrivateKey(OTASCIIArmor& ascKey) const // (ascKey is
936  // the output.)
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 }
948 
949 // Decodes a private key from ASCII armor into an actual key pointer
950 // and sets that as the keypointer on this object.
951 // This is the version that will handle the bookends ( --------- BEGIN ENCRYPTED
952 // PRIVATE KEY -------)
953 bool OTAsymmetricKey::SetPrivateKey(const OTString& strKey, bool bEscaped)
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 }
974 
975 // Copies to the internal ascii-armored storage. Wipes the internal
976 // private key, if one is loaded.
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 }
993 
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 }
1006 
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 }
1070 
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 }
1089 
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 }
1099 
1100 // High-level, used only by programmatic user, not by this class internally.
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 }
1163 
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 }
1172 
1173 // Load the private key from a .pem file
1175  const OTString& strFoldername, const OTString& strFilename,
1176  const OTString* pstrReason,
1177  const OTPassword* pImportPassword) // This reason
1178  // is what
1179  // displays on
1180 // the passphrase dialog.
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 }
1222 
1223 // Load the public key from a .pem file
1224 bool OTAsymmetricKey::LoadPublicKey(const OTString& strFoldername,
1225  const OTString& strFilename)
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 }
1256 
1257 // Load the public key from a x509 stored in a .pem file
1259  const OTString& strFoldername, const OTString& strFilename,
1260  const OTString* pstrReason, const OTPassword* pImportPassword)
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 }
1296 
1297 } // namespace opentxs
EXPORT const uint8_t * getMemory_uint8() const
Definition: OTPassword.cpp:582
static EXPORT OTCrypto * It()
Definition: OTCrypto.cpp:630
OTLOG_IMPORT OTLogStream otLog4
virtual OTAsymmetricKey * ClonePubKey() const
static EXPORT OTAsymmetricKey * KeyFactory()
EXPORT const char * GetDisplayString() const
virtual bool LoadPublicKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
static OTCaller * s_pCaller
EXPORT uint32_t getMemorySize() const
Definition: OTPassword.cpp:619
EXPORT bool isUsingOldSystem() const
EXPORT OT_OPENSSL_CALLBACK souped_up_pass_cb
bool LoadPublicKey(const OTString &strFoldername, const OTString &strFilename)
EXPORT bool GetPasswordFromConsole(OTPassword &theOutput, bool bRepeat=false) const
Definition: OTCrypto.cpp:587
int32_t OT_OPENSSL_CALLBACK(char *buf, int32_t size, int32_t rwflag, void *userdata)
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
OTSignatureMetadata * m_pMetadata
OTLOG_IMPORT OTLogStream otOut
virtual bool LoadPrivateKeyFromCertString(const OTString &strCert, bool bEscaped=true, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)=0
EXPORT OT_OPENSSL_CALLBACK default_pass_cb
EXPORT bool isPassword() const
Definition: OTPassword.cpp:537
OTLOG_IMPORT OTLogStream otLog3
bool LoadPublicKeyFromCertFile(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
EXPORT int32_t setMemory(const void *input, uint32_t size)
EXPORT int32_t setPassword(const char *input, int32_t size)
Definition: OTPassword.cpp:665
EXPORT void Concatenate(const char *arg,...)
Definition: OTString.cpp:1334
static OTCaller * GetPasswordCaller()
EXPORT bool Exists() const
Definition: OTString.cpp:1035
static EXPORT std::shared_ptr< OTCachedKey > It(OTIdentifier *pIdentifier=nullptr)
std::shared_ptr< OTCachedKey > GetCachedKey() const
bool SetPrivateKey(const OTString &strKey, bool bEscaped=false)
static OT_OPENSSL_CALLBACK * s_pwCallback
static EXPORT bool LoadFromString(OTASCIIArmor &ascArmor, const OTString &strInput, std::string str_bookend="-----BEGIN")
EXPORT bool LoadFromFile(const OTString &foldername, const OTString &filename)
static bool SetPasswordCaller(OTCaller &theCaller)
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
void clear()
Definition: Timer.cpp:69
static size_t safe_strlen(const char *s, size_t max)
Definition: OTString.cpp:388
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
bool GetPrivateKey(OTString &strKey, bool bEscaped=true) const
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:728
EXPORT bool GetPublicKey(OTASCIIArmor &strKey) const
EXPORT void callTwo()
Definition: OTCaller.cpp:277
virtual bool CalculateID(OTIdentifier &theOutput) const
static void SetPasswordCallback(OT_OPENSSL_CALLBACK *pCallback)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT void SetDisplay(const char *szDisplay, int32_t nLength)
Definition: OTCaller.cpp:191
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
virtual void ReleaseKeyLowLevel_Hook() const =0
OTLOG_IMPORT OTLogStream otInfo
EXPORT uint32_t getPasswordSize() const
Definition: OTPassword.cpp:613
EXPORT bool isCallbackSet() const
Definition: OTCaller.cpp:256
#define OT_FAIL
Definition: Assert.hpp:139
static bool IsPasswordCallbackSet()
EXPORT bool GetPassword(OTPassword &theOutput) const
Definition: OTCaller.cpp:204
OTLOG_IMPORT OTLogStream otWarn
bool LoadPrivateKey(const OTString &strFoldername, const OTString &strFilename, const OTString *pstrReason=nullptr, const OTPassword *pImportPassword=nullptr)
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
#define _PASSWORD_LEN
EXPORT const uint8_t * getPassword_uint8() const
Definition: OTPassword.cpp:554
static EXPORT OT_OPENSSL_CALLBACK * GetPasswordCallback()
OTPassword * GetMasterPW() const
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
virtual EXPORT ~OTAsymmetricKey()
static EXPORT void * safe_memcpy(void *dest, uint32_t dsize, const void *src, uint32_t ssize, bool zeroSource=false)
Definition: OTPassword.cpp:357
EXPORT bool isForCachedKey() const
EXPORT bool isForNormalNym() const
virtual EXPORT void Release()
Definition: OTString.cpp:765
EXPORT bool OT_API_Set_PasswordCallback(OTCaller &theCaller)
EXPORT void callOne()
Definition: OTCaller.cpp:261
OTLOG_IMPORT OTLogStream otLog5