| 1 | # Copyright 1999-2004 Gentoo Foundation |
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.12 2007/12/09 08:09:56 ulm Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ssl-cert.eclass,v 1.13 2007/12/28 17:48:34 ulm Exp $ |
| 4 | # |
4 | # |
|
|
5 | # @ECLASS: ssl-cert.eclass |
|
|
6 | # @MAINTAINER: |
| 5 | # Author: Max Kalika <max@gentoo.org> |
7 | # Author: Max Kalika <max@gentoo.org> |
| 6 | # |
8 | # @BLURB: Eclass for SSL certificates |
|
|
9 | # @DESCRIPTION: |
| 7 | # This eclass implements standard installation procedure for installing |
10 | # This eclass implements standard installation procedure for installing |
| 8 | # self-signed SSL certificates. |
11 | # self-signed SSL certificates. |
|
|
12 | # @EXAMPLE: |
|
|
13 | # "install_cert /foo/bar" installs ${ROOT}/foo/bar.{key,csr,crt,pem} |
| 9 | |
14 | |
| 10 | # Conditionally depend on OpenSSL: allows inheretence |
15 | # Conditionally depend on OpenSSL: allows inheretence |
| 11 | # without pulling extra packages if not needed |
16 | # without pulling extra packages if not needed |
| 12 | DEPEND="ssl? ( dev-libs/openssl )" |
17 | DEPEND="ssl? ( dev-libs/openssl )" |
| 13 | IUSE="ssl" |
18 | IUSE="ssl" |
| 14 | |
19 | |
|
|
20 | # @FUNCTION: gen_cnf |
|
|
21 | # @USAGE: |
|
|
22 | # @DESCRIPTION: |
| 15 | # Initializes variables and generates the needed |
23 | # Initializes variables and generates the needed |
| 16 | # OpenSSL configuration file and a CA serial file |
24 | # OpenSSL configuration file and a CA serial file |
| 17 | # |
25 | # |
| 18 | # Access: private |
26 | # Access: private |
| 19 | gen_cnf() { |
27 | gen_cnf() { |
| … | |
… | |
| 58 | eend $? |
66 | eend $? |
| 59 | |
67 | |
| 60 | return $? |
68 | return $? |
| 61 | } |
69 | } |
| 62 | |
70 | |
|
|
71 | # @FUNCTION: get_base |
|
|
72 | # @USAGE: [if_ca] |
|
|
73 | # @RETURN: <base path> |
|
|
74 | # @DESCRIPTION: |
| 63 | # Simple function to determine whether we're creating |
75 | # Simple function to determine whether we're creating |
| 64 | # a CA (which should only be done once) or final part |
76 | # a CA (which should only be done once) or final part |
| 65 | # |
77 | # |
| 66 | # Access: private |
78 | # Access: private |
| 67 | get_base() { |
79 | get_base() { |
| … | |
… | |
| 70 | else |
82 | else |
| 71 | echo "${T}/${$}server" |
83 | echo "${T}/${$}server" |
| 72 | fi |
84 | fi |
| 73 | } |
85 | } |
| 74 | |
86 | |
|
|
87 | # @FUNCTION: gen_key |
|
|
88 | # @USAGE: <base path> |
|
|
89 | # @DESCRIPTION: |
| 75 | # Generates an RSA key |
90 | # Generates an RSA key |
| 76 | # |
91 | # |
| 77 | # Access: private |
92 | # Access: private |
| 78 | gen_key() { |
93 | gen_key() { |
| 79 | local base=`get_base $1` |
94 | local base=`get_base $1` |
| … | |
… | |
| 83 | eend $? |
98 | eend $? |
| 84 | |
99 | |
| 85 | return $? |
100 | return $? |
| 86 | } |
101 | } |
| 87 | |
102 | |
|
|
103 | # @FUNCTION: gen_csr |
|
|
104 | # @USAGE: <base path> |
|
|
105 | # @DESCRIPTION: |
| 88 | # Generates a certificate signing request using |
106 | # Generates a certificate signing request using |
| 89 | # the key made by gen_key() |
107 | # the key made by gen_key() |
| 90 | # |
108 | # |
| 91 | # Access: private |
109 | # Access: private |
| 92 | gen_csr() { |
110 | gen_csr() { |
| … | |
… | |
| 97 | eend $? |
115 | eend $? |
| 98 | |
116 | |
| 99 | return $? |
117 | return $? |
| 100 | } |
118 | } |
| 101 | |
119 | |
|
|
120 | # @FUNCTION: gen_crt |
|
|
121 | # @USAGE: <base path> |
|
|
122 | # @DESCRIPTION: |
| 102 | # Generates either a self-signed CA certificate using |
123 | # Generates either a self-signed CA certificate using |
| 103 | # the csr and key made by gen_csr() and gen_key() or |
124 | # the csr and key made by gen_csr() and gen_key() or |
| 104 | # a signed server certificate using the CA cert previously |
125 | # a signed server certificate using the CA cert previously |
| 105 | # created by gen_crt() |
126 | # created by gen_crt() |
| 106 | # |
127 | # |
| … | |
… | |
| 123 | eend $? |
144 | eend $? |
| 124 | |
145 | |
| 125 | return $? |
146 | return $? |
| 126 | } |
147 | } |
| 127 | |
148 | |
|
|
149 | # @FUNCTION: gen_pem |
|
|
150 | # @USAGE: <base path> |
|
|
151 | # @DESCRIPTION: |
| 128 | # Generates a PEM file by concatinating the key |
152 | # Generates a PEM file by concatinating the key |
| 129 | # and cert file created by gen_key() and gen_cert() |
153 | # and cert file created by gen_key() and gen_cert() |
| 130 | # |
154 | # |
| 131 | # Access: private |
155 | # Access: private |
| 132 | gen_pem() { |
156 | gen_pem() { |
| … | |
… | |
| 206 | elif [ ${count} != ${#} ] ; then |
230 | elif [ ${count} != ${#} ] ; then |
| 207 | ewarn "Some requested certificates were not generated" |
231 | ewarn "Some requested certificates were not generated" |
| 208 | fi |
232 | fi |
| 209 | } |
233 | } |
| 210 | |
234 | |
|
|
235 | # @FUNCTION: install_cert |
|
|
236 | # @USAGE: <certificates> |
|
|
237 | # @DESCRIPTION: |
| 211 | # Uses all the private functions above to generate |
238 | # Uses all the private functions above to generate and install the |
| 212 | # and install the requested certificates |
239 | # requested certificates. |
| 213 | # |
|
|
| 214 | # Usage: install_cert <certificates> |
|
|
| 215 | # where <certificates> are full pathnames relative to ROOT, without extension. |
240 | # <certificates> are full pathnames relative to ROOT, without extension. |
| 216 | # |
241 | # |
| 217 | # Example: "install_cert /foo/bar" installs ${ROOT}/foo/bar.{key,csr,crt,pem} |
242 | # Example: "install_cert /foo/bar" installs ${ROOT}/foo/bar.{key,csr,crt,pem} |
| 218 | # |
243 | # |
| 219 | # Access: public |
244 | # Access: public |
| 220 | install_cert() { |
245 | install_cert() { |