From 7852fbe6d1a6ed8289222fd034dabc578c5e0430 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Thu, 13 Aug 2020 23:34:10 +0100 Subject: [PATCH] Code to create PEM output and read cert data --- application/controllers/Lotw.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index 4e2feb42..c6130645 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -37,20 +37,34 @@ class Lotw extends CI_Controller { public function key() { $results = array(); $password = ""; - $filename = file_get_contents('file:///mnt/c/lotw/php/'); + $filename = file_get_contents('file:///mnt/c/lotw/php/file-to-read.p12'); $worked = openssl_pkcs12_read($filename, $results, $password); if($worked) { - $new_password = "peter"; + // Reading p12 successful + $new_password = "cloudlog"; // set default password $result = null; $worked = openssl_pkey_export($results['pkey'], $result, $new_password); if($worked) { - echo "
Your new pkey is:\n", $result, '
'; + // Store PEM Key in Array + $data['pem_key'] = $result; } else { echo openssl_error_string(); } } else { + // Reading p12 failed echo openssl_error_string(); } + + // Read Cert Data + $certdata= openssl_x509_parse($results['cert'],0); + + // Store Variables + $data['issued_callsign'] = $certdata['subject']['undefined']; + $data['issued_name'] = $certdata['subject']['commonName']; + $data['validFrom_Date'] = date("d-m-Y H:i:s", strtotime($certdata['validFrom'])); + $data['validTo_Date'] = date("d-m-Y H:i:s", strtotime($certdata['validTo'])); + + print_r($data); } private function loadFromFile($filepath) @@ -417,7 +431,7 @@ class Lotw extends CI_Controller { $key = ""; - $pkeyid = openssl_pkey_get_private($key, 'peter'); + $pkeyid = openssl_pkey_get_private($key, 'cloudlog'); //openssl_sign($plaintext, $signature, $pkeyid, OPENSSL_ALGO_SHA1 ); //openssl_free_key($pkeyid);