summaryrefslogtreecommitdiffstats
path: root/base/silent/templates/subca_silent.template
blob: bbcc225529a4fc62a2440b0d71f5077c05863b87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
#!/bin/bash
##  BEGIN COPYRIGHT BLOCK
##  (C) 2009 Red Hat, Inc.
##  All rights reserved.
##  END COPYRIGHT BLOCK


##  Always switch into this base directory
##  prior to script execution so that all
##  of its output is written to this directory

cd `dirname $0`


##  Disallow script to be run as the name of this template
subca_silent_script=`basename $0`
if	[ "${subca_silent_script}" = "subca_silent.template" ] ; then
	printf "\n"
	printf "Usage:  (1) Install AND configure a directory server instance.\n\n"
	printf "        (2) Install AND configure a Root CA subsystem instance\n"
	printf "            that is its own security domain.\n\n"
	printf "        (3) Use 'pkicreate' to install a second CA subsystem\n"
	printf "            instance (this will become a Subordinate CA).\n"
	printf "            [Do NOT configure this CA subsystem instance!]\n\n"
	printf "        (4) Copy '$0' to a new script name\n"
	printf "            without the '.template' extension.\n"
	printf "            (e .g. - 'configure_subca_instance')\n\n"
	printf "        (5) Fill in all MANDATORY user-defined variables\n"
	printf "            in the new script.\n\n"
	printf "        (6) Change any OPTIONAL user-defined variables\n"
	printf "            in the new script as desired.\n\n"
	printf "        (7) Become the 'root' user, and execute the new script to\n"
	printf "            configure a Subordinate CA subsystem instance.\n\n"
	exit 255
fi


##
##  This script MUST be run as root!
##

ROOTUID=0

OS=`uname`
if [ "${OS}" = "Linux" ] ; then
	MY_EUID=`/usr/bin/id -u`
	MY_UID=`/usr/bin/id -ur`
	USERNAME=`/usr/bin/id -un`
else
	printf "ERROR:  Unsupported operating system '${OS}'!\n"
	exit 255
fi

if	[ "${MY_UID}"  != "${ROOTUID}" ] &&
	[ "${MY_EUID}" != "${ROOTUID}" ] ; then
	printf "ERROR:  The '$0' script must be run as root!\n"
	exit 255
fi



##############################################################################
##############################################################################
##                                                                          ##
##  P K I   S I L E N T  -  V A R I A B L E   D E C L A R A T I O N         ##
##                                                                          ##
##############################################################################
##############################################################################

##############################################################################
##  U S E R - D E F I N E D   V A R I A B L E S   ( M A N D A T O R Y )     ##
##############################################################################

##
##  IMPORTANT:  'Escape' ALL spaces in EACH variable specified below!
##
##              For Example:
##
##                  pki_security_domain_name="My\ Security\ Domain"
##

##  PKI Silent Security Database Variables
##  (e. g. - PKI Silent "browser" database)
pki_silent_security_database_repository="/tmp"
pki_silent_security_database_password=

##  PKI Security Domain Variables
##  (e. g. - Security Domain Login Panel)
pki_security_domain_name=
pki_security_domain_host=`hostname`
pki_security_domain_admin_name=admin
pki_security_domain_admin_password=

##  PKI Internal LDAP Database Variables
##  (e. g. - Database Panel)
pki_ldap_host=localhost
pki_ldap_port=389
pki_bind_dn="cn=Directory\ Manager"
pki_bind_password=

##  PKI Instance-Specific Token Variables
##  (e. g. - Module Panel)
subca_token_name=internal
subca_token_password=

##  PKI Instance-Specific Backup Variables
##  (e. g. - Backup Key and Certificates Panel)
subca_backup_password=

##  PKI Email Variables
##
##      For example, to specify 'pkitest@example.com':
##
##          pki_email_name=pkitest
##          pki_email_company=example
##          pki_email_domain=com
##
pki_email_name=
pki_email_company=
pki_email_domain=

