Example #1
0
/*
** Save / Load complete list of event definitions for all assets
*/
void CEventDefList::Serialize(CArchive & ar)
{
	if (ar.IsStoring())
	{
		// write the signature string at the top
		CString strSignature(EVENT_SIG);
		ar << strSignature;

		// then the count of items
		DWORD dwCount = GetCount();
		ar << dwCount;
		
		// then each item
		for (DWORD dwItem = 0 ; dwItem < GetCount() ; dwItem++)
			m_pData[dwItem].Serialize(ar);
	}
	else
	{
		// reading from disk - empty any current data
		Empty();

		// validate the signature string
		CString strTest;
		try
		{
			ar >> strTest;
		}
		catch (CException * pE)
		{
			pE->Delete();
			return;
		}
		
		// if signature invalid or doesn't match then don't read any further - leave list empty
		if (strTest != EVENT_SIG)
			return;

		// all is well - read record count
		DWORD dwCount;
		ar >> dwCount;
		
		// then read and add each item
		for (DWORD dwItem = 0 ; dwItem < dwCount ; dwItem++)
		{
			CEventDef rdTemp;
			rdTemp.Serialize(ar);
			Add(rdTemp);
		}
	}
}
/// Encodes identity info
void SipXauthIdentity::encode(UtlString        & identityValue,
                              const UtlString  & callId,
                              const UtlString  & fromTag,
                              const OsDateTime & timestamp,
                              DialogRule       bindRule
                              )
{

   // calculate timestamp
   OsTime osTime;
   timestamp.cvtToTimeSinceEpoch(osTime);
   long seconds = osTime.seconds();
   char stamp[65];
   sprintf(stamp, "%lX", seconds);
   UtlString strSignature(stamp);

   strSignature.append(SignatureFieldSeparator);

   // signature-hash=MD5(<timestamp><secret><from-tag><call-id><identity>)
   NetMd5Codec signatureHash;
   signatureHash.hash(stamp);
   signatureHash.hash(sSignatureSecret);
   if (requireDialogBinding == bindRule)
   {
      signatureHash.hash(fromTag);
      signatureHash.hash(callId);
   }
   else
   {
      strSignature.append(SignatureFieldSeparator);
   }
   signatureHash.hash(mIdentity);

   UtlString strSignatureHash;
   signatureHash.appendHashValue(strSignature);

   Url encodedUrl(mIdentity);
   encodedUrl.setScheme(Url::SipUrlScheme);
   encodedUrl.setUrlParameter(SignatureUrlParamName, strSignature.data());

   encodedUrl.toString(identityValue);

   Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                 "SipXauthIdentity::encode "
                 "identity '%s'",
                 identityValue.data()
                 );
}
void Java_com_seastar_spg_Interface_GameSDK_onGooglePayCb(JNIEnv *env, jclass obj, jint flags, jstring sku,
		jstring itemType, jstring googleOrder, jstring signature, jstring purchaseOriginalData)
{
	if (flags)
	{
		std::string strSku("");
		std::string strItemType("");
		std::string strGoogleOrder("");
		std::string strSignature("");
		std::string strPurchaseOriginalData("");

		const char *pszSku = env->GetStringUTFChars(sku, NULL);
		const char *pszItemType = env->GetStringUTFChars(itemType, NULL);
		const char *pszGoogleOrder = env->GetStringUTFChars(googleOrder, NULL);
		const char *pszSignature = env->GetStringUTFChars(signature, NULL);
		const char *pszPurchaseOriginalData = env->GetStringUTFChars(purchaseOriginalData, NULL);

		strSku = pszSku;
		strItemType = pszItemType;
		strGoogleOrder = pszGoogleOrder;
		strSignature = pszSignature;
		strPurchaseOriginalData = pszPurchaseOriginalData;

		env->ReleaseStringUTFChars(sku, pszSku);
		env->ReleaseStringUTFChars(itemType, pszItemType);
		env->ReleaseStringUTFChars(googleOrder, pszGoogleOrder);
		env->ReleaseStringUTFChars(signature, pszSignature);
		env->ReleaseStringUTFChars(purchaseOriginalData, pszPurchaseOriginalData);

		// pay success proc
	}
	else
	{
		// pay failure proc
	}
}
// Lucre step 3: the mint signs the token
// 
bool OTMint_Lucre::SignToken(OTPseudonym & theNotary, OTToken & theToken, OTString & theOutput, int32_t nTokenIndex)
{
	bool bReturnValue = false;
	
	//OTLog::Error("%s <bank file> <coin request> <coin signature> [<signature repeats>]\n",
    _OT_Lucre_Dumper setDumper;
	
//	OTLog::vError("OTMint::SignToken!!\nnTokenIndex: %d\n Denomination: %lld\n", nTokenIndex, theToken.GetDenomination());
	
    OpenSSL_BIO bioBank		= BIO_new(BIO_s_mem()); // input
    OpenSSL_BIO bioRequest		= BIO_new(BIO_s_mem()); // input
    OpenSSL_BIO bioSignature	= BIO_new(BIO_s_mem()); // output
	
	OTASCIIArmor thePrivate;
	GetPrivate(thePrivate, theToken.GetDenomination());
	
	// The Mint private info is encrypted in m_mapPrivates[theToken.GetDenomination()]. 
	// So I need to extract that first before I can use it.
	OTEnvelope theEnvelope(thePrivate);

	OTString strContents; // output from opening the envelope.
	// Decrypt the Envelope into strContents    
	if (!theEnvelope.Open(theNotary, strContents))
		return false;

	// copy strContents to a BIO
	BIO_puts(bioBank, strContents.Get());
	
//	OTLog::vError("BANK CONTENTS:\n%s--------------------------------------\n", strContents.Get());
	
	// Instantiate the Bank with its private key
    Bank bank(bioBank);
//	OTLog::vError("BANK INSTANTIATED.--------------------------------------\n");

	// I need the request. the prototoken.
	OTASCIIArmor ascPrototoken;
	bool bFoundToken = theToken.GetPrototoken(ascPrototoken, nTokenIndex);
	
	if (bFoundToken)
	{
		// base64-Decode the prototoken
		OTString strPrototoken(ascPrototoken);
		
//		OTLog::vError("\n--------------------------------------\nDEBUG:  PROTOTOKEN CONTENTS:\n"
//				"-----------------%s---------------------\n", strPrototoken.Get() );
		
		// copy strPrototoken to a BIO
		BIO_puts(bioRequest, strPrototoken.Get());

		// Load up the coin request from the bio (the prototoken)
		PublicCoinRequest req(bioRequest);
//		OTLog::Error("PROTOTOKEN INSTANTIATED.--------------------------------------\n");

		// Sign it with the bank we previously instantiated.
		// results will be in bnSignature (BIGNUM)
		BIGNUM * bnSignature = bank.SignRequest(req);

		if (NULL == bnSignature)
		{
			OTLog::Error("MAJOR ERROR!: Bank.SignRequest failed in OTMint_Lucre::SignToken\n");
		}
		
		else 
		{
//			OTLog::Error("BANK.SIGNREQUEST SUCCESSFUL.--------------------------------------\n");

			// Write the request contents, followed by the signature contents,
			// to the Signature bio. Then free the BIGNUM.
			req.WriteBIO(bioSignature); // the original request contents
			DumpNumber(bioSignature,"signature=", bnSignature); // the new signature contents
			BN_free(bnSignature);

			// Read the signature bio into a C-style buffer...
			char sig_buf[1024];   // todo stop hardcoding these string lengths
//			memset(sig_buf, 0, 1024); // zero it out. (I had this commented out, but the size was 2048, so maybe it's safe now at 1024.)
			
			int32_t sig_len	= BIO_read(bioSignature, sig_buf, 1000); // cutting it a little short on purpose, with the buffer. Just makes me feel more comfortable for some reason.
			
			
			// Add the null terminator by hand (just in case.)
			sig_buf[sig_len]	= '\0';
			
			if (sig_len)
			{ // ***********************************************
//				OTLog::vError("\n--------------------------------------\n"
//						"*** Siglen is %d. sig_str_len is %d.\nsig buf:\n------------%s------------\nLAST "
//						"CHARACTER IS '%c'  SECOND TO LAST CHARACTER IS '%c'\n", 
//						sig_len, sig_str_len, sig_buf, sig_buf[sig_str_len-1], sig_buf[sig_str_len-2]);
				
				// Copy the original coin request into the spendable field of the token object.
				// (It won't actually be spendable until the client processes it, though.)
				theToken.SetSpendable(ascPrototoken);
				
//				OTLog::vError("*** SPENDABLE:\n-----------%s---------------------\n", ascPrototoken.Get());
						
						
				// Base64-encode the signature contents into theToken.m_Signature.
				OTString	strSignature(sig_buf);
	//			strSignature.Set(sig_buf, sig_len-1); // sig_len includes null terminator, whereas Set() adds 1 for it.
				
//				OTLog::vError("SIGNATURE:\n--------------------%s"
//						"------------------\n", strSignature.Get());

				// Here we pass the signature back to the caller.
				// He will probably set it onto the token.
				theOutput.Set(sig_buf, sig_len);
				bReturnValue = true;
				
				// This is also where we set the expiration date on the token.
				// The client should have already done this, but we are explicitly
				// setting the values here to prevent any funny business.
				theToken.SetSeriesAndExpiration(m_nSeries, m_VALID_FROM, m_VALID_TO);
			}
		}
	}

	return bReturnValue;
}