20 #include <ripple/basics/chrono.h>
21 #include <ripple/basics/contract.h>
22 #include <ripple/basics/make_SSLContext.h>
23 #include <ripple/beast/container/aged_unordered_set.h>
71 EVP_PKEY_free(evp_pkey);
109 #if OPENSSL_VERSION_NUMBER >= 0x00908000L
110 BIGNUM* bn = BN_new();
111 BN_set_word(bn, RSA_F4);
113 RSA* rsa = RSA_new();
114 if (RSA_generate_key_ex(rsa, n_bits, bn,
nullptr) != 1)
122 RSA* rsa = RSA_generate_key(n_bits, RSA_F4,
nullptr,
nullptr);
138 EVP_PKEY* evp_pkey = EVP_PKEY_new();
140 if (evp_pkey ==
nullptr)
149 if (!EVP_PKEY_assign_RSA(evp_pkey, rsa.
get()))
162 X509* x509 = X509_new();
167 X509_set_version(x509, NID_X509);
169 int const margin = 60 * 60;
170 int const length = 10 * 365.25 * 24 * 60 * 60;
172 X509_gmtime_adj(X509_get_notBefore(x509), -margin);
173 X509_gmtime_adj(X509_get_notAfter(x509), length);
181 X509_set_pubkey(x509, evp_pkey);
187 if (!X509_sign(x509, evp_pkey, EVP_sha1()))
194 if (SSL_CTX_use_certificate(ctx, cert.
get()) <= 0)
201 if (SSL_CTX_use_PrivateKey(ctx, key.
get()) <= 0)
209 ss << what <<
": " << ec.message() <<
" (" << ec.value() <<
")";
216 using namespace openssl;
225 SSL_CTX*
const ctx = context.native_handle();
232 boost::asio::ssl::context& context,
237 SSL_CTX*
const ssl = context.native_handle();
239 bool cert_set =
false;
241 if (!cert_file.
empty())
243 boost::system::error_code ec;
245 context.use_certificate_file(
246 cert_file, boost::asio::ssl::context::pem, ec);
257 if (!chain_file.
empty())
260 FILE* f = fopen(chain_file.
c_str(),
"r");
265 "Problem opening SSL chain file.",
266 boost::system::error_code(
267 errno, boost::system::generic_category()))
275 X509*
const x = PEM_read_X509(f,
nullptr,
nullptr,
nullptr);
282 if (SSL_CTX_use_certificate(ssl, x) != 1)
284 "Problem retrieving SSL certificate from chain "
289 else if (SSL_CTX_add_extra_chain_cert(ssl, x) != 1)
292 LogicError(
"Problem adding SSL chain certificate.");
301 LogicError(
"Reading the SSL chain file generated an exception.");
305 if (!key_file.
empty())
307 boost::system::error_code ec;
309 context.use_private_key_file(
310 key_file, boost::asio::ssl::context::pem, ec);
320 if (SSL_CTX_check_private_key(ssl) != 1)
322 LogicError(
"Invalid key in SSL private key file.");
329 auto c = std::make_shared<boost::asio::ssl::context>(
330 boost::asio::ssl::context::sslv23);
333 boost::asio::ssl::context::default_workarounds |
334 boost::asio::ssl::context::no_sslv2 |
335 boost::asio::ssl::context::no_sslv3 |
336 boost::asio::ssl::context::no_tlsv1 |
337 boost::asio::ssl::context::no_tlsv1_1 |
338 boost::asio::ssl::context::single_dh_use |
339 boost::asio::ssl::context::no_compression);
343 auto result = SSL_CTX_set_cipher_list(c->native_handle(), l.c_str());
352 unsigned char const params[] = {
353 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0x8f, 0xca, 0x66,
354 0x85, 0x33, 0xcb, 0xcf, 0x36, 0x27, 0xb2, 0x4c, 0xb8, 0x50, 0xb8, 0xf9,
355 0x53, 0xf8, 0xb9, 0x2d, 0x1c, 0xa2, 0xad, 0x86, 0x58, 0x29, 0x3b, 0x88,
356 0x3e, 0xf5, 0x65, 0xb8, 0xda, 0x22, 0xf4, 0x8b, 0x21, 0x12, 0x18, 0xf7,
357 0x16, 0xcd, 0x7c, 0xc7, 0x3a, 0x2d, 0x61, 0xb7, 0x11, 0xf6, 0xb0, 0x65,
358 0xa0, 0x5b, 0xa4, 0x06, 0x95, 0x28, 0xa4, 0x4f, 0x76, 0xc0, 0xeb, 0xfa,
359 0x95, 0xdf, 0xbf, 0x19, 0x90, 0x64, 0x8f, 0x60, 0xd5, 0x36, 0xba, 0xab,
360 0x0d, 0x5a, 0x5c, 0x94, 0xd5, 0xf7, 0x32, 0xd6, 0x2a, 0x76, 0x77, 0x83,
361 0x10, 0xc4, 0x2f, 0x10, 0x96, 0x3e, 0x37, 0x84, 0x45, 0x9c, 0xef, 0x33,
362 0xf6, 0xd0, 0x2a, 0xa7, 0xce, 0x0a, 0xce, 0x0d, 0xa1, 0xa7, 0x44, 0x5d,
363 0x18, 0x3f, 0x4f, 0xa4, 0x23, 0x9c, 0x5d, 0x74, 0x4f, 0xee, 0xdf, 0xaa,
364 0x0d, 0x0a, 0x52, 0x57, 0x73, 0xb1, 0xe4, 0xc5, 0x72, 0x93, 0x9d, 0x03,
365 0xe9, 0xf5, 0x48, 0x8c, 0xd1, 0xe6, 0x7c, 0x21, 0x65, 0x4e, 0x16, 0x51,
366 0xa3, 0x16, 0x51, 0x10, 0x75, 0x60, 0x37, 0x93, 0xb8, 0x15, 0xd6, 0x14,
367 0x41, 0x4a, 0x61, 0xc9, 0x1a, 0x4e, 0x9f, 0x38, 0xd8, 0x2c, 0xa5, 0x31,
368 0xe1, 0x87, 0xda, 0x1f, 0xa4, 0x31, 0xa2, 0xa4, 0x42, 0x1e, 0xe0, 0x30,
369 0xea, 0x2f, 0x9b, 0x77, 0x91, 0x59, 0x3e, 0xd5, 0xd0, 0xc5, 0x84, 0x45,
370 0x17, 0x19, 0x74, 0x8b, 0x18, 0xb0, 0xc1, 0xe0, 0xfc, 0x1c, 0xaf, 0xe6,
371 0x2a, 0xef, 0x4e, 0x0e, 0x8a, 0x5c, 0xc2, 0x91, 0xb9, 0x2b, 0xf8, 0x17,
372 0x8d, 0xed, 0x44, 0xaa, 0x47, 0xaa, 0x52, 0xa2, 0xdb, 0xb6, 0xf5, 0xa1,
373 0x88, 0x85, 0xa1, 0xd5, 0x87, 0xb8, 0x07, 0xd3, 0x97, 0xbe, 0x37, 0x74,
374 0x72, 0xf1, 0xa8, 0x29, 0xf1, 0xa7, 0x7d, 0x19, 0xc3, 0x27, 0x09, 0xcf,
375 0x23, 0x02, 0x01, 0x02};
377 unsigned char const* data = ¶ms[0];
380 d2i_DHparams(
nullptr, &data,
sizeof(params))};
384 SSL_CTX_set_tmp_dh(c->native_handle(), dh.get());
390 SSL_CTX_set_options(c->native_handle(), SSL_OP_NO_RENEGOTIATION);
406 context->set_verify_mode(boost::asio::ssl::verify_none);