SSL module updates and random class addition
This commit is contained in:
parent
01d7f09a68
commit
1d2d589ff5
17
application/classes/lnapp/random.php
Normal file
17
application/classes/lnapp/random.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is for generating Random data.
|
||||
*
|
||||
* @package lnApp
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class lnApp_Random {
|
||||
public static function char($num=NULL) {
|
||||
return substr(md5(rand()),0,is_null($num) ? rand(6,10) : $num-1);
|
||||
}
|
||||
}
|
||||
?>
|
4
application/classes/random.php
Normal file
4
application/classes/random.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
class Random extends lnApp_Random {}
|
||||
?>
|
@ -28,7 +28,7 @@ class Payment_Bulk_Ezypay {
|
||||
|
||||
// Process payment
|
||||
$file = file_get_contents($_FILES['payment']['tmp_name']);
|
||||
$file = explode("\r\n",$file);
|
||||
$file = preg_split("/[\r]?[\n]+/",$file);
|
||||
|
||||
$i = 0;
|
||||
foreach ($file as $line) {
|
||||
@ -55,7 +55,7 @@ class Payment_Bulk_Ezypay {
|
||||
}
|
||||
|
||||
$file = file_get_contents($_FILES['transaction']['tmp_name']);
|
||||
$file = explode("\r\n",$file);
|
||||
$file = preg_split("/[\r]?[\n]+/",$file);
|
||||
|
||||
$i = 0;
|
||||
foreach ($file as $line) {
|
||||
|
@ -38,7 +38,26 @@ class Model_Service_Plugin_SSL extends Model_Service_Plugin {
|
||||
}
|
||||
|
||||
public function name() {
|
||||
return $this->display($this->cert ? 'cert' : 'csr');
|
||||
if ($this->cert) {
|
||||
return sprintf('%s:%s',$this->ssl_ca->subject(),$this->display('cert'));
|
||||
} else
|
||||
return $this->display('csr');
|
||||
}
|
||||
|
||||
public function algorithm() {
|
||||
return SSL::algorithm($this->cert);
|
||||
}
|
||||
|
||||
public function dn() {
|
||||
return SSL::dn($this->cert);
|
||||
}
|
||||
|
||||
public function dnissuer() {
|
||||
return SSL::dnissuer($this->cert);
|
||||
}
|
||||
|
||||
public function issuer() {
|
||||
return SSL::issuer($this->cert);
|
||||
}
|
||||
|
||||
// @todo This needs to be validated for this model
|
||||
@ -49,6 +68,10 @@ class Model_Service_Plugin_SSL extends Model_Service_Plugin {
|
||||
return $this->service->product->plugin();
|
||||
}
|
||||
|
||||
public function details() {
|
||||
return SSL::details($this->cert);
|
||||
}
|
||||
|
||||
public function valid_from($format=FALSE) {
|
||||
return SSL::from($this->cert,$format);
|
||||
}
|
||||
@ -132,6 +155,7 @@ class Model_Service_Plugin_SSL extends Model_Service_Plugin {
|
||||
$res = openssl_csr_sign($this->csr,$this->ssl_ca->sign_cert,$this->ssl_ca->sign_pk,$this->service->product->plugin()->days,array(
|
||||
'config'=>$ssl_conf['config'],
|
||||
'x509_extensions'=>$this->service->product->plugin()->extensions,
|
||||
'digest_alg'=>'sha1',
|
||||
),time());
|
||||
|
||||
if ($res AND openssl_x509_export($res,$cert)) {
|
||||
|
@ -15,43 +15,90 @@ class SSL {
|
||||
return new SSL;
|
||||
}
|
||||
|
||||
public static function details($key) {
|
||||
return openssl_x509_parse($key);
|
||||
public static function details($cert,$key=NULL) {
|
||||
$k = openssl_x509_parse($cert);
|
||||
|
||||
return is_null($key) ? $k : $k[$key];
|
||||
}
|
||||
|
||||
public static function issuer($key) {
|
||||
$k = static::details($key);
|
||||
return $k['issuer']['CN'];
|
||||
public static function algorithm($cert,$key=NULL) {
|
||||
if (! $cert)
|
||||
return '';
|
||||
|
||||
$r = openssl_x509_read($cert);
|
||||
openssl_x509_export($r,$e,FALSE);
|
||||
|
||||
// @todo There must be a nice way to get this?
|
||||
if (preg_match('/^\s+Signature Algorithm:\s*(.*)\s*$/m',$e,$match))
|
||||
return $match[1];
|
||||
else
|
||||
return _('Unknown');
|
||||
}
|
||||
|
||||
public static function from($key,$format=FALSE) {
|
||||
$k = static::details($key);
|
||||
return $format ? Config::date($k['validFrom_time_t']) : $k['validFrom_time_t'];
|
||||
public static function dn($cert) {
|
||||
if (! $cert)
|
||||
return '';
|
||||
|
||||
$s = '';
|
||||
|
||||
$c = 0;
|
||||
foreach (static::details($cert,'subject') as $k=>$v) {
|
||||
if ($c++)
|
||||
$s .= ',';
|
||||
|
||||
$s .= sprintf('%s=%s',$k,$v);
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
public static function dnissuer($cert) {
|
||||
if (! $cert)
|
||||
return '';
|
||||
|
||||
$s = '';
|
||||
|
||||
$c = 0;
|
||||
foreach (static::details($cert,'issuer') as $k=>$v) {
|
||||
if ($c++)
|
||||
$s .= ',';
|
||||
|
||||
$s .= sprintf('%s=%s',$k,$v);
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
public static function issuer($cert) {
|
||||
$k = static::details($cert,'issuer');
|
||||
return $k['CN'];
|
||||
}
|
||||
|
||||
public static function from($cert,$format=FALSE) {
|
||||
$k = static::details($cert,'validFrom_time_t');
|
||||
return $format ? Config::date($k) : $k;
|
||||
}
|
||||
|
||||
public static function expire($key,$format=FALSE) {
|
||||
$k = static::details($key);
|
||||
return $format ? Config::date($k['validTo_time_t']) : $k['validTo_time_t'];
|
||||
$k = static::details($key,'validTo_time_t');
|
||||
return $format ? Config::date($k) : $k;
|
||||
}
|
||||
|
||||
public static function hash($key) {
|
||||
$k = static::details($key);
|
||||
return $k['hash'];
|
||||
return static::details($key,'hash');
|
||||
}
|
||||
|
||||
public static function serial($key) {
|
||||
$k = static::details($key);
|
||||
return $k['serialNumber'];
|
||||
return static::details($key,'serialNumber');
|
||||
}
|
||||
|
||||
public static function subject($key) {
|
||||
$k = static::details($key);
|
||||
return $k['subject']['CN'];
|
||||
$k = static::details($key,'subject');
|
||||
return $k['CN'];
|
||||
}
|
||||
|
||||
public static function version($key) {
|
||||
$k = static::details($key);
|
||||
return $k['version'];
|
||||
return static::details($key,'version');
|
||||
}
|
||||
|
||||
public static function csrsubject($csr) {
|
||||
|
@ -10,8 +10,16 @@
|
||||
<td>
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td style="width: 25%;">Service Name</td>
|
||||
<td style="width: 75%;" class="data"><?php echo $so->display('csr'); ?></td>
|
||||
<td style="width: 25%;">Subject</td>
|
||||
<td style="width: 75%;" class="data"><?php echo $so->dn(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Issuer</td>
|
||||
<td class="data"><?php echo $so->dnissuer(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>CA</td>
|
||||
<td class="data"><?php echo $so->ssl_ca->subject(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Valid From</td>
|
||||
@ -33,6 +41,10 @@
|
||||
<td>Hash</td>
|
||||
<td class="data"><?php echo $so->hash(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Algorithm</td>
|
||||
<td class="data"><?php echo $so->algorithm(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Certificate</td>
|
||||
<td class="data"><pre><?php echo $so->cert; ?></pre></td>
|
||||
|
@ -27,6 +27,10 @@
|
||||
<td>Version</td>
|
||||
<td class="data"><?php echo SSL::version($so->sign_cert); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Key Algorithm</td>
|
||||
<td class="data"><?php echo SSL::algorithm($so->sign_cert); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width: 40%;">Private Key</td>
|
||||
<td style="width: 60%;"><?php echo FORM::textarea('sign_pk',$so->sign_pk,array('cols'=>64,'rows'=>13)); ?></td>
|
||||
|
Reference in New Issue
Block a user