From 7239bcf0b70e18d25524606e3118b887ab79428b Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 12 Jun 2015 11:52:41 -0700 Subject: [PATCH] Support larger EDH keys: In the past we used only 512-bit EDH keys. To protect against the LOGJAM attack, OpenSSL 1.0.1n and later versions reject EDH keys that are less than 768 bits and a future version will increase the minimum to 1024. We now have DH parameters for 1024-bit and 2048-bit EDH keys and will correctly return and use those, when asked. Note that at this time, OpenSSL will only ask for 512 or 1024 bit keys. --- src/ripple/basics/impl/make_SSLContext.cpp | 102 ++++++++++++++++----- 1 file changed, 78 insertions(+), 24 deletions(-) diff --git a/src/ripple/basics/impl/make_SSLContext.cpp b/src/ripple/basics/impl/make_SSLContext.cpp index 5d533580bb..4e2f517d36 100644 --- a/src/ripple/basics/impl/make_SSLContext.cpp +++ b/src/ripple/basics/impl/make_SSLContext.cpp @@ -132,7 +132,7 @@ static x509_ptr x509_new() int const margin = 60 * 60; // 3600, one hour int const length = 10 * 365.25 * 24 * 60 * 60; // 315576000, ten years - + X509_gmtime_adj (X509_get_notBefore (x509), -margin); X509_gmtime_adj (X509_get_notAfter (x509), length); @@ -198,10 +198,10 @@ static DH* getDH (int keyLength) { - if (keyLength == 512 || keyLength == 1024) + if (keyLength == 512 || keyLength == 1024 || keyLength == 2048) { - static dh_ptr dh512 = make_DH(getRawDHParams (keyLength)); - return dh512.get (); + static dh_ptr dh = make_DH(getRawDHParams (keyLength)); + return dh.get (); } else { @@ -434,35 +434,89 @@ initAuthenticated (boost::asio::ssl::context& context, } // openssl //------------------------------------------------------------------------------ - std::string getRawDHParams (int keySize) { std::string params; - // Original code provided the 512-bit keySize parameters - // when 1024 bits were requested so we will do the same. - if (keySize == 1024) - keySize = 512; - switch (keySize) { case 512: - { - // These are the DH parameters that OpenCoin has chosen for Ripple - // - std::uint8_t const raw [] = { - 0x30, 0x46, 0x02, 0x41, 0x00, 0x98, 0x15, 0xd2, 0xd0, 0x08, 0x32, 0xda, - 0xaa, 0xac, 0xc4, 0x71, 0xa3, 0x1b, 0x11, 0xf0, 0x6c, 0x62, 0xb2, 0x35, - 0x8a, 0x10, 0x92, 0xc6, 0x0a, 0xa3, 0x84, 0x7e, 0xaf, 0x17, 0x29, 0x0b, - 0x70, 0xef, 0x07, 0x4f, 0xfc, 0x9d, 0x6d, 0x87, 0x99, 0x19, 0x09, 0x5b, - 0x6e, 0xdb, 0x57, 0x72, 0x4a, 0x7e, 0xcd, 0xaf, 0xbd, 0x3a, 0x97, 0x55, - 0x51, 0x77, 0x5a, 0x34, 0x7c, 0xe8, 0xc5, 0x71, 0x63, 0x02, 0x01, 0x02 - }; + { + // These are the DH parameters that OpenCoin has chosen for Ripple + // + std::uint8_t const raw512 [] = { + 0x30, 0x46, 0x02, 0x41, 0x00, 0x98, 0x15, 0xd2, 0xd0, 0x08, 0x32, 0xda, + 0xaa, 0xac, 0xc4, 0x71, 0xa3, 0x1b, 0x11, 0xf0, 0x6c, 0x62, 0xb2, 0x35, + 0x8a, 0x10, 0x92, 0xc6, 0x0a, 0xa3, 0x84, 0x7e, 0xaf, 0x17, 0x29, 0x0b, + 0x70, 0xef, 0x07, 0x4f, 0xfc, 0x9d, 0x6d, 0x87, 0x99, 0x19, 0x09, 0x5b, + 0x6e, 0xdb, 0x57, 0x72, 0x4a, 0x7e, 0xcd, 0xaf, 0xbd, 0x3a, 0x97, 0x55, + 0x51, 0x77, 0x5a, 0x34, 0x7c, 0xe8, 0xc5, 0x71, 0x63, 0x02, 0x01, 0x02 + }; - params.resize (sizeof (raw)); - std::copy (raw, raw + sizeof (raw), params.begin ()); - } + params.resize (sizeof (raw512)); + std::copy (raw512, raw512 + sizeof (raw512), params.begin ()); + break; + } + + case 1024: + { + // These are the DH parameters that Ripple Labs has chosen for Ripple + // + std::uint8_t const raw1024 [] = { + 0x30, 0x81, 0x87, 0x02, 0x81, 0x81, 0x00, 0x86, 0xb1, 0x85, 0x36, 0x3d, + 0xbc, 0x0b, 0x03, 0xa5, 0xde, 0x53, 0x23, 0x4c, 0x59, 0xd4, 0x2b, 0x2e, + 0x88, 0xdf, 0x83, 0x8e, 0xab, 0xe9, 0xc9, 0x0f, 0x20, 0x5c, 0x3e, 0x8d, + 0x0e, 0x2c, 0xff, 0xcf, 0x3a, 0xfa, 0x71, 0x67, 0xb2, 0x90, 0xb5, 0x9e, + 0x13, 0x9f, 0xa3, 0x70, 0xb2, 0xdf, 0x8d, 0xa4, 0x91, 0xfb, 0x26, 0xe0, + 0x95, 0xd2, 0xf9, 0x3b, 0xa5, 0x1f, 0xe4, 0x88, 0x0f, 0x65, 0xfc, 0x8e, + 0x58, 0x47, 0x8c, 0x77, 0x93, 0x8c, 0x2d, 0x2a, 0xfa, 0x50, 0xb4, 0xc5, + 0x29, 0xba, 0x65, 0xc4, 0x39, 0xeb, 0x8a, 0xc5, 0x93, 0x39, 0xf9, 0x3c, + 0x15, 0x1e, 0x95, 0x82, 0x0d, 0x02, 0xff, 0x92, 0x4c, 0xc5, 0x07, 0x76, + 0x62, 0xaf, 0xdc, 0xc0, 0x96, 0x95, 0xcf, 0x61, 0x51, 0x17, 0x7c, 0x02, + 0x81, 0xdb, 0xc2, 0x6b, 0x07, 0x03, 0x96, 0x39, 0xcc, 0xde, 0xc9, 0xcd, + 0x5d, 0x77, 0x3b, 0x02, 0x01, 0x02 + }; + params.resize (sizeof (raw1024)); + std::copy (raw1024, raw1024 + sizeof (raw1024), params.begin ()); + break; + } + + case 2048: + { + // These are the DH parameters that Ripple Labs has chosen for Ripple + // + std::uint8_t const raw2048 [] = { + 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0x8f, 0xca, 0x66, + 0x85, 0x33, 0xcb, 0xcf, 0x36, 0x27, 0xb2, 0x4c, 0xb8, 0x50, 0xb8, 0xf9, + 0x53, 0xf8, 0xb9, 0x2d, 0x1c, 0xa2, 0xad, 0x86, 0x58, 0x29, 0x3b, 0x88, + 0x3e, 0xf5, 0x65, 0xb8, 0xda, 0x22, 0xf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0xb9, 0x2b, 0xf8, 0x17, + 0x8d, 0xed, 0x44, 0xaa, 0x47, 0xaa, 0x52, 0xa2, 0xdb, 0xb6, 0xf5, 0xa1, + 0x88, 0x85, 0xa1, 0xd5, 0x87, 0xb8, 0x07, 0xd3, 0x97, 0xbe, 0x37, 0x74, + 0x72, 0xf1, 0xa8, 0x29, 0xf1, 0xa7, 0x7d, 0x19, 0xc3, 0x27, 0x09, 0xcf, + 0x23, 0x02, 0x01, 0x02 + }; + params.resize (sizeof (raw2048)); + std::copy (raw2048, raw2048 + sizeof (raw2048), params.begin ()); + break; + } + + default: break; };