Improved http validation with exponential backoff

Added documentation
Simplified HTTP validation flow (no longer need challenge to get file contents)
Updated README.md
This commit is contained in:
peterbakker
2020-03-18 19:31:57 +01:00
parent 03914ce189
commit b7ff268e4e
9 changed files with 228 additions and 46 deletions

View File

@@ -31,6 +31,14 @@ class Account
protected $accountURL;
/**
* Account constructor.
* @param array $contact
* @param \DateTime $createdAt
* @param bool $isValid
* @param string $initialIp
* @param string $accountURL
*/
public function __construct(
array $contact,
\DateTime $createdAt,
@@ -45,23 +53,35 @@ class Account
$this->accountURL = $accountURL;
}
/**
* Return the account ID
* @return string
*/
public function getId(): string
{
return substr($this->accountURL, strrpos($this->accountURL, '/') + 1);
}
/**
* Return create date for the account
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* Return the URL for the account
* @return string
*/
public function getAccountURL(): string
{
return $this->accountURL;
}
/**
* Return contact data
* @return array
*/
public function getContact(): array
@@ -70,6 +90,7 @@ class Account
}
/**
* Return initial IP
* @return string
*/
public function getInitialIp(): string
@@ -78,6 +99,7 @@ class Account
}
/**
* Returns validation status
* @return bool
*/
public function isValid(): bool

View File

@@ -27,6 +27,13 @@ class Authorization
*/
protected $digest;
/**
* Authorization constructor.
* @param string $domain
* @param string $expires
* @param string $digest
* @throws \Exception
*/
public function __construct(string $domain, string $expires, string $digest)
{
$this->domain = $domain;
@@ -34,13 +41,18 @@ class Authorization
$this->digest = $digest;
}
/**
* Add a challenge to the authorization
* @param Challenge $challenge
*/
public function addChallenge(Challenge $challenge)
{
$this->challenges[] = $challenge;
}
/**
* @return array
* Return the domain that is being authorized
* @return string
*/
public function getDomain(): string
{
@@ -49,6 +61,7 @@ class Authorization
/**
* Return the expiry of the authorization
* @return \DateTime
*/
public function getExpires(): \DateTime
@@ -57,6 +70,7 @@ class Authorization
}
/**
* Return array of challenges
* @return Challenge[]
*/
public function getChallenges(): array
@@ -65,6 +79,7 @@ class Authorization
}
/**
* Return the HTTP challenge
* @return Challenge|bool
*/
public function getHttpChallenge()
@@ -79,14 +94,14 @@ class Authorization
}
/**
* @param Challenge $challenge
* Return File object for the given challenge
* @return File|bool
*/
public function getFile(Challenge $challenge)
public function getFile()
{
if ($challenge->getType() == Client::VALIDATION_HTTP) {
$file = new File($challenge->getToken(), $challenge->getToken() . '.' . $this->digest);
return $file;
$challenge = $this->getHttpChallenge();
if ($challenge !== false) {
return new File($challenge->getToken(), $challenge->getToken() . '.' . $this->digest);
}
return false;
}

View File

@@ -43,6 +43,7 @@ class Certificate
}
/**
* Get the certificate signing request
* @return string
*/
public function getCsr(): string
@@ -51,6 +52,7 @@ class Certificate
}
/**
* Get the expiry date of the current certificate
* @return \DateTime
*/
public function getExpiryDate(): \DateTime
@@ -59,6 +61,7 @@ class Certificate
}
/**
* Return the certificate as a multi line string
* @return string
*/
public function getCertificate(): string
@@ -67,6 +70,7 @@ class Certificate
}
/**
* Return the private key as a multi line string
* @return string
*/
public function getPrivateKey(): string

View File

@@ -48,6 +48,7 @@ class Challenge
}
/**
* Get the URL for the challenge
* @return string
*/
public function getUrl(): string
@@ -56,6 +57,7 @@ class Challenge
}
/**
* Returns challenge type (DNS or HTTP)
* @return string
*/
public function getType(): string
@@ -64,6 +66,7 @@ class Challenge
}
/**
* Returns the token
* @return string
*/
public function getToken(): string
@@ -71,11 +74,19 @@ class Challenge
return $this->token;
}
/**
* Returns the status
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
/**
* Returns authorization URL
* @return string
*/
public function getAuthorizationURL(): string
{
return $this->authorizationURL;

View File

@@ -15,7 +15,11 @@ class File
*/
protected $contents;
/**
* File constructor.
* @param string $filename
* @param string $contents
*/
public function __construct(string $filename, string $contents)
{
$this->contents = $contents;
@@ -23,6 +27,7 @@ class File
}
/**
* Return the filename for HTTP validation
* @return string
*/
public function getFilename(): string
@@ -31,6 +36,7 @@ class File
}
/**
* Return the file contents for HTTP validation
* @return string
*/
public function getContents(): string

View File

@@ -41,7 +41,17 @@ class Order
*/
protected $domains;
/**
* Order constructor.
* @param array $domains
* @param string $url
* @param string $status
* @param string $expiresAt
* @param array $identifiers
* @param array $authorizations
* @param string $finalizeURL
* @throws \Exception
*/
public function __construct(
array $domains,
string $url,
@@ -51,6 +61,10 @@ class Order
array $authorizations,
string $finalizeURL
) {
//Handle the microtime date format
if (strpos($expiresAt, '.') !== false) {
$expiresAt = substr($expiresAt, 0, strpos($expiresAt, '.')) . 'Z';
}
$this->domains = $domains;
$this->url = $url;
$this->status = $status;
@@ -60,41 +74,74 @@ class Order
$this->finalizeURL = $finalizeURL;
}
/**
* Returns the order number
* @return string
*/
public function getId(): string
{
return substr($this->url, strrpos($this->url, '/') + 1);
}
/**
* Returns the order URL
* @return string
*/
public function getURL(): string
{
return $this->url;
}
/**
* Return set of authorizations for the order
* @return Authorization[]
*/
public function getAuthorizationURLs(): array
{
return $this->authorizations;
}
/**
* Returns order status
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
/**
* Returns expires at
* @return \DateTime
*/
public function getExpiresAt(): \DateTime
{
return $this->expiresAt;
}
/**
* Returs domains as identifiers
* @return array
*/
public function getIdentifiers(): array
{
return $this->identifiers;
}
/**
* Returns url
* @return string
*/
public function getFinalizeURL(): string
{
return $this->finalizeURL;
}
/**
* Returns domains for the order
* @return array
*/
public function getDomains(): array
{
return $this->domains;