Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 1 | #pragma once |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 2 | #ifdef CROW_ENABLE_SSL |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 3 | |
| 4 | #include <openssl/bio.h> |
| 5 | #include <openssl/dh.h> |
| 6 | #include <openssl/dsa.h> |
| 7 | #include <openssl/dsa.h> |
| 8 | #include <openssl/err.h> |
| 9 | #include <openssl/evp.h> |
| 10 | #include <openssl/pem.h> |
| 11 | #include <openssl/rand.h> |
| 12 | #include <openssl/rsa.h> |
| 13 | #include <openssl/ssl.h> |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 14 | #include <random> |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 15 | #include <boost/asio.hpp> |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 16 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 17 | namespace ensuressl { |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 18 | static void init_openssl(void); |
| 19 | static void cleanup_openssl(void); |
| 20 | static EVP_PKEY *create_rsa_key(void); |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 21 | static EVP_PKEY *create_ec_key(void); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 22 | static void handle_openssl_error(void); |
| 23 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 24 | inline bool verify_openssl_key_cert(const std::string &filepath) { |
| 25 | bool private_key_valid = false; |
| 26 | bool cert_valid = false; |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 27 | |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 28 | std::cout << "Checking certs in file " << filepath << "\n"; |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 29 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 30 | FILE *file = fopen(filepath.c_str(), "r"); |
| 31 | if (file != NULL) { |
| 32 | EVP_PKEY *pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL); |
| 33 | int rc; |
| 34 | if (pkey) { |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 35 | RSA *rsa = EVP_PKEY_get1_RSA(pkey); |
| 36 | if (rsa) { |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 37 | std::cout << "Found an RSA key\n"; |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 38 | if (RSA_check_key(rsa) == 1) { |
| 39 | // private_key_valid = true; |
| 40 | } else { |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 41 | std::cerr << "Key not valid error number " << ERR_get_error() << "\n"; |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 42 | } |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 43 | RSA_free(rsa); |
| 44 | } else { |
| 45 | EC_KEY *ec = EVP_PKEY_get1_EC_KEY(pkey); |
| 46 | if (ec) { |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 47 | std::cout << "Found an EC key\n"; |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 48 | if (EC_KEY_check_key(ec) == 1) { |
| 49 | private_key_valid = true; |
| 50 | } else { |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 51 | std::cerr << "Key not valid error number " << ERR_get_error() << "\n"; |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 52 | } |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 53 | EC_KEY_free(ec); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 54 | } |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | if (private_key_valid) { |
| 58 | X509 *x509 = PEM_read_X509(file, NULL, NULL, NULL); |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 59 | if (!x509) { |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 60 | std::cout << "error getting x509 cert " << ERR_get_error() << "\n"; |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 61 | } else { |
| 62 | rc = X509_verify(x509, pkey); |
| 63 | if (rc == 1) { |
| 64 | cert_valid = true; |
| 65 | } else { |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 66 | std::cerr << "Error in verifying private key signature " |
| 67 | << ERR_get_error() << "\n"; |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 68 | } |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | EVP_PKEY_free(pkey); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 73 | } |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 74 | fclose(file); |
| 75 | } |
| 76 | return cert_valid; |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 79 | inline void generate_ssl_certificate(const std::string &filepath) { |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 80 | FILE *pFile = NULL; |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 81 | std::cout << "Generating new keys\n"; |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 82 | init_openssl(); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 83 | |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 84 | // std::cerr << "Generating RSA key"; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 85 | // EVP_PKEY *pRsaPrivKey = create_rsa_key(); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 86 | |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 87 | std::cerr << "Generating EC key\n"; |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame] | 88 | EVP_PKEY *pRsaPrivKey = create_ec_key(); |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 89 | if (pRsaPrivKey) { |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 90 | std::cerr << "Generating x509 Certificate\n"; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 91 | // Use this code to directly generate a certificate |
| 92 | X509 *x509; |
| 93 | x509 = X509_new(); |
| 94 | if (x509) { |
| 95 | // Get a random number from the RNG for the certificate serial number |
| 96 | // If this is not random, regenerating certs throws broswer errors |
| 97 | std::random_device rd; |
| 98 | int serial = rd(); |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 99 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 100 | ASN1_INTEGER_set(X509_get_serialNumber(x509), serial); |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 101 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 102 | // not before this moment |
| 103 | X509_gmtime_adj(X509_get_notBefore(x509), 0); |
| 104 | // Cert is valid for 10 years |
| 105 | X509_gmtime_adj(X509_get_notAfter(x509), 60L * 60L * 24L * 365L * 10L); |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 106 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 107 | // set the public key to the key we just generated |
| 108 | X509_set_pubkey(x509, pRsaPrivKey); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 109 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 110 | // Get the subject name |
| 111 | X509_NAME *name; |
| 112 | name = X509_get_subject_name(x509); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 113 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 114 | X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, (unsigned char *)"US", |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 115 | -1, -1, 0); |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 116 | X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 117 | (unsigned char *)"Intel BMC", -1, -1, 0); |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 118 | X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 119 | (unsigned char *)"testhost", -1, -1, 0); |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 120 | // set the CSR options |
| 121 | X509_set_issuer_name(x509, name); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 122 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 123 | // Sign the certificate with our private key |
| 124 | X509_sign(x509, pRsaPrivKey, EVP_sha256()); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 125 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 126 | pFile = fopen(filepath.c_str(), "wt"); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 127 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 128 | if (pFile) { |
| 129 | PEM_write_PrivateKey(pFile, pRsaPrivKey, NULL, NULL, 0, 0, NULL); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 130 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 131 | PEM_write_X509(pFile, x509); |
| 132 | fclose(pFile); |
| 133 | pFile = NULL; |
| 134 | } |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 135 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 136 | X509_free(x509); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 139 | EVP_PKEY_free(pRsaPrivKey); |
| 140 | pRsaPrivKey = NULL; |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 141 | } |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 142 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 143 | // cleanup_openssl(); |
| 144 | } |
| 145 | |
| 146 | EVP_PKEY *create_rsa_key(void) { |
| 147 | RSA *pRSA = NULL; |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 148 | #if OPENSSL_VERSION_NUMBER < 0x00908000L |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 149 | pRSA = RSA_generate_key(2048, RSA_3, NULL, NULL); |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 150 | #else |
| 151 | RSA_generate_key_ex(pRSA, 2048, NULL, NULL); |
| 152 | #endif |
| 153 | |
| 154 | EVP_PKEY *pKey = EVP_PKEY_new(); |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 155 | if (pRSA && pKey && EVP_PKEY_assign_RSA(pKey, pRSA)) { |
| 156 | /* pKey owns pRSA from now */ |
| 157 | if (RSA_check_key(pRSA) <= 0) { |
| 158 | fprintf(stderr, "RSA_check_key failed.\n"); |
| 159 | handle_openssl_error(); |
| 160 | EVP_PKEY_free(pKey); |
| 161 | pKey = NULL; |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 162 | } |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 163 | } else { |
| 164 | handle_openssl_error(); |
| 165 | if (pRSA) { |
| 166 | RSA_free(pRSA); |
| 167 | pRSA = NULL; |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 168 | } |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 169 | if (pKey) { |
| 170 | EVP_PKEY_free(pKey); |
| 171 | pKey = NULL; |
| 172 | } |
| 173 | } |
| 174 | return pKey; |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 177 | EVP_PKEY *create_ec_key(void) { |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 178 | EVP_PKEY *pKey = NULL; |
| 179 | int eccgrp = 0; |
| 180 | eccgrp = OBJ_txt2nid("prime256v1"); |
| 181 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 182 | EC_KEY *myecc = EC_KEY_new_by_curve_name(eccgrp); |
| 183 | if (myecc) { |
| 184 | EC_KEY_set_asn1_flag(myecc, OPENSSL_EC_NAMED_CURVE); |
| 185 | EC_KEY_generate_key(myecc); |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 186 | pKey = EVP_PKEY_new(); |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 187 | if (pKey) { |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 188 | if (EVP_PKEY_assign_EC_KEY(pKey, myecc)) { |
| 189 | /* pKey owns pRSA from now */ |
| 190 | if (EC_KEY_check_key(myecc) <= 0) { |
| 191 | fprintf(stderr, "EC_check_key failed.\n"); |
| 192 | } |
| 193 | } |
Ed Tanous | 9b65f1f | 2017-03-07 15:17:13 -0800 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | return pKey; |
| 197 | } |
| 198 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 199 | void init_openssl(void) { |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 200 | #if OPENSSL_VERSION_NUMBER < 0x10100000L |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 201 | SSL_load_error_strings(); |
| 202 | OpenSSL_add_all_algorithms(); |
| 203 | RAND_load_file("/dev/urandom", 1024); |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 204 | #endif |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 207 | void cleanup_openssl(void) { |
| 208 | CRYPTO_cleanup_all_ex_data(); |
| 209 | ERR_free_strings(); |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 210 | #if OPENSSL_VERSION_NUMBER < 0x10100000L |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 211 | ERR_remove_thread_state(0); |
Ed Tanous | a1e077c | 2017-04-25 12:42:19 -0700 | [diff] [blame] | 212 | #endif |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 213 | EVP_cleanup(); |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void handle_openssl_error(void) { ERR_print_errors_fp(stderr); } |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 217 | inline void ensure_openssl_key_present_and_valid(const std::string &filepath) { |
| 218 | bool pem_file_valid = false; |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 219 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 220 | pem_file_valid = verify_openssl_key_cert(filepath); |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 221 | |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 222 | if (!pem_file_valid) { |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 223 | std::cerr << "Error in verifying signature, regenerating\n"; |
Ed Tanous | 9992332 | 2017-03-03 14:21:24 -0800 | [diff] [blame] | 224 | generate_ssl_certificate(filepath); |
| 225 | } |
Ed Tanous | 0fdddb1 | 2017-02-28 11:06:34 -0800 | [diff] [blame] | 226 | } |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame] | 227 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 228 | boost::asio::ssl::context get_ssl_context(std::string ssl_pem_file) { |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame] | 229 | boost::asio::ssl::context m_ssl_context{boost::asio::ssl::context::sslv23}; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 230 | m_ssl_context.set_options(boost::asio::ssl::context::default_workarounds | |
| 231 | boost::asio::ssl::context::no_sslv2 | |
| 232 | boost::asio::ssl::context::no_sslv3 | |
| 233 | boost::asio::ssl::context::single_dh_use | |
| 234 | boost::asio::ssl::context::no_tlsv1 | |
| 235 | boost::asio::ssl::context::no_tlsv1_1); |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame] | 236 | |
| 237 | // m_ssl_context.set_verify_mode(boost::asio::ssl::verify_peer); |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 238 | m_ssl_context.use_certificate_file(ssl_pem_file, |
| 239 | boost::asio::ssl::context::pem); |
| 240 | m_ssl_context.use_private_key_file(ssl_pem_file, |
| 241 | boost::asio::ssl::context::pem); |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame] | 242 | |
| 243 | // Set up EC curves to auto (boost asio doesn't have a method for this) |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 244 | // There is a pull request to add this. Once this is included in an asio |
| 245 | // drop, use the right way |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame] | 246 | // http://stackoverflow.com/questions/18929049/boost-asio-with-ecdsa-certificate-issue |
| 247 | if (SSL_CTX_set_ecdh_auto(m_ssl_context.native_handle(), 1) != 1) { |
| 248 | CROW_LOG_ERROR << "Error setting tmp ecdh list\n"; |
| 249 | } |
| 250 | |
| 251 | // From mozilla "compatibility" |
| 252 | std::string ciphers = |
| 253 | "ECDHE-ECDSA-CHACHA20-POLY1305:" |
| 254 | "ECDHE-RSA-CHACHA20-POLY1305:" |
| 255 | "ECDHE-ECDSA-AES128-GCM-SHA256:" |
| 256 | "ECDHE-RSA-AES128-GCM-SHA256:" |
| 257 | "ECDHE-ECDSA-AES256-GCM-SHA384:" |
| 258 | "ECDHE-RSA-AES256-GCM-SHA384:" |
| 259 | "DHE-RSA-AES128-GCM-SHA256:" |
| 260 | "DHE-RSA-AES256-GCM-SHA384:" |
| 261 | "ECDHE-ECDSA-AES128-SHA256:" |
| 262 | "ECDHE-RSA-AES128-SHA256:" |
| 263 | "ECDHE-ECDSA-AES128-SHA:" |
| 264 | "ECDHE-RSA-AES256-SHA384:" |
| 265 | "ECDHE-RSA-AES128-SHA:" |
| 266 | "ECDHE-ECDSA-AES256-SHA384:" |
| 267 | "ECDHE-ECDSA-AES256-SHA:" |
| 268 | "ECDHE-RSA-AES256-SHA:" |
| 269 | "DHE-RSA-AES128-SHA256:" |
| 270 | "DHE-RSA-AES128-SHA:" |
| 271 | "DHE-RSA-AES256-SHA256:" |
| 272 | "DHE-RSA-AES256-SHA:" |
| 273 | "ECDHE-ECDSA-DES-CBC3-SHA:" |
| 274 | "ECDHE-RSA-DES-CBC3-SHA:" |
| 275 | "EDH-RSA-DES-CBC3-SHA:" |
| 276 | "AES128-GCM-SHA256:" |
| 277 | "AES256-GCM-SHA384:" |
| 278 | "AES128-SHA256:" |
| 279 | "AES256-SHA256:" |
| 280 | "AES128-SHA:" |
| 281 | "AES256-SHA:" |
| 282 | "DES-CBC3-SHA:" |
| 283 | "!DSS"; |
| 284 | |
| 285 | // From mozilla "modern" |
| 286 | std::string modern_ciphers = |
| 287 | "ECDHE-ECDSA-AES256-GCM-SHA384:" |
| 288 | "ECDHE-RSA-AES256-GCM-SHA384:" |
| 289 | "ECDHE-ECDSA-CHACHA20-POLY1305:" |
| 290 | "ECDHE-RSA-CHACHA20-POLY1305:" |
| 291 | "ECDHE-ECDSA-AES128-GCM-SHA256:" |
| 292 | "ECDHE-RSA-AES128-GCM-SHA256:" |
| 293 | "ECDHE-ECDSA-AES256-SHA384:" |
| 294 | "ECDHE-RSA-AES256-SHA384:" |
| 295 | "ECDHE-ECDSA-AES128-SHA256:" |
| 296 | "ECDHE-RSA-AES128-SHA256"; |
| 297 | |
| 298 | std::string lighttp_ciphers = "AES128+EECDH:AES128+EDH:!aNULL:!eNULL"; |
| 299 | |
Ed Tanous | 0d485ef | 2017-05-23 09:23:53 -0700 | [diff] [blame] | 300 | if (SSL_CTX_set_cipher_list(m_ssl_context.native_handle(), lighttp_ciphers.c_str()) != |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 301 | 1) { |
Ed Tanous | c4771fb | 2017-03-13 13:39:49 -0700 | [diff] [blame] | 302 | CROW_LOG_ERROR << "Error setting cipher list\n"; |
| 303 | } |
| 304 | return m_ssl_context; |
| 305 | } |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | #endif |