Skip to content

Instantly share code, notes, and snippets.

@phpdave
Last active September 14, 2015 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpdave/8d594cfcfd6c11e704af to your computer and use it in GitHub Desktop.
Save phpdave/8d594cfcfd6c11e704af to your computer and use it in GitHub Desktop.
Pseudo code for detecting php version, operating system and a default location for CA bundle.
<?
$os = php_uname("s");
$phpversion = floatval(substr(phpversion (),0,3));
if($phpversion<5.6)
{
if($os=="OS400")
{
$defaultcafile = "/QOpenSys/QIBM/ProdData/SC1/OpenSSL/openssl-0.9.7d/cert.pem";
}
else if ($os=="Linux")
{
$defaultcafile = "/etc/pki/tls/certs/ca-bundle.crt";
}
}
if(!file_exists($defaultcafile) && $userDidntProvideCABundle)
{
//possible security issue as you have to trust that the DNS and server below is not compromised.
$certFromWeb = readfile("http://curl.haxx.se/ca/cacert.pem");
//::TODO:: cache this cert so we don't send multiple requests. Have to add logic above to see if we have the cached cert
$defaultcafile = $certFromWeb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment