@@ -36,6 +36,7 @@ const Timer = process.binding('timer_wrap').Timer;
36
36
const tls_wrap = process . binding ( 'tls_wrap' ) ;
37
37
const TCP = process . binding ( 'tcp_wrap' ) . TCP ;
38
38
const Pipe = process . binding ( 'pipe_wrap' ) . Pipe ;
39
+ const errors = require ( 'internal/errors' ) ;
39
40
40
41
function onhandshakestart ( ) {
41
42
debug ( 'onhandshakestart' ) ;
@@ -59,7 +60,7 @@ function onhandshakestart() {
59
60
// state machine and OpenSSL is not re-entrant. We cannot allow the user's
60
61
// callback to destroy the connection right now, it would crash and burn.
61
62
setImmediate ( function ( ) {
62
- var err = new Error ( 'TLS session renegotiation attack detected ' ) ;
63
+ var err = new errors . Error ( 'ERR_TLS_SESSION_ATTACK ' ) ;
63
64
self . _emitTLSError ( err ) ;
64
65
} ) ;
65
66
}
@@ -77,14 +78,14 @@ function loadSession(self, hello, cb) {
77
78
var once = false ;
78
79
function onSession ( err , session ) {
79
80
if ( once )
80
- return cb ( new Error ( 'TLS session callback was called 2 times ' ) ) ;
81
+ return cb ( new errors . Error ( 'ERR_MULTIPLE_CALLBACK ' ) ) ;
81
82
once = true ;
82
83
83
84
if ( err )
84
85
return cb ( err ) ;
85
86
86
87
if ( ! self . _handle )
87
- return cb ( new Error ( 'Socket is closed ' ) ) ;
88
+ return cb ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
88
89
89
90
self . _handle . loadSession ( session ) ;
90
91
cb ( null ) ;
@@ -106,14 +107,14 @@ function loadSNI(self, servername, cb) {
106
107
var once = false ;
107
108
self . _SNICallback ( servername , function ( err , context ) {
108
109
if ( once )
109
- return cb ( new Error ( 'TLS SNI callback was called 2 times ' ) ) ;
110
+ return cb ( new errors . Error ( 'ERR_MULTIPLE_CALLBACK ' ) ) ;
110
111
once = true ;
111
112
112
113
if ( err )
113
114
return cb ( err ) ;
114
115
115
116
if ( ! self . _handle )
116
- return cb ( new Error ( 'Socket is closed ' ) ) ;
117
+ return cb ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
117
118
118
119
// TODO(indutny): eventually disallow raw `SecureContext`
119
120
if ( context )
@@ -152,14 +153,14 @@ function requestOCSP(self, hello, ctx, cb) {
152
153
var once = false ;
153
154
function onOCSP ( err , response ) {
154
155
if ( once )
155
- return cb ( new Error ( 'TLS OCSP callback was called 2 times ' ) ) ;
156
+ return cb ( new errors . Error ( 'ERR_MULTIPLE_CALLBACK ' ) ) ;
156
157
once = true ;
157
158
158
159
if ( err )
159
160
return cb ( err ) ;
160
161
161
162
if ( ! self . _handle )
162
- return cb ( new Error ( 'Socket is closed ' ) ) ;
163
+ return cb ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
163
164
164
165
if ( response )
165
166
self . _handle . setOCSPResponse ( response ) ;
@@ -192,7 +193,7 @@ function oncertcb(info) {
192
193
return self . destroy ( err ) ;
193
194
194
195
if ( ! self . _handle )
195
- return self . destroy ( new Error ( 'Socket is closed ' ) ) ;
196
+ return self . destroy ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
196
197
197
198
try {
198
199
self . _handle . certCbDone ( ) ;
@@ -221,7 +222,7 @@ function onnewsession(key, session) {
221
222
once = true ;
222
223
223
224
if ( ! self . _handle )
224
- return self . destroy ( new Error ( 'Socket is closed ' ) ) ;
225
+ return self . destroy ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
225
226
226
227
self . _handle . newSessionDone ( ) ;
227
228
@@ -552,7 +553,7 @@ TLSSocket.prototype.renegotiate = function(options, callback) {
552
553
}
553
554
if ( ! this . _handle . renegotiate ( ) ) {
554
555
if ( callback ) {
555
- process . nextTick ( callback , new Error ( 'Failed to renegotiate ' ) ) ;
556
+ process . nextTick ( callback , new errors . Error ( 'ERR_TLS_RENEGOTIATE ' ) ) ;
556
557
}
557
558
return false ;
558
559
}
@@ -578,7 +579,7 @@ TLSSocket.prototype.getTLSTicket = function getTLSTicket() {
578
579
} ;
579
580
580
581
TLSSocket . prototype . _handleTimeout = function ( ) {
581
- this . _emitTLSError ( new Error ( 'TLS handshake timeout ' ) ) ;
582
+ this . _emitTLSError ( new errors . Error ( 'ERR_TLS_HANDSHAKE_TIMEOUT ' ) ) ;
582
583
} ;
583
584
584
585
TLSSocket . prototype . _emitTLSError = function ( err ) {
@@ -780,7 +781,7 @@ function Server(options, listener) {
780
781
} else if ( options == null || typeof options === 'object' ) {
781
782
options = options || { } ;
782
783
} else {
783
- throw new TypeError ( 'options must be an object' ) ;
784
+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , ' options' , ' object') ;
784
785
}
785
786
786
787
@@ -811,7 +812,7 @@ function Server(options, listener) {
811
812
var timeout = options . handshakeTimeout || ( 120 * 1000 ) ;
812
813
813
814
if ( typeof timeout !== 'number' ) {
814
- throw new TypeError ( 'handshakeTimeout must be a number' ) ;
815
+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'timeout' , ' number') ;
815
816
}
816
817
817
818
if ( self . sessionTimeout ) {
@@ -949,7 +950,7 @@ Server.prototype.setOptions = function(options) {
949
950
// SNI Contexts High-Level API
950
951
Server . prototype . addContext = function ( servername , context ) {
951
952
if ( ! servername ) {
952
- throw new Error ( '"servername" is required parameter for Server.addContext ' ) ;
953
+ throw new errors . Error ( 'ERR_TLS_REQUIRED_SERVER_NAME ' ) ;
953
954
}
954
955
955
956
var re = new RegExp ( '^' +
@@ -1088,8 +1089,7 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) {
1088
1089
// specified in options.
1089
1090
var ekeyinfo = socket . getEphemeralKeyInfo ( ) ;
1090
1091
if ( ekeyinfo . type === 'DH' && ekeyinfo . size < options . minDHSize ) {
1091
- var err = new Error ( 'DH parameter size ' + ekeyinfo . size +
1092
- ' is less than ' + options . minDHSize ) ;
1092
+ var err = new errors . Error ( 'ERR_TLS_DH_PARAM_SIZE' , ekeyinfo . size ) ;
1093
1093
socket . emit ( 'error' , err ) ;
1094
1094
socket . destroy ( ) ;
1095
1095
return ;
0 commit comments