Skip to content

Commit 96b1622

Browse files
author
Chris
committed
Improvement for OSX and Boost
Add support Boost 1.66 Add support for OpenSSL over 1.0.0. --with-unsupported-ssl
1 parent 492d6d4 commit 96b1622

File tree

6 files changed

+84
-52
lines changed

6 files changed

+84
-52
lines changed

configure.ac

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,10 @@ else
766766
fi
767767

768768
AC_CHECK_LIB([crypto],[RAND_egd],[],[
769-
AC_ARG_WITH([libressl],
770-
[AS_HELP_STRING([--with-libressl],[Build with system LibreSSL (default is no; DANGEROUS; NOT SUPPORTED)])],
771-
[AC_MSG_WARN([Detected LibreSSL: This is NOT supported, and may break consensus compatibility!])],
772-
[AC_MSG_ERROR([Detected LibreSSL: This is NOT supported, and may break consensus compatibility!])]
769+
AC_ARG_WITH([unsupported-ssl],
770+
[AS_HELP_STRING([--with-unsupported-ssl],[Build with system SSL (default is no; DANGEROUS; NOT SUPPORTED; You should use OpenSSL 1.0)])],
771+
[AC_MSG_WARN([Detected unsupported SSL version: This is NOT supported, and may break consensus compatibility!])],
772+
[AC_MSG_ERROR([Detected unsupported SSL version: This is NOT supported, and may break consensus compatibility!])]
773773
)
774774
])
775775

src/bitcloud-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Object CallRPC(const string& strMethod, const Array& params)
110110
// Connect to localhost
111111
bool fUseSSL = GetBoolArg("-rpcssl", false);
112112
asio::io_service io_service;
113-
ssl::context context(io_service, ssl::context::sslv23);
113+
ssl::context context(ssl::context::sslv23);
114114
context.set_options(ssl::context::no_sslv2 | ssl::context::no_sslv3);
115115
asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context);
116116
SSLIOStreamDevice<asio::ip::tcp> d(sslStream, fUseSSL);

src/crypter.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned
5757
int nCLen = nLen + AES_BLOCK_SIZE, nFLen = 0;
5858
vchCiphertext = std::vector<unsigned char>(nCLen);
5959

60-
EVP_CIPHER_CTX ctx;
61-
6260
bool fOk = true;
6361

64-
EVP_CIPHER_CTX_init(&ctx);
65-
if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
66-
if (fOk) fOk = EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen) != 0;
67-
if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0]) + nCLen, &nFLen) != 0;
68-
EVP_CIPHER_CTX_cleanup(&ctx);
62+
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
63+
if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
64+
if (fOk) fOk = EVP_EncryptUpdate(ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen) != 0;
65+
if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (&vchCiphertext[0]) + nCLen, &nFLen) != 0;
66+
EVP_CIPHER_CTX_free(ctx);
6967

7068
if (!fOk) return false;
7169

@@ -84,15 +82,13 @@ bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingM
8482

8583
vchPlaintext = CKeyingMaterial(nPLen);
8684

87-
EVP_CIPHER_CTX ctx;
88-
8985
bool fOk = true;
9086

91-
EVP_CIPHER_CTX_init(&ctx);
92-
if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
93-
if (fOk) fOk = EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen) != 0;
94-
if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0]) + nPLen, &nFLen) != 0;
95-
EVP_CIPHER_CTX_cleanup(&ctx);
87+
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
88+
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
89+
if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen) != 0;
90+
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0]) + nPLen, &nFLen) != 0;
91+
EVP_CIPHER_CTX_free(ctx);
9692

9793
if (!fOk) return false;
9894

@@ -131,15 +127,15 @@ bool EncryptAES256(const SecureString& sKey, const SecureString& sPlaintext, con
131127
sCiphertext.resize(nCLen);
132128

133129
// Perform the encryption
134-
EVP_CIPHER_CTX ctx;
130+
EVP_CIPHER_CTX* ctx;
135131

136132
bool fOk = true;
137133

138-
EVP_CIPHER_CTX_init(&ctx);
139-
if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, (const unsigned char*)&sKey[0], (const unsigned char*)&sIV[0]);
140-
if (fOk) fOk = EVP_EncryptUpdate(&ctx, (unsigned char*)&sCiphertext[0], &nCLen, (const unsigned char*)&sPlaintext[0], nLen);
141-
if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (unsigned char*)(&sCiphertext[0]) + nCLen, &nFLen);
142-
EVP_CIPHER_CTX_cleanup(&ctx);
134+
ctx = EVP_CIPHER_CTX_new();
135+
if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, (const unsigned char*)&sKey[0], (const unsigned char*)&sIV[0]);
136+
if (fOk) fOk = EVP_EncryptUpdate(ctx, (unsigned char*)&sCiphertext[0], &nCLen, (const unsigned char*)&sPlaintext[0], nLen);
137+
if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (unsigned char*)(&sCiphertext[0]) + nCLen, &nFLen);
138+
EVP_CIPHER_CTX_free(ctx);
143139

