@@ -49,7 +49,7 @@ server-side resources, which makes it a potential vector for denial-of-service
49
49
attacks.
50
50
51
51
To mitigate this, renegotiations are limited to three times every 10 minutes. An
52
- error is emitted on the [ CleartextStream ] [ ] instance when the threshold is
52
+ error is emitted on the [ tls.TLSSocket ] [ ] instance when the threshold is
53
53
exceeded. The limits are configurable:
54
54
55
55
- ` tls.CLIENT_RENEG_LIMIT ` : renegotiation limit, default is 3.
@@ -188,12 +188,12 @@ Here is a simple example echo server:
188
188
ca: [ fs.readFileSync('client-cert.pem') ]
189
189
};
190
190
191
- var server = tls.createServer(options, function(cleartextStream ) {
191
+ var server = tls.createServer(options, function(socket ) {
192
192
console.log('server connected',
193
- cleartextStream .authorized ? 'authorized' : 'unauthorized');
194
- cleartextStream .write("welcome!\n");
195
- cleartextStream .setEncoding('utf8');
196
- cleartextStream .pipe(cleartextStream );
193
+ socket .authorized ? 'authorized' : 'unauthorized');
194
+ socket .write("welcome!\n");
195
+ socket .setEncoding('utf8');
196
+ socket .pipe(socket );
197
197
});
198
198
server.listen(8000, function() {
199
199
console.log('server bound');
212
212
213
213
};
214
214
215
- var server = tls.createServer(options, function(cleartextStream ) {
215
+ var server = tls.createServer(options, function(socket ) {
216
216
console.log('server connected',
217
- cleartextStream .authorized ? 'authorized' : 'unauthorized');
218
- cleartextStream .write("welcome!\n");
219
- cleartextStream .setEncoding('utf8');
220
- cleartextStream .pipe(cleartextStream );
217
+ socket .authorized ? 'authorized' : 'unauthorized');
218
+ socket .write("welcome!\n");
219
+ socket .setEncoding('utf8');
220
+ socket .pipe(socket );
221
221
});
222
222
server.listen(8000, function() {
223
223
console.log('server bound');
@@ -228,15 +228,6 @@ You can test this server by connecting to it with `openssl s_client`:
228
228
openssl s_client -connect 127.0.0.1:8000
229
229
230
230
231
- ## tls.SLAB_BUFFER_SIZE
232
-
233
- Size of slab buffer used by all tls servers and clients.
234
- Default: ` 10 * 1024 * 1024 ` .
235
-
236
-
237
- Don't change the defaults unless you know what you are doing.
238
-
239
-
240
231
## tls.connect(options, [ callback] )
241
232
## tls.connect(port, [ host] , [ options] , [ callback] )
242
233
@@ -285,7 +276,7 @@ Creates a new client connection to the given `port` and `host` (old API) or
285
276
The ` callback ` parameter will be added as a listener for the
286
277
[ 'secureConnect'] [ ] event.
287
278
288
- ` tls.connect() ` returns a [ CleartextStream ] [ ] object.
279
+ ` tls.connect() ` returns a [ tls.TLSSocket ] [ ] object.
289
280
290
281
Here is an example of a client of echo server as described previously:
291
282
@@ -301,17 +292,17 @@ Here is an example of a client of echo server as described previously:
301
292
ca: [ fs.readFileSync('server-cert.pem') ]
302
293
};
303
294
304
- var cleartextStream = tls.connect(8000, options, function() {
295
+ var socket = tls.connect(8000, options, function() {
305
296
console.log('client connected',
306
- cleartextStream .authorized ? 'authorized' : 'unauthorized');
307
- process.stdin.pipe(cleartextStream );
297
+ socket .authorized ? 'authorized' : 'unauthorized');
298
+ process.stdin.pipe(socket );
308
299
process.stdin.resume();
309
300
});
310
- cleartextStream .setEncoding('utf8');
311
- cleartextStream .on('data', function(data) {
301
+ socket .setEncoding('utf8');
302
+ socket .on('data', function(data) {
312
303
console.log(data);
313
304
});
314
- cleartextStream .on('end', function() {
305
+ socket .on('end', function() {
315
306
server.close();
316
307
});
317
308
324
315
pfx: fs.readFileSync('client.pfx')
325
316
};
326
317
327
- var cleartextStream = tls.connect(8000, options, function() {
318
+ var socket = tls.connect(8000, options, function() {
328
319
console.log('client connected',
329
- cleartextStream .authorized ? 'authorized' : 'unauthorized');
330
- process.stdin.pipe(cleartextStream );
320
+ socket .authorized ? 'authorized' : 'unauthorized');
321
+ process.stdin.pipe(socket );
331
322
process.stdin.resume();
332
323
});
333
- cleartextStream .setEncoding('utf8');
334
- cleartextStream .on('data', function(data) {
324
+ socket .setEncoding('utf8');
325
+ socket .on('data', function(data) {
335
326
console.log(data);
336
327
});
337
- cleartextStream .on('end', function() {
328
+ socket .on('end', function() {
338
329
server.close();
339
330
});
340
331
341
332
## tls.createSecurePair([ credentials] , [ isServer] , [ requestCert] , [ rejectUnauthorized] )
342
333
334
+ ** Deprecated **
335
+
343
336
Creates a new secure pair object with two streams, one of which reads/writes
344
337
encrypted data, and one reads/writes cleartext data.
345
338
Generally the encrypted one is piped to/from an incoming encrypted data stream,
@@ -357,9 +350,11 @@ and the cleartext one is used as a replacement for the initial encrypted stream.
357
350
automatically reject clients with invalid certificates. Only applies to
358
351
servers with ` requestCert ` enabled.
359
352
360
- ` tls.createSecurePair() ` returns a SecurePair object with [ cleartext] [ ] and
353
+ ` tls.createSecurePair() ` returns a SecurePair object with ` cleartext ` and
361
354
` encrypted ` stream properties.
362
355
356
+ NOTE: ` cleartext ` has the same APIs as [ tls.TLSSocket] [ ]
357
+
363
358
## Class: SecurePair
364
359
365
360
Returned by tls.createSecurePair.
@@ -381,50 +376,31 @@ connections using TLS or SSL.
381
376
382
377
### Event: 'secureConnection'
383
378
384
- ` function (cleartextStream ) {} `
379
+ ` function (tlsSocket ) {} `
385
380
386
381
This event is emitted after a new connection has been successfully
387
- handshaked. The argument is a instance of [ CleartextStream ] [ ] . It has all the
382
+ handshaked. The argument is a instance of [ tls.TLSSocket ] [ ] . It has all the
388
383
common stream methods and events.
389
384
390
- ` cleartextStream .authorized` is a boolean value which indicates if the
385
+ ` socket .authorized` is a boolean value which indicates if the
391
386
client has verified by one of the supplied certificate authorities for the
392
- server. If ` cleartextStream .authorized` is false, then
393
- ` cleartextStream .authorizationError` is set to describe how authorization
387
+ server. If ` socket .authorized` is false, then
388
+ ` socket .authorizationError` is set to describe how authorization
394
389
failed. Implied but worth mentioning: depending on the settings of the TLS
395
390
server, you unauthorized connections may be accepted.
396
- ` cleartextStream .npnProtocol` is a string containing selected NPN protocol.
397
- ` cleartextStream .servername` is a string containing servername requested with
391
+ ` socket .npnProtocol` is a string containing selected NPN protocol.
392
+ ` socket .servername` is a string containing servername requested with
398
393
SNI.
399
394
400
395
401
396
### Event: 'clientError'
402
397
403
- ` function (exception, securePair ) { } `
398
+ ` function (exception, tlsSocket ) { } `
404
399
405
400
When a client connection emits an 'error' event before secure connection is
406
401
established - it will be forwarded here.
407
402
408
- ` securePair ` is the ` tls.SecurePair ` that the error originated from.
409
-
410
-
411
- ### Event: 'newSession'
412
-
413
- ` function (sessionId, sessionData) { } `
414
-
415
- Emitted on creation of TLS session. May be used to store sessions in external
416
- storage.
417
-
418
-
419
- ### Event: 'resumeSession'
420
-
421
- ` function (sessionId, callback) { } `
422
-
423
- Emitted when client wants to resume previous TLS session. Event listener may
424
- perform lookup in external storage using given ` sessionId ` , and invoke
425
- ` callback(null, sessionData) ` once finished. If session can't be resumed
426
- (i.e. doesn't exist in storage) one may call ` callback(null, null) ` . Calling
427
- ` callback(err) ` will terminate incoming connection and destroy socket.
403
+ ` tlsSocket ` is the [ tls.TLSSocket] [ ] that the error originated from.
428
404
429
405
430
406
### server.listen(port, [ host] , [ callback] )
@@ -469,44 +445,44 @@ The number of concurrent connections on the server.
469
445
470
446
## Class: CryptoStream
471
447
448
+ ** Deprecated **
449
+
472
450
This is an encrypted stream.
473
451
474
452
### cryptoStream.bytesWritten
475
453
476
454
A proxy to the underlying socket's bytesWritten accessor, this will return
477
455
the total bytes written to the socket, * including the TLS overhead* .
478
456
479
- ## Class: tls.CleartextStream
457
+ ## Class: tls.TLSSocket
480
458
481
- This is a stream on top of the * Encrypted * stream that makes it possible to
482
- read/write an encrypted data as a cleartext data .
459
+ This is a wrapped version of [ net.Socket ] [ ] that does transparent encryption
460
+ of written data and all required TLS negotiation .
483
461
484
462
This instance implements a duplex [ Stream] [ ] interfaces. It has all the
485
463
common stream methods and events.
486
464
487
- A ClearTextStream is the ` clear ` member of a SecurePair object.
488
-
489
465
### Event: 'secureConnect'
490
466
491
- This event is emitted after a new connection has been successfully handshaked.
467
+ This event is emitted after a new connection has been successfully handshaked.
492
468
The listener will be called no matter if the server's certificate was
493
- authorized or not. It is up to the user to test ` cleartextStream .authorized`
469
+ authorized or not. It is up to the user to test ` tlsSocket .authorized`
494
470
to see if the server certificate was signed by one of the specified CAs.
495
- If ` cleartextStream .authorized === false` then the error can be found in
496
- ` cleartextStream .authorizationError` . Also if NPN was used - you can check
497
- ` cleartextStream .npnProtocol` for negotiated protocol.
471
+ If ` tlsSocket .authorized === false` then the error can be found in
472
+ ` tlsSocket .authorizationError` . Also if NPN was used - you can check
473
+ ` tlsSocket .npnProtocol` for negotiated protocol.
498
474
499
- ### cleartextStream .authorized
475
+ ### tlsSocket .authorized
500
476
501
477
A boolean that is ` true ` if the peer certificate was signed by one of the
502
478
specified CAs, otherwise ` false `
503
479
504
- ### cleartextStream .authorizationError
480
+ ### tlsSocket .authorizationError
505
481
506
482
The reason why the peer's certificate has not been verified. This property
507
- becomes available only when ` cleartextStream .authorized === false` .
483
+ becomes available only when ` tlsSocket .authorized === false` .
508
484
509
- ### cleartextStream .getPeerCertificate()
485
+ ### tlsSocket .getPeerCertificate()
510
486
511
487
Returns an object representing the peer's certificate. The returned object has
512
488
some properties corresponding to the field of the certificate.
@@ -534,7 +510,7 @@ Example:
534
510
If the peer does not provide a certificate, it returns ` null ` or an empty
535
511
object.
536
512
537
- ### cleartextStream .getCipher()
513
+ ### tlsSocket .getCipher()
538
514
Returns an object representing the cipher name and the SSL/TLS
539
515
protocol version of the current connection.
540
516
@@ -545,33 +521,33 @@ See SSL_CIPHER_get_name() and SSL_CIPHER_get_version() in
545
521
http://www.openssl.org/docs/ssl/ssl.html#DEALING_WITH_CIPHERS for more
546
522
information.
547
523
548
- ### cleartextStream .address()
524
+ ### tlsSocket .address()
549
525
550
526
Returns the bound address, the address family name and port of the
551
527
underlying socket as reported by the operating system. Returns an
552
528
object with three properties, e.g.
553
529
` { port: 12346, family: 'IPv4', address: '127.0.0.1' } `
554
530
555
- ### cleartextStream .remoteAddress
531
+ ### tlsSocket .remoteAddress
556
532
557
533
The string representation of the remote IP address. For example,
558
534
` '74.125.127.100' ` or ` '2001:4860:a005::68' ` .
559
535
560
- ### cleartextStream .remotePort
536
+ ### tlsSocket .remotePort
561
537
562
538
The numeric representation of the remote port. For example, ` 443 ` .
563
539
564
- ### cleartextStream .localAddress
540
+ ### tlsSocket .localAddress
565
541
566
542
The string representation of the local IP address.
567
543
568
- ### cleartextStream .localPort
544
+ ### tlsSocket .localPort
569
545
570
546
The numeric representation of the local port.
571
547
572
548
[ OpenSSL cipher list format documentation ] : http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT
573
549
[ BEAST attacks ] : http://blog.ivanristic.com/2011/10/mitigating-the-beast-attack-on-tls.html
574
- [ CleartextStream ] : #tls_class_tls_cleartextstream
550
+ [ tls.TLSSocket ] : #tls_class_tls_tlssocket
575
551
[ net.Server.address() ] : net.html#net_server_address
576
552
[ 'secureConnect' ] : #tls_event_secureconnect
577
553
[ secureConnection ] : #tls_event_secureconnection
0 commit comments