src/ssl.c

changeset 30
36ed99e1ce1e
parent 21
c3755cb3d246
child 31
87625285de20
--- a/src/ssl.c	Sat Nov 20 20:04:11 2010 -0800
+++ b/src/ssl.c	Sat Nov 20 20:04:11 2010 -0800
@@ -376,6 +376,24 @@
 }
 
 /**
+ * Return the validation state of the peer chain
+ */
+static int meth_getpeerchainvalid(lua_State *L)
+{
+   p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
+   long result = SSL_get_verify_result(ssl->ssl);
+
+   if (result == X509_V_OK) {
+     lua_pushboolean(L, 1);
+     return 1;
+   }
+
+   lua_pushboolean(L, 0);
+   lua_pushstring(L, X509_verify_cert_error_string(result));
+   return 2;
+}
+
+/**
  * Return the peer certificate.
  */
 static int meth_getpeercertificate(lua_State *L)
@@ -448,6 +466,7 @@
   {"want",              meth_want},
   {"compression",       meth_compression},
   {"getpeercertificate",meth_getpeercertificate},
+  {"getpeerchainvalid", meth_getpeerchainvalid},
   {"getfinished",       meth_getfinished},
   {"getpeerfinished",   meth_getpeerfinished},
   {NULL,                NULL}

mercurial