Compare commits
3 Commits
b2b0478685
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
73dfd8ae15 | ||
|
2168e24899 | ||
|
ba5edbf696 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -11,6 +11,10 @@
|
|||||||
**/8*
|
**/8*
|
||||||
**/9*
|
**/9*
|
||||||
|
|
||||||
|
**/*crt
|
||||||
|
**/*prv
|
||||||
|
**/*pem
|
||||||
|
|
||||||
**/*.log*
|
**/*.log*
|
||||||
**/*log
|
**/*log
|
||||||
**/LOG*
|
**/LOG*
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
$out = array();
|
$out = array();
|
||||||
|
|
||||||
$x->createCA($parm, $out);
|
$x->cmpOpenSslCaGen($parm, $out);
|
||||||
|
|
||||||
var_export($out);
|
var_export($out);
|
||||||
|
|
||||||
@@ -45,12 +45,12 @@
|
|||||||
"organizationalUnitName" => "TEST-OIT" ,
|
"organizationalUnitName" => "TEST-OIT" ,
|
||||||
);
|
);
|
||||||
|
|
||||||
$x->loadFromFileCACrt("test-ca-01.crt");
|
$x->cmpOpenSslCaCertFromFile("test-ca-01.crt");
|
||||||
$x->loadFromFileCAPrv("test-ca-01.prv");
|
$x->cmpOpenSslCaPrivFromFile("test-ca-01.prv");
|
||||||
|
|
||||||
$out = array();
|
$out = array();
|
||||||
|
|
||||||
$x->createServer($parm, $out);
|
$x->cmpOpenSslCertServerGen($parm, $out);
|
||||||
|
|
||||||
var_export($out);
|
var_export($out);
|
||||||
|
|
||||||
@@ -69,12 +69,12 @@
|
|||||||
"organizationalUnitName" => "TEST-OIT" ,
|
"organizationalUnitName" => "TEST-OIT" ,
|
||||||
);
|
);
|
||||||
|
|
||||||
$x->loadFromFileCACrt("test-ca-01.crt");
|
$x->cmpOpenSslCaCertFromFile("test-ca-01.crt");
|
||||||
$x->loadFromFileCAPrv("test-ca-01.prv");
|
$x->cmpOpenSslCaPrivFromFile("test-ca-01.prv");
|
||||||
|
|
||||||
$out = array();
|
$out = array();
|
||||||
|
|
||||||
$x->createClient($parm, $out);
|
$x->cmpOpenSslCertClientGen($parm, $out);
|
||||||
|
|
||||||
var_export($out);
|
var_export($out);
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
trait cmpOpenSSLTrait {
|
trait cmpOpenSSLTrait {
|
||||||
var $cmpOpenSSLVersion = "20240124";
|
var $cmpOpenSSLVersion = "20240126";
|
||||||
|
|
||||||
var $caDN = NULL ;
|
var $caDN = NULL ;
|
||||||
|
|
||||||
@@ -289,7 +289,7 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCertInfo($crt, $prv, &$out = null) {
|
function cmpOpenSslCertGetInfo($crt, $prv, &$out = null) {
|
||||||
$txtPub = "";
|
$txtPub = "";
|
||||||
$txtPrv = "";
|
$txtPrv = "";
|
||||||
|
|
||||||
@@ -392,7 +392,7 @@
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCA($parm, &$out = null) {
|
function cmpOpenSslCaGen($parm, &$out = null) {
|
||||||
try {
|
try {
|
||||||
$confFile = $this->cmpOpenSslConfTemp();
|
$confFile = $this->cmpOpenSslConfTemp();
|
||||||
|
|
||||||
@@ -458,7 +458,7 @@
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getCertInfo($this->caCrt, $this->caPrv, $out);
|
$this->cmpOpenSslCertGetInfo($this->caCrt, $this->caPrv, $out);
|
||||||
|
|
||||||
$txtPub = "";
|
$txtPub = "";
|
||||||
$txtPrv = "";
|
$txtPrv = "";
|
||||||
@@ -467,7 +467,7 @@
|
|||||||
openssl_pkey_export($this->caPrv , $txtPrv, NULL );
|
openssl_pkey_export($this->caPrv , $txtPrv, NULL );
|
||||||
|
|
||||||
if($out !== null) {
|
if($out !== null) {
|
||||||
if(!$this->getCertInfo($this->caCrt, $this->caPrv, $out))
|
if(!$this->cmpOpenSslCertGetInfo($this->caCrt, $this->caPrv, $out))
|
||||||
return NULL;
|
return 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);
|
||||||
@@ -489,14 +488,14 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFromFileCACrt($file) {
|
function cmpOpenSslCaCertFromFile($file) {
|
||||||
// var_dump(openssl_get_cert_locations());
|
// var_dump(openssl_get_cert_locations());
|
||||||
|
|
||||||
$this->caCrtFile = $file;
|
$this->caCrtFile = $file;
|
||||||
|
|
||||||
$text = @file_get_contents($file);
|
$text = @file_get_contents($file);
|
||||||
|
|
||||||
if($this->loadFromTextCACrt($text)) {
|
if($this->cmpOpenSslCaCertFromText($text)) {
|
||||||
$this->caCrtFile = $file;
|
$this->caCrtFile = $file;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -504,22 +503,20 @@
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFromTextCACrt($text) {
|
function cmpOpenSslCaCertFromText($text) {
|
||||||
$this->caCrtFile = "";
|
$this->caCrtFile = "";
|
||||||
|
|
||||||
$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,19 +538,18 @@
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFromFileCAPrv($file, $pass = NULL) {
|
function cmpOpenSslCaPrivFromFile($file, $pass = NULL) {
|
||||||
$this->caPrvFile = $file;
|
$this->caPrvFile = $file;
|
||||||
|
|
||||||
$text = @file_get_contents($file);
|
$text = @file_get_contents($file);
|
||||||
|
|
||||||
if($this->loadFromTextCAPrv($text, $pass)) {
|
if($this->cmpOpenSslCaPrivFromText($text, $pass)) {
|
||||||
$this->caPrvFile = $file;
|
$this->caPrvFile = $file;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -563,7 +557,7 @@
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFromTextCAPrv($text, $pass = NULL) {
|
function cmpOpenSslCaPrivFromText($text, $pass = NULL) {
|
||||||
$this->caPrvFile = "";
|
$this->caPrvFile = "";
|
||||||
/*
|
/*
|
||||||
if(@$file)
|
if(@$file)
|
||||||
@@ -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();
|
||||||
|
|
||||||
@@ -692,7 +675,7 @@
|
|||||||
openssl_pkey_export($this->cliPrv, $txtPrv, NULL );
|
openssl_pkey_export($this->cliPrv, $txtPrv, NULL );
|
||||||
|
|
||||||
if($out !== null) {
|
if($out !== null) {
|
||||||
if(!$this->getCertInfo($this->cliCrt, $this->cliPrv, $out))
|
if(!$this->cmpOpenSslCertGetInfo($this->cliCrt, $this->cliPrv, $out))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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) {
|
||||||
|
Reference in New Issue
Block a user