/** * Constructor. * * @since 1.0.0 * @access private * * @param string $domain The root domain of this certificate. */ private function __construct($domain) { $this->domain = $domain; $this->path = Util::get_letsencrypt_certificates_dir_path() . '/' . $domain; }
/** * Constructor. * * @since 1.0.0 * @access protected * * @param string $sub_path The relative sub path for the key files. */ protected function __construct($sub_path) { $this->path = Util::get_letsencrypt_certificates_dir_path() . '/' . trim($sub_path, '/'); }
/** * Deletes all certificates, keys and challenges. * * Use this method with extreme caution - do not use it when your server is currently using any of * those files. * * @since 1.0.0 * @access public * * @return bool|WP_Error True if everything was deleted successfully, an error object otherwise. */ public function reset() { $filesystem = Util::get_filesystem(); $paths = array(Util::get_letsencrypt_certificates_dir_path(), Util::get_letsencrypt_challenges_dir_path()); foreach ($paths as $path) { if ($filesystem->is_dir($path)) { $filelist = $filesystem->dirlist(trailingslashit($path), true); if (is_array($filelist)) { foreach ($filelist as $fileinfo) { if (!$filesystem->delete(trailingslashit($path) . $fileinfo['name'], true, $fileinfo['type'])) { return new WP_Error('cannot_delete_directory', sprintf(__('Unable to delete <code>%s</code>.', 'wp-encrypt'), trailingslashit($path) . $fileinfo['name'])); } } } } } return true; }
/** * Returns an array of directories for the certificates and keys for a domain. * * @since 1.0.0 * @access protected * * @param string $domain The domain to get the directories for. * @return array An array containing 'base', 'cert', 'chain', 'fullchain' and 'key' keys with their respective directory as value. */ protected function get_certificate_dirs($domain) { $site_domain = 'network' === $this->context ? Util::get_network_domain() : Util::get_site_domain(); $certificate_dirs = array('base' => CoreUtil::get_letsencrypt_certificates_dir_path() . '/' . $domain); $certificate_dirs['cert'] = $certificate_dirs['base'] . '/' . Certificate::CERT_NAME; $certificate_dirs['chain'] = $certificate_dirs['base'] . '/' . Certificate::CHAIN_NAME; $certificate_dirs['fullchain'] = $certificate_dirs['base'] . '/' . Certificate::FULLCHAIN_NAME; $certificate_dirs['key'] = $certificate_dirs['base'] . '/' . KeyPair::PRIVATE_NAME; return $certificate_dirs; }