Bv2.1 7.2.3: Check that subtitle <StartTime> exists and is 0.
[libdcp.git] / src / certificate.cc
index a83d800d3f934e78c70e0f61aadf1e837efb5d0c..2e33907d2e2f1dfd694866e480aa322f160aa832 100644 (file)
@@ -337,6 +337,50 @@ 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;
+       }
+
+       t.tm_mon--;
+
+       return t;
+}
+
+struct tm
+Certificate::not_before () const
+{
+       DCP_ASSERT (_certificate);
+#if OPENSSL_VERSION_NUMBER > 0x10100000L
+       return convert_time(X509_get0_notBefore(_certificate));
+#else
+       return convert_time(X509_get_notBefore(_certificate));
+#endif
+}
+
+struct tm
+Certificate::not_after () const
+{
+       DCP_ASSERT (_certificate);
+#if OPENSSL_VERSION_NUMBER > 0x10100000L
+       return convert_time(X509_get0_notAfter(_certificate));
+#else
+       return convert_time(X509_get_notAfter(_certificate));
+#endif
+}
+
 string
 Certificate::serial () const
 {