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