浏览代码

Use makecert for email

Bob Mottram 11 年前
父节点
当前提交
deebb07cb8
共有 1 个文件被更改,包括 68 次插入150 次删除
  1. 68
    150
      beaglebone.txt

+ 68
- 150
beaglebone.txt 查看文件

1617
 ip6tables -L
1617
 ip6tables -L
1618
 #+END_SRC
1618
 #+END_SRC
1619
 
1619
 
1620
+** Make SSL/TLS certificates
1621
+
1622
+For email, web server and other services we will be using SSL/TLS certificates, so create a script which makes this easy to do with a single command.
1623
+
1624
+#+BEGIN_SRC: bash
1625
+editor /usr/bin/makecert
1626
+#+END_SRC
1627
+
1628
+Enter the following.  You can change the country code and location if you wish, but that's not essential.
1629
+
1630
+#+BEGIN_SRC: bash
1631
+#!/bin/bash
1632
+
1633
+HOSTNAME=$1
1634
+COUNTRY_CODE="US"
1635
+AREA="Free Speech Zone"
1636
+LOCATION="Freedomville"
1637
+ORGANISATION="Freedombone"
1638
+UNIT="Freedombone Unit"
1639
+
1640
+if ! which openssl > /dev/null ;then
1641
+    echo "$0: openssl is not installed, exiting" 1>&2
1642
+    exit 1
1643
+fi
1644
+
1645
+openssl req \
1646
+  -x509 -nodes -days 3650 \
1647
+  -sha256 \
1648
+  -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
1649
+  -newkey rsa:2048 \
1650
+  -keyout /etc/ssl/private/$HOSTNAME.key \
1651
+  -out /etc/ssl/certs/$HOSTNAME.crt
1652
+
1653
+openssl dhparam -check -text -5 1024 -out /etc/ssl/certs/$HOSTNAME.dhparam
1654
+
1655
+chmod 400 /etc/ssl/private/$HOSTNAME.key
1656
+chmod 640 /etc/ssl/certs/$HOSTNAME.crt
1657
+chmod 640 /etc/ssl/certs/$HOSTNAME.dhparam
1658
+/etc/init.d/nginx reload
1659
+
1660
+# add the public certificate to a separate directory
1661
+# so that we can redistribute it easily
1662
+if [ ! -d /etc/ssl/mycerts ]; then
1663
+  mkdir /etc/ssl/mycerts
1664
+fi
1665
+cp /etc/ssl/certs/$HOSTNAME.crt /etc/ssl/mycerts
1666
+# Create a bundle of your certificates
1667
+cat /etc/ssl/mycerts/*.crt > /etc/ssl/freedombone-bundle.crt
1668
+tar -czvf /etc/ssl/freedombone-certs.tar.gz /etc/ssl/mycerts/*.crt
1669
+#+END_SRC
1670
+
1671
+Save and exit.
1672
+
1673
+#+BEGIN_SRC: bash
1674
+chmod +x /usr/bin/makecert
1675
+#+END_SRC
1620
 ** Install Email
1676
 ** Install Email
1621
 
1677
 
1622
 #+BEGIN_VERSE
1678
 #+BEGIN_VERSE
1681
 
1737
 
1682
 #+BEGIN_SRC: bash
1738
 #+BEGIN_SRC: bash
1683
 /etc/init.d/saslauthd start
1739
 /etc/init.d/saslauthd start
1684
-editor /usr/bin/exim-gencert
1685
-#+END_SRC
1686
-
1687
-Add the following:
1688
-
1689
-#+BEGIN_SRC: bash
1690
-#!/bin/sh -e
1691
-
1692
-if [ -n "$EX4DEBUG" ]; then
1693
-  echo "now debugging $0 $@"
1694
-  set -x
1695
-fi
1696
-
1697
-DIR=/etc/exim4
1698
-CERT=$DIR/exim.crt
1699
-KEY=$DIR/exim.key
1700
-
1701
-# This exim binary was built with GnuTLS which does not support dhparams
1702
-# from a file. See /usr/share/doc/exim4-base/README.Debian.gz
1703
-#DH=$DIR/exim.dhparam
1704
-
1705
-if ! which openssl > /dev/null ;then
1706
-    echo "$0: openssl is not installed, exiting" 1>&2
1707
-    exit 1
1708
-fi
1709
-
1710
-# valid for ten years
1711
-DAYS=3650
1712
-
1713
-if [ "$1" != "--force" ] && [ -f $CERT ] && [ -f $KEY ]; then
1714
-  echo "[*] $CERT and $KEY exists!"
1715
-  echo "    Use \"$0 --force\" to force generation!"
1716
-  exit 0
1717
-fi
1718
-
1719
-if [ "$1" = "--force" ]; then
1720
-  shift
1721
-fi
1722
-
1723
-#SSLEAY=/tmp/exim.ssleay.$$.cnf
1724
-SSLEAY="$(tempfile -m600 -pexi)"
1725
-cat > $SSLEAY <<EOM
1726
-RANDFILE = $HOME/.rnd
1727
-[ req ]
1728
-default_bits = 4096
1729
-default_keyfile = exim.key
1730
-distinguished_name = req_distinguished_name
1731
-[ req_distinguished_name ]
1732
-countryName = Country Code (2 letters)
1733
-countryName_default = GB
1734
-countryName_min = 2
1735
-countryName_max = 2
1736
-stateOrProvinceName = State or Province Name (full name)
1737
-localityName = Locality Name (eg, city)
1738
-organizationName = Organization Name (eg, company; recommended)
1739
-organizationName_max = 64
1740
-organizationalUnitName = Organizational Unit Name (eg, section)
1741
-organizationalUnitName_max = 64
1742
-commonName = Server name (eg. ssl.domain.tld; required!!!)
1743
-commonName_max = 64
1744
-emailAddress = Email Address
1745
-emailAddress_max = 40
1746
-EOM
1747
-
1748
-echo "[*] Creating a self signed SSL certificate for Exim!"
1749
-echo "    This may be sufficient to establish encrypted connections but for"
1750
-echo "    secure identification you need to buy a real certificate!"
1751
-echo "    "
1752
-echo "    Please enter the hostname of your MTA at the Common Name (CN) prompt!"
1753
-echo "    "
1754
-
1755
-openssl req -config $SSLEAY -x509 -sha256 -newkey rsa:4096 -keyout $KEY -out $CERT -days $DAYS -nodes
1756
-#see README.Debian.gz*# openssl dhparam -check -text -5 512 -out $DH
1757
-rm -f $SSLEAY
1758
-
1759
-chown root:Debian-exim $KEY $CERT $DH
1760
-chmod 640 $KEY $CERT $DH
1761
-
1762
-echo "[*] Done generating self signed certificates for exim!"
1763
-echo "    Refer to the documentation and example configuration files"
1764
-echo "    over at /usr/share/doc/exim4-base/ for an idea on how to enable TLS"
1765
-echo "    support in your mail transfer agent."
1766
-#+END_SRC
1767
-
1768
-Save and exit
1769
-
1770
-#+BEGIN_SRC: bash
1771
-chmod +x /usr/bin/exim-gencert
1772
-exim-gencert --force
1773
-#+END_SRC
1774
-
1775
-This will generate the certificate used for email authentication.  You will be asked for various details, the most important of which is the server name, which should be your domain name.
1776
-
1777
-#+BEGIN_SRC: bash
1740
+makecert exim
1741
+mv /etc/ssl/private/exim.key /etc/exim4
1742
+mv /etc/ssl/certs/exim.crt /etc/exim4
1743
+mv /etc/ssl/certs/exim.dhparam /etc/exim4
1744
+chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
1745
+chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
1778
 editor /etc/exim4/exim4.conf.template
1746
 editor /etc/exim4/exim4.conf.template
1779
 #+END_SRC
1747
 #+END_SRC
1780
 
1748
 
2627
 #+BEGIN_SRC: bash
2595
 #+BEGIN_SRC: bash
2628
 nginx_dissite default
2596
 nginx_dissite default
2629
 nginx_ensite $HOSTNAME
2597
 nginx_ensite $HOSTNAME
2630
-#+END_SRC
2631
-
2632
-Create a self-signed certificate. The passphrase isn't important and will be removed, so make it easy (such as "password").
2633
-
2634
-#+BEGIN_SRC: bash
2635
-editor /usr/bin/makecert
2636
-#+END_SRC
2637
-
2638
-Enter the following, changing the country code and location as needed:
2639
-
2640
-#+BEGIN_SRC: bash
2641
-#!/bin/bash
2642
-
2643
-HOSTNAME=$1
2644
-COUNTRY_CODE="US"
2645
-AREA="Free Speech Zone"
2646
-LOCATION="Freedomville"
2647
-ORGANISATION="Freedombone"
2648
-UNIT="Freedombone Unit"
2649
-
2650
-if ! which openssl > /dev/null ;then
2651
-    echo "$0: openssl is not installed, exiting" 1>&2
2652
-    exit 1
2653
-fi
2654
-
2655
-openssl req \
2656
-  -x509 -nodes -days 3650 \
2657
-  -sha256 \
2658
-  -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
2659
-  -newkey rsa:2048 \
2660
-  -keyout /etc/ssl/private/$HOSTNAME.key \
2661
-  -out /etc/ssl/certs/$HOSTNAME.crt
2662
-
2663
-openssl dhparam -check -text -5 1024 -out /etc/ssl/certs/$HOSTNAME.dhparam
2664
-
2665
-chmod 400 /etc/ssl/private/$HOSTNAME.key
2666
-chmod 640 /etc/ssl/certs/$HOSTNAME.crt
2667
-chmod 640 /etc/ssl/certs/$HOSTNAME.dhparam
2668
-/etc/init.d/nginx reload
2669
-
2670
-# add the public certificate to a separate directory
2671
-# so that we can redistribute it easily
2672
-if [ ! -d /etc/ssl/mycerts ]; then
2673
-  mkdir /etc/ssl/mycerts
2674
-fi
2675
-cp /etc/ssl/certs/$HOSTNAME.crt /etc/ssl/mycerts
2676
-# Create a bundle of your certificates
2677
-cat /etc/ssl/mycerts/*.crt > /etc/ssl/freedombone-bundle.crt
2678
-tar -czvf /etc/ssl/freedombone-certs.tar.gz /etc/ssl/mycerts/*.crt
2679
-#+END_SRC
2680
-
2681
-Save and exit.
2682
-
2683
-#+BEGIN_SRC: bash
2684
-chmod +x /usr/bin/makecert
2685
 makecert $HOSTNAME
2598
 makecert $HOSTNAME
2686
 #+END_SRC
2599
 #+END_SRC
2687
 
2600
 
7861
 Regenerate email certificate.
7774
 Regenerate email certificate.
7862
 
7775
 
7863
 #+BEGIN_SRC: bash
7776
 #+BEGIN_SRC: bash
7864
-exim-gencert --force
7777
+makecert exim
7778
+mv /etc/ssl/private/exim.key /etc/exim4
7779
+mv /etc/ssl/certs/exim.crt /etc/exim4
7780
+mv /etc/ssl/certs/exim.dhparam /etc/exim4
7781
+chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
7782
+chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
7865
 #+END_SRC
7783
 #+END_SRC
7866
 
7784
 
7867
 As an added precaution you may wish to regenerate your ssh host keys:
7785
 As an added precaution you may wish to regenerate your ssh host keys: