1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
5 | %general-entities;
|
---|
6 |
|
---|
7 | <!ENTITY certhost "http://mxr.mozilla.org">
|
---|
8 | <!ENTITY certdir "/mozilla/source/security/nss/lib/ckfw/builtins">
|
---|
9 | <!ENTITY ca-bundle-download "&certhost;&certdir;/certdata.txt?raw=1">
|
---|
10 | <!ENTITY ca-bundle-size "1.2 MB">
|
---|
11 | <!ENTITY cacerts-buildsize "1.2 MB">
|
---|
12 | <!ENTITY cacerts-time "less than 0.1 SBU">
|
---|
13 | ]>
|
---|
14 |
|
---|
15 | <sect1 id="cacerts" xreflabel="Certificate Authority Certificates">
|
---|
16 | <?dbhtml filename="cacerts.html"?>
|
---|
17 |
|
---|
18 | <sect1info>
|
---|
19 | <othername>$LastChangedBy$</othername>
|
---|
20 | <date>$Date$</date>
|
---|
21 | </sect1info>
|
---|
22 |
|
---|
23 | <title>Certificate Authority Certificates</title>
|
---|
24 |
|
---|
25 | <para>The Public Key Inrastructure is used for many security issues in a
|
---|
26 | Linux system. In order for a certificate to be trusted, it must be signed by
|
---|
27 | a trusted agent called a Certificate Authority (CA). The certificates loaded
|
---|
28 | by this section are from the list on the Mozilla version control system and
|
---|
29 | formats it into a form used by <xref linkend='openssl'/>. The certificates
|
---|
30 | can also be used by other applications either directly of indirectly through
|
---|
31 | <application>openssl</application>.</para>
|
---|
32 |
|
---|
33 | &lfs70_checked;
|
---|
34 |
|
---|
35 | <indexterm zone="cacerts">
|
---|
36 | <primary sortas="a-cacerts">Certificate Authority Certificates</primary>
|
---|
37 | </indexterm>
|
---|
38 |
|
---|
39 | <sect2 role="package">
|
---|
40 | <title>Introduction to Certificate Authorities</title>
|
---|
41 |
|
---|
42 | <bridgehead renderas="sect3">Package Information</bridgehead>
|
---|
43 | <itemizedlist spacing="compact">
|
---|
44 | <listitem>
|
---|
45 | <para>CA Certificate Download: <ulink url="&ca-bundle-download;"/></para>
|
---|
46 | </listitem>
|
---|
47 | <listitem>
|
---|
48 | <para>CA Bundle size: &ca-bundle-size;</para>
|
---|
49 | </listitem>
|
---|
50 | <listitem>
|
---|
51 | <para>Estimated disk space required: &cacerts-buildsize;</para>
|
---|
52 | </listitem>
|
---|
53 | <listitem>
|
---|
54 | <para>Estimated build time: &cacerts-time;</para>
|
---|
55 | </listitem>
|
---|
56 | </itemizedlist>
|
---|
57 |
|
---|
58 | <bridgehead renderas="sect3">Certificate Authority Certificates Dependencies</bridgehead>
|
---|
59 |
|
---|
60 | <bridgehead renderas="sect4">Required</bridgehead>
|
---|
61 | <para role="required"><xref linkend="openssl"/></para>
|
---|
62 |
|
---|
63 | <bridgehead renderas="sect4">Optional</bridgehead>
|
---|
64 | <para role="optional"><xref linkend="wget"/></para>
|
---|
65 |
|
---|
66 | <para condition="html" role="usernotes">User Notes:
|
---|
67 | <ulink url='&blfs-wiki;/cacerts'/></para>
|
---|
68 | </sect2>
|
---|
69 |
|
---|
70 | <sect2 role="installation">
|
---|
71 | <title>Installation of Certificate Authority Certificates</title>
|
---|
72 |
|
---|
73 | <para>First create a script to reformat a certificate into a
|
---|
74 | form needed by <application>openssl</application>. As the <systemitem
|
---|
75 | class="username">root</systemitem> user:</para>
|
---|
76 |
|
---|
77 | <screen><userinput>cat > /bin/make-cert.pl << "EOF"
|
---|
78 | #!/usr/bin/perl -w
|
---|
79 |
|
---|
80 | # Used to generate PEM encoded files from Mozilla certdata.txt.
|
---|
81 | # Run as ./mkcrt.pl > certificate.crt
|
---|
82 | #
|
---|
83 | # Parts of this script courtesy of RedHat (mkcabundle.pl)
|
---|
84 | #
|
---|
85 | # This script modified for use with single file data (tempfile.cer) extracted
|
---|
86 | # from certdata.txt, taken from the latest version in the Mozilla NSS source.
|
---|
87 | # mozilla/security/nss/lib/ckfw/builtins/certdata.txt
|
---|
88 | #
|
---|
89 | # Authors: DJ Lucas
|
---|
90 | # Bruce Dubbs
|
---|
91 |
|
---|
92 | my $certdata = './tempfile.cer';
|
---|
93 |
|
---|
94 | open( IN, "cat $certdata|" )
|
---|
95 | || die "could not open $certdata";
|
---|
96 |
|
---|
97 | my $incert = 0;
|
---|
98 |
|
---|
99 | while ( <IN> )
|
---|
100 | {
|
---|
101 | if ( /^CKA_VALUE MULTILINE_OCTAL/ )
|
---|
102 | {
|
---|
103 | $incert = 1;
|
---|
104 | open( OUT, "|openssl x509 -text -inform DER -fingerprint" )
|
---|
105 | || die "could not pipe to openssl x509";
|
---|
106 | }
|
---|
107 |
|
---|
108 | elsif ( /^END/ && $incert )
|
---|
109 | {
|
---|
110 | close( OUT );
|
---|
111 | $incert = 0;
|
---|
112 | print "\n\n";
|
---|
113 | }
|
---|
114 |
|
---|
115 | elsif ($incert)
|
---|
116 | {
|
---|
117 | my @bs = split( /\\/ );
|
---|
118 | foreach my $b (@bs)
|
---|
119 | {
|
---|
120 | chomp $b;
|
---|
121 | printf( OUT "%c", oct($b) ) unless $b eq '';
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|
125 | EOF
|
---|
126 |
|
---|
127 | chmod +x /bin/make-cert.pl</userinput></screen>
|
---|
128 |
|
---|
129 | <para>The following script creates the certificates and a bundle of all the
|
---|
130 | certificates. It creates a <filename class='directory'>./certs</filename>
|
---|
131 | directory and <filename>./BLFS-ca-bundle-${VERSION}.crt</filename>. Again
|
---|
132 | create this script as the <systemitem class="username">root</systemitem>
|
---|
133 | user:</para>
|
---|
134 |
|
---|
135 | <screen><userinput>cat > /bin/make-ca.sh << "EOF"
|
---|
136 | #!/bin/bash
|
---|
137 | # Begin make-ca.sh
|
---|
138 | # Script to populate OpenSSL's CApath from a bundle of PEM formatted CAs
|
---|
139 | #
|
---|
140 | # The file certdata.txt must exist in the local directory
|
---|
141 | # Version number is obtained from the version of the data.
|
---|
142 | #
|
---|
143 | # Authors: DJ Lucas
|
---|
144 | # Bruce Dubbs
|
---|
145 |
|
---|
146 | certdata="certdata.txt"
|
---|
147 |
|
---|
148 | if [ ! -r $certdata ]; then
|
---|
149 | echo "$certdata must be in the local directory"
|
---|
150 | exit 1
|
---|
151 | fi
|
---|
152 |
|
---|
153 | REVISION=$(grep CVS_ID $certdata | cut -f4 -d'$')
|
---|
154 |
|
---|
155 | if [ -z "${REVISION}" ]; then
|
---|
156 | echo "$certfile has no 'Revision' in CVS_ID"
|
---|
157 | exit 1
|
---|
158 | fi
|
---|
159 |
|
---|
160 | VERSION=$(echo $REVISION | cut -f2 -d" ")
|
---|
161 |
|
---|
162 | TEMPDIR=$(mktemp -d)
|
---|
163 | TRUSTATTRIBUTES="CKA_TRUST_SERVER_AUTH"
|
---|
164 | BUNDLE="BLFS-ca-bundle-${VERSION}.crt"
|
---|
165 | CONVERTSCRIPT="make-cert.pl"
|
---|
166 | SSLDIR="/etc/ssl"
|
---|
167 |
|
---|
168 | mkdir "${TEMPDIR}/certs"
|
---|
169 |
|
---|
170 | # Get a list of staring lines for each cert
|
---|
171 | CERTBEGINLIST=$(grep -n "^# Certificate" "${certdata}" | cut -d ":" -f1)
|
---|
172 |
|
---|
173 | # Get a list of ending lines for each cert
|
---|
174 | CERTENDLIST=`grep -n "^CKA_TRUST_STEP_UP_APPROVED" "${certdata}" | cut -d ":" -f 1`
|
---|
175 |
|
---|
176 | # Start a loop
|
---|
177 | for certbegin in ${CERTBEGINLIST}; do
|
---|
178 | for certend in ${CERTENDLIST}; do
|
---|
179 | if test "${certend}" -gt "${certbegin}"; then
|
---|
180 | break
|
---|
181 | fi
|
---|
182 | done
|
---|
183 |
|
---|
184 | # Dump to a temp file with the name of the file as the beginning line number
|
---|
185 | sed -n "${certbegin},${certend}p" "${certdata}" > "${TEMPDIR}/certs/${certbegin}.tmp"
|
---|
186 | done
|
---|
187 |
|
---|
188 | unset CERTBEGINLIST CERTDATA CERTENDLIST certebegin certend
|
---|
189 |
|
---|
190 | mkdir -p certs
|
---|
191 | rm certs/* # Make sure the directory is clean
|
---|
192 |
|
---|
193 | for tempfile in ${TEMPDIR}/certs/*.tmp; do
|
---|
194 | # Make sure that the cert is trusted...
|
---|
195 | grep "CKA_TRUST_SERVER_AUTH" "${tempfile}" | \
|
---|
196 | grep "CKT_NETSCAPE_TRUST_UNKNOWN" > /dev/null
|
---|
197 |
|
---|
198 | if test "${?}" = "0"; then
|
---|
199 | # Throw a meaningful error and remove the file
|
---|
200 | cp "${tempfile}" tempfile.cer
|
---|
201 | "${CONVERTSCRIPT}" > tempfile.crt
|
---|
202 | keyhash=$(openssl x509 -noout -in tempfile.crt -hash)
|
---|
203 | echo "Certificate ${keyhash} is not trusted! Removing..."
|
---|
204 | rm -f tempfile.cer tempfile.crt "${tempfile}"
|
---|
205 | continue
|
---|
206 | fi
|
---|
207 |
|
---|
208 | # If execution made it to here in the loop, the temp cert is trusted
|
---|
209 | # Find the cert data and generate a cert file for it
|
---|
210 |
|
---|
211 | cp "${tempfile}" tempfile.cer
|
---|
212 | "${CONVERTSCRIPT}" > tempfile.crt
|
---|
213 | keyhash=$(openssl x509 -noout -in tempfile.crt -hash)
|
---|
214 | mv tempfile.crt "certs/${keyhash}.pem"
|
---|
215 | rm -f tempfile.cer "${tempfile}"
|
---|
216 | echo "Created ${keyhash}.pem"
|
---|
217 | done
|
---|
218 |
|
---|
219 | # Remove blacklisted files
|
---|
220 | # MD5 Collision Proof of Concept CA
|
---|
221 | if test -f certs/8f111d69.pem; then
|
---|
222 | echo "Certificate 8f111d69 is not trusted! Removing..."
|
---|
223 | rm -f certs/8f111d69.pem
|
---|
224 | fi
|
---|
225 |
|
---|
226 | # Finally, generate the bundle and clean up.
|
---|
227 | cat certs/*.pem > ${BUNDLE}
|
---|
228 | rm -r "${TEMPDIR}"
|
---|
229 | EOF
|
---|
230 |
|
---|
231 | chmod +x /bin/make-ca.sh</userinput></screen>
|
---|
232 |
|
---|
233 | <para>Add a short script to remove expired certifictes from a directory.
|
---|
234 | Again create this script as the <systemitem
|
---|
235 | class="username">root</systemitem> user:</para>
|
---|
236 |
|
---|
237 | <screen><userinput>cat > /bin/remove-expired-certs.sh << "EOF"
|
---|
238 | #!/bin/bash
|
---|
239 | # Begin /bin/remove-expired-certs.sh
|
---|
240 |
|
---|
241 | OPENSSL=/usr/bin/openssl
|
---|
242 | DIR=/etc/ssl/certs
|
---|
243 |
|
---|
244 | if [ $# -gt 0 ]; then
|
---|
245 | DIR="$1"
|
---|
246 | fi
|
---|
247 |
|
---|
248 | certs=$( find ${DIR} -type f -name "*.pem" -o -name "*.crt" )
|
---|
249 | today=$( date +%Y%m%d )
|
---|
250 |
|
---|
251 | for cert in $certs; do
|
---|
252 | notafter=$( $OPENSSL x509 -enddate -in "${cert}" -noout )
|
---|
253 | date=$( echo ${notafter} | sed 's/^notAfter=//' )
|
---|
254 |
|
---|
255 | if [ $( date -d "${date}" +%Y%m%d ) -lt ${today} ]; then
|
---|
256 | echo "${cert} is expired! Removing..."
|
---|
257 | rm -f "${cert}"
|
---|
258 | fi
|
---|
259 | done
|
---|
260 | EOF
|
---|
261 |
|
---|
262 | chmod +x /bin/remove-expired-certs.sh</userinput></screen>
|
---|
263 |
|
---|
264 | <para>The following commands will fetch the certificates and convert them to
|
---|
265 | the correct format. If desired, a web browser may be used instead of
|
---|
266 | <application>wget</application> but the file will need to be saved with the
|
---|
267 | name <filename>certdata.txt</filename>. These commands can be repeated as
|
---|
268 | necessary to update the CA Certificates.</para>
|
---|
269 |
|
---|
270 | <screen><userinput>certhost='http://mxr.mozilla.org' &&
|
---|
271 | certdir='/mozilla/source/security/nss/lib/ckfw/builtins' &&
|
---|
272 | url="$certhost$certdir/certdata.txt?raw=1" &&
|
---|
273 |
|
---|
274 | wget --output-document certdata.txt $url &&
|
---|
275 | unset certhost certdir url &&
|
---|
276 | make-ca.sh &&
|
---|
277 | remove-expired-certs.sh certs</userinput></screen>
|
---|
278 |
|
---|
279 | <para>Now, as the <systemitem class="username">root</systemitem> user:</para>
|
---|
280 |
|
---|
281 | <screen><userinput>SSLDIR=/etc/ssl &&
|
---|
282 | install -d ${SSLDIR}/certs &&
|
---|
283 | cp -v certs/*.pem ${SSLDIR}/certs &&
|
---|
284 | c_rehash &&
|
---|
285 | install BLFS-ca-bundle*.crt ${SSLDIR}/ca-bundle.crt &&
|
---|
286 | unset SSLDIR</userinput></screen>
|
---|
287 |
|
---|
288 | <para>Finally, clean up the current directory:</para>
|
---|
289 |
|
---|
290 | <screen><userinput>rm -r certs BLFS-ca-bundle*</userinput></screen>
|
---|
291 |
|
---|
292 | </sect2>
|
---|
293 |
|
---|
294 | <sect2 role="content">
|
---|
295 | <title>Contents</title>
|
---|
296 |
|
---|
297 | <segmentedlist>
|
---|
298 | <segtitle>Installed Programs</segtitle>
|
---|
299 | <segtitle>Installed Libraries</segtitle>
|
---|
300 | <segtitle>Installed Directories</segtitle>
|
---|
301 |
|
---|
302 | <seglistitem>
|
---|
303 | <seg>make-ca.sh, make-cert.pl and remove-expired-certs.sh</seg>
|
---|
304 | <seg>None</seg>
|
---|
305 | <seg>/etc/ssl/certs</seg>
|
---|
306 | </seglistitem>
|
---|
307 | </segmentedlist>
|
---|
308 |
|
---|
309 | <variablelist>
|
---|
310 | <bridgehead renderas="sect3">Short Descriptions</bridgehead>
|
---|
311 | <?dbfo list-presentation="list"?>
|
---|
312 | <?dbhtml list-presentation="table"?>
|
---|
313 |
|
---|
314 | <varlistentry id="make-ca">
|
---|
315 | <term><command>make-ca.sh</command></term>
|
---|
316 | <listitem>
|
---|
317 | <para>is a <application>bash</application> script that reformats
|
---|
318 | the <filename>certdata.txt</filename> file for use by
|
---|
319 | <application>openssl</application>.</para>
|
---|
320 | <indexterm zone="cacerts make-ca">
|
---|
321 | <primary sortas="b-make-ca">make-ca</primary>
|
---|
322 | </indexterm>
|
---|
323 | </listitem>
|
---|
324 | </varlistentry>
|
---|
325 |
|
---|
326 | <varlistentry id="make-cert">
|
---|
327 | <term><command>make-cert.pl</command></term>
|
---|
328 | <listitem>
|
---|
329 | <para>is a utility <application>perl</application> script that
|
---|
330 | converts a single binary certificate (.der format) into .pem format.</para>
|
---|
331 | <indexterm zone="cacerts make-cert">
|
---|
332 | <primary sortas="b-make-cert">make-cert</primary>
|
---|
333 | </indexterm>
|
---|
334 | </listitem>
|
---|
335 | </varlistentry>
|
---|
336 |
|
---|
337 | <varlistentry id="remove-expired-certs">
|
---|
338 | <term><command>remove-expired-certs.sh</command></term>
|
---|
339 | <listitem>
|
---|
340 | <para>is a utility <application>perl</application> script that
|
---|
341 | removed expired certificates fom a directory. The defaut
|
---|
342 | directory is <filename class='directory'>/etc/ssl/ceerts</filename>.</para>
|
---|
343 | <indexterm zone="cacerts remove-expired-certs">
|
---|
344 | <primary sortas="b-remove-expired-certs">remove-expired-certs</primary>
|
---|
345 | </indexterm>
|
---|
346 | </listitem>
|
---|
347 | </varlistentry>
|
---|
348 | </variablelist>
|
---|
349 |
|
---|
350 | </sect2>
|
---|
351 | </sect1>
|
---|