Certificationauthority : Add phpstan @return values when parameter is null
This commit is contained in:
@@ -12,7 +12,6 @@ namespace Domframework;
|
|||||||
class Certificationauthority
|
class Certificationauthority
|
||||||
{
|
{
|
||||||
// PROPERTIES
|
// PROPERTIES
|
||||||
// {{{
|
|
||||||
/** The opensslCnfPath file
|
/** The opensslCnfPath file
|
||||||
*/
|
*/
|
||||||
private $opensslCnfPath;
|
private $opensslCnfPath;
|
||||||
@@ -53,12 +52,10 @@ basicConstraints = CA:FALSE
|
|||||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
||||||
extendedKeyUsage = serverAuth, clientAuth
|
extendedKeyUsage = serverAuth, clientAuth
|
||||||
';
|
';
|
||||||
// }}}
|
|
||||||
|
|
||||||
/** Check if openssl support is available in PHP
|
/** Check if openssl support is available in PHP
|
||||||
*/
|
*/
|
||||||
public function __construct ()
|
public function __construct ()
|
||||||
// {{{
|
|
||||||
{
|
{
|
||||||
if (! function_exists ("openssl_csr_new"))
|
if (! function_exists ("openssl_csr_new"))
|
||||||
throw new \Exception (dgettext ("domframework",
|
throw new \Exception (dgettext ("domframework",
|
||||||
@@ -71,17 +68,14 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
"private_key_bits" => 4096,
|
"private_key_bits" => 4096,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
|
|
||||||
/** Remove the temporary files when destroying the object
|
/** Remove the temporary files when destroying the object
|
||||||
*/
|
*/
|
||||||
public function __destruct ()
|
public function __destruct ()
|
||||||
// {{{
|
|
||||||
{
|
{
|
||||||
if (file_exists ($this->opensslCnfPath))
|
if (file_exists ($this->opensslCnfPath))
|
||||||
unlink ($this->opensslCnfPath);
|
unlink ($this->opensslCnfPath);
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
|
|
||||||
/** Create the pair key/cert for authority
|
/** Create the pair key/cert for authority
|
||||||
* @param string $countryName Country name (like FR)
|
* @param string $countryName Country name (like FR)
|
||||||
@@ -93,7 +87,6 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
*/
|
*/
|
||||||
public function createCA ($countryName, $organizationName, $commonName,
|
public function createCA ($countryName, $organizationName, $commonName,
|
||||||
$days = 3650)
|
$days = 3650)
|
||||||
// {{{
|
|
||||||
{
|
{
|
||||||
$req_key = openssl_pkey_new (array (
|
$req_key = openssl_pkey_new (array (
|
||||||
"config" => $this->opensslCnfPath,
|
"config" => $this->opensslCnfPath,
|
||||||
@@ -117,14 +110,12 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
openssl_pkey_export ($req_key, $this->caKey);
|
openssl_pkey_export ($req_key, $this->caKey);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
|
|
||||||
/** Get/Set the ca cert
|
/** Get/Set the ca cert
|
||||||
* @param string|null $caCert The CA cert to get/set
|
* @param string|null $caCert The CA cert to get/set
|
||||||
* @return string|self the CA if get in PEM, $this if set
|
* @return (string|self if caCert = null) the CA if get in PEM, $this if set
|
||||||
*/
|
*/
|
||||||
public function caCert ($caCert = null)
|
public function caCert ($caCert = null)
|
||||||
// {{{
|
|
||||||
{
|
{
|
||||||
if ($caCert === null)
|
if ($caCert === null)
|
||||||
return $this->caCert;
|
return $this->caCert;
|
||||||
@@ -133,14 +124,12 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
$this->caCert = $caCert;
|
$this->caCert = $caCert;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
|
|
||||||
/** Get/Set the ca key
|
/** Get/Set the ca key
|
||||||
* @param string|null $caKey The CA key to get/set
|
* @param string|null $caKey The CA key to get/set
|
||||||
* @return string|self the CA if get, $this if set
|
* @return (string|self if caKey = null) the CA if get, $this if set
|
||||||
*/
|
*/
|
||||||
public function caKey ($caKey = null)
|
public function caKey ($caKey = null)
|
||||||
// {{{
|
|
||||||
{
|
{
|
||||||
if ($caKey === null)
|
if ($caKey === null)
|
||||||
return $this->caKey;
|
return $this->caKey;
|
||||||
@@ -149,13 +138,11 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
$this->caKey = $caKey;
|
$this->caKey = $caKey;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
|
|
||||||
/** Create a private key
|
/** Create a private key
|
||||||
* @return $this;
|
* @return $this;
|
||||||
*/
|
*/
|
||||||
public function createPrivateKey ()
|
public function createPrivateKey ()
|
||||||
// {{{
|
|
||||||
{
|
{
|
||||||
$this->privateKey = openssl_pkey_new (array (
|
$this->privateKey = openssl_pkey_new (array (
|
||||||
"config" => $this->opensslCnfPath,
|
"config" => $this->opensslCnfPath,
|
||||||
@@ -164,14 +151,12 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
));
|
));
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
|
|
||||||
/** Get in PEM/Set the private key
|
/** Get in PEM/Set the private key
|
||||||
* @param string|null $privateKey The private key to use
|
* @param string|null $privateKey The private key to use
|
||||||
* @return string|self the privatekey if get in PEM, $this if set
|
* @return (string|self if $privateKey = null) the privatekey if get in PEM, $this if set
|
||||||
*/
|
*/
|
||||||
public function privateKey ($privateKey = null)
|
public function privateKey ($privateKey = null)
|
||||||
// {{{
|
|
||||||
{
|
{
|
||||||
if ($privateKey === null)
|
if ($privateKey === null)
|
||||||
{
|
{
|
||||||
@@ -184,7 +169,6 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
$this->privateKey = openssl_pkey_get_private ($privateKey);
|
$this->privateKey = openssl_pkey_get_private ($privateKey);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
|
|
||||||
/** Create a CSR.
|
/** Create a CSR.
|
||||||
* Will create a private key if none is already exists
|
* Will create a private key if none is already exists
|
||||||
@@ -194,7 +178,6 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
* @return string the CSR created in PEM
|
* @return string the CSR created in PEM
|
||||||
*/
|
*/
|
||||||
public function createCSR ($countryName, $organizationName, $commonName)
|
public function createCSR ($countryName, $organizationName, $commonName)
|
||||||
// {{{
|
|
||||||
{
|
{
|
||||||
if ($this->privateKey === null)
|
if ($this->privateKey === null)
|
||||||
$this->createPrivateKey ();
|
$this->createPrivateKey ();
|
||||||
@@ -211,7 +194,6 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
openssl_csr_export ($req_csr, $out);
|
openssl_csr_export ($req_csr, $out);
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
|
|
||||||
/** Sign a CSR with an CA cert/key pair and return the signed certificate in
|
/** Sign a CSR with an CA cert/key pair and return the signed certificate in
|
||||||
* PEM mode
|
* PEM mode
|
||||||
@@ -225,7 +207,6 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
*/
|
*/
|
||||||
public function signCSR ($csr, $caCert, $caKey, $days = 365,
|
public function signCSR ($csr, $caCert, $caKey, $days = 365,
|
||||||
$altNames = array ())
|
$altNames = array ())
|
||||||
// {{{
|
|
||||||
{
|
{
|
||||||
$conf = $this->opensslConf;
|
$conf = $this->opensslConf;
|
||||||
if (! empty($altNames))
|
if (! empty($altNames))
|
||||||
@@ -256,5 +237,4 @@ extendedKeyUsage = serverAuth, clientAuth
|
|||||||
file_put_contents ($this->opensslCnfPath, $this->opensslConf);
|
file_put_contents ($this->opensslCnfPath, $this->opensslConf);
|
||||||
return $certout;
|
return $certout;
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user