self::check_header( $config ), 'cert' => self::check_certificate(), 'redirect' => self::check_redirect(), 'submitUrl' => self::SUBMIT_URL, ); } /** Direkt aus den gespeicherten Einstellungen -- kein Netzwerk-Request noetig, die Werte sind bereits bekannt. */ private static function check_header( array $config ) { if ( ! $config['enabled'] ) { return array( 'ok' => false, 'message' => __( 'HSTS is not enabled for the frontend. Enable it above first.', '360-orbit-header-security' ), ); } $missing = array(); if ( $config['max_age'] < self::MIN_MAX_AGE ) { $missing[] = __( 'max-age of at least 1 year (31536000)', '360-orbit-header-security' ); } if ( ! $config['include_subdomains'] ) { $missing[] = 'includeSubDomains'; } if ( ! $config['preload'] ) { $missing[] = 'preload'; } if ( ! empty( $missing ) ) { return array( 'ok' => false, /* translators: %s: comma-separated list of missing HSTS requirements */ 'message' => sprintf( __( 'Missing for eligibility: %s.', '360-orbit-header-security' ), implode( ', ', $missing ) ), ); } return array( 'ok' => true, 'message' => __( 'The HSTS header meets hstspreload.org\'s requirements.', '360-orbit-header-security' ), ); } /** * Loopback-Request MIT Zertifikatspruefung (anders als der allgemeine * Selbsttest anderer Plugins der Suite, der bewusst sslverify=false nutzt, * um reine Erreichbarkeit zu pruefen) -- hier geht es gezielt darum, ob * das Zertifikat selbst gueltig ist, denn genau das verlangt * hstspreload.org. */ private static function check_certificate() { if ( 'https' !== wp_parse_url( home_url( '/' ), PHP_URL_SCHEME ) ) { return array( 'ok' => false, 'message' => __( 'The site is not served over HTTPS at all.', '360-orbit-header-security' ), ); } $response = wp_remote_get( home_url( '/' ), array( 'timeout' => 10, 'sslverify' => true, 'headers' => array( 'Cache-Control' => 'no-cache' ), ) ); if ( is_wp_error( $response ) ) { return array( 'ok' => false, /* translators: %s: underlying error message */ 'message' => sprintf( __( 'Certificate check failed: %s', '360-orbit-header-security' ), $response->get_error_message() ), ); } return array( 'ok' => true, 'message' => __( 'A valid, trusted certificate was found.', '360-orbit-header-security' ), ); } /** Prueft per Loopback (ohne automatische Weiterleitung zu folgen), ob HTTP auf HTTPS desselben Hosts umleitet -- eine der drei technischen hstspreload.org-Voraussetzungen. */ private static function check_redirect() { $http_url = set_url_scheme( home_url( '/' ), 'http' ); $response = wp_remote_get( $http_url, array( 'timeout' => 10, 'sslverify' => false, 'redirection' => 0, 'headers' => array( 'Cache-Control' => 'no-cache' ), ) ); if ( is_wp_error( $response ) ) { return array( 'ok' => false, /* translators: %s: underlying error message */ 'message' => sprintf( __( 'The HTTP version could not be reached: %s', '360-orbit-header-security' ), $response->get_error_message() ), ); } $code = wp_remote_retrieve_response_code( $response ); $location = wp_remote_retrieve_header( $response, 'location' ); $is_redirect_to_https = in_array( $code, array( 301, 302, 307, 308 ), true ) && is_string( $location ) && 0 === stripos( $location, 'https://' ); if ( ! $is_redirect_to_https ) { return array( 'ok' => false, /* translators: %d: HTTP status code received instead of a redirect */ 'message' => sprintf( __( 'HTTP does not redirect to HTTPS (received status %d instead).', '360-orbit-header-security' ), $code ), ); } return array( 'ok' => true, 'message' => __( 'HTTP redirects to HTTPS.', '360-orbit-header-security' ), ); } }