ossl-guide-tls-introduction.7ossl 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "OSSL-GUIDE-TLS-INTRODUCTION 7ossl"
  136. .TH OSSL-GUIDE-TLS-INTRODUCTION 7ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. ossl\-guide\-tls\-introduction
  143. \&\- OpenSSL Guide: An introduction to SSL/TLS in OpenSSL
  144. .SH "INTRODUCTION"
  145. .IX Header "INTRODUCTION"
  146. This page will provide an introduction to some basic \s-1SSL/TLS\s0 concepts and
  147. background and how it is used within OpenSSL. It assumes that you have a basic
  148. understanding of \s-1TCP/IP\s0 and sockets.
  149. .SH "WHAT IS TLS?"
  150. .IX Header "WHAT IS TLS?"
  151. \&\s-1TLS\s0 stands for Transport Layer Security. \s-1TLS\s0 allows applications to securely
  152. communicate with each other across a network such that the confidentiality of
  153. the information exchanged is protected (i.e. it prevents eavesdroppers from
  154. listening in to the communication). Additionally it protects the integrity of
  155. the information exchanged to prevent an attacker from changing it. Finally it
  156. provides authentication so that one or both parties can be sure that they are
  157. talking to who they think they are talking to and not some imposter.
  158. .PP
  159. Sometimes \s-1TLS\s0 is referred to by its predecessor's name \s-1SSL\s0 (Secure Sockets
  160. Layer). OpenSSL dates from a time when the \s-1SSL\s0 name was still in common use and
  161. hence many of the functions and names used by OpenSSL contain the \*(L"\s-1SSL\*(R"\s0
  162. abbreviation. Nonetheless OpenSSL contains a fully fledged \s-1TLS\s0 implementation.
  163. .PP
  164. \&\s-1TLS\s0 is based on a client/server model. The application that initiates a
  165. communication is known as the client. The application that responds to a
  166. remotely initiated communication is the server. The term \*(L"endpoint\*(R" refers to
  167. either of the client or the server in a communication. The term \*(L"peer\*(R" refers to
  168. the endpoint at the other side of the communication that we are currently
  169. referring to. So if we are currently talking about the client then the peer
  170. would be the server.
  171. .PP
  172. \&\s-1TLS\s0 is a standardised protocol and there are numerous different implementations
  173. of it. Due to the standards an OpenSSL client or server is able to communicate
  174. seamlessly with an application using some different implementation of \s-1TLS. TLS\s0
  175. (and its predecessor \s-1SSL\s0) have been around for a significant period of time and
  176. the protocol has undergone various changes over the years. Consequently there
  177. are different versions of the protocol available. \s-1TLS\s0 includes the ability to
  178. perform version negotiation so that the highest protocol version that the client
  179. and server share in common is used.
  180. .PP
  181. \&\s-1TLS\s0 acts as a security layer over some lower level transport protocol. Typically
  182. the transport layer will be \s-1TCP.\s0
  183. .SH "SSL AND TLS VERSIONS"
  184. .IX Header "SSL AND TLS VERSIONS"
  185. \&\s-1SSL\s0 was initially developed by Netscape Communications and its first publicly
  186. released version was SSLv2 in 1995. Note that SSLv1 was never publicly released.
  187. SSLv3 came along quickly afterwards in 1996. Subsequently development of the
  188. protocol moved to the \s-1IETF\s0 which released the first version of \s-1TLS\s0 (TLSv1.0) in
  189. 1999 as \s-1RFC2246.\s0 TLSv1.1 was released in 2006 as \s-1RFC4346\s0 and TLSv1.2 came along
  190. in 2008 as \s-1RFC5246.\s0 The most recent version of the standard is TLSv1.3 which
  191. was released in 2018 as \s-1RFC8446.\s0
  192. .PP
  193. Today TLSv1.3 and TLSv1.2 are the most commonly deployed versions of the
  194. protocol. The \s-1IETF\s0 have formally deprecated TLSv1.1 and TLSv1.0, so anything
  195. below TLSv1.2 should be avoided since the older protocol versions are
  196. susceptible to security problems.
  197. .PP
  198. OpenSSL does not support SSLv2 (it was removed in OpenSSL 1.1.0). Support for
  199. SSLv3 is available as a compile time option \- but it is not built by default.
  200. Support for TLSv1.0, TLSv1.1, TLSv1.2 and TLSv1.3 are all available by default
  201. in a standard build of OpenSSL. However special run-time configuration is
  202. required in order to make TLSv1.0 and TLSv1.1 work successfully.
  203. .PP
  204. OpenSSL will always try to negotiate the highest protocol version that it has
  205. been configured to support. In most cases this will mean either TLSv1.3 or
  206. TLSv1.2 is chosen.
  207. .SH "CERTIFICATES"
  208. .IX Header "CERTIFICATES"
  209. In order for a client to establish a connection to a server it must authenticate
  210. the identify of that server, i.e. it needs to confirm that the server is really
  211. the server that it claims to be and not some imposter. In order to do this the
  212. server will send to the client a digital certificate (also commonly referred to
  213. as an X.509 certificate). The certificate contains various information about the
  214. server including its full \s-1DNS\s0 hostname. Also within the certificate is the
  215. server's public key. The server operator will have a private key which is
  216. linked to the public key and must not be published.
  217. .PP
  218. Along with the certificate the server will also send to the client proof that it
  219. knows the private key associated with the public key in the certificate. It does
  220. this by digitally signing a message to the client using that private key. The
  221. client can verify the signature using the public key from the certificate. If
  222. the signature verifies successfully then the client knows that the server is in
  223. possession of the correct private key.
  224. .PP
  225. The certificate that the server sends will also be signed by a Certificate
  226. Authority. The Certificate Authority (commonly known as a \s-1CA\s0) is a third party
  227. organisation that is responsible for verifying the information in the server's
  228. certificate (including its \s-1DNS\s0 hostname). The \s-1CA\s0 should only sign the
  229. certificate if it has been able to confirm that the server operator does indeed
  230. have control of the server associated with its \s-1DNS\s0 hostname and that the server
  231. operator has control of the private key.
  232. .PP
  233. In this way, if the client trusts the \s-1CA\s0 that has signed the server's
  234. certificate and it can verify that the server has the right private key then it
  235. can trust that the server truly does represent the \s-1DNS\s0 hostname given in the
  236. certificate. The client must also verify that the hostname given in the
  237. certificate matches the hostname that it originally sent the request to.
  238. .PP
  239. Once all of these checks have been done the client has successfully verified the
  240. identify of the server. OpenSSL can perform all of these checks automatically
  241. but it must be provided with certain information in order to do so, i.e. the set
  242. of CAs that the client trusts as well as the \s-1DNS\s0 hostname for the server that
  243. this client is trying to connect to.
  244. .PP
  245. Note that it is common for certificates to be built up into a chain. For example
  246. a server's certificate may be signed by a key owned by a an intermediate \s-1CA.\s0
  247. That intermediate \s-1CA\s0 also has a certificate containing its public key which is
  248. in turn signed by a key owned by a root \s-1CA.\s0 The client may only trust the root
  249. \&\s-1CA,\s0 but if the server sends both its own certificate and the certificate for the
  250. intermediate \s-1CA\s0 then the client can still successfully verify the identity of
  251. the server. There is a chain of trust between the root \s-1CA\s0 and the server.
  252. .PP
  253. By default it is only the client that authenticates the server using this
  254. method. However it is also possible to set things up such that the server
  255. additionally authenticates the client. This is known as \*(L"client authentication\*(R".
  256. In this approach the client will still authenticate the server in the same way,
  257. but the server will request a certificate from the client. The client sends the
  258. server its certificate and the server authenticates it in the same way that the
  259. client does.
  260. .SH "TRUSTED CERTIFICATE STORE"
  261. .IX Header "TRUSTED CERTIFICATE STORE"
  262. The system described above only works if a chain of trust can be built between
  263. the set of CAs that the endpoint trusts and the certificate that the peer is
  264. using. The endpoint must therefore have a set of certificates for CAs that it
  265. trusts before any communication can take place. OpenSSL itself does not provide
  266. such a set of certificates. Therefore you will need to make sure you have them
  267. before you start if you are going to be verifying certificates (i.e. always if
  268. the endpoint is a client, and only if client authentication is in use for a
  269. server).
  270. .PP
  271. Fortunately other organisations do maintain such a set of certificates. If you
  272. have obtained your copy of OpenSSL from an Operating System (\s-1OS\s0) vendor (e.g. a
  273. Linux distribution) then normally the set of \s-1CA\s0 certificates will also be
  274. distributed with that copy.
  275. .PP
  276. You can check this by running the OpenSSL command line application like this:
  277. .PP
  278. .Vb 1
  279. \& openssl version \-d
  280. .Ve
  281. .PP
  282. This will display a value for \fB\s-1OPENSSLDIR\s0\fR. Look in the \fBcerts\fR sub directory
  283. of \fB\s-1OPENSSLDIR\s0\fR and check its contents. For example if \fB\s-1OPENSSLDIR\s0\fR is
  284. \&\*(L"/usr/local/ssl\*(R", then check the contents of the \*(L"/usr/local/ssl/certs\*(R"
  285. directory.
  286. .PP
  287. You are expecting to see a list of files, typically with the suffix \*(L".pem\*(R" or
  288. \&\*(L".0\*(R". If they exist then you already have a suitable trusted certificate store.
  289. .PP
  290. If you are running your version of OpenSSL on Windows then OpenSSL (from version
  291. 3.2 onwards) will use the default Windows set of trusted CAs.
  292. .PP
  293. If you have built your version of OpenSSL from source, or obtained it from some
  294. other location and it does not have a set of trusted \s-1CA\s0 certificates then you
  295. will have to obtain them yourself. One such source is the Curl project. See the
  296. page <https://curl.se/docs/caextract.html> where you can download trusted
  297. certificates in a single file. Rename the file to \*(L"cert.pem\*(R" and store it
  298. directly in \fB\s-1OPENSSLDIR\s0\fR. For example if \fB\s-1OPENSSLDIR\s0\fR is \*(L"/usr/local/ssl\*(R",
  299. then save it as \*(L"/usr/local/ssl/cert.pem\*(R".
  300. .PP
  301. You can also use environment variables to override the default location that
  302. OpenSSL will look for its trusted certificate store. Set the \fB\s-1SSL_CERT_PATH\s0\fR
  303. environment variable to give the directory where OpenSSL should looks for its
  304. certificates or the \fB\s-1SSL_CERT_FILE\s0\fR environment variable to give the name of
  305. a single file containing all of the certificates. See \fBopenssl\-env\fR\|(7) for
  306. further details about OpenSSL environment variables. For example you could use
  307. this capability to have multiple versions of OpenSSL all installed on the same
  308. system using different values for \fB\s-1OPENSSLDIR\s0\fR but all using the same
  309. trusted certificate store.
  310. .PP
  311. You can test that your trusted certificate store is setup correctly by using it
  312. via the OpenSSL command line. Use the following command to connect to a \s-1TLS\s0
  313. server:
  314. .PP
  315. .Vb 1
  316. \& openssl s_client www.openssl.org:443
  317. .Ve
  318. .PP
  319. Once the command has connected type the letter \*(L"Q\*(R" followed by \*(L"<enter>\*(R" to exit
  320. the session. This will print a lot of information on the screen about the
  321. connection. Look for a block of text like this:
  322. .PP
  323. .Vb 2
  324. \& SSL handshake has read 4584 bytes and written 403 bytes
  325. \& Verification: OK
  326. .Ve
  327. .PP
  328. Hopefully if everything has worked then the \*(L"Verification\*(R" line will say \*(L"\s-1OK\*(R".\s0
  329. If its not working as expected then you might see output like this instead:
  330. .PP
  331. .Vb 2
  332. \& SSL handshake has read 4584 bytes and written 403 bytes
  333. \& Verification error: unable to get local issuer certificate
  334. .Ve
  335. .PP
  336. The \*(L"unable to get local issuer certificate\*(R" error means that OpenSSL has been
  337. unable to find a trusted \s-1CA\s0 for the chain of certificates provided by the server
  338. in its trusted certificate store. Check your trusted certificate store
  339. configuration again.
  340. .PP
  341. Note that s_client is a testing tool and will still allow you to connect to the
  342. \&\s-1TLS\s0 server regardless of the verification error. Most applications should not do
  343. this and should abort the connection in the event of a verification error.
  344. .SH "IMPORTANT OBJECTS FOR AN OPENSSL TLS APPLICATION"
  345. .IX Header "IMPORTANT OBJECTS FOR AN OPENSSL TLS APPLICATION"
  346. A \s-1TLS\s0 connection is represented by the \fB\s-1SSL\s0\fR object in an OpenSSL based
  347. application. Once a connection with a remote peer has been established an
  348. endpoint can \*(L"write\*(R" data to the \fB\s-1SSL\s0\fR object to send data to the peer, or
  349. \&\*(L"read\*(R" data from it to receive data from the server.
  350. .PP
  351. A new \fB\s-1SSL\s0\fR object is created from an \fB\s-1SSL_CTX\s0\fR object. Think of an \fB\s-1SSL_CTX\s0\fR
  352. as a \*(L"factory\*(R" for creating \fB\s-1SSL\s0\fR objects. You can create a single \fB\s-1SSL_CTX\s0\fR
  353. object and then create multiple connections (i.e. \fB\s-1SSL\s0\fR objects) from it.
  354. Typically you can set up common configuration options on the \fB\s-1SSL_CTX\s0\fR so that
  355. all the \fB\s-1SSL\s0\fR object created from it inherit the same configuration options.
  356. .PP
  357. Note that internally to OpenSSL various items that are shared between multiple
  358. \&\fB\s-1SSL\s0\fR objects are cached in the \fB\s-1SSL_CTX\s0\fR for performance reasons. Therefore
  359. it is considered best practice to create one \fB\s-1SSL_CTX\s0\fR for use by multiple
  360. \&\fB\s-1SSL\s0\fR objects instead of having one \fB\s-1SSL_CTX\s0\fR for each \fB\s-1SSL\s0\fR object that you
  361. create.
  362. .PP
  363. Each \fB\s-1SSL\s0\fR object is also associated with two \fB\s-1BIO\s0\fR objects. A \fB\s-1BIO\s0\fR object
  364. is used for sending or receiving data from the underlying transport layer. For
  365. example you might create a \fB\s-1BIO\s0\fR to represent a \s-1TCP\s0 socket. The \fB\s-1SSL\s0\fR object
  366. uses one \fB\s-1BIO\s0\fR for reading data and one \fB\s-1BIO\s0\fR for writing data. In most cases
  367. you would use the same \fB\s-1BIO\s0\fR for each direction but there could be some
  368. circumstances where you want them to be different.
  369. .PP
  370. It is up to the application programmer to create the \fB\s-1BIO\s0\fR objects that are
  371. needed and supply them to the \fB\s-1SSL\s0\fR object. See
  372. \&\fBossl\-guide\-tls\-client\-block\fR\|(7) for further information.
  373. .PP
  374. Finally, an endpoint can establish a \*(L"session\*(R" with its peer. The session holds
  375. various \s-1TLS\s0 parameters about the connection between the client and the server.
  376. The session details can then be reused in a subsequent connection attempt to
  377. speed up the process of connecting. This is known as \*(L"resumption\*(R". Sessions are
  378. represented in OpenSSL by the \fB\s-1SSL_SESSION\s0\fR object. In TLSv1.2 there is always
  379. exactly one session per connection. In TLSv1.3 there can be any number per
  380. connection including none.
  381. .SH "PHASES OF A TLS CONNECTION"
  382. .IX Header "PHASES OF A TLS CONNECTION"
  383. A \s-1TLS\s0 connection starts with an initial \*(L"set up\*(R" phase. The endpoint creates the
  384. \&\fB\s-1SSL_CTX\s0\fR (if one has not already been created) and configures it.
  385. .PP
  386. A client then creates an \fB\s-1SSL\s0\fR object to represent the new \s-1TLS\s0 connection. Any
  387. connection specific configuration parameters are then applied and the underlying
  388. socket is created and associated with the \fB\s-1SSL\s0\fR via \fB\s-1BIO\s0\fR objects.
  389. .PP
  390. A server will create a socket for listening for incoming connection attempts
  391. from clients. Once a connection attempt is made the server will create an \fB\s-1SSL\s0\fR
  392. object in the same way as for a client and associate it with a \fB\s-1BIO\s0\fR for the
  393. newly created incoming socket.
  394. .PP
  395. After set up is complete the \s-1TLS\s0 \*(L"handshake\*(R" phase begins. A \s-1TLS\s0 handshake
  396. consists of the client and server exchanging a series of \s-1TLS\s0 handshake messages
  397. to establish the connection. The client starts by sending a \*(L"ClientHello\*(R"
  398. handshake message and the server responds with a \*(L"ServerHello\*(R". The handshake is
  399. complete once an endpoint has sent its last message (known as the \*(L"Finished\*(R"
  400. message) and received a Finished message from its peer. Note that this might
  401. occur at slightly different times for each peer. For example in TLSv1.3 the
  402. server always sends its Finished message before the client. The client later
  403. responds with its Finished message. At this point the client has completed the
  404. handshake because it has both sent and received a Finished message. The server
  405. has sent its Finished message but the Finished message from the client may still
  406. be in-flight, so the server is still in the handshake phase. It is even possible
  407. that the server will fail to complete the handshake (if it considers there is
  408. some problem with the messages sent from the client), even though the client may
  409. have already progressed to sending application data. In TLSv1.2 this can happen
  410. the other way around, i.e. the server finishes first and the client finishes
  411. second.
  412. .PP
  413. Once the handshake is complete the application data transfer phase begins.
  414. Strictly speaking there are some situations where the client can start sending
  415. application data even earlier (using the TLSv1.3 \*(L"early data\*(R" capability) \- but
  416. we're going to skip over that for this basic introduction.
  417. .PP
  418. During application data transfer the client and server can read and write data
  419. to the connection freely. The details of this are typically left to some higher
  420. level application protocol (for example \s-1HTTP\s0). Not all information exchanged
  421. during this phase is application data. Some protocol level messages may still
  422. be exchanged \- so it is not necessarily the case that, just because the
  423. underlying socket is \*(L"readable\*(R", that application data will be available to read.
  424. .PP
  425. When the connection is no longer required then it should be shutdown. A shutdown
  426. may be initiated by either the client or the server via a message known as a
  427. \&\*(L"close_notify\*(R" alert. The client or server that receives a close_notify may
  428. respond with one and then the connection is fully closed and application data
  429. can no longer be sent or received.
  430. .PP
  431. Once shutdown is complete a \s-1TLS\s0 application must clean up by freeing the \s-1SSL\s0
  432. object.
  433. .SH "FURTHER READING"
  434. .IX Header "FURTHER READING"
  435. See \fBossl\-guide\-tls\-client\-block\fR\|(7) to see an example of applying these
  436. concepts in order to write a simple \s-1TLS\s0 client based on a blocking socket.
  437. See \fBossl\-guide\-quic\-introduction\fR\|(7) for an introduction to \s-1QUIC\s0 in OpenSSL.
  438. .SH "SEE ALSO"
  439. .IX Header "SEE ALSO"
  440. \&\fBossl\-guide\-introduction\fR\|(7), \fBossl\-guide\-libraries\-introduction\fR\|(7),
  441. \&\fBossl\-guide\-libssl\-introduction\fR\|(7), \fBossl\-guide\-tls\-client\-block\fR\|(7),
  442. \&\fBossl\-guide\-quic\-introduction\fR\|(7)
  443. .SH "COPYRIGHT"
  444. .IX Header "COPYRIGHT"
  445. Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
  446. .PP
  447. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  448. this file except in compliance with the License. You can obtain a copy
  449. in the file \s-1LICENSE\s0 in the source distribution or at
  450. <https://www.openssl.org/source/license.html>.