Skip to content

Commit

Permalink
restyle and security improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sarcoin committed Dec 20, 2015
1 parent a14e548 commit 7cb9a78
Show file tree
Hide file tree
Showing 668 changed files with 6,735 additions and 94,530 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Expand Up @@ -41,3 +41,11 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk

# Qt
*.user
*.user.*
*.*.pro

# Temp files
*~
24 changes: 2 additions & 22 deletions sarcoin.pro
Expand Up @@ -3,6 +3,7 @@ TARGET = SARCoin-qt
VERSION = 1.0.0
INCLUDEPATH += src src/json src/qt
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE HAVE_CXX_STDHEADERS MINIUPNP_STATICLIB
DEFINES += ENABLE_WALLET
CONFIG += no_include_pwd
CONFIG += thread
CONFIG += static
Expand Down Expand Up @@ -196,17 +197,6 @@ HEADERS += src/qt/bitcoingui.h \
src/kernel.h \
src/scrypt.h \
src/pbkdf2.h \
src/zerocoin/Accumulator.h \
src/zerocoin/AccumulatorProofOfKnowledge.h \
src/zerocoin/Coin.h \
src/zerocoin/CoinSpend.h \
src/zerocoin/Commitment.h \
src/zerocoin/ParamGeneration.h \
src/zerocoin/Params.h \
src/zerocoin/SerialNumberSignatureOfKnowledge.h \
src/zerocoin/SpendMetaData.h \
src/zerocoin/ZeroTest.h \
src/zerocoin/Zerocoin.h \
src/serialize.h \
src/strlcpy.h \
src/main.h \
Expand Down Expand Up @@ -349,16 +339,6 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/scrypt-x86_64.S \
src/scrypt.cpp \
src/pbkdf2.cpp \
src/zerocoin/Accumulator.cpp \
src/zerocoin/AccumulatorProofOfKnowledge.cpp \
src/zerocoin/Coin.cpp \
src/zerocoin/CoinSpend.cpp \
src/zerocoin/Commitment.cpp \
src/zerocoin/ParamGeneration.cpp \
src/zerocoin/Params.cpp \
src/zerocoin/SerialNumberSignatureOfKnowledge.cpp \
src/zerocoin/SpendMetaData.cpp \
src/zerocoin/ZeroTest.cpp

RESOURCES += \
src/qt/bitcoin.qrc
Expand Down Expand Up @@ -483,4 +463,4 @@ contains(RELEASE, 1) {

system($$QMAKE_LRELEASE -silent $$_PRO_FILE_)

include(./install.pri)
include(./install.pri)
4 changes: 2 additions & 2 deletions src/clientversion.h
Expand Up @@ -7,8 +7,8 @@

// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 1
#define CLIENT_VERSION_MINOR 3
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_MINOR 0
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_BUILD 0

// Converts the parameter X to a string after macro replacement on X has been performed.
Expand Down
13 changes: 0 additions & 13 deletions src/init.cpp
Expand Up @@ -10,7 +10,6 @@
#include "util.h"
#include "ui_interface.h"
#include "checkpoints.h"
#include "zerocoin/ZeroTest.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/convenience.hpp>
Expand Down Expand Up @@ -751,18 +750,6 @@ bool AppInit2()
return false;
}

// ********************************************************* Testing Zerocoin


if (GetBoolArg("-zerotest", false))
{
printf("\n=== ZeroCoin tests start ===\n");
Test_RunAllTests();
printf("=== ZeroCoin tests end ===\n\n");
}

// ********************************************************* Step 8: load wallet

uiInterface.InitMessage(_("Loading wallet..."));
printf("Loading wallet...\n");
nStart = GetTimeMillis();
Expand Down
51 changes: 47 additions & 4 deletions src/key.cpp
Expand Up @@ -389,13 +389,56 @@ bool CKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>& v
return false;
}

bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& vchSig)
bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& vchSigParam)
{
// -1 = error, 0 = bad sig, 1 = good
if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1)
// https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-July/009697.html
std::vector<unsigned char> vchSig(vchSigParam.begin(), vchSigParam.end());
if (vchSig.size() > 1 && vchSig[1] & 0x80)
{
unsigned char nLengthBytes = vchSig[1] & 0x7f;

if (vchSig.size() < 2 + nLengthBytes)
return false;

if (nLengthBytes > 4)
{
unsigned char nExtraBytes = nLengthBytes - 4;
for (unsigned char i = 0; i < nExtraBytes; i++)
if (vchSig[2 + i])
return false;
vchSig.erase(vchSig.begin() + 2, vchSig.begin() + 2 + nExtraBytes);
vchSig[1] = 0x80 | (nLengthBytes - nExtraBytes);
}
}

if (vchSig.empty())
return false;

return true;
// New versions of OpenSSL will reject non-canonical DER signatures. de/re-serialize first.
unsigned char *norm_der = NULL;
ECDSA_SIG *norm_sig = ECDSA_SIG_new();
const unsigned char* sigptr = &vchSig[0];
assert(norm_sig);
if (d2i_ECDSA_SIG(&norm_sig, &sigptr, vchSig.size()) == NULL)
{
/* As of OpenSSL 1.0.0p d2i_ECDSA_SIG frees and nulls the pointer on
* error. But OpenSSL's own use of this function redundantly frees the
* result. As ECDSA_SIG_free(NULL) is a no-op, and in the absence of a
* clear contract for the function behaving the same way is more
* conservative.
*/
ECDSA_SIG_free(norm_sig);
return false;
}
int derlen = i2d_ECDSA_SIG(norm_sig, &norm_der);
ECDSA_SIG_free(norm_sig);
if (derlen <= 0)
return false;

// -1 = error, 0 = bad sig, 1 = good
bool ret = ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), norm_der, derlen, pkey) == 1;
OPENSSL_free(norm_der);
return ret;
}

bool CKey::VerifyCompact(uint256 hash, const std::vector<unsigned char>& vchSig)
Expand Down
2 changes: 1 addition & 1 deletion src/key.h
Expand Up @@ -151,7 +151,7 @@ class CKey
// (the signature is a valid signature of the given data for that key)
bool SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig);

bool Verify(uint256 hash, const std::vector<unsigned char>& vchSig);
bool Verify(uint256 hash, const std::vector<unsigned char>& vchSigParam);

// Verify a compact signature
bool VerifyCompact(uint256 hash, const std::vector<unsigned char>& vchSig);
Expand Down
13 changes: 0 additions & 13 deletions src/leveldb-base/.gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions src/leveldb-base/AUTHORS

This file was deleted.

27 changes: 0 additions & 27 deletions src/leveldb-base/LICENSE

This file was deleted.

0 comments on commit 7cb9a78

Please sign in to comment.