Skip to content

Commit 26dd9e1

Browse files
committed
build,src: remove sslv2 support
SSLv2 has been deprecated and known broken for nearly twenty years now. I made SSLv2 support opt-in well over a year ago in commit 39aa894 and now this commit removes it entirely. PR-URL: #290 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 3ecad1d commit 26dd9e1

File tree

6 files changed

+17
-90
lines changed

6 files changed

+17
-90
lines changed

configure

-10
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,6 @@ parser.add_option('--with-perfctr',
252252
dest='with_perfctr',
253253
help='build with performance counters (default is true on Windows)')
254254

255-
parser.add_option('--with-sslv2',
256-
action='store_true',
257-
dest='with_sslv2',
258-
help='enable SSL v2')
259-
260255
parser.add_option('--without-dtrace',
261256
action='store_true',
262257
dest='without_dtrace',
@@ -588,11 +583,6 @@ def configure_openssl(o):
588583
if options.without_ssl:
589584
return
590585

591-
# OpenSSL uses `#ifndef OPENSSL_NO_SSL2` checks so only define the
592-
# macro when we want to _disable_ SSL2.
593-
if not options.with_sslv2:
594-
o['defines'] += ['OPENSSL_NO_SSL2=1']
595-
596586
if options.shared_openssl:
597587
(libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
598588

deps/openssl/openssl.gyp

+4
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,10 @@
10951095
'PURIFY',
10961096
'_REENTRANT',
10971097

1098+
# SSLv2 is known broken and has been superseded by SSLv3 for almost
1099+
# twenty years now.
1100+
'OPENSSL_NO_SSL2',
1101+
10981102
# Heartbeat is a TLS extension, that couldn't be turned off or
10991103
# asked to be not advertised. Unfortunately this is unacceptable for
11001104
# Microsoft's IIS, which seems to be ignoring whole ClientHello after

doc/api/tls.markdown

-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ automatically set as a listener for the [secureConnection][] event. The
184184
use this option in conjunction with the `ciphers` option to mitigate
185185
BEAST attacks.
186186

187-
Note: If SSLv2 is used, the server will send its list of preferences to the
188-
client, and the client chooses the cipher. Support for SSLv2 is disabled
189-
unless node.js was configured with `./configure --with-sslv2`.
190-
191187
- `requestCert`: If `true` the server will request a certificate from
192188
clients that connect and attempt to verify that certificate. Default:
193189
`false`.

src/node_crypto.cc

+5-12
Original file line numberDiff line numberDiff line change
@@ -310,23 +310,11 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
310310
const node::Utf8Value sslmethod(env->isolate(), args[0]);
311311

312312
if (strcmp(*sslmethod, "SSLv2_method") == 0) {
313-
#ifndef OPENSSL_NO_SSL2
314-
method = SSLv2_method();
315-
#else
316313
return env->ThrowError("SSLv2 methods disabled");
317-
#endif
318314
} else if (strcmp(*sslmethod, "SSLv2_server_method") == 0) {
319-
#ifndef OPENSSL_NO_SSL2
320-
method = SSLv2_server_method();
321-
#else
322315
return env->ThrowError("SSLv2 methods disabled");
323-
#endif
324316
} else if (strcmp(*sslmethod, "SSLv2_client_method") == 0) {
325-
#ifndef OPENSSL_NO_SSL2
326-
method = SSLv2_client_method();
327-
#else
328317
return env->ThrowError("SSLv2 methods disabled");
329-
#endif
330318
} else if (strcmp(*sslmethod, "SSLv3_method") == 0) {
331319
#ifndef OPENSSL_NO_SSL3
332320
method = SSLv3_method();
@@ -376,6 +364,11 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
376364

377365
sc->ctx_ = SSL_CTX_new(method);
378366

367+
// Disable SSLv2 in the case when method == SSLv23_method() and the
368+
// cipher list contains SSLv2 ciphers (not the default, should be rare.)
369+
// The bundled OpenSSL doesn't have SSLv2 support but the system OpenSSL may.
370+
SSL_CTX_set_options(sc->ctx_, SSL_OP_NO_SSLv2);
371+
379372
// SSL session cache configuration
380373
SSL_CTX_set_session_cache_mode(sc->ctx_,
381374
SSL_SESS_CACHE_SERVER |

src/node_crypto_clienthello.cc

+8-58
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ void ClientHelloParser::Parse(const uint8_t* data, size_t avail) {
3232
break;
3333
// Fall through
3434
case kTLSHeader:
35-
case kSSL2Header:
3635
ParseHeader(data, avail);
3736
break;
3837
case kPaused:
@@ -59,20 +58,8 @@ bool ClientHelloParser::ParseRecordHeader(const uint8_t* data, size_t avail) {
5958
state_ = kTLSHeader;
6059
body_offset_ = 5;
6160
} else {
62-
#ifdef OPENSSL_NO_SSL2
63-
frame_len_ = ((data[0] << 8) & kSSL2HeaderMask) + data[1];
64-
state_ = kSSL2Header;
65-
if (data[0] & kSSL2TwoByteHeaderBit) {
66-
// header without padding
67-
body_offset_ = 2;
68-
} else {
69-
// header with padding
70-
body_offset_ = 3;
71-
}
72-
#else
7361
End();
7462
return false;
75-
#endif // OPENSSL_NO_SSL2
7663
}
7764

7865
// Sanity check (too big frame, or too small)
@@ -85,12 +72,6 @@ bool ClientHelloParser::ParseRecordHeader(const uint8_t* data, size_t avail) {
8572
return true;
8673
}
8774

88-
#ifdef OPENSSL_NO_SSL2
89-
# define NODE_SSL2_VER_CHECK(buf) false
90-
#else
91-
# define NODE_SSL2_VER_CHECK(buf) ((buf)[0] == 0x00 && (buf)[1] == 0x02)
92-
#endif // OPENSSL_NO_SSL2
93-
9475

9576
void ClientHelloParser::ParseHeader(const uint8_t* data, size_t avail) {
9677
ClientHello hello;
@@ -99,24 +80,20 @@ void ClientHelloParser::ParseHeader(const uint8_t* data, size_t avail) {
9980
if (body_offset_ + frame_len_ > avail)
10081
return;
10182

102-
// Skip unsupported frames and gather some data from frame
103-
// Check hello protocol version
104-
if (!(data[body_offset_ + 4] == 0x03 && data[body_offset_ + 5] <= 0x03) &&
105-
!NODE_SSL2_VER_CHECK(data + body_offset_ + 4)) {
83+
// Check hello protocol version. Protocol tuples that we know about:
84+
//
85+
// (3,0) SSL v3.0
86+
// (3,1) TLS v1.0
87+
// (3,2) TLS v1.1
88+
// (3,3) TLS v1.2
89+
//
90+
if (data[body_offset_ + 4] != 0x03 || data[body_offset_ + 5] > 0x03)
10691
goto fail;
107-
}
10892

10993
if (data[body_offset_] == kClientHello) {
11094
if (state_ == kTLSHeader) {
11195
if (!ParseTLSClientHello(data, avail))
11296
goto fail;
113-
} else if (state_ == kSSL2Header) {
114-
#ifdef OPENSSL_NO_SSL2
115-
if (!ParseSSL2ClientHello(data, avail))
116-
goto fail;
117-
#else
118-
abort(); // Unreachable
119-
#endif // OPENSSL_NO_SSL2
12097
} else {
12198
// We couldn't get here, but whatever
12299
goto fail;
@@ -145,9 +122,6 @@ void ClientHelloParser::ParseHeader(const uint8_t* data, size_t avail) {
145122
}
146123

147124

148-
#undef NODE_SSL2_VER_CHECK
149-
150-
151125
void ClientHelloParser::ParseExtension(ClientHelloParser::ExtensionType type,
152126
const uint8_t* data,
153127
size_t len) {
@@ -269,28 +243,4 @@ bool ClientHelloParser::ParseTLSClientHello(const uint8_t* data, size_t avail) {
269243
return true;
270244
}
271245

272-
273-
#ifdef OPENSSL_NO_SSL2
274-
bool ClientHelloParser::ParseSSL2ClientHello(const uint8_t* data,
275-
size_t avail) {
276-
const uint8_t* body;
277-
278-
// Skip header, version
279-
size_t session_offset = body_offset_ + 3;
280-
281-
if (session_offset + 4 < avail) {
282-
body = data + session_offset;
283-
284-
uint16_t ciphers_size = (body[0] << 8) + body[1];
285-
286-
if (body + 4 + ciphers_size < data + avail) {
287-
session_size_ = (body[2] << 8) + body[3];
288-
session_id_ = body + 4 + ciphers_size;
289-
}
290-
}
291-
292-
return true;
293-
}
294-
#endif // OPENSSL_NO_SSL2
295-
296246
} // namespace node

src/node_crypto_clienthello.h

-6
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ class ClientHelloParser {
7777
inline bool IsEnded() const;
7878

7979
private:
80-
static const uint8_t kSSL2TwoByteHeaderBit = 0x80;
81-
static const uint8_t kSSL2HeaderMask = 0x3f;
8280
static const size_t kMaxTLSFrameLen = 16 * 1024 + 5;
8381
static const size_t kMaxSSLExFrameLen = 32 * 1024;
8482
static const uint8_t kServernameHostname = 0;
@@ -88,7 +86,6 @@ class ClientHelloParser {
8886
enum ParseState {
8987
kWaiting,
9088
kTLSHeader,
91-
kSSL2Header,
9289
kPaused,
9390
kEnded
9491
};
@@ -117,9 +114,6 @@ class ClientHelloParser {
117114
const uint8_t* data,
118115
size_t len);
119116
bool ParseTLSClientHello(const uint8_t* data, size_t avail);
120-
#ifdef OPENSSL_NO_SSL2
121-
bool ParseSSL2ClientHello(const uint8_t* data, size_t avail);
122-
#endif // OPENSSL_NO_SSL2
123117

124118
ParseState state_;
125119
OnHelloCb onhello_cb_;

0 commit comments

Comments
 (0)