144140
if (!fOk) return false;
145141

@@ -172,15 +168,15 @@ bool DecryptAES256(const SecureString& sKey, const std::string& sCiphertext, con
172168

173169
sPlaintext.resize(nPLen);
174170

175-
EVP_CIPHER_CTX ctx;
171+
EVP_CIPHER_CTX* ctx;
176172

177173
bool fOk = true;
178174

179-
EVP_CIPHER_CTX_init(&ctx);
180-
if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, (const unsigned char*)&sKey[0], (const unsigned char*)&sIV[0]);
181-
if (fOk) fOk = EVP_DecryptUpdate(&ctx, (unsigned char*)&sPlaintext[0], &nPLen, (const unsigned char*)&sCiphertext[0], nLen);
182-
if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (unsigned char*)(&sPlaintext[0]) + nPLen, &nFLen);
183-
EVP_CIPHER_CTX_cleanup(&ctx);
175+
ctx = EVP_CIPHER_CTX_new();
176+
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, (const unsigned char*)&sKey[0], (const unsigned char*)&sIV[0]);
177+
if (fOk) fOk = EVP_DecryptUpdate(ctx, (unsigned char*)&sPlaintext[0], &nPLen, (const unsigned char*)&sCiphertext[0], nLen);
178+
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (unsigned char*)(&sPlaintext[0]) + nPLen, &nFLen);
179+
EVP_CIPHER_CTX_free(ctx);
184180

185181
if (!fOk) return false;
186182

src/ecwrapper.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY* eckey, ECDSA_SIG* ecsig, const unsigned ch
3939
int n = 0;
4040
int i = recid / 2;
4141

42+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
43+
const BIGNUM *sig_r, *sig_s;
44+
ECDSA_SIG_get0(ecsig, &sig_r, &sig_s);
45+
#endif
46+
4247
const EC_GROUP* group = EC_KEY_get0_group(eckey);
4348
if ((ctx = BN_CTX_new()) == NULL) {
4449
ret = -1;
@@ -59,7 +64,11 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY* eckey, ECDSA_SIG* ecsig, const unsigned ch
5964
ret = -1;
6065
goto err;
6166
}
67+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
68+
if (!BN_add(x, x, sig_r)) {
69+
#else
6270
if (!BN_add(x, x, ecsig->r)) {
71+
#endif
6372
ret = -1;
6473
goto err;
6574
}
@@ -115,12 +124,20 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY* eckey, ECDSA_SIG* ecsig, const unsigned ch
115124
goto err;
116125
}
117126
rr = BN_CTX_get(ctx);
127+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
128+
if (!BN_mod_inverse(rr, sig_r, order, ctx)) {
129+
#else
118130
if (!BN_mod_inverse(rr, ecsig->r, order, ctx)) {
131+
#endif
119132
ret = -1;
120133
goto err;
121134
}
122135
sor = BN_CTX_get(ctx);
136+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
137+
if (!BN_mod_mul(sor, sig_s, rr, order, ctx)) {
138+
#else
123139
if (!BN_mod_mul(sor, ecsig->s, rr, order, ctx)) {
140+
#endif
124141
ret = -1;
125142
goto err;
126143
}
@@ -218,8 +235,20 @@ bool CECKey::Recover(const uint256& hash, const unsigned char* p64, int rec)
218235
if (rec < 0 || rec >= 3)
219236
return false;
220237
ECDSA_SIG* sig = ECDSA_SIG_new();
221-
BN_bin2bn(&p64[0], 32, sig->r);
238+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
239+
BIGNUM *sig_r = NULL;
240+
BIGNUM *sig_s = NULL;
241+
if (!(sig_r = BN_bin2bn(&p64[0], 32, nullptr)) ||
242+
!(sig_s = BN_bin2bn(&p64[32], 32, nullptr)) ||
243+
!ECDSA_SIG_set0(sig, sig_r, sig_s)) {
244+
BN_free(sig_r);
245+
BN_free(sig_s);
246+
return false;
247+
}
248+
#else
249+
BN_bin2bn(&p64[0], 32, sig->r);
222250
BN_bin2bn(&p64[32], 32, sig->s);
251+
#endif
223252
bool ret = ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), rec, 0) == 1;
224253
ECDSA_SIG_free(sig);
225254
return ret;

src/qt/paymentrequestplus.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,21 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
154154
std::string data_to_verify; // Everything but the signature
155155
rcopy.SerializeToString(&data_to_verify);
156156