##  PKI Silent Admin Variables
##  (e. g. - Import Admin Certificate into PKI Silent "browser" database)
pki_silent_admin_user=admin
pki_silent_admin_password=
pki_silent_admin_email="${pki_email_name}\@${pki_email_company}\.${pki_email_domain}"



##############################################################################
##  P R E - D E F I N E D   " D E F A U L T "   V A R I A B L E S           ##
##############################################################################

##  PKI Subsystem Host (computed by default)
pki_host=`hostname`

##  PKI Subsystem Names
ca_subsystem_name="Certificate\ Authority"

##  PKI Subsystem Instance Names
subca_instance_name="pki-subca"

##  PKI Subsystem Init Script Names
subca_init_script="pki-cad"

##
##  NOTE:  Default PKI Instance Ports
##
##      CA:
##
##          *180 - non-secure port (not role specific)
##          *701 - non-secure Tomcat port
##          *443 - secure EE port
##          *444 - secure Agent port
##          *445 - secure Admin port
##
##
##  For Example:
##
##      semanage port -l | grep pki
##
##      pki_ca_port_t          tcp      9180, 9701, 9443, 9444, 9445
##      pki_subca_port_t       tcp      9580, 9801, 9543, 9544, 9545
##

## CA ports
ca_nonssl_port=9180
ca_agent_port=9443
ca_ee_port=9444
ca_admin_port=9445

## Subordinate CA ports
subca_nonssl_port=9580
subca_agent_port=9543
subca_ee_port=9544
subca_admin_port=9545



##############################################################################
##  U S E R - D E F I N E D   V A R I A B L E S   ( O P T I O N A L )       ##
##############################################################################

##  PKI Silent Log Files
pki_silent_subca_log=/tmp/subca.log


##
## NOTE:  For comparison's sake, if the default instances were manually
##        configured using a Firefox browser, the content of the corresponding
##        Firefox browser's security libraries would be something similar
##        to this:
##
##            Certificate Nickname                          Trust Attributes
##                                                          SSL,S/MIME,JAR/XPI
##
##            Certificate Authority 2 - ${pki_security_domain_name}   ,,   
##            CA Administrator of Instance ${subca_instance_name}'s
##                              ${pki_security_domain_name} ID        u,u,u
##            ${pki_host}                                             P,,
##            Certificate Authority - ${pki_security_domain_name}     CT,C,C
##
##        where:
##
##                Nickname:  "Certificate Authority 2 - "
##                        +  "${pki_security_domain_name}"
##            Subject Name:  "cn=Certificate Authority 2,"
##                        +  "o=${pki_security_domain_name}"
##
##                Nickname:  "CA Administrator of Instance "
##                        +  "${subca_instance_name}'s "
##                        +  "${pki_security_domain_name} ID"
##            Subject Name:  "cn=CA Administrator of Instance "
##                        +  "${subca_instance_name},"
##                        +  "uid=admin,"
##                        +  "e=${pki_silent_admin_email},"
##                        +  "o=${pki_security_domain_name}"
##
##                Nickname:  "${pki_host}"
##            Subject Name:  "cn=${pki_host},"
##                        +  "o=${pki_security_domain_name}"
##
##                Nickname:  "Certificate Authority - "
##                        +  "${pki_security_domain_name}"
##            Subject Name:  "cn=Certificate Authority,"
##                        +  "o=${pki_security_domain_name}"
##


