methods.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /* ssl/t1_meth.c */
  2. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young (eay@cryptsoft.com).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young (eay@cryptsoft.com)"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. /* ====================================================================
  59. * Copyright (c) 1998-2015 The OpenSSL Project. All rights reserved.
  60. *
  61. * Redistribution and use in source and binary forms, with or without
  62. * modification, are permitted provided that the following conditions
  63. * are met:
  64. *
  65. * 1. Redistributions of source code must retain the above copyright
  66. * notice, this list of conditions and the following disclaimer.
  67. *
  68. * 2. Redistributions in binary form must reproduce the above copyright
  69. * notice, this list of conditions and the following disclaimer in
  70. * the documentation and/or other materials provided with the
  71. * distribution.
  72. *
  73. * 3. All advertising materials mentioning features or use of this
  74. * software must display the following acknowledgment:
  75. * "This product includes software developed by the OpenSSL Project
  76. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  77. *
  78. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  79. * endorse or promote products derived from this software without
  80. * prior written permission. For written permission, please contact
  81. * openssl-core@openssl.org.
  82. *
  83. * 5. Products derived from this software may not be called "OpenSSL"
  84. * nor may "OpenSSL" appear in their names without prior written
  85. * permission of the OpenSSL Project.
  86. *
  87. * 6. Redistributions of any form whatsoever must retain the following
  88. * acknowledgment:
  89. * "This product includes software developed by the OpenSSL Project
  90. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  91. *
  92. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  93. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  94. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  95. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  96. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  97. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  98. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  99. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  100. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  101. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  102. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  103. * OF THE POSSIBILITY OF SUCH DAMAGE.
  104. * ====================================================================
  105. *
  106. * This product includes cryptographic software written by Eric Young
  107. * (eay@cryptsoft.com). This product includes software written by Tim
  108. * Hudson (tjh@cryptsoft.com).
  109. *
  110. */
  111. #include <stdio.h>
  112. #include <openssl/objects.h>
  113. #include "ssl_locl.h"
  114. /*
  115. * TLS/SSLv3 methods
  116. */
  117. static const SSL_METHOD *tls1_get_method(int ver)
  118. {
  119. if (ver == TLS_ANY_VERSION)
  120. return TLS_method();
  121. #ifndef OPENSSL_NO_TLS1_2
  122. if (ver == TLS1_2_VERSION)
  123. return TLSv1_2_method();
  124. #endif
  125. #ifndef OPENSSL_NO_TLS1_1
  126. if (ver == TLS1_1_VERSION)
  127. return TLSv1_1_method();
  128. #endif
  129. #ifndef OPENSSL_NO_TLS1
  130. if (ver == TLS1_VERSION)
  131. return TLSv1_method();
  132. #endif
  133. #ifndef OPENSSL_NO_SSL3
  134. if (ver == SSL3_VERSION)
  135. return (SSLv3_method());
  136. else
  137. #endif
  138. return NULL;
  139. }
  140. IMPLEMENT_tls_meth_func(TLS_ANY_VERSION, 0, 0,
  141. TLS_method,
  142. ossl_statem_accept,
  143. ossl_statem_connect, tls1_get_method, TLSv1_2_enc_data)
  144. #ifndef OPENSSL_NO_TLS1_2_METHOD
  145. IMPLEMENT_tls_meth_func(TLS1_2_VERSION, 0, SSL_OP_NO_TLSv1_2,
  146. TLSv1_2_method,
  147. ossl_statem_accept,
  148. ossl_statem_connect, tls1_get_method, TLSv1_2_enc_data)
  149. #endif
  150. #ifndef OPENSSL_NO_TLS1_1_METHOD
  151. IMPLEMENT_tls_meth_func(TLS1_1_VERSION, SSL_METHOD_NO_SUITEB, SSL_OP_NO_TLSv1_1,
  152. TLSv1_1_method,
  153. ossl_statem_accept,
  154. ossl_statem_connect, tls1_get_method, TLSv1_1_enc_data)
  155. #endif
  156. #ifndef OPENSSL_NO_TLS1_METHOD
  157. IMPLEMENT_tls_meth_func(TLS1_VERSION, SSL_METHOD_NO_SUITEB, SSL_OP_NO_TLSv1,
  158. TLSv1_method,
  159. ossl_statem_accept,
  160. ossl_statem_connect, tls1_get_method, TLSv1_enc_data)
  161. #endif
  162. #ifndef OPENSSL_NO_SSL3_METHOD
  163. IMPLEMENT_ssl3_meth_func(SSLv3_method, ossl_statem_accept, ossl_statem_connect,
  164. tls1_get_method)
  165. #endif
  166. /*
  167. * TLS/SSLv3 server methods
  168. */
  169. static const SSL_METHOD *tls1_get_server_method(int ver)
  170. {
  171. if (ver == TLS_ANY_VERSION)
  172. return TLS_server_method();
  173. #ifndef OPENSSL_NO_TLS1_2
  174. if (ver == TLS1_2_VERSION)
  175. return TLSv1_2_server_method();
  176. #endif
  177. #ifndef OPENSSL_NO_TLS1_1
  178. if (ver == TLS1_1_VERSION)
  179. return TLSv1_1_server_method();
  180. #endif
  181. #ifndef OPENSSL_NO_TLS1
  182. if (ver == TLS1_VERSION)
  183. return TLSv1_server_method();
  184. #endif
  185. #ifndef OPENSSL_NO_SSL3
  186. if (ver == SSL3_VERSION)
  187. return (SSLv3_server_method());
  188. #endif
  189. return NULL;
  190. }
  191. IMPLEMENT_tls_meth_func(TLS_ANY_VERSION, 0, 0,
  192. TLS_server_method,
  193. ossl_statem_accept,
  194. ssl_undefined_function,
  195. tls1_get_server_method, TLSv1_2_enc_data)
  196. #ifndef OPENSSL_NO_TLS1_2_METHOD
  197. IMPLEMENT_tls_meth_func(TLS1_2_VERSION, 0, SSL_OP_NO_TLSv1_2,
  198. TLSv1_2_server_method,
  199. ossl_statem_accept,
  200. ssl_undefined_function,
  201. tls1_get_server_method, TLSv1_2_enc_data)
  202. #endif
  203. #ifndef OPENSSL_NO_TLS1_1_METHOD
  204. IMPLEMENT_tls_meth_func(TLS1_1_VERSION, SSL_METHOD_NO_SUITEB, SSL_OP_NO_TLSv1_1,
  205. TLSv1_1_server_method,
  206. ossl_statem_accept,
  207. ssl_undefined_function,
  208. tls1_get_server_method, TLSv1_1_enc_data)
  209. #endif
  210. #ifndef OPENSSL_NO_TLS1_METHOD
  211. IMPLEMENT_tls_meth_func(TLS1_VERSION, SSL_METHOD_NO_SUITEB, SSL_OP_NO_TLSv1,
  212. TLSv1_server_method,
  213. ossl_statem_accept,
  214. ssl_undefined_function,
  215. tls1_get_server_method, TLSv1_enc_data)
  216. #endif
  217. #ifndef OPENSSL_NO_SSL3_METHOD
  218. IMPLEMENT_ssl3_meth_func(SSLv3_server_method,
  219. ossl_statem_accept,
  220. ssl_undefined_function, tls1_get_server_method)
  221. #endif
  222. /*
  223. * TLS/SSLv3 client methods
  224. */
  225. static const SSL_METHOD *tls1_get_client_method(int ver)
  226. {
  227. if (ver == TLS_ANY_VERSION)
  228. return TLS_client_method();
  229. #ifndef OPENSSL_NO_TLS1_2
  230. if (ver == TLS1_2_VERSION)
  231. return TLSv1_2_client_method();
  232. #endif
  233. #ifndef OPENSSL_NO_TLS1_1
  234. if (ver == TLS1_1_VERSION)
  235. return TLSv1_1_client_method();
  236. #endif
  237. #ifndef OPENSSL_NO_TLS1
  238. if (ver == TLS1_VERSION)
  239. return TLSv1_client_method();
  240. #endif
  241. #ifndef OPENSSL_NO_SSL3
  242. if (ver == SSL3_VERSION)
  243. return (SSLv3_client_method());
  244. #endif
  245. return NULL;
  246. }
  247. IMPLEMENT_tls_meth_func(TLS_ANY_VERSION, 0, 0,
  248. TLS_client_method,
  249. ssl_undefined_function,
  250. ossl_statem_connect,
  251. tls1_get_client_method, TLSv1_2_enc_data)
  252. #ifndef OPENSSL_NO_TLS1_2_METHOD
  253. IMPLEMENT_tls_meth_func(TLS1_2_VERSION, 0, SSL_OP_NO_TLSv1_2,
  254. TLSv1_2_client_method,
  255. ssl_undefined_function,
  256. ossl_statem_connect,
  257. tls1_get_client_method, TLSv1_2_enc_data)
  258. #endif
  259. #ifndef OPENSSL_NO_TLS1_1_METHOD
  260. IMPLEMENT_tls_meth_func(TLS1_1_VERSION, SSL_METHOD_NO_SUITEB, SSL_OP_NO_TLSv1_1,
  261. TLSv1_1_client_method,
  262. ssl_undefined_function,
  263. ossl_statem_connect,
  264. tls1_get_client_method, TLSv1_1_enc_data)
  265. #endif
  266. #ifndef OPENSSL_NO_TLS1_METHOD
  267. IMPLEMENT_tls_meth_func(TLS1_VERSION, SSL_METHOD_NO_SUITEB, SSL_OP_NO_TLSv1,
  268. TLSv1_client_method,
  269. ssl_undefined_function,
  270. ossl_statem_connect,
  271. tls1_get_client_method, TLSv1_enc_data)
  272. #endif
  273. #ifndef OPENSSL_NO_SSL3_METHOD
  274. IMPLEMENT_ssl3_meth_func(SSLv3_client_method,
  275. ssl_undefined_function,
  276. ossl_statem_connect, tls1_get_client_method)
  277. #endif
  278. /*
  279. * DTLS methods
  280. */
  281. static const SSL_METHOD *dtls1_get_method(int ver)
  282. {
  283. if (ver == DTLS_ANY_VERSION)
  284. return DTLS_method();
  285. #ifndef OPENSSL_NO_DTLS1
  286. else if (ver == DTLS1_VERSION)
  287. return DTLSv1_method();
  288. #endif
  289. #ifndef OPENSSL_NO_DTLS1_2
  290. else if (ver == DTLS1_2_VERSION)
  291. return DTLSv1_2_method();
  292. #endif
  293. else
  294. return NULL;
  295. }
  296. #ifndef OPENSSL_NO_DTLS1_METHOD
  297. IMPLEMENT_dtls1_meth_func(DTLS1_VERSION, SSL_METHOD_NO_SUITEB, SSL_OP_NO_DTLSv1,
  298. DTLSv1_method,
  299. ossl_statem_accept,
  300. ossl_statem_connect,
  301. dtls1_get_method, DTLSv1_enc_data)
  302. #endif
  303. #ifndef OPENSSL_NO_DTLS1_2_METHOD
  304. IMPLEMENT_dtls1_meth_func(DTLS1_2_VERSION, 0, SSL_OP_NO_DTLSv1_2,
  305. DTLSv1_2_method,
  306. ossl_statem_accept,
  307. ossl_statem_connect,
  308. dtls1_get_method, DTLSv1_2_enc_data)
  309. #endif
  310. IMPLEMENT_dtls1_meth_func(DTLS_ANY_VERSION, 0, 0,
  311. DTLS_method,
  312. ossl_statem_accept,
  313. ossl_statem_connect,
  314. dtls1_get_method, DTLSv1_2_enc_data)
  315. /*
  316. * DTLS server methods
  317. */
  318. static const SSL_METHOD *dtls1_get_server_method(int ver)
  319. {
  320. if (ver == DTLS_ANY_VERSION)
  321. return DTLS_server_method();
  322. #ifndef OPENSSL_NO_DTLS1
  323. else if (ver == DTLS1_VERSION)
  324. return DTLSv1_server_method();
  325. #endif
  326. #ifndef OPENSSL_NO_DTLS1_2
  327. else if (ver == DTLS1_2_VERSION)
  328. return DTLSv1_2_server_method();
  329. #endif
  330. else
  331. return NULL;
  332. }
  333. #ifndef OPENSSL_NO_DTLS1_METHOD
  334. IMPLEMENT_dtls1_meth_func(DTLS1_VERSION, SSL_METHOD_NO_SUITEB, SSL_OP_NO_DTLSv1,
  335. DTLSv1_server_method,
  336. ossl_statem_accept,
  337. ssl_undefined_function,
  338. dtls1_get_server_method, DTLSv1_enc_data)
  339. #endif
  340. #ifndef OPENSSL_NO_DTLS1_2_METHOD
  341. IMPLEMENT_dtls1_meth_func(DTLS1_2_VERSION, 0, SSL_OP_NO_DTLSv1_2,
  342. DTLSv1_2_server_method,
  343. ossl_statem_accept,
  344. ssl_undefined_function,
  345. dtls1_get_server_method, DTLSv1_2_enc_data)
  346. #endif
  347. IMPLEMENT_dtls1_meth_func(DTLS_ANY_VERSION, 0, 0,
  348. DTLS_server_method,
  349. ossl_statem_accept,
  350. ssl_undefined_function,
  351. dtls1_get_server_method, DTLSv1_2_enc_data)
  352. /*
  353. * DTLS client methods
  354. */
  355. static const SSL_METHOD *dtls1_get_client_method(int ver)
  356. {
  357. if (ver == DTLS_ANY_VERSION)
  358. return DTLS_client_method();
  359. #ifndef OPENSSL_NO_DTLS1
  360. else if (ver == DTLS1_VERSION || ver == DTLS1_BAD_VER)
  361. return DTLSv1_client_method();
  362. #endif
  363. #ifndef OPENSSL_NO_DTLS1_2
  364. else if (ver == DTLS1_2_VERSION)
  365. return DTLSv1_2_client_method();
  366. #endif
  367. else
  368. return NULL;
  369. }
  370. #ifndef OPENSSL_NO_DTLS1_METHOD
  371. IMPLEMENT_dtls1_meth_func(DTLS1_VERSION, SSL_METHOD_NO_SUITEB, SSL_OP_NO_DTLSv1,
  372. DTLSv1_client_method,
  373. ssl_undefined_function,
  374. ossl_statem_connect,
  375. dtls1_get_client_method, DTLSv1_enc_data)
  376. #endif
  377. #ifndef OPENSSL_NO_DTLS1_2_METHOD
  378. IMPLEMENT_dtls1_meth_func(DTLS1_2_VERSION, 0, SSL_OP_NO_DTLSv1_2,
  379. DTLSv1_2_client_method,
  380. ssl_undefined_function,
  381. ossl_statem_connect,
  382. dtls1_get_client_method, DTLSv1_2_enc_data)
  383. #endif
  384. IMPLEMENT_dtls1_meth_func(DTLS_ANY_VERSION, 0, 0,
  385. DTLS_client_method,
  386. ssl_undefined_function,
  387. ossl_statem_connect,
  388. dtls1_get_client_method, DTLSv1_2_enc_data)