summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorLutz Jänicke <jaenicke@openssl.org>2007-02-22 17:39:47 +0000
committerLutz Jänicke <jaenicke@openssl.org>2007-02-22 17:39:47 +0000
commitee373e7f190914ce7d95a9011864f4d7c9502c6b (patch)
treeda20e18e7c298daa2758b7b649b8032d96c2dbe9 /apps
parent8d72476e2b4a00b9702d50e5b57a95ba9c32e41e (diff)
Fix problem with multi line responses in -starttls by using a buffering
BIO and BIO_gets().
Diffstat (limited to 'apps')
-rw-r--r--apps/s_client.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/apps/s_client.c b/apps/s_client.c
index 633d110f79..66c0f8aa33 100644
--- a/apps/s_client.c
+++ b/apps/s_client.c
@@ -912,25 +912,37 @@ re_start:
sbuf_off=0;
/* This is an ugly hack that does a lot of assumptions */
+ /* We do have to handle multi-line responses which may come
+ in a single packet or not. We therefore have to use
+ BIO_gets() which does need a buffering BIO. So during
+ the initial chitchat we do push a buffering BIO into the
+ chain that is removed again later on to not disturb the
+ rest of the s_client operation. */
if (starttls_proto == PROTO_SMTP)
{
int foundit=0;
+ BIO *fbio = BIO_new(BIO_f_buffer());
+ BIO_push(fbio, sbio);
/* wait for multi-line response to end from SMTP */
do
{
- mbuf_len = BIO_read(sbio,mbuf,BUFSIZZ);
+ mbuf_len = BIO_gets(fbio,mbuf,BUFSIZZ);
}
while (mbuf_len>3 && mbuf[3]=='-');
/* STARTTLS command requires EHLO... */
- BIO_printf(sbio,"EHLO openssl.client.net\r\n");
+ BIO_printf(fbio,"EHLO openssl.client.net\r\n");
+ BIO_flush(fbio);
/* wait for multi-line response to end EHLO SMTP response */
do
{
- mbuf_len = BIO_read(sbio,mbuf,BUFSIZZ);
+ mbuf_len = BIO_gets(fbio,mbuf,BUFSIZZ);
if (strstr(mbuf,"STARTTLS"))
foundit=1;
}
while (mbuf_len>3 && mbuf[3]=='-');
+ BIO_flush(fbio);
+ BIO_pop(fbio);
+ BIO_free(fbio);
if (!foundit)
BIO_printf(bio_err,
"didn't found starttls in server response,"
@@ -947,17 +959,23 @@ re_start:
else if (starttls_proto == PROTO_IMAP)
{
int foundit=0;
- BIO_read(sbio,mbuf,BUFSIZZ);
+ BIO *fbio = BIO_new(BIO_f_buffer());
+ BIO_push(fbio, sbio);
+ BIO_gets(fbio,mbuf,BUFSIZZ);
/* STARTTLS command requires CAPABILITY... */
- BIO_printf(sbio,". CAPABILITY\r\n");
+ BIO_printf(fbio,". CAPABILITY\r\n");
+ BIO_flush(fbio);
/* wait for multi-line CAPABILITY response */
do
{
- mbuf_len = BIO_read(sbio,mbuf,BUFSIZZ);
+ mbuf_len = BIO_gets(fbio,mbuf,BUFSIZZ);
if (strstr(mbuf,"STARTTLS"))
foundit=1;
}
- while (mbuf_len>3);
+ while (mbuf_len>3 && mbuf[0]!='.');
+ BIO_flush(fbio);
+ BIO_pop(fbio);
+ BIO_free(fbio);
if (!foundit)
BIO_printf(bio_err,
"didn't found STARTTLS in server response,"
@@ -967,12 +985,17 @@ re_start:
}
else if (starttls_proto == PROTO_FTP)
{
+ BIO *fbio = BIO_new(BIO_f_buffer());
+ BIO_push(fbio, sbio);
/* wait for multi-line response to end from FTP */
do
{
- mbuf_len = BIO_read(sbio,mbuf,BUFSIZZ);
+ mbuf_len = BIO_gets(fbio,mbuf,BUFSIZZ);
}
while (mbuf_len>3 && mbuf[3]=='-');
+ BIO_flush(fbio);
+ BIO_pop(fbio);
+ BIO_free(fbio);
BIO_printf(sbio,"AUTH TLS\r\n");
BIO_read(sbio,sbuf,BUFSIZZ);
}