Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit df46c8e

Browse files
committed
Rip out the old TLS implementation
1 parent 2a750bf commit df46c8e

File tree

7 files changed

+5
-250
lines changed

7 files changed

+5
-250
lines changed

doc/api/http.markdown

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,6 @@ This function is asynchronous. The last parameter `callback` will be called
121121
when the server has been bound.
122122

123123

124-
### server.setSecure(credentials)
125-
126-
Enables HTTPS support for the server, with the crypto module credentials
127-
specifying the private key and certificate of the server, and optionally
128-
the CA certificates for use in client authentication.
129-
130-
If the credentials hold one or more CA certificates, then the server will request
131-
for the client to submit a client certificate as part of the HTTPS connection handshake.
132-
The validity and content of this can be accessed via `verifyPeer()`
133-
and `getPeerCertificate()` from the server's `request.connection`.
134-
135124
### server.close()
136125

137126
Stops the server from accepting new connections.

doc/api/net.markdown

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,6 @@ Either `'closed'`, `'open'`, `'opening'`, `'readOnly'`, or `'writeOnly'`.
257257
Emitted when a stream connection successfully is established.
258258
See `connect()`.
259259

260-
261-
#### Event: 'secure'
262-
263-
`function () { }`
264-
265-
Emitted when a stream connection successfully establishes an SSL handshake with its peer.
266-
267-
268260
#### Event: 'data'
269261

270262
`function (data) { }`

lib/http.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,6 @@ function Server (requestListener) {
753753
}
754754
util.inherits(Server, net.Server);
755755

756-
Server.prototype.setSecure = function (credentials) {
757-
this.secure = true;
758-
this.credentials = credentials;
759-
};
760-
761756
exports.Server = Server;
762757

