Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/helper/SimpleDnsCloudflareSolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class SimpleDnsCloudflareSolver implements SolverInterface {
*/
protected $zones;

/**
* @var array TXT values this solver added, by record name without the trailing dot.
*/
private $created_records = [];

/**
* @param DnsDataExtractor $extractor
* @param OutputInterface $output
Expand Down Expand Up @@ -71,6 +76,7 @@ public function solve( AuthorizationChallenge $authorizationChallenge ) {
try {
if ( $this->dns->addRecord( $zoneID, "TXT", $recordName, $recordValue, 0, false ) === true ) {
EE::log( "Created DNS record: $recordName with value $recordValue." . PHP_EOL );
$this->created_records[ rtrim( $recordName, '.' ) ][] = $recordValue;
} else {
$manual = true;
}
Expand Down Expand Up @@ -104,6 +110,15 @@ public function solve( AuthorizationChallenge $authorizationChallenge ) {
}
}

/**
* TXT records this solver added through the Cloudflare API.
*
* @return array Expected values by record name.
*/
public function get_created_records() {
return $this->created_records;
}

/**
* {@inheritdoc}
*/
Expand All @@ -116,12 +131,12 @@ public function cleanup( AuthorizationChallenge $authorizationChallenge ) {

foreach ( $record_ids as $record_id ) {
if ( $this->dns->deleteRecord( $zoneID, $record_id ) ) {
EE::log( "Cleaned up DNS record: _acme-challenge.$recordName" );
EE::log( "Cleaned up DNS record: $recordName" );
} else {
$this->output->writeln(
sprintf(
<<<'EOF'
You can now cleanup your DNS by removing the domain <comment>_acme-challenge.%s.</comment>
You can now cleanup your DNS by removing the domain <comment>%s</comment>
EOF
,
$recordName
Expand Down
32 changes: 23 additions & 9 deletions src/helper/Site_Letsencrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ class Site_Letsencrypt {
private $repository;
private $conf_dir;

/**
* @var array TXT values the last authorize() published through the DNS API, by record name.
*/
private $published_dns_records = [];

function __construct() {
$this->conf_dir = EE_ROOT_DIR . '/services/nginx-proxy/acme-conf';
$this->setRepository();
Expand Down Expand Up @@ -324,7 +329,8 @@ public function authorize( Array $domains, $wildcard = false, $preferred_challen
} else {
$solver = new SimpleHttpSolver();
}
$solverName = $is_solver_dns ? 'dns-01' : 'http-01';
$solverName = $is_solver_dns ? 'dns-01' : 'http-01';
$this->published_dns_records = [];
try {
$order = $this->client->requestOrder( $domains );
} catch ( \Exception $e ) {
Expand All @@ -334,7 +340,6 @@ public function authorize( Array $domains, $wildcard = false, $preferred_challen
} else {
\EE::warning( 'Let\'s Encrypt order request failed (' . $e->getMessage() . '). It seems you\'re in local environment or using non-public domain, please check logs. Skipping letsencrypt.' );
}
\EE::log( 'You can fix the issue and re-run: ee site ssl-verify ' . $domains[0] );

return false;
}
Expand All @@ -356,7 +361,6 @@ public function authorize( Array $domains, $wildcard = false, $preferred_challen
}
if ( null === $authorizationChallenge ) {
\EE::warning( 'Challenge not supported for domain ' . $domainKey );
\EE::log( 'You can fix the issue and re-run: ee site ssl-verify ' . $domainKey );

return false;
}
Expand Down Expand Up @@ -389,11 +393,24 @@ public function authorize( Array $domains, $wildcard = false, $preferred_challen
}
}

if ( $solver instanceof SimpleDnsCloudflareSolver ) {
$this->published_dns_records = $solver->get_created_records();
}

$this->repository->storeCertificateOrder( $domains, $order );

return true;
}

/**
* TXT records the last authorize() published through the DNS API, to wait for before validation.
*
* @return array Expected values by record name.
*/
public function getPublishedDnsRecords() {
return $this->published_dns_records;
}

public function revokeAuthorizationChallenges( array $domains ) {
foreach ( $domains as $domain ) {
if ( $this->repository->hasDomainAuthorizationChallenge( $domain ) ) {
Expand Down Expand Up @@ -522,6 +539,9 @@ public function check( Array $domains, $wildcard = false, $preferred_challenge =

return false;
}
if ( $is_solver_dns ) {
\EE\Site\Utils\wait_for_dns_txt_records( $this->published_dns_records );
}

$order = $this->repository->loadCertificateOrder( $domains );
}
Expand Down Expand Up @@ -561,7 +581,6 @@ public function check( Array $domains, $wildcard = false, $preferred_challenge =
\EE::debug( sprintf( 'Testing the challenge for domain %s', $domain ) );
if ( ! $validator->isValid( $authorizationChallenge ) ) {
\EE::warning( 'Can not validate challenge for domain ' . $domain );
\EE::log( 'You can fix the issue and re-run: ee site ssl-verify ' . $domain );

return false;
}
Expand All @@ -573,11 +592,6 @@ public function check( Array $domains, $wildcard = false, $preferred_challenge =
\EE::debug( $e->getMessage() );
\EE::warning( 'Challenge Authorization failed (' . $e->getMessage() . '). Check logs and check if your domain is pointed correctly to this server.' );

$site_name = $domains[0];
$site_name = str_replace( '*.', '', $site_name );

\EE::log( "Re-run `ee site ssl-verify $site_name` after fixing the issue." );

return false;
}
}
Expand Down
Loading
Loading