Skip to content

Commit 168e181

Browse files
authored
Merge pull request #89 from lafriks/feat/autocert
Add support for automatic self-signec cert generation
2 parents 1a1a3dc + c390566 commit 168e181

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,14 @@ openssl req -x509 -nodes -newkey rsa:2048 -sha256 -keyout \
270270
chmod 600 /etc/ssl/private/*.pem
271271
```
272272

273+
Automatic TLS certificate generation
274+
------------------------------
275+
276+
If `ADDED_FLAGS` contains `--tls` and file `/etc/ssl/private/pure-ftpd.pem` does not exists
277+
it is possible to generate self-signed certificate if `TLS_CN`, `TLS_ORG` and `TLS_C` are set.
278+
279+
Keep in mind that if no volume is set for `/etc/ssl/private/` directory generated
280+
certificates won't be persisted and new ones will be generated on each start.
273281

274282
Credits
275283
-------------

run.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ then
2626
PURE_FTPD_FLAGS="$PURE_FTPD_FLAGS --tls=1 "
2727
fi
2828

29+
# If TLS flag is set and no certificate exists, generate it
30+
if [ ! -e /etc/ssl/private/pure-ftpd.pem ] && [[ "$PURE_FTPD_FLAGS" == *"--tls"* ]] && [ ! -z "$TLS_CN" ] && [ ! -z "$TLS_ORG" ] && [ ! -z "$TLS_C" ]
31+
then
32+
echo "Generating self-signed certificate"
33+
mkdir -p /etc/ssl/private
34+
openssl dhparam -out /etc/ssl/private/pure-ftpd-dhparams.pem 2048
35+
openssl req -subj "/CN=${TLS_CN}/O=${TLS_ORG}/C=${TLS_C}" -days 1826 \
36+
-x509 -nodes -newkey rsa:2048 -sha256 -keyout \
37+
/etc/ssl/private/pure-ftpd.pem \
38+
-out /etc/ssl/private/pure-ftpd.pem
39+
chmod 600 /etc/ssl/private/*.pem
40+
fi
41+
2942
# Add user
3043
if [ ! -z "$FTP_USER_NAME" ] && [ ! -z "$FTP_USER_PASS" ] && [ ! -z "$FTP_USER_HOME" ]
3144
then

0 commit comments

Comments
 (0)