763758
exports.createServer = function (requestListener) {
@@ -780,10 +775,6 @@ function connectionListener (socket) {
780775
parser.reinitialize('request');
781776
parser.socket = socket;
782777

783-
if (self.secure) {
784-
socket.setSecure(self.credentials);
785-
}
786-
787778
socket.addListener('error', function (e) {
788779
self.emit('clientError', e);
789780
});
@@ -912,16 +903,6 @@ function Client ( ) {
912903
self.ondata = onData;
913904
self.onend = onEnd;
914905

915-
if (this.https) {
916-
this.setSecure(this.credentials);
917-
} else {
918-
self._initParser();
919-
debug('requests: ' + util.inspect(self._outgoing));
920-
outgoingFlush(self);
921-
}
922-
});
923-
924-
self.addListener("secure", function () {
925906
self._initParser();
926907
debug('requests: ' + util.inspect(self._outgoing));
927908
outgoingFlush(self);

lib/net.js

Lines changed: 5 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ var ENOENT = constants.ENOENT;
4848
var EMFILE = constants.EMFILE;
4949

5050
var END_OF_FILE = 42;
51-
var SecureContext, SecureStream; // lazy loaded
5251

5352

5453
var ioWatchers = new FreeList("iowatcher", 100, function () {
@@ -78,11 +77,6 @@ function allocNewPool () {
7877
pool.used = 0;
7978
}
8079

81-
var securePool = null;
82-
function allocNewSecurePool () {
83-
securePool = new Buffer(40*1024);
84-
}
85-
8680
var emptyBuffer = null;
8781
function allocEmptyBuffer () {
8882
emptyBuffer = new Buffer(1);
@@ -108,7 +102,7 @@ function setImplmentationMethods (self) {
108102
return sendMsg(self.fd, buf, off, len, fd, flags);
109103
};
110104

111-
self._readImpl = function (buf, off, len, calledByIOWatcher) {
105+
self._readImpl = function (buf, off, len) {
112106
var bytesRead = recvMsg(self.fd, buf, off, len);
113107

114108
// Do not emit this in the same stack, otherwise we risk corrupting our
@@ -139,7 +133,7 @@ function setImplmentationMethods (self) {
139133
return write(self.fd, buf, off, len);
140134
};
141135

142-
self._readImpl = function (buf, off, len, calledByIOWatcher) {
136+
self._readImpl = function (buf, off, len) {
143137
return read(self.fd, buf, off, len);
144138
};
145139
}
@@ -148,132 +142,13 @@ function setImplmentationMethods (self) {
148142
shutdown(self.fd, 'write');
149143
};
150144

151-
if (self.secure) {
152-
var oldWrite = self._writeImpl;
153-
self._writeImpl = function (buf, off, len, fd, flags) {
154-
assert(buf);
155-
assert(self.secure);
156-
157-
var bytesWritten = self.secureStream.clearIn(buf, off, len);
158-
159-
if (!securePool) {
160-
allocNewSecurePool();
161-
}
162-
163-
var secureLen = self.secureStream.encOut(securePool,
164-
0,
165-
securePool.length);
166-
167-
if (secureLen == -1) {
168-
// Check our read again for secure handshake
169-
self._onReadable();
170-
} else {
171-
oldWrite(securePool, 0, secureLen, fd, flags);
172-
}
173-
174-
if (!self.secureEstablished && self.secureStream.isInitFinished()) {
175-
self.secureEstablished = true;
176-
177-
if (self._events && self._events['secure']) {
178-
self.emit('secure');
179-
}
180-
}
181-
182-
return bytesWritten;
183-
};
184-
185-
var oldRead = self._readImpl;
186-
self._readImpl = function (buf, off, len, calledByIOWatcher) {
187-
assert(self.secure);
188-
189-
var bytesRead = 0;
190-
var secureBytesRead = null;
191-
192-
if (!securePool) {
193-
allocNewSecurePool();
194-
}
195-
196-
if (calledByIOWatcher) {
197-
secureBytesRead = oldRead(securePool, 0, securePool.length);
198-
self.secureStream.encIn(securePool, 0, secureBytesRead);
199-
}
200-
201-
var chunkBytes;
202-
do {
203-
chunkBytes =
204-
self.secureStream.clearOut(pool,
205-
pool.used + bytesRead,
206-
pool.length - pool.used - bytesRead);
207-
bytesRead += chunkBytes;
208-
} while ((chunkBytes > 0) && (pool.used + bytesRead < pool.length));
209-
210-
if (bytesRead == 0 && !calledByIOWatcher) {
211-
return -1;
212-
}
213-
214-
if (self.secureStream.clearPending()) {
215-
process.nextTick(function () {
216-
if (self.readable) self._onReadable();
217-
});
218-
}
219-
220-
if (!self.secureEstablished) {
221-
if (self.secureStream.isInitFinished()) {
222-
self.secureEstablished = true;
223-
if (self._events && self._events['secure']) {
224-
self.emit('secure');
225-
}
226-
}
227-
}
228-
229-
if (calledByIOWatcher && secureBytesRead === null && !self.server) {
230-
// Client needs to write as part of handshake
231-
self._writeWatcher.start();
232-
return -1;
233-
}
234-
235-
if (bytesRead == 0 && secureBytesRead > 0) {
236-
// Deal with SSL handshake
237-
if (self.server) {
238-
self._checkForSecureHandshake();
239-
} else {
240-
if (self.secureEstablised) {
241-
self.flush();
242-
} else {
243-
self._checkForSecureHandshake();
244-
}
245-
}
246-
247-
return -1;
248-
}
249-
250-
return bytesRead;
251-
};
252-
253-
var oldShutdown = self._shutdownImpl;
254-
self._shutdownImpl = function () {
255-
self.secureStream.shutdown();
256-
257-
if (!securePool) {
258-
allocNewSecurePool();
259-
}
260-
261-
var len = self.secureStream.encOut(securePool, 0, securePool.length);
262-
263-
try {
264-
oldWrite(securePool, 0, len);
265-
} catch (e) { }
266-
267-
oldShutdown();
268-
};
269-
}
270145
};
271146

272147

273148
function onReadable (readable, writeable) {
274149
assert(this.socket);
275150
var socket = this.socket;
276-
socket._onReadable(true);
151+
socket._onReadable();
277152
}
278153

279154

@@ -312,13 +187,11 @@ function Stream (options) {
312187

313188
this.fd = null;
314189
this.type = null;
315-
this.secure = false;
316190
this.allowHalfOpen = false;
317191

318192
if (typeof options == "object") {
319193
this.fd = options.fd !== undefined ? parseInt(options.fd, 10) : null;
320194
this.type = options.type || null;
321-
this.secure = options.secure || false;
322195
this.allowHalfOpen = options.allowHalfOpen || false;
323196
} else if (typeof options == "number") {
324197
this.fd = arguments[0];
@@ -340,76 +213,6 @@ Stream.prototype._onTimeout = function () {
340213
};
341214

342215

343-
Stream.prototype.setSecure = function (credentials) {
344-
// Do we have openssl crypto?
345-
try {
346-
SecureContext = process.binding('crypto').SecureContext;
347-
SecureStream = process.binding('crypto').SecureStream;
348-
} catch (e) {
349-
throw new Error('node.js not compiled with openssl crypto support.');
350-
}
351-
352-
var crypto = require("crypto");
353-
this.secure = true;
354-
this.secureEstablished = false;
355-
// If no credentials given, create a new one for just this Stream
356-
if (!credentials) {
357-
this.credentials = crypto.createCredentials();
358-
} else {
359-
this.credentials = credentials;
360-
}
361-
if (!this.server) {
362-
// For clients, we will always have either a given ca list or the default on
363-
this.credentials.shouldVerify = true;
364-
}
365-
this.secureStream = new SecureStream(this.credentials.context,
366-
this.server ? true : false,
367-
this.credentials.shouldVerify);
368-
369-
setImplmentationMethods(this);
370-
371-
if (!this.server) {
372-
// If client, trigger handshake
373-
this._checkForSecureHandshake();
374-
}
375-
};
376-
377-
378-
Stream.prototype.verifyPeer = function () {
379-
if (!this.secure) {
380-
throw new Error('Stream is not a secure stream.');
381-
}
382-
return this.secureStream.verifyPeer(this.credentials.context);
383-
};
384-
385-
386-
Stream.prototype._checkForSecureHandshake = function () {
387-
if (!this.writable) {
388-
return;
389-
}
390-
391-
// Do an empty write to see if we need to write out as part of handshake
392-
if (!emptyBuffer) allocEmptyBuffer();
393-
this.write(emptyBuffer);
394-
};
395-
396-
397-
Stream.prototype.getPeerCertificate = function (credentials) {
398-
if (!this.secure) {
399-
throw new Error('Stream is not a secure stream.');
400-
}
401-
return this.secureStream.getPeerCertificate();
402-
};
403-
404-
405-
Stream.prototype.getCipher = function () {
406-
if (!this.secure) {
407-
throw new Error('Stream is not a secure stream.');
408-
}
409-
return this.secureStream.getCurrentCipher();
410-
};
411-
412-
413216
Stream.prototype.open = function (fd, type) {
414217
initStream(this);
415218

@@ -699,7 +502,7 @@ Stream.prototype._onWritable = function () {
699502
};
700503

701504

702-
Stream.prototype._onReadable = function (calledByIOWatcher) {
505+
Stream.prototype._onReadable = function () {
703506
var self = this;
704507

705508
// If this is the first recv (pool doesn't exist) or we've used up
@@ -717,8 +520,7 @@ Stream.prototype._onReadable = function (calledByIOWatcher) {
717520
try {
718521
bytesRead = self._readImpl(pool,
719522
pool.used,
720-
pool.length - pool.used,
721-
calledByIOWatcher);
523+
pool.length - pool.used);
722524
} catch (e) {
723525
self.destroy(e);
724526
return;
@@ -760,11 +562,6 @@ Stream.prototype._onReadable = function (calledByIOWatcher) {
760562

761563
// Optimization: emit the original buffer with end points
762564
if (self.ondata) self.ondata(pool, start, end);
763-
} else if (bytesRead == -2) {
764-
// Temporary fix - need SSL refactor.
765-
// -2 originates from SecureStream::ReadExtract
766-
self.destroy(new Error('openssl read error'));
767-
return false;
768565
}
769566
};
770567

@@ -873,10 +670,6 @@ Stream.prototype.destroy = function (exception) {
873670

874671
require('timers').unenroll(this);
875672

876-
if (this.secure) {
877-
this.secureStream.close();
878-
}
879-
880673
if (this.server) {
881674
this.server.connections--;
882675
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)