/[gentoo-x86]/eclass/ssl-cert.eclass
Gentoo

Diff of /eclass/ssl-cert.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 Revision 1.15
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2004 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/ssl-cert.eclass,v 1.3 2004/04/11 05:46:09 mr_bones_ Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/ssl-cert.eclass,v 1.15 2008/04/14 06:27:45 ulm Exp $
4# 4#
5# Author: Max Kalika <max@gentoo.org> 5# Author: Max Kalika <max@gentoo.org>
6# 6#
7# This eclass implements standard installation procedure for installing 7# This eclass implements standard installation procedure for installing
8# self-signed SSL certificates. 8# self-signed SSL certificates.
9
10ECLASS=ssl-cert
11INHERITED="$INHERITED $ECLASS"
12 9
13# Conditionally depend on OpenSSL: allows inheretence 10# Conditionally depend on OpenSSL: allows inheretence
14# without pulling extra packages if not needed 11# without pulling extra packages if not needed
15DEPEND="ssl? ( dev-libs/openssl )" 12DEPEND="ssl? ( dev-libs/openssl )"
13IUSE="ssl"
16 14
17# Initializes variables and generates the needed 15# Initializes variables and generates the needed
18# OpenSSL configuration file and a CA serial file 16# OpenSSL configuration file and a CA serial file
19# 17#
20# Access: private 18# Access: private
21gen_cnf() { 19gen_cnf() {
22 # Location of the config file 20 # Location of the config file
23 SSL_CONF="${T}/${$}ssl.cnf" 21 SSL_CONF="${T}/${$}ssl.cnf"
24 # Location of the CA serial file 22 # Location of the CA serial file
25 SSL_SERIAL="${T}/${$}ca.ser" 23 SSL_SERIAL="${T}/${$}ca.ser"
26 # Location of some random files OpenSSL can use: don't use 24 # Location of some random files OpenSSL can use: don't use
27 # /dev/u?random here -- doesn't work properly on all platforms 25 # /dev/u?random here -- doesn't work properly on all platforms
28 SSL_RANDOM="${T}/evironment:${T}/eclass-debug.log:/etc/resolv.conf" 26 SSL_RANDOM="${T}/environment:${T}/eclass-debug.log:/etc/resolv.conf"
29 27
30 # These can be overridden in the ebuild 28 # These can be overridden in the ebuild
31 SSL_DAYS="${SSL_BITS:-730}" 29 SSL_DAYS="${SSL_DAYS:-730}"
32 SSL_BITS="${SSL_BITS:-1024}" 30 SSL_BITS="${SSL_BITS:-1024}"
33 SSL_COUNTRY="${SSL_COUNTRY:-US}" 31 SSL_COUNTRY="${SSL_COUNTRY:-US}"
34 SSL_STATE="${SSL_STATE:-California}" 32 SSL_STATE="${SSL_STATE:-California}"
35 SSL_LOCALITY="${SSL_LOCALITY:-Santa Barbara}" 33 SSL_LOCALITY="${SSL_LOCALITY:-Santa Barbara}"
36 SSL_ORGANIZATION="${SSL_ORGANIZATION:-SSL Server}" 34 SSL_ORGANIZATION="${SSL_ORGANIZATION:-SSL Server}"
56 OU = ${SSL_UNIT} 54 OU = ${SSL_UNIT}
57 CN = ${SSL_COMMONNAME} 55 CN = ${SSL_COMMONNAME}
58 emailAddress = ${SSL_EMAIL} 56 emailAddress = ${SSL_EMAIL}
59 EOF 57 EOF
60 eend $? 58 eend $?
61 59
62 return $? 60 return $?
63} 61}
64 62
65# Simple function to determine whether we're creating 63# Simple function to determine whether we're creating
66# a CA (which should only be done once) or final part 64# a CA (which should only be done once) or final part
138 eend $? 136 eend $?
139 137
140 return $? 138 return $?
141} 139}
142 140
141# Removed due to bug 174759
142docert() {
143 eerror "Function \"docert\" has been removed for security reasons."
144 eerror "\"install_cert\" should be used instead. See bug 174759."
145 die
146}
147
143# Uses all the private functions above to generate 148# Uses all the private functions above to generate
144# and install the requested certificates 149# and install the requested certificates
145# 150#
151# Usage: install_cert <certificates>
152# where <certificates> are full pathnames relative to ROOT, without extension.
153#
154# Example: "install_cert /foo/bar" installs ${ROOT}/foo/bar.{key,csr,crt,pem}
155#
146# Access: public 156# Access: public
147docert() { 157install_cert() {
148 if [ $# -lt 1 ] ; then 158 if [ $# -lt 1 ] ; then
149 eerror "At least one argument needed" 159 eerror "At least one argument needed"
150 return 1; 160 return 1;
151 fi 161 fi
162
163 case ${EBUILD_PHASE} in
164 unpack|compile|test|install)
165 eerror "install_cert cannot be called in ${EBUILD_PHASE}"
166 return 1 ;;
167 esac
152 168
153 # Initialize configuration 169 # Initialize configuration
154 gen_cnf || return 1 170 gen_cnf || return 1
155 echo 171 echo
156 172
160 gen_crt 1 || return 1 176 gen_crt 1 || return 1
161 echo 177 echo
162 178
163 local count=0 179 local count=0
164 for cert in "$@" ; do 180 for cert in "$@" ; do
165 # Sanitize and check the requested certificate 181 # Check the requested certificate
166 cert="`/usr/bin/basename "${cert}"`"
167 if [ -z "${cert}" ] ; then 182 if [ -z "${cert##*/}" ] ; then
168 ewarn "Invalid certification requested, skipping" 183 ewarn "Invalid certification requested, skipping"
169 continue 184 continue
170 fi 185 fi
171 186
172 # Check for previous existence of generated files 187 # Check for previous existence of generated files
173 for type in key crt pem ; do 188 for type in key csr crt pem ; do
174 if [ -e "${D}${INSDESTTREE}/${cert}.${type}" ] ; then 189 if [ -e "${ROOT}${cert}.${type}" ] ; then
175 ewarn "${D}${INSDESTTREE}/${cert}.${type}: exists, skipping" 190 ewarn "${ROOT}${cert}.${type}: exists, skipping"
176 continue 2 191 continue 2
177 fi 192 fi
178 done 193 done
179 194
180 # Generate the requested files 195 # Generate the requested files
183 gen_crt || continue 198 gen_crt || continue
184 gen_pem || continue 199 gen_pem || continue
185 echo 200 echo
186 201
187 # Install the generated files and set sane permissions 202 # Install the generated files and set sane permissions
188 local base=`get_base` 203 local base=$(get_base)
204 install -d "${ROOT}${cert%/*}"
189 newins "${base}.key" "${cert}.key" 205 install -m0400 "${base}.key" "${ROOT}${cert}.key"
190 fperms 0400 "${INSDESTTREE}/${cert}.key"
191 newins "${base}.csr" "${cert}.csr" 206 install -m0444 "${base}.csr" "${ROOT}${cert}.csr"
192 fperms 0444 "${INSDESTTREE}/${cert}.csr"
193 newins "${base}.crt" "${cert}.crt" 207 install -m0444 "${base}.crt" "${ROOT}${cert}.crt"
194 fperms 0444 "${INSDESTTREE}/${cert}.crt"
195 newins "${base}.pem" "${cert}.pem" 208 install -m0400 "${base}.pem" "${ROOT}${cert}.pem"
196 fperms 0400 "${INSDESTTREE}/${cert}.pem"
197 count=$((${count}+1)) 209 count=$((${count}+1))
198 done 210 done
199 211
200 # Resulting status 212 # Resulting status
201 if [ ! ${count} ] ; then 213 if [ ! ${count} ] ; then

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.20