##  Miscellaneous CA Variables
##
##  REMINDER:  'Escape' ALL spaces in EACH variable specified below!
##
##  NOTE:  For comparison's sake, if the default instances were manually
##         configured using a Firefox browser, the content of the corresponding
##         "/var/lib/${subca_instance_name}/alias/" security libraries would be
##         something similar to this:
##
##             Certificate Nickname                         Trust Attributes
##                                                          SSL,S/MIME,JAR/XPI
##
##             caSigningCert cert-${subca_instance_name}             CTu,Cu,Cu
##             Server-Cert cert-${subca_instance_name}               u,u,u
##             Certificate Authority - ${pki_security_domain_name}   CT,c,
##             ocspSigningCert cert-${subca_instance_name}           u,u,u
##             auditSigningCert cert-${subca_instance_name}          u,u,u
##             subsystemCert cert-${subca_instance_name}             u,u,u
##
##         where:
##
##                 Nickname:  "caSigningCert cert-${subca_instance_name}"
##             Subject Name:  "cn=Certificate Authority 2,"
##                         +  "o=${pki_security_domain_name}"
##
##                 Nickname:  "Server-Cert cert-${subca_instance_name}"
##             Subject Name:  "cn=${pki_host},"
##                         +  "o=${pki_security_domain_name}"
##
##                 Nickname:  "Certificate Authority - "
##                         +  "${pki_security_domain_name}"
##             Subject Name:  "cn=Certificate Authority,"
##                         +  "o=${pki_security_domain_name}"
##
##                 Nickname:  "ocspSigningCert cert-${subca_instance_name}"
##             Subject Name:  "cn=OCSP Signing Certificate 2,"
##                         +  "o=${pki_security_domain_name}"
##
##                 Nickname:  "auditSigningCert cert-${subca_instance_name}"
##             Subject Name:  "cn=CA Audit Signing Certificate 2,"
##                         +  "o=${pki_security_domain_name}"
##
##                 Nickname:  "subsystemCert cert-${subca_instance_name}"
##             Subject Name:  "cn=CA Subsystem Certificate 2,"
##                         +  "o=${pki_security_domain_name}"
##
##  NOTE:  The parameters for the signing algorithms have the following meaning:
##         subca_signing_algorithm             - signature algorithm used by the CA and OCSP signing certs to sign objects.
##         subca_signing_signingalgorithm      - optionally specify the algorithm used by the CA signing cert to sign objects
##         subca_ocsp_signing_signingalgorithm - optionally specify the algorithm used by the CA ocsp signing cert to sign objects
##

subca_agent_name="CA\ Administrator\ of\ Instance\ ${subca_instance_name}\'s\ ${pki_security_domain_name}\ ID"
subca_agent_key_size=2048
subca_agent_key_type=rsa
subca_agent_cert_subject="cn=CA\ Administrator\ of\ Instance\ ${subca_instance_name},uid=admin,e=${pki_silent_admin_email},o=${pki_security_domain_name}"
subca_base_dn="dc=${pki_host}-${subca_instance_name}"
subca_db_name="${pki_host}-${subca_instance_name}"
subca_key_size=2048
subca_key_type=rsa
subca_signing_algorithm=SHA256withRSA
subca_signing_signingalgorithm=SHA256withRSA
subca_ocsp_signing_signingalgorithm=SHA256withRSA
subca_sign_cert_subject_name="cn=Certificate\ Authority\ 2,o=${pki_security_domain_name}"
subca_subsystem_cert_subject_name="cn=CA\ Subsystem\ Certificate\ 2,o=${pki_security_domain_name}"
subca_ocsp_cert_subject_name="cn=OCSP\ Signing\ Certificate\ 2,o=${pki_security_domain_name}"
subca_server_cert_subject_name="cn=${pki_host},o=${pki_security_domain_name}"
subca_audit_signing_cert_subject_name="cn=CA\ Audit\ Signing\ Certificate\ 2,o=${pki_security_domain_name}"



##############################################################################
##############################################################################
##                                                                          ##
##  P K I   S I L E N T  -  S U B S Y S T E M   C O N F I G U R A T I O N   ##
##                                                                          ##
##############################################################################
##############################################################################

##############################################################################
##  P K I   S I L E N T   I N I T I A L I Z A T I O N                       ##
##############################################################################

## (1) Make certain that user has defined all MANDATORY user-defined variables!
usage_errors=0
usage_error_preamble="ERROR:  User MUST define a value for"

if [ "${pki_silent_security_database_password}" = "" ] ; then
	printf "${usage_error_preamble} 'pki_silent_security_database_password'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi
if [ "${pki_security_domain_name}" = "" ] ; then
	printf "${usage_error_preamble} 'pki_security_domain_name'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi
