2
0

s_client.pod 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. =pod
  2. =head1 NAME
  3. s_client - SSL/TLS client program
  4. =head1 SYNOPSIS
  5. B<openssl> B<s_client>
  6. [B<-connect host:port>]
  7. [B<-servername name>]
  8. [B<-verify depth>]
  9. [B<-verify_return_error>]
  10. [B<-cert filename>]
  11. [B<-certform DER|PEM>]
  12. [B<-key filename>]
  13. [B<-keyform DER|PEM>]
  14. [B<-pass arg>]
  15. [B<-CApath directory>]
  16. [B<-CAfile filename>]
  17. [B<-no_alt_chains>]
  18. [B<-reconnect>]
  19. [B<-pause>]
  20. [B<-showcerts>]
  21. [B<-debug>]
  22. [B<-msg>]
  23. [B<-nbio_test>]
  24. [B<-state>]
  25. [B<-nbio>]
  26. [B<-crlf>]
  27. [B<-ign_eof>]
  28. [B<-no_ign_eof>]
  29. [B<-quiet>]
  30. [B<-ssl2>]
  31. [B<-ssl3>]
  32. [B<-tls1>]
  33. [B<-no_ssl2>]
  34. [B<-no_ssl3>]
  35. [B<-no_tls1>]
  36. [B<-no_tls1_1>]
  37. [B<-no_tls1_2>]
  38. [B<-fallback_scsv>]
  39. [B<-bugs>]
  40. [B<-sigalgs sigalglist>]
  41. [B<-curves curvelist>]
  42. [B<-cipher cipherlist>]
  43. [B<-serverpref>]
  44. [B<-starttls protocol>]
  45. [B<-engine id>]
  46. [B<-tlsextdebug>]
  47. [B<-no_ticket>]
  48. [B<-sess_out filename>]
  49. [B<-sess_in filename>]
  50. [B<-rand file(s)>]
  51. [B<-serverinfo types>]
  52. [B<-status>]
  53. [B<-alpn protocols>]
  54. [B<-nextprotoneg protocols>]
  55. =head1 DESCRIPTION
  56. The B<s_client> command implements a generic SSL/TLS client which connects
  57. to a remote host using SSL/TLS. It is a I<very> useful diagnostic tool for
  58. SSL servers.
  59. =head1 OPTIONS
  60. =over 4
  61. =item B<-connect host:port>
  62. This specifies the host and optional port to connect to. If not specified
  63. then an attempt is made to connect to the local host on port 4433.
  64. =item B<-servername name>
  65. Set the TLS SNI (Server Name Indication) extension in the ClientHello message.
  66. =item B<-cert certname>
  67. The certificate to use, if one is requested by the server. The default is
  68. not to use a certificate.
  69. =item B<-certform format>
  70. The certificate format to use: DER or PEM. PEM is the default.
  71. =item B<-key keyfile>
  72. The private key to use. If not specified then the certificate file will
  73. be used.
  74. =item B<-keyform format>
  75. The private format to use: DER or PEM. PEM is the default.
  76. =item B<-pass arg>
  77. the private key password source. For more information about the format of B<arg>
  78. see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
  79. =item B<-verify depth>
  80. The verify depth to use. This specifies the maximum length of the
  81. server certificate chain and turns on server certificate verification.
  82. Currently the verify operation continues after errors so all the problems
  83. with a certificate chain can be seen. As a side effect the connection
  84. will never fail due to a server certificate verify failure.
  85. =item B<-verify_return_error>
  86. Return verification errors instead of continuing. This will typically
  87. abort the handshake with a fatal error.
  88. =item B<-CApath directory>
  89. The directory to use for server certificate verification. This directory
  90. must be in "hash format", see B<verify> for more information. These are
  91. also used when building the client certificate chain.
  92. =item B<-CAfile file>
  93. A file containing trusted certificates to use during server authentication
  94. and to use when attempting to build the client certificate chain.
  95. =item B<-purpose, -ignore_critical, -issuer_checks, -crl_check, -crl_check_all, -policy_check, -extended_crl, -x509_strict, -policy -check_ss_sig -no_alt_chains>
  96. Set various certificate chain valiadition option. See the
  97. L<B<verify>|verify(1)> manual page for details.
  98. =item B<-reconnect>
  99. reconnects to the same server 5 times using the same session ID, this can
  100. be used as a test that session caching is working.
  101. =item B<-pause>
  102. pauses 1 second between each read and write call.
  103. =item B<-showcerts>
  104. display the whole server certificate chain: normally only the server
  105. certificate itself is displayed.
  106. =item B<-prexit>
  107. print session information when the program exits. This will always attempt
  108. to print out information even if the connection fails. Normally information
  109. will only be printed out once if the connection succeeds. This option is useful
  110. because the cipher in use may be renegotiated or the connection may fail
  111. because a client certificate is required or is requested only after an
  112. attempt is made to access a certain URL. Note: the output produced by this
  113. option is not always accurate because a connection might never have been
  114. established.
  115. =item B<-state>
  116. prints out the SSL session states.
  117. =item B<-debug>
  118. print extensive debugging information including a hex dump of all traffic.
  119. =item B<-msg>
  120. show all protocol messages with hex dump.
  121. =item B<-nbio_test>
  122. tests non-blocking I/O
  123. =item B<-nbio>
  124. turns on non-blocking I/O
  125. =item B<-crlf>
  126. this option translated a line feed from the terminal into CR+LF as required
  127. by some servers.
  128. =item B<-ign_eof>
  129. inhibit shutting down the connection when end of file is reached in the
  130. input.
  131. =item B<-quiet>
  132. inhibit printing of session and certificate information. This implicitly
  133. turns on B<-ign_eof> as well.
  134. =item B<-no_ign_eof>
  135. shut down the connection when end of file is reached in the input.
  136. Can be used to override the implicit B<-ign_eof> after B<-quiet>.
  137. =item B<-psk_identity identity>
  138. Use the PSK identity B<identity> when using a PSK cipher suite.
  139. The default value is "Client_identity" (without the quotes).
  140. =item B<-psk key>
  141. Use the PSK key B<key> when using a PSK cipher suite. The key is
  142. given as a hexadecimal number without leading 0x, for example -psk
  143. 1a2b3c4d.
  144. This option must be provided in order to use a PSK cipher.
  145. =item B<-ssl2>, B<-ssl3>, B<-tls1>, B<-tls1_1>, B<-tls1_2>, B<-no_ssl2>, B<-no_ssl3>, B<-no_tls1>, B<-no_tls1_1>, B<-no_tls1_2>
  146. These options require or disable the use of the specified SSL or TLS protocols.
  147. By default the initial handshake uses a I<version-flexible> method which will
  148. negotiate the highest mutually supported protocol version.
  149. =item B<-fallback_scsv>
  150. Send TLS_FALLBACK_SCSV in the ClientHello.
  151. =item B<-bugs>
  152. there are several known bug in SSL and TLS implementations. Adding this
  153. option enables various workarounds.
  154. =item B<-sigalgs sigalglist>
  155. Specifies the list of signature algorithms that are sent by the client.
  156. The server selects one entry in the list based on its preferences.
  157. For example strings, see L<SSL_CTX_set1_sigalgs(3)>
  158. =item B<-curves curvelist>
  159. Specifies the list of supported curves to be sent by the client. The curve is
  160. is ultimately selected by the server. For a list of all curves, use:
  161. $ openssl ecparam -list_curves
  162. =item B<-cipher cipherlist>
  163. this allows the cipher list sent by the client to be modified. Although
  164. the server determines which cipher suite is used it should take the first
  165. supported cipher in the list sent by the client. See the B<ciphers>
  166. command for more information.
  167. =item B<-serverpref>
  168. use the server's cipher preferences; only used for SSLV2.
  169. =item B<-starttls protocol>
  170. send the protocol-specific message(s) to switch to TLS for communication.
  171. B<protocol> is a keyword for the intended protocol. Currently, the only
  172. supported keywords are "smtp", "pop3", "imap", and "ftp".
  173. =item B<-tlsextdebug>
  174. print out a hex dump of any TLS extensions received from the server.
  175. =item B<-no_ticket>
  176. disable RFC4507bis session ticket support.
  177. =item B<-sess_out filename>
  178. output SSL session to B<filename>
  179. =item B<-sess_in sess.pem>
  180. load SSL session from B<filename>. The client will attempt to resume a
  181. connection from this session.
  182. =item B<-engine id>
  183. specifying an engine (by its unique B<id> string) will cause B<s_client>
  184. to attempt to obtain a functional reference to the specified engine,
  185. thus initialising it if needed. The engine will then be set as the default
  186. for all available algorithms.
  187. =item B<-rand file(s)>
  188. a file or files containing random data used to seed the random number
  189. generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
  190. Multiple files can be specified separated by a OS-dependent character.
  191. The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
  192. all others.
  193. =item B<-serverinfo types>
  194. a list of comma-separated TLS Extension Types (numbers between 0 and
  195. 65535). Each type will be sent as an empty ClientHello TLS Extension.
  196. The server's response (if any) will be encoded and displayed as a PEM
  197. file.
  198. =item B<-status>
  199. sends a certificate status request to the server (OCSP stapling). The server
  200. response (if any) is printed out.
  201. =item B<-alpn protocols>, B<-nextprotoneg protocols>
  202. these flags enable the
  203. Enable the Application-Layer Protocol Negotiation or Next Protocol
  204. Negotiation extension, respectively. ALPN is the IETF standard and
  205. replaces NPN.
  206. The B<protocols> list is a
  207. comma-separated protocol names that the client should advertise
  208. support for. The list should contain most wanted protocols first.
  209. Protocol names are printable ASCII strings, for example "http/1.1" or
  210. "spdy/3".
  211. Empty list of protocols is treated specially and will cause the client to
  212. advertise support for the TLS extension but disconnect just after
  213. reciving ServerHello with a list of server supported protocols.
  214. =back
  215. =head1 CONNECTED COMMANDS
  216. If a connection is established with an SSL server then any data received
  217. from the server is displayed and any key presses will be sent to the
  218. server. When used interactively (which means neither B<-quiet> nor B<-ign_eof>
  219. have been given), the session will be renegotiated if the line begins with an
  220. B<R>, and if the line begins with a B<Q> or if end of file is reached, the
  221. connection will be closed down.
  222. =head1 NOTES
  223. B<s_client> can be used to debug SSL servers. To connect to an SSL HTTP
  224. server the command:
  225. openssl s_client -connect servername:443
  226. would typically be used (https uses port 443). If the connection succeeds
  227. then an HTTP command can be given such as "GET /" to retrieve a web page.
  228. If the handshake fails then there are several possible causes, if it is
  229. nothing obvious like no client certificate then the B<-bugs>, B<-ssl2>,
  230. B<-ssl3>, B<-tls1>, B<-no_ssl2>, B<-no_ssl3>, B<-no_tls1> options can be tried
  231. in case it is a buggy server. In particular you should play with these
  232. options B<before> submitting a bug report to an OpenSSL mailing list.
  233. A frequent problem when attempting to get client certificates working
  234. is that a web client complains it has no certificates or gives an empty
  235. list to choose from. This is normally because the server is not sending
  236. the clients certificate authority in its "acceptable CA list" when it
  237. requests a certificate. By using B<s_client> the CA list can be viewed
  238. and checked. However some servers only request client authentication
  239. after a specific URL is requested. To obtain the list in this case it
  240. is necessary to use the B<-prexit> option and send an HTTP request
  241. for an appropriate page.
  242. If a certificate is specified on the command line using the B<-cert>
  243. option it will not be used unless the server specifically requests
  244. a client certificate. Therefor merely including a client certificate
  245. on the command line is no guarantee that the certificate works.
  246. If there are problems verifying a server certificate then the
  247. B<-showcerts> option can be used to show the whole chain.
  248. Since the SSLv23 client hello cannot include compression methods or extensions
  249. these will only be supported if its use is disabled, for example by using the
  250. B<-no_sslv2> option.
  251. The B<s_client> utility is a test tool and is designed to continue the
  252. handshake after any certificate verification errors. As a result it will
  253. accept any certificate chain (trusted or not) sent by the peer. None test
  254. applications should B<not> do this as it makes them vulnerable to a MITM
  255. attack. This behaviour can be changed by with the B<-verify_return_error>
  256. option: any verify errors are then returned aborting the handshake.
  257. =head1 BUGS
  258. Because this program has a lot of options and also because some of
  259. the techniques used are rather old, the C source of s_client is rather
  260. hard to read and not a model of how things should be done. A typical
  261. SSL client program would be much simpler.
  262. The B<-prexit> option is a bit of a hack. We should really report
  263. information whenever a session is renegotiated.
  264. =head1 SEE ALSO
  265. L<sess_id(1)|sess_id(1)>, L<s_server(1)|s_server(1)>, L<ciphers(1)|ciphers(1)>
  266. =head1 HISTORY
  267. The -no_alt_chains options was first added to OpenSSL 1.0.2b.
  268. =cut