Add Postgres support to -starttls
authorValentin Vidic <Valentin.Vidic@CARNet.hr>
Mon, 15 Feb 2016 14:28:41 +0000 (15:28 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 17 Oct 2016 22:05:36 +0000 (23:05 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
apps/s_client.c
doc/apps/s_client.pod

index 0442aecf96e243b1e58d865db3ff6a63daae6a7c..c2a00f539d04a3cf2c2cdec1b6224ee25761470c 100644 (file)
@@ -739,7 +739,8 @@ typedef enum PROTOCOL_choice {
     PROTO_XMPP,
     PROTO_XMPP_SERVER,
     PROTO_CONNECT,
-    PROTO_IRC
+    PROTO_IRC,
+    PROTO_POSTGRES
 } PROTOCOL_CHOICE;
 
 static const OPT_PAIR services[] = {
@@ -751,6 +752,7 @@ static const OPT_PAIR services[] = {
     {"xmpp-server", PROTO_XMPP_SERVER},
     {"telnet", PROTO_TELNET},
     {"irc", PROTO_IRC},
+    {"postgres", PROTO_POSTGRES},
     {NULL, 0}
 };
 
@@ -2084,6 +2086,25 @@ int s_client_main(int argc, char **argv)
                 goto shut;
             }
         }
+        break;
+    case PROTO_POSTGRES:
+        {
+            static const unsigned char ssl_request[] = {
+                /* Length        SSLRequest */
+                   0, 0, 0, 8,   4, 210, 22, 47
+            };
+            int bytes;
+
+            /* Send SSLRequest packet */
+            BIO_write(sbio, ssl_request, 8);
+            (void)BIO_flush(sbio);
+
+            /* Reply will be a single S if SSL is enabled */
+            bytes = BIO_read(sbio, sbuf, BUFSIZZ);
+            if (bytes != 1 || sbuf[0] != 'S')
+                goto shut;
+        }
+        break;
     }
 
     for (;;) {
index 7ad981111890f30902eb27ba863fdeb8bdc18e93..4a2a28021c52cd78737faf051f691c72aebd0f13 100644 (file)
@@ -420,7 +420,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", "ftp", "xmpp", "xmpp-server",
-and "irc."
+"irc" and "postgres."
 
 =item B<-xmpphost hostname>