2017-01-03 22:16:48 +01:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-31 00:38:06 +01:00
|
|
|
const common = require('../common');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
2017-07-01 01:29:09 +02:00
|
|
|
if (!common.hasCrypto)
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('missing crypto');
|
2013-12-09 16:47:55 +01:00
|
|
|
|
2017-07-01 01:29:09 +02:00
|
|
|
const tls = require('tls');
|
2017-07-18 00:33:46 +02:00
|
|
|
const fixtures = require('../common/fixtures');
|
2013-12-09 16:47:55 +01:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const server = tls.createServer({
|
2017-07-18 00:33:46 +02:00
|
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
|
|
cert: fixtures.readKey('agent1-cert.pem')
|
2013-12-09 16:47:55 +01:00
|
|
|
}, function(c) {
|
|
|
|
// Send close-notify without shutting down TCP socket
|
stream_base: introduce StreamBase
StreamBase is an improved way to write C++ streams. The class itself is
for separting `StreamWrap` (with the methods like `.writeAsciiString`,
`.writeBuffer`, `.writev`, etc) from the `HandleWrap` class, making
possible to write abstract C++ streams that are not bound to any uv
socket.
The following methods are important part of the abstraction (which
mimics libuv's stream API):
* Events:
* `OnAlloc(size_t size, uv_buf_t*)`
* `OnRead(ssize_t nread, const uv_buf_t*, uv_handle_type pending)`
* `OnAfterWrite(WriteWrap*)`
* Wrappers:
* `DoShutdown(ShutdownWrap*)`
* `DoTryWrite(uv_buf_t** bufs, size_t* count)`
* `DoWrite(WriteWrap*, uv_buf_t*, size_t count, uv_stream_t* handle)`
* `Error()`
* `ClearError()`
The implementation should provide all of these methods, thus providing
the access to the underlying resource (be it uv handle, TLS socket, or
anything else).
A C++ stream may consume the input of another stream by replacing the
event callbacks and proxying the writes. This kind of API is actually
used now for the TLSWrap implementation, making it possible to wrap TLS
stream into another TLS stream. Thus legacy API calls are no longer
required in `_tls_wrap.js`.
PR-URL: https://github.com/iojs/io.js/pull/840
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-02-22 19:59:07 +01:00
|
|
|
if (c._handle.shutdownSSL() !== 1)
|
|
|
|
c._handle.shutdownSSL();
|
2016-07-15 21:43:24 +02:00
|
|
|
}).listen(0, common.mustCall(function() {
|
2017-01-08 14:19:00 +01:00
|
|
|
const c = tls.connect(this.address().port, {
|
2013-12-09 16:47:55 +01:00
|
|
|
rejectUnauthorized: false
|
2016-07-15 21:43:24 +02:00
|
|
|
}, common.mustCall(function() {
|
2013-12-09 16:47:55 +01:00
|
|
|
// Ensure that we receive 'end' event anyway
|
2016-07-15 21:43:24 +02:00
|
|
|
c.on('end', common.mustCall(function() {
|
2013-12-09 16:47:55 +01:00
|
|
|
c.destroy();
|
|
|
|
server.close();
|
2016-07-15 21:43:24 +02:00
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|