Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Webterminal: Added SSL support with existing LE certificates. #130

Merged
merged 9 commits into from
Mar 13, 2018
Merged

Webterminal: Added SSL support with existing LE certificates. #130

merged 9 commits into from
Mar 13, 2018

Conversation

ludeeus
Copy link
Member

@ludeeus ludeeus commented Mar 4, 2018

Description:

This add the option to use existing Let's Encrypt certificates.

Tested with:

  • Generated with Dehydrated. (DuckDNS script) tested by @ludeeus
  • Generated with certbot. Simulated testing bt @ludeeus, se comment, this should work.

Related issue (if applicable): Fixes #74

Checklist:

  • The code change is tested and works locally.
  • Script has validation check of the job.

If pertinent:

  • Created/Updated documentation at /docs

image

FULLCHAIN=$(find "$CERTDIR" -type f | grep fullchain)
PRIVKEY=$(find "$CERTDIR" -type f | grep privkey)
DOMAIN=$(ls "$CERTDIR")
cat $FULLCHAIN $PRIVKEY > /var/lib/shellinabox/certificate-"$DOMAIN".pem

Choose a reason for hiding this comment

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

Double quote to prevent globbing and word splitting.

PRIVKEY=$(find "$CERTDIR" -type f | grep privkey)
DOMAIN=$(ls "$CERTDIR")
echo "Merging files and adding to correct dir..."
cat $FULLCHAIN $PRIVKEY > /var/lib/shellinabox/certificate-"$DOMAIN".pem

Choose a reason for hiding this comment

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

Double quote to prevent globbing and word splitting.

@ludeeus ludeeus added this to the v0.8.0 milestone Mar 4, 2018
@ludeeus ludeeus added this to To do in v0.8.0 via automation Mar 4, 2018
@ludeeus ludeeus moved this from To do to In progress in v0.8.0 Mar 4, 2018
@ludeeus
Copy link
Member Author

ludeeus commented Mar 4, 2018

@juan11perez Can you test this with your certificates generated with the certbot?

Copy link
Collaborator

@Landrash Landrash left a comment

Choose a reason for hiding this comment

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

Question is if we want to copy the certificate or if you should try to link the certificate instead.

#### Notes for SSL
If you enable the use of existing Let's Encrypt certificates you need to open ports in your firewall to use them.

If SSL is used the panel_iframe has to use your domain.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use the same domain.

FULLCHAIN=$(find "$CERTDIR" -type f | grep fullchain)
PRIVKEY=$(find "$CERTDIR" -type f | grep privkey)
DOMAIN=$(ls "$CERTDIR")
cat "$FULLCHAIN" "$PRIVKEY" > /var/lib/shellinabox/certificate-"$DOMAIN".pem
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doing it this way would not link the cert but only "copy" it. Preferable would be to create a symlink to the certificate so that it's linked to the used certificate.

Copy link
Member Author

@ludeeus ludeeus Mar 7, 2018

Choose a reason for hiding this comment

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

In every guide I have found, and my own testing. the cert file used for shellinabox has to include both certificate and privkey, is it possible to merge with linking?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed that. That would require some strange magic.
Most likely this will stop working as soon as the certificate expires. If your ok with that then we can merge this.
Could you add to the update function to update the certificate if it's there?

Copy link
Member Author

@ludeeus ludeeus Mar 7, 2018

Choose a reason for hiding this comment

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

I hope not :( that defeats the purpose of the separate webterminalhelper.sh script..
Should't this update the cert for shellinabox 1AM every night?
looking at the timestamp after running the file it looks like that would work.
image
I can add a note about running that file in the docs?

"Could you add to the update function to update the certificate if it's there?"
Do you mean the update for dehydrated with the DuckDNS script, then no. that will result in certbot certs not being updated.
If this was not what you ment, enlighten me :D

Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed that part of the webterminalhepler.sh script.

This look great now!

Landrash
Landrash previously approved these changes Mar 8, 2018
Copy link
Collaborator

@Landrash Landrash left a comment

Choose a reason for hiding this comment

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

Looks good to me.
Ready to merge? If so remove the WIP tag :)

@ludeeus
Copy link
Member Author

ludeeus commented Mar 8, 2018

I still want someone that can use certbot certs to verify this before er merge.

@juan11perez
Copy link

@ludeeus i'll pull out my Pi and test it. I still have a valid installation, I think ;-)
where do I get the script from ?

@ludeeus
Copy link
Member Author

ludeeus commented Mar 8, 2018

@juan11perez Great!
Its in this PR, but hit me up on discord and I can help you :)

@juan11perez
Copy link

@ludeeus ok, give me about half hour and ill contact you in discord

@ludeeus
Copy link
Member Author

ludeeus commented Mar 10, 2018

Steps for testing this:
First upgrade hassbian-config to dev:

sudo hassbian-config upgrade hassbian-script && sudo hassbian-config upgrade hassbian-script-dev

Then download the new files:

sudo curl -o /opt/hassbian/suites/webterminal.sh https://raw.githubusercontent.com/ludeeus/hassbian-scripts/webterminal-ssl/package/opt/hassbian/suites/webterminal.sh && sudo curl -o /opt/hassbian/suites/files/webterminalhelper.sh https://raw.githubusercontent.com/ludeeus/hassbian-scripts/webterminal-ssl/package/opt/hassbian/suites/files/webterminalsslhelper.sh

Then run it:

sudo hassbian-config install webterminal --force

If you at an earlier time have installed webterminal, you need to change the settings for it:
sudo nano /etc/default/shellinabox
Change SHELLINABOX_ARGS="--no-beep --disable-ssl" to SHELLINABOX_ARGS="--no-beep"

Landrash
Landrash previously approved these changes Mar 10, 2018
@juan11perez
Copy link

@ludeeus not working. see entire process
https://hastebin.com/xuwajoheci.erl

@ludeeus ludeeus changed the title WIP: Added SSL support with existing LE certificates. Webterminal: Added SSL support with existing LE certificates. Mar 11, 2018
@ludeeus
Copy link
Member Author

ludeeus commented Mar 11, 2018

I added my fulchain.pem and privkey.pem to an folder named /etc/letsencrypt/live/mydomain.com/
It ran the script and used those cert files.
This make me belive that this will work with certbot certs also.
@Landrash I have now removed WIP, can you take a check on this now? :D

Copy link
Collaborator

@Landrash Landrash left a comment

Choose a reason for hiding this comment

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

Looks good to me.
Great job!

@Landrash Landrash merged commit f43eb30 into home-assistant:dev Mar 13, 2018
v0.8.0 automation moved this from In progress to Done Mar 13, 2018
@ludeeus ludeeus deleted the webterminal-ssl branch March 13, 2018 11:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
v0.8.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants