s_client.pod 10 KB

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