SSL module updates and random class addition
This commit is contained in:
@@ -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