@@ -934,49 +934,24 @@ The `callback` function, if specified, will be added as a listener for the
934
934
935
935
` tls.connect() ` returns a [ ` tls.TLSSocket ` ] [ ] object.
936
936
937
- Here is an example of a client of echo server as described in
937
+ The following illustrates a client for the echo server example from
938
938
[ ` tls.createServer() ` ] [ ] :
939
939
940
940
``` js
941
- // This example assumes that you have created an echo server that is
942
- // listening on port 8000.
941
+ // Assumes an echo server that is listening on port 8000.
943
942
const tls = require (' tls' );
944
943
const fs = require (' fs' );
945
944
946
945
const options = {
947
- // Necessary only if using the client certificate authentication
946
+ // Necessary only if the server requires client certificate authentication.
948
947
key: fs .readFileSync (' client-key.pem' ),
949
948
cert: fs .readFileSync (' client-cert.pem' ),
950
949
951
- // Necessary only if the server uses the self-signed certificate
952
- ca: [ fs .readFileSync (' server-cert.pem' ) ]
953
- };
950
+ // Necessary only if the server uses a self-signed certificate.
951
+ ca: [ fs .readFileSync (' server-cert.pem' ) ],
954
952
955
- const socket = tls .connect (8000 , options, () => {
956
- console .log (' client connected' ,
957
- socket .authorized ? ' authorized' : ' unauthorized' );
958
- process .stdin .pipe (socket);
959
- process .stdin .resume ();
960
- });
961
- socket .setEncoding (' utf8' );
962
- socket .on (' data' , (data ) => {
963
- console .log (data);
964
- });
965
- socket .on (' end' , () => {
966
- console .log (' client ends' );
967
- });
968
- ```
969
-
970
- Or
971
-
972
- ``` js
973
- // This example assumes that you have created an echo server that is
974
- // listening on port 8000.
975
- const tls = require (' tls' );
976
- const fs = require (' fs' );
977
-
978
- const options = {
979
- pfx: fs .readFileSync (' client.pfx' )
953
+ // Necessary only if the server's cert isn't for "localhost".
954
+ checkServerIdentity : () => { return null ; },
980
955
};
981
956
982
957
const socket = tls .connect (8000 , options, () => {
@@ -990,7 +965,7 @@ socket.on('data', (data) => {
990
965
console .log (data);
991
966
});
992
967
socket .on (' end' , () => {
993
- console .log (' client ends' );
968
+ console .log (' server ends connection ' );
994
969
});
995
970
```
996
971
@@ -1213,10 +1188,10 @@ const options = {
1213
1188
key: fs .readFileSync (' server-key.pem' ),
1214
1189
cert: fs .readFileSync (' server-cert.pem' ),
1215
1190
1216
- // This is necessary only if using the client certificate authentication.
1191
+ // This is necessary only if using client certificate authentication.
1217
1192
requestCert: true ,
1218
1193
1219
- // This is necessary only if the client uses the self-signed certificate.
1194
+ // This is necessary only if the client uses a self-signed certificate.
1220
1195
ca: [ fs .readFileSync (' client-cert.pem' ) ]
1221
1196
};
1222
1197
@@ -1232,36 +1207,8 @@ server.listen(8000, () => {
1232
1207
});
1233
1208
```
1234
1209
1235
- Or
1236
-
1237
- ``` js
1238
- const tls = require (' tls' );
1239
- const fs = require (' fs' );
1240
-
1241
- const options = {
1242
- pfx: fs .readFileSync (' server.pfx' ),
1243
-
1244
- // This is necessary only if using the client certificate authentication.
1245
- requestCert: true ,
1246
- };
1247
-
1248
- const server = tls .createServer (options, (socket ) => {
1249
- console .log (' server connected' ,
1250
- socket .authorized ? ' authorized' : ' unauthorized' );
1251
- socket .write (' welcome!\n ' );
1252
- socket .setEncoding (' utf8' );
1253
- socket .pipe (socket);
1254
- });
1255
- server .listen (8000 , () => {
1256
- console .log (' server bound' );
1257
- });
1258
- ```
1259
-
1260
- This server can be tested by connecting to it using ` openssl s_client ` :
1261
-
1262
- ``` sh
1263
- openssl s_client -connect 127.0.0.1:8000
1264
- ```
1210
+ The server can be tested by connecting to it using the example client from
1211
+ [ ` tls.connect() ` ] [ ] .
1265
1212
1266
1213
## tls.getCiphers()
1267
1214
<!-- YAML
0 commit comments