Re: [libvirt] [PATCH] tests: fix compilation failures

2011-07-26 Thread Daniel P. Berrange
On Mon, Jul 25, 2011 at 01:36:23PM -0600, Eric Blake wrote:
> On 07/25/2011 09:39 AM, Daniel P. Berrange wrote:
> >>(struct testTLSCertReq): Alter time members.
> >>(testTLSGenerateCert): Reflect the change.
> >>(mymain): Reduce stack usage.
> >>---
> >>
> >>
> >>-/* if zero, then the current time will be used */
> >>-time_t start;
> >>-time_t expire;
> >>+/* zero for current time, or non-zero for hours from now */
> >>+int start_offset;
> >>+/* zero for 24 hours from now, or non-zero for hours from now */
> >>+int expire_offset;
> >>  };
> >>
> 
> >
> >This is actually a change in semantics introduced here. The
> >start/expire values were treated as absolute values, eg in
> >places we pass '1' for expiry time to indicate a time way
> >in the past. This has now become 1 hour into the future.
> >This is why the 3 expiry tests were broken.
> >
> >I pushed the following change to make sure the expiry tests
> >have times in the past again
> >
> >+++ b/tests/virnettlscontexttest.c
> >@@ -1112,7 +1112,7 @@ mymain(void)
> >  true, true, true,
> >  true, true, GNUTLS_KEY_KEY_CERT_SIGN,
> >  false, false, NULL, NULL,
> >-0, 1,
> >+0, -1,
> 
> Ah - while I fixed the future stamps, I forgot to fix the past
> stamps. ACK to this change; however, I still find it odd that the
> start time is now but the expire time is in the past.  Instead,
> shouldn't we be using something like start time of -2 and expire
> time of -1, so the start time still comes before the expire time?

Well we're not really testing the start time in this scenario, so
it doesn't really matter either way.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] tests: fix compilation failures

2011-07-25 Thread Eric Blake

On 07/25/2011 09:39 AM, Daniel P. Berrange wrote:

(struct testTLSCertReq): Alter time members.
(testTLSGenerateCert): Reflect the change.
(mymain): Reduce stack usage.
---


-/* if zero, then the current time will be used */
-time_t start;
-time_t expire;
+/* zero for current time, or non-zero for hours from now */
+int start_offset;
+/* zero for 24 hours from now, or non-zero for hours from now */
+int expire_offset;
  };





This is actually a change in semantics introduced here. The
start/expire values were treated as absolute values, eg in
places we pass '1' for expiry time to indicate a time way
in the past. This has now become 1 hour into the future.
This is why the 3 expiry tests were broken.

I pushed the following change to make sure the expiry tests
have times in the past again

+++ b/tests/virnettlscontexttest.c
@@ -1112,7 +1112,7 @@ mymain(void)
  true, true, true,
  true, true, GNUTLS_KEY_KEY_CERT_SIGN,
  false, false, NULL, NULL,
-0, 1,
+0, -1,


Ah - while I fixed the future stamps, I forgot to fix the past stamps. 
ACK to this change; however, I still find it odd that the start time is 
now but the expire time is in the past.  Instead, shouldn't we be using 
something like start time of -2 and expire time of -1, so the start time 
still comes before the expire time?


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] tests: fix compilation failures

2011-07-25 Thread Daniel P. Berrange
On Fri, Jul 22, 2011 at 12:33:10PM -0600, Eric Blake wrote:
> Even though gnutls is a hard-req for libvirt, and gnutls depends
> on libtasn1, that does not mean that you have to have the libtasn1
> development files installed.  Skip the test rather than failing
> compilation in that case.
> 
> With newer gcc, the test consumed too much stack space.  Move
> things to static storage to fix that.
> 
> * configure.ac (AC_CHECK_HEADERS): Check for libtasn1.h.
> (HAVE_LIBTASN1): New automake conditional.
> * tests/Makefile.am (virnettlsconvirnettlscontexttest_SOURCES)
> (virnettlscontexttest_LDADD): Allow compilation without libtasn1.
> * tests/virnettlscontexttest.c: Skip test if headers not present.
> (struct testTLSCertReq): Alter time members.
> (testTLSGenerateCert): Reflect the change.
> (mymain): Reduce stack usage.
> ---
> 
> With this patch, I successfully skip the test if libtasn1-devel is
> not installed, and successfully pass the test on a RHEL 6 machine.
> I haven't yet tested on a F14 machine, where I heard reports from
> Laine of a failure (possibly due to an older library), but we can
> deal with that in a later patch.
> 
> I will push this under the build-breaker, once libvirt.org is back
> up (or even sooner to an alternate repo, if the downtime gets to
> be too painful).
> 
>  configure.ac |7 ++-
>  tests/Makefile.am|   10 +++-
>  tests/virnettlscontexttest.c |  109 -
>  3 files changed, 67 insertions(+), 59 deletions(-)

