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>
38 "HIGH:MEDIUM:!aNULL:!MD5:!DSS:!3DES:!RC4:!EXPORT";
63 EVP_PKEY_free(evp_pkey);
101 #if OPENSSL_VERSION_NUMBER >= 0x00908000L
102 BIGNUM* bn = BN_new();
103 BN_set_word(bn, RSA_F4);
105 RSA* rsa = RSA_new();
106 if (RSA_generate_key_ex(rsa, n_bits, bn,
nullptr) != 1)
114 RSA* rsa = RSA_generate_key(n_bits, RSA_F4,
nullptr,
nullptr);
130 EVP_PKEY* evp_pkey = EVP_PKEY_new();
132 if (evp_pkey ==
nullptr)
141 if (!EVP_PKEY_assign_RSA(evp_pkey, rsa.
get()))
154 X509* x509 = X509_new();
159 X509_set_version(x509, NID_X509);
161 int const margin = 60 * 60;
162 int const length = 10 * 365.25 * 24 * 60 * 60;
164 X509_gmtime_adj(X509_get_notBefore(x509), -margin);
165 X509_gmtime_adj(X509_get_notAfter(x509), length);
173 X509_set_pubkey(x509, evp_pkey);
179 if (!X509_sign(x509, evp_pkey, EVP_sha1()))
186 if (SSL_CTX_use_certificate(ctx, cert.
get()) <= 0)
193 if (SSL_CTX_use_PrivateKey(ctx, key.
get()) <= 0)
197 #ifdef SSL_FLAGS_NO_RENEGOTIATE_CIPHERS
199 disallowRenegotiation(SSL
const* ssl,
bool isNew)
214 static StaticData sd;
219 for (
auto iter(sd.set.chronological.begin());
220 (iter != sd.set.chronological.end()) && (iter.when() <= expired);
221 iter = sd.set.chronological.begin())
226 auto iter = sd.set.find(ssl);
227 if (iter != sd.set.end())
246 info_handler(SSL
const* ssl,
int event,
int)
248 #if OPENSSL_VERSION_NUMBER < 0x10100000L
249 if ((ssl->s3) && (event & SSL_CB_HANDSHAKE_START))
251 if (disallowRenegotiation(ssl, SSL_in_before(ssl)))
252 ssl->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS;
264 ss << what <<
": " << ec.message() <<
" (" << ec.value() <<
")";
271 using namespace openssl;
280 SSL_CTX*
const ctx = context.native_handle();
287 boost::asio::ssl::context& context,
292 SSL_CTX*
const ssl = context.native_handle();
294 bool cert_set =
false;
296 if (!cert_file.
empty())
298 boost::system::error_code ec;
300 context.use_certificate_file(
301 cert_file, boost::asio::ssl::context::pem, ec);
312 if (!chain_file.
empty())
315 FILE* f = fopen(chain_file.
c_str(),
"r");
320 "Problem opening SSL chain file.",
321 boost::system::error_code(
322 errno, boost::system::generic_category()))
330 X509*
const x = PEM_read_X509(f,
nullptr,
nullptr,
nullptr);
337 if (SSL_CTX_use_certificate(ssl, x) != 1)
339 "Problem retrieving SSL certificate from chain "
344 else if (SSL_CTX_add_extra_chain_cert(ssl, x) != 1)
347 LogicError(
"Problem adding SSL chain certificate.");
356 LogicError(
"Reading the SSL chain file generated an exception.");
360 if (!key_file.
empty())
362 boost::system::error_code ec;
364 context.use_private_key_file(
365 key_file, boost::asio::ssl::context::pem, ec);
375 if (SSL_CTX_check_private_key(ssl) != 1)
377 LogicError(
"Invalid key in SSL private key file.");
384 auto c = std::make_shared<boost::asio::ssl::context>(
385 boost::asio::ssl::context::sslv23);
388 boost::asio::ssl::context::default_workarounds |
389 boost::asio::ssl::context::no_sslv2 |
390 boost::asio::ssl::context::no_sslv3 |
391 boost::asio::ssl::context::single_dh_use);
395 auto result = SSL_CTX_set_cipher_list(c->native_handle(), l.c_str());
404 unsigned char const params[] = {
405 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0x8f, 0xca, 0x66,
406 0x85, 0x33, 0xcb, 0xcf, 0x36, 0x27, 0xb2, 0x4c, 0xb8, 0x50, 0xb8, 0xf9,
407 0x53, 0xf8, 0xb9, 0x2d, 0x1c, 0xa2, 0xad, 0x86, 0x58, 0x29, 0x3b, 0x88,
408 0x3e, 0xf5, 0x65, 0xb8, 0xda, 0x22, 0xf4, 0x8b, 0x21, 0x12, 0x18, 0xf7,
409 0x16, 0xcd, 0x7c, 0xc7, 0x3a, 0x2d, 0x61, 0xb7, 0x11, 0xf6, 0xb0, 0x65,
410 0xa0, 0x5b, 0xa4, 0x06, 0x95, 0x28, 0xa4, 0x4f, 0x76, 0xc0, 0xeb, 0xfa,
411 0x95, 0xdf, 0xbf, 0x19, 0x90, 0x64, 0x8f, 0x60, 0xd5, 0x36, 0xba, 0xab,
412 0x0d, 0x5a, 0x5c, 0x94, 0xd5, 0xf7, 0x32, 0xd6, 0x2a, 0x76, 0x77, 0x83,
413 0x10, 0xc4, 0x2f, 0x10, 0x96, 0x3e, 0x37, 0x84, 0x45, 0x9c, 0xef, 0x33,
414 0xf6, 0xd0, 0x2a, 0xa7, 0xce, 0x0a, 0xce, 0x0d, 0xa1, 0xa7, 0x44, 0x5d,
415 0x18, 0x3f, 0x4f, 0xa4, 0x23, 0x9c, 0x5d, 0x74, 0x4f, 0xee, 0xdf, 0xaa,
416 0x0d, 0x0a, 0x52, 0x57, 0x73, 0xb1, 0xe4, 0xc5, 0x72, 0x93, 0x9d, 0x03,
417 0xe9, 0xf5, 0x48, 0x8c, 0xd1, 0xe6, 0x7c, 0x21, 0x65, 0x4e, 0x16, 0x51,
418 0xa3, 0x16, 0x51, 0x10, 0x75, 0x60, 0x37, 0x93, 0xb8, 0x15, 0xd6, 0x14,
419 0x41, 0x4a, 0x61, 0xc9, 0x1a, 0x4e, 0x9f, 0x38, 0xd8, 0x2c, 0xa5, 0x31,
420 0xe1, 0x87, 0xda, 0x1f, 0xa4, 0x31, 0xa2, 0xa4, 0x42, 0x1e, 0xe0, 0x30,
421 0xea, 0x2f, 0x9b, 0x77, 0x91, 0x59, 0x3e, 0xd5, 0xd0, 0xc5, 0x84, 0x45,
422 0x17, 0x19, 0x74, 0x8b, 0x18, 0xb0, 0xc1, 0xe0, 0xfc, 0x1c, 0xaf, 0xe6,
423 0x2a, 0xef, 0x4e, 0x0e, 0x8a, 0x5c, 0xc2, 0x91, 0xb9, 0x2b, 0xf8, 0x17,
424 0x8d, 0xed, 0x44, 0xaa, 0x47, 0xaa, 0x52, 0xa2, 0xdb, 0xb6, 0xf5, 0xa1,
425 0x88, 0x85, 0xa1, 0xd5, 0x87, 0xb8, 0x07, 0xd3, 0x97, 0xbe, 0x37, 0x74,
426 0x72, 0xf1, 0xa8, 0x29, 0xf1, 0xa7, 0x7d, 0x19, 0xc3, 0x27, 0x09, 0xcf,
427 0x23, 0x02, 0x01, 0x02};
429 unsigned char const* data = ¶ms[0];
432 d2i_DHparams(
nullptr, &data,
sizeof(params))};
436 SSL_CTX_set_tmp_dh(c->native_handle(), dh.get());
438 #ifdef SSL_FLAGS_NO_RENEGOTIATE_CIPHERS
439 SSL_CTX_set_info_callback(c->native_handle(), info_handler);
456 context->set_verify_mode(boost::asio::ssl::verify_none);