When retrieving a public key for a certificate, private key, or signing request, write the certificate data out to a temp file instead of echoing it through a pipe. Fixes #8153

This commit is contained in:
jim-p 2017-12-01 12:41:56 -05:00
parent 9038f44c7e
commit b6dcbd646f

View File

@ -603,20 +603,23 @@ function cert_get_publickey($str_crt, $decode = true, $type = "crt") {
if ($decode) {
$str_crt = base64_decode($str_crt);
}
$certfn = tempnam('/tmp', 'CGPK');
file_put_contents($certfn, $str_crt);
switch ($type) {
case 'prv':
exec("echo \"{$str_crt}\" | openssl pkey -pubout", $out);
exec("/usr/bin/openssl pkey -in {$certfn} -pubout", $out);
break;
case 'crt':
exec("echo \"{$str_crt}\" | openssl x509 -inform pem -noout -pubkey", $out);
exec("/usr/bin/openssl x509 -in {$certfn} -inform pem -noout -pubkey", $out);
break;
case 'csr':
exec("echo \"{$str_crt}\" | openssl req -inform pem -noout -pubkey", $out);
exec("/usr/bin/openssl req -in {$certfn} -inform pem -noout -pubkey", $out);
break;
default:
$out = array();
break;
}
unlink($certfn);
return implode("\n", $out);
}