Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: automatically generating certs if not provided (Waku Canary) #2408

Merged

Conversation

gabrielmer
Copy link
Contributor

Description

Automatically generating a self signed certificate in Waku Canary if not provided and WSS is used.

Notice that the keys and certificate are generated only if OpenSSL is installed. It comes preinstalled in Ubuntu, other common Linux distributions and MacOS.
If openssl command is not available and certificates are not provided, an error message is shown.

Changes

  • generating key and certificate if needed and not provided

How to test

  1. Build Waku Canary: make wakucanary
  2. Run it on a WSS address without setting certificates: ./build/wakucanary --address=/dns4/node-01.gc-us-central1-a.status.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmGDX3iAFox93PupVYaHa88kULGqMpJ7AEHGwj3jbMtt76 --protocol=relay

Issue

closes #2349

Copy link

github-actions bot commented Feb 8, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2408

Built from fe82558

@@ -24,6 +26,7 @@ const ProtocolsTable = {
}.toTable

const WebSocketPortOffset = 1000
const CertsDirectory = "./apps/wakucanary/certs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would either make this configurable, or used some more general path like ./certs or ./self-signed-certs - WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Wasn't sure what was the best approach. Didn't want to make it configurable so we don't require another CLI flag (the whole idea is for this to happen under the hood/on its own). Also wanted to keep it inside the wakucanary directory so it doesn't mix with other stuff.

So I assumed that the instructions are being followed literally and it would be run from the root of the repo.

But makes sense, maybe it's better to store the certs in the directory where the executable is run, and avoid errors if it's run from a different place. Fixing it now :)

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

My only concert about self-signed certificate is whether the nwaku node would accept a connection from that. I think it worth to try it, if not done already.

@gabrielmer
Copy link
Contributor Author

LGTM! Thanks!

My only concert about self-signed certificate is whether the nwaku node would accept a connection from that. I think it worth to try it, if not done already.

Yes! It seems to be accepted :)

Ran wakucanary trying to contact one of our fleets with that certificate and the connection was successful

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@chaitanyaprem chaitanyaprem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for the comment.


# Command to generate private key and cert
let
cmd = "openssl req -x509 -newkey rsa:4096 -keyout " & keyPath & " -out " & certPath &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we leave the CN=CommonNameOrHostname like this, it may cause problems in case a node is validating the certificate. Can we pick this up from either system's domain name or public IP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Just changed it :)

Now we use the public IP and if for some reason it cannot be retrieved then "127.0.0.1" is used.
With domain name is more problematic as we want for it to be automatic and not require any input from the user, so public IP is used instead.

WDYT?

@gabrielmer gabrielmer force-pushed the chore-automatically-generating-certificates-for-wakucanary branch from cac0dbb to aab8b00 Compare February 12, 2024 08:46
@gabrielmer gabrielmer merged commit 849d76d into master Feb 12, 2024
9 of 10 checks passed
@gabrielmer gabrielmer deleted the chore-automatically-generating-certificates-for-wakucanary branch February 12, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: wakucanary requires key path to test client connections
5 participants