Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTEnvelope.cpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTEnvelope.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 
135 #include "crypto/OTEnvelope.hpp"
136 
137 #include "crypto/OTCrypto.hpp"
138 #include "OTLog.hpp"
139 #include "crypto/OTPassword.hpp"
140 #include "OTPseudonym.hpp"
141 #include "OTStorage.hpp"
142 #include "crypto/OTSymmetricKey.hpp"
143 
144 extern "C" {
145 #ifdef _WIN32
146 #include <winsock2.h>
147 #pragma comment(lib, "ws2_32.lib")
148 #else
149 #include <netinet/in.h>
150 #endif
151 }
152 
153 namespace opentxs
154 {
155 
156 // Presumably this Envelope contains encrypted data (in binary form.)
157 // If you would like an ASCII-armored version of that data, just call this
158 // function.
159 // Should be called "Get Binary Envelope Encrypted Contents Into Ascii-Armored
160 // Form"
161 //
163  bool bLineBreaks) const
164 {
165  return theArmoredText.SetData(m_dataContents, bLineBreaks);
166 }
167 
168 // Should be called "Set This Envelope's binary ciphertext data, from an
169 // ascii-armored input string."
170 //
171 // Let's say you just retrieved the ASCII-armored contents of an encrypted
172 // envelope.
173 // Perhaps someone sent it to you, and you just read it out of his message.
174 // And let's say you want to get those contents back into binary form in an
175 // Envelope object again, so that they can be decrypted and extracted back as
176 // plaintext. Fear not, just call this function.
177 //
179  bool bLineBreaks)
180 {
181  return theArmoredText.GetData(m_dataContents, bLineBreaks);
182 }
183 
185  OTString& strArmorWithBookends, // output (if successful.)
186  bool bEscaped) const
187 {
188  OTASCIIArmor theArmoredText;
189  // This function will base64 ENCODE m_dataContents, and then
190  // Set() that as the string contents on theArmoredText.
191  const bool bSetData = theArmoredText.SetData(
192  m_dataContents, true); // bLineBreaks=true (by default anyway.)
193 
194  if (bSetData) {
195  const bool bWritten = theArmoredText.WriteArmoredString(
196  strArmorWithBookends, "ENVELOPE", // todo hardcoded
197  bEscaped);
198  if (!bWritten)
199  otErr << __FUNCTION__ << ": Failed while calling: "
200  "theArmoredText.WriteArmoredString\n";
201  else
202  return true;
203  }
204  else
205  otErr << __FUNCTION__
206  << ": Failed while calling: "
207  "theArmoredText.SetData(m_dataContents, true)\n";
208 
209  return false;
210 }
211 
213  const OTString& strArmorWithBookends, // input
214  bool bEscaped)
215 {
216  OTASCIIArmor theArmoredText;
217  const bool bLoaded = theArmoredText.LoadFromString(
218  const_cast<OTString&>(strArmorWithBookends),
219  bEscaped); // std::string str_override="-----BEGIN");
220 
221  if (bLoaded) {
222  // This function will base64 DECODE theArmoredText's string contents
223  // and return them as binary in m_dataContents
224  const bool bGotData =
225  theArmoredText.GetData(m_dataContents, true); // bLineBreaks = true
226 
227  if (!bGotData)
228  otErr << __FUNCTION__ << ": Failed while calling: "
229  "theArmoredText.GetData\n";
230  else
231  return true;
232  }
233  else
234  otErr << __FUNCTION__ << ": Failed while calling: "
235  "theArmoredText.LoadFromString\n";
236 
237  return false;
238 }
239 
240 // Encrypt theInput as envelope using symmetric crypto, using a random AES key
241 // that's
242 // kept encrypted in an OTSymmetricKey (encrypted using another key derived from
243 // thePassword.)
244 
245 bool OTEnvelope::Encrypt(const OTString& theInput, OTSymmetricKey& theKey,
246  const OTPassword& thePassword)
247 {
248  OT_ASSERT(
249  (thePassword.isPassword() && (thePassword.getPasswordSize() > 0)) ||
250  (thePassword.isMemory() && (thePassword.getMemorySize() > 0)));
251  OT_ASSERT(theInput.Exists());
252 
253  // Generate a random initialization vector.
254  //
255  OTPayload theIV;
256 
257  if (!theIV.Randomize(OTCryptoConfig::SymmetricIvSize())) {
258  otErr << __FUNCTION__ << ": Failed trying to randomly generate IV.\n";
259  return false;
260  }
261 
262  // If the symmetric key hasn't already been generated, we'll just do that
263  // now...
264  // (The passphrase is used to derive another key that is used to encrypt the
265  // actual symmetric key, and to access it later.)
266  //
267  if ((false == theKey.IsGenerated()) &&
268  (false == theKey.GenerateKey(thePassword))) {
269  otErr << __FUNCTION__
270  << ": Failed trying to generate symmetric key using password.\n";
271  return false;
272  }
273 
274  if (!theKey.HasHashCheck()) {
275  if (!theKey.GenerateHashCheck(thePassword)) {
276  otErr << __FUNCTION__
277  << ": Failed trying to generate hash check using password.\n";
278  return false;
279  }
280  }
281 
282  OT_ASSERT(theKey.HasHashCheck());
283 
284  OTPassword theRawSymmetricKey;
285 
286  if (false ==
287  theKey.GetRawKeyFromPassphrase(thePassword, theRawSymmetricKey)) {
288  otErr << __FUNCTION__ << ": Failed trying to retrieve raw symmetric "
289  "key using password.\n";
290  return false;
291  }
292 
293  OTPayload theCipherText;
294 
295  const bool bEncrypted = OTCrypto::It()->Encrypt(
296  theRawSymmetricKey, // The symmetric key, in clear form.
297  theInput.Get(), // This is the Plaintext.
298  theInput.GetLength() + 1, // for null terminator
299  theIV, // Initialization vector.
300  theCipherText); // OUTPUT. (Ciphertext.)
301 
302  //
303  // Success?
304  //
305  if (!bEncrypted) {
306  otErr << __FUNCTION__ << ": (static) call failed to encrypt. Wrong "
307  "key? (Returning false.)\n";
308  return false;
309  }
310 
311  // This is where the envelope final contents will be placed,
312  // including the envelope type, the size of the IV, the IV
313  // itself, and the ciphertext.
314  //
315  m_dataContents.Release();
316 
317  // Write the ENVELOPE TYPE (network order version.)
318  //
319  // 0 == Error
320  // 1 == Asymmetric Key (other functions -- Seal / Open.)
321  // 2 == Symmetric Key (this function -- Encrypt / Decrypt.)
322  // Anything else: error.
323 
324  uint16_t env_type_n = static_cast<uint16_t>(htons(static_cast<uint16_t>(
325  2))); // Calculate "network-order" version of envelope type 2.
326 
327  m_dataContents.Concatenate(reinterpret_cast<void*>(&env_type_n),
328  // (uint32_t here is the 2nd parameter to
329  // Concatenate, and has nothing to do with
330  // env_type_n being uint16_t)
331  static_cast<uint32_t>(sizeof(env_type_n)));
332 
333  // Write IV size (in network-order)
334  //
335  uint32_t ivlen =
336  OTCryptoConfig::SymmetricIvSize(); // Length of IV for this cipher...
337  OT_ASSERT(ivlen >= theIV.GetSize());
338  uint32_t ivlen_n = htonl(
339  theIV.GetSize()); // Calculate "network-order" version of iv length.
340 
341  m_dataContents.Concatenate(reinterpret_cast<void*>(&ivlen_n),
342  static_cast<uint32_t>(sizeof(ivlen_n)));
343 
344  // Write the IV itself.
345  //
346  m_dataContents.Concatenate(theIV.GetPayloadPointer(),
347  static_cast<uint32_t>(theIV.GetSize()));
348 
349  // Write the Ciphertext.
350  //
351  m_dataContents.Concatenate(theCipherText.GetPayloadPointer(),
352  static_cast<uint32_t>(theCipherText.GetSize()));
353 
354  // We don't write the size of the ciphertext before the ciphertext itself,
355  // since the decryption is able to deduce the size based on the total
356  // envelope
357  // size minus the other pieces. We might still want to add that size here,
358  // however.
359  // (for security / safety reasons.)
360 
361  return true;
362 }
363 
364 bool OTEnvelope::Decrypt(OTString& theOutput, const OTSymmetricKey& theKey,
365  const OTPassword& thePassword)
366 {
367  const char* szFunc = "OTEnvelope::Decrypt";
368 
369  OT_ASSERT(
370  (thePassword.isPassword() && (thePassword.getPasswordSize() > 0)) ||
371  (thePassword.isMemory() && (thePassword.getMemorySize() > 0)));
372  OT_ASSERT(theKey.IsGenerated());
373 
374  OTPassword theRawSymmetricKey;
375 
376  if (false ==
377  theKey.GetRawKeyFromPassphrase(thePassword, theRawSymmetricKey)) {
378  otErr << szFunc << ": Failed trying to retrieve raw symmetric key "
379  "using password. (Wrong password?)\n";
380  return false;
381  }
382 
383  uint32_t nRead = 0;
384  uint32_t nRunningTotal = 0;
385 
386  m_dataContents.reset(); // Reset the fread position on this object to 0.
387 
388  //
389  // Read the ENVELOPE TYPE (as network order version -- and convert to host
390  // version.)
391  //
392  // 0 == Error
393  // 1 == Asymmetric Key (this function -- Seal / Open)
394  // 2 == Symmetric Key (other functions -- Encrypt / Decrypt use this.)
395  // Anything else: error.
396  //
397  uint16_t env_type_n = 0;
398 
399  if (0 == (nRead = m_dataContents.OTfread(
400  reinterpret_cast<uint8_t*>(&env_type_n),
401  static_cast<uint32_t>(sizeof(env_type_n))))) {
402  otErr << szFunc << ": Error reading Envelope Type. Expected "
403  "asymmetric(1) or symmetric (2).\n";
404  return false;
405  }
406  nRunningTotal += nRead;
407  OT_ASSERT(nRead == static_cast<uint32_t>(sizeof(env_type_n)));
408 
409  // convert that envelope type from network to HOST endian.
410  //
411  const uint16_t env_type =
412  static_cast<uint16_t>(ntohs(static_cast<uint16_t>(env_type_n)));
413  // nRunningTotal += env_type; // NOPE! Just because envelope type is 1
414  // or 2, doesn't mean we add 1 or 2 extra bytes to the length here. Nope!
415 
416  if (2 != env_type) {
417  const uint32_t l_env_type = static_cast<uint32_t>(env_type);
418  otErr << szFunc << ": Error: Expected Envelope for Symmetric key (type "
419  "2) but instead found type: " << l_env_type << ".\n";
420  return false;
421  }
422 
423  // Read network-order IV size (and convert to host version)
424  //
425  const uint32_t max_iv_length =
426  OTCryptoConfig::SymmetricIvSize(); // I believe this is a max length, so
427  // it may not match the actual length
428  // of the IV.
429 
430  // Read the IV SIZE (network order version -- convert to host version.)
431  //
432  uint32_t iv_size_n = 0;
433 
434  if (0 == (nRead = m_dataContents.OTfread(
435  reinterpret_cast<uint8_t*>(&iv_size_n),
436  static_cast<uint32_t>(sizeof(iv_size_n))))) {
437  otErr << szFunc << ": Error reading IV Size.\n";
438  return false;
439  }
440  nRunningTotal += nRead;
441  OT_ASSERT(nRead == static_cast<uint32_t>(sizeof(iv_size_n)));
442 
443  // convert that iv size from network to HOST endian.
444  //
445  const uint32_t iv_size_host_order = ntohl(iv_size_n);
446 
447  if (iv_size_host_order > max_iv_length) {
448  otErr << szFunc << ": Error: iv_size ("
449  << static_cast<int64_t>(iv_size_host_order)
450  << ") is larger than max_iv_length ("
451  << static_cast<int64_t>(max_iv_length) << ").\n";
452  return false;
453  }
454  // nRunningTotal += iv_size_host_order; // Nope!
455 
456  // Then read the IV (initialization vector) itself.
457  //
458  OTPayload theIV;
459  theIV.SetPayloadSize(iv_size_host_order);
460 
461  if (0 == (nRead = m_dataContents.OTfread(
462  static_cast<uint8_t*>(
463  const_cast<void*>(theIV.GetPayloadPointer())),
464  static_cast<uint32_t>(iv_size_host_order)))) {
465  otErr << szFunc << ": Error reading initialization vector.\n";
466  return false;
467  }
468  nRunningTotal += nRead;
469  OT_ASSERT(nRead == static_cast<uint32_t>(iv_size_host_order));
470 
471  OT_ASSERT(nRead <= max_iv_length);
472 
473  // We create an OTPayload object to store the ciphertext itself, which
474  // begins AFTER the end of the IV.
475  // So we see pointer + nRunningTotal as the starting point for the
476  // ciphertext.
477  // the size of the ciphertext, meanwhile, is the size of the entire thing,
478  // MINUS nRunningTotal.
479  //
480  OTPayload theCipherText(
481  static_cast<const void*>(
482  static_cast<const uint8_t*>(m_dataContents.GetPointer()) +
483  nRunningTotal),
484  m_dataContents.GetSize() - nRunningTotal);
485 
486  // Now we've got all the pieces together, let's try to decrypt it...
487  //
488  OTPayload thePlaintext; // for output.
489 
490  const bool bDecrypted = OTCrypto::It()->Decrypt(
491  theRawSymmetricKey, // The symmetric key, in clear form.
492  static_cast<const char*>(
493  theCipherText.GetPayloadPointer()), // This is the Ciphertext.
494  theCipherText.GetSize(),
495  theIV, thePlaintext); // OUTPUT. (Recovered plaintext.) You can pass
496  // OTPassword& OR OTPayload& here (either will
497  // work.)
498 
499  // theOutput is where we'll put the decrypted data.
500  //
501  theOutput.Release();
502 
503  if (bDecrypted) {
504 
505  // Make sure it's null-terminated...
506  //
507  uint32_t nIndex = thePlaintext.GetSize() - 1;
508  (static_cast<uint8_t*>(
509  const_cast<void*>(thePlaintext.GetPointer())))[nIndex] = '\0';
510 
511  // Set it into theOutput (to return the plaintext to the caller)
512  //
513  theOutput.Set(static_cast<const char*>(thePlaintext.GetPointer()));
514  }
515 
516  return bDecrypted;
517 }
518 
519 // RSA / AES
520 
521 bool OTEnvelope::Seal(const OTPseudonym& theRecipient, const OTString& theInput)
522 {
523  OTString strNymID;
524  mapOfAsymmetricKeys theKeys;
525  theRecipient.GetIdentifier(strNymID);
526  theKeys.insert(std::pair<std::string, OTAsymmetricKey*>(
527  strNymID.Get(),
528  const_cast<OTAsymmetricKey*>(&(theRecipient.GetPublicEncrKey()))));
529 
530  return Seal(theKeys, theInput);
531 }
532 
533 bool OTEnvelope::Seal(setOfNyms& theRecipients, const OTString& theInput)
534 {
535  mapOfAsymmetricKeys RecipPubKeys;
536 
537  // Loop through theRecipients, and add the public key of each one to a set
538  // of keys.
539  for (auto& it : theRecipients) {
540  OTPseudonym* pNym = it;
541  OT_ASSERT_MSG(nullptr != pNym,
542  "OTEnvelope::Seal: Assert: nullptr pseudonym pointer.");
543 
544  OTString strNymID;
545  pNym->GetIdentifier(strNymID);
546  RecipPubKeys.insert(std::pair<std::string, OTAsymmetricKey*>(
547  strNymID.Get(),
548  const_cast<OTAsymmetricKey*>(&(pNym->GetPublicEncrKey()))));
549  }
550 
551  if (RecipPubKeys.empty()) return false;
552 
553  return Seal(RecipPubKeys, theInput);
554 }
555 
556 bool OTEnvelope::Seal(const OTAsymmetricKey& RecipPubKey,
557  const OTString& theInput)
558 {
559  mapOfAsymmetricKeys theKeys;
560  theKeys.insert(std::pair<std::string, OTAsymmetricKey*>(
561  "", // Normally the NymID goes here, but we don't know what it is, in
562  // this case.
563  const_cast<OTAsymmetricKey*>(&RecipPubKey)));
564 
565  return Seal(theKeys, theInput);
566 }
567 
568 // Seal up as envelope (Asymmetric, using public key and then AES key.)
569 
571  const OTString& theInput)
572 {
573  OT_ASSERT_MSG(!RecipPubKeys.empty(),
574  "OTEnvelope::Seal: ASSERT: RecipPubKeys.size() > 0");
575 
576  return OTCrypto::It()->Seal(RecipPubKeys, theInput, m_dataContents);
577 }
578 
579 // RSA / AES
580 
581 bool OTEnvelope::Open(const OTPseudonym& theRecipient, OTString& theOutput,
582  const OTPasswordData* pPWData)
583 {
584  return OTCrypto::It()->Open(m_dataContents, theRecipient, theOutput,
585  pPWData);
586 }
587 
588 // DONE: Fix OTEnvelope so we can seal to multiple recipients simultaneously.
589 // DONE: Fix OTEnvelope so it supports symmetric crypto as well as asymmetric.
590 
591 // DONE: Remove the Nym stored inside the purse, and replace with a
592 // session key, just as envelopes will support a session key.
593 
594 // TODO: Make sure OTEnvelope / OTCrypto_OpenSSL is safe with zeroing memory
595 // wherever needed.
596 
597 // Todo: Once envelopes support multiple recipient Nyms, then make a habit of
598 // encrypting
599 // to the user's key AND server's key, when sending.
600 
601 // Hmm this might be better than a session key, since we don't have to worry
602 // about keeping track
603 // of the session key for LATER, since envelopes generate a session key already.
604 // BUT: That means we do it already, and that means we wouldn't get any speed
605 // benefit.
606 // Transport protocol should have session key already built-in -- hmm what if
607 // going over email or
608 // some insecure channel?
609 // Solution: Make it always encrypted to public key (as it already is now) with
610 // session key automatically
611 // (as already) by virtue of using OpenSSL envelope. This will, of course,
612 // generate a new session key for
613 // EACH envelope, so we will STILL add the protocol of initiating sessions,
614 // purely to reduce CPU cycles
615 // during each session. This means we'll have the same protocol as before but
616 // just faster (in a way.)
617 //
618 
619 // We just read some encrypted (and armored) data, and we want to put it in
620 // an envelope so that it can be opened. So we can just directly set the
621 // armored string here, and it will be decoded into the original binary,
622 // inside this envelope. That way we can decrypt it (symmetric), or open it
623 // (asymmetric) and get the original plaintext that was sent.
624 //
625 OTEnvelope::OTEnvelope(const OTASCIIArmor& theArmoredText)
626 {
627  SetAsciiArmoredData(theArmoredText);
628 }
629 
631 {
632 }
633 
635 {
636 }
637 
638 } // namespace opentxs
static EXPORT OTCrypto * It()
Definition: OTCrypto.cpp:630
static EXPORT uint32_t SymmetricIvSize()
Definition: OTCrypto.cpp:391
virtual bool Encrypt(const OTPassword &theRawSymmetricKey, const char *szInput, uint32_t lInputLength, const OTPayload &theIV, OTPayload &theEncryptedOutput) const =0
EXPORT uint32_t getMemorySize() const
Definition: OTPassword.cpp:619
EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
EXPORT bool Decrypt(OTString &theOutput, const OTSymmetricKey &theKey, const OTPassword &thePassword)
Definition: OTEnvelope.cpp:364
EXPORT const OTAsymmetricKey & GetPublicEncrKey() const
EXPORT bool GetAsBookendedString(OTString &strArmorWithBookends, bool bEscaped=false) const
Definition: OTEnvelope.cpp:184
EXPORT bool isPassword() const
Definition: OTPassword.cpp:537
EXPORT uint32_t GetLength() const
Definition: OTString.cpp:1040
std::set< OTPseudonym * > setOfNyms
Definition: OTEnvelope.hpp:154
EXPORT bool SetAsciiArmoredData(const OTASCIIArmor &theArmoredText, bool bLineBreaks=true)
Definition: OTEnvelope.cpp:178
EXPORT bool Open(const OTPseudonym &theRecipient, OTString &theOutput, const OTPasswordData *pPWData=nullptr)
Definition: OTEnvelope.cpp:581
EXPORT bool Seal(const OTPseudonym &theRecipient, const OTString &theInput)
Definition: OTEnvelope.cpp:521
EXPORT bool WriteArmoredString(OTString &strOutput, const std::string str_type, bool bEscaped=false) const
EXPORT bool Encrypt(const OTString &theInput, OTSymmetricKey &theKey, const OTPassword &thePassword)
Definition: OTEnvelope.cpp:245
EXPORT bool GetRawKeyFromPassphrase(const OTPassword &thePassphrase, OTPassword &theRawKeyOutput, OTPassword *pDerivedKey=nullptr) const
EXPORT bool Exists() const
Definition: OTString.cpp:1035
static EXPORT bool LoadFromString(OTASCIIArmor &ascArmor, const OTString &strInput, std::string str_bookend="-----BEGIN")
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
EXPORT bool GetAsciiArmoredData(OTASCIIArmor &theArmoredText, bool bLineBreaks=true) const
Definition: OTEnvelope.cpp:162
virtual EXPORT ~OTEnvelope()
Definition: OTEnvelope.cpp:634
EXPORT bool GenerateKey(const OTPassword &thePassphrase, OTPassword **ppDerivedKey=nullptr)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
void reset()
Definition: OTData.hpp:186
EXPORT void SetPayloadSize(uint32_t lNewSize)
Definition: OTPayload.cpp:313
EXPORT uint32_t getPasswordSize() const
Definition: OTPassword.cpp:613
EXPORT bool GetData(OTData &theData, bool bLineBreaks=true) const
std::multimap< std::string, OTAsymmetricKey * > mapOfAsymmetricKeys
Definition: OTCrypto.hpp:155
EXPORT bool SetFromBookendedString(const OTString &strArmorWithBookends, bool bEscaped=false)
Definition: OTEnvelope.cpp:212
virtual bool Seal(mapOfAsymmetricKeys &RecipPubKeys, const OTString &theInput, OTData &dataOutput) const =0
EXPORT const char * Get() const
Definition: OTString.cpp:1045
virtual bool Open(OTData &dataInput, const OTPseudonym &theRecipient, OTString &theOutput, const OTPasswordData *pPWData=nullptr) const =0
EXPORT const void * GetPayloadPointer() const
Definition: OTPayload.cpp:318
OTLOG_IMPORT OTLogStream otErr
const void * GetPointer() const
Definition: OTData.hpp:162
EXPORT bool isMemory() const
Definition: OTPassword.cpp:542
EXPORT bool GenerateHashCheck(const OTPassword &thePassphrase)
virtual bool Decrypt(const OTPassword &theRawSymmetricKey, const char *szInput, uint32_t lInputLength, const OTPayload &theIV, OTCrypto_Decrypt_Output theDecryptedOutput) const =0
EXPORT uint32_t OTfread(uint8_t *data, uint32_t size)
Definition: OTData.cpp:214
EXPORT bool SetData(const OTData &theData, bool bLineBreaks=true)
virtual EXPORT void Release()
Definition: OTData.cpp:257
EXPORT void Concatenate(const void *data, uint32_t size)
Definition: OTData.cpp:333
virtual EXPORT void Release()
Definition: OTString.cpp:765
uint32_t GetSize() const
Definition: OTData.hpp:174