s3_lib.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799
  1. /* ssl/s3_lib.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-2002 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. #include "kssl_lcl.h"
  115. #include <openssl/md5.h>
  116. const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT;
  117. #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
  118. static long ssl3_default_timeout(void );
  119. OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
  120. /* The RSA ciphers */
  121. /* Cipher 01 */
  122. {
  123. 1,
  124. SSL3_TXT_RSA_NULL_MD5,
  125. SSL3_CK_RSA_NULL_MD5,
  126. SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_MD5|SSL_SSLV3,
  127. SSL_NOT_EXP|SSL_STRONG_NONE,
  128. 0,
  129. 0,
  130. 0,
  131. SSL_ALL_CIPHERS,
  132. SSL_ALL_STRENGTHS,
  133. },
  134. /* Cipher 02 */
  135. {
  136. 1,
  137. SSL3_TXT_RSA_NULL_SHA,
  138. SSL3_CK_RSA_NULL_SHA,
  139. SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_SSLV3,
  140. SSL_NOT_EXP|SSL_STRONG_NONE,
  141. 0,
  142. 0,
  143. 0,
  144. SSL_ALL_CIPHERS,
  145. SSL_ALL_STRENGTHS,
  146. },
  147. /* anon DH */
  148. /* Cipher 17 */
  149. {
  150. 1,
  151. SSL3_TXT_ADH_RC4_40_MD5,
  152. SSL3_CK_ADH_RC4_40_MD5,
  153. SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
  154. SSL_EXPORT|SSL_EXP40,
  155. 0,
  156. 40,
  157. 128,
  158. SSL_ALL_CIPHERS,
  159. SSL_ALL_STRENGTHS,
  160. },
  161. /* Cipher 18 */
  162. {
  163. 1,
  164. SSL3_TXT_ADH_RC4_128_MD5,
  165. SSL3_CK_ADH_RC4_128_MD5,
  166. SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
  167. SSL_NOT_EXP|SSL_MEDIUM,
  168. 0,
  169. 128,
  170. 128,
  171. SSL_ALL_CIPHERS,
  172. SSL_ALL_STRENGTHS,
  173. },
  174. /* Cipher 19 */
  175. {
  176. 1,
  177. SSL3_TXT_ADH_DES_40_CBC_SHA,
  178. SSL3_CK_ADH_DES_40_CBC_SHA,
  179. SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_SSLV3,
  180. SSL_EXPORT|SSL_EXP40,
  181. 0,
  182. 40,
  183. 128,
  184. SSL_ALL_CIPHERS,
  185. SSL_ALL_STRENGTHS,
  186. },
  187. /* Cipher 1A */
  188. {
  189. 1,
  190. SSL3_TXT_ADH_DES_64_CBC_SHA,
  191. SSL3_CK_ADH_DES_64_CBC_SHA,
  192. SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_SSLV3,
  193. SSL_NOT_EXP|SSL_LOW,
  194. 0,
  195. 56,
  196. 56,
  197. SSL_ALL_CIPHERS,
  198. SSL_ALL_STRENGTHS,
  199. },
  200. /* Cipher 1B */
  201. {
  202. 1,
  203. SSL3_TXT_ADH_DES_192_CBC_SHA,
  204. SSL3_CK_ADH_DES_192_CBC_SHA,
  205. SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_SSLV3,
  206. SSL_NOT_EXP|SSL_HIGH,
  207. 0,
  208. 168,
  209. 168,
  210. SSL_ALL_CIPHERS,
  211. SSL_ALL_STRENGTHS,
  212. },
  213. /* RSA again */
  214. /* Cipher 03 */
  215. {
  216. 1,
  217. SSL3_TXT_RSA_RC4_40_MD5,
  218. SSL3_CK_RSA_RC4_40_MD5,
  219. SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
  220. SSL_EXPORT|SSL_EXP40,
  221. 0,
  222. 40,
  223. 128,
  224. SSL_ALL_CIPHERS,
  225. SSL_ALL_STRENGTHS,
  226. },
  227. /* Cipher 04 */
  228. {
  229. 1,
  230. SSL3_TXT_RSA_RC4_128_MD5,
  231. SSL3_CK_RSA_RC4_128_MD5,
  232. SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5|SSL_SSLV3,
  233. SSL_NOT_EXP|SSL_MEDIUM,
  234. 0,
  235. 128,
  236. 128,
  237. SSL_ALL_CIPHERS,
  238. SSL_ALL_STRENGTHS,
  239. },
  240. /* Cipher 05 */
  241. {
  242. 1,
  243. SSL3_TXT_RSA_RC4_128_SHA,
  244. SSL3_CK_RSA_RC4_128_SHA,
  245. SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_SHA1|SSL_SSLV3,
  246. SSL_NOT_EXP|SSL_MEDIUM,
  247. 0,
  248. 128,
  249. 128,
  250. SSL_ALL_CIPHERS,
  251. SSL_ALL_STRENGTHS,
  252. },
  253. /* Cipher 06 */
  254. {
  255. 1,
  256. SSL3_TXT_RSA_RC2_40_MD5,
  257. SSL3_CK_RSA_RC2_40_MD5,
  258. SSL_kRSA|SSL_aRSA|SSL_RC2 |SSL_MD5 |SSL_SSLV3,
  259. SSL_EXPORT|SSL_EXP40,
  260. 0,
  261. 40,
  262. 128,
  263. SSL_ALL_CIPHERS,
  264. SSL_ALL_STRENGTHS,
  265. },
  266. /* Cipher 07 */
  267. #ifndef OPENSSL_NO_IDEA
  268. {
  269. 1,
  270. SSL3_TXT_RSA_IDEA_128_SHA,
  271. SSL3_CK_RSA_IDEA_128_SHA,
  272. SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_SSLV3,
  273. SSL_NOT_EXP|SSL_MEDIUM,
  274. 0,
  275. 128,
  276. 128,
  277. SSL_ALL_CIPHERS,
  278. SSL_ALL_STRENGTHS,
  279. },
  280. #endif
  281. /* Cipher 08 */
  282. {
  283. 1,
  284. SSL3_TXT_RSA_DES_40_CBC_SHA,
  285. SSL3_CK_RSA_DES_40_CBC_SHA,
  286. SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
  287. SSL_EXPORT|SSL_EXP40,
  288. 0,
  289. 40,
  290. 56,
  291. SSL_ALL_CIPHERS,
  292. SSL_ALL_STRENGTHS,
  293. },
  294. /* Cipher 09 */
  295. {
  296. 1,
  297. SSL3_TXT_RSA_DES_64_CBC_SHA,
  298. SSL3_CK_RSA_DES_64_CBC_SHA,
  299. SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3,
  300. SSL_NOT_EXP|SSL_LOW,
  301. 0,
  302. 56,
  303. 56,
  304. SSL_ALL_CIPHERS,
  305. SSL_ALL_STRENGTHS,
  306. },
  307. /* Cipher 0A */
  308. {
  309. 1,
  310. SSL3_TXT_RSA_DES_192_CBC3_SHA,
  311. SSL3_CK_RSA_DES_192_CBC3_SHA,
  312. SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
  313. SSL_NOT_EXP|SSL_HIGH,
  314. 0,
  315. 168,
  316. 168,
  317. SSL_ALL_CIPHERS,
  318. SSL_ALL_STRENGTHS,
  319. },
  320. /* The DH ciphers */
  321. /* Cipher 0B */
  322. {
  323. 0,
  324. SSL3_TXT_DH_DSS_DES_40_CBC_SHA,
  325. SSL3_CK_DH_DSS_DES_40_CBC_SHA,
  326. SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
  327. SSL_EXPORT|SSL_EXP40,
  328. 0,
  329. 40,
  330. 56,
  331. SSL_ALL_CIPHERS,
  332. SSL_ALL_STRENGTHS,
  333. },
  334. /* Cipher 0C */
  335. {
  336. 0,
  337. SSL3_TXT_DH_DSS_DES_64_CBC_SHA,
  338. SSL3_CK_DH_DSS_DES_64_CBC_SHA,
  339. SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3,
  340. SSL_NOT_EXP|SSL_LOW,
  341. 0,
  342. 56,
  343. 56,
  344. SSL_ALL_CIPHERS,
  345. SSL_ALL_STRENGTHS,
  346. },
  347. /* Cipher 0D */
  348. {
  349. 0,
  350. SSL3_TXT_DH_DSS_DES_192_CBC3_SHA,
  351. SSL3_CK_DH_DSS_DES_192_CBC3_SHA,
  352. SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
  353. SSL_NOT_EXP|SSL_HIGH,
  354. 0,
  355. 168,
  356. 168,
  357. SSL_ALL_CIPHERS,
  358. SSL_ALL_STRENGTHS,
  359. },
  360. /* Cipher 0E */
  361. {
  362. 0,
  363. SSL3_TXT_DH_RSA_DES_40_CBC_SHA,
  364. SSL3_CK_DH_RSA_DES_40_CBC_SHA,
  365. SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
  366. SSL_EXPORT|SSL_EXP40,
  367. 0,
  368. 40,
  369. 56,
  370. SSL_ALL_CIPHERS,
  371. SSL_ALL_STRENGTHS,
  372. },
  373. /* Cipher 0F */
  374. {
  375. 0,
  376. SSL3_TXT_DH_RSA_DES_64_CBC_SHA,
  377. SSL3_CK_DH_RSA_DES_64_CBC_SHA,
  378. SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3,
  379. SSL_NOT_EXP|SSL_LOW,
  380. 0,
  381. 56,
  382. 56,
  383. SSL_ALL_CIPHERS,
  384. SSL_ALL_STRENGTHS,
  385. },
  386. /* Cipher 10 */
  387. {
  388. 0,
  389. SSL3_TXT_DH_RSA_DES_192_CBC3_SHA,
  390. SSL3_CK_DH_RSA_DES_192_CBC3_SHA,
  391. SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
  392. SSL_NOT_EXP|SSL_HIGH,
  393. 0,
  394. 168,
  395. 168,
  396. SSL_ALL_CIPHERS,
  397. SSL_ALL_STRENGTHS,
  398. },
  399. /* The Ephemeral DH ciphers */
  400. /* Cipher 11 */
  401. {
  402. 1,
  403. SSL3_TXT_EDH_DSS_DES_40_CBC_SHA,
  404. SSL3_CK_EDH_DSS_DES_40_CBC_SHA,
  405. SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_SSLV3,
  406. SSL_EXPORT|SSL_EXP40,
  407. 0,
  408. 40,
  409. 56,
  410. SSL_ALL_CIPHERS,
  411. SSL_ALL_STRENGTHS,
  412. },
  413. /* Cipher 12 */
  414. {
  415. 1,
  416. SSL3_TXT_EDH_DSS_DES_64_CBC_SHA,
  417. SSL3_CK_EDH_DSS_DES_64_CBC_SHA,
  418. SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_SSLV3,
  419. SSL_NOT_EXP|SSL_LOW,
  420. 0,
  421. 56,
  422. 56,
  423. SSL_ALL_CIPHERS,
  424. SSL_ALL_STRENGTHS,
  425. },
  426. /* Cipher 13 */
  427. {
  428. 1,
  429. SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA,
  430. SSL3_CK_EDH_DSS_DES_192_CBC3_SHA,
  431. SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_SSLV3,
  432. SSL_NOT_EXP|SSL_HIGH,
  433. 0,
  434. 168,
  435. 168,
  436. SSL_ALL_CIPHERS,
  437. SSL_ALL_STRENGTHS,
  438. },
  439. /* Cipher 14 */
  440. {
  441. 1,
  442. SSL3_TXT_EDH_RSA_DES_40_CBC_SHA,
  443. SSL3_CK_EDH_RSA_DES_40_CBC_SHA,
  444. SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
  445. SSL_EXPORT|SSL_EXP40,
  446. 0,
  447. 40,
  448. 56,
  449. SSL_ALL_CIPHERS,
  450. SSL_ALL_STRENGTHS,
  451. },
  452. /* Cipher 15 */
  453. {
  454. 1,
  455. SSL3_TXT_EDH_RSA_DES_64_CBC_SHA,
  456. SSL3_CK_EDH_RSA_DES_64_CBC_SHA,
  457. SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3,
  458. SSL_NOT_EXP|SSL_LOW,
  459. 0,
  460. 56,
  461. 56,
  462. SSL_ALL_CIPHERS,
  463. SSL_ALL_STRENGTHS,
  464. },
  465. /* Cipher 16 */
  466. {
  467. 1,
  468. SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA,
  469. SSL3_CK_EDH_RSA_DES_192_CBC3_SHA,
  470. SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
  471. SSL_NOT_EXP|SSL_HIGH,
  472. 0,
  473. 168,
  474. 168,
  475. SSL_ALL_CIPHERS,
  476. SSL_ALL_STRENGTHS,
  477. },
  478. /* Fortezza */
  479. /* Cipher 1C */
  480. {
  481. 0,
  482. SSL3_TXT_FZA_DMS_NULL_SHA,
  483. SSL3_CK_FZA_DMS_NULL_SHA,
  484. SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_SSLV3,
  485. SSL_NOT_EXP|SSL_STRONG_NONE,
  486. 0,
  487. 0,
  488. 0,
  489. SSL_ALL_CIPHERS,
  490. SSL_ALL_STRENGTHS,
  491. },
  492. /* Cipher 1D */
  493. {
  494. 0,
  495. SSL3_TXT_FZA_DMS_FZA_SHA,
  496. SSL3_CK_FZA_DMS_FZA_SHA,
  497. SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_SSLV3,
  498. SSL_NOT_EXP|SSL_STRONG_NONE,
  499. 0,
  500. 0,
  501. 0,
  502. SSL_ALL_CIPHERS,
  503. SSL_ALL_STRENGTHS,
  504. },
  505. #if 0
  506. /* Cipher 1E */
  507. {
  508. 0,
  509. SSL3_TXT_FZA_DMS_RC4_SHA,
  510. SSL3_CK_FZA_DMS_RC4_SHA,
  511. SSL_kFZA|SSL_aFZA |SSL_RC4 |SSL_SHA1|SSL_SSLV3,
  512. SSL_NOT_EXP|SSL_MEDIUM,
  513. 0,
  514. 128,
  515. 128,
  516. SSL_ALL_CIPHERS,
  517. SSL_ALL_STRENGTHS,
  518. },
  519. #endif
  520. #ifndef OPENSSL_NO_KRB5
  521. /* The Kerberos ciphers
  522. ** 20000107 VRS: And the first shall be last,
  523. ** in hopes of avoiding the lynx ssl renegotiation problem.
  524. */
  525. /* Cipher 1E VRS */
  526. {
  527. 1,
  528. SSL3_TXT_KRB5_DES_64_CBC_SHA,
  529. SSL3_CK_KRB5_DES_64_CBC_SHA,
  530. SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3,
  531. SSL_NOT_EXP|SSL_LOW,
  532. 0,
  533. 56,
  534. 56,
  535. SSL_ALL_CIPHERS,
  536. SSL_ALL_STRENGTHS,
  537. },
  538. /* Cipher 1F VRS */
  539. {
  540. 1,
  541. SSL3_TXT_KRB5_DES_192_CBC3_SHA,
  542. SSL3_CK_KRB5_DES_192_CBC3_SHA,
  543. SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_SHA1 |SSL_SSLV3,
  544. SSL_NOT_EXP|SSL_HIGH,
  545. 0,
  546. 112,
  547. 168,
  548. SSL_ALL_CIPHERS,
  549. SSL_ALL_STRENGTHS,
  550. },
  551. /* Cipher 20 VRS */
  552. {
  553. 1,
  554. SSL3_TXT_KRB5_RC4_128_SHA,
  555. SSL3_CK_KRB5_RC4_128_SHA,
  556. SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3,
  557. SSL_NOT_EXP|SSL_MEDIUM,
  558. 0,
  559. 128,
  560. 128,
  561. SSL_ALL_CIPHERS,
  562. SSL_ALL_STRENGTHS,
  563. },
  564. /* Cipher 21 VRS */
  565. {
  566. 1,
  567. SSL3_TXT_KRB5_IDEA_128_CBC_SHA,
  568. SSL3_CK_KRB5_IDEA_128_CBC_SHA,
  569. SSL_kKRB5|SSL_aKRB5| SSL_IDEA|SSL_SHA1 |SSL_SSLV3,
  570. SSL_NOT_EXP|SSL_MEDIUM,
  571. 0,
  572. 128,
  573. 128,
  574. SSL_ALL_CIPHERS,
  575. SSL_ALL_STRENGTHS,
  576. },
  577. /* Cipher 22 VRS */
  578. {
  579. 1,
  580. SSL3_TXT_KRB5_DES_64_CBC_MD5,
  581. SSL3_CK_KRB5_DES_64_CBC_MD5,
  582. SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3,
  583. SSL_NOT_EXP|SSL_LOW,
  584. 0,
  585. 56,
  586. 56,
  587. SSL_ALL_CIPHERS,
  588. SSL_ALL_STRENGTHS,
  589. },
  590. /* Cipher 23 VRS */
  591. {
  592. 1,
  593. SSL3_TXT_KRB5_DES_192_CBC3_MD5,
  594. SSL3_CK_KRB5_DES_192_CBC3_MD5,
  595. SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_MD5 |SSL_SSLV3,
  596. SSL_NOT_EXP|SSL_HIGH,
  597. 0,
  598. 112,
  599. 168,
  600. SSL_ALL_CIPHERS,
  601. SSL_ALL_STRENGTHS,
  602. },
  603. /* Cipher 24 VRS */
  604. {
  605. 1,
  606. SSL3_TXT_KRB5_RC4_128_MD5,
  607. SSL3_CK_KRB5_RC4_128_MD5,
  608. SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3,
  609. SSL_NOT_EXP|SSL_MEDIUM,
  610. 0,
  611. 128,
  612. 128,
  613. SSL_ALL_CIPHERS,
  614. SSL_ALL_STRENGTHS,
  615. },
  616. /* Cipher 25 VRS */
  617. {
  618. 1,
  619. SSL3_TXT_KRB5_IDEA_128_CBC_MD5,
  620. SSL3_CK_KRB5_IDEA_128_CBC_MD5,
  621. SSL_kKRB5|SSL_aKRB5| SSL_IDEA|SSL_MD5 |SSL_SSLV3,
  622. SSL_NOT_EXP|SSL_MEDIUM,
  623. 0,
  624. 128,
  625. 128,
  626. SSL_ALL_CIPHERS,
  627. SSL_ALL_STRENGTHS,
  628. },
  629. /* Cipher 26 VRS */
  630. {
  631. 1,
  632. SSL3_TXT_KRB5_DES_40_CBC_SHA,
  633. SSL3_CK_KRB5_DES_40_CBC_SHA,
  634. SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3,
  635. SSL_EXPORT|SSL_EXP40,
  636. 0,
  637. 40,
  638. 56,
  639. SSL_ALL_CIPHERS,
  640. SSL_ALL_STRENGTHS,
  641. },
  642. /* Cipher 27 VRS */
  643. {
  644. 1,
  645. SSL3_TXT_KRB5_RC2_40_CBC_SHA,
  646. SSL3_CK_KRB5_RC2_40_CBC_SHA,
  647. SSL_kKRB5|SSL_aKRB5| SSL_RC2|SSL_SHA1 |SSL_SSLV3,
  648. SSL_EXPORT|SSL_EXP40,
  649. 0,
  650. 40,
  651. 128,
  652. SSL_ALL_CIPHERS,
  653. SSL_ALL_STRENGTHS,
  654. },
  655. /* Cipher 28 VRS */
  656. {
  657. 1,
  658. SSL3_TXT_KRB5_RC4_40_SHA,
  659. SSL3_CK_KRB5_RC4_40_SHA,
  660. SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3,
  661. SSL_EXPORT|SSL_EXP40,
  662. 0,
  663. 128,
  664. 128,
  665. SSL_ALL_CIPHERS,
  666. SSL_ALL_STRENGTHS,
  667. },
  668. /* Cipher 29 VRS */
  669. {
  670. 1,
  671. SSL3_TXT_KRB5_DES_40_CBC_MD5,
  672. SSL3_CK_KRB5_DES_40_CBC_MD5,
  673. SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3,
  674. SSL_EXPORT|SSL_EXP40,
  675. 0,
  676. 40,
  677. 56,
  678. SSL_ALL_CIPHERS,
  679. SSL_ALL_STRENGTHS,
  680. },
  681. /* Cipher 2A VRS */
  682. {
  683. 1,
  684. SSL3_TXT_KRB5_RC2_40_CBC_MD5,
  685. SSL3_CK_KRB5_RC2_40_CBC_MD5,
  686. SSL_kKRB5|SSL_aKRB5| SSL_RC2|SSL_MD5 |SSL_SSLV3,
  687. SSL_EXPORT|SSL_EXP40,
  688. 0,
  689. 40,
  690. 128,
  691. SSL_ALL_CIPHERS,
  692. SSL_ALL_STRENGTHS,
  693. },
  694. /* Cipher 2B VRS */
  695. {
  696. 1,
  697. SSL3_TXT_KRB5_RC4_40_MD5,
  698. SSL3_CK_KRB5_RC4_40_MD5,
  699. SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3,
  700. SSL_EXPORT|SSL_EXP40,
  701. 0,
  702. 128,
  703. 128,
  704. SSL_ALL_CIPHERS,
  705. SSL_ALL_STRENGTHS,
  706. },
  707. #endif /* OPENSSL_NO_KRB5 */
  708. #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES
  709. /* New TLS Export CipherSuites */
  710. /* Cipher 60 */
  711. {
  712. 1,
  713. TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5,
  714. TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5,
  715. SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_TLSV1,
  716. SSL_EXPORT|SSL_EXP56,
  717. 0,
  718. 56,
  719. 128,
  720. SSL_ALL_CIPHERS,
  721. SSL_ALL_STRENGTHS,
  722. },
  723. /* Cipher 61 */
  724. {
  725. 1,
  726. TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
  727. TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
  728. SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_TLSV1,
  729. SSL_EXPORT|SSL_EXP56,
  730. 0,
  731. 56,
  732. 128,
  733. SSL_ALL_CIPHERS,
  734. SSL_ALL_STRENGTHS,
  735. },
  736. /* Cipher 62 */
  737. {
  738. 1,
  739. TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA,
  740. TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA,
  741. SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1,
  742. SSL_EXPORT|SSL_EXP56,
  743. 0,
  744. 56,
  745. 56,
  746. SSL_ALL_CIPHERS,
  747. SSL_ALL_STRENGTHS,
  748. },
  749. /* Cipher 63 */
  750. {
  751. 1,
  752. TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
  753. TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
  754. SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_TLSV1,
  755. SSL_EXPORT|SSL_EXP56,
  756. 0,
  757. 56,
  758. 56,
  759. SSL_ALL_CIPHERS,
  760. SSL_ALL_STRENGTHS,
  761. },
  762. /* Cipher 64 */
  763. {
  764. 1,
  765. TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA,
  766. TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA,
  767. SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
  768. SSL_EXPORT|SSL_EXP56,
  769. 0,
  770. 56,
  771. 128,
  772. SSL_ALL_CIPHERS,
  773. SSL_ALL_STRENGTHS,
  774. },
  775. /* Cipher 65 */
  776. {
  777. 1,
  778. TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
  779. TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
  780. SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
  781. SSL_EXPORT|SSL_EXP56,
  782. 0,
  783. 56,
  784. 128,
  785. SSL_ALL_CIPHERS,
  786. SSL_ALL_STRENGTHS,
  787. },
  788. /* Cipher 66 */
  789. {
  790. 1,
  791. TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA,
  792. TLS1_CK_DHE_DSS_WITH_RC4_128_SHA,
  793. SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
  794. SSL_NOT_EXP|SSL_MEDIUM,
  795. 0,
  796. 128,
  797. 128,
  798. SSL_ALL_CIPHERS,
  799. SSL_ALL_STRENGTHS
  800. },
  801. #endif
  802. /* New AES ciphersuites */
  803. /* Cipher 2F */
  804. {
  805. 1,
  806. TLS1_TXT_RSA_WITH_AES_128_SHA,
  807. TLS1_CK_RSA_WITH_AES_128_SHA,
  808. SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1,
  809. SSL_NOT_EXP|SSL_MEDIUM,
  810. 0,
  811. 128,
  812. 128,
  813. SSL_ALL_CIPHERS,
  814. SSL_ALL_STRENGTHS,
  815. },
  816. /* Cipher 30 */
  817. {
  818. 0,
  819. TLS1_TXT_DH_DSS_WITH_AES_128_SHA,
  820. TLS1_CK_DH_DSS_WITH_AES_128_SHA,
  821. SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
  822. SSL_NOT_EXP|SSL_MEDIUM,
  823. 0,
  824. 128,
  825. 128,
  826. SSL_ALL_CIPHERS,
  827. SSL_ALL_STRENGTHS,
  828. },
  829. /* Cipher 31 */
  830. {
  831. 0,
  832. TLS1_TXT_DH_RSA_WITH_AES_128_SHA,
  833. TLS1_CK_DH_RSA_WITH_AES_128_SHA,
  834. SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
  835. SSL_NOT_EXP|SSL_MEDIUM,
  836. 0,
  837. 128,
  838. 128,
  839. SSL_ALL_CIPHERS,
  840. SSL_ALL_STRENGTHS,
  841. },
  842. /* Cipher 32 */
  843. {
  844. 1,
  845. TLS1_TXT_DHE_DSS_WITH_AES_128_SHA,
  846. TLS1_CK_DHE_DSS_WITH_AES_128_SHA,
  847. SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1,
  848. SSL_NOT_EXP|SSL_MEDIUM,
  849. 0,
  850. 128,
  851. 128,
  852. SSL_ALL_CIPHERS,
  853. SSL_ALL_STRENGTHS,
  854. },
  855. /* Cipher 33 */
  856. {
  857. 1,
  858. TLS1_TXT_DHE_RSA_WITH_AES_128_SHA,
  859. TLS1_CK_DHE_RSA_WITH_AES_128_SHA,
  860. SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
  861. SSL_NOT_EXP|SSL_MEDIUM,
  862. 0,
  863. 128,
  864. 128,
  865. SSL_ALL_CIPHERS,
  866. SSL_ALL_STRENGTHS,
  867. },
  868. /* Cipher 34 */
  869. {
  870. 1,
  871. TLS1_TXT_ADH_WITH_AES_128_SHA,
  872. TLS1_CK_ADH_WITH_AES_128_SHA,
  873. SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
  874. SSL_NOT_EXP|SSL_MEDIUM,
  875. 0,
  876. 128,
  877. 128,
  878. SSL_ALL_CIPHERS,
  879. SSL_ALL_STRENGTHS,
  880. },
  881. /* Cipher 35 */
  882. {
  883. 1,
  884. TLS1_TXT_RSA_WITH_AES_256_SHA,
  885. TLS1_CK_RSA_WITH_AES_256_SHA,
  886. SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1,
  887. SSL_NOT_EXP|SSL_HIGH,
  888. 0,
  889. 256,
  890. 256,
  891. SSL_ALL_CIPHERS,
  892. SSL_ALL_STRENGTHS,
  893. },
  894. /* Cipher 36 */
  895. {
  896. 0,
  897. TLS1_TXT_DH_DSS_WITH_AES_256_SHA,
  898. TLS1_CK_DH_DSS_WITH_AES_256_SHA,
  899. SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
  900. SSL_NOT_EXP|SSL_HIGH,
  901. 0,
  902. 256,
  903. 256,
  904. SSL_ALL_CIPHERS,
  905. SSL_ALL_STRENGTHS,
  906. },
  907. /* Cipher 37 */
  908. {
  909. 0,
  910. TLS1_TXT_DH_RSA_WITH_AES_256_SHA,
  911. TLS1_CK_DH_RSA_WITH_AES_256_SHA,
  912. SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
  913. SSL_NOT_EXP|SSL_HIGH,
  914. 0,
  915. 256,
  916. 256,
  917. SSL_ALL_CIPHERS,
  918. SSL_ALL_STRENGTHS,
  919. },
  920. /* Cipher 38 */
  921. {
  922. 1,
  923. TLS1_TXT_DHE_DSS_WITH_AES_256_SHA,
  924. TLS1_CK_DHE_DSS_WITH_AES_256_SHA,
  925. SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1,
  926. SSL_NOT_EXP|SSL_HIGH,
  927. 0,
  928. 256,
  929. 256,
  930. SSL_ALL_CIPHERS,
  931. SSL_ALL_STRENGTHS,
  932. },
  933. /* Cipher 39 */
  934. {
  935. 1,
  936. TLS1_TXT_DHE_RSA_WITH_AES_256_SHA,
  937. TLS1_CK_DHE_RSA_WITH_AES_256_SHA,
  938. SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
  939. SSL_NOT_EXP|SSL_HIGH,
  940. 0,
  941. 256,
  942. 256,
  943. SSL_ALL_CIPHERS,
  944. SSL_ALL_STRENGTHS,
  945. },
  946. /* Cipher 3A */
  947. {
  948. 1,
  949. TLS1_TXT_ADH_WITH_AES_256_SHA,
  950. TLS1_CK_ADH_WITH_AES_256_SHA,
  951. SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
  952. SSL_NOT_EXP|SSL_HIGH,
  953. 0,
  954. 256,
  955. 256,
  956. SSL_ALL_CIPHERS,
  957. SSL_ALL_STRENGTHS,
  958. },
  959. /* end of list */
  960. };
  961. static SSL3_ENC_METHOD SSLv3_enc_data={
  962. ssl3_enc,
  963. ssl3_mac,
  964. ssl3_setup_key_block,
  965. ssl3_generate_master_secret,
  966. ssl3_change_cipher_state,
  967. ssl3_final_finish_mac,
  968. MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
  969. ssl3_cert_verify_mac,
  970. SSL3_MD_CLIENT_FINISHED_CONST,4,
  971. SSL3_MD_SERVER_FINISHED_CONST,4,
  972. ssl3_alert_code,
  973. };
  974. static SSL_METHOD SSLv3_data= {
  975. SSL3_VERSION,
  976. ssl3_new,
  977. ssl3_clear,
  978. ssl3_free,
  979. ssl_undefined_function,
  980. ssl_undefined_function,
  981. ssl3_read,
  982. ssl3_peek,
  983. ssl3_write,
  984. ssl3_shutdown,
  985. ssl3_renegotiate,
  986. ssl3_renegotiate_check,
  987. ssl3_ctrl,
  988. ssl3_ctx_ctrl,
  989. ssl3_get_cipher_by_char,
  990. ssl3_put_cipher_by_char,
  991. ssl3_pending,
  992. ssl3_num_ciphers,
  993. ssl3_get_cipher,
  994. ssl_bad_method,
  995. ssl3_default_timeout,
  996. &SSLv3_enc_data,
  997. ssl_undefined_function,
  998. ssl3_callback_ctrl,
  999. ssl3_ctx_callback_ctrl,
  1000. };
  1001. static long ssl3_default_timeout(void)
  1002. {
  1003. /* 2 hours, the 24 hours mentioned in the SSLv3 spec
  1004. * is way too long for http, the cache would over fill */
  1005. return(60*60*2);
  1006. }
  1007. SSL_METHOD *sslv3_base_method(void)
  1008. {
  1009. return(&SSLv3_data);
  1010. }
  1011. int ssl3_num_ciphers(void)
  1012. {
  1013. return(SSL3_NUM_CIPHERS);
  1014. }
  1015. SSL_CIPHER *ssl3_get_cipher(unsigned int u)
  1016. {
  1017. if (u < SSL3_NUM_CIPHERS)
  1018. return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
  1019. else
  1020. return(NULL);
  1021. }
  1022. int ssl3_pending(SSL *s)
  1023. {
  1024. if (s->rstate == SSL_ST_READ_BODY)
  1025. return 0;
  1026. return (s->s3->rrec.type == SSL3_RT_APPLICATION_DATA) ? s->s3->rrec.length : 0;
  1027. }
  1028. int ssl3_new(SSL *s)
  1029. {
  1030. SSL3_STATE *s3;
  1031. if ((s3=OPENSSL_malloc(sizeof *s3)) == NULL) goto err;
  1032. memset(s3,0,sizeof *s3);
  1033. EVP_MD_CTX_init(&s3->finish_dgst1);
  1034. EVP_MD_CTX_init(&s3->finish_dgst2);
  1035. s->s3=s3;
  1036. s->method->ssl_clear(s);
  1037. return(1);
  1038. err:
  1039. return(0);
  1040. }
  1041. void ssl3_free(SSL *s)
  1042. {
  1043. if(s == NULL)
  1044. return;
  1045. ssl3_cleanup_key_block(s);
  1046. if (s->s3->rbuf.buf != NULL)
  1047. OPENSSL_free(s->s3->rbuf.buf);
  1048. if (s->s3->wbuf.buf != NULL)
  1049. OPENSSL_free(s->s3->wbuf.buf);
  1050. if (s->s3->rrec.comp != NULL)
  1051. OPENSSL_free(s->s3->rrec.comp);
  1052. #ifndef OPENSSL_NO_DH
  1053. if (s->s3->tmp.dh != NULL)
  1054. DH_free(s->s3->tmp.dh);
  1055. #endif
  1056. if (s->s3->tmp.ca_names != NULL)
  1057. sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
  1058. EVP_MD_CTX_cleanup(&s->s3->finish_dgst1);
  1059. EVP_MD_CTX_cleanup(&s->s3->finish_dgst2);
  1060. OPENSSL_cleanse(s->s3,sizeof *s->s3);
  1061. OPENSSL_free(s->s3);
  1062. s->s3=NULL;
  1063. }
  1064. void ssl3_clear(SSL *s)
  1065. {
  1066. unsigned char *rp,*wp;
  1067. size_t rlen, wlen;
  1068. ssl3_cleanup_key_block(s);
  1069. if (s->s3->tmp.ca_names != NULL)
  1070. sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
  1071. if (s->s3->rrec.comp != NULL)
  1072. {
  1073. OPENSSL_free(s->s3->rrec.comp);
  1074. s->s3->rrec.comp=NULL;
  1075. }
  1076. #ifndef OPENSSL_NO_DH
  1077. if (s->s3->tmp.dh != NULL)
  1078. DH_free(s->s3->tmp.dh);
  1079. #endif
  1080. rp = s->s3->rbuf.buf;
  1081. wp = s->s3->wbuf.buf;
  1082. rlen = s->s3->rbuf.len;
  1083. wlen = s->s3->wbuf.len;
  1084. EVP_MD_CTX_cleanup(&s->s3->finish_dgst1);
  1085. EVP_MD_CTX_cleanup(&s->s3->finish_dgst2);
  1086. memset(s->s3,0,sizeof *s->s3);
  1087. s->s3->rbuf.buf = rp;
  1088. s->s3->wbuf.buf = wp;
  1089. s->s3->rbuf.len = rlen;
  1090. s->s3->wbuf.len = wlen;
  1091. ssl_free_wbio_buffer(s);
  1092. s->packet_length=0;
  1093. s->s3->renegotiate=0;
  1094. s->s3->total_renegotiations=0;
  1095. s->s3->num_renegotiations=0;
  1096. s->s3->in_read_app_data=0;
  1097. s->version=SSL3_VERSION;
  1098. }
  1099. long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
  1100. {
  1101. int ret=0;
  1102. #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
  1103. if (
  1104. #ifndef OPENSSL_NO_RSA
  1105. cmd == SSL_CTRL_SET_TMP_RSA ||
  1106. cmd == SSL_CTRL_SET_TMP_RSA_CB ||
  1107. #endif
  1108. #ifndef OPENSSL_NO_DSA
  1109. cmd == SSL_CTRL_SET_TMP_DH ||
  1110. cmd == SSL_CTRL_SET_TMP_DH_CB ||
  1111. #endif
  1112. 0)
  1113. {
  1114. if (!ssl_cert_inst(&s->cert))
  1115. {
  1116. SSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE);
  1117. return(0);
  1118. }
  1119. }
  1120. #endif
  1121. switch (cmd)
  1122. {
  1123. case SSL_CTRL_GET_SESSION_REUSED:
  1124. ret=s->hit;
  1125. break;
  1126. case SSL_CTRL_GET_CLIENT_CERT_REQUEST:
  1127. break;
  1128. case SSL_CTRL_GET_NUM_RENEGOTIATIONS:
  1129. ret=s->s3->num_renegotiations;
  1130. break;
  1131. case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS:
  1132. ret=s->s3->num_renegotiations;
  1133. s->s3->num_renegotiations=0;
  1134. break;
  1135. case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS:
  1136. ret=s->s3->total_renegotiations;
  1137. break;
  1138. case SSL_CTRL_GET_FLAGS:
  1139. ret=(int)(s->s3->flags);
  1140. break;
  1141. #ifndef OPENSSL_NO_RSA
  1142. case SSL_CTRL_NEED_TMP_RSA:
  1143. if ((s->cert != NULL) && (s->cert->rsa_tmp == NULL) &&
  1144. ((s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
  1145. (EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8))))
  1146. ret = 1;
  1147. break;
  1148. case SSL_CTRL_SET_TMP_RSA:
  1149. {
  1150. RSA *rsa = (RSA *)parg;
  1151. if (rsa == NULL)
  1152. {
  1153. SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
  1154. return(ret);
  1155. }
  1156. if ((rsa = RSAPrivateKey_dup(rsa)) == NULL)
  1157. {
  1158. SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB);
  1159. return(ret);
  1160. }
  1161. if (s->cert->rsa_tmp != NULL)
  1162. RSA_free(s->cert->rsa_tmp);
  1163. s->cert->rsa_tmp = rsa;
  1164. ret = 1;
  1165. }
  1166. break;
  1167. case SSL_CTRL_SET_TMP_RSA_CB:
  1168. {
  1169. SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
  1170. return(ret);
  1171. }
  1172. break;
  1173. #endif
  1174. #ifndef OPENSSL_NO_DH
  1175. case SSL_CTRL_SET_TMP_DH:
  1176. {
  1177. DH *dh = (DH *)parg;
  1178. if (dh == NULL)
  1179. {
  1180. SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
  1181. return(ret);
  1182. }
  1183. if ((dh = DHparams_dup(dh)) == NULL)
  1184. {
  1185. SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
  1186. return(ret);
  1187. }
  1188. if (!(s->options & SSL_OP_SINGLE_DH_USE))
  1189. {
  1190. if (!DH_generate_key(dh))
  1191. {
  1192. DH_free(dh);
  1193. SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
  1194. return(ret);
  1195. }
  1196. }
  1197. if (s->cert->dh_tmp != NULL)
  1198. DH_free(s->cert->dh_tmp);
  1199. s->cert->dh_tmp = dh;
  1200. ret = 1;
  1201. }
  1202. break;
  1203. case SSL_CTRL_SET_TMP_DH_CB:
  1204. {
  1205. SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
  1206. return(ret);
  1207. }
  1208. break;
  1209. #endif
  1210. default:
  1211. break;
  1212. }
  1213. return(ret);
  1214. }
  1215. long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)())
  1216. {
  1217. int ret=0;
  1218. #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
  1219. if (
  1220. #ifndef OPENSSL_NO_RSA
  1221. cmd == SSL_CTRL_SET_TMP_RSA_CB ||
  1222. #endif
  1223. #ifndef OPENSSL_NO_DSA
  1224. cmd == SSL_CTRL_SET_TMP_DH_CB ||
  1225. #endif
  1226. 0)
  1227. {
  1228. if (!ssl_cert_inst(&s->cert))
  1229. {
  1230. SSLerr(SSL_F_SSL3_CALLBACK_CTRL, ERR_R_MALLOC_FAILURE);
  1231. return(0);
  1232. }
  1233. }
  1234. #endif
  1235. switch (cmd)
  1236. {
  1237. #ifndef OPENSSL_NO_RSA
  1238. case SSL_CTRL_SET_TMP_RSA_CB:
  1239. {
  1240. s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
  1241. }
  1242. break;
  1243. #endif
  1244. #ifndef OPENSSL_NO_DH
  1245. case SSL_CTRL_SET_TMP_DH_CB:
  1246. {
  1247. s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
  1248. }
  1249. break;
  1250. #endif
  1251. default:
  1252. break;
  1253. }
  1254. return(ret);
  1255. }
  1256. long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
  1257. {
  1258. CERT *cert;
  1259. cert=ctx->cert;
  1260. switch (cmd)
  1261. {
  1262. #ifndef OPENSSL_NO_RSA
  1263. case SSL_CTRL_NEED_TMP_RSA:
  1264. if ( (cert->rsa_tmp == NULL) &&
  1265. ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
  1266. (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))
  1267. )
  1268. return(1);
  1269. else
  1270. return(0);
  1271. /* break; */
  1272. case SSL_CTRL_SET_TMP_RSA:
  1273. {
  1274. RSA *rsa;
  1275. int i;
  1276. rsa=(RSA *)parg;
  1277. i=1;
  1278. if (rsa == NULL)
  1279. i=0;
  1280. else
  1281. {
  1282. if ((rsa=RSAPrivateKey_dup(rsa)) == NULL)
  1283. i=0;
  1284. }
  1285. if (!i)
  1286. {
  1287. SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB);
  1288. return(0);
  1289. }
  1290. else
  1291. {
  1292. if (cert->rsa_tmp != NULL)
  1293. RSA_free(cert->rsa_tmp);
  1294. cert->rsa_tmp=rsa;
  1295. return(1);
  1296. }
  1297. }
  1298. /* break; */
  1299. case SSL_CTRL_SET_TMP_RSA_CB:
  1300. {
  1301. SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
  1302. return(0);
  1303. }
  1304. break;
  1305. #endif
  1306. #ifndef OPENSSL_NO_DH
  1307. case SSL_CTRL_SET_TMP_DH:
  1308. {
  1309. DH *new=NULL,*dh;
  1310. dh=(DH *)parg;
  1311. if ((new=DHparams_dup(dh)) == NULL)
  1312. {
  1313. SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
  1314. return 0;
  1315. }
  1316. if (!(ctx->options & SSL_OP_SINGLE_DH_USE))
  1317. {
  1318. if (!DH_generate_key(new))
  1319. {
  1320. SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
  1321. DH_free(new);
  1322. return 0;
  1323. }
  1324. }
  1325. if (cert->dh_tmp != NULL)
  1326. DH_free(cert->dh_tmp);
  1327. cert->dh_tmp=new;
  1328. return 1;
  1329. }
  1330. /*break; */
  1331. case SSL_CTRL_SET_TMP_DH_CB:
  1332. {
  1333. SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
  1334. return(0);
  1335. }
  1336. break;
  1337. #endif
  1338. /* A Thawte special :-) */
  1339. case SSL_CTRL_EXTRA_CHAIN_CERT:
  1340. if (ctx->extra_certs == NULL)
  1341. {
  1342. if ((ctx->extra_certs=sk_X509_new_null()) == NULL)
  1343. return(0);
  1344. }
  1345. sk_X509_push(ctx->extra_certs,(X509 *)parg);
  1346. break;
  1347. default:
  1348. return(0);
  1349. }
  1350. return(1);
  1351. }
  1352. long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
  1353. {
  1354. CERT *cert;
  1355. cert=ctx->cert;
  1356. switch (cmd)
  1357. {
  1358. #ifndef OPENSSL_NO_RSA
  1359. case SSL_CTRL_SET_TMP_RSA_CB:
  1360. {
  1361. cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
  1362. }
  1363. break;
  1364. #endif
  1365. #ifndef OPENSSL_NO_DH
  1366. case SSL_CTRL_SET_TMP_DH_CB:
  1367. {
  1368. cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
  1369. }
  1370. break;
  1371. #endif
  1372. default:
  1373. return(0);
  1374. }
  1375. return(1);
  1376. }
  1377. /* This function needs to check if the ciphers required are actually
  1378. * available */
  1379. SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
  1380. {
  1381. static int init=1;
  1382. static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS];
  1383. SSL_CIPHER c,*cp= &c,**cpp;
  1384. unsigned long id;
  1385. int i;
  1386. if (init)
  1387. {
  1388. CRYPTO_w_lock(CRYPTO_LOCK_SSL);
  1389. if (init)
  1390. {
  1391. for (i=0; i<SSL3_NUM_CIPHERS; i++)
  1392. sorted[i]= &(ssl3_ciphers[i]);
  1393. qsort(sorted,
  1394. SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
  1395. FP_ICC ssl_cipher_ptr_id_cmp);
  1396. init=0;
  1397. }
  1398. CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
  1399. }
  1400. id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
  1401. c.id=id;
  1402. cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp,
  1403. (char *)sorted,
  1404. SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
  1405. FP_ICC ssl_cipher_ptr_id_cmp);
  1406. if ((cpp == NULL) || !(*cpp)->valid)
  1407. return(NULL);
  1408. else
  1409. return(*cpp);
  1410. }
  1411. int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
  1412. {
  1413. long l;
  1414. if (p != NULL)
  1415. {
  1416. l=c->id;
  1417. if ((l & 0xff000000) != 0x03000000) return(0);
  1418. p[0]=((unsigned char)(l>> 8L))&0xFF;
  1419. p[1]=((unsigned char)(l ))&0xFF;
  1420. }
  1421. return(2);
  1422. }
  1423. SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
  1424. STACK_OF(SSL_CIPHER) *srvr)
  1425. {
  1426. SSL_CIPHER *c,*ret=NULL;
  1427. STACK_OF(SSL_CIPHER) *prio, *allow;
  1428. int i,j,ok;
  1429. CERT *cert;
  1430. unsigned long alg,mask,emask;
  1431. /* Let's see which ciphers we can support */
  1432. cert=s->cert;
  1433. #if 0
  1434. /* Do not set the compare functions, because this may lead to a
  1435. * reordering by "id". We want to keep the original ordering.
  1436. * We may pay a price in performance during sk_SSL_CIPHER_find(),
  1437. * but would have to pay with the price of sk_SSL_CIPHER_dup().
  1438. */
  1439. sk_SSL_CIPHER_set_cmp_func(srvr, ssl_cipher_ptr_id_cmp);
  1440. sk_SSL_CIPHER_set_cmp_func(clnt, ssl_cipher_ptr_id_cmp);
  1441. #endif
  1442. #ifdef CIPHER_DEBUG
  1443. printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr), srvr);
  1444. for(i=0 ; i < sk_SSL_CIPHER_num(srvr) ; ++i)
  1445. {
  1446. c=sk_SSL_CIPHER_value(srvr,i);
  1447. printf("%p:%s\n",c,c->name);
  1448. }
  1449. printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt), clnt);
  1450. for(i=0 ; i < sk_SSL_CIPHER_num(clnt) ; ++i)
  1451. {
  1452. c=sk_SSL_CIPHER_value(clnt,i);
  1453. printf("%p:%s\n",c,c->name);
  1454. }
  1455. #endif
  1456. if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE)
  1457. {
  1458. prio = srvr;
  1459. allow = clnt;
  1460. }
  1461. else
  1462. {
  1463. prio = clnt;
  1464. allow = srvr;
  1465. }
  1466. for (i=0; i<sk_SSL_CIPHER_num(prio); i++)
  1467. {
  1468. c=sk_SSL_CIPHER_value(prio,i);
  1469. ssl_set_cert_masks(cert,c);
  1470. mask=cert->mask;
  1471. emask=cert->export_mask;
  1472. #ifdef KSSL_DEBUG
  1473. printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);
  1474. #endif /* KSSL_DEBUG */
  1475. alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK);
  1476. #ifndef OPENSSL_NO_KRB5
  1477. if (alg & SSL_KRB5)
  1478. {
  1479. if ( !kssl_keytab_is_available(s->kssl_ctx) )
  1480. continue;
  1481. }
  1482. #endif /* OPENSSL_NO_KRB5 */
  1483. if (SSL_C_IS_EXPORT(c))
  1484. {
  1485. ok=((alg & emask) == alg)?1:0;
  1486. #ifdef CIPHER_DEBUG
  1487. printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok,alg,emask,
  1488. c,c->name);
  1489. #endif
  1490. }
  1491. else
  1492. {
  1493. ok=((alg & mask) == alg)?1:0;
  1494. #ifdef CIPHER_DEBUG
  1495. printf("%d:[%08lX:%08lX]%p:%s\n",ok,alg,mask,c,
  1496. c->name);
  1497. #endif
  1498. }
  1499. if (!ok) continue;
  1500. j=sk_SSL_CIPHER_find(allow,c);
  1501. if (j >= 0)
  1502. {
  1503. ret=sk_SSL_CIPHER_value(allow,j);
  1504. break;
  1505. }
  1506. }
  1507. return(ret);
  1508. }
  1509. int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
  1510. {
  1511. int ret=0;
  1512. unsigned long alg;
  1513. alg=s->s3->tmp.new_cipher->algorithms;
  1514. #ifndef OPENSSL_NO_DH
  1515. if (alg & (SSL_kDHr|SSL_kEDH))
  1516. {
  1517. # ifndef OPENSSL_NO_RSA
  1518. p[ret++]=SSL3_CT_RSA_FIXED_DH;
  1519. # endif
  1520. # ifndef OPENSSL_NO_DSA
  1521. p[ret++]=SSL3_CT_DSS_FIXED_DH;
  1522. # endif
  1523. }
  1524. if ((s->version == SSL3_VERSION) &&
  1525. (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr)))
  1526. {
  1527. # ifndef OPENSSL_NO_RSA
  1528. p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH;
  1529. # endif
  1530. # ifndef OPENSSL_NO_DSA
  1531. p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH;
  1532. # endif
  1533. }
  1534. #endif /* !OPENSSL_NO_DH */
  1535. #ifndef OPENSSL_NO_RSA
  1536. p[ret++]=SSL3_CT_RSA_SIGN;
  1537. #endif
  1538. #ifndef OPENSSL_NO_DSA
  1539. p[ret++]=SSL3_CT_DSS_SIGN;
  1540. #endif
  1541. return(ret);
  1542. }
  1543. int ssl3_shutdown(SSL *s)
  1544. {
  1545. /* Don't do anything much if we have not done the handshake or
  1546. * we don't want to send messages :-) */
  1547. if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE))
  1548. {
  1549. s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
  1550. return(1);
  1551. }
  1552. if (!(s->shutdown & SSL_SENT_SHUTDOWN))
  1553. {
  1554. s->shutdown|=SSL_SENT_SHUTDOWN;
  1555. #if 1
  1556. ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY);
  1557. #endif
  1558. /* our shutdown alert has been sent now, and if it still needs
  1559. * to be written, s->s3->alert_dispatch will be true */
  1560. }
  1561. else if (s->s3->alert_dispatch)
  1562. {
  1563. /* resend it if not sent */
  1564. #if 1
  1565. ssl3_dispatch_alert(s);
  1566. #endif
  1567. }
  1568. else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
  1569. {
  1570. /* If we are waiting for a close from our peer, we are closed */
  1571. ssl3_read_bytes(s,0,NULL,0,0);
  1572. }
  1573. if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
  1574. !s->s3->alert_dispatch)
  1575. return(1);
  1576. else
  1577. return(0);
  1578. }
  1579. int ssl3_write(SSL *s, const void *buf, int len)
  1580. {
  1581. int ret,n;
  1582. #if 0
  1583. if (s->shutdown & SSL_SEND_SHUTDOWN)
  1584. {
  1585. s->rwstate=SSL_NOTHING;
  1586. return(0);
  1587. }
  1588. #endif
  1589. clear_sys_error();
  1590. if (s->s3->renegotiate) ssl3_renegotiate_check(s);
  1591. /* This is an experimental flag that sends the
  1592. * last handshake message in the same packet as the first
  1593. * use data - used to see if it helps the TCP protocol during
  1594. * session-id reuse */
  1595. /* The second test is because the buffer may have been removed */
  1596. if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
  1597. {
  1598. /* First time through, we write into the buffer */
  1599. if (s->s3->delay_buf_pop_ret == 0)
  1600. {
  1601. ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
  1602. buf,len);
  1603. if (ret <= 0) return(ret);
  1604. s->s3->delay_buf_pop_ret=ret;
  1605. }
  1606. s->rwstate=SSL_WRITING;
  1607. n=BIO_flush(s->wbio);
  1608. if (n <= 0) return(n);
  1609. s->rwstate=SSL_NOTHING;
  1610. /* We have flushed the buffer, so remove it */
  1611. ssl_free_wbio_buffer(s);
  1612. s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
  1613. ret=s->s3->delay_buf_pop_ret;
  1614. s->s3->delay_buf_pop_ret=0;
  1615. }
  1616. else
  1617. {
  1618. ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
  1619. buf,len);
  1620. if (ret <= 0) return(ret);
  1621. }
  1622. return(ret);
  1623. }
  1624. static int ssl3_read_internal(SSL *s, void *buf, int len, int peek)
  1625. {
  1626. int ret;
  1627. clear_sys_error();
  1628. if (s->s3->renegotiate) ssl3_renegotiate_check(s);
  1629. s->s3->in_read_app_data=1;
  1630. ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
  1631. if ((ret == -1) && (s->s3->in_read_app_data == 2))
  1632. {
  1633. /* ssl3_read_bytes decided to call s->handshake_func, which
  1634. * called ssl3_read_bytes to read handshake data.
  1635. * However, ssl3_read_bytes actually found application data
  1636. * and thinks that application data makes sense here; so disable
  1637. * handshake processing and try to read application data again. */
  1638. s->in_handshake++;
  1639. ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
  1640. s->in_handshake--;
  1641. }
  1642. else
  1643. s->s3->in_read_app_data=0;
  1644. return(ret);
  1645. }
  1646. int ssl3_read(SSL *s, void *buf, int len)
  1647. {
  1648. return ssl3_read_internal(s, buf, len, 0);
  1649. }
  1650. int ssl3_peek(SSL *s, void *buf, int len)
  1651. {
  1652. return ssl3_read_internal(s, buf, len, 1);
  1653. }
  1654. int ssl3_renegotiate(SSL *s)
  1655. {
  1656. if (s->handshake_func == NULL)
  1657. return(1);
  1658. if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
  1659. return(0);
  1660. s->s3->renegotiate=1;
  1661. return(1);
  1662. }
  1663. int ssl3_renegotiate_check(SSL *s)
  1664. {
  1665. int ret=0;
  1666. if (s->s3->renegotiate)
  1667. {
  1668. if ( (s->s3->rbuf.left == 0) &&
  1669. (s->s3->wbuf.left == 0) &&
  1670. !SSL_in_init(s))
  1671. {
  1672. /*
  1673. if we are the server, and we have sent a 'RENEGOTIATE' message, we
  1674. need to go to SSL_ST_ACCEPT.
  1675. */
  1676. /* SSL_ST_ACCEPT */
  1677. s->state=SSL_ST_RENEGOTIATE;
  1678. s->s3->renegotiate=0;
  1679. s->s3->num_renegotiations++;
  1680. s->s3->total_renegotiations++;
  1681. ret=1;
  1682. }
  1683. }
  1684. return(ret);
  1685. }