SSL module updates and random class addition

This commit is contained in:
Deon George 2012-05-09 00:59:08 +10:00
parent 01d7f09a68
commit 1d2d589ff5
7 changed files with 131 additions and 23 deletions

View 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);
}
}
?>

View File

@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Random extends lnApp_Random {}
?>

View File

@ -28,7 +28,7 @@ class Payment_Bulk_Ezypay {
// Process payment // Process payment
$file = file_get_contents($_FILES['payment']['tmp_name']); $file = file_get_contents($_FILES['payment']['tmp_name']);
$file = explode("\r\n",$file); $file = preg_split("/[\r]?[\n]+/",$file);
$i = 0; $i = 0;
foreach ($file as $line) { foreach ($file as $line) {
@ -55,7 +55,7 @@ class Payment_Bulk_Ezypay {
} }
$file = file_get_contents($_FILES['transaction']['tmp_name']); $file = file_get_contents($_FILES['transaction']['tmp_name']);
$file = explode("\r\n",$file); $file = preg_split("/[\r]?[\n]+/",$file);
$i = 0; $i = 0;
foreach ($file as $line) { foreach ($file as $line) {

View File

@ -38,7 +38,26 @@ class Model_Service_Plugin_SSL extends Model_Service_Plugin {
} }
public function name() { 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 // @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(); return $this->service->product->plugin();
} }
public function details() {
return SSL::details($this->cert);
}
public function valid_from($format=FALSE) { public function valid_from($format=FALSE) {
return SSL::from($this->cert,$format); 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( $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'], 'config'=>$ssl_conf['config'],
'x509_extensions'=>$this->service->product->plugin()->extensions, 'x509_extensions'=>$this->service->product->plugin()->extensions,
'digest_alg'=>'sha1',
),time()); ),time());
if ($res AND openssl_x509_export($res,$cert)) { if ($res AND openssl_x509_export($res,$cert)) {

View File

@ -15,43 +15,90 @@ class SSL {
return new SSL; return new SSL;
} }
public static function details($key) { public static function details($cert,$key=NULL) {
return openssl_x509_parse($key); $k = openssl_x509_parse($cert);
return is_null($key) ? $k : $k[$key];
} }
public static function issuer($key) { public static function algorithm($cert,$key=NULL) {
$k = static::details($key); if (! $cert)
return $k['issuer']['CN']; 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) { public static function dn($cert) {
$k = static::details($key); if (! $cert)
return $format ? Config::date($k['validFrom_time_t']) : $k['validFrom_time_t']; 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) { public static function expire($key,$format=FALSE) {
$k = static::details($key); $k = static::details($key,'validTo_time_t');
return $format ? Config::date($k['validTo_time_t']) : $k['validTo_time_t']; return $format ? Config::date($k) : $k;
} }
public static function hash($key) { public static function hash($key) {
$k = static::details($key); return static::details($key,'hash');
return $k['hash'];
} }
public static function serial($key) { public static function serial($key) {
$k = static::details($key); return static::details($key,'serialNumber');
return $k['serialNumber'];
} }
public static function subject($key) { public static function subject($key) {
$k = static::details($key); $k = static::details($key,'subject');
return $k['subject']['CN']; return $k['CN'];
} }
public static function version($key) { public static function version($key) {
$k = static::details($key); return static::details($key,'version');
return $k['version'];
} }
public static function csrsubject($csr) { public static function csrsubject($csr) {

View File

@ -10,8 +10,16 @@
<td> <td>
<table width="100%"> <table width="100%">
<tr> <tr>
<td style="width: 25%;">Service Name</td> <td style="width: 25%;">Subject</td>
<td style="width: 75%;" class="data"><?php echo $so->display('csr'); ?></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>
<tr> <tr>
<td>Valid From</td> <td>Valid From</td>
@ -33,6 +41,10 @@
<td>Hash</td> <td>Hash</td>
<td class="data"><?php echo $so->hash(); ?></td> <td class="data"><?php echo $so->hash(); ?></td>
</tr> </tr>
<tr>
<td>Algorithm</td>
<td class="data"><?php echo $so->algorithm(); ?></td>
</tr>
<tr> <tr>
<td>Certificate</td> <td>Certificate</td>
<td class="data"><pre><?php echo $so->cert; ?></pre></td> <td class="data"><pre><?php echo $so->cert; ?></pre></td>

View File

@ -27,6 +27,10 @@
<td>Version</td> <td>Version</td>
<td class="data"><?php echo SSL::version($so->sign_cert); ?></td> <td class="data"><?php echo SSL::version($so->sign_cert); ?></td>
</tr> </tr>
<tr>
<td>Key Algorithm</td>
<td class="data"><?php echo SSL::algorithm($so->sign_cert); ?></td>
</tr>
<tr> <tr>
<td style="width: 40%;">Private Key</td> <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> <td style="width: 60%;"><?php echo FORM::textarea('sign_pk',$so->sign_pk,array('cols'=>64,'rows'=>13)); ?></td>