s_client: add sieve starttls protocol support
Similar to SMTP, IMAP, etc the ManageSieve protocol has a method to
start TLS communications after an initial cleartext connection. This
patch adds support for that protocol to the s_client application.
---
apps/s_client.c | 31 +++++++++++++++++++++++++++++--
doc/apps/s_client.pod | 3 +--
2 files changed, 30 insertions(+), 4 deletions(-)
diff -up openssl-0.9.8g/apps/s_client.c.orig openssl-0.9.8g/apps/s_client.c
--- openssl-0.9.8g/apps/s_client.c.orig 2008-09-02 15:35:02.000000000 -0400
+++ openssl-0.9.8g/apps/s_client.c 2008-09-02 18:26:12.000000000 -0400
@@ -229,7 +229,8 @@ static void sc_usage(void)
BIO_printf(bio_err," -starttls prot - use the STARTTLS command before
starting TLS\n");
BIO_printf(bio_err," for those protocols that support
it, where\n");
BIO_printf(bio_err," 'prot' defines which one to
assume. Currently,\n");
- BIO_printf(bio_err," only \"smtp\", \"pop3\", \"imap\",
and \"ftp\" are supported.\n");
+ BIO_printf(bio_err," only \"smtp\", \"pop3\", \"imap\",
\"ftp\", and \"sieve\"\n");
+ BIO_printf(bio_err," are supported.\n");
#ifndef OPENSSL_NO_ENGINE
BIO_printf(bio_err," -engine id - Initialise and use the specified
engine\n");
#endif
@@ -270,7 +271,8 @@ enum
PROTO_SMTP,
PROTO_POP3,
PROTO_IMAP,
- PROTO_FTP
+ PROTO_FTP,
+ PROTO_SIEVE
};
int MAIN(int, char **);
@@ -537,6 +539,8 @@ int MAIN(int argc, char **argv)
starttls_proto = PROTO_IMAP;
else if (strcmp(*argv,"ftp") == 0)
starttls_proto = PROTO_FTP;
+ else if (strcmp(*argv,"sieve") == 0)
+ starttls_proto = PROTO_SIEVE;
else
goto bad;
}
@@ -933,6 +937,29 @@ re_start:
BIO_printf(sbio,"AUTH TLS\r\n");
BIO_read(sbio,sbuf,BUFSIZZ);
}
+ else if (starttls_proto == PROTO_SIEVE)
+ {
+ int foundit=0;
+ BIO *fbio = BIO_new(BIO_f_buffer());
+ BIO_push(fbio, sbio);
+ /* wait for multi-line CAPABILITY response */
+ do
+ {
+ mbuf_len = BIO_gets(fbio,mbuf,BUFSIZZ);
+ if (strstr(mbuf,"\"STARTTLS\""))
+ foundit=1;
+ }
+ while (mbuf_len>4 && strncmp(mbuf, "OK", 2));
+ (void)BIO_flush(fbio);
+ BIO_pop(fbio);
+ BIO_free(fbio);
+ if (!foundit)
+ BIO_printf(bio_err,
+ "didn't found STARTTLS in server response,"
+ " try anyway...\n");
+ BIO_printf(sbio,"STARTTLS\r\n");
+ BIO_read(sbio,sbuf,BUFSIZZ);
+ }
for (;;)
{
diff -up openssl-0.9.8g/doc/apps/s_client.pod.orig
openssl-0.9.8g/doc/apps/s_client.pod
--- openssl-0.9.8g/doc/apps/s_client.pod.orig 2008-09-02 15:35:02.000000000
-0400
+++ openssl-0.9.8g/doc/apps/s_client.pod 2008-09-02 15:35:07.000000000
-0400
@@ -188,7 +188,7 @@ command for more information.
send the protocol-specific message(s) to switch to TLS for communication.
B<protocol> is a keyword for the intended protocol. Currently, the only
-supported keywords are "smtp", "pop3", "imap", and "ftp".
+supported keywords are "smtp", "pop3", "imap", "ftp", and "sieve".
=item B<-tlsextdebug>
--
John W. Linville
[EMAIL PROTECTED]
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]