SSL module updates and random class addition
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user