if [ "${pki_security_domain_admin_password}" = "" ] ; then
	printf "${usage_error_preamble} 'pki_security_domain_admin_password'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi
if [ "${pki_bind_password}" = "" ] ; then
	printf "${usage_error_preamble} 'pki_bind_password'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi
if [ "${subca_token_password}" = "" ] ; then
	printf "${usage_error_preamble} 'subca_token_password'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi
if [ "${subca_backup_password}" = "" ] ; then
	printf "${usage_error_preamble} 'subca_backup_password'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi
if [ "${pki_email_name}" = "" ] ; then
	printf "${usage_error_preamble} 'pki_email_name'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi
if [ "${pki_email_company}" = "" ] ; then
	printf "${usage_error_preamble} 'pki_email_company'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi
if [ "${pki_email_domain}" = "" ] ; then
	printf "${usage_error_preamble} 'pki_email_domain'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi
if [ "${pki_silent_admin_password}" = "" ] ; then
	printf "${usage_error_preamble} 'pki_silent_admin_password'!\n"
	usage_errors=`expr ${usage_errors} + 1`
fi


## (2) Make certain that a PKI instance of the specified name EXISTS,
##     but has NOT been previously CONFIGURED!
existence_errors=0
existence_error_preamble="ERROR:  No PKI Instance named"
configuration_errors=0
configuration_error_preamble="ERROR:  A PKI Instance named"
configuration_error_postamble="EXISTS,\n        but has PREVIOUSLY been CONFIGURED!"

if [ ! -f "/var/lib/${subca_instance_name}/conf/CS.cfg" ] ; then
	printf "${existence_error_preamble} '${subca_instance_name}' EXISTS!\n"
	existence_errors=`expr ${existence_errors} + 1`
else
	subca_configuration_check=`grep -c preop /var/lib/${subca_instance_name}/conf/CS.cfg`
	if [ ${subca_configuration_check} -eq 0 ] ; then
	    printf "${configuration_error_preamble} '${subca_instance_name}' "
		printf "${configuration_error_postamble}\n"
		configuration_errors=`expr ${configuration_errors} + 1`
	fi
fi


if	[ ${usage_errors} -ne 0 ]     ||
	[ ${existence_errors} -ne 0 ] ||
	[ ${configuration_errors} -ne 0 ] ; then
	printf "\n"
	printf "Please correct ALL errors listed above and re-run\n"
	printf "the '$0' script!\n\n"
	exit 255
fi


## (3) Make certain that 'pkisilent' exists and is executable on this system.
if [ ! -x "/usr/bin/pkisilent" ] ; then
	printf "\n"
	printf "ERROR:  Please install the 'pki-server' package and re-run\n"
	printf "the '$0' script!\n\n"
	exit 255
fi


## (4) Check for old PKI Silent Security Databases, but DO NOT remove them!
##     Instead, inform the user and exit this script.
if	[ -f "${pki_silent_security_database_repository}/cert8.db" ] ||
	[ -f "${pki_silent_security_database_repository}/key3.db" ] ||
	[ -f "${pki_silent_security_database_repository}/secmod.db" ] ; then
	printf "\n"
	printf "WARNING:  At least one of the security databases\n"
	printf "          (i. e. - 'cert8.db', 'key3.db', and/or 'secmod.db')\n"
	printf "          required by '${subca_silent_script}' exists at the\n"
	printf "          specified location '${pki_silent_security_database_repository}'.\n"
	printf "\n"
	printf "          Please MANUALLY move or erase these security database(s),\n"
	printf "          or specify a different location before re-running this script.\n\n"
	exit 255
fi


## (5) Remove ALL old PKI Silent log files
printf "Removing old PKI Silent log files:\n"
if [ -f ${pki_silent_subca_log} ] ; then
	printf "    Removing old '${pki_silent_subca_log}' . . . "
	rm ${pki_silent_subca_log}
	printf "done.\n"
fi
printf "Done.\n\n"



