diff options
author | jim-p <jimp@pfsense.org> | 2011-07-06 14:32:30 -0400 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2011-07-06 14:33:06 -0400 |
commit | b4a7f7f230f55baa18a8eca7a0100db84ccd2171 (patch) | |
tree | ca2047304e08bb66880ccccf73dfb00b506c6583 /etc/inc | |
parent | b7ca271f7e7e0c7e977f027f752dccc3b19bf63e (diff) | |
download | pfsense-b4a7f7f230f55baa18a8eca7a0100db84ccd2171.zip pfsense-b4a7f7f230f55baa18a8eca7a0100db84ccd2171.tar.gz |
Add function to return a certificate's common name.
Diffstat (limited to 'etc/inc')
-rw-r--r-- | etc/inc/certs.inc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/etc/inc/certs.inc b/etc/inc/certs.inc index 3f655b1..60ce951 100644 --- a/etc/inc/certs.inc +++ b/etc/inc/certs.inc @@ -649,4 +649,25 @@ function is_crl_internal($crl) { return (!(!empty($crl['text']) && empty($crl['cert'])) || ($crl["method"] == "internal")); } +function cert_get_cn($crt, $isref = false) { + /* If this is a certref, not an actual cert, look up the cert first */ + if ($isref) { + $cert = lookup_cert($crt); + /* If it's not a valid cert, bail. */ + if (!(is_array($cert) && !empty($cert['crt']))) + return ""; + $cert = $cert['crt']; + } else { + $cert = $crt; + } + $sub = cert_get_subject_array($cert); + if (is_array($sub)) { + foreach ($sub as $s) { + if (strtoupper($s['a']) == "CN") + return $s['v']; + } + } + return ""; +} + ?> |