From 2168e24899a678c75f93a3da0c2702a8662e8933 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jan 2024 12:54:46 +0300 Subject: [PATCH] Rename func for all and fix error out --- cmpOpenSSLTests.php | 4 ++-- cmpOpenSSLTrait.php | 52 +++++++++++++++------------------------------ 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/cmpOpenSSLTests.php b/cmpOpenSSLTests.php index f6321ee..a3080d4 100644 --- a/cmpOpenSSLTests.php +++ b/cmpOpenSSLTests.php @@ -50,7 +50,7 @@ $out = array(); - $x->createServer($parm, $out); + $x->cmpOpenSslCertServerGen($parm, $out); var_export($out); @@ -74,7 +74,7 @@ $out = array(); - $x->createClient($parm, $out); + $x->cmpOpenSslCertClientGen($parm, $out); var_export($out); diff --git a/cmpOpenSSLTrait.php b/cmpOpenSSLTrait.php index 6492bb5..98a2c34 100644 --- a/cmpOpenSSLTrait.php +++ b/cmpOpenSSLTrait.php @@ -1,7 +1,7 @@ caPub = openssl_pkey_get_public($this->caCrt); if(!$this->caPub) { - $this->e(__LINE__, "openssl_pkey_get_public: error"); - return NULL; + throw new Exception("openssl_pkey_get_public: " . openssl_error_string()); } // var_export($csrout); @@ -510,16 +509,14 @@ $this->caCrtPEM = $text; if(!$this->caCrtPEM) { - $this->e(__LINE__, "Invalid CA text"); - return NULL; + throw new Exception("Invalid CA text"); } // openssl_get_privatekey() $this->caCrt = openssl_x509_read( $this->caCrtPEM ); if(!$this->caCrt) { - $this->e(__LINE__, "openssl_x509_read: error"); - return NULL; + throw new Exception("openssl_x509_read: " . openssl_error_string()); } // openssl_x509_parse(file_get_contents($file)); @@ -527,15 +524,13 @@ $this->caPub = openssl_pkey_get_public($this->caCrt); if(!$this->caPub) { - $this->e(__LINE__, "openssl_pkey_get_public: error"); - return NULL; + throw new Exception("openssl_pkey_get_public: " . openssl_error_string()); } $pkey = openssl_pkey_get_details($this->caPub); if(!$pkey) { - $this->e(__LINE__, "openssl_pkey_get_details: error"); - return NULL; + throw new Exception("openssl_pkey_get_details: " . openssl_error_string()); } $this->caPubPEM = $pkey["key"]; @@ -543,8 +538,7 @@ $this->caPub = openssl_pkey_get_public($this->caPubPEM); if(!$this->caPub) { - $this->e(__LINE__, "openssl_pkey_get_public: error"); - return NULL; + throw new Exception("openssl_pkey_get_public: " . openssl_error_string()); } return true; @@ -581,8 +575,7 @@ $this->caPrv = openssl_pkey_get_private($this->caPrvPEM, $pass); if(!$this->caPrv) { - $this->e(__LINE__, "openssl_pkey_get_private: error"); - return NULL; + throw new Exception("openssl_pkey_get_private: " . openssl_error_string()); } $sign = ""; @@ -590,8 +583,7 @@ //Вычисляем подпись if(!openssl_sign($test, $sign, $this->caPrv, "sha1WithRSAEncryption")) { - $this->e(__LINE__, "openssl_sign: error"); - return NULL; + throw new Exception("openssl_sign: " . openssl_error_string()); } switch( openssl_verify($test, $sign, $this->caPub, OPENSSL_ALGO_SHA1) ) { @@ -601,11 +593,11 @@ case 0: // echo "некорректна\n"; - $this->e(__LINE__, "Incorrect CA private key"); + $this->e("Incorrect CA private key"); return NULL; case -1: - $this->e(__LINE__, openssl_error_string()); + $this->e(openssl_error_string()); return NULL; } @@ -613,16 +605,7 @@ } - function infoCA() { - var_export(openssl_x509_parse($this->caCrt)); - echo "\n"; - - // var_export(openssl_pkey_get_details($this->caPrv)); - // echo "\n"; - } - - - function createCli($parm, &$out = null) { + function cmpOpenSslCertGen($parm, &$out = null) { try { $confFile = $this->cmpOpenSslConfTemp(); @@ -704,8 +687,7 @@ $this->cliPub = openssl_pkey_get_public($this->cliCrt); if(!$this->cliPub) { - $this->e(__LINE__, "openssl_pkey_get_public: error"); - return NULL; + throw new Exception("openssl_pkey_get_public: " . openssl_error_string()); } // var_export($csrout); @@ -714,14 +696,14 @@ return true; } - function createClient($parm = NULL, &$out = null) { + function cmpOpenSslCertClientGen($parm = NULL, &$out = null) { $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"; - return $this->createCli($parm, $out); + return $this->cmpOpenSslCertGen($parm, $out); } function cmpOpenSslGenDh($bits = 2048) {