Rename func for all and fix error out

This commit is contained in:
root
2024-01-26 12:54:46 +03:00
parent ba5edbf696
commit 2168e24899
2 changed files with 19 additions and 37 deletions

View File

@@ -50,7 +50,7 @@
$out = array(); $out = array();
$x->createServer($parm, $out); $x->cmpOpenSslCertServerGen($parm, $out);
var_export($out); var_export($out);
@@ -74,7 +74,7 @@
$out = array(); $out = array();
$x->createClient($parm, $out); $x->cmpOpenSslCertClientGen($parm, $out);
var_export($out); var_export($out);

View File

@@ -1,7 +1,7 @@
<?php <?php
trait cmpOpenSSLTrait { trait cmpOpenSSLTrait {
var $cmpOpenSSLVersion = "20240124"; var $cmpOpenSSLVersion = "20240126";
var $caDN = NULL ; var $caDN = NULL ;
@@ -479,8 +479,7 @@
$this->caPub = openssl_pkey_get_public($this->caCrt); $this->caPub = openssl_pkey_get_public($this->caCrt);
if(!$this->caPub) { if(!$this->caPub) {
$this->e(__LINE__, "openssl_pkey_get_public: error"); throw new Exception("openssl_pkey_get_public: " . openssl_error_string());
return NULL;
} }
// var_export($csrout); // var_export($csrout);
@@ -510,16 +509,14 @@
$this->caCrtPEM = $text; $this->caCrtPEM = $text;
if(!$this->caCrtPEM) { if(!$this->caCrtPEM) {
$this->e(__LINE__, "Invalid CA text"); throw new Exception("Invalid CA text");
return NULL;
} }
// openssl_get_privatekey() // openssl_get_privatekey()
$this->caCrt = openssl_x509_read( $this->caCrtPEM ); $this->caCrt = openssl_x509_read( $this->caCrtPEM );
if(!$this->caCrt) { if(!$this->caCrt) {
$this->e(__LINE__, "openssl_x509_read: error"); throw new Exception("openssl_x509_read: " . openssl_error_string());
return NULL;
} }
// openssl_x509_parse(file_get_contents($file)); // openssl_x509_parse(file_get_contents($file));
@@ -527,15 +524,13 @@
$this->caPub = openssl_pkey_get_public($this->caCrt); $this->caPub = openssl_pkey_get_public($this->caCrt);
if(!$this->caPub) { if(!$this->caPub) {
$this->e(__LINE__, "openssl_pkey_get_public: error"); throw new Exception("openssl_pkey_get_public: " . openssl_error_string());
return NULL;
} }
$pkey = openssl_pkey_get_details($this->caPub); $pkey = openssl_pkey_get_details($this->caPub);
if(!$pkey) { if(!$pkey) {
$this->e(__LINE__, "openssl_pkey_get_details: error"); throw new Exception("openssl_pkey_get_details: " . openssl_error_string());
return NULL;
} }
$this->caPubPEM = $pkey["key"]; $this->caPubPEM = $pkey["key"];
@@ -543,8 +538,7 @@
$this->caPub = openssl_pkey_get_public($this->caPubPEM); $this->caPub = openssl_pkey_get_public($this->caPubPEM);
if(!$this->caPub) { if(!$this->caPub) {
$this->e(__LINE__, "openssl_pkey_get_public: error"); throw new Exception("openssl_pkey_get_public: " . openssl_error_string());
return NULL;
} }
return true; return true;
@@ -581,8 +575,7 @@
$this->caPrv = openssl_pkey_get_private($this->caPrvPEM, $pass); $this->caPrv = openssl_pkey_get_private($this->caPrvPEM, $pass);
if(!$this->caPrv) { if(!$this->caPrv) {
$this->e(__LINE__, "openssl_pkey_get_private: error"); throw new Exception("openssl_pkey_get_private: " . openssl_error_string());
return NULL;
} }
$sign = ""; $sign = "";
@@ -590,8 +583,7 @@
//Вычисляем подпись //Вычисляем подпись
if(!openssl_sign($test, $sign, $this->caPrv, "sha1WithRSAEncryption")) { if(!openssl_sign($test, $sign, $this->caPrv, "sha1WithRSAEncryption")) {
$this->e(__LINE__, "openssl_sign: error"); throw new Exception("openssl_sign: " . openssl_error_string());
return NULL;
} }
switch( openssl_verify($test, $sign, $this->caPub, OPENSSL_ALGO_SHA1) ) { switch( openssl_verify($test, $sign, $this->caPub, OPENSSL_ALGO_SHA1) ) {
@@ -601,11 +593,11 @@
case 0: case 0:
// echo "некорректна\n"; // echo "некорректна\n";
$this->e(__LINE__, "Incorrect CA private key"); $this->e("Incorrect CA private key");
return NULL; return NULL;
case -1: case -1:
$this->e(__LINE__, openssl_error_string()); $this->e(openssl_error_string());
return NULL; return NULL;
} }
@@ -613,16 +605,7 @@
} }
function infoCA() { function cmpOpenSslCertGen($parm, &$out = null) {
var_export(openssl_x509_parse($this->caCrt));
echo "\n";
// var_export(openssl_pkey_get_details($this->caPrv));
// echo "\n";
}
function createCli($parm, &$out = null) {
try { try {
$confFile = $this->cmpOpenSslConfTemp(); $confFile = $this->cmpOpenSslConfTemp();
@@ -704,8 +687,7 @@
$this->cliPub = openssl_pkey_get_public($this->cliCrt); $this->cliPub = openssl_pkey_get_public($this->cliCrt);
if(!$this->cliPub) { if(!$this->cliPub) {
$this->e(__LINE__, "openssl_pkey_get_public: error"); throw new Exception("openssl_pkey_get_public: " . openssl_error_string());
return NULL;
} }
// var_export($csrout); // var_export($csrout);
@@ -714,14 +696,14 @@
return true; return true;
} }
function createClient($parm = NULL, &$out = null) { function cmpOpenSslCertClientGen($parm = NULL, &$out = null) {
$parm["x509_extensions"] = "cmp_x509_ext_cli"; $parm["x509_extensions"] = "cmp_x509_ext_cli";
return $this->createCli($parm, $out); return $this->cmpOpenSslCertGen($parm, $out);
} }
function createServer($parm = NULL, &$out = null) { function cmpOpenSslCertServerGen($parm = NULL, &$out = null) {
$parm["x509_extensions"] = "cmp_x509_ext_srv"; $parm["x509_extensions"] = "cmp_x509_ext_srv";
return $this->createCli($parm, $out); return $this->cmpOpenSslCertGen($parm, $out);
} }
function cmpOpenSslGenDh($bits = 2048) { function cmpOpenSslGenDh($bits = 2048) {