source: trunk/sysadmin/bin/cacert-cert.sh @ 87

Last change on this file since 87 was 65, checked in by sebas, 17 years ago

initial import

  • Property svn:executable set to *
File size: 3.7 KB
RevLine 
[65]1#!/bin/sh
2
3# This script will find all the ServerNames and ServerAliases
4# that are in files in the $HTTPD_VHOSTS_DIR directory and
5# it will then generates a Certificate Signing Request for a
6# new CAcert.org certificate.
7
8# PLEASE NOTE:
9#
10# 1. You need each ServerAlias on a new line, multiple aliases
11#    on one line doesn't work with this.
12#
13# 2. The variables below WILL need editing for each sever you
14#    install this on.
15#
16# Chris <chrisc@indymedia.org>
17# 29th April 2007
18
19# ===========================
20#
21# Please check all the variables in this part of the script
22# Most will probably need changing for each server you install
23# this on.
24#
25##HTTPD_VHOSTS_DIR=/etc/httpd/vhosts-ssl.d/
26HTTPD_VHOSTS_DIR="/etc/apache-ssl/redcta_hacks/"
27DATE=`date "+%Y-%m-%d_%H-%M-%S"`
28CERTS_DIR="/root/certs/crypt"
29CERTS_DIR_NEW="$CERTS_DIR/.$DATE"
30HOST=german
31COMMONNAME=ssl.redcta.org.ar
32#
33#===========================
34
35# be safe about permissions
36LASTUMASK=`umask`
37umask 077
38
39# OpenSSL for HPUX needs a random file
40RANDOMFILE=$HOME/.rnd
41
42# create a config file for openssl
43CONFIG=`mktemp -q $CERTS_DIR/openssl-conf.XXXXXXXX`
44if [ ! $? -eq 0 ]; then
45    echo "Could not create temporary config file. exiting"
46    exit 1
47fi
48
49echo "Private Key and Certificate Signing Request Generator"
50echo "This script was designed to suit the request format needed by"
51echo "the CAcert Certificate Authority. www.CAcert.org"
52echo
53
54  # if the certs directory doesn't exist then create it
55  if [[ ! -d $CERTS_DIR_NEW ]]; then
56    mkdir -p $CERTS_DIR_NEW
57  fi
58
59  # get the ServerNames
60  SERVER_NAMES=`grep -h ServerName $HTTPD_VHOSTS_DIR/* | sed  s/ServerName//g `
61  for name in $SERVER_NAMES
62    do
63      if [ "$SANAMES" = "" ]; then
64          SANAMES="DNS:$name"
65      else
66          SANAMES="$SANAMES, DNS:$name"
67      fi
68  done
69
70  # get the ServerAliases
71  SERVER_ALIASES=`grep -h ServerAlias $HTTPD_VHOSTS_DIR/* | sed  s/ServerAlias//g `
72  for name in $SERVER_ALIASES
73    do
74      if [ "$SANAMES" = "" ]; then
75          SANAMES="DNS:$name"
76      else
77          SANAMES="$SANAMES, DNS:$name"
78      fi
79  done
80
81  MAILMAN_DOMAINS=`cat /etc/mailman/domains_list.txt `
82  for name in $MAILMAN_DOMAINS
83    do
84      if [ "$SANAMES" = "" ]; then
85          SANAMES="DNS:$name"
86      else
87          SANAMES="$SANAMES, DNS:$name"
88      fi
89  done
90
91
92# Config File Generation
93cat <<EOF > $CONFIG
94# -------------- BEGIN custom openssl.cnf -----
95 HOME                    = $CERTS_DIR_NEW
96 oid_section             = new_oids
97 [ new_oids ]
98 [ req ]
99 default_days            = 730
100 default_keyfile         = $CERTS_DIR_NEW/${HOST}-privatekey.pem
101 distinguished_name      = req_distinguished_name
102 encrypt_key             = no
103 string_mask             = nombstr
104 req_extensions          = v3_req
105 [ req_distinguished_name ]
106 commonName              = Common Name (eg, YOUR name)
107 commonName_default      = $COMMONNAME
108 commonName_max          = 64
109 [ v3_req ]
110EOF
111
112if [ ! "$SANAMES" = "" ]; then
113    echo "subjectAltName=$SANAMES" >> $CONFIG
114fi
115
116echo "# -------------- END custom openssl.cnf -----" >> $CONFIG
117
118echo "Running OpenSSL..."
119  echo "Running OpenSSL..."
120  openssl req -batch -config $CONFIG -newkey rsa:2048 -out ${CERTS_DIR_NEW}/${HOST}-csr.pem
121
122
123
124  echo "Copy the following Certificate Request and paste into CAcert website to obtain a Certificate."
125  echo "When you receive your certificate, you save it to"
126  echo "${CERTS_DIR_NEW}/${HOST}-cert.pem"
127  echo
128  cat ${CERTS_DIR_NEW}/${HOST}-csr.pem
129  echo
130  echo The Certificate request is also available in ${CERTS_DIR_NEW}/${HOST}-csr.pem
131  echo The Private Key is stored in ${CERTS_DIR_NEW}/${HOST}-privatekey.pem
132  echo These will all need moving to ${CERTS_DIR}, like this:
133  echo mv ${CERTS_DIR_NEW}/\* ${CERTS_DIR}/
134  echo
135
136
137#rm $CONFIG
138
139#restore umask
140umask $LASTUMASK
Note: See TracBrowser for help on using the repository browser.