ssl_ciph.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. /* ssl/ssl_ciph.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. #include <stdio.h>
  59. #include <openssl/objects.h>
  60. #include <openssl/comp.h>
  61. #include "ssl_locl.h"
  62. #define SSL_ENC_DES_IDX 0
  63. #define SSL_ENC_3DES_IDX 1
  64. #define SSL_ENC_RC4_IDX 2
  65. #define SSL_ENC_RC2_IDX 3
  66. #define SSL_ENC_IDEA_IDX 4
  67. #define SSL_ENC_eFZA_IDX 5
  68. #define SSL_ENC_NULL_IDX 6
  69. #define SSL_ENC_AES128_IDX 7
  70. #define SSL_ENC_AES256_IDX 8
  71. #define SSL_ENC_NUM_IDX 9
  72. static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={
  73. NULL,NULL,NULL,NULL,NULL,NULL,
  74. };
  75. static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL;
  76. #define SSL_MD_MD5_IDX 0
  77. #define SSL_MD_SHA1_IDX 1
  78. #define SSL_MD_NUM_IDX 2
  79. static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={
  80. NULL,NULL,
  81. };
  82. #define CIPHER_ADD 1
  83. #define CIPHER_KILL 2
  84. #define CIPHER_DEL 3
  85. #define CIPHER_ORD 4
  86. #define CIPHER_SPECIAL 5
  87. typedef struct cipher_order_st
  88. {
  89. SSL_CIPHER *cipher;
  90. int active;
  91. int dead;
  92. struct cipher_order_st *next,*prev;
  93. } CIPHER_ORDER;
  94. static const SSL_CIPHER cipher_aliases[]={
  95. /* Don't include eNULL unless specifically enabled. */
  96. {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */
  97. {0,SSL_TXT_CMPALL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, /* COMPLEMENT OF ALL */
  98. {0,SSL_TXT_CMPDEF,0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK,0},
  99. {0,SSL_TXT_kKRB5,0,SSL_kKRB5,0,0,0,0,SSL_MKEY_MASK,0}, /* VRS Kerberos5 */
  100. {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0},
  101. {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0},
  102. {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0},
  103. {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0},
  104. {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0},
  105. {0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0},
  106. {0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0},
  107. {0,SSL_TXT_aKRB5,0,SSL_aKRB5,0,0,0,0,SSL_AUTH_MASK,0}, /* VRS Kerberos5 */
  108. {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0},
  109. {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0},
  110. {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,0,0,0,SSL_AUTH_MASK,0},
  111. {0,SSL_TXT_aNULL,0,SSL_aNULL,0,0,0,0,SSL_AUTH_MASK,0},
  112. {0,SSL_TXT_aDH, 0,SSL_aDH, 0,0,0,0,SSL_AUTH_MASK,0},
  113. {0,SSL_TXT_DSS, 0,SSL_DSS, 0,0,0,0,SSL_AUTH_MASK,0},
  114. {0,SSL_TXT_DES, 0,SSL_DES, 0,0,0,0,SSL_ENC_MASK,0},
  115. {0,SSL_TXT_3DES,0,SSL_3DES, 0,0,0,0,SSL_ENC_MASK,0},
  116. {0,SSL_TXT_RC4, 0,SSL_RC4, 0,0,0,0,SSL_ENC_MASK,0},
  117. {0,SSL_TXT_RC2, 0,SSL_RC2, 0,0,0,0,SSL_ENC_MASK,0},
  118. #ifndef OPENSSL_NO_IDEA
  119. {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0},
  120. #endif
  121. {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0},
  122. {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0},
  123. {0,SSL_TXT_AES, 0,SSL_AES, 0,0,0,0,SSL_ENC_MASK,0},
  124. {0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0},
  125. {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0},
  126. {0,SSL_TXT_SHA, 0,SSL_SHA, 0,0,0,0,SSL_MAC_MASK,0},
  127. {0,SSL_TXT_NULL,0,SSL_NULL, 0,0,0,0,SSL_ENC_MASK,0},
  128. {0,SSL_TXT_KRB5,0,SSL_KRB5, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
  129. {0,SSL_TXT_RSA, 0,SSL_RSA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
  130. {0,SSL_TXT_ADH, 0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
  131. {0,SSL_TXT_FZA, 0,SSL_FZA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK,0},
  132. {0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,0,0,0,SSL_SSL_MASK,0},
  133. {0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,0,0,0,SSL_SSL_MASK,0},
  134. {0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,0,0,0,SSL_SSL_MASK,0},
  135. {0,SSL_TXT_EXP ,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
  136. {0,SSL_TXT_EXPORT,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
  137. {0,SSL_TXT_EXP40, 0, 0, SSL_EXP40, 0,0,0,0,SSL_STRONG_MASK},
  138. {0,SSL_TXT_EXP56, 0, 0, SSL_EXP56, 0,0,0,0,SSL_STRONG_MASK},
  139. {0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK},
  140. {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK},
  141. {0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK},
  142. };
  143. static int init_ciphers=1;
  144. static void load_ciphers(void)
  145. {
  146. init_ciphers=0;
  147. ssl_cipher_methods[SSL_ENC_DES_IDX]=
  148. EVP_get_cipherbyname(SN_des_cbc);
  149. ssl_cipher_methods[SSL_ENC_3DES_IDX]=
  150. EVP_get_cipherbyname(SN_des_ede3_cbc);
  151. ssl_cipher_methods[SSL_ENC_RC4_IDX]=
  152. EVP_get_cipherbyname(SN_rc4);
  153. ssl_cipher_methods[SSL_ENC_RC2_IDX]=
  154. EVP_get_cipherbyname(SN_rc2_cbc);
  155. #ifndef OPENSSL_NO_IDEA
  156. ssl_cipher_methods[SSL_ENC_IDEA_IDX]=
  157. EVP_get_cipherbyname(SN_idea_cbc);
  158. #else
  159. ssl_cipher_methods[SSL_ENC_IDEA_IDX]= NULL;
  160. #endif
  161. ssl_cipher_methods[SSL_ENC_AES128_IDX]=
  162. EVP_get_cipherbyname(SN_aes_128_cbc);
  163. ssl_cipher_methods[SSL_ENC_AES256_IDX]=
  164. EVP_get_cipherbyname(SN_aes_256_cbc);
  165. ssl_digest_methods[SSL_MD_MD5_IDX]=
  166. EVP_get_digestbyname(SN_md5);
  167. ssl_digest_methods[SSL_MD_SHA1_IDX]=
  168. EVP_get_digestbyname(SN_sha1);
  169. }
  170. int ssl_cipher_get_evp(SSL_SESSION *s, const EVP_CIPHER **enc,
  171. const EVP_MD **md, SSL_COMP **comp)
  172. {
  173. int i;
  174. SSL_CIPHER *c;
  175. c=s->cipher;
  176. if (c == NULL) return(0);
  177. if (comp != NULL)
  178. {
  179. SSL_COMP ctmp;
  180. if (s->compress_meth == 0)
  181. *comp=NULL;
  182. else if (ssl_comp_methods == NULL)
  183. {
  184. /* bad */
  185. *comp=NULL;
  186. }
  187. else
  188. {
  189. ctmp.id=s->compress_meth;
  190. i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp);
  191. if (i >= 0)
  192. *comp=sk_SSL_COMP_value(ssl_comp_methods,i);
  193. else
  194. *comp=NULL;
  195. }
  196. }
  197. if ((enc == NULL) || (md == NULL)) return(0);
  198. switch (c->algorithms & SSL_ENC_MASK)
  199. {
  200. case SSL_DES:
  201. i=SSL_ENC_DES_IDX;
  202. break;
  203. case SSL_3DES:
  204. i=SSL_ENC_3DES_IDX;
  205. break;
  206. case SSL_RC4:
  207. i=SSL_ENC_RC4_IDX;
  208. break;
  209. case SSL_RC2:
  210. i=SSL_ENC_RC2_IDX;
  211. break;
  212. case SSL_IDEA:
  213. i=SSL_ENC_IDEA_IDX;
  214. break;
  215. case SSL_eNULL:
  216. i=SSL_ENC_NULL_IDX;
  217. break;
  218. case SSL_AES:
  219. switch(c->alg_bits)
  220. {
  221. case 128: i=SSL_ENC_AES128_IDX; break;
  222. case 256: i=SSL_ENC_AES256_IDX; break;
  223. default: i=-1; break;
  224. }
  225. break;
  226. default:
  227. i= -1;
  228. break;
  229. }
  230. if ((i < 0) || (i > SSL_ENC_NUM_IDX))
  231. *enc=NULL;
  232. else
  233. {
  234. if (i == SSL_ENC_NULL_IDX)
  235. *enc=EVP_enc_null();
  236. else
  237. *enc=ssl_cipher_methods[i];
  238. }
  239. switch (c->algorithms & SSL_MAC_MASK)
  240. {
  241. case SSL_MD5:
  242. i=SSL_MD_MD5_IDX;
  243. break;
  244. case SSL_SHA1:
  245. i=SSL_MD_SHA1_IDX;
  246. break;
  247. default:
  248. i= -1;
  249. break;
  250. }
  251. if ((i < 0) || (i > SSL_MD_NUM_IDX))
  252. *md=NULL;
  253. else
  254. *md=ssl_digest_methods[i];
  255. if ((*enc != NULL) && (*md != NULL))
  256. return(1);
  257. else
  258. return(0);
  259. }
  260. #define ITEM_SEP(a) \
  261. (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
  262. static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
  263. CIPHER_ORDER **tail)
  264. {
  265. if (curr == *tail) return;
  266. if (curr == *head)
  267. *head=curr->next;
  268. if (curr->prev != NULL)
  269. curr->prev->next=curr->next;
  270. if (curr->next != NULL) /* should always be true */
  271. curr->next->prev=curr->prev;
  272. (*tail)->next=curr;
  273. curr->prev= *tail;
  274. curr->next=NULL;
  275. *tail=curr;
  276. }
  277. static unsigned long ssl_cipher_get_disabled(void)
  278. {
  279. unsigned long mask;
  280. mask = SSL_kFZA;
  281. #ifdef OPENSSL_NO_RSA
  282. mask |= SSL_aRSA|SSL_kRSA;
  283. #endif
  284. #ifdef OPENSSL_NO_DSA
  285. mask |= SSL_aDSS;
  286. #endif
  287. #ifdef OPENSSL_NO_DH
  288. mask |= SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH;
  289. #endif
  290. #ifdef OPENSSL_NO_KRB5
  291. mask |= SSL_kKRB5|SSL_aKRB5;
  292. #endif
  293. #ifdef SSL_FORBID_ENULL
  294. mask |= SSL_eNULL;
  295. #endif
  296. mask |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0;
  297. mask |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0;
  298. mask |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0;
  299. mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0;
  300. mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0;
  301. mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0;
  302. mask |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES:0;
  303. mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0;
  304. mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0;
  305. return(mask);
  306. }
  307. static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
  308. int num_of_ciphers, unsigned long mask, CIPHER_ORDER *co_list,
  309. CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
  310. {
  311. int i, co_list_num;
  312. SSL_CIPHER *c;
  313. /*
  314. * We have num_of_ciphers descriptions compiled in, depending on the
  315. * method selected (SSLv2 and/or SSLv3, TLSv1 etc).
  316. * These will later be sorted in a linked list with at most num
  317. * entries.
  318. */
  319. /* Get the initial list of ciphers */
  320. co_list_num = 0; /* actual count of ciphers */
  321. for (i = 0; i < num_of_ciphers; i++)
  322. {
  323. c = ssl_method->get_cipher(i);
  324. /* drop those that use any of that is not available */
  325. if ((c != NULL) && c->valid && !(c->algorithms & mask))
  326. {
  327. co_list[co_list_num].cipher = c;
  328. co_list[co_list_num].next = NULL;
  329. co_list[co_list_num].prev = NULL;
  330. co_list[co_list_num].active = 0;
  331. co_list_num++;
  332. #ifdef KSSL_DEBUG
  333. printf("\t%d: %s %lx %lx\n",i,c->name,c->id,c->algorithms);
  334. #endif /* KSSL_DEBUG */
  335. /*
  336. if (!sk_push(ca_list,(char *)c)) goto err;
  337. */
  338. }
  339. }
  340. /*
  341. * Prepare linked list from list entries
  342. */
  343. for (i = 1; i < co_list_num - 1; i++)
  344. {
  345. co_list[i].prev = &(co_list[i-1]);
  346. co_list[i].next = &(co_list[i+1]);
  347. }
  348. if (co_list_num > 0)
  349. {
  350. (*head_p) = &(co_list[0]);
  351. (*head_p)->prev = NULL;
  352. (*head_p)->next = &(co_list[1]);
  353. (*tail_p) = &(co_list[co_list_num - 1]);
  354. (*tail_p)->prev = &(co_list[co_list_num - 2]);
  355. (*tail_p)->next = NULL;
  356. }
  357. }
  358. static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list,
  359. int num_of_group_aliases, unsigned long mask,
  360. CIPHER_ORDER *head)
  361. {
  362. CIPHER_ORDER *ciph_curr;
  363. SSL_CIPHER **ca_curr;
  364. int i;
  365. /*
  366. * First, add the real ciphers as already collected
  367. */
  368. ciph_curr = head;
  369. ca_curr = ca_list;
  370. while (ciph_curr != NULL)
  371. {
  372. *ca_curr = ciph_curr->cipher;
  373. ca_curr++;
  374. ciph_curr = ciph_curr->next;
  375. }
  376. /*
  377. * Now we add the available ones from the cipher_aliases[] table.
  378. * They represent either an algorithm, that must be fully
  379. * supported (not match any bit in mask) or represent a cipher
  380. * strength value (will be added in any case because algorithms=0).
  381. */
  382. for (i = 0; i < num_of_group_aliases; i++)
  383. {
  384. if ((i == 0) || /* always fetch "ALL" */
  385. !(cipher_aliases[i].algorithms & mask))
  386. {
  387. *ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
  388. ca_curr++;
  389. }
  390. }
  391. *ca_curr = NULL; /* end of list */
  392. }
  393. static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask,
  394. unsigned long algo_strength, unsigned long mask_strength,
  395. int rule, int strength_bits, CIPHER_ORDER *co_list,
  396. CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
  397. {
  398. CIPHER_ORDER *head, *tail, *curr, *curr2, *tail2;
  399. SSL_CIPHER *cp;
  400. unsigned long ma, ma_s;
  401. #ifdef CIPHER_DEBUG
  402. printf("Applying rule %d with %08lx %08lx %08lx %08lx (%d)\n",
  403. rule, algorithms, mask, algo_strength, mask_strength,
  404. strength_bits);
  405. #endif
  406. curr = head = *head_p;
  407. curr2 = head;
  408. tail2 = tail = *tail_p;
  409. for (;;)
  410. {
  411. if ((curr == NULL) || (curr == tail2)) break;
  412. curr = curr2;
  413. curr2 = curr->next;
  414. cp = curr->cipher;
  415. /*
  416. * Selection criteria is either the number of strength_bits
  417. * or the algorithm used.
  418. */
  419. if (strength_bits == -1)
  420. {
  421. ma = mask & cp->algorithms;
  422. ma_s = mask_strength & cp->algo_strength;
  423. #ifdef CIPHER_DEBUG
  424. printf("\nName: %s:\nAlgo = %08lx Algo_strength = %08lx\nMask = %08lx Mask_strength %08lx\n", cp->name, cp->algorithms, cp->algo_strength, mask, mask_strength);
  425. printf("ma = %08lx ma_s %08lx, ma&algo=%08lx, ma_s&algos=%08lx\n", ma, ma_s, ma&algorithms, ma_s&algo_strength);
  426. #endif
  427. /*
  428. * Select: if none of the mask bit was met from the
  429. * cipher or not all of the bits were met, the
  430. * selection does not apply.
  431. */
  432. if (((ma == 0) && (ma_s == 0)) ||
  433. ((ma & algorithms) != ma) ||
  434. ((ma_s & algo_strength) != ma_s))
  435. continue; /* does not apply */
  436. }
  437. else if (strength_bits != cp->strength_bits)
  438. continue; /* does not apply */
  439. #ifdef CIPHER_DEBUG
  440. printf("Action = %d\n", rule);
  441. #endif
  442. /* add the cipher if it has not been added yet. */
  443. if (rule == CIPHER_ADD)
  444. {
  445. if (!curr->active)
  446. {
  447. ll_append_tail(&head, curr, &tail);
  448. curr->active = 1;
  449. }
  450. }
  451. /* Move the added cipher to this location */
  452. else if (rule == CIPHER_ORD)
  453. {
  454. if (curr->active)
  455. {
  456. ll_append_tail(&head, curr, &tail);
  457. }
  458. }
  459. else if (rule == CIPHER_DEL)
  460. curr->active = 0;
  461. else if (rule == CIPHER_KILL)
  462. {
  463. if (head == curr)
  464. head = curr->next;
  465. else
  466. curr->prev->next = curr->next;
  467. if (tail == curr)
  468. tail = curr->prev;
  469. curr->active = 0;
  470. if (curr->next != NULL)
  471. curr->next->prev = curr->prev;
  472. if (curr->prev != NULL)
  473. curr->prev->next = curr->next;
  474. curr->next = NULL;
  475. curr->prev = NULL;
  476. }
  477. }
  478. *head_p = head;
  479. *tail_p = tail;
  480. }
  481. static int ssl_cipher_strength_sort(CIPHER_ORDER *co_list,
  482. CIPHER_ORDER **head_p,
  483. CIPHER_ORDER **tail_p)
  484. {
  485. int max_strength_bits, i, *number_uses;
  486. CIPHER_ORDER *curr;
  487. /*
  488. * This routine sorts the ciphers with descending strength. The sorting
  489. * must keep the pre-sorted sequence, so we apply the normal sorting
  490. * routine as '+' movement to the end of the list.
  491. */
  492. max_strength_bits = 0;
  493. curr = *head_p;
  494. while (curr != NULL)
  495. {
  496. if (curr->active &&
  497. (curr->cipher->strength_bits > max_strength_bits))
  498. max_strength_bits = curr->cipher->strength_bits;
  499. curr = curr->next;
  500. }
  501. number_uses = OPENSSL_malloc((max_strength_bits + 1) * sizeof(int));
  502. if (!number_uses)
  503. {
  504. SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT,ERR_R_MALLOC_FAILURE);
  505. return(0);
  506. }
  507. memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int));
  508. /*
  509. * Now find the strength_bits values actually used
  510. */
  511. curr = *head_p;
  512. while (curr != NULL)
  513. {
  514. if (curr->active)
  515. number_uses[curr->cipher->strength_bits]++;
  516. curr = curr->next;
  517. }
  518. /*
  519. * Go through the list of used strength_bits values in descending
  520. * order.
  521. */
  522. for (i = max_strength_bits; i >= 0; i--)
  523. if (number_uses[i] > 0)
  524. ssl_cipher_apply_rule(0, 0, 0, 0, CIPHER_ORD, i,
  525. co_list, head_p, tail_p);
  526. OPENSSL_free(number_uses);
  527. return(1);
  528. }
  529. static int ssl_cipher_process_rulestr(const char *rule_str,
  530. CIPHER_ORDER *co_list, CIPHER_ORDER **head_p,
  531. CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list)
  532. {
  533. unsigned long algorithms, mask, algo_strength, mask_strength;
  534. const char *l, *start, *buf;
  535. int j, multi, found, rule, retval, ok, buflen;
  536. char ch;
  537. retval = 1;
  538. l = rule_str;
  539. for (;;)
  540. {
  541. ch = *l;
  542. if (ch == '\0')
  543. break; /* done */
  544. if (ch == '-')
  545. { rule = CIPHER_DEL; l++; }
  546. else if (ch == '+')
  547. { rule = CIPHER_ORD; l++; }
  548. else if (ch == '!')
  549. { rule = CIPHER_KILL; l++; }
  550. else if (ch == '@')
  551. { rule = CIPHER_SPECIAL; l++; }
  552. else
  553. { rule = CIPHER_ADD; }
  554. if (ITEM_SEP(ch))
  555. {
  556. l++;
  557. continue;
  558. }
  559. algorithms = mask = algo_strength = mask_strength = 0;
  560. start=l;
  561. for (;;)
  562. {
  563. ch = *l;
  564. buf = l;
  565. buflen = 0;
  566. #ifndef CHARSET_EBCDIC
  567. while ( ((ch >= 'A') && (ch <= 'Z')) ||
  568. ((ch >= '0') && (ch <= '9')) ||
  569. ((ch >= 'a') && (ch <= 'z')) ||
  570. (ch == '-'))
  571. #else
  572. while ( isalnum(ch) || (ch == '-'))
  573. #endif
  574. {
  575. ch = *(++l);
  576. buflen++;
  577. }
  578. if (buflen == 0)
  579. {
  580. /*
  581. * We hit something we cannot deal with,
  582. * it is no command or separator nor
  583. * alphanumeric, so we call this an error.
  584. */
  585. SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
  586. SSL_R_INVALID_COMMAND);
  587. retval = found = 0;
  588. l++;
  589. break;
  590. }
  591. if (rule == CIPHER_SPECIAL)
  592. {
  593. found = 0; /* unused -- avoid compiler warning */
  594. break; /* special treatment */
  595. }
  596. /* check for multi-part specification */
  597. if (ch == '+')
  598. {
  599. multi=1;
  600. l++;
  601. }
  602. else
  603. multi=0;
  604. /*
  605. * Now search for the cipher alias in the ca_list. Be careful
  606. * with the strncmp, because the "buflen" limitation
  607. * will make the rule "ADH:SOME" and the cipher
  608. * "ADH-MY-CIPHER" look like a match for buflen=3.
  609. * So additionally check whether the cipher name found
  610. * has the correct length. We can save a strlen() call:
  611. * just checking for the '\0' at the right place is
  612. * sufficient, we have to strncmp() anyway. (We cannot
  613. * use strcmp(), because buf is not '\0' terminated.)
  614. */
  615. j = found = 0;
  616. while (ca_list[j])
  617. {
  618. if (!strncmp(buf, ca_list[j]->name, buflen) &&
  619. (ca_list[j]->name[buflen] == '\0'))
  620. {
  621. found = 1;
  622. break;
  623. }
  624. else
  625. j++;
  626. }
  627. if (!found)
  628. break; /* ignore this entry */
  629. algorithms |= ca_list[j]->algorithms;
  630. mask |= ca_list[j]->mask;
  631. algo_strength |= ca_list[j]->algo_strength;
  632. mask_strength |= ca_list[j]->mask_strength;
  633. if (!multi) break;
  634. }
  635. /*
  636. * Ok, we have the rule, now apply it
  637. */
  638. if (rule == CIPHER_SPECIAL)
  639. { /* special command */
  640. ok = 0;
  641. if ((buflen == 8) &&
  642. !strncmp(buf, "STRENGTH", 8))
  643. ok = ssl_cipher_strength_sort(co_list,
  644. head_p, tail_p);
  645. else
  646. SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
  647. SSL_R_INVALID_COMMAND);
  648. if (ok == 0)
  649. retval = 0;
  650. /*
  651. * We do not support any "multi" options
  652. * together with "@", so throw away the
  653. * rest of the command, if any left, until
  654. * end or ':' is found.
  655. */
  656. while ((*l != '\0') && ITEM_SEP(*l))
  657. l++;
  658. }
  659. else if (found)
  660. {
  661. ssl_cipher_apply_rule(algorithms, mask,
  662. algo_strength, mask_strength, rule, -1,
  663. co_list, head_p, tail_p);
  664. }
  665. else
  666. {
  667. while ((*l != '\0') && ITEM_SEP(*l))
  668. l++;
  669. }
  670. if (*l == '\0') break; /* done */
  671. }
  672. return(retval);
  673. }
  674. STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
  675. STACK_OF(SSL_CIPHER) **cipher_list,
  676. STACK_OF(SSL_CIPHER) **cipher_list_by_id,
  677. const char *rule_str)
  678. {
  679. int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
  680. unsigned long disabled_mask;
  681. STACK_OF(SSL_CIPHER) *cipherstack;
  682. const char *rule_p;
  683. CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;
  684. SSL_CIPHER **ca_list = NULL;
  685. /*
  686. * Return with error if nothing to do.
  687. */
  688. if (rule_str == NULL) return(NULL);
  689. if (init_ciphers)
  690. {
  691. CRYPTO_w_lock(CRYPTO_LOCK_SSL);
  692. if (init_ciphers) load_ciphers();
  693. CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
  694. }
  695. /*
  696. * To reduce the work to do we only want to process the compiled
  697. * in algorithms, so we first get the mask of disabled ciphers.
  698. */
  699. disabled_mask = ssl_cipher_get_disabled();
  700. /*
  701. * Now we have to collect the available ciphers from the compiled
  702. * in ciphers. We cannot get more than the number compiled in, so
  703. * it is used for allocation.
  704. */
  705. num_of_ciphers = ssl_method->num_ciphers();
  706. #ifdef KSSL_DEBUG
  707. printf("ssl_create_cipher_list() for %d ciphers\n", num_of_ciphers);
  708. #endif /* KSSL_DEBUG */
  709. co_list = (CIPHER_ORDER *)OPENSSL_malloc(sizeof(CIPHER_ORDER) * num_of_ciphers);
  710. if (co_list == NULL)
  711. {
  712. SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
  713. return(NULL); /* Failure */
  714. }
  715. ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask,
  716. co_list, &head, &tail);
  717. /*
  718. * We also need cipher aliases for selecting based on the rule_str.
  719. * There might be two types of entries in the rule_str: 1) names
  720. * of ciphers themselves 2) aliases for groups of ciphers.
  721. * For 1) we need the available ciphers and for 2) the cipher
  722. * groups of cipher_aliases added together in one list (otherwise
  723. * we would be happy with just the cipher_aliases table).
  724. */
  725. num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
  726. num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
  727. ca_list =
  728. (SSL_CIPHER **)OPENSSL_malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
  729. if (ca_list == NULL)
  730. {
  731. OPENSSL_free(co_list);
  732. SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
  733. return(NULL); /* Failure */
  734. }
  735. ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mask,
  736. head);
  737. /*
  738. * If the rule_string begins with DEFAULT, apply the default rule
  739. * before using the (possibly available) additional rules.
  740. */
  741. ok = 1;
  742. rule_p = rule_str;
  743. if (strncmp(rule_str,"DEFAULT",7) == 0)
  744. {
  745. ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,
  746. co_list, &head, &tail, ca_list);
  747. rule_p += 7;
  748. if (*rule_p == ':')
  749. rule_p++;
  750. }
  751. if (ok && (strlen(rule_p) > 0))
  752. ok = ssl_cipher_process_rulestr(rule_p, co_list, &head, &tail,
  753. ca_list);
  754. OPENSSL_free(ca_list); /* Not needed anymore */
  755. if (!ok)
  756. { /* Rule processing failure */
  757. OPENSSL_free(co_list);
  758. return(NULL);
  759. }
  760. /*
  761. * Allocate new "cipherstack" for the result, return with error
  762. * if we cannot get one.
  763. */
  764. if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL)
  765. {
  766. OPENSSL_free(co_list);
  767. return(NULL);
  768. }
  769. /*
  770. * The cipher selection for the list is done. The ciphers are added
  771. * to the resulting precedence to the STACK_OF(SSL_CIPHER).
  772. */
  773. for (curr = head; curr != NULL; curr = curr->next)
  774. {
  775. if (curr->active)
  776. {
  777. sk_SSL_CIPHER_push(cipherstack, curr->cipher);
  778. #ifdef CIPHER_DEBUG
  779. printf("<%s>\n",curr->cipher->name);
  780. #endif
  781. }
  782. }
  783. OPENSSL_free(co_list); /* Not needed any longer */
  784. /*
  785. * The following passage is a little bit odd. If pointer variables
  786. * were supplied to hold STACK_OF(SSL_CIPHER) return information,
  787. * the old memory pointed to is free()ed. Then, however, the
  788. * cipher_list entry will be assigned just a copy of the returned
  789. * cipher stack. For cipher_list_by_id a copy of the cipher stack
  790. * will be created. See next comment...
  791. */
  792. if (cipher_list != NULL)
  793. {
  794. if (*cipher_list != NULL)
  795. sk_SSL_CIPHER_free(*cipher_list);
  796. *cipher_list = cipherstack;
  797. }
  798. if (cipher_list_by_id != NULL)
  799. {
  800. if (*cipher_list_by_id != NULL)
  801. sk_SSL_CIPHER_free(*cipher_list_by_id);
  802. *cipher_list_by_id = sk_SSL_CIPHER_dup(cipherstack);
  803. }
  804. /*
  805. * Now it is getting really strange. If something failed during
  806. * the previous pointer assignment or if one of the pointers was
  807. * not requested, the error condition is met. That might be
  808. * discussable. The strange thing is however that in this case
  809. * the memory "ret" pointed to is "free()ed" and hence the pointer
  810. * cipher_list becomes wild. The memory reserved for
  811. * cipher_list_by_id however is not "free()ed" and stays intact.
  812. */
  813. if ( (cipher_list_by_id == NULL) ||
  814. (*cipher_list_by_id == NULL) ||
  815. (cipher_list == NULL) ||
  816. (*cipher_list == NULL))
  817. {
  818. sk_SSL_CIPHER_free(cipherstack);
  819. return(NULL);
  820. }
  821. sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp);
  822. return(cipherstack);
  823. }
  824. char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len)
  825. {
  826. int is_export,pkl,kl;
  827. char *ver,*exp_str;
  828. char *kx,*au,*enc,*mac;
  829. unsigned long alg,alg2,alg_s;
  830. #ifdef KSSL_DEBUG
  831. static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx\n";
  832. #else
  833. static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
  834. #endif /* KSSL_DEBUG */
  835. alg=cipher->algorithms;
  836. alg_s=cipher->algo_strength;
  837. alg2=cipher->algorithm2;
  838. is_export=SSL_C_IS_EXPORT(cipher);
  839. pkl=SSL_C_EXPORT_PKEYLENGTH(cipher);
  840. kl=SSL_C_EXPORT_KEYLENGTH(cipher);
  841. exp_str=is_export?" export":"";
  842. if (alg & SSL_SSLV2)
  843. ver="SSLv2";
  844. else if (alg & SSL_SSLV3)
  845. ver="SSLv3";
  846. else
  847. ver="unknown";
  848. switch (alg&SSL_MKEY_MASK)
  849. {
  850. case SSL_kRSA:
  851. kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA";
  852. break;
  853. case SSL_kDHr:
  854. kx="DH/RSA";
  855. break;
  856. case SSL_kDHd:
  857. kx="DH/DSS";
  858. break;
  859. case SSL_kKRB5: /* VRS */
  860. case SSL_KRB5: /* VRS */
  861. kx="KRB5";
  862. break;
  863. case SSL_kFZA:
  864. kx="Fortezza";
  865. break;
  866. case SSL_kEDH:
  867. kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH";
  868. break;
  869. default:
  870. kx="unknown";
  871. }
  872. switch (alg&SSL_AUTH_MASK)
  873. {
  874. case SSL_aRSA:
  875. au="RSA";
  876. break;
  877. case SSL_aDSS:
  878. au="DSS";
  879. break;
  880. case SSL_aDH:
  881. au="DH";
  882. break;
  883. case SSL_aKRB5: /* VRS */
  884. case SSL_KRB5: /* VRS */
  885. au="KRB5";
  886. break;
  887. case SSL_aFZA:
  888. case SSL_aNULL:
  889. au="None";
  890. break;
  891. default:
  892. au="unknown";
  893. break;
  894. }
  895. switch (alg&SSL_ENC_MASK)
  896. {
  897. case SSL_DES:
  898. enc=(is_export && kl == 5)?"DES(40)":"DES(56)";
  899. break;
  900. case SSL_3DES:
  901. enc="3DES(168)";
  902. break;
  903. case SSL_RC4:
  904. enc=is_export?(kl == 5 ? "RC4(40)" : "RC4(56)")
  905. :((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)");
  906. break;
  907. case SSL_RC2:
  908. enc=is_export?(kl == 5 ? "RC2(40)" : "RC2(56)"):"RC2(128)";
  909. break;
  910. case SSL_IDEA:
  911. enc="IDEA(128)";
  912. break;
  913. case SSL_eFZA:
  914. enc="Fortezza";
  915. break;
  916. case SSL_eNULL:
  917. enc="None";
  918. break;
  919. case SSL_AES:
  920. switch(cipher->strength_bits)
  921. {
  922. case 128: enc="AES(128)"; break;
  923. case 192: enc="AES(192)"; break;
  924. case 256: enc="AES(256)"; break;
  925. default: enc="AES(?""?""?)"; break;
  926. }
  927. break;
  928. default:
  929. enc="unknown";
  930. break;
  931. }
  932. switch (alg&SSL_MAC_MASK)
  933. {
  934. case SSL_MD5:
  935. mac="MD5";
  936. break;
  937. case SSL_SHA1:
  938. mac="SHA1";
  939. break;
  940. default:
  941. mac="unknown";
  942. break;
  943. }
  944. if (buf == NULL)
  945. {
  946. len=128;
  947. buf=OPENSSL_malloc(len);
  948. if (buf == NULL) return("OPENSSL_malloc Error");
  949. }
  950. else if (len < 128)
  951. return("Buffer too small");
  952. #ifdef KSSL_DEBUG
  953. BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str,alg);
  954. #else
  955. BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str);
  956. #endif /* KSSL_DEBUG */
  957. return(buf);
  958. }
  959. char *SSL_CIPHER_get_version(SSL_CIPHER *c)
  960. {
  961. int i;
  962. if (c == NULL) return("(NONE)");
  963. i=(int)(c->id>>24L);
  964. if (i == 3)
  965. return("TLSv1/SSLv3");
  966. else if (i == 2)
  967. return("SSLv2");
  968. else
  969. return("unknown");
  970. }
  971. /* return the actual cipher being used */
  972. const char *SSL_CIPHER_get_name(SSL_CIPHER *c)
  973. {
  974. if (c != NULL)
  975. return(c->name);
  976. return("(NONE)");
  977. }
  978. /* number of bits for symmetric cipher */
  979. int SSL_CIPHER_get_bits(SSL_CIPHER *c, int *alg_bits)
  980. {
  981. int ret=0;
  982. if (c != NULL)
  983. {
  984. if (alg_bits != NULL) *alg_bits = c->alg_bits;
  985. ret = c->strength_bits;
  986. }
  987. return(ret);
  988. }
  989. SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
  990. {
  991. SSL_COMP *ctmp;
  992. int i,nn;
  993. if ((n == 0) || (sk == NULL)) return(NULL);
  994. nn=sk_SSL_COMP_num(sk);
  995. for (i=0; i<nn; i++)
  996. {
  997. ctmp=sk_SSL_COMP_value(sk,i);
  998. if (ctmp->id == n)
  999. return(ctmp);
  1000. }
  1001. return(NULL);
  1002. }
  1003. static int sk_comp_cmp(const SSL_COMP * const *a,
  1004. const SSL_COMP * const *b)
  1005. {
  1006. return((*a)->id-(*b)->id);
  1007. }
  1008. STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void)
  1009. {
  1010. return(ssl_comp_methods);
  1011. }
  1012. int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
  1013. {
  1014. SSL_COMP *comp;
  1015. STACK_OF(SSL_COMP) *sk;
  1016. if (cm == NULL || cm->type == NID_undef)
  1017. return 1;
  1018. MemCheck_off();
  1019. comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP));
  1020. comp->id=id;
  1021. comp->method=cm;
  1022. if (ssl_comp_methods == NULL)
  1023. sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp);
  1024. else
  1025. sk=ssl_comp_methods;
  1026. if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp))
  1027. {
  1028. MemCheck_on();
  1029. SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE);
  1030. return(1);
  1031. }
  1032. else
  1033. {
  1034. MemCheck_on();
  1035. return(0);
  1036. }
  1037. }