Skip to content
Merged
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
10 changes: 7 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ public function __construct(

if ($requester !== null) {
$this->requester = $requester;
} elseif (in_array("curl", get_loaded_extensions(), true)) {
$this->requester = new CurlRequester();
} else {
$this->requester = new FileRequester();
$this->requester = new CurlRequester();
}

$this->paging = $paging;
Expand All @@ -69,6 +67,12 @@ public function __construct(
*/
public function setRequesterOption($option, $value)
{
// Normalize the legacy ca=IGNORE flag to disable_ca_pinning
if ($option === "ca" && $value === "IGNORE") {
$this->options["disable_ca_pinning"] = true;
unset($this->options["ca"]);
return $this;
}
if ($option === "ca" && isset($this->options["disable_ca_pinning"]) && $this->options["disable_ca_pinning"]) {
throw new \InvalidArgumentException(
"Cannot use custom CA certificates when CA pinning is disabled"
Expand Down
12 changes: 10 additions & 2 deletions src/CurlRequester.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ public function options($options)
unset($curl_options[CURLOPT_CAINFO]);
} elseif (!isset($curl_options[CURLOPT_CAINFO])) {
$curl_options[CURLOPT_CAINFO] = DEFAULT_CA_CERTS;
} elseif ($curl_options[CURLOPT_CAINFO] == "IGNORE") {
unset($curl_options[CURLOPT_CAINFO]);
}

if (isset($curl_options[CURLOPT_CAINFO])) {
$capath = "/dev/null/" . \bin2hex(\random_bytes(16));
if (!curl_setopt($this->ch, CURLOPT_CAPATH, $capath)) {
throw new \RuntimeException(
"Failed to set CURLOPT_CAPATH; CA pinning cannot be enforced on this cURL/TLS backend"
);
}
$curl_options[CURLOPT_CAPATH] = $capath;
}

// Mandatory configuration options
Expand Down
150 changes: 0 additions & 150 deletions src/FileRequester.php

This file was deleted.

67 changes: 0 additions & 67 deletions tests/SSL/SSLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,6 @@ public function testCorrectlySignedCertificateCurl()
$this->assertTrue($result["success"]);
}

public function testCorrectlySignedCertificateFile()
{
$requester = new \DuoAPI\FileRequester();
$result = $this->pingSSLServer(
$requester,
GOOD_STUNNEL_SERVER,
$this->good_chain
);

/*
* A '404' here is fine. We're simply trying to test if a good
* SSL *connection* is made, there's not a fully implemented API
* waiting for us on the other side of the connection.
*/
$this->assertEquals(404, $result["http_status_code"]);
}

/*
* Test our custom certificate that was signed by our custom CA against
* a third-party certificate chain.
Expand Down Expand Up @@ -153,23 +136,6 @@ public function testMismatchedCertificateCurl()
);
}

public function testMismatchedCertificateFile()
{
$requester = new \DuoAPI\FileRequester();
$result = $this->pingSSLServer(
$requester,
GOOD_STUNNEL_SERVER,
$this->bad_chain
);

$this->assertFalse($result["success"]);
$this->assertEquals($result["response"]["stat"], "FAIL");
$this->assertStringContainsStringIgnoringCase(
"failed to open stream: operation failed",
$result["response"]["message"]
);
}

/*
* Test an unsigned certificate against our custom certificate chain.
*
Expand All @@ -195,23 +161,6 @@ public function testSelfSignedCertificateCurl()
);
}

public function testSelfSignedCertificateFile()
{
$requester = new \DuoAPI\FileRequester();
$result = $this->pingSSLServer(
$requester,
SELF_SIGNED_STUNNEL_SERVER,
$this->good_chain
);

$this->assertFalse($result["success"]);
$this->assertEquals($result["response"]["stat"], "FAIL");
$this->assertStringContainsStringIgnoringCase(
"failed to open stream: operation failed",
$result["response"]["message"]
);
}

/*
* Test a custom certificate with an incorrect hostname that was signed
* by our custom CA against the certificate chain created by our custom CA.
Expand All @@ -238,20 +187,4 @@ public function testCertificateBadHostnameCurl()
);
}

public function testCertificateBadHostnameFile()
{
$requester = new \DuoAPI\FileRequester();
$result = $this->pingSSLServer(
$requester,
BAD_HOSTNAME_STUNNEL_SERVER,
$this->good_chain
);

$this->assertFalse($result["success"]);
$this->assertEquals($result["response"]["stat"], "FAIL");
$this->assertStringContainsStringIgnoringCase(
"failed to open stream: operation failed",
$result["response"]["message"]
);
}
}
Loading
Loading