bool oAuth::getEtradeHeader( const eOAuthHttpRequestType eType, /* in */ const std::string& rawUrl, /* in */ const std::string& rawData, /* in */ std::string& oAuthHttpHeader, /* out */ const bool includeOAuthVerifierPin, /* in */ const bool includeOAuthTokenPin /* in */ ) { bool b_return = getOAuthHeader( eType, rawUrl, rawData, oAuthHttpHeader, includeOAuthVerifierPin ); // Build the header in the only field order that I know that works with E*Trade's API. Id10ts. if (includeOAuthVerifierPin) { oAuthHttpHeader = string("Authorization: OAuth oauth_nonce=\"") + getNonce() + "\",oauth_timestamp=\"" + getTimeStamp() + "\",oauth_consumer_key=\"" + getConsumerKey() + "\",oauth_token=\"" + m_oAuthTokenKey + "\",oauth_verifier=\"" + m_oAuthPin + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_signature=\"" + getOAuthSignature() + "\"\r\n"; } else if (includeOAuthTokenPin) { oAuthHttpHeader = string("Authorization: OAuth oauth_nonce=\"") + getNonce() + "\",oauth_timestamp=\"" + getTimeStamp() + "\",oauth_consumer_key=\"" + getConsumerKey() + "\",oauth_token=\"" + m_oAuthTokenKey + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_signature=\"" + getOAuthSignature() + "\"\r\n"; } else { oAuthHttpHeader = string("Authorization: OAuth oauth_nonce=\"") + getNonce() + "\",oauth_timestamp=\"" + getTimeStamp() + "\",oauth_consumer_key=\"" + getConsumerKey() + "\",oauth_callback=\"oob\",oauth_signature_method=\"HMAC-SHA1\",oauth_signature=\"" + getOAuthSignature() + "\"\r\n"; } return b_return; }
size_t Interest::wireEncode(EncodingImpl<TAG>& block) const { size_t totalLength = 0; // Interest ::= INTEREST-TYPE TLV-LENGTH // Name // Selectors? // Nonce // Scope? // InterestLifetime? // Link? // SelectedDelegation? // (reverse encoding) if (hasLink()) { if (hasSelectedDelegation()) { totalLength += prependNonNegativeIntegerBlock(block, tlv::SelectedDelegation, m_selectedDelegationIndex); } totalLength += prependBlock(block, m_link); } else { BOOST_ASSERT(!hasSelectedDelegation()); } // InterestLifetime if (getInterestLifetime() >= time::milliseconds::zero() && getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) { totalLength += prependNonNegativeIntegerBlock(block, tlv::InterestLifetime, getInterestLifetime().count()); } // Scope if (getScope() >= 0) { totalLength += prependNonNegativeIntegerBlock(block, tlv::Scope, getScope()); } // Nonce getNonce(); // to ensure that Nonce is properly set totalLength += block.prependBlock(m_nonce); // Selectors if (hasSelectors()) { totalLength += getSelectors().wireEncode(block); } // Name totalLength += getName().wireEncode(block); totalLength += block.prependVarNumber(totalLength); totalLength += block.prependVarNumber(tlv::Interest); return totalLength; }
bError_t btreeDispatch::finalize(bcb cb) { tid_t tid = getNonce(); transaction *trn = New transaction(tid, cb, OP_FINALIZE); cbTable.insert(tid, trn); return t->finalize(tid); }
bError_t btreeDispatch::iterate(bIteration *it, bcb cb) { tid_t tid = getNonce(); transaction *trn = New transaction(tid, cb, OP_ITERATE); cbTable.insert(tid, trn); return t->iterate(tid, it); }
bError_t btreeDispatch::remove(void *key, int len, bcb cb) { tid_t tid = getNonce(); transaction *trn = New transaction(tid, cb, OP_DELETE); cbTable.insert(tid, trn); return t->remove(tid, key, len); }
bError_t btreeDispatch::insert(void *key, int keyLen, void *value, int valueLen, bcb cb) { tid_t tid = getNonce(); transaction *trn = New transaction(tid, cb, OP_INSERT); cbTable.insert(tid, trn); return t->insert(tid, key, keyLen, value, valueLen); }
bError_t btreeDispatch::lookup(void *key, int len, bcb cb) { tid_t tid = getNonce(); transaction *trn = New transaction(tid, cb, OP_SEARCH); cbTable.insert(tid, trn); return t->search(tid, key, len); }
size_t Interest::encode03(EncodingImpl<TAG>& encoder) const { size_t totalLength = 0; // Encode as NDN Packet Format v0.3 // Interest ::= INTEREST-TYPE TLV-LENGTH // Name // CanBePrefix? // MustBeFresh? // ForwardingHint? // Nonce? // InterestLifetime? // HopLimit? // ApplicationParameters? // (reverse encoding) // ApplicationParameters if (hasApplicationParameters()) { totalLength += encoder.prependBlock(getApplicationParameters()); } // HopLimit: not yet supported // InterestLifetime if (getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) { totalLength += prependNonNegativeIntegerBlock(encoder, tlv::InterestLifetime, static_cast<uint64_t>(getInterestLifetime().count())); } // Nonce uint32_t nonce = getNonce(); // if nonce was unset, getNonce generates a random nonce totalLength += encoder.prependByteArrayBlock(tlv::Nonce, reinterpret_cast<uint8_t*>(&nonce), sizeof(nonce)); // ForwardingHint if (!getForwardingHint().empty()) { totalLength += getForwardingHint().wireEncode(encoder); } // MustBeFresh if (getMustBeFresh()) { totalLength += prependEmptyBlock(encoder, tlv::MustBeFresh); } // CanBePrefix if (getCanBePrefix()) { totalLength += prependEmptyBlock(encoder, tlv::CanBePrefix); } // Name totalLength += getName().wireEncode(encoder); totalLength += encoder.prependVarNumber(totalLength); totalLength += encoder.prependVarNumber(tlv::Interest); return totalLength; }
bool CJaiku::GetRequestToken( const char *consumerKey, const char *consumerSecret, CString &oauthToken, CString &oauthTokenSecret ) { bool ret = false; time_t t = time( NULL ); size_t sz = MAX_CONTENT_SIZE * 16; char base[MAX_CONTENT_SIZE]; char param[MAX_CONTENT_SIZE]; char nonce[MAX_KEYLENGTH]; char key[MAX_KEYLENGTH * 2]; char *request = new char[sz]; char *response = new char[sz]; CString targetURL = _T(""); targetURL.LoadString(IDS_URL_JAIKU_REQUEST_TOKEN); strcpy( nonce, getNonce(NULL) ); sprintf( key, "%s&", encodeURLi( consumerSecret, FALSE ) ); sprintf( base, "GET&" "%s&", encodeURLi( targetURL, FALSE ) ); sprintf( param, "oauth_consumer_key=%s&" "oauth_nonce=%s&" "oauth_signature_method=HMAC-SHA1&" "oauth_timestamp=%ld&" "oauth_version=1.0", consumerKey, nonce, t ); MakeOAuthRequest( targetURL, "GET", request, key, base, param ); SetUserAgent(); setUpReceiveBuffer( response, sz ); _http_getBASIC( request, NULL, NULL, response, NULL, NULL ); ret = GetToken( response, oauthToken, oauthTokenSecret ); delete [] response; delete [] request; return ( ret ); }
void Interest::refreshNonce() { if (!hasNonce()) return; uint32_t oldNonce = getNonce(); uint32_t newNonce = oldNonce; while (newNonce == oldNonce) newNonce = random::generateWord32(); setNonce(newNonce); }
void Interest::wireDecode(const Block& wire) { m_wire = wire; m_wire.parse(); if (m_wire.type() != tlv::Interest) { BOOST_THROW_EXCEPTION(Error("expecting Interest element, got " + to_string(m_wire.type()))); } if (!decode02()) { decode03(); if (!hasNonce()) { setNonce(getNonce()); } } }
void Interest::wireDecode(const Block& wire) { m_wire = wire; m_wire.parse(); if (m_wire.type() != tlv::Interest) { NDN_THROW(Error("Interest", m_wire.type())); } if (!decode02()) { decode03(); if (!hasNonce()) { setNonce(getNonce()); } } m_isCanBePrefixSet = true; // don't trigger warning from decoded packet }
size_t Interest::encode02(EncodingImpl<TAG>& encoder) const { size_t totalLength = 0; // Encode as NDN Packet Format v0.2 // Interest ::= INTEREST-TYPE TLV-LENGTH // Name // Selectors? // Nonce // InterestLifetime? // ForwardingHint? // (reverse encoding) // ForwardingHint if (getForwardingHint().size() > 0) { totalLength += getForwardingHint().wireEncode(encoder); } // InterestLifetime if (getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) { totalLength += prependNonNegativeIntegerBlock(encoder, tlv::InterestLifetime, static_cast<uint64_t>(getInterestLifetime().count())); } // Nonce uint32_t nonce = getNonce(); // if nonce was unset, getNonce generates a random nonce totalLength += encoder.prependByteArrayBlock(tlv::Nonce, reinterpret_cast<uint8_t*>(&nonce), sizeof(nonce)); // Selectors if (hasSelectors()) { totalLength += getSelectors().wireEncode(encoder); } // Name totalLength += getName().wireEncode(encoder); totalLength += encoder.prependVarNumber(totalLength); totalLength += encoder.prependVarNumber(tlv::Interest); return totalLength; }
void BlockHeader::pprint(ostream & os, int nIndent, bool pBigendian) const { string indent = ""; for(int i=0; i<nIndent; i++) indent = indent + " "; string endstr = (pBigendian ? " (BE)" : " (LE)"); os << indent << "Block Information: " << blockHeight_ << endl; os << indent << " Hash: " << getThisHash().toHexStr(pBigendian).c_str() << endstr << endl; os << indent << " Timestamp: " << getTimestamp() << endl; os << indent << " Prev Hash: " << getPrevHash().toHexStr(pBigendian).c_str() << endstr << endl; os << indent << " MerkleRoot: " << getMerkleRoot().toHexStr(pBigendian).c_str() << endstr << endl; os << indent << " Difficulty: " << (difficultyDbl_) << " (" << getDiffBits().toHexStr().c_str() << ")" << endl; os << indent << " CumulDiff: " << (difficultySum_) << endl; os << indent << " Nonce: " << getNonce() << endl; }
void CJaiku::MakeOAuthBase( const char *url, const char *method, char *key, char *base, char *param ) { CChirrupApp *ap = (CChirrupApp *)AfxGetApp(); time_t t = time( NULL ); char nonce[MAX_KEYLENGTH]; strcpy( nonce, getNonce(NULL) ); sprintf( key, "%s&", encodeURLi( ap->m_jcSecret, FALSE ) ); sprintf( key + strlen(key), "%s", encodeURLi( m_oauthTokenSecret, FALSE ) ); sprintf( base, "%s&" "%s&", method, encodeURLi( url, FALSE ) ); sprintf( param[0] ? param + strlen(param) : param, "oauth_consumer_key=%s&" "oauth_nonce=%s&" "oauth_signature_method=HMAC-SHA1&" "oauth_timestamp=%ld&" "oauth_token=%s&" "oauth_version=1.0", ap->m_jcKey, nonce, t, m_oauthToken ); }
bool CJaiku::GetAccessToken( const char *consumerKey, const char *consumerSecret, CString &oauthToken, CString &oauthTokenSecret ) { bool ret = false; if ( !consumerKey || !(*consumerKey) || !consumerSecret || !(*consumerSecret) ) return ( ret ); // request token 取得 CString _oauthToken = _T(""); CString _oauthTokenSecret = _T(""); if ( !GetRequestToken( consumerKey, consumerSecret, _oauthToken, _oauthTokenSecret ) ) { MessageBox( NULL, "リクエストトークンの取得に失敗しました。 ", "アクセス中止", MB_OK|MB_ICONERROR ); return ( ret ); } // ブラウザ起動 -- ユーザにアクセス許可を求める CString targetURL = _T(""); targetURL.LoadString(IDS_URL_JAIKU_AUTHORIZE); char url[MAX_URLLENGTH]; sprintf( url, "%s?" "oauth_token=%s&" "perms=%s", targetURL, _oauthToken, "write" ); ShellExecute( NULL, "open", url, NULL, NULL, SW_SHOWNORMAL ); // ユーザの許可待ち int r = MessageBox( NULL, "Chirrup が Jaiku にアクセスする許可を与えてください。\r\n" "許可を与え終わったら、OK ボタンを押してください。\r\n" "許可を与えたくない場合は キャンセル ボタンを押してください。 ", "Jaiku へのアクセス許可", MB_OKCANCEL|MB_ICONINFORMATION ); if ( r != IDOK ) { MessageBox( NULL, "Jaiku へのアクセスを中止します。 ", "アクセス中止", MB_OK|MB_ICONWARNING ); return ( ret ); } // access token 取得 time_t t = time( NULL ); size_t sz = MAX_CONTENT_SIZE * 16; char base[MAX_CONTENT_SIZE]; char param[MAX_CONTENT_SIZE]; char nonce[MAX_KEYLENGTH]; char key[MAX_KEYLENGTH * 2]; char *request = new char[sz]; char *response = new char[sz]; targetURL = _T(""); targetURL.LoadString(IDS_URL_JAIKU_ACCESS_TOKEN); strcpy( nonce, getNonce(NULL) ); sprintf( key, "%s&", encodeURLi( consumerSecret, FALSE ) ); sprintf( key + strlen(key), "%s", encodeURLi( _oauthTokenSecret, FALSE ) ); sprintf( base, "GET&" "%s&", encodeURLi( targetURL, FALSE ) ); sprintf( param, "oauth_consumer_key=%s&" "oauth_nonce=%s&" "oauth_signature_method=HMAC-SHA1&" "oauth_timestamp=%ld&" "oauth_token=%s&" "oauth_version=1.0", consumerKey, nonce, t, _oauthToken ); MakeOAuthRequest( targetURL, "GET", request, key, base, param ); SetUserAgent(); setUpReceiveBuffer( response, sz ); _http_getBASIC( request, NULL, NULL, response, NULL, NULL ); ret = GetToken( response, oauthToken, oauthTokenSecret ); if ( ret ) { m_oauthToken = oauthToken; m_oauthTokenSecret = oauthTokenSecret; } else MessageBox( NULL, "アクセストークンの取得に失敗しました。 ", "アクセス中止", MB_OK|MB_ICONERROR ); delete [] response; delete [] request; return ( ret ); }