[Development] os: add gnutls_x509_crt_print() implementation, older systems
don't have it and improve backward compatibility of TLS code.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4277 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx
index 7d58469..f81c634 100644
--- a/common/rfb/CSecurityTLS.cxx
+++ b/common/rfb/CSecurityTLS.cxx
@@ -43,16 +43,18 @@
 #include <rdr/TLSOutStream.h>
 #include <os/os.h>
 #include <os/print.h>
+#include <os/tls.h>
 
 #include <gnutls/x509.h>
 
-#if !defined(GNUTLS_VERSION_NUMBER) || (GNUTLS_VERSION_NUMBER < 0x020708)
-#define GNUTLS_CERT_NOT_ACTIVATED 512
-#define GNUTLS_CERT_EXPIRED 1024
-#endif
-
-#if !defined(GNUTLS_VERSION_NUMBER) || (GNUTLS_VERSION_NUMBER < 0x020301)
-#define GNUTLS_CRT_PRINT_ONELINE 1
+/*
+ * GNUTLS 2.6.5 and older didn't have some variables defined so don't use them.
+ * GNUTLS 1.X.X defined LIBGNUTLS_VERSION_NUMBER so treat it as "old" gnutls as
+ * well
+ */
+#if (defined(GNUTLS_VERSION_NUMBER) && GNUTLS_VERSION_NUMBER < 0x020606) || \
+    defined(LIBGNUTLS_VERSION_NUMBER)
+#define WITHOUT_X509_TIMES
 #endif
 
 #define TLS_DEBUG
@@ -284,6 +286,7 @@
   if (status & GNUTLS_CERT_REVOKED)
     throw AuthFailureException("server certificate has been revoked");
 
+#ifndef WITHOUT_X509_TIMES
   if (status & GNUTLS_CERT_NOT_ACTIVATED)
     throw AuthFailureException("server certificate has not been activated");
 
@@ -294,6 +297,7 @@
 			 "do you want to continue?"))
       throw AuthFailureException("server certificate has expired");
   }
+#endif
   /* Process other errors later */
 
   cert_list = gnutls_certificate_get_peers(session, &cert_list_size);
@@ -338,7 +342,6 @@
 
   vlog.debug("Saved server certificates don't match");
 
-  #if defined(GNUTLS_VERSION_NUMBER) && (GNUTLS_VERSION_NUMBER >= 0x010706)
   if (gnutls_x509_crt_print(crt, GNUTLS_CRT_PRINT_ONELINE, &info)) {
     /*
      * GNUTLS doesn't correctly export gnutls_free symbol which is
@@ -352,9 +355,8 @@
 #endif
     throw AuthFailureException("Could not find certificate to display");
   }
-  #endif
 
-  size_t out_size;
+  size_t out_size = 0;
   char *out_buf = NULL;
   char *certinfo = NULL;
   int len = 0;