@ -36,6 +36,7 @@ const Timer = process.binding('timer_wrap').Timer;
const tls_wrap = process . binding ( 'tls_wrap' ) ;
const TCP = process . binding ( 'tcp_wrap' ) . TCP ;
const Pipe = process . binding ( 'pipe_wrap' ) . Pipe ;
const errors = require ( 'internal/errors' ) ;
function onhandshakestart ( ) {
debug ( 'onhandshakestart' ) ;
@ -59,7 +60,7 @@ function onhandshakestart() {
// state machine and OpenSSL is not re-entrant. We cannot allow the user's
// callback to destroy the connection right now, it would crash and burn.
setImmediate ( function ( ) {
var err = new Error ( 'TLS session renegotiation attack detected ' ) ;
var err = new errors . Error ( 'ERR_TLS_SESSION_ATTACK ' ) ;
self . _ emitTLSError ( err ) ;
} ) ;
}
@ -77,14 +78,14 @@ function loadSession(self, hello, cb) {
var once = false ;
function onSession ( err , session ) {
if ( once )
return cb ( new Error ( 'TLS session callback was called 2 times ') ) ;
return cb ( new errors . Error ( 'ERR_MULTIPLE_CALLBACK ') ) ;
once = true ;
if ( err )
return cb ( err ) ;
if ( ! self . _ handle )
return cb ( new Error ( 'Socket is closed ' ) ) ;
return cb ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
self . _ handle . loadSession ( session ) ;
cb ( null ) ;
@ -106,14 +107,14 @@ function loadSNI(self, servername, cb) {
var once = false ;
self . _ SNICallback ( servername , function ( err , context ) {
if ( once )
return cb ( new Error ( 'TLS SNI callback was called 2 times ' ) ) ;
return cb ( new errors . Error ( 'ERR_MULTIPLE_CALLBACK ' ) ) ;
once = true ;
if ( err )
return cb ( err ) ;
if ( ! self . _ handle )
return cb ( new Error ( 'Socket is closed ' ) ) ;
return cb ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
// TODO(indutny): eventually disallow raw `SecureContext`
if ( context )
@ -152,14 +153,14 @@ function requestOCSP(self, hello, ctx, cb) {
var once = false ;
function onOCSP ( err , response ) {
if ( once )
return cb ( new Error ( 'TLS OCSP callback was called 2 times ' ) ) ;
return cb ( new errors . Error ( 'ERR_MULTIPLE_CALLBACK ' ) ) ;
once = true ;
if ( err )
return cb ( err ) ;
if ( ! self . _ handle )
return cb ( new Error ( 'Socket is closed ' ) ) ;
return cb ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
if ( response )
self . _ handle . setOCSPResponse ( response ) ;
@ -192,7 +193,7 @@ function oncertcb(info) {
return self . destroy ( err ) ;
if ( ! self . _ handle )
return self . destroy ( new Error ( 'Socket is closed ' ) ) ;
return self . destroy ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
try {
self . _ handle . certCbDone ( ) ;
@ -221,7 +222,7 @@ function onnewsession(key, session) {
once = true ;
if ( ! self . _ handle )
return self . destroy ( new Error ( 'Socket is closed ' ) ) ;
return self . destroy ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
self . _ handle . newSessionDone ( ) ;
@ -552,7 +553,7 @@ TLSSocket.prototype.renegotiate = function(options, callback) {
}
if ( ! this . _ handle . renegotiate ( ) ) {
if ( callback ) {
process . nextTick ( callback , new Error ( 'Failed to renegotiate ' ) ) ;
process . nextTick ( callback , new errors . Error ( 'ERR_TLS_RENEGOTIATE ' ) ) ;
}
return false ;
}
@ -578,7 +579,7 @@ TLSSocket.prototype.getTLSTicket = function getTLSTicket() {
} ;
TLSSocket . prototype . _ handleTimeout = function ( ) {
this . _ emitTLSError ( new Error ( 'TLS handshake timeout ' ) ) ;
this . _ emitTLSError ( new errors . Error ( 'ERR_TLS_HANDSHAKE_TIMEOUT ' ) ) ;
} ;
TLSSocket . prototype . _ emitTLSError = function ( err ) {
@ -780,7 +781,7 @@ function Server(options, listener) {
} else if ( options == null || typeof options === 'object' ) {
options = options || { } ;
} else {
throw new TypeError ( 'options must be an object' ) ;
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'options' , ' object' ) ;
}
@ -811,7 +812,7 @@ function Server(options, listener) {
var timeout = options . handshakeTimeout || ( 120 * 1000 ) ;
if ( typeof timeout !== 'number' ) {
throw new TypeError ( 'handshakeTimeout must be a number' ) ;
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'timeout' , ' number' ) ;
}
if ( self . sessionTimeout ) {
@ -949,7 +950,7 @@ Server.prototype.setOptions = function(options) {
// SNI Contexts High-Level API
Server . prototype . addContext = function ( servername , context ) {
if ( ! servername ) {
throw new Error ( '"servername" is required parameter for Server.addContext ') ;
throw new errors . Error ( 'ERR_TLS_REQUIRED_SERVER_NAME ') ;
}
var re = new RegExp ( '^' +
@ -1088,8 +1089,7 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) {
// specified in options.
var ekeyinfo = socket . getEphemeralKeyInfo ( ) ;
if ( ekeyinfo . type === 'DH' && ekeyinfo . size < options . minDHSize ) {
var err = new Error ( 'DH parameter size ' + ekeyinfo . size +
' is less than ' + options . minDHSize ) ;
var err = new errors . Error ( 'ERR_TLS_DH_PARAM_SIZE' , ekeyinfo . size ) ;
socket . emit ( 'error' , err ) ;
socket . destroy ( ) ;
return ;