From 6f2f058cd8997020c672d9c1ac11814cb5a18b00 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 27 Apr 2012 11:48:32 -0700 Subject: [PATCH 1/3] Derive Serialized ledger and transaction classes from SerializedType, not STObject. --- src/SerializedLedger.cpp | 6 +++--- src/SerializedLedger.h | 2 +- src/SerializedTransaction.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SerializedLedger.cpp b/src/SerializedLedger.cpp index 7cf36ed7e..4a566542a 100644 --- a/src/SerializedLedger.cpp +++ b/src/SerializedLedger.cpp @@ -2,7 +2,7 @@ #include "SerializedLedger.h" SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index) - : STObject("LedgerEntry"), mIndex(index) + : SerializedType("LedgerEntry"), mIndex(index) { uint16 type = sit.get16(); mFormat = getLgrFormat(static_cast(type)); @@ -13,7 +13,7 @@ SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint } SerializedLedgerEntry::SerializedLedgerEntry(const Serializer& s, const uint256& index) - : STObject("LedgerEntry"), mIndex(index) + : SerializedType("LedgerEntry"), mIndex(index) { SerializerIterator sit(s); @@ -25,7 +25,7 @@ SerializedLedgerEntry::SerializedLedgerEntry(const Serializer& s, const uint256& mObject = STObject(mFormat->elements, sit); } -SerializedLedgerEntry::SerializedLedgerEntry(LedgerEntryType type) : STObject("LedgerEntry"), mType(type) +SerializedLedgerEntry::SerializedLedgerEntry(LedgerEntryType type) : SerializedType("LedgerEntry"), mType(type) { mFormat = getLgrFormat(type); if (mFormat == NULL) throw std::runtime_error("invalid ledger entry type"); diff --git a/src/SerializedLedger.h b/src/SerializedLedger.h index a87cb360c..628e6640f 100644 --- a/src/SerializedLedger.h +++ b/src/SerializedLedger.h @@ -5,7 +5,7 @@ #include "LedgerFormats.h" #include "NewcoinAddress.h" -class SerializedLedgerEntry : public STObject +class SerializedLedgerEntry : public SerializedType { public: typedef boost::shared_ptr pointer; diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h index fe6609518..d4ac9f035 100644 --- a/src/SerializedTransaction.h +++ b/src/SerializedTransaction.h @@ -10,7 +10,7 @@ #include "TransactionFormats.h" #include "NewcoinAddress.h" -class SerializedTransaction : public STObject +class SerializedTransaction : public SerializedType { public: typedef boost::shared_ptr pointer; From 3e6014dcf58f6f1d7c5512355b8c33a4f94428c6 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 27 Apr 2012 11:48:59 -0700 Subject: [PATCH 2/3] Bugfix. --- src/Transaction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 15278c8ea..7f63e9de2 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -125,8 +125,8 @@ Transaction::Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toI mTransaction->makeITFieldPresent(sfSourceTag); mTransaction->setITFieldU32(sfSourceTag, ident); } - mTransaction->setValueFieldU64(sfAmount, amount); - mTransaction->setValueFieldAccount(sfDestination, toID.getAccountID()); + mTransaction->setITFieldU64(sfAmount, amount); + mTransaction->setITFieldAccount(sfDestination, toID.getAccountID()); updateID(); } From daf696042d55a3863b6cbf9210ab9eaaa33b29dd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sat, 28 Apr 2012 17:40:40 -0700 Subject: [PATCH 3/3] Peer::getSessionCookie --- src/Peer.cpp | 21 +++++++++++++++++++++ src/Peer.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/Peer.cpp b/src/Peer.cpp index c248dd41b..e65dc147b 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -665,6 +665,27 @@ void Peer::recvLedger(newcoin::TMLedgerData& packet) punishPeer(PP_UNWANTED_DATA); } +std::vector Peer::getSessionCookie() +{ + // get session information we can sign + // (both sides get the same information, neither side controls it) + SSL* ssl = mSocketSsl.native_handle(); + if (!ssl) throw std::runtime_error("No underlying connection"); + + // Get both finished messages + unsigned char s1[1024], s2[1024]; + int l1 = SSL_get_finished(ssl, s1, 1024); + int l2 = SSL_get_finished(ssl, s2, 1024); + if ((l1 < 16) || (l2 < 16)) throw std::runtime_error("Connection setup not complete"); + + // Hash them and XOR the results + unsigned char sha1[32], sha2[32]; + SHA512(s1, l1, sha1); + SHA512(s2, l2, sha2); + for(int i=0; i<32; i++) sha1[i]^=sha2[i]; + return std::vector(sha1, sha1+33); +} + void Peer::sendHello() { // XXX Start timer for hello required by. diff --git a/src/Peer.h b/src/Peer.h index 7e943e286..d8ac6e087 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -78,6 +78,8 @@ protected: void recvGetLedger(newcoin::TMGetLedger& packet); void recvLedger(newcoin::TMLedgerData& packet); + std::vector getSessionCookie(); + public: typedef boost::shared_ptr pointer;