s_client.pod 11 KB

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