summaryrefslogtreecommitdiffstats
path: root/base/server/sbin/pkispawn
blob: fa14d49096bc0455bbb055f5081d1c4abb12aa59 (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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
#!/usr/bin/python -tu
# Authors:
#     Matthew Harmsen <mharmsen@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright (C) 2011 Red Hat, Inc.
# All rights reserved.
#

# System Imports
from __future__ import absolute_import
from __future__ import print_function
import sys
import signal

if not hasattr(sys, "hexversion") or sys.hexversion < 0x020700f0:
    print("Python version %s.%s.%s is too old." % sys.version_info[:3])
    print("Please upgrade to at least Python 2.7.0.")
    sys.exit(1)
try:
    import ldap
    import os
    import requests
    import socket
    import struct
    import subprocess
    import time
    import traceback
    from time import strftime as date
    from pki.server.deployment import pkiconfig as config
    from pki.server.deployment.pkiparser import PKIConfigParser
    from pki.server.deployment import pkilogging
    from pki.server.deployment import pkimessages as log
    import pki.server.deployment.pkihelper as util
except ImportError:
    print("""\
There was a problem importing one of the required Python modules. The
error was:

    %s
""" % sys.exc_info()[1], file=sys.stderr)
    sys.exit(1)


# Handle the Keyboard Interrupt
# pylint: disable=W0613
def interrupt_handler(event, frame):
    print()
    print('\nInstallation canceled.')
    sys.exit(1)


# PKI Deployment Functions
def main(argv):
    """main entry point"""

    config.pki_deployment_executable = os.path.basename(argv[0])

    # Set the umask
    os.umask(config.PKI_DEPLOYMENT_DEFAULT_UMASK)

    # Set installation time
    ticks = time.time()
    config.pki_install_time = time.asctime(time.localtime(ticks))

    # Generate a timestamp
    config.pki_timestamp = date('%Y%m%d%H%M%S', time.localtime(ticks))
    config.pki_certificate_timestamp = \
        date('%Y-%m-%d %H:%M:%S', time.localtime(ticks))

    # Obtain the architecture bit-size
    config.pki_architecture = struct.calcsize("P") * 8

    # Retrieve hostname
    config.pki_hostname = socket.getfqdn()

    # Retrieve DNS domainname
    try:
        dnsdomainname = subprocess.check_output(["dnsdomainname"])
        dnsdomainname = dnsdomainname.decode('ascii').rstrip('\n')
        config.pki_dns_domainname = dnsdomainname
        if not len(config.pki_dns_domainname):
            print(log.PKI_DNS_DOMAIN_NOT_SET)
            config.pki_dns_domainname = config.pki_hostname
    except subprocess.CalledProcessError as exc:
        print(log.PKI_SUBPROCESS_ERROR_1 % exc)
        sys.exit(1)

    # Read and process command-line arguments.
    parser = PKIConfigParser(
        'PKI Instance Installation and Configuration',
        log.PKISPAWN_EPILOG)

    parser.optional.add_argument(
        '-f',
        dest='user_deployment_cfg', action='store',
        nargs=1, metavar='<file>',
        help='configuration filename '
        '(MUST specify complete path)')

    parser.optional.add_argument(
        '--precheck',
        dest='precheck', action='store_true',
        help='Execute pre-checks and exit')

    args = parser.process_command_line_arguments()

    config.default_deployment_cfg = \
        config.PKI_DEPLOYMENT_DEFAULT_CONFIGURATION_FILE

    # -f <user deployment config>
    if args.user_deployment_cfg is not None:
        config.user_deployment_cfg = str(
            args.user_deployment_cfg).strip('[\']')

    parser.validate()
    interactive = False

    if config.user_deployment_cfg is None:
        interactive = True
        parser.indent = 0
        print(log.PKISPAWN_INTERACTIVE_INSTALLATION)

    # Only run this program as "root".
    if not os.geteuid() == 0:
        sys.exit("'%s' must be run as root!" % argv[0])

    while True:
        # -s <subsystem>
        if args.pki_subsystem is None:
            interactive = True
            parser.indent = 0

            config.pki_subsystem = parser.read_text(
                'Subsystem (CA/KRA/OCSP/TKS/TPS)',
                options=['CA', 'KRA', 'OCSP', 'TKS', 'TPS'],
                default='CA', case_sensitive=False).upper()
            print()
        else:
            config.pki_subsystem = str(args.pki_subsystem).strip('[\']')

        parser.init_config()

        if config.user_deployment_cfg is None:
            if args.precheck:
                sys.exit(
                    'precheck mode is only valid for non-interactive installs')
            interactive = True
            parser.indent = 2

            print("Tomcat:")
            instance_name = parser.read_text(
                'Instance', 'DEFAULT', 'pki_instance_name')
            existing_data = parser.read_existing_deployment_data(instance_name)

            set_port(parser,
                     'pki_http_port',
                     'HTTP port',
                     existing_data)

            set_port(parser,
                     'pki_https_port',
                     'Secure HTTP port',
                     existing_data)

            set_port(parser,
                     'pki_ajp_port',
                     'AJP port',
                     existing_data)

            set_port(parser,
                     'pki_tomcat_server_port',
                     'Management port',
                     existing_data)

            print()

            print("Administrator:")
            parser.read_text('Username', config.pki_subsystem, 'pki_admin_uid')

            admin_password = parser.read_password(
                'Password', config.pki_subsystem, 'pki_admin_password',
                verifyMessage='Verify password')

            parser.set_property(config.pki_subsystem, 'pki_backup_password',
                                admin_password)
            parser.set_property(config.pki_subsystem,
                                'pki_client_database_password',
                                admin_password)
            parser.set_property(config.pki_subsystem,
                                'pki_client_pkcs12_password',
                                admin_password)

            if parser.mdict['pki_import_admin_cert'] == 'True':
                import_cert = 'Y'
            else:
                import_cert = 'N'

            import_cert = parser.read_text(
                'Import certificate (Yes/No)',
                default=import_cert, options=['Yes', 'Y', 'No', 'N'],
                sign='?', case_sensitive=False).lower()

            if import_cert == 'y' or import_cert == 'yes':
                parser.set_property(config.pki_subsystem,
                                    'pki_import_admin_cert',
                                    'True')
                parser.read_text('Import certificate from',
                                 config.pki_subsystem,
                                 'pki_admin_cert_file')
            else:
                parser.set_property(config.pki_subsystem,
                                    'pki_import_admin_cert',
                                    'False')

            parser.read_text('Export certificate to',
                             config.pki_subsystem,
                             'pki_client_admin_cert')

            # if parser.mdict['pki_hsm_enable'] == 'True':
            #     use_hsm = 'Y'
            # else:
            #     use_hsm = 'N'

            # use_hsm = parser.read_text(
            #     'Using hardware security module (HSM) (Yes/No)',
            #     default=use_hsm, options=['Yes', 'Y', 'No', 'N'],
            #     sign='?', case_sensitive=False).lower()

            # if use_hsm == 'y' or use_hsm == 'yes':
            #     # XXX:  Suppress interactive HSM installation
            #     print "Interactive HSM installation is currently unsupported."
            #     sys.exit(0)

            # TBD:  Interactive HSM installation
            # parser.set_property(config.pki_subsystem,
            #                     'pki_hsm_enable',
            #                     'True')
            # modulename = parser.read_text(
            #     'HSM Module Name (e. g. - nethsm)', allow_empty=False)
            # parser.set_property(config.pki_subsystem,
            #                     'pki_hsm_modulename',
            #                     modulename)
            # libfile = parser.read_text(
            #     'HSM Lib File ' +
            #     '(e. g. - /opt/nfast/toolkits/pkcs11/libcknfast.so)',
            #     allow_empty=False)
            # parser.set_property(config.pki_subsystem,
            #                     'pki_hsm_libfile',
            #                     libfile)
            # print

            print("Directory Server:")
            while True:
                parser.read_text('Hostname',
                                 config.pki_subsystem,
                                 'pki_ds_hostname')

                if parser.mdict['pki_ds_secure_connection'] == 'True':
                    secure = 'Y'
                else:
                    secure = 'N'

                secure = parser.read_text(
                    'Use a secure LDAPS connection (Yes/No/Quit)',
                    default=secure,
                    options=['Yes', 'Y', 'No', 'N', 'Quit', 'Q'],
                    sign='?', case_sensitive=False).lower()

                if secure == 'q' or secure == 'quit':
                    print("Installation canceled.")
                    sys.exit(0)

                if secure == 'y' or secure == 'yes':
                    # Set secure DS connection to true
                    parser.set_property(config.pki_subsystem,
                                        'pki_ds_secure_connection',
                                        'True')
                    # Prompt for secure 'ldaps' port
                    parser.read_text('Secure LDAPS Port',
                                     config.pki_subsystem,
                                     'pki_ds_ldaps_port')
                    # Specify complete path to a directory server
                    # CA certificate pem file
                    pem_file = parser.read_text(
                        'Directory Server CA certificate pem file',
                        allow_empty=False)
                    parser.set_property(config.pki_subsystem,
                                        'pki_ds_secure_connection_ca_pem_file',
                                        pem_file)
                else:
                    parser.read_text('LDAP Port',
                                     config.pki_subsystem,
                                     'pki_ds_ldap_port')

                parser.read_text('Bind DN',
                                 config.pki_subsystem,
                                 'pki_ds_bind_dn')
                parser.read_password('Password',
                                     config.pki_subsystem,
                                     'pki_ds_password')

                try:
                    parser.ds_verify_configuration()

                except ldap.LDAPError as e:
                    parser.print_text('ERROR: ' + e.args[0]['desc'])
                    continue

                parser.read_text('Base DN',
                                 config.pki_subsystem,
                                 'pki_ds_base_dn')
                try:
                    if not parser.ds_base_dn_exists():
                        break

                except ldap.LDAPError as e:
                    parser.print_text('ERROR: ' + e.args[0]['desc'])
                    continue

                remove = parser.read_text(
                    'Base DN already exists. Overwrite (Yes/No/Quit)',
                    options=['Yes', 'Y', 'No', 'N', 'Quit', 'Q'],
                    sign='?', allow_empty=False, case_sensitive=False).lower()

                if remove == 'q' or remove == 'quit':
                    print("Installation canceled.")
                    sys.exit(0)

                if remove == 'y' or remove == 'yes':
                    break

            print()

            print("Security Domain:")

            if config.pki_subsystem == "CA":
                parser.read_text('Name',
                                 config.pki_subsystem,
                                 'pki_security_domain_name')

            else:
                while True:
                    parser.read_text('Hostname',
                                     config.pki_subsystem,
                                     'pki_security_domain_hostname')

                    parser.read_text('Secure HTTP port',
                                     config.pki_subsystem,
                                     'pki_security_domain_https_port')

                    try:
                        parser.sd_connect()
                        info = parser.sd_get_info()
                        parser.print_text('Name: ' + info.name)
                        parser.set_property(config.pki_subsystem,
                                            'pki_security_domain_name',
                                            info.name)
                        break
                    except requests.exceptions.ConnectionError as e:
                        parser.print_text('ERROR: ' + str(e))

                while True:
                    parser.read_text('Username',
                                     config.pki_subsystem,
                                     'pki_security_domain_user')
                    parser.read_password('Password',
                                         config.pki_subsystem,
                                         'pki_security_domain_password')

                    try:
                        parser.sd_authenticate()
                        break
                    except requests.exceptions.HTTPError as e:
                        parser.print_text('ERROR: ' + str(e))

            print()

            if config.pki_subsystem == "TPS":
                print("External Servers:")

                while True:
                    parser.read_text('CA URL',
                                     config.pki_subsystem,
                                     'pki_ca_uri')
                    try:
                        status = parser.get_server_status('ca', 'pki_ca_uri')
                        if status == 'running':
                            break
                        parser.print_text('ERROR: CA is not running')
                    except requests.exceptions.ConnectionError as e:
                        parser.print_text('ERROR: ' + str(e))

                while True:
                    parser.read_text('TKS URL',
                                     config.pki_subsystem,
                                     'pki_tks_uri')
                    try:
                        status = parser.get_server_status('tks', 'pki_tks_uri')
                        if status == 'running':
                            break
                        parser.print_text('ERROR: TKS is not running')
                    except requests.exceptions.ConnectionError as e:
                        parser.print_text('ERROR: ' + str(e))

                while True:
                    keygen = parser.read_text(
                        'Enable server side key generation (Yes/No)',
                        options=['Yes', 'Y', 'No', 'N'], default='N',
                        sign='?', case_sensitive=False).lower()

                    if keygen == 'y' or keygen == 'yes':
                        parser.set_property(config.pki_subsystem,
                                            'pki_enable_server_side_keygen',
                                            'True')

                        parser.read_text('KRA URL',
                                         config.pki_subsystem,
                                         'pki_kra_uri')
                        try:
                            status = parser.get_server_status(
                                'kra', 'pki_kra_uri')
                            if status == 'running':
                                break
                            parser.print_text('ERROR: KRA is not running')
                        except requests.exceptions.ConnectionError as e:
                            parser.print_text('ERROR: ' + str(e))
                    else:
                        parser.set_property(config.pki_subsystem,
                                            'pki_enable_server_side_keygen',
                                            'False')
                        break

                print()

                print("Authentication Database:")

                while True:
                    parser.read_text('Hostname',
                                     config.pki_subsystem,
                                     'pki_authdb_hostname')
                    parser.read_text('Port',
                                     config.pki_subsystem,
                                     'pki_authdb_port')
                    basedn = parser.read_text('Base DN', allow_empty=False)
                    parser.set_property(config.pki_subsystem,
                                        'pki_authdb_basedn',
                                        basedn)

                    try:
                        parser.authdb_connect()
                        if parser.authdb_base_dn_exists():
                            break
                        else:
                            parser.print_text('ERROR: base DN does not exist')

                    except ldap.LDAPError as e:
                        parser.print_text('ERROR: ' + e.args[0]['desc'])

                print()

        if interactive:
            parser.indent = 0

            begin = parser.read_text(
                'Begin installation (Yes/No/Quit)',
                options=['Yes', 'Y', 'No', 'N', 'Quit', 'Q'],
                sign='?', allow_empty=False, case_sensitive=False).lower()
            print()

            if begin == 'q' or begin == 'quit':
                print("Installation canceled.")
                sys.exit(0)

            if begin == 'y' or begin == 'yes':
                break

        else:
            break

    if not os.path.exists(config.PKI_DEPLOYMENT_SOURCE_ROOT +
                          "/" + config.pki_subsystem.lower()):
        print("ERROR:  " + log.PKI_SUBSYSTEM_NOT_INSTALLED_1 %
              config.pki_subsystem.lower())
        sys.exit(1)

    start_logging()
    create_master_dictionary(parser)

    if not interactive and \
            not config.str2bool(parser.mdict['pki_skip_configuration']):
        check_ds(parser)
        check_security_domain(parser)

    if args.precheck:
        print('pre-checks completed successfully.')
        sys.exit(0)

    print("Installing " + config.pki_subsystem + " into " +
          parser.mdict['pki_instance_path'] + ".")

    # Process the various "scriptlets" to create the specified PKI subsystem.
    pki_subsystem_scriptlets = parser.mdict['spawn_scriplets'].split()
    deployer = util.PKIDeployer(parser.mdict, parser.slots_dict)

    try:
        for scriptlet_name in pki_subsystem_scriptlets:

            scriptlet_module = __import__(
                "pki.server.deployment.scriptlets." + scriptlet_name,
                fromlist=[scriptlet_name])

            scriptlet = scriptlet_module.PkiScriptlet()

            scriptlet.spawn(deployer)

    # pylint: disable=W0703
    except Exception as e:
        log_error_details()
        print()
        print("Installation failed: %s" % e)
        print()
        sys.exit(1)

    config.pki_log.debug(log.PKI_DICTIONARY_MASTER,
                         extra=config.PKI_INDENTATION_LEVEL_0)
    config.pki_log.debug(pkilogging.log_format(parser.mdict),
                         extra=config.PKI_INDENTATION_LEVEL_0)

    external = deployer.configuration_file.external
    step_one = deployer.configuration_file.external_step_one

    if external and step_one:
        external_csr_path = deployer.mdict['pki_external_csr_path']
        if external_csr_path:
            print_external_ca_step_one_information(parser.mdict)
        else:
            print_existing_ca_step_one_information(parser.mdict)
    else:
        print_install_information(parser.mdict)


def start_logging():
    # Enable 'pkispawn' logging.
    config.pki_log_dir = config.pki_root_prefix + \
        config.PKI_DEPLOYMENT_LOG_ROOT
    config.pki_log_name = "pki" + "-" + \
                          config.pki_subsystem.lower() + \
                          "-" + "spawn" + "." + \
                          config.pki_timestamp + "." + "log"
    print('Log file: %s/%s' % (config.pki_log_dir, config.pki_log_name))
    rv = pkilogging.enable_pki_logger(config.pki_log_dir,
                                      config.pki_log_name,
                                      config.pki_log_level,
                                      config.pki_console_log_level,
                                      "pkispawn")
    if rv != OSError:
        config.pki_log = rv
    else:
        print(log.PKI_UNABLE_TO_CREATE_LOG_DIRECTORY_1 % config.pki_log_dir)
        sys.exit(1)


def create_master_dictionary(parser):
    # Read the specified PKI configuration file.
    rv = parser.read_pki_configuration_file()
    if rv != 0:
        config.pki_log.error(log.PKI_UNABLE_TO_PARSE_1, rv,
                             extra=config.PKI_INDENTATION_LEVEL_0)
        sys.exit(1)

    # Read in the PKI slots configuration file.
    parser.compose_pki_slots_dictionary()
    config.pki_log.debug(log.PKI_DICTIONARY_SLOTS,
                         extra=config.PKI_INDENTATION_LEVEL_0)
    config.pki_log.debug(pkilogging.log_format(parser.slots_dict),
                         extra=config.PKI_INDENTATION_LEVEL_0)
    # Combine the various sectional dictionaries into a PKI master dictionary
    parser.compose_pki_master_dictionary()
    parser.mdict['pki_spawn_log'] = \
        config.pki_log_dir + "/" + config.pki_log_name
    config.pki_log.debug(log.PKI_DICTIONARY_MASTER,
                         extra=config.PKI_INDENTATION_LEVEL_0)
    config.pki_log.debug(pkilogging.log_format(parser.mdict),
                         extra=config.PKI_INDENTATION_LEVEL_0)


def check_security_domain(parser):
    if parser.mdict['pki_security_domain_type'] != "new":
        try:
            # Verify existence of Security Domain Password
            if 'pki_security_domain_password' not in parser.mdict or \
                    not len(parser.mdict['pki_security_domain_password']):
                config.pki_log.error(
                    log.PKIHELPER_UNDEFINED_CONFIGURATION_FILE_ENTRY_2,
                    "pki_security_domain_password",
                    parser.mdict['pki_user_deployment_cfg'],
                    extra=config.PKI_INDENTATION_LEVEL_0)
                sys.exit(1)

            if not config.str2bool(parser.mdict['pki_skip_sd_verify']):
                parser.sd_connect()
                info = parser.sd_get_info()
                parser.set_property(config.pki_subsystem,
                                    'pki_security_domain_name',
                                    info.name)
                parser.sd_authenticate()

        except requests.exceptions.ConnectionError as e:
            print(('ERROR:  Unable to access security domain: ' + str(e)))
            sys.exit(1)

        except requests.exceptions.HTTPError as e:
            print(('ERROR:  Unable to access security domain: ' + str(e)))
            sys.exit(1)


def check_ds(parser):
    try:
        # Verify existence of Directory Server Password
        if 'pki_ds_password' not in parser.mdict or \
                not len(parser.mdict['pki_ds_password']):
            config.pki_log.error(
                log.PKIHELPER_UNDEFINED_CONFIGURATION_FILE_ENTRY_2,
                "pki_ds_password",
                parser.mdict['pki_user_deployment_cfg'],
                extra=config.PKI_INDENTATION_LEVEL_0)
            sys.exit(1)

        if not config.str2bool(parser.mdict['pki_skip_ds_verify']):
            parser.ds_verify_configuration()

            if parser.ds_base_dn_exists() and not \
                    config.str2bool(parser.mdict['pki_ds_remove_data']):
                print('ERROR:  Base DN already exists.')
                sys.exit(1)

    except ldap.LDAPError as e:
        print('ERROR:  Unable to access directory server: ' +
              e.args[0]['desc'])
        sys.exit(1)


def set_port(parser, tag, prompt, existing_data):
    if tag in existing_data:
        parser.set_property(config.pki_subsystem, tag, existing_data[tag])
    else:
        parser.read_text(prompt, config.pki_subsystem, tag)


def print_external_ca_step_one_information(mdict):

    print(log.PKI_SPAWN_INFORMATION_HEADER)
    print("      The %s subsystem of the '%s' instance is still incomplete." %
          (config.pki_subsystem, mdict['pki_instance_name']))
    print()
    print("      A CSR for the CA certificate has been generated at:\n"
          "            %s"
          % mdict['pki_external_csr_path'])
    print()
    print("      Submit the CSR to an external CA to generate a CA certificate\n"
          "      for this subsystem. Import the CA certificate and the certificate\n"
          "      chain, then continue the installation.")
    print(log.PKI_SPAWN_INFORMATION_FOOTER)


def print_existing_ca_step_one_information(mdict):

    print(log.PKI_SPAWN_INFORMATION_HEADER)
    print("      The %s subsystem of the '%s' instance is still incomplete." %
          (config.pki_subsystem, mdict['pki_instance_name']))
    print()
    print("      Import an existing CA certificate with the key and the CSR, and\n"
          "      the certificate chain if available, then continue the installation.")
    print(log.PKI_SPAWN_INFORMATION_FOOTER)


def print_install_information(mdict):

    skip_configuration = config.str2bool(mdict['pki_skip_configuration'])
    print(log.PKI_SPAWN_INFORMATION_HEADER)
    if skip_configuration:
        print("      The %s subsystem of the '%s' instance\n"
              "      must still be configured!" %
              (config.pki_subsystem, mdict['pki_instance_name']))
    else:
        print("      Administrator's username:             %s" %
              mdict['pki_admin_uid'])
        if os.path.isfile(mdict['pki_client_admin_cert_p12']):
            print("      Administrator's PKCS #12 file:\n            %s" %
                  mdict['pki_client_admin_cert_p12'])
        if not config.str2bool(mdict['pki_client_database_purge']):
            print()
            print("      Administrator's certificate nickname:\n            %s"
                  % mdict['pki_admin_nickname'])
        if not config.str2bool(mdict['pki_clone']):
            print("      Administrator's certificate database:\n            %s"
                  % mdict['pki_client_database_dir'])
        else:
            print()
            print("      This %s subsystem of the '%s' instance\n"
                  "      is a clone." %
                  (config.pki_subsystem, mdict['pki_instance_name']))
        print(log.PKI_CHECK_STATUS_MESSAGE % mdict['pki_instance_name'])
        print(log.PKI_INSTANCE_RESTART_MESSAGE % mdict['pki_instance_name'])
        if (((config.pki_subsystem == "KRA" or
              config.pki_subsystem == "OCSP") and
             config.str2bool(mdict['pki_standalone'])) and
                not config.str2bool(mdict['pki_external_step_two'])):
            # Stand-alone PKI KRA/OCSP (External CA Step 1)
            print(log.PKI_CONFIGURATION_STANDALONE_1 % config.pki_subsystem)
        else:
            print(log.PKI_ACCESS_URL % (mdict['pki_hostname'],
                                        mdict['pki_https_port'],
                                        config.pki_subsystem.lower()))
            if not config.str2bool(mdict['pki_enable_on_system_boot']):
                print(log.PKI_SYSTEM_BOOT_STATUS_MESSAGE % "disabled")
            else:
                print(log.PKI_SYSTEM_BOOT_STATUS_MESSAGE % "enabled")
    print(log.PKI_SPAWN_INFORMATION_FOOTER)


def log_error_details():
    e_type, e_value, e_stacktrace = sys.exc_info()
    config.pki_log.debug(
        "Error Type: " + e_type.__name__, extra=config.PKI_INDENTATION_LEVEL_2)
    config.pki_log.debug(
        "Error Message: " + str(e_value), extra=config.PKI_INDENTATION_LEVEL_2)
    stacktrace_list = traceback.format_list(traceback.extract_tb(e_stacktrace))
    e_stacktrace = ""
    for l in stacktrace_list:
        e_stacktrace += l
    config.pki_log.debug(e_stacktrace, extra=config.PKI_INDENTATION_LEVEL_2)
    del e_type, e_value, e_stacktrace

# PKI Deployment Entry Point
if __name__ == "__main__":
    signal.signal(signal.SIGINT, interrupt_handler)
    main(sys.argv)