Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Documentation does not provide an SSL-friendly setup. #238

Closed
@0xjjpa

Description

@0xjjpa

When following 0.27.x libp2p in the browser example, the README describes how to run a signalling server and even points you to this repository (i.e. js-libp2p-webrtc-star). If you run the server (e.g. docker run -p 9090:9090 libp2p/js-libp2p-webrtc-star) and then connect locally (e.g. http://localhost:1234 from parcel index.html), you can see the application up and running. All good so far!

However, whenever you are trying to run the demo behind SSL (e.g. using an online service like Glitch.com or via remote desktop), you will be presented with an SSL error similar to the following one:

Mixed Content: The page at 'https://endurable-eggplant-parmesan.glitch.me/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://34.65.51.50:9090/socket.io/?EIO=3&transport=websocket'. This request has been blocked; this endpoint must be available over WSS.

You can also find the same error if you run parcel index.html --https instead, which is closer to a production setup. In addition, if you try to connect via the browser using a non-local http application, you'll see something like this:

webcrypto.js:12 Uncaught (in promise) Error: Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p-crypto/blob/master/README.md#web-crypto-api
    at Object.exports.get (webcrypto.js:12)
    at Object.exports.generateKey (rsa-browser.js:10)
    at Object.generateKeyPair (rsa-class.js:154)
    at Object.exports.generateKeyPair (index.js:41)
    at Function.exports.create (index.js:207)
    at Function.PeerInfo.create (index.js:47)
    at Function.create (index.js:528)
    at HTMLDocument.<anonymous> (index.js:11)

This can be avoided by providing some instructions to users on how to setup an SSL reverse proxy. For instance, locally one can setup nginx/proxy with a docker-compose.yml file as follows:

version: '3'
services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./nginx/certs:/etc/nginx/certs
    depends_on:
      - web

  web:
    image: libp2p/js-libp2p-webrtc-star
    environment:
      - VIRTUAL_HOST=localdomain.test
      - VIRTUAL_PORT=9090

Where nginx/certs with the following commands:

$ mkcert localdomain.test
$ mkdir -p nginx/certs
$ cp localdomain.test-key.pem nginx/certs/localdomain.test.key
$ cp localdomain.test.pem nginx/certs/localdomain.test.crt
$ sudo -- sh -c "echo '127.0.0.1 localdomain.test' >> /etc/hosts"

The nginx/certs would look something like this:

➜  $ tree nginx
nginx
└── certs
    ├── hopr.test.crt
    └── hopr.test.key

After running docker-compose up users would see something like the following:
image

which can then be used as the actual server.

A similar setup can be achieved on a live server. Either way, it would be ideal if these instructions could be described in your README so beginners could connect easily and check the capabilities of libp2p in the browser. If you think this would be useful, I can happily send a PR with the instructions for the README in addition on how to achieve this on production using something like LE on GCP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions