本文整理汇总了C++中OTEnvelope::Seal方法的典型用法代码示例。如果您正苦于以下问题:C++ OTEnvelope::Seal方法的具体用法?C++ OTEnvelope::Seal怎么用?C++ OTEnvelope::Seal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OTEnvelope
的用法示例。
在下文中一共展示了OTEnvelope::Seal方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReassignOwnership
bool OTToken::ReassignOwnership(const OTPseudonym & oldOwner, const OTPseudonym & newOwner)
{
bool bSuccess = false;
// load the bank and coin info into the bios
// The Mint private info is encrypted in m_ascPrivate. So I need to extract that
// first before I can use it.
OTEnvelope theEnvelope(m_ascSpendable);
OTString theString;
// Decrypt the Envelope into strContents
if (!theEnvelope.Open(oldOwner, theString))
bSuccess = false;
else
{
bSuccess = true;
}
if (bSuccess)
{
OTEnvelope theNewEnvelope;
bSuccess = theNewEnvelope.Seal(newOwner, theString);
if (bSuccess)
bSuccess = theNewEnvelope.GetAsciiArmoredData(m_ascSpendable);
}
return bSuccess;
}
示例2: Push
// Use a local variable for theToken, do NOT allocate it on the heap
// unless you are going to delete it yourself.
// Repeat: OTPurse is NOT responsible to delete it. We create our OWN internal
// variable here, new that, and add it to the stack. We do not add the one passed in.
bool OTPurse::Push(const OTPseudonym & theOwner, const OTToken & theToken)
{
if (theToken.GetAssetID() == m_AssetID)
{
OTString strToken(theToken);
// OTLog::vError("$$$$$$$$$$$$$$$ PUSHING token to Purse:\n---------->%s<-------------\n", strToken.Get());
OTEnvelope theEnvelope;
theEnvelope.Seal(theOwner, strToken);
OTASCIIArmor * pArmor = new OTASCIIArmor(theEnvelope);
// OTLog::vError("$$$$$$$$$$$$$$$ PUSHING token to Purse in armored form:\n---------->%s<-------------\n",
// pArmor->Get());
m_dequeTokens.push_front(pArmor);
// We keep track of the purse's total value.
m_lTotalValue += theToken.GetDenomination();
return true;
}
else {
OTString strPurseAssetType(m_AssetID), strTokenAssetType(theToken.GetAssetID());
OTLog::vError("ERROR: Tried to push token with wrong asset type in OTPurse::Push\nPurse Asset Type:\n%s\n"
"Token Asset Type:\n%s\n", strPurseAssetType.Get(), strTokenAssetType.Get());
return false;
}
}
示例3: SealMessageForRecipient
// This function, you pass in a message and it returns true or false to let
// you know whether the message was successfully sealed into theEnvelope.
// (Based on the public key into cached in the OTClientConnection...)
// This is for XmlRpc / HTTP mode.
bool OTClientConnection::SealMessageForRecipient(OTMessage & theMsg, OTEnvelope & theEnvelope)
{
if (m_PublicKey.GetKey())
{
// Save the ready-to-go message into a string.
OTString strEnvelopeContents(theMsg);
// Seal the string up into an encrypted Envelope
if (strEnvelopeContents.Exists())
return theEnvelope.Seal(m_PublicKey, strEnvelopeContents);
}
return false;
}
示例4: SealMessageForRecipient
// This function, you pass in a message and it returns true or false to let
// you know whether the message was successfully sealed into theEnvelope.
// (Based on the public key into cached in the OTClientConnection...)
// This is for XmlRpc / HTTP mode.
bool OTClientConnection::SealMessageForRecipient(OTMessage & theMsg, OTEnvelope & theEnvelope)
{
if (m_PublicKey.GetKey())
{
// Save the ready-to-go message into a string.
OTString strEnvelopeContents(theMsg);
// Seal the string up into an encrypted Envelope
if (strEnvelopeContents.Exists())
return theEnvelope.Seal(m_PublicKey, strEnvelopeContents);
}
else
OTLog::Error("OTClientConnection::SealMessageForRecipient: Unable to seal message, since this->m_PublicKey isn't set. \n");
return false;
}
示例5: SealMessageForRecipient
// This function, you pass in a message and it returns true or false to let
// you know whether the message was successfully sealed into theEnvelope.
// (Based on the public key into cached in the OTClientConnection...)
// This is for XmlRpc / HTTP mode.
//
bool OTClientConnection::SealMessageForRecipient(OTMessage & theMsg, OTEnvelope & theEnvelope)
{
OT_ASSERT(NULL != m_pPublicKey);
if (!(m_pPublicKey->IsEmpty()) && m_pPublicKey->IsPublic())
{
// Save the ready-to-go message into a string.
OTString strEnvelopeContents(theMsg);
// Seal the string up into an encrypted Envelope.
if (strEnvelopeContents.Exists())
return theEnvelope.Seal(*m_pPublicKey, strEnvelopeContents);
}
else
OTLog::Error("OTClientConnection::SealMessageForRecipient: "
"Unable to seal message, possibly a missing public key. \n");
return false;
}
示例6: AddDenomination
// The mint has a different key pair for each denomination.
// Pass the actual denomination such as 5, 10, 20, 50, 100...
bool OTMint_Lucre::AddDenomination(OTPseudonym & theNotary, int64_t lDenomination, int32_t nPrimeLength/*=1024*/)
{
OT_ASSERT(NULL != m_pKeyPublic);
bool bReturnValue = false;
// Let's make sure it doesn't already exist
OTASCIIArmor theArmor;
if (GetPublic(theArmor, lDenomination))
{
// it already exists.
OTLog::Error("Error: Denomination public already exists in OTMint::AddDenomination\n");
return false;
}
if (GetPrivate(theArmor, lDenomination))
{
// it already exists.
OTLog::Error("Error: Denomination private already exists in OTMint::AddDenomination\n");
return false;
}
// OTLog::Error("%s <size of bank prime in bits> <bank data file> <bank public data file>\n",
if ((nPrimeLength/8) < (MIN_COIN_LENGTH+DIGEST_LENGTH))
{
OTLog::vError("Prime must be at least %d bits\n",
(MIN_COIN_LENGTH+DIGEST_LENGTH)*8);
return false;
}
if (nPrimeLength%8)
{
OTLog::Error("Prime length must be a multiple of 8\n");
return false;
}
#ifdef _WIN32
SetMonitor("openssl.dump");
#else
SetMonitor(stderr);
#endif
OpenSSL_BIO bio = BIO_new(BIO_s_mem());
OpenSSL_BIO bioPublic = BIO_new(BIO_s_mem());
// Generate the mint private key information
Bank bank(nPrimeLength/8);
bank.WriteBIO(bio);
// Generate the mint public key information
PublicBank pbank(bank);
pbank.WriteBIO(bioPublic);
// Copy from BIO back to a normal OTString or Ascii-Armor
char privateBankBuffer[4096], publicBankBuffer[4096]; // todo stop hardcoding these string lengths
int32_t privatebankLen = BIO_read(bio, privateBankBuffer, 4000); // cutting it a little short on purpose, with the buffer.
int32_t publicbankLen = BIO_read(bioPublic, publicBankBuffer, 4000); // Just makes me feel more comfortable for some reason.
if (privatebankLen && publicbankLen)
{
// With this, we have the Lucre public and private bank info converted to OTStrings
OTString strPublicBank; strPublicBank.Set(publicBankBuffer, publicbankLen);
OTString strPrivateBank; strPrivateBank.Set(privateBankBuffer, privatebankLen);
OTASCIIArmor * pPublic = new OTASCIIArmor();
OTASCIIArmor * pPrivate = new OTASCIIArmor();
OT_ASSERT(NULL != pPublic);
OT_ASSERT(NULL != pPrivate);
// Set the public bank info onto pPublic
pPublic->SetString(strPublicBank, true); // linebreaks = true
// Seal the private bank info up into an encrypted Envelope
// and set it onto pPrivate
OTEnvelope theEnvelope;
theEnvelope.Seal(theNotary, strPrivateBank); // Todo check the return values on these two functions
theEnvelope.GetAsciiArmoredData(*pPrivate);
// Add the new key pair to the maps, using denomination as the key
m_mapPublic[lDenomination] = pPublic;
m_mapPrivate[lDenomination] = pPrivate;
// Grab the Server Nym ID and save it with this Mint
theNotary.GetIdentifier(m_ServerNymID);
// ---------------------------
// Grab the Server's public key and save it with this Mint
//
const OTAsymmetricKey & theNotaryPubKey = theNotary.GetPublicSignKey();
delete m_pKeyPublic;
m_pKeyPublic = theNotaryPubKey.ClonePubKey();
// ---------------------------
m_nDenominationCount++;
// ---------------------------
// Success!
bReturnValue = true;
OTLog::vOutput(1, "Successfully added denomination: %lld\n", lDenomination);
}
//.........这里部分代码省略.........
示例7: ProcessReply
// Process my reply back out to the client. @something.
// For TCP / SSL mode.
void OTClientConnection::ProcessReply(OTMessage &theReply)
{
OT_ASSERT(NULL != m_pPublicKey);
int err = 0;
uint32_t nwritten = 0;
bool bSendCommand = false;
bool bSendPayload = false;
u_header theCMD;
OTPayload thePayload;
memset((void *)theCMD.buf, 0, OT_CMD_HEADER_SIZE); // todo cast
// For now let's send ALL replies in Envelopes (encrypted to public key of client)
// IF we have a public key, that is. Otherwise we send as a normal message.
//
// All messages already require either a public key, or a nymID used to look up a
// public key. So given that I have that information when I reply, I might as well
// ENCRYPT my reply to that same public key. More secure that way.
//
// The wallet (and server) are both ready to open and process these encrypted envelopes.
// If GetKey() returns something, that means the key was set in there, it's
// not just a null pointer. This means we can use it! So let's encrypt to it.
if (m_pPublicKey->IsPublic())
{
OTString strEnvelopeContents(theReply);
// Save the ready-to-go message into a string.
OTEnvelope theEnvelope;
// Seal the string up into an encrypted Envelope
theEnvelope.Seal(*m_pPublicKey, strEnvelopeContents);
// From here on out, theMessage is disposable. OTPayload takes over.
// OTMessage doesn't care about checksums and headers.
thePayload.SetEnvelope(theEnvelope);
// Now that the payload is ready, we'll set up the header.
SetupHeader(&theCMD, CMD_TYPE_1, TYPE_1_CMD_2, thePayload);
}
else
{
thePayload.SetMessage(theReply);
// Now that the payload is ready, we'll set up the header.
SetupHeader(&theCMD, CMD_TYPE_1, TYPE_1_CMD_1, thePayload);
}
bSendCommand = true;
bSendPayload = true;
OTLog::vOutput(2, "\n****************************************************************\n"
"===> Finished setting up header for response.\nFirst 9 bytes are: %d %d %d %d %d %d %d %d %d...\n",
theCMD.buf[0], theCMD.buf[1], theCMD.buf[2], theCMD.buf[3], theCMD.buf[4],
theCMD.buf[5], theCMD.buf[6], theCMD.buf[7], theCMD.buf[8]);
// ------------------------------------------------------------------------------
/*
// Write to Client
strcpy(buffer, "Hello Client!");
SFSocketWrite(clientSocket, buffer, strlen(buffer));
*/
if (bSendCommand)
{
const unsigned int nHeaderSize = OT_CMD_HEADER_SIZE;
for (nwritten = 0; nwritten < nHeaderSize; nwritten += err)
{
// err = SFSocketWrite(m_pSocket, theCMD.buf + nwritten, nHeaderSize - nwritten);
#ifdef _WIN32
if (0 == err || SOCKET_ERROR == err) // 0 means disconnect. error means error. >0 means bytes read.
#else
if (err <= 0)
#endif
break;
}
}
// At this point, we have sent the header across the pipe.
if (bSendPayload)
{
uint32_t nPayloadSize = thePayload.GetSize();
for (nwritten = 0; nwritten < nPayloadSize; nwritten += err)
{
// err = SFSocketWrite(m_pSocket, (unsigned char *)thePayload.GetPayloadPointer() + nwritten, nPayloadSize - nwritten);
#ifdef _WIN32
if (0 == err || SOCKET_ERROR == err) // 0 means disconnect. error means error. >0 means bytes read.
//.........这里部分代码省略.........
示例8: Seal_or_Encrypt
bool OTNym_or_SymmetricKey::Seal_or_Encrypt( OTEnvelope & outputEnvelope,
const OTString strInput,
const OTString * pstrDisplay/*=NULL*/)
{
const char * szFunc = "OTNym_or_SymmetricKey::Seal_or_Encrypt";
// --------------------------
bool bSuccess = false;
bool bHadToInstantiatePassword = false;
// ---------------
// Encrypt/Seal strInput into outputEnvelope
//
if (this->IsNym())
{
bSuccess = outputEnvelope.Seal(*(this->GetNym()), strInput);
}
// -------------------------------------------
else if (this->IsKey())
{
OTPassword * pPassword = NULL;
if (this->HasPassword()) // Password is already available. Let's use it.
pPassword = this->GetPassword();
else // no password? let's collect it from the user...
{
const OTString strDisplay((NULL == pstrDisplay) ? szFunc : pstrDisplay->Get());
// NOTE: m_pstrDisplay overrides this below.
// -------------------------------------------
// returns a text OTPassword, or NULL.
//
pPassword = OTSymmetricKey::GetPassphraseFromUser((NULL == m_pstrDisplay) ? &strDisplay : m_pstrDisplay);//bool bAskTwice=false
if (NULL == pPassword) // Unable to retrieve passphrase from user.
{
OTLog::vOutput(0, "%s: Failed trying to retrieve passphrase for key. "
"Returning false.\n", szFunc);
return false;
}
else // OTNym_or_SymmetricKey stores this, if it creates it.
// (And cleans it up on destruction, IF it created it.)
//
bHadToInstantiatePassword = true;
}
// -------------------------------------------
//
bSuccess = outputEnvelope.Encrypt(strInput, *(this->GetKey()), *pPassword);
// We only set this, presuming we have to at all, if it was a success.
if (bHadToInstantiatePassword)
{
if (bSuccess)
{
m_bCleanupPassword = true;
m_pPassword = pPassword; // Not bothering to cleanup whatever was here before, since we only end up here if m_pPassword was set to NULL (according to above logic...)
}
else // We instantiated the password, but the encrypt failed. (Need to cleanup the password then.)
{
delete pPassword;
pPassword = NULL;
}
}
}
// else ? should never happen.
// -----------------------------------
return bSuccess;
}
示例9: ProcessToken
// Lucre step 4: client unblinds token -- now it's ready for use.
bool OTToken::ProcessToken(const OTPseudonym & theNym, OTMint & theMint, OTToken & theRequest)
{
// OTLog::vError("%s <bank public info> <private coin request> <signed coin request> <coin>\n",
bool bReturnValue = false;
// When the Mint has signed a token and sent it back to the client,
// the client must unblind the token and set it as spendable. Thus,
// this function is only performed on tokens in the signedToken state.
if (OTToken::signedToken != m_State)
{
OTLog::Error("Signed token expected in OTToken::ProcessToken\n");
return false;
}
// Lucre
SetDumper(stderr);
BIO *bioBank = BIO_new(BIO_s_mem()); // input
BIO *bioSignature = BIO_new(BIO_s_mem()); // input
BIO *bioPrivateRequest = BIO_new(BIO_s_mem()); // input
BIO *bioCoin = BIO_new(BIO_s_mem()); // output
// Get the bank's public key (decoded into strPublicMint)
// and put it into bioBank so we can use it with Lucre.
OTASCIIArmor ascPublicMint;
theMint.GetPublic(ascPublicMint, GetDenomination());
OTString strPublicMint(ascPublicMint);
BIO_puts(bioBank, strPublicMint.Get());
// Get the existing signature into a bio.
// OTLog::vError("DEBUGGING, m_Signature: -------------%s--------------\n", m_Signature.Get());
OTString strSignature(m_Signature);
BIO_puts(bioSignature, strSignature.Get());
// I need the Private coin request also. (Only the client has this private coin request data.)
OTASCIIArmor thePrototoken; // The server sets m_nChosenIndex when it signs the token.
bool bFoundToken = theRequest.GetPrivatePrototoken(thePrototoken, m_nChosenIndex);
if (bFoundToken)
{
// OTLog::vError("THE PRIVATE REQUEST ARMORED CONTENTS:\n------------------>%s<-----------------------\n",
// thePrototoken.Get());
// Decrypt the prototoken
OTString strPrototoken;
OTEnvelope theEnvelope(thePrototoken);
theEnvelope.Open(theNym, strPrototoken); // todo check return value.
// OTLog::vError("THE PRIVATE REQUEST CONTENTS:\n------------------>%s<-----------------------\n",
// strPrototoken.Get());
// copy strPrototoken to a BIO
BIO_puts(bioPrivateRequest, strPrototoken.Get());
// ------- Okay, the BIOs are all loaded.... let's process...
PublicBank bank(bioBank);
CoinRequest req(bioPrivateRequest);
// TODO make sure I'm not leaking memory with these ReadNumbers
// Probably need to be calling some free function for each one.
// Apparently reading the request id here and then just discarding it...
ReadNumber(bioSignature,"request=");
// Versus the signature data, which is read into bnSignature apparently.
BIGNUM * bnSignature = ReadNumber(bioSignature,"signature=");
DumpNumber("signature=", bnSignature);
// Produce the final unblinded token in Coin coin, and write it to bioCoin...
Coin coin; // Coin Request, processes into Coin, with Bank and Signature passed in.
req.ProcessResponse(&coin, bank, bnSignature); // Notice still apparently "request" info is discarded.
coin.WriteBIO(bioCoin);
// convert bioCoin to a C-style string...
char CoinBuffer[1024]; // todo stop hardcoding these string lengths
int coinLen = BIO_read(bioCoin, CoinBuffer, 1000); // cutting it a little short on purpose, with the buffer. Just makes me feel more comfortable for some reason.
if (coinLen)
{
// ...to OTString...
OTString strCoin;
strCoin.Set(CoinBuffer, coinLen);
// OTLog::vError("Processing token...\n%s\n", strCoin.Get());
// ...to Envelope stored in m_ascSpendable (encrypted and base64-encoded)
OTEnvelope theEnvelope;
theEnvelope.Seal(theNym, strCoin); // Todo check the return values on these two functions
theEnvelope.GetAsciiArmoredData(m_ascSpendable); // Here's the final product.
// OTLog::vError("NEW SPENDABLE token...\n--------->%s<----------------\n", m_ascSpendable.Get());
// Now the coin is encrypted from here on out, and otherwise ready-to-spend.
m_State = OTToken::spendableToken;
bReturnValue = true;
// Lastly, we free the signature data, which is no longer needed, and which could be
// otherwise used to trace the token. (Which we don't want.)
m_Signature.Release();
//.........这里部分代码省略.........
示例10: GenerateTokenRequest
// Lucre step 2 (client generates coin request)
// nDenomination must be one of the denominations supported by the mint.
// sets m_nTokenCount and populates the maps with prototokens (in ASCII-armored format.)
bool OTToken::GenerateTokenRequest(const OTPseudonym & theNym, OTMint & theMint,
long lDenomination, int nTokenCount/*=OTToken::nMinimumPrototokenCount*/)
{
// OTLog::vError("%s <bank public info> <coin request private output file> <coin request public output file>\n", argv[0]);
if (OTToken::blankToken != m_State)
{
OTLog::Error("Blank token expected in OTToken::GenerateTokenRequest\n");
return false;
}
// We are supposed to set these values here.
// The server actually sets them again, for security reasons.
// But we should still set them since server may choose to reject the request.
SetSeriesAndExpiration(theMint.GetSeries(), theMint.GetValidFrom(), theMint.GetValidTo());
SetDumper(stderr);
BIO *bioBank = BIO_new(BIO_s_mem()); // Input. We must supply the bank's public lucre info
BIO *bioCoin = BIO_new(BIO_s_mem()); // These two are output. We must write these bios, after
BIO *bioPublicCoin = BIO_new(BIO_s_mem()); // the operation, back into some form we can use
// This version base64-DECODES the ascii-armored string passed in,
// and then sets the decoded plaintext string onto the string.
//OTString::OTString(const OTASCIIArmor & strValue)
OTASCIIArmor ascPublicMint;
theMint.GetPublic(ascPublicMint, lDenomination);
// OTLog::vError("DEBUG: OTToken public asc: \n%s\n", ascPublicMint.Get());
OTString strPublicMint(ascPublicMint);
// OTLog::vError("DEBUG: OTToken public str: \n%s\n", strPublicMint.Get());
// Get the bank's public key (now decoded in strPublicMint)
// and put it into bioBank so we can use it with Lucre.
BIO_puts(bioBank, strPublicMint.Get());
// Instantiate a PublicBank (Lucre) object.
// We will use it to generate all the prototokens in the loop below.
PublicBank bank;
bank.ReadBIO(bioBank);
Release();
const int nFinalTokenCount = (nTokenCount < OTToken::nMinimumPrototokenCount) ?
OTToken::nMinimumPrototokenCount : nTokenCount;
// Token count is actually 1 (always) with Lucre, although this lib has potential to work with
// multiple proto-tokens, you can see this loop as though it always executes just once.
for (int i = 0; i < nFinalTokenCount; i++)
{
CoinRequest req(bank);
// write the private coin request to BIO
req.WriteBIO(bioCoin);
// write the public coin request to BIO
((PublicCoinRequest *)&req)->WriteBIO(bioPublicCoin);
// Convert the two bios to our format
char privateCoinBuffer[4096], publicCoinBuffer[4096]; // todo stop hardcoding these string lengths
int privatecoinLen = BIO_read(bioCoin, privateCoinBuffer, 4000); // cutting it a little short on purpose, with the buffer. Just makes me feel more comfortable for some reason.
int publiccoinLen = BIO_read(bioPublicCoin, publicCoinBuffer, 4000);
if (privatecoinLen && publiccoinLen)
{
// With this, we have the Lucre public and private bank info converted to OTStrings
OTString strPublicCoin; strPublicCoin.Set(publicCoinBuffer, publiccoinLen);
OTString strPrivateCoin; strPrivateCoin.Set(privateCoinBuffer, privatecoinLen);
OTASCIIArmor * pArmoredPublic = new OTASCIIArmor(strPublicCoin);
OTASCIIArmor * pArmoredPrivate = new OTASCIIArmor();
OT_ASSERT_MSG(((NULL != pArmoredPublic) && (NULL != pArmoredPrivate)), "ERROR: Unable to allocate memory in OTToken::GenerateTokenRequest\n");
// Change the state. It's no longer a blank token, but a prototoken.
m_State = OTToken::protoToken;
// Seal the private coin info up into an encrypted Envelope
// and set it onto pArmoredPrivate (which was just added to our internal map, above.)
OTEnvelope theEnvelope;
theEnvelope.Seal(theNym, strPrivateCoin); // Todo check the return values on these two functions
theEnvelope.GetAsciiArmoredData(*pArmoredPrivate);
m_mapPublic[i] = pArmoredPublic;
m_mapPrivate[i] = pArmoredPrivate;
m_nTokenCount = nFinalTokenCount;
SetDenomination(lDenomination);
}
else {
// Error condition
}
//.........这里部分代码省略.........