News for hackers. Stuff that matters.
Re:CertBot: Automatically enable HTTPS on your website with ... by exratione on Monday May 16, 2016 @09:56AM (#11706257)
This example script assumes that the server has a running webserver, either Apache or Nginx. Since it doesn't use a package install for Certbot, this script should work on most Linux distributions. It installs Certbot, obtains the certificate, and sets up the cron task for renewal.

---

  #!/bin/bash
  #
  # This sets up Let's Encrypt SSL certificates and automatic renewal
  # using certbot: https://certbot.eff.org
  #
  # - Run this script as root.
  # - A webserver must be up and running.
  #
  # Certificate files are placed into subdirectories under
  # /etc/letsencrypt/live/*.
  #
  # Configuration must then be updated for the systems using the
  # certificates.
  #
  # The certbot-auto program logs to /var/log/letsencrypt.
  #

  set -o nounset
  set -o errexit

  # May or may not have HOME set, and this drops stuff into ~/.local.
  export HOME="/root"
  export
  PATH="${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

  # No package install yet.
  wget https://dl.eff.org/certbot-auto
  chmod a+x certbot-auto
  mv certbot-auto /usr/local/bin

  # Install the dependencies.
  certbot-auto --noninteractive --os-packages-only

  # Set up config file.
  mkdir -p /etc/letsencrypt
  cat > /etc/letsencrypt/cli.ini <<EOF
  # Uncomment to use the staging/testing server - avoids rate limiting.
  # server = https://acme-staging.api.letsencrypt.org/directory

  # Use a 4096 bit RSA key instead of 2048.
  rsa-key-size = 4096

  # Set email and domains.
  email = [email protected]
  domains = example.com, www.example.com

  # Text interface.
  text = True
  # No prompts.
  non-interactive = True
  # Suppress the Terms of Service agreement interaction.
  agree-tos = True

  # Use the webroot authenticator.
  authenticator = webroot
  webroot-path = /var/www/html
  EOF

  # Obtain cert.
  certbot-auto certonly

  # Set up daily cron job.
  CRON_SCRIPT="/etc/cron.daily/certbot-renew"

  cat > "${CRON_SCRIPT}" <<EOF
  #!/bin/bash
  #
  # Renew the Let's Encrypt certificate if it is time. It won't do anything if
  # not.
  #
  # This reads the standard /etc/letsencrypt/cli.ini.
  #

  # May or may not have HOME set, and this drops stuff into ~/.local.
  export HOME="/root"
  # PATH is never what you want it it to be in cron.
  export
  PATH="\${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

  certbot-auto --no-self-upgrade certonly

  # If the cert updated, we need to update the services using it. E.g.:
  if service --status-all | grep -Fq 'apache2'; then
     service apache2 reload
  fi
  if service --status-all | grep -Fq 'httpd'; then
     service httpd reload
  fi
  if service --status-all | grep -Fq 'nginx'; then
     service nginx reload
  fi
  EOF
  chmod a+x "${CRON_SCRIPT}"
---
Re:CertBot: Automatically enable HTTPS on your website with ... by pde3 on Monday May 16, 2016 @08:49PM (#11710666)
A couple of suggestions based on recent (0.5.0+) Certbot features:

1. You can now do certbot certonly --post-hook "service XYZ reload" to run something if and only if certs were obtained / renewed. Or if you use the renew verb, you can use --renew-hook to get a callback for each renewed cert individually. See certbot --help renew for details.

2. You can set "quiet = True" to minimize output from the client (but see https://github.com/certbot/certbot/issues/2990)

Re:CertBot: Automatically enable HTTPS on your website with ... by nailer on Monday May 16, 2016 @10:32AM (#11706499)
Unless your whole chain is 4096 bit - which is unlikely - a 4096 bit RSA key just adds a little latency.
Re:CertBot: Automatically enable HTTPS on your website with ... by tombrossman on Monday May 16, 2016 @03:07PM (#11708766)
It's probably more than 'a little' latency, try:

openssl speed rsa2048 rsa4096

on your server for what is probably going to be a rude awakening. For a small, low-traffic site you might be able to manage but as traffic increases you are probably going to regret choosing 4096 bit certs unless you absolutely need them for a specific reason.

Re:CertBot: Automatically enable HTTPS on your website with ... by davidcollantes on Monday May 16, 2016 @11:09AM (#11706762)
You will not get an A+[0] without 4096.

[0] https://www.ssllabs.com/ssltest/

Re:CertBot: Automatically enable HTTPS on your website with ... by finnn on Monday May 16, 2016 @01:57PM (#11708160)
That is not true[0]. I have no idea why you think that's the case, I've never seen that anywhere.

[0] https://www.ssllabs.com/ssltest/analyze.html?d=finn.io

Re:CertBot: Automatically enable HTTPS on your website with ... by nailer on Monday May 16, 2016 @01:59PM (#11708173)
In defence of davidcollantes I think it used to be the case a year ago.
Re:CertBot: Automatically enable HTTPS on your website with ... by finnn on Monday May 16, 2016 @02:06PM (#11708231)
How long ago? I've had an A+ with a 2048 bit cert for years (I think... there's a small chance I used to have a 4096 bit cert before LE came out)
Re:CertBot: Automatically enable HTTPS on your website with ... by nailer on Monday May 16, 2016 @03:18PM (#11708844)
OK it's was never required for A+, but it was required for one of the individual scores: straight from the horse's mouth: https://news.ycombinator.com/item?id=11708830
Re:CertBot: Automatically enable HTTPS on your website with ... by davidcollantes on Monday May 16, 2016 @11:05AM (#11706739)
Nice script, thanks!

Will this work for multiple domains? If so, is it just a matter to add them to the "domains" variable?

Re:CertBot: Automatically enable HTTPS on your website with ... by exratione on Monday May 16, 2016 @11:35AM (#11706952)
For multiple domains, you have to validate each one separately via the webroot method unless they are all getting served from the same webroot.

If it is all the same webroot, then yes, add them all to the domains variable.

If different webroots you might need to use the command line, which lets you run

--w /x/y/z -d example1.com --w /a/b/c -d example2.com

in one command. I'm not sure how to make that work in the configuration file, though I'm sure there's a way.