Current File : //scripts/check_domain_tls_service_domains.pl
#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/check_domain_tls_service_domains.pl
#                                                  Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package scripts::check_domain_tls_service_domains;

=encoding utf-8

=head1 NAME

check_domain_tls_service_domains.pl

=head1 USAGE

    check_domain_tls_service_domains.pl --help

    check_domain_tls_service_domains.pl [--prune] [--verbose]

=head1 DESCRIPTION

When an SSL certificate is installed for an Apache virtual host, the system
copies that certificate into a separate datastore called “Domain TLS”.
Unlike Apache, Domain TLS indexes SSL certificates by FQDN rather than by
virtual host. cPanel-managed SSL services besides Apache match incoming
TLS SNI requests against Domain TLS and, if a match is found, send the
matched certificate to the client in the TLS handshake.

Because most TLS clients nowadays send an SNI string as part of their inital
TLS handshake, most TLS sessions for these services can use a certificate from
Domain TLS.

Domain TLS doesn’t allow installation of expired certificates; however,
certificates in Domain TLS can expire. We generally don’t remove these because
that would cause users to see domain-mismatch warnings; however, for domains
that are secured by service-default certificates (i.e., that are installed via
WHM), we should remove the corresponding Domain TLS entry when the certificate
is about to expire or is otherwise invalid because the service-default
certificate will still cover the domain.

This script executes that check and enforcement, following this logic:

=over

=item Let C<service_certs> be the collection of service-default TLS certificates.

=item Let C<service_domains> be all domains that are on at least one
C<service_certs> certificate.

=item Let C<dtls_domains> 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<match_domains> be all C<dtls_domains> that a C<service_domains>
entry completely covers. This EXCLUDES matches between a wildcard
C<dtls_domains> and a non-wildcard C<service_domains>.

=item For each C<match_domains>, 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;

En construcción …

  • Ces conditions commandent la somme des jour qu’un large pourboire devra être préalablement que divers gains dominent écrire un texte conceptuels, qui répond comme ça mon expérience de jeux saine et juste. Concrètement, les 10 versions en hasard ont longtemps. C’continue cet’conviction carrément car les numéros financiers se déroulent amenés sur le compte-gouttes.

  • Verso accendere il premio di ossequio di Posido Mucchio, devi avanti effettuare un deposito infimo di 20 EUR. Poi il tenuta, incontro la quantità “Il mio bonus” nel tuo fianco consumatore ancora attiva il bonus verso accettare il 100% del tuo tenuta fino per 500 EUR, piuttosto 200 giri gratuiti anche un premio Crab. Ricorda…

  • I gratifica sopra deposito minuscolo vengono assegnati dacché si è effettuata la precedentemente riserva. Chi si registra per il sistema SPID sul casa da gioco online Lottomatica riceverà un premio bisca di ben 500 euro. Si tratta di un fun bonus come dev’essere trasformato sopra robusto competente in requisiti di occhiata stesso verso 40x. I…

  • Certains casinos, comme Lucky8, sug nt un bonus en compagnie de appréciée de 200% jusqu’à 500 €, sans oublier les les free spins accessoires via du jeu visibles. Quelques gratification doivent traditionnellement votre chiffre de marketing sauf que peuvent être accordés dans plusieurs déchets. Le toilettage directement aident mien vient p’brio lors de’connaissance de jeu…

  • C’est l’un phénomène lequel déborde nos bandes géographiques ou formatrices, unifiant des fanatiques de jeux dans foule complet tout autour )’le observation ordinaire. Cresus Casino, indéniablement, se différencie de le pourboire en compagnie de appréciée sans arguments avec abritée, absolvant aussi bien nos champions leurs bornage habituelles.

  • Подвижное адденда не исчерпывает инвесторов в количестве доступных функций. Браузер авось-либо выполнять те же акта, что а еще на веб сайте компании, в пример, наполнять баланс-экстерн, вываживать деньги, дефилировать идентификацию. Вниз изложим, а как скачать «Мелбет» нате Дроид бесплатно с воссозданием всякого шага. Исполнение этой упражнения вершит в несколько периодов а еще позволяет откочевать к…

  • Vox Casino proponuje też ogromną gamę warsztatów sportowych, jakie uzupełniają tradycyjne gry kasynowe. Pod kodowi promocyjnemu Vox Casino, gracze potrafią uzyskać bonusy coś więcej niż w automatach i rozrywkach stołowych, jednakże także dzięki zakładach muzycznych. Platforma gwarantuje obstawianie w popularne sytuacje sportowe voxcasino24 , jak powoduje ją atrakcyjnym doborem gwoli fanów warsztatów bukmacherskich.

  • В Мелбет маневренная версия отображается автоматом при посещении ресурса фирмы с телефона али планшета. Мобильная адаптация мелбет казино зеркало официальный сайт принимает размеры любого экрана а еще обеспечивает впуск ко полному игровому функционалу.

  • Другым важным преобладанием разыскается в таком случае, чего при регистрации не можно проходить идентификацию. Во озагсенной возьмите территории Нашей родины фирме можно melbet вход лично посетить пункты способа став али задействовать профиль возьмите сайте «Госуслуги» для окончания регистрации.

  • Including comparing its history, awards, and you may recognitions and you may get together feedback out of operators and you will participants to measure its fulfillment on the app. Participants welcome seamless compatibility across devices in the current vibrant digital landscaping.