-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Feature: Enable self-signed certificates #1973
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ usage() { | |
| echo " Default: 6080 (on all interfaces)" | ||
| echo " --vnc VNC_HOST:PORT VNC server host:port proxy target" | ||
| echo " Default: localhost:5900" | ||
| echo " --self-sign hostname Generate self-signed certificates for hostname" | ||
| echo " Requires OpenSSL to be installed" | ||
blitztide marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo " --cert CERT Path to combined cert/key file, or just" | ||
| echo " the cert file if used with --key" | ||
| echo " Default: self.pem" | ||
|
|
@@ -51,6 +53,7 @@ HOST="" | |
| PORT="6080" | ||
| LISTEN="$PORT" | ||
| VNC_DEST="localhost:5900" | ||
| SELF_SIGN="" | ||
| CERT="" | ||
| KEY="" | ||
| WEB="" | ||
|
|
@@ -90,6 +93,7 @@ while [ "$*" ]; do | |
| case $param in | ||
| --listen) LISTEN="${OPTARG}"; shift ;; | ||
| --vnc) VNC_DEST="${OPTARG}"; shift ;; | ||
| --self-sign) SELF_SIGN="${OPTARG}"; shift ;; | ||
| --cert) CERT="${OPTARG}"; shift ;; | ||
| --key) KEY="${OPTARG}"; shift ;; | ||
| --web) WEB="${OPTARG}"; shift ;; | ||
|
|
@@ -128,6 +132,14 @@ if [ -z "${HOST}" ]; then | |
| fi | ||
| fi | ||
|
|
||
| # Check if (cert | key) & self-sign are set, as they are incompatible | ||
| if [ -n "$CERT" ] || [ -n "$KEY" ] && [ -n "$SELF_SIGN" ]; then | ||
| echo "Arguments --cert and --key and incompatible with --self-sign" | ||
| echo "" | ||
| usage | ||
| exit 1 | ||
| fi | ||
CendioZeijlon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| trap "cleanup" TERM QUIT INT EXIT | ||
|
|
||
| # Find vnc.html | ||
|
|
@@ -147,6 +159,29 @@ else | |
| die "Could not find vnc.html" | ||
| fi | ||
|
|
||
| # Create self-signed certificates | ||
| if [ -n "${SELF_SIGN}" ]; then | ||
| # Check if OpenSSL is installed | ||
| which openssl > /dev/null | ||
CendioZeijlon marked this conversation as resolved.
Show resolved
Hide resolved
CendioZeijlon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [ $? != 0 ]; then | ||
| echo "Unable to find OpenSSL, please ensure you have OpenSSL installed and available in \$PATH" | ||
| exit 1 | ||
| fi | ||
| # Check that the file doesn't already exist | ||
| if [ -f $(pwd)/self.pem ]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should probably check for the existence of all files that are generated by your OpenSSL command.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also allowed to set |
||
| read -p "$(pwd)/self.pem aleady exists, overwrite? (Y/N) " overwrite | ||
| if [ "$overwrite" != "Y" ]; then | ||
| echo "Not overwriting $(pwd)/self.pem" | ||
| exit 1 | ||
| fi | ||
| fi | ||
| echo "Generating Certificate for: ${SELF_SIGN}" | ||
| openssl req -x509 -newkey rsa:4096 -keyout key.pem -out self.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=NoVNC/L=NoVNC/O=NoVNC/OU=NoVNC/CN=${SELF_SIGN}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
Comment on lines
+166
to
+180
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be more convenient if Right now, if I e.g. run I know this maybe reverts parts of what you added here; sorry about that.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. --self-signed is more likely to be used in a test scenario. If you are running scripts to spawn something, then certificate management will also be used in the higher level script.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hear you, I still think forcing users to make a choice every time they run with |
||
| CERT=$(pwd)/self.pem | ||
| KEY=$(pwd)/key.pem | ||
blitztide marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
| # Find self.pem | ||
| if [ -n "${CERT}" ]; then | ||
| if [ ! -e "${CERT}" ]; then | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to not force users to provide the
hostnameargument here? If they care enough, they will probably generate a more detailed certificate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you suggest for the default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using it to point to something behind a reverse proxy, for testing, so hostname is pretty critical for this.
Once fully set up, then a proper SSL would be generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest something equally generic to the other properties like
CN=noVNC-hostor perhapsCN=${HOSTNAME}if that environment variable is set.Why is CN in the certificate important in this case?