|
| 1 | +from leapp import reporting |
| 2 | +from leapp.libraries.common.config import architecture, version |
| 3 | +from leapp.libraries.common.rpms import has_package |
| 4 | +from leapp.libraries.stdlib import api |
| 5 | +from leapp.models import DistributionSignedRPM, TrackedFilesInfoSource |
| 6 | + |
| 7 | +DEFAULT_OPENSSL_CONF = '/etc/pki/tls/openssl.cnf' |
| 8 | +URL_8_CRYPTOPOLICIES = 'https://red.ht/rhel-8-system-wide-crypto-policies' |
| 9 | +URL_9_CRYPTOPOLICIES = 'https://red.ht/rhel-9-system-wide-crypto-policies' |
| 10 | + |
| 11 | + |
| 12 | +def check_ibmca(): |
| 13 | + if not architecture.matches_architecture(architecture.ARCH_S390X): |
| 14 | + # not needed check really, but keeping it to make it clear |
| 15 | + return |
| 16 | + if not has_package(DistributionSignedRPM, 'openssl-ibmca'): |
| 17 | + return |
| 18 | + # In RHEL 9 has been introduced new technology: openssl providers. The engine |
| 19 | + # is deprecated, so keep proper teminology to not confuse users. |
| 20 | + dst_tech = 'engine' if version.get_target_major_version() == '8' else 'providers' |
| 21 | + summary = ( |
| 22 | + 'The presence of openssl-ibmca package suggests that the system may be configured' |
| 23 | + ' to use the IBMCA OpenSSL engine.' |
| 24 | + ' Due to major changes in OpenSSL and libica between RHEL {source} and RHEL {target} it is not' |
| 25 | + ' possible to migrate OpenSSL configuration files automatically. Therefore,' |
| 26 | + ' it is necessary to enable IBMCA {tech} in the OpenSSL config file manually' |
| 27 | + ' after the system upgrade.' |
| 28 | + .format( |
| 29 | + source=version.get_source_major_version(), |
| 30 | + target=version.get_target_major_version(), |
| 31 | + tech=dst_tech |
| 32 | + ) |
| 33 | + ) |
| 34 | + |
| 35 | + hint = ( |
| 36 | + 'Configure the IBMCA {tech} manually after the upgrade.' |
| 37 | + ' Please, be aware that it is not recommended to configure the system default' |
| 38 | + ' {fpath}. Instead, it is recommended to configure a copy of' |
| 39 | + ' that file and use this copy only for particular applications that are supposed' |
| 40 | + ' to utilize the IBMCA {tech}. The location of the OpenSSL configuration file' |
| 41 | + ' can be specified using the OPENSSL_CONF environment variable.' |
| 42 | + .format(tech=dst_tech, fpath=DEFAULT_OPENSSL_CONF) |
| 43 | + ) |
| 44 | + |
| 45 | + reporting.create_report([ |
| 46 | + reporting.Title('Detected possible use of IBMCA in OpenSSL'), |
| 47 | + reporting.Summary(summary), |
| 48 | + reporting.Remediation(hint=hint), |
| 49 | + reporting.Severity(reporting.Severity.MEDIUM), |
| 50 | + reporting.Groups([ |
| 51 | + reporting.Groups.POST, |
| 52 | + reporting.Groups.ENCRYPTION |
| 53 | + ]), |
| 54 | + ]) |
| 55 | + |
| 56 | + |
| 57 | +def _is_openssl_modified(): |
| 58 | + tracked_files = next(api.consume(TrackedFilesInfoSource), None) |
| 59 | + if not tracked_files: |
| 60 | + # unexpected at all, skipping testing, but keeping the log just in case |
| 61 | + api.current_logger.warning('The TrackedFilesInfoSource message is missing! Skipping check of openssl config.') |
| 62 | + return False |
| 63 | + for finfo in tracked_files.files: |
| 64 | + if finfo.path == DEFAULT_OPENSSL_CONF: |
| 65 | + return finfo.is_modified |
| 66 | + return False |
| 67 | + |
| 68 | + |
| 69 | +def check_default_openssl(): |
| 70 | + if not _is_openssl_modified(): |
| 71 | + return |
| 72 | + |
| 73 | + crypto_url = URL_8_CRYPTOPOLICIES if version.get_target_major_version == '8' else URL_9_CRYPTOPOLICIES |
| 74 | + |
| 75 | + # TODO(pstodulk): Needs in future some rewording, as OpenSSL engines are |
| 76 | + # deprecated since "RHEL 8" and people should use OpenSSL providers instead. |
| 77 | + # (IIRC, they are required to use OpenSSL providers since RHEL 9.) The |
| 78 | + # current wording could be inaccurate. |
| 79 | + summary = ( |
| 80 | + 'The OpenSSL configuration file ({fpath}) has been' |
| 81 | + ' modified on the system. RHEL 8 (and newer) systems provide a crypto-policies' |
| 82 | + ' mechanism ensuring usage of system-wide secure cryptography algorithms.' |
| 83 | + ' Also the target system uses newer version of OpenSSL that is not fully' |
| 84 | + ' compatible with the current one.' |
| 85 | + ' To ensure the upgraded system uses crypto-policies as expected,' |
| 86 | + ' the new version of the openssl configuration file must be installed' |
| 87 | + ' during the upgrade. This will be done automatically.' |
| 88 | + ' The original configuration file will be saved' |
| 89 | + ' as "{fpath}.leappsave".' |
| 90 | + '\n\nNote this can affect the ability to connect to the system after' |
| 91 | + ' the upgrade if it depends on the current OpenSSL configuration.' |
| 92 | + ' Such a problem may be caused by using a particular OpenSSL engine, as' |
| 93 | + ' OpenSSL engines built for the' |
| 94 | + ' RHEL {source} system are not compatible with RHEL {target}.' |
| 95 | + .format( |
| 96 | + fpath=DEFAULT_OPENSSL_CONF, |
| 97 | + source=version.get_source_major_version(), |
| 98 | + target=version.get_target_major_version() |
| 99 | + ) |
| 100 | + ) |
| 101 | + if version.get_target_major_version() == '9': |
| 102 | + # NOTE(pstodulk): that a try to make things with engine/providers a |
| 103 | + # little bit better (see my TODO note above) |
| 104 | + summary += ( |
| 105 | + '\n\nNote the legacy ENGINE API is deprecated since RHEL 8 and' |
| 106 | + ' it is required to use the new OpenSSL providers API instead on' |
| 107 | + ' RHEL 9 systems.' |
| 108 | + ) |
| 109 | + hint = ( |
| 110 | + 'Check that your ability to login to the system does not depend on' |
| 111 | + ' the OpenSSL configuration. After the upgrade, review the system configuration' |
| 112 | + ' and configure the system as needed.' |
| 113 | + ' Please, be aware that it is not recommended to configure the system default' |
| 114 | + ' {fpath}. Instead, it is recommended to copy the file and use this copy' |
| 115 | + ' to configure particular applications.' |
| 116 | + ' The default OpenSSL configuration file should be modified only' |
| 117 | + ' when it is really necessary.' |
| 118 | + ) |
| 119 | + reporting.create_report([ |
| 120 | + reporting.Title('The /etc/pki/tls/openssl.cnf file is modified and will be replaced during the upgrade.'), |
| 121 | + reporting.Summary(summary), |
| 122 | + reporting.Remediation(hint=hint), |
| 123 | + reporting.Severity(reporting.Severity.HIGH), |
| 124 | + reporting.Groups([reporting.Groups.POST, reporting.Groups.SECURITY]), |
| 125 | + reporting.RelatedResource('file', DEFAULT_OPENSSL_CONF), |
| 126 | + reporting.ExternalLink( |
| 127 | + title='Using system-wide cryptographic policies.', |
| 128 | + url=crypto_url |
| 129 | + ) |
| 130 | + ]) |
| 131 | + |
| 132 | + |
| 133 | +def process(): |
| 134 | + check_ibmca() |
| 135 | + check_default_openssl() |
0 commit comments