From b4a7f7f230f55baa18a8eca7a0100db84ccd2171 Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 6 Jul 2011 14:32:30 -0400 Subject: Add function to return a certificate's common name. --- etc/inc/certs.inc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'etc') 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 ""; +} + ?> -- cgit v1.1