##############################################################################
##  C A L C U L A T E   P K I   I N S T A N C E   P I N S                   ##
##############################################################################

##  PKI Subsystem Instance PINS
subca_preop_pin=`cat /var/lib/${subca_instance_name}/conf/CS.cfg \
	| grep preop.pin | grep -v grep | awk -F= '{print $2}'`



##############################################################################
##  C E R T I F I C A T E   A U T H O R I T Y                               ##
##############################################################################
##
##  For example, upon completion,
##  execute '/sbin/service ${subca_init_script} status ${subca_instance_name}':
##
##      ${subca_instance_name} (pid 7843) is running ...
##
##          Unsecure Port     = http://${pki_host}:9180/ca/ee/ca
##          Secure Agent Port = https://${pki_host}:9443/ca/agent/ca
##          Secure EE Port    = https://${pki_host}:9444/ca/ee/ca
##          Secure Admin Port = https://${pki_host}:9445/ca/services
##          PKI Console Port  = pkiconsole https://${pki_host}:9445/ca
##          Tomcat Port       = 9701 (for shutdown)
##
##
##          Security Domain URL:
##          ==================================================================
##          https://${pki_host}:9445
##          ==================================================================
##

##  Configure Subordinate CA
printf "'${subca_silent_script}':  Configuring '${subca_instance_name}' . . .\n"
pkisilent ConfigureSubCA \
	-cs_hostname "${pki_host}" \
	-cs_port ${subca_admin_port} \
	-sd_hostname "${pki_security_domain_host}" \
	-sd_ssl_port ${ca_ee_port} \
	-sd_agent_port ${ca_agent_port} \
	-sd_admin_port ${ca_admin_port} \
	-sd_admin_name "${pki_security_domain_admin_name}" \
	-sd_admin_password ${pki_security_domain_admin_password} \
	-ca_hostname ${pki_security_domain_host} \
	-ca_port ${ca_nonssl_port} \
	-ca_ssl_port ${ca_ee_port} \
	-client_certdb_dir ${pki_silent_security_database_repository} \
	-client_certdb_pwd ${pki_silent_security_database_password} \
	-preop_pin ${subca_preop_pin} \
	-domain_name "${pki_security_domain_name}" \
	-admin_user ${pki_silent_admin_user} \
	-admin_email "${pki_silent_admin_email}" \
	-admin_password ${pki_silent_admin_password} \
	-agent_name ${subca_agent_name} \
	-ldap_host ${pki_ldap_host} \
	-ldap_port ${pki_ldap_port} \
	-bind_dn "${pki_bind_dn}" \
	-bind_password ${pki_bind_password} \
	-base_dn "${subca_base_dn}" \
	-db_name "${subca_db_name}" \
	-key_size ${subca_key_size} \
	-key_type ${subca_key_type} \
        -signing_algorithm ${subca_signing_algorithm} \
        -signing_signingalgorithm ${subca_signing_signingalgorithm} \
        -ocsp_signing_signingalgorithm ${subca_ocsp_signing_signingalgorithm} \
	-token_name ${subca_token_name} \
	-token_pwd ${subca_token_password} \
	-agent_key_size ${subca_agent_key_size} \
	-agent_key_type ${subca_agent_key_type} \
	-agent_cert_subject "${subca_agent_cert_subject}" \
	-backup_pwd ${subca_backup_password} \
	-subsystem_name "${ca_subsystem_name}" \
	-subca_sign_cert_subject_name "${subca_sign_cert_subject_name}" \
	-subca_subsystem_cert_subject_name "${subca_subsystem_cert_subject_name}" \
	-subca_ocsp_cert_subject_name "${subca_ocsp_cert_subject_name}" \
	-subca_server_cert_subject_name "${subca_server_cert_subject_name}" \
	-subca_audit_signing_cert_subject_name \
	"${subca_audit_signing_cert_subject_name}" \
	| tee ${pki_silent_subca_log}

##  Restart Subordinate CA
/sbin/service ${subca_init_script} restart ${subca_instance_name}

exit 0