@@ -243,6 +243,127 @@ Options:
243
243
--transfer-timeout INT Transfer timeout
244
244
```
245
245
246
- ## Cobra Client
246
+ ## Cobra client and server
247
247
248
- [ cobra] ( https://github.com/machinezone/cobra ) is a real time messenging server. ws has a sub-command to interact with cobra.
248
+ [ cobra] ( https://github.com/machinezone/cobra ) is a real time messenging server. ws has several sub-command to interact with cobra. There is also a minimal cobra compatible server named snake available.
249
+
250
+ Below are examples on running a snake server and clients with TLS enabled (the server only works with the OpenSSL backend for now).
251
+
252
+ First, generate certificates.
253
+
254
+ ```
255
+ $ cd /path/to/IXWebSocket
256
+ $ cd ixsnake/ixsnake
257
+ $ bash ../../ws/generate_certs.sh
258
+ Generating RSA private key, 2048 bit long modulus
259
+ .....+++
260
+ .................+++
261
+ e is 65537 (0x10001)
262
+ generated ./.certs/trusted-ca-key.pem
263
+ generated ./.certs/trusted-ca-crt.pem
264
+ Generating RSA private key, 2048 bit long modulus
265
+ ..+++
266
+ .......................................+++
267
+ e is 65537 (0x10001)
268
+ generated ./.certs/trusted-server-key.pem
269
+ Signature ok
270
+ subject=/O=machinezone/O=IXWebSocket/CN=trusted-server
271
+ Getting CA Private Key
272
+ generated ./.certs/trusted-server-crt.pem
273
+ Generating RSA private key, 2048 bit long modulus
274
+ ...................................+++
275
+ ..................................................+++
276
+ e is 65537 (0x10001)
277
+ generated ./.certs/trusted-client-key.pem
278
+ Signature ok
279
+ subject=/O=machinezone/O=IXWebSocket/CN=trusted-client
280
+ Getting CA Private Key
281
+ generated ./.certs/trusted-client-crt.pem
282
+ Generating RSA private key, 2048 bit long modulus
283
+ ..............+++
284
+ .......................................+++
285
+ e is 65537 (0x10001)
286
+ generated ./.certs/untrusted-ca-key.pem
287
+ generated ./.certs/untrusted-ca-crt.pem
288
+ Generating RSA private key, 2048 bit long modulus
289
+ ..........+++
290
+ ................................................+++
291
+ e is 65537 (0x10001)
292
+ generated ./.certs/untrusted-client-key.pem
293
+ Signature ok
294
+ subject=/O=machinezone/O=IXWebSocket/CN=untrusted-client
295
+ Getting CA Private Key
296
+ generated ./.certs/untrusted-client-crt.pem
297
+ Generating RSA private key, 2048 bit long modulus
298
+ .....................................................................................+++
299
+ ...........+++
300
+ e is 65537 (0x10001)
301
+ generated ./.certs/selfsigned-client-key.pem
302
+ Signature ok
303
+ subject=/O=machinezone/O=IXWebSocket/CN=selfsigned-client
304
+ Getting Private key
305
+ generated ./.certs/selfsigned-client-crt.pem
306
+ ```
307
+
308
+ Now run the snake server.
309
+
310
+ ```
311
+ $ export certs=.certs
312
+ $ ws snake --tls --port 8765 --cert-file ${certs}/trusted-server-crt.pem --key-file ${certs}/trusted-server-key.pem --ca-file ${certs}/trusted-ca-crt.pem
313
+ {
314
+ "apps": {
315
+ "FC2F10139A2BAc53BB72D9db967b024f": {
316
+ "roles": {
317
+ "_sub": {
318
+ "secret": "66B1dA3ED5fA074EB5AE84Dd8CE3b5ba"
319
+ },
320
+ "_pub": {
321
+ "secret": "1c04DB8fFe76A4EeFE3E318C72d771db"
322
+ }
323
+ }
324
+ }
325
+ }
326
+ }
327
+
328
+ redis host: 127.0.0.1
329
+ redis password:
330
+ redis port: 6379
331
+ ```
332
+
333
+ As a new connection comes in, such output should be printed
334
+
335
+ ```
336
+ [2019-12-19 20:27:19.724] [info] New connection
337
+ id: 0
338
+ Uri: /v2?appkey=_health
339
+ Headers:
340
+ Connection: Upgrade
341
+ Host: 127.0.0.1:8765
342
+ Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=15; client_max_window_bits=15
343
+ Sec-WebSocket-Key: d747B0fE61Db73f7Eh47c0==
344
+ Sec-WebSocket-Protocol: json
345
+ Sec-WebSocket-Version: 13
346
+ Upgrade: websocket
347
+ User-Agent: ixwebsocket/7.5.8 macos ssl/OpenSSL OpenSSL 1.0.2q 20 Nov 2018 zlib 1.2.11
348
+ ```
349
+
350
+ To connect and publish a message, do:
351
+
352
+ ```
353
+ $ export certs=.certs
354
+ $ cd /path/to/ws/folder
355
+ $ ls cobraMetricsSample.json
356
+ cobraMetricsSample.json
357
+ $ ws cobra_publish --endpoint wss://127.0.0.1:8765 --appkey FC2F10139A2BAc53BB72D9db967b024f --rolename _pub --rolesecret 1c04DB8fFe76A4EeFE3E318C72d771db --channel foo --cert-file ${certs}/trusted-client-crt.pem --key-file ${certs}/trusted-client-key.pem --ca-file ${certs}/trusted-ca-crt.pem cobraMetricsSample.json
358
+ [2019-12-19 20:46:42.656] [info] Publisher connected
359
+ [2019-12-19 20:46:42.657] [info] Connection: Upgrade
360
+ [2019-12-19 20:46:42.657] [info] Sec-WebSocket-Accept: rs99IFThoBrhSg+k8G4ixH9yaq4=
361
+ [2019-12-19 20:46:42.657] [info] Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=15; client_max_window_bits=15
362
+ [2019-12-19 20:46:42.657] [info] Server: ixwebsocket/7.5.8 macos ssl/OpenSSL OpenSSL 1.0.2q 20 Nov 2018 zlib 1.2.11
363
+ [2019-12-19 20:46:42.657] [info] Upgrade: websocket
364
+ [2019-12-19 20:46:42.658] [info] Publisher authenticated
365
+ [2019-12-19 20:46:42.658] [info] Published msg 3
366
+ [2019-12-19 20:46:42.659] [info] Published message id 3 acked
367
+ ```
368
+
369
+ To use OpenSSL on macOS, compile with ` make ws_openssl ` . First you will have to install OpenSSL libraries, which can be done with Homebrew.
0 commit comments