gnutls-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnutls-dev] gnutls-cli -s triggered by SIGALRM too?


From: Simon Josefsson
Subject: [gnutls-dev] gnutls-cli -s triggered by SIGALRM too?
Date: Sun Sep 21 03:07:01 2003
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Hello, I'm working on a STARTTLS interface for Emacs using GNUTLS,
since the current Emacs solution uses a non-standard command line
application based on OpenSSL, so moving to gnutls-cli seems better.

However, triggering the STARTTLS negotiation by EOF seem slightly
problematic to do in a portable way from Emacs.  The old starttls
application triggered the STARTTLS negotiation by SIGALRM.  Would it
be possible to support this as well, in gnutls-cli?  Suggested patch
attached.

Btw, elisp code is at
<http://quimby.gnus.org/cgi-bin/cvsweb.cgi/gnus/contrib/starttls.el?rev=1.3&content-type=text/x-cvsweb-markup>.
As you can see, it searches for certain strings that gnutls-cli
prints, so it would be good if those didn't change too much.

Thanks.

Index: src/cli.c
===================================================================
RCS file: /cvs/gnutls/gnutls/src/cli.c,v
retrieving revision 2.211
diff -u -p -r2.211 cli.c
--- src/cli.c   17 Sep 2003 20:00:14 -0000      2.211
+++ src/cli.c   21 Sep 2003 01:04:42 -0000
@@ -236,6 +236,12 @@ static int handle_error(socket_st hd, in
        return ret;
 }
 
+int starttls_alarmed;
+
+void starttls_alarm (int signum)
+{
+  starttls_alarmed = 1;
+}
 
 int main(int argc, char **argv)
 {
@@ -358,6 +364,8 @@ int main(int argc, char **argv)
 
        printf("\n- Simple Client Mode:\n\n");
 
+       signal (SIGALRM, &starttls_alarm);
+
        FD_ZERO(&rset);
        for (;;) {
                FD_SET(fileno(stdin), &rset);
@@ -366,7 +374,26 @@ int main(int argc, char **argv)
                maxfd = MAX(fileno(stdin), sd);
                tv.tv_sec = 3;
                tv.tv_usec = 0;
-               select(maxfd + 1, &rset, NULL, NULL, &tv);
+               err = select(maxfd + 1, &rset, NULL, NULL, &tv);
+
+               if (err < 0) {
+                 if (errno == EINTR && starttls_alarmed) {
+                   if (hd.secure == 0) {
+                     fprintf(stderr,
+                             "*** Starting TLS handshake\n");
+                     ret = do_handshake(&hd);
+                     if (ret < 0) {
+                       fprintf(stderr,
+                               "*** Handshake has failed\n");
+                       socket_bye(&hd);
+                       user_term = 1;
+                     }
+                   } else {
+                     user_term = 1;
+                   }
+                 }
+                 continue;
+               }
 
                if (FD_ISSET(sd, &rset)) {
                        bzero(buffer, MAX_BUF + 1);
Index: src/common.c
===================================================================
RCS file: /cvs/gnutls/gnutls/src/common.c,v
retrieving revision 2.61
diff -u -p -r2.61 common.c
--- src/common.c        17 Sep 2003 20:00:14 -0000      2.61
+++ src/common.c        21 Sep 2003 01:04:43 -0000
@@ -362,6 +362,8 @@ int print_info(gnutls_session session, c
        tmp = gnutls_compression_get_name(gnutls_compression_get(session));
        printf("- Compression: %s\n", tmp);
 
+       fflush (stdout);
+
        return 0;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]