Skip to content

Commit 6191e6b

Browse files
committed
Add Postgres support to s_client -starttls
Minor adaptation from openssl#683 - original author Valentin Vidic
1 parent 1cf8ef4 commit 6191e6b

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

apps/s_client.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static void sc_usage(void)
400400
" 'prot' defines which one to assume. Currently,\n");
401401
BIO_printf(bio_err,
402402
" only \"smtp\", \"pop3\", \"imap\", \"ftp\", \"xmpp\"\n");
403-
BIO_printf(bio_err, " \"telnet\" and \"ldap\" are supported.\n");
403+
BIO_printf(bio_err, " \"telnet\", \"ldap\" and \"postgres\" are supported.\n");
404404
BIO_printf(bio_err, " are supported.\n");
405405
BIO_printf(bio_err," -xmpphost host - When used with \"-starttls xmpp\" specifies the virtual host.\n");
406406
#ifndef OPENSSL_NO_ENGINE
@@ -657,8 +657,9 @@ enum {
657657
PROTO_IMAP,
658658
PROTO_FTP,
659659
PROTO_XMPP,
660-
PROTO_TELNET,
661-
PROTO_LDAP
660+
PROTO_TELNET,
661+
PROTO_LDAP,
662+
PROTO_POSTGRES
662663
};
663664

664665
int MAIN(int, char **);
@@ -1105,6 +1106,8 @@ int MAIN(int argc, char **argv)
11051106
starttls_proto = PROTO_TELNET;
11061107
else if (strcmp(*argv, "ldap") == 0)
11071108
starttls_proto = PROTO_LDAP;
1109+
else if (strcmp(*argv, "postgres") == 0)
1110+
starttls_proto = PROTO_POSTGRES;
11081111
else
11091112
goto bad;
11101113
}
@@ -1790,6 +1793,23 @@ int MAIN(int argc, char **argv)
17901793
ASN1_TYPE_free(atyp);
17911794
}
17921795

1796+
if (starttls_proto == PROTO_POSTGRES) {
1797+
static const unsigned char ssl_request[] = {
1798+
/* Length SSLRequest */
1799+
0, 0, 0, 8, 4, 210, 22, 47
1800+
};
1801+
int bytes;
1802+
1803+
/* Send SSLRequest packet */
1804+
BIO_write(sbio, ssl_request, 8);
1805+
(void)BIO_flush(sbio);
1806+
1807+
/* Reply will be a single S if SSL is enabled */
1808+
bytes = BIO_read(sbio, sbuf, BUFSIZZ);
1809+
if (bytes != 1 || sbuf[0] != 'S')
1810+
goto shut;
1811+
}
1812+
17931813
for (;;) {
17941814
FD_ZERO(&readfds);
17951815
FD_ZERO(&writefds);
@@ -2179,6 +2199,7 @@ int MAIN(int argc, char **argv)
21792199
write_ssl = 1;
21802200
read_tty = 0;
21812201
}
2202+
break;
21822203
}
21832204

21842205
ret = 0;

0 commit comments

Comments
 (0)