Add an "-xmpphost" option to s_client
authorCarlos Alberto Lopez Perez <clopez@igalia.com>
Mon, 6 Aug 2012 00:24:51 +0000 (02:24 +0200)
committerBen Laurie <ben@links.org>
Thu, 5 Sep 2013 16:24:56 +0000 (17:24 +0100)
 * Many XMPP servers are configured with multiple domains (virtual hosts)
 * In order to establish successfully the TLS connection you have to specify
   which virtual host you are trying to connect.
 * Test this, for example with ::
   * Fail:
       openssl s_client -connect talk.google.com:5222 -starttls xmpp
   * Works:
       openssl s_client -connect talk.google.com:5222 -starttls xmpp -xmpphost gmail.com

apps/s_client.c
doc/apps/s_client.pod

index 9c7f45f33c507f9827a3b71c04218330d43121b2..3089a97176935a81cf5d7181ffea3191e465cf67 100644 (file)
@@ -350,6 +350,7 @@ static void sc_usage(void)
        BIO_printf(bio_err,"                 'prot' defines which one to assume.  Currently,\n");
        BIO_printf(bio_err,"                 only \"smtp\", \"pop3\", \"imap\", \"ftp\" and \"xmpp\"\n");
        BIO_printf(bio_err,"                 are supported.\n");
        BIO_printf(bio_err,"                 'prot' defines which one to assume.  Currently,\n");
        BIO_printf(bio_err,"                 only \"smtp\", \"pop3\", \"imap\", \"ftp\" and \"xmpp\"\n");
        BIO_printf(bio_err,"                 are supported.\n");
+       BIO_printf(bio_err," -xmpphost host - When used with \"-starttls xmpp\" specifies the virtual host.\n");
 #ifndef OPENSSL_NO_ENGINE
        BIO_printf(bio_err," -engine id    - Initialise and use the specified engine\n");
 #endif
 #ifndef OPENSSL_NO_ENGINE
        BIO_printf(bio_err," -engine id    - Initialise and use the specified engine\n");
 #endif
@@ -595,6 +596,7 @@ int MAIN(int argc, char **argv)
        short port=PORT;
        int full_log=1;
        char *host=SSL_HOST_NAME;
        short port=PORT;
        int full_log=1;
        char *host=SSL_HOST_NAME;
+       char *xmpphost = NULL;
        char *cert_file=NULL,*key_file=NULL,*chain_file=NULL;
        int cert_format = FORMAT_PEM, key_format = FORMAT_PEM;
        char *passarg = NULL, *pass = NULL;
        char *cert_file=NULL,*key_file=NULL,*chain_file=NULL;
        int cert_format = FORMAT_PEM, key_format = FORMAT_PEM;
        char *passarg = NULL, *pass = NULL;
@@ -726,6 +728,11 @@ static char *jpake_secret = NULL;
                        if (!extract_host_port(*(++argv),&host,NULL,&port))
                                goto bad;
                        }
                        if (!extract_host_port(*(++argv),&host,NULL,&port))
                                goto bad;
                        }
+               else if (strcmp(*argv,"-xmpphost") == 0)
+                       {
+                       if (--argc < 1) goto bad;
+                       xmpphost= *(++argv);
+                       }
                else if (strcmp(*argv,"-verify") == 0)
                        {
                        verify=SSL_VERIFY_PEER;
                else if (strcmp(*argv,"-verify") == 0)
                        {
                        verify=SSL_VERIFY_PEER;
@@ -1670,7 +1677,7 @@ SSL_set_tlsext_status_ids(con, ids);
                int seen = 0;
                BIO_printf(sbio,"<stream:stream "
                    "xmlns:stream='http://etherx.jabber.org/streams' "
                int seen = 0;
                BIO_printf(sbio,"<stream:stream "
                    "xmlns:stream='http://etherx.jabber.org/streams' "
-                   "xmlns='jabber:client' to='%s' version='1.0'>", host);
+                   "xmlns='jabber:client' to='%s' version='1.0'>", xmpphost? xmpphost:host);
                seen = BIO_read(sbio,mbuf,BUFSIZZ);
                mbuf[seen] = 0;
                while (!strstr(mbuf, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'") &&
                seen = BIO_read(sbio,mbuf,BUFSIZZ);
                mbuf[seen] = 0;
                while (!strstr(mbuf, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'") &&
index 1c50836a8a76c00452fe5b1bc54f12b96b510adc..a37c4e2b7c294c9f739cfdd91ce687c5cadb61cd 100644 (file)
@@ -37,6 +37,7 @@ B<openssl> B<s_client>
 [B<-bugs>]
 [B<-cipher cipherlist>]
 [B<-starttls protocol>]
 [B<-bugs>]
 [B<-cipher cipherlist>]
 [B<-starttls protocol>]
+[B<-xmpphost hostname>]
 [B<-engine id>]
 [B<-tlsextdebug>]
 [B<-no_ticket>]
 [B<-engine id>]
 [B<-tlsextdebug>]
 [B<-no_ticket>]
@@ -225,6 +226,13 @@ 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", "ftp" and "xmpp".
 
 B<protocol> is a keyword for the intended protocol.  Currently, the only
 supported keywords are "smtp", "pop3", "imap", "ftp" and "xmpp".
 
+=item B<-xmpphost hostname>
+
+This option, when used with "-starttls xmpp", specifies the host for the
+"to" attribute of the stream element.
+If this option is not specified, then the host specified with "-connect"
+will be used.
+
 =item B<-tlsextdebug>
 
 print out a hex dump of any TLS extensions received from the server.
 =item B<-tlsextdebug>
 
 print out a hex dump of any TLS extensions received from the server.