summaryrefslogtreecommitdiff
path: root/src/certificate.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-03-14 17:01:47 +0000
committerCarl Hetherington <cth@carlh.net>2019-03-14 17:01:47 +0000
commit50bfe5a5a595f8200811d6916a777e24c880b441 (patch)
treeaf7a175ff6415ec58e78cec8f14f2190d0dc980f /src/certificate.cc
parentf218289708a9912f73707cb4bef13ffc469c1296 (diff)
Some new features in dcpkdm.
Diffstat (limited to 'src/certificate.cc')
-rw-r--r--src/certificate.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/certificate.cc b/src/certificate.cc
index a83d800d..6edf4f4c 100644
--- a/src/certificate.cc
+++ b/src/certificate.cc
@@ -337,6 +337,40 @@ Certificate::subject_organizational_unit_name () const
return get_name_part (X509_get_subject_name (_certificate), NID_organizationalUnitName);
}
+static
+struct tm
+convert_time (ASN1_TIME const * time)
+{
+ struct tm t;
+ char const * s = (char const *) time->data;
+
+ if (time->type == V_ASN1_UTCTIME) {
+ sscanf(s, "%2d%2d%2d%2d%2d%2d", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec);
+ if (t.tm_year < 70) {
+ t.tm_year += 100;
+ }
+ } else if (time->type == V_ASN1_GENERALIZEDTIME) {
+ sscanf(s, "%4d%2d%2d%2d%2d%2d", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec);
+ t.tm_year -= 1900;
+ }
+
+ return t;
+}
+
+struct tm
+Certificate::not_before () const
+{
+ DCP_ASSERT (_certificate);
+ return convert_time(X509_get0_notBefore(_certificate));
+}
+
+struct tm
+Certificate::not_after () const
+{
+ DCP_ASSERT (_certificate);
+ return convert_time(X509_get0_notAfter(_certificate));
+}
+
string
Certificate::serial () const
{