Skip to content

Commit b1cfcf0

Browse files
committed
Enable socket_wrapper and nss_wrapper support for tests
Uncomment the socket_wrapper and nss_wrapper checks in configure.ac and add custom GnuTLS push/pull functions to work better with socket_wrapper. Update test environment to use cwrap_test when both wrappers are available.
1 parent 99622f8 commit b1cfcf0

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

configure.ac

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ AC_CHECK_HEADERS([sys/mount.h],,,
264264
]])
265265
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h syslog.h linux/types.h sys/dirent.h sys/uio.h])
266266
PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.32.0 gthread-2.0 >= 2.32.0], [HAVE_GLIB=yes], AC_MSG_ERROR([Missing glib]))
267-
#PKG_CHECK_MODULES(SW, [socket_wrapper], [HAVE_SW=yes], [HAVE_SW=no])
268-
#PKG_CHECK_MODULES(NW, [nss_wrapper], [HAVE_NW=yes], [HAVE_NW=no])
269-
#AM_CONDITIONAL(CWRAP, test "$HAVE_SW" = "yes" -a "$HAVE_NW" = "yes")
267+
PKG_CHECK_MODULES(SW, [socket_wrapper], [HAVE_SW=yes], [HAVE_SW=no])
268+
PKG_CHECK_MODULES(NW, [nss_wrapper], [HAVE_NW=yes], [HAVE_NW=no])
269+
AM_CONDITIONAL(CWRAP, test "$HAVE_SW" = "yes" -a "$HAVE_NW" = "yes")
270270

271271
my_save_cflags="$CFLAGS"
272272
my_save_libs="$LIBS"

crypto-gnutls.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ struct tlssession
6767
#define BUF_SIZE 65536
6868
#define BUF_HWM ((BUF_SIZE*3)/4)
6969

70+
/* Custom push/pull functions for GnuTLS to handle socket wrapper better */
71+
static inline ssize_t custom_gnutls_push(gnutls_transport_ptr_t ptr, const void *data, size_t len) {
72+
return write((int)(intptr_t)ptr, data, len);
73+
}
74+
75+
static inline ssize_t custom_gnutls_pull(gnutls_transport_ptr_t ptr, void *data, size_t len) {
76+
return read((int)(intptr_t)ptr, data, len);
77+
}
78+
7079
static int
7180
falsequit (void *opaque)
7281
{
@@ -374,9 +383,11 @@ tlssession_mainloop (int cryptfd, int plainfd, tlssession_t * s)
374383
goto error;
375384
}
376385

377-
/* set it up to work with our FD */
386+
/* set it up to work with our FD using custom push/pull functions */
378387
gnutls_transport_set_ptr (s->session,
379388
(gnutls_transport_ptr_t) (intptr_t) cryptfd);
389+
gnutls_transport_set_push_function (s->session, custom_gnutls_push);
390+
gnutls_transport_set_pull_function (s->session, custom_gnutls_pull);
380391

381392

382393
/* Now do the handshake */

tests/run/Makefile.am

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ TLSSRC = $(top_srcdir)/crypto-gnutls.c $(top_srcdir)/crypto-gnutls.h $(top_srcdi
33
else
44
TLSSRC =
55
endif
6-
#if CWRAP
7-
#TESTS_ENVIRONMENT=$(srcdir)/cwrap_test
8-
#else
6+
if CWRAP
7+
TESTS_ENVIRONMENT=$(srcdir)/cwrap_test
8+
else
99
TESTS_ENVIRONMENT=$(srcdir)/simple_test
10-
#endif
10+
endif
1111
TESTS = cfg1 cfgmulti cfgnew cfgsize write flush integrity dirconfig list inetd \
1212
rowrite tree rotree unix integrityhuge handshake tls tlswrongcert tlshuge \
1313
connstatus nlconnect

0 commit comments

Comments
 (0)