�&ǐk�@'bJ�h�ۊL'}T� :��'2�Z#$��n�a��� �>a��`��_3d�Qpt�/�P -��#5�,�M��� �pA:©�q�����NW��ډ�A���� �9nʺج���� �TSM��{J6?7��r�@�\����D��� �׶���s�f�TJj?"��D��`?��̒� b�#�%�C*v�$�{�$����5Ծ�F�s��y�e/8��h-�f�̰&(����Gj�L:U� 2�� ����v�_k����Y��gp,�k�WF�R������_C�R��N@���R�@�ߔ?A�w9���F("iNa-S���Q�o�3tDMLh*�#4k�T/iQ��Y*�G��m����)��8�hBm/�I�,g�ﯖ���Z��}�Cz�q@´��d.����L�ŕ�,��1�Z�܌�: ̪���F+J-'��c�tvJ8��]Q-��b��y �6;*J`r_�d ��'�G ~p��)'�C,�%F��E(��2�k�����lР�z�!�=t ��_�0��f7��� ;�p�|�U �% be the collection of service-default TLS certificates. =item Let C be all domains that are on at least one C certificate. =item Let C be all domains with Domain TLS entries. (This is not the same as “all domains on all certificates in Domain TLS”; we only care about the actual FQDN(s) for which a given Domain TLS certificate was installed.) =item Let C be all C that a C entry completely covers. This EXCLUDES matches between a wildcard C and a non-wildcard C. =item For each C, verify that the Domain TLS certificate has at least 25 hours of validity left; if not, print a message. If the C<--prune> argument was given, delete the Domain TLS entry, and print a message about it. =back The C<--verbose> flag prints extra diagnostic information that you may find useful. =head1 CAVEATS The drawback to this system is that a Domain TLS entry can be removed even if only one service’s default certificate covers that domain. For this reason it is strongly recommended that service default certificates all be the same certificate. =cut use strict; use warnings; use Try::Tiny; use parent 'Cpanel::HelpfulScript'; use Cpanel::Domain::TLS (); use Cpanel::Domain::TLS::ServiceOverlap (); use Cpanel::Domain::TLS::Write (); use Cpanel::SSL::Utils (); use Cpanel::SSL::Verify (); #mocked in tests *_get_service_domains = *Cpanel::Domain::TLS::ServiceOverlap::get_service_domains; __PACKAGE__->new(@ARGV)->run() if !caller; use constant _OPTIONS => ( 'prune', 'verbose', ); use constant MIN_VALIDITY_LEFT => 86400 + 3600; #25 hours sub run { my ($self) = @_; my @domains_to_verify = $self->_get_service_domains(); if ( !@domains_to_verify ) { if ( $self->getopt('verbose') ) { $self->say_maketext('[asis,Domain TLS] has no domains that are on the service default certificates.'); } return; } if ( $self->getopt('verbose') ) { $self->say_maketext( 'The system will check the [asis,Domain TLS] [numerate,_1,entry,entries] for the following [numerate,_1,domain,domains]: [join,~, ,_2]', 0 + @domains_to_verify, \@domains_to_verify ); } my $faulty_count = 0; my $verify = Cpanel::SSL::Verify->new(); for my $domain (@domains_to_verify) { my $remove_yn = 0; try { my @certs = Cpanel::Domain::TLS->get_certificates($domain); my $v = $verify->verify(@certs); if ( $v->ok() ) { my ( $ok, $parse ) = Cpanel::SSL::Utils::parse_certificate_text( $certs[0] ); die $parse if !$ok; my $validity_left = 1 + $parse->{'not_after'} - time; if ( $validity_left < MIN_VALIDITY_LEFT ) { $remove_yn = 1; my @to_say = $self->locale()->maketext( '“[_1]”’s certificate is valid, but it will expire soon.', $domain ); if ( $self->getopt('prune') ) { push @to_say, $self->locale()->maketext('The system will remove the certificate now to ensure that no client receives it after it expires.'); } else { push @to_say, $self->bold( $self->locale()->maketext('This certificate should be removed or replaced.') ); } $self->say( join( ' ', @to_say ) ); } elsif ( $self->getopt('verbose') ) { $self->say_maketext( '“[_1]”’s certificate is valid.', $domain ); } } else { $self->say_maketext( '“[_1]”’s certificate failed validation: [_2]', $domain, $v->get_error_string() ); $remove_yn = 1; } if ($remove_yn) { $faulty_count++; if ( $self->getopt('prune') ) { Cpanel::Domain::TLS::Write->enqueue_unset_tls($domain); #Technically this is no longer true; the certificate #still exists until we reap Domain TLS’s unset queue. $self->say_maketext( '“[_1]”’s certificate is removed. Non-[asis,HTTP] services will no longer use this certificate.', $domain ); } } } catch { warn "An error occurred while checking “$domain”’s certificate: $_"; }; } if ( $faulty_count && !$self->getopt('prune') ) { $self->say(q<>); $self->say_maketext( '[quant,_1,domain has a certificate,domains have certificates] that should be removed or replaced. Run the following command to do this:', $faulty_count ); $self->say(q<>); $self->say( $self->bold("$0 --prune") ); } return; } 1;