157-
EVP_MD_CTX ctx;
157+
EVP_MD_CTX* ctx;
158158
EVP_PKEY* pubkey = X509_get_pubkey(signing_cert);
159-
EVP_MD_CTX_init(&ctx);
160-
if (!EVP_VerifyInit_ex(&ctx, digestAlgorithm, NULL) ||
161-
!EVP_VerifyUpdate(&ctx, data_to_verify.data(), data_to_verify.size()) ||
162-
!EVP_VerifyFinal(&ctx, (const unsigned char*)paymentRequest.signature().data(), paymentRequest.signature().size(), pubkey)) {
159+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
160+
ctx = EVP_MD_CTX_new();
161+
#else
162+
EVP_MD_CTX_init(ctx);
163+
#endif
164+
if (!EVP_VerifyInit_ex(ctx, digestAlgorithm, NULL) ||
165+
!EVP_VerifyUpdate(ctx, data_to_verify.data(), data_to_verify.size()) ||
166+
!EVP_VerifyFinal(ctx, (const unsigned char*)paymentRequest.signature().data(), paymentRequest.signature().size(), pubkey)) {
163167
throw SSLVerifyError("Bad signature, invalid PaymentRequest.");
164168
}
169+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
170+
EVP_MD_CTX_free(ctx);
171+
#endif
165172

166173
// OpenSSL API for getting human printable strings from certs is baroque.
167174
int textlen = X509_NAME_get_text_by_NID(certname, NID_commonName, NULL, 0);

src/rpcserver.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -472,28 +472,28 @@ class AcceptedConnectionImpl : public AcceptedConnection
472472
void ServiceConnection(AcceptedConnection* conn);
473473

474474
//! Forward declaration required for RPCListen
475-
template <typename Protocol, typename SocketAcceptorService>
476-
static void RPCAcceptHandler(boost::shared_ptr<basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor,
477-
ssl::context& context,
478-
bool fUseSSL,
479-
boost::shared_ptr<AcceptedConnection> conn,
475+
template <typename Protocol>
476+
static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol> > acceptor,
477+
ssl::context& context,
478+
bool fUseSSL,
479+
boost::shared_ptr< AcceptedConnection > conn,
480480
const boost::system::error_code& error);
481481

482482
/**
483483
* Sets up I/O resources to accept and handle a new connection.
484484
*/
485-
template <typename Protocol, typename SocketAcceptorService>
486-
static void RPCListen(boost::shared_ptr<basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor,
487-
ssl::context& context,
488-
const bool fUseSSL)
485+
template <typename Protocol>
486+
static void RPCListen(boost::shared_ptr< basic_socket_acceptor<Protocol> > acceptor,
487+
ssl::context& context,
488+
const bool fUseSSL)
489489
{
490490
// Accept connection
491491
boost::shared_ptr<AcceptedConnectionImpl<Protocol> > conn(new AcceptedConnectionImpl<Protocol>(acceptor->get_io_service(), context, fUseSSL));
492492

493493
acceptor->async_accept(
494494
conn->sslStream.lowest_layer(),
495495
conn->peer,
496-
boost::bind(&RPCAcceptHandler<Protocol, SocketAcceptorService>,
496+
boost::bind(&RPCAcceptHandler<Protocol>,
497497
acceptor,
498498
boost::ref(context),
499499
fUseSSL,
@@ -505,11 +505,11 @@ static void RPCListen(boost::shared_ptr<basic_socket_acceptor<Protocol, SocketAc
505505
/**
506506
* Accept and handle incoming connection.
507507
*/
508-
template <typename Protocol, typename SocketAcceptorService>
509-
static void RPCAcceptHandler(boost::shared_ptr<basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor,
508+
template <typename Protocol>
509+
static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol> > acceptor,
510510
ssl::context& context,
511511
const bool fUseSSL,
512-
boost::shared_ptr<AcceptedConnection> conn,
512+
boost::shared_ptr< AcceptedConnection > conn,
513513
const boost::system::error_code& error)
514514
{
515515
// Immediately start accepting new connections, except when we're cancelled or our socket is closed.
@@ -594,7 +594,7 @@ void StartRPCThreads()
594594

595595
assert(rpc_io_service == NULL);
596596
rpc_io_service = new asio::io_service();
597-
rpc_ssl_context = new ssl::context(*rpc_io_service, ssl::context::sslv23);
597+
rpc_ssl_context = new ssl::context(ssl::context::sslv23);
598598

599599
const bool fUseSSL = GetBoolArg("-rpcssl", false);
600600

@@ -616,7 +616,7 @@ void StartRPCThreads()
616616
LogPrintf("ThreadRPCServer ERROR: missing server private key file %s\n", pathPKFile.string());
617617

618618
string strCiphers = GetArg("-rpcsslciphers", "TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH");
619-
SSL_CTX_set_cipher_list(rpc_ssl_context->impl(), strCiphers.c_str());
619+
SSL_CTX_set_cipher_list(rpc_ssl_context->native_handle(), strCiphers.c_str());
620620
}
621621

622622
std::vector<ip::tcp::endpoint> vEndpoints;

0 commit comments

Comments
 (0)