diff options
Diffstat (limited to 'eclass/ssl-cert.eclass')
-rw-r--r-- | eclass/ssl-cert.eclass | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/eclass/ssl-cert.eclass b/eclass/ssl-cert.eclass index fca4242ce7f1..e44102552f2a 100644 --- a/eclass/ssl-cert.eclass +++ b/eclass/ssl-cert.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/ssl-cert.eclass,v 1.9 2005/07/11 15:08:06 swegener Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/ssl-cert.eclass,v 1.10 2007/12/07 22:41:04 ulm Exp $ # # Author: Max Kalika <max@gentoo.org> # @@ -140,6 +140,7 @@ gen_pem() { # Uses all the private functions above to generate # and install the requested certificates +# Note: This function is deprecated, use install_cert instead # # Access: public docert() { @@ -203,3 +204,71 @@ docert() { ewarn "Some requested certificates were not generated" fi } + +# Uses all the private functions above to generate +# and install the requested certificates +# +# Access: public +install_cert() { + if [ $# -lt 1 ] ; then + eerror "At least one argument needed" + return 1; + fi + + case ${EBUILD_PHASE} in + unpack|compile|test|install) + eerror "install_cert cannot be called in ${EBUILD_PHASE}" + return 1 ;; + esac + + # Initialize configuration + gen_cnf || return 1 + echo + + # Generate a CA environment + gen_key 1 || return 1 + gen_csr 1 || return 1 + gen_crt 1 || return 1 + echo + + local count=0 + for cert in "$@" ; do + # Check the requested certificate + if [ -z "${cert##*/}" ] ; then + ewarn "Invalid certification requested, skipping" + continue + fi + + # Check for previous existence of generated files + for type in key csr crt pem ; do + if [ -e "${ROOT}${cert}.${type}" ] ; then + ewarn "${ROOT}${cert}.${type}: exists, skipping" + continue 2 + fi + done + + # Generate the requested files + gen_key || continue + gen_csr || continue + gen_crt || continue + gen_pem || continue + echo + + # Install the generated files and set sane permissions + local base=$(get_base) + install -d "${ROOT}${cert%/*}" + install -m0400 "${base}.key" "${ROOT}${cert}.key" + install -m0444 "${base}.csr" "${ROOT}${cert}.csr" + install -m0444 "${base}.crt" "${ROOT}${cert}.crt" + install -m0400 "${base}.pem" "${ROOT}${cert}.pem" + count=$((${count}+1)) + done + + # Resulting status + if [ ! ${count} ] ; then + eerror "No certificates were generated" + return 1 + elif [ ${count} != ${#} ] ; then + ewarn "Some requested certificates were not generated" + fi +} |