From owner-svn-ports-head@freebsd.org Sun Jun 19 12:36:10 2016 Return-Path: Delivered-To: svn-ports-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E4C61A78E08; Sun, 19 Jun 2016 12:36:10 +0000 (UTC) (envelope-from brnrd@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A6AF6115A; Sun, 19 Jun 2016 12:36:10 +0000 (UTC) (envelope-from brnrd@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5JCa9Pl077327; Sun, 19 Jun 2016 12:36:09 GMT (envelope-from brnrd@FreeBSD.org) Received: (from brnrd@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5JCa9s0077321; Sun, 19 Jun 2016 12:36:09 GMT (envelope-from brnrd@FreeBSD.org) Message-Id: <201606191236.u5JCa9s0077321@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: brnrd set sender to brnrd@FreeBSD.org using -f From: Bernard Spil Date: Sun, 19 Jun 2016 12:36:09 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r417119 - in head/security/letskencrypt: . files X-SVN-Group: ports-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Jun 2016 12:36:11 -0000 Author: brnrd Date: Sun Jun 19 12:36:09 2016 New Revision: 417119 URL: https://svnweb.freebsd.org/changeset/ports/417119 Log: security/letskencrypt: Add periodic(8) and multi-cert capability - Add periodic script - Make Domain+SAN names and challenge-dir configurable - Add multiple Domain+SAN certificates capability using scripts - Add sample renewal script - Add sample deployment script - Add pkg-message documenting periodic.conf variables Added: head/security/letskencrypt/files/ head/security/letskencrypt/files/000.letskencrypt.sh.in (contents, props changed) head/security/letskencrypt/files/deploy.sh.sample.in (contents, props changed) head/security/letskencrypt/files/letskencrypt.sh.sample.in (contents, props changed) head/security/letskencrypt/files/pkg-message.in (contents, props changed) Modified: head/security/letskencrypt/Makefile head/security/letskencrypt/pkg-plist Modified: head/security/letskencrypt/Makefile ============================================================================== --- head/security/letskencrypt/Makefile Sun Jun 19 12:34:47 2016 (r417118) +++ head/security/letskencrypt/Makefile Sun Jun 19 12:36:09 2016 (r417119) @@ -24,16 +24,30 @@ OPENSSL_PORT= security/libressl WWWDIR= ${PREFIX}/www/letsencrypt +SAMPLE_FILES= letskencrypt.sh.sample deploy.sh.sample +SUB_FILES= 000.letskencrypt.sh pkg-message ${SAMPLE_FILES} +SUB_LIST= PORTNAME=${PORTNAME} + +PERIODIC_DIRS= etc/periodic/weekly +PERIODIC_FILES= 000.letskencrypt.sh + post-patch: ${REINPLACE_CMD} -e "s|/etc/|${PREFIX}/etc/|" \ -e "s|/var/www/letsencrypt|${WWWDIR}|" \ ${WRKSRC}/main.c ${WRKSRC}/letskencrypt.1 +post-install: + ${MKDIR} -p ${STAGEDIR}${PREFIX}/${PERIODIC_DIRS} + ${INSTALL_SCRIPT} ${WRKDIR}/${PERIODIC_FILES} ${STAGEDIR}${PREFIX}/${PERIODIC_DIRS}/${PERIODIC_FILES} + post-stage: ${STRIP_CMD} ${STAGEDIR}${PREFIX}/bin/letskencrypt . for d in etc/ssl/letsencrypt etc/ssl/letsencrypt/private \ etc/letsencrypt www/letsencrypt ${MKDIR} ${STAGEDIR}${PREFIX}/${d} . endfor +. for d in ${SAMPLE_FILES} + ${INSTALL_SCRIPT} ${WRKDIR}/${d} ${STAGEDIR}${PREFIX}/etc/letsencrypt/${d} +. endfor .include Added: head/security/letskencrypt/files/000.letskencrypt.sh.in ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/security/letskencrypt/files/000.letskencrypt.sh.in Sun Jun 19 12:36:09 2016 (r417119) @@ -0,0 +1,42 @@ +#/bin/sh + +if [ -r /etc/defaults/periodic.conf ] +then + . /etc/defaults/periodic.conf + source_periodic_confs +fi + +PATH=$PATH:%%LOCALBASE%%/bin:%%LOCALBASE%%/sbin +export PATH + +case "$weekly_letskencrypt_enable" in + [Yy][Ee][Ss]) + echo + echo "Checking Let's Encrypt certificate status:" + + if [ -x "$weekly_letskencrypt_renewscript" ] ; then + $weekly_letskencrypt_renewscript + elif [ -x %%PREFIX%%/letsencrypt/letskencrypt.sh ] ; then + %%PREFIX%%/letsencrypt/letskencrypt.sh + else + if [ -z "$weekly_letskencrypt_domains" ] ; then + weekly_letskencrypt_domains=$(hostname -f) + echo "Using hostname: $weekly_letskencrypt_domains" + fi + if [ -n "$weekly_letskencrypt_challengedir" ] ; then + weekly_letskencrypt_args="$weekly_letskencrypt_args -C $weekly_letskencrypt_challengedir" + fi + %%LOCALBASE%%/bin/letskencrypt $weekly_letskencrypt_args $weekly_letskencrypt_domains + fi + + echo "Deploying Let's Encrypt certificates:" + + if [ -x "$weekly_letskencrypt_deployscript" ] ; then + $weekly_letskencrypt_deployscript + else + echo 'Skipped, deploy script not set.' + fi + ;; + *) + ;; +esac Added: head/security/letskencrypt/files/deploy.sh.sample.in ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/security/letskencrypt/files/deploy.sh.sample.in Sun Jun 19 12:36:09 2016 (r417119) @@ -0,0 +1,37 @@ +#!/bin/sh + +set -e + +DOMAIN="example.net" +LEDIR="%%PREFIX%%/etc/ssl/letsencrypt" +JAILSDIR="/usr/jails" +TARGETS="mail http" +for jail in ${targets}; do + targetdir="${JAILSDIR}/${jail}/etc/ssl" + # Check if the certificate has changed + [[ -z "`diff -rq ${LEDIR}/${domain}/fullchain.pem ${targetdir}/certs/${domain}.pem`" ]] && continue + cp -L "${LEDIR}/private/${domain}.pem" "${targetdir}/priv/${domain}.pem" + cp -L "${LEDIR}/${domain}/fullchain.pem" "${targetdir}/certs/${domain}.pem" + chmod 400 "${targetdir}/priv/${domain}.pem" + chmod 644 "${targetdir}/certs/${domain}.pem" + # Restart/-load relevant services + [[ "${jail}" = "http" ]] && jexec ${jail} service apache24 restart + [[ "${jail}" = "mail" ]] && jexec ${jail} service smtpd restart +done + +# Repeat for other certificates +#DOMAIN="example.org" +#TARGETS="mail" +#for jail in ${targets}; do +# targetdir="${JAILSDIR}/${jail}/etc/ssl" +# # Check if the certificate has changed +# [[ -z "`diff -rq ${LEDIR}/${domain}/fullchain.pem ${targetdir}/certs/${domain}.pem`" ]] && continue +# cp -L "${LEDIR}/private/${domain}.pem" "${targetdir}/priv/${domain}.pem" +# cp -L "${LEDIR}/${domain}/fullchain.pem" "${targetdir}/certs/${domain}.pem" +# chmod 400 "${targetdir}/priv/${domain}.pem" +# chmod 644 "${targetdir}/certs/${domain}.pem" +# # Restart/-load relevant services +# [[ "${jail}" = "http" ]] && jexec ${jail} service apache24 restart +# [[ "${jail}" = "mail" ]] && jexec ${jail} service smtpd restart +#done + Added: head/security/letskencrypt/files/letskencrypt.sh.sample.in ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/security/letskencrypt/files/letskencrypt.sh.sample.in Sun Jun 19 12:36:09 2016 (r417119) @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +BASEDIR="%%PREFIX%%/etc/letsencrypt" +SSLDIR="%%PREFIX%%/etc/ssl/letsencrypt" +DOMAINSFILE="${BASEDIR}/domains.txt" +CHALLENGEDIR="/usr/jails/http/usr/local/www/.well-known/acme-challenge" + +[ ! -d "${SSLDIR}/priv" ] && mkdir -pm700 "${SSLDIR}/private" + +cat "${DOMAINSFILE}" | while read domain line ; do + CERTSDIR="${SSLDIR}/${domain}" + [ ! -d "${CERTSDIR}" ] && mkdir -pm755 "${CERTSDIR}" + letskencrypt -C "${CHALLENGEDIR}" \ + -k "${SSLDIR}/private/${domain}.pem" \ + -c "${CERTSDIR}" \ + ${domain} ${line} +done Added: head/security/letskencrypt/files/pkg-message.in ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/security/letskencrypt/files/pkg-message.in Sun Jun 19 12:36:09 2016 (r417119) @@ -0,0 +1,28 @@ + +There are example scripts in +%%PREFIX%%/etc/letsencrypt +that you can for renewing and deploying multiple certificates + +In order to run the script regularly to update +the certificates add this line to /etc/periodic.conf + +weekly_letskencrypt_enable="YES" + +Additionally the following parameters can be added to +/etc/periodic.conf (showing default values): + +To specify the domain name(s) to include in the certificate +weekly_letskencrypt_domains="$(hostname -f)" + +To specify the .well-known/acme-challenge directory (full path) +weekly_letskencrypt_challengedir="/usr/local/www/letsencrypt" + +To set additional letskencrypt arguments (see letskencrypt(1)) +weekly_letskencrypt_args="" + +To run a specific script for the renewal (ignore previously set variables) +allows generating/renewing multiple keys/certificates +weekly_letskencrypt_renewscript=""%%PREFIX%%/etc/letsencrypt/%%PORTNAME%%.sh" + +To run a script after the renewal to deploy changed certs +weekly_letskencrypt_deployscript="%%PREFIX%%/etc/letsencrypt/deploy.sh" Modified: head/security/letskencrypt/pkg-plist ============================================================================== --- head/security/letskencrypt/pkg-plist Sun Jun 19 12:34:47 2016 (r417118) +++ head/security/letskencrypt/pkg-plist Sun Jun 19 12:36:09 2016 (r417119) @@ -1,7 +1,10 @@ bin/letskencrypt man/man1/letskencrypt.1.gz +etc/periodic/weekly/000.letskencrypt.sh @dir(,,0700) etc/letsencrypt @dir(,,0755) etc/ssl @dir(,,0755) etc/ssl/letsencrypt @dir(,,0700) etc/ssl/letsencrypt/private @dir(,www,) %%WWWDIR%% +@sample etc/letsencrypt/deploy.sh.sample +@sample etc/letsencrypt/letskencrypt.sh.sample