> -#ifndef WIN32
> +#if !defined WIN32 && HAVE_LIBTASN1_H
>  # include 
>  # include 
>  # include 
> @@ -112,9 +112,10 @@ struct testTLSCertReq {
>  const char *keyPurposeOID1;
>  const char *keyPurposeOID2;
> 
> -/* if zero, then the current time will be used */
> -time_t start;
> -time_t expire;
> +/* zero for current time, or non-zero for hours from now */
> +int start_offset;
> +/* zero for 24 hours from now, or non-zero for hours from now */
> +int expire_offset;
>  };
> 
> 
> @@ -160,13 +161,9 @@ testTLSGenerateCert(struct testTLSCertReq *req)
>  size_t size = sizeof(buffer);
>  char serial[5] = { 1, 2, 3, 4, 0 };
>  gnutls_datum_t der = { (unsigned char *)buffer, size };
> -time_t start = req->start;
> -time_t expire = req->expire;
> -
> -if (!start)
> -start = time(NULL);
> -if (!expire)
> -expire = time(NULL) + (60*60*24);
> +time_t start = time(NULL) + (60*60*req->start_offset);
> +time_t expire = time(NULL) + (60*60*(req->expire_offset
> + ? req->expire_offset : 24));

This is actually a change in semantics introduced here. The
start/expire values were treated as absolute values, eg in
places we pass '1' for expiry time to indicate a time way
in the past. This has now become 1 hour into the future.
This is why the 3 expiry tests were broken.

I pushed the following change to make sure the expiry tests
have times in the past again

commit 567b8d69b97827da0e6e7145edb83ec0d7deff86
Author: Daniel P. Berrange 
Date:   Mon Jul 25 16:18:56 2011 +0100

Fix TLS context tests with expired certs

commit 5283ea9b1d8a4b0f2fd6796bf60615aca7b6c3e6 changed the
semantics of the 'expire_offset' field in the test case struct
so that instead of being an absolute timestamp, it was a delta
relative to the current time. This broke the test cases which
were testing expiry of certificates, by putting the expiry
time into the future, instead of in the past.

Fix this by changing the expiry values to be negative, so that
the delta goes into the past again.

* virnettlscontexttest.c: Fix expiry tests

diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c
index 043ccc2..dfc0ac4 100644
--- a/tests/virnettlscontexttest.c
+++ b/tests/virnettlscontexttest.c
@@ -1112,7 +1112,7 @@ mymain(void)
 true, true, true,
 true, true, GNUTLS_KEY_KEY_CERT_SIGN,
 false, false, NULL, NULL,
-0, 1,
+0, -1,
 };
 static struct testTLSCertReq servercertexpreq = {
 NULL, NULL, "servercert.pem", "UK",
@@ -1120,7 +1120,7 @@ mymain(void)
 true, true, false,
 true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
 true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL,
-0, 1,
+0, -1,
 };
 static struct testTLSCertReq clientcertexpreq = {
 NULL, NULL, "clientcert.pem", "UK",
@@ -1128,7 +1128,7 @@ mymain(void)
 true, true, false,
 true, true, GNUTLS_KEY_DIGITAL_SIGNATURE | GNUTLS_KEY_KEY_ENCIPHERMENT,
 true, true, GNUTLS_KP_TLS_WWW_CLIENT, NULL,
-0, 1,
+0, -1,
 };
 
 DO_CTX_TEST(true, cacertexpreq, servercertreq, true);


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http:/

[libvirt] [PATCH] tests: fix compilation failures

2011-07-22 Thread Eric Blake
Even though gnutls is a hard-req for libvirt, and gnutls depends
on libtasn1, that does not mean that you have to have the libtasn1
development files installed.  Skip the test rather than failing
compilation in that case.

With newer gcc, the test consumed too much stack space.  Move
things to static storage to fix that.

* configure.ac (AC_CHECK_HEADERS): Check for libtasn1.h.
(HAVE_LIBTASN1): New automake conditional.
* tests/Makefile.am (virnettlsconvirnettlscontexttest_SOURCES)
(virnettlscontexttest_LDADD): Allow compilation without libtasn1.
* tests/virnettlscontexttest.c: Skip test if headers not present.
(struct testTLSCertReq): Alter time members.
(testTLSGenerateCert): Reflect the change.
(mymain): Reduce stack usage.
---

With this patch, I successfully skip the test if libtasn1-devel is
not installed, and successfully pass the test on a RHEL 6 machine.
I haven't yet tested on a F14 machine, where I heard reports from
Laine of a failure (possibly due to an older library), but we can
deal with that in a later patch.

