x509: Add :valid_at() method to discover whether a certificate would be valid at the given timestamp

Sat, 06 Nov 2010 01:10:01 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 06 Nov 2010 01:10:01 +0000
changeset 24
bbf12f9be71c
parent 23
20528cb40c4a
child 25
4bc25168aa1c

x509: Add :valid_at() method to discover whether a certificate would be valid at the given timestamp

src/x509.c file | annotate | diff | comparison | revisions
--- a/src/x509.c	Sat Nov 06 00:39:17 2010 +0000
+++ b/src/x509.c	Sat Nov 06 01:10:01 2010 +0000
@@ -192,6 +192,15 @@
   return 1;
 }
 
+int meth_valid_at(lua_State* L)
+{
+  X509* cert = luasec_to_x509(L, 1);
+  time_t time = luaL_checkinteger(L, 2);
+  lua_pushboolean(L, (X509_cmp_time(X509_get_notAfter(cert), &time) > 0
+                  && X509_cmp_time(X509_get_notBefore(cert), &time) < 0));
+  return 1;
+}
+
 int meth_pem(lua_State* L)
 {
   X509* cert = luasec_to_x509(L, 1);
@@ -256,6 +265,7 @@
   {"subject",       meth_subject},
   {"issuer",        meth_issuer},
   {"extensions",    meth_extensions},
+  {"valid_at",      meth_valid_at},
   {"pem",           meth_pem},
   {"digest",        meth_digest},
   {NULL,            NULL}

mercurial