From 94f3060419ccc44af904e6c9784ec68046688e1d Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Wed, 26 Aug 2020 16:31:35 +0100 Subject: [PATCH] Adds main cert & fixes some typos --- application/config/migration.php | 2 +- application/controllers/Lotw.php | 9 ++++++-- .../migrations/045_add_cert_to_lotw_certs.php | 21 +++++++++++++++++++ application/models/LotwCert.php | 6 ++++-- .../lotw_views/adif_views/adif_export.php | 11 +++++----- 5 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 application/migrations/045_add_cert_to_lotw_certs.php diff --git a/application/config/migration.php b/application/config/migration.php index 9efb31da..2bc24f50 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 44; +$config['migration_version'] = 45; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index a775dced..65084e78 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -103,14 +103,14 @@ class Lotw extends CI_Controller { // New Certificate Store in Database // Store Certificate Data into MySQL - $this->LotwCert->store_certficiate($this->session->userdata('user_id'), $info['issued_callsign'], $dxcc, $info['validFrom'], $info['validTo_Date'], $info['pem_key']); + $this->LotwCert->store_certficiate($this->session->userdata('user_id'), $info['issued_callsign'], $dxcc, $info['validFrom'], $info['validTo_Date'], $info['pem_key'], $info['general_cert']); // Cert success flash message $this->session->set_flashdata('Success', $info['issued_callsign'].' Certficiate Imported.'); } else { // Certficiate is in the system time to update - $this->LotwCert->update_certficiate($this->session->userdata('user_id'), $info['issued_callsign'], $dxcc, $info['validFrom'], $info['validTo_Date'], $info['pem_key']); + $this->LotwCert->update_certficiate($this->session->userdata('user_id'), $info['issued_callsign'], $dxcc, $info['validFrom'], $info['validTo_Date'], $info['pem_key'], $info['general_cert']); // Cert success flash message $this->session->set_flashdata('Success', $info['issued_callsign'].' Certficiate Updated.'); @@ -237,11 +237,16 @@ class Lotw extends CI_Controller { $password = $password; // Only needed if 12 has a password set $filename = file_get_contents('file://'.$file); $worked = openssl_pkcs12_read($filename, $results, $password); + + $data['general_cert'] = $results['cert']; + + if($worked) { // Reading p12 successful $new_password = "cloudlog"; // set default password $result = null; $worked = openssl_pkey_export($results['pkey'], $result, $new_password); + if($worked) { // Store PEM Key in Array $data['pem_key'] = $result; diff --git a/application/migrations/045_add_cert_to_lotw_certs.php b/application/migrations/045_add_cert_to_lotw_certs.php new file mode 100644 index 00000000..d47f74f6 --- /dev/null +++ b/application/migrations/045_add_cert_to_lotw_certs.php @@ -0,0 +1,21 @@ +dbforge->add_column('lotw_certs', $fields); + } + + public function down() + { + $this->dbforge->drop_column('lotw_certs', 'cert'); + } +} \ No newline at end of file diff --git a/application/models/LotwCert.php b/application/models/LotwCert.php index d28f9b30..c43b7f83 100644 --- a/application/models/LotwCert.php +++ b/application/models/LotwCert.php @@ -40,7 +40,7 @@ class LotwCert extends CI_Model { return $query->num_rows(); } - function store_certficiate($user_id, $callsign, $dxcc, $date_created, $date_expires, $cert_key) { + function store_certficiate($user_id, $callsign, $dxcc, $date_created, $date_expires, $cert_key, $general_cert) { $data = array( 'user_id' => $user_id, 'callsign' => $callsign, @@ -48,17 +48,19 @@ class LotwCert extends CI_Model { 'date_created' => $date_created, 'date_expires' => $date_expires, 'cert_key' => $cert_key, + 'cert' => $general_cert, ); $this->db->insert('lotw_certs', $data); } - function update_certficiate($user_id, $callsign, $dxcc, $date_created, $date_expires, $cert_key) { + function update_certficiate($user_id, $callsign, $dxcc, $date_created, $date_expires, $cert_key, $general_cert) { $data = array( 'cert_dxcc' => $dxcc, 'date_created' => $date_created, 'date_expires' => $date_expires, 'cert_key' => $cert_key, + 'cert' => $general_cert ); $this->db->where('user_id', $user_id); diff --git a/application/views/lotw_views/adif_views/adif_export.php b/application/views/lotw_views/adif_views/adif_export.php index 38c671d4..fd84b1af 100644 --- a/application/views/lotw_views/adif_views/adif_export.php +++ b/application/views/lotw_views/adif_views/adif_export.php @@ -2,14 +2,15 @@ header('Content-Type: text/plain; charset=utf-8'); ?> cert_key); -$cert2 = str_replace("-----END ENCRYPTED PRIVATE KEY-----", "", $cert1); +$clean_cert = trim($lotw_cert_info->cert); +$cert1 = str_replace("-----BEGIN CERTIFICATE-----", "", $clean_cert); +$cert2 = str_replace("-----END CERTIFICATE-----", "", $cert1); ?> -TQSL V2.5.1 Lib: V2.5 Config: V11.9 AllowDupes: false +TQSL V2.5.4 Lib: V2.5 Config: V11.12 AllowDupes: false tCERT 1 -> +> @@ -121,7 +122,7 @@ if($qso->COL_SAT_NAME) { $signed_item = $CI->signlog($lotw_cert_info->cert_key, $sign_string); ?> -:6> +:6> >