I will push this under the build-breaker, once libvirt.org is back
up (or even sooner to an alternate repo, if the downtime gets to
be too painful).

 configure.ac |7 ++-
 tests/Makefile.am|   10 +++-
 tests/virnettlscontexttest.c |  109 -
 3 files changed, 67 insertions(+), 59 deletions(-)

diff --git a/configure.ac b/configure.ac
index 9e39f44..4e04950 100644
--- a/configure.ac
+++ b/configure.ac
@@ -136,7 +136,12 @@ LIBS=$old_libs
 dnl Availability of various common headers (non-fatal if missing).
 AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/un.h \
   sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h \
-  sys/un.h sys/syscall.h netinet/tcp.h ifaddrs.h])
+  sys/un.h sys/syscall.h netinet/tcp.h ifaddrs.h libtasn1.h])
+
+dnl Our only use of libtasn1.h is in the testsuite, and can be skipped
+dnl if the header is not present.  Assume -ltasn1 is present if the
+dnl header could be found.
+AM_CONDITIONAL([HAVE_LIBTASN1], [test "x$ac_cv_header_libtasn1_h" = "xyes"])

 AC_CHECK_LIB([intl],[gettext],[])

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1c91a1e..872aa22 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -454,9 +454,15 @@ virnetsockettest_CFLAGS = 
-Dabs_builddir="\"$(abs_builddir)\"" $(AM_CFLAGS)
 virnetsockettest_LDADD = ../src/libvirt-net-rpc.la $(LDADDS)

 virnettlscontexttest_SOURCES = \
-   virnettlscontexttest.c testutils.h testutils.c pkix_asn1_tab.c
+   virnettlscontexttest.c testutils.h testutils.c
 virnettlscontexttest_CFLAGS = -Dabs_builddir="\"$(abs_builddir)\"" $(AM_CFLAGS)
-virnettlscontexttest_LDADD = ../src/libvirt-net-rpc.la $(LDADDS) -ltasn1
+virnettlscontexttest_LDADD = ../src/libvirt-net-rpc.la $(LDADDS)
+if HAVE_LIBTASN1
+virnettlscontexttest_SOURCES += pkix_asn1_tab.c
+virnettlscontexttest_LDADD += -ltasn1
+else
+EXTRA_DIST += pkix_asn1_tab.c
+endif


 seclabeltest_SOURCES = \
diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c
index c8775eb..e70cd8b 100644
--- a/tests/virnettlscontexttest.c
+++ b/tests/virnettlscontexttest.c
@@ -33,7 +33,7 @@
 #include "command.h"
 #include "network.h"

-#ifndef WIN32
+#if !defined WIN32 && HAVE_LIBTASN1_H
 # include 
 # include 
 # include 
@@ -112,9 +112,10 @@ struct testTLSCertReq {
 const char *keyPurposeOID1;
 const char *keyPurposeOID2;

-/* if zero, then the current time will be used */
-time_t start;
-time_t expire;
+/* zero for current time, or non-zero for hours from now */
+int start_offset;
+/* zero for 24 hours from now, or non-zero for hours from now */
+int expire_offset;
 };


@@ -160,13 +161,9 @@ testTLSGenerateCert(struct testTLSCertReq *req)
 size_t size = sizeof(buffer);
 char serial[5] = { 1, 2, 3, 4, 0 };
 gnutls_datum_t der = { (unsigned char *)buffer, size };
-time_t start = req->start;
-time_t expire = req->expire;
-
-if (!start)
-start = time(NULL);
-if (!expire)
-expire = time(NULL) + (60*60*24);
+time_t start = time(NULL) + (60*60*req->start_offset);
+time_t expire = time(NULL) + (60*60*(req->expire_offset
+ ? req->expire_offset : 24));

 /*
  * Prepare our new certificate object
@@ -767,7 +764,7 @@ mymain(void)
 /* A perfect CA, perfect client & perfect server */

 /* Basic:CA:critical */
-struct testTLSCertReq cacertreq = {
+static struct testTLSCertReq cacertreq = {
 NULL, NULL, "cacert.pem", "UK",
 "libvirt CA", NULL, NULL, NULL, NULL,
 true, true, true,
@@ -775,7 +772,7 @@ mymain(void)
 false, false, NULL, NULL,
 0, 0,
 };
-struct testTLSCertReq servercertreq = {
+static struct testTLSCertReq servercertreq = {
 NULL, NULL, "servercert.pem", "UK",
 "libvirt.org", NULL, NULL, NULL, NULL,
 true, true, false,
@@ -783,7 +780,7 @@ mymain(void)