ssl: Support for Diffie-Hellman and Elliptic-Curve Diffie-Hellman key exchange (fixes #2301, #2246, #2239)
- add ssl.use-sslv3 - load all algorithms git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2780 152afb58-edef-0310-8abb-c4023f1b3aa9
This commit is contained in:
parent
562a6ba83b
commit
f610f894a3
3
NEWS
3
NEWS
|
@ -8,6 +8,9 @@ NEWS
|
|||
* Silence annoying "connection closed: poll() -> ERR" error.log message (fixes #2257)
|
||||
* mod_cgi: make read buffer as big as incoming data block
|
||||
* [build] Fix detection of libev (fixes #2300)
|
||||
* ssl: Support for Diffie-Hellman and Elliptic-Curve Diffie-Hellman key exchange (fixes #2301)
|
||||
add ssl.use-sslv3 (fixes #2246)
|
||||
load all algorithms (fixes #2239)
|
||||
|
||||
- 1.4.28 - 2010-08-22
|
||||
* Rename fdevent_event_add to _set to reflect what the function does. Fix some handlers. (fixes #2249)
|
||||
|
|
|
@ -275,7 +275,10 @@ typedef struct {
|
|||
buffer *ssl_pemfile;
|
||||
buffer *ssl_ca_file;
|
||||
buffer *ssl_cipher_list;
|
||||
buffer *ssl_dh_file;
|
||||
buffer *ssl_ec_curve;
|
||||
unsigned short ssl_use_sslv2;
|
||||
unsigned short ssl_use_sslv3;
|
||||
unsigned short ssl_verifyclient;
|
||||
unsigned short ssl_verifyclient_enforce;
|
||||
unsigned short ssl_verifyclient_depth;
|
||||
|
@ -527,7 +530,10 @@ typedef struct {
|
|||
buffer *ssl_pemfile;
|
||||
buffer *ssl_ca_file;
|
||||
buffer *ssl_cipher_list;
|
||||
buffer *ssl_dh_file;
|
||||
buffer *ssl_ec_curve;
|
||||
unsigned short ssl_use_sslv2;
|
||||
unsigned short ssl_use_sslv3;
|
||||
unsigned short use_ipv6;
|
||||
unsigned short is_ssl;
|
||||
|
||||
|
|
|
@ -102,6 +102,9 @@ static int config_insert(server *srv) {
|
|||
{ "ssl.verifyclient.exportcert", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 60 */
|
||||
|
||||
{ "server.set-v6only", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 61 */
|
||||
{ "ssl.use-sslv3", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 62 */
|
||||
{ "ssl.dh-file", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 63 */
|
||||
{ "ssl.ec-curve", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 64 */
|
||||
|
||||
{ "server.host", "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
|
||||
{ "server.docroot", "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
|
||||
|
@ -164,6 +167,8 @@ static int config_insert(server *srv) {
|
|||
s->error_handler = buffer_init();
|
||||
s->server_tag = buffer_init();
|
||||
s->ssl_cipher_list = buffer_init();
|
||||
s->ssl_dh_file = buffer_init();
|
||||
s->ssl_ec_curve = buffer_init();
|
||||
s->errorfile_prefix = buffer_init();
|
||||
s->max_keep_alive_requests = 16;
|
||||
s->max_keep_alive_idle = 5;
|
||||
|
@ -172,6 +177,7 @@ static int config_insert(server *srv) {
|
|||
s->use_xattr = 0;
|
||||
s->is_ssl = 0;
|
||||
s->ssl_use_sslv2 = 0;
|
||||
s->ssl_use_sslv3 = 1;
|
||||
s->use_ipv6 = 0;
|
||||
s->set_v6only = 1;
|
||||
s->defer_accept = 0;
|
||||
|
@ -236,6 +242,9 @@ static int config_insert(server *srv) {
|
|||
|
||||
cv[47].destination = s->ssl_cipher_list;
|
||||
cv[48].destination = &(s->ssl_use_sslv2);
|
||||
cv[62].destination = &(s->ssl_use_sslv3);
|
||||
cv[63].destination = s->ssl_dh_file;
|
||||
cv[64].destination = s->ssl_ec_curve;
|
||||
cv[49].destination = &(s->etag_use_inode);
|
||||
cv[50].destination = &(s->etag_use_mtime);
|
||||
cv[51].destination = &(s->etag_use_size);
|
||||
|
@ -324,7 +333,10 @@ int config_setup_connection(server *srv, connection *con) {
|
|||
#endif
|
||||
PATCH(ssl_ca_file);
|
||||
PATCH(ssl_cipher_list);
|
||||
PATCH(ssl_dh_file);
|
||||
PATCH(ssl_ec_curve);
|
||||
PATCH(ssl_use_sslv2);
|
||||
PATCH(ssl_use_sslv3);
|
||||
PATCH(etag_use_inode);
|
||||
PATCH(etag_use_mtime);
|
||||
PATCH(etag_use_size);
|
||||
|
@ -390,10 +402,16 @@ int config_patch_connection(server *srv, connection *con, comp_key_t comp) {
|
|||
PATCH(ssl_ca_file);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.use-sslv2"))) {
|
||||
PATCH(ssl_use_sslv2);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.use-sslv3"))) {
|
||||
PATCH(ssl_use_sslv3);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.cipher-list"))) {
|
||||
PATCH(ssl_cipher_list);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.engine"))) {
|
||||
PATCH(is_ssl);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.dh-file"))) {
|
||||
PATCH(ssl_dh_file);
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.ec-curve"))) {
|
||||
PATCH(ssl_ec_curve);
|
||||
#ifdef HAVE_LSTAT
|
||||
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.follow-symlink"))) {
|
||||
PATCH(follow_symlink);
|
||||
|
|
115
src/network.c
115
src/network.c
|
@ -479,6 +479,52 @@ int network_init(server *srv) {
|
|||
size_t i;
|
||||
network_backend_t backend;
|
||||
|
||||
DH *dh;
|
||||
BIO *bio;
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0090800fL
|
||||
EC_KEY *ecdh;
|
||||
int nid;
|
||||
#endif
|
||||
|
||||
/* 1024-bit MODP Group with 160-bit prime order subgroup (RFC5114)
|
||||
* -----BEGIN DH PARAMETERS-----
|
||||
* MIIBDAKBgQCxC4+WoIDgHd6S3l6uXVTsUsmfvPsGo8aaap3KUtI7YWBz4oZ1oj0Y
|
||||
* mDjvHi7mUsAT7LSuqQYRIySXXDzUm4O/rMvdfZDEvXCYSI6cIZpzck7/1vrlZEc4
|
||||
* +qMaT/VbzMChUa9fDci0vUW/N982XBpl5oz9p21NpwjfH7K8LkpDcQKBgQCk0cvV
|
||||
* w/00EmdlpELvuZkF+BBN0lisUH/WQGz/FCZtMSZv6h5cQVZLd35pD1UE8hMWAhe0
|
||||
* sBuIal6RVH+eJ0n01/vX07mpLuGQnQ0iY/gKdqaiTAh6CR9THb8KAWm2oorWYqTR
|
||||
* jnOvoy13nVkY0IvIhY9Nzvl8KiSFXm7rIrOy5QICAKA=
|
||||
* -----END DH PARAMETERS-----
|
||||
*/
|
||||
|
||||
static unsigned char dh1024_p[]={
|
||||
0xB1,0x0B,0x8F,0x96,0xA0,0x80,0xE0,0x1D,0xDE,0x92,0xDE,0x5E,
|
||||
0xAE,0x5D,0x54,0xEC,0x52,0xC9,0x9F,0xBC,0xFB,0x06,0xA3,0xC6,
|
||||
0x9A,0x6A,0x9D,0xCA,0x52,0xD2,0x3B,0x61,0x60,0x73,0xE2,0x86,
|
||||
0x75,0xA2,0x3D,0x18,0x98,0x38,0xEF,0x1E,0x2E,0xE6,0x52,0xC0,
|
||||
0x13,0xEC,0xB4,0xAE,0xA9,0x06,0x11,0x23,0x24,0x97,0x5C,0x3C,
|
||||
0xD4,0x9B,0x83,0xBF,0xAC,0xCB,0xDD,0x7D,0x90,0xC4,0xBD,0x70,
|
||||
0x98,0x48,0x8E,0x9C,0x21,0x9A,0x73,0x72,0x4E,0xFF,0xD6,0xFA,
|
||||
0xE5,0x64,0x47,0x38,0xFA,0xA3,0x1A,0x4F,0xF5,0x5B,0xCC,0xC0,
|
||||
0xA1,0x51,0xAF,0x5F,0x0D,0xC8,0xB4,0xBD,0x45,0xBF,0x37,0xDF,
|
||||
0x36,0x5C,0x1A,0x65,0xE6,0x8C,0xFD,0xA7,0x6D,0x4D,0xA7,0x08,
|
||||
0xDF,0x1F,0xB2,0xBC,0x2E,0x4A,0x43,0x71,
|
||||
};
|
||||
|
||||
static unsigned char dh1024_g[]={
|
||||
0xA4,0xD1,0xCB,0xD5,0xC3,0xFD,0x34,0x12,0x67,0x65,0xA4,0x42,
|
||||
0xEF,0xB9,0x99,0x05,0xF8,0x10,0x4D,0xD2,0x58,0xAC,0x50,0x7F,
|
||||
0xD6,0x40,0x6C,0xFF,0x14,0x26,0x6D,0x31,0x26,0x6F,0xEA,0x1E,
|
||||
0x5C,0x41,0x56,0x4B,0x77,0x7E,0x69,0x0F,0x55,0x04,0xF2,0x13,
|
||||
0x16,0x02,0x17,0xB4,0xB0,0x1B,0x88,0x6A,0x5E,0x91,0x54,0x7F,
|
||||
0x9E,0x27,0x49,0xF4,0xD7,0xFB,0xD7,0xD3,0xB9,0xA9,0x2E,0xE1,
|
||||
0x90,0x9D,0x0D,0x22,0x63,0xF8,0x0A,0x76,0xA6,0xA2,0x4C,0x08,
|
||||
0x7A,0x09,0x1F,0x53,0x1D,0xBF,0x0A,0x01,0x69,0xB6,0xA2,0x8A,
|
||||
0xD6,0x62,0xA4,0xD1,0x8E,0x73,0xAF,0xA3,0x2D,0x77,0x9D,0x59,
|
||||
0x18,0xD0,0x8B,0xC8,0x85,0x8F,0x4D,0xCE,0xF9,0x7C,0x2A,0x24,
|
||||
0x85,0x5E,0x6E,0xEB,0x22,0xB3,0xB2,0xE5,
|
||||
};
|
||||
|
||||
struct nb_map {
|
||||
network_backend_t nb;
|
||||
const char *name;
|
||||
|
@ -521,6 +567,7 @@ int network_init(server *srv) {
|
|||
if (srv->ssl_is_init == 0) {
|
||||
SSL_load_error_strings();
|
||||
SSL_library_init();
|
||||
OpenSSL_add_all_algorithms();
|
||||
srv->ssl_is_init = 1;
|
||||
|
||||
if (0 == RAND_status()) {
|
||||
|
@ -545,6 +592,15 @@ int network_init(server *srv) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!s->ssl_use_sslv3) {
|
||||
/* disable SSLv3 */
|
||||
if (!(SSL_OP_NO_SSLv3 & SSL_CTX_set_options(s->ssl_ctx, SSL_OP_NO_SSLv3))) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:",
|
||||
ERR_error_string(ERR_get_error(), NULL));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!buffer_is_empty(s->ssl_cipher_list)) {
|
||||
/* Disable support for low encryption ciphers */
|
||||
if (SSL_CTX_set_cipher_list(s->ssl_ctx, s->ssl_cipher_list->ptr) != 1) {
|
||||
|
@ -554,6 +610,65 @@ int network_init(server *srv) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Support for Diffie-Hellman key exchange */
|
||||
if (!buffer_is_empty(s->ssl_dh_file)) {
|
||||
/* DH parameters from file */
|
||||
bio = BIO_new_file((char *) s->ssl_dh_file->ptr, "r");
|
||||
if (bio == NULL) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "SSL: Unable to open file", s->ssl_dh_file->ptr);
|
||||
return -1;
|
||||
}
|
||||
dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
|
||||
BIO_free(bio);
|
||||
if (dh == NULL) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "SSL: PEM_read_bio_DHparams failed", s->ssl_dh_file->ptr);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* Default DH parameters from RFC5114 */
|
||||
dh = DH_new();
|
||||
if (dh == NULL) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "s", "SSL: DH_new () failed");
|
||||
return -1;
|
||||
}
|
||||
dh->p = BN_bin2bn(dh1024_p,sizeof(dh1024_p), NULL);
|
||||
dh->g = BN_bin2bn(dh1024_g,sizeof(dh1024_g), NULL);
|
||||
dh->length = 160;
|
||||
if ((dh->p == NULL) || (dh->g == NULL)) {
|
||||
DH_free(dh);
|
||||
log_error_write(srv, __FILE__, __LINE__, "s", "SSL: BN_bin2bn () failed");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
SSL_CTX_set_tmp_dh(s->ssl_ctx,dh);
|
||||
SSL_CTX_set_options(s->ssl_ctx,SSL_OP_SINGLE_DH_USE);
|
||||
DH_free(dh);
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0090800fL
|
||||
#ifndef OPENSSL_NO_ECDH
|
||||
/* Support for Elliptic-Curve Diffie-Hellman key exchange */
|
||||
if (!buffer_is_empty(s->ssl_ec_curve)) {
|
||||
/* OpenSSL only supports the "named curves" from RFC 4492, section 5.1.1. */
|
||||
nid = OBJ_sn2nid((char *) s->ssl_ec_curve->ptr);
|
||||
if (nid == 0) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "SSL: Unknown curve name", s->ssl_ec_curve->ptr);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* Default curve */
|
||||
nid = OBJ_sn2nid("prime256v1");
|
||||
}
|
||||
ecdh = EC_KEY_new_by_curve_name(nid);
|
||||
if (ecdh == NULL) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "SSL: Unable to create curve", s->ssl_ec_curve->ptr);
|
||||
return -1;
|
||||
}
|
||||
SSL_CTX_set_tmp_ecdh(s->ssl_ctx,ecdh);
|
||||
SSL_CTX_set_options(s->ssl_ctx,SSL_OP_SINGLE_ECDH_USE);
|
||||
EC_KEY_free(ecdh);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (!buffer_is_empty(s->ssl_ca_file)) {
|
||||
if (1 != SSL_CTX_load_verify_locations(s->ssl_ctx, s->ssl_ca_file->ptr, NULL)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ssb", "SSL:",
|
||||
|
|
Loading…
Reference in New Issue