s2_clnt.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. /* ssl/s2_clnt.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-2001 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 "ssl_locl.h"
  112. #ifndef OPENSSL_NO_SSL2
  113. # include <stdio.h>
  114. # include <openssl/rand.h>
  115. # include <openssl/buffer.h>
  116. # include <openssl/objects.h>
  117. # include <openssl/evp.h>
  118. static SSL_METHOD *ssl2_get_client_method(int ver);
  119. static int get_server_finished(SSL *s);
  120. static int get_server_verify(SSL *s);
  121. static int get_server_hello(SSL *s);
  122. static int client_hello(SSL *s);
  123. static int client_master_key(SSL *s);
  124. static int client_finished(SSL *s);
  125. static int client_certificate(SSL *s);
  126. static int ssl_rsa_public_encrypt(SESS_CERT *sc, int len, unsigned char *from,
  127. unsigned char *to, int padding);
  128. # define BREAK break
  129. static SSL_METHOD *ssl2_get_client_method(int ver)
  130. {
  131. if (ver == SSL2_VERSION)
  132. return (SSLv2_client_method());
  133. else
  134. return (NULL);
  135. }
  136. IMPLEMENT_ssl2_meth_func(SSLv2_client_method,
  137. ssl_undefined_function,
  138. ssl2_connect, ssl2_get_client_method)
  139. int ssl2_connect(SSL *s)
  140. {
  141. unsigned long l = (unsigned long)time(NULL);
  142. BUF_MEM *buf = NULL;
  143. int ret = -1;
  144. void (*cb) (const SSL *ssl, int type, int val) = NULL;
  145. int new_state, state;
  146. RAND_add(&l, sizeof(l), 0);
  147. ERR_clear_error();
  148. clear_sys_error();
  149. if (s->info_callback != NULL)
  150. cb = s->info_callback;
  151. else if (s->ctx->info_callback != NULL)
  152. cb = s->ctx->info_callback;
  153. /* init things to blank */
  154. s->in_handshake++;
  155. if (!SSL_in_init(s) || SSL_in_before(s))
  156. SSL_clear(s);
  157. for (;;) {
  158. state = s->state;
  159. switch (s->state) {
  160. case SSL_ST_BEFORE:
  161. case SSL_ST_CONNECT:
  162. case SSL_ST_BEFORE | SSL_ST_CONNECT:
  163. case SSL_ST_OK | SSL_ST_CONNECT:
  164. s->server = 0;
  165. if (cb != NULL)
  166. cb(s, SSL_CB_HANDSHAKE_START, 1);
  167. s->version = SSL2_VERSION;
  168. s->type = SSL_ST_CONNECT;
  169. buf = s->init_buf;
  170. if ((buf == NULL) && ((buf = BUF_MEM_new()) == NULL)) {
  171. ret = -1;
  172. goto end;
  173. }
  174. if (!BUF_MEM_grow(buf, SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) {
  175. if (buf == s->init_buf)
  176. buf = NULL;
  177. ret = -1;
  178. goto end;
  179. }
  180. s->init_buf = buf;
  181. buf = NULL;
  182. s->init_num = 0;
  183. s->state = SSL2_ST_SEND_CLIENT_HELLO_A;
  184. s->ctx->stats.sess_connect++;
  185. s->handshake_func = ssl2_connect;
  186. BREAK;
  187. case SSL2_ST_SEND_CLIENT_HELLO_A:
  188. case SSL2_ST_SEND_CLIENT_HELLO_B:
  189. s->shutdown = 0;
  190. ret = client_hello(s);
  191. if (ret <= 0)
  192. goto end;
  193. s->init_num = 0;
  194. s->state = SSL2_ST_GET_SERVER_HELLO_A;
  195. BREAK;
  196. case SSL2_ST_GET_SERVER_HELLO_A:
  197. case SSL2_ST_GET_SERVER_HELLO_B:
  198. ret = get_server_hello(s);
  199. if (ret <= 0)
  200. goto end;
  201. s->init_num = 0;
  202. if (!s->hit) { /* new session */
  203. s->state = SSL2_ST_SEND_CLIENT_MASTER_KEY_A;
  204. BREAK;
  205. } else {
  206. s->state = SSL2_ST_CLIENT_START_ENCRYPTION;
  207. break;
  208. }
  209. case SSL2_ST_SEND_CLIENT_MASTER_KEY_A:
  210. case SSL2_ST_SEND_CLIENT_MASTER_KEY_B:
  211. ret = client_master_key(s);
  212. if (ret <= 0)
  213. goto end;
  214. s->init_num = 0;
  215. s->state = SSL2_ST_CLIENT_START_ENCRYPTION;
  216. break;
  217. case SSL2_ST_CLIENT_START_ENCRYPTION:
  218. /*
  219. * Ok, we now have all the stuff needed to start encrypting, so
  220. * lets fire it up :-)
  221. */
  222. if (!ssl2_enc_init(s, 1)) {
  223. ret = -1;
  224. goto end;
  225. }
  226. s->s2->clear_text = 0;
  227. s->state = SSL2_ST_SEND_CLIENT_FINISHED_A;
  228. break;
  229. case SSL2_ST_SEND_CLIENT_FINISHED_A:
  230. case SSL2_ST_SEND_CLIENT_FINISHED_B:
  231. ret = client_finished(s);
  232. if (ret <= 0)
  233. goto end;
  234. s->init_num = 0;
  235. s->state = SSL2_ST_GET_SERVER_VERIFY_A;
  236. break;
  237. case SSL2_ST_GET_SERVER_VERIFY_A:
  238. case SSL2_ST_GET_SERVER_VERIFY_B:
  239. ret = get_server_verify(s);
  240. if (ret <= 0)
  241. goto end;
  242. s->init_num = 0;
  243. s->state = SSL2_ST_GET_SERVER_FINISHED_A;
  244. break;
  245. case SSL2_ST_GET_SERVER_FINISHED_A:
  246. case SSL2_ST_GET_SERVER_FINISHED_B:
  247. ret = get_server_finished(s);
  248. if (ret <= 0)
  249. goto end;
  250. break;
  251. case SSL2_ST_SEND_CLIENT_CERTIFICATE_A:
  252. case SSL2_ST_SEND_CLIENT_CERTIFICATE_B:
  253. case SSL2_ST_SEND_CLIENT_CERTIFICATE_C:
  254. case SSL2_ST_SEND_CLIENT_CERTIFICATE_D:
  255. case SSL2_ST_X509_GET_CLIENT_CERTIFICATE:
  256. ret = client_certificate(s);
  257. if (ret <= 0)
  258. goto end;
  259. s->init_num = 0;
  260. s->state = SSL2_ST_GET_SERVER_FINISHED_A;
  261. break;
  262. case SSL_ST_OK:
  263. if (s->init_buf != NULL) {
  264. BUF_MEM_free(s->init_buf);
  265. s->init_buf = NULL;
  266. }
  267. s->init_num = 0;
  268. /* ERR_clear_error(); */
  269. /*
  270. * If we want to cache session-ids in the client and we
  271. * successfully add the session-id to the cache, and there is a
  272. * callback, then pass it out. 26/11/96 - eay - only add if not a
  273. * re-used session.
  274. */
  275. ssl_update_cache(s, SSL_SESS_CACHE_CLIENT);
  276. if (s->hit)
  277. s->ctx->stats.sess_hit++;
  278. ret = 1;
  279. /* s->server=0; */
  280. s->ctx->stats.sess_connect_good++;
  281. if (cb != NULL)
  282. cb(s, SSL_CB_HANDSHAKE_DONE, 1);
  283. goto end;
  284. /* break; */
  285. default:
  286. SSLerr(SSL_F_SSL2_CONNECT, SSL_R_UNKNOWN_STATE);
  287. return (-1);
  288. /* break; */
  289. }
  290. if ((cb != NULL) && (s->state != state)) {
  291. new_state = s->state;
  292. s->state = state;
  293. cb(s, SSL_CB_CONNECT_LOOP, 1);
  294. s->state = new_state;
  295. }
  296. }
  297. end:
  298. s->in_handshake--;
  299. if (buf != NULL)
  300. BUF_MEM_free(buf);
  301. if (cb != NULL)
  302. cb(s, SSL_CB_CONNECT_EXIT, ret);
  303. return (ret);
  304. }
  305. static int get_server_hello(SSL *s)
  306. {
  307. unsigned char *buf;
  308. unsigned char *p;
  309. int i, j;
  310. unsigned long len;
  311. STACK_OF(SSL_CIPHER) *sk = NULL, *cl, *prio, *allow;
  312. buf = (unsigned char *)s->init_buf->data;
  313. p = buf;
  314. if (s->state == SSL2_ST_GET_SERVER_HELLO_A) {
  315. i = ssl2_read(s, (char *)&(buf[s->init_num]), 11 - s->init_num);
  316. if (i < (11 - s->init_num))
  317. return (ssl2_part_read(s, SSL_F_GET_SERVER_HELLO, i));
  318. s->init_num = 11;
  319. if (*(p++) != SSL2_MT_SERVER_HELLO) {
  320. if (p[-1] != SSL2_MT_ERROR) {
  321. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  322. SSLerr(SSL_F_GET_SERVER_HELLO, SSL_R_READ_WRONG_PACKET_TYPE);
  323. } else
  324. SSLerr(SSL_F_GET_SERVER_HELLO, SSL_R_PEER_ERROR);
  325. return (-1);
  326. }
  327. # ifdef __APPLE_CC__
  328. /*
  329. * The Rhapsody 5.5 (a.k.a. MacOS X) compiler bug workaround.
  330. * <appro@fy.chalmers.se>
  331. */
  332. s->hit = (i = *(p++)) ? 1 : 0;
  333. # else
  334. s->hit = (*(p++)) ? 1 : 0;
  335. # endif
  336. s->s2->tmp.cert_type = *(p++);
  337. n2s(p, i);
  338. if (i < s->version)
  339. s->version = i;
  340. n2s(p, i);
  341. s->s2->tmp.cert_length = i;
  342. n2s(p, i);
  343. s->s2->tmp.csl = i;
  344. n2s(p, i);
  345. s->s2->tmp.conn_id_length = i;
  346. s->state = SSL2_ST_GET_SERVER_HELLO_B;
  347. }
  348. /* SSL2_ST_GET_SERVER_HELLO_B */
  349. len =
  350. 11 + (unsigned long)s->s2->tmp.cert_length +
  351. (unsigned long)s->s2->tmp.csl +
  352. (unsigned long)s->s2->tmp.conn_id_length;
  353. if (len > SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER) {
  354. SSLerr(SSL_F_GET_SERVER_HELLO, SSL_R_MESSAGE_TOO_LONG);
  355. return -1;
  356. }
  357. j = (int)len - s->init_num;
  358. i = ssl2_read(s, (char *)&(buf[s->init_num]), j);
  359. if (i != j)
  360. return (ssl2_part_read(s, SSL_F_GET_SERVER_HELLO, i));
  361. if (s->msg_callback) {
  362. /* SERVER-HELLO */
  363. s->msg_callback(0, s->version, 0, buf, (size_t)len, s,
  364. s->msg_callback_arg);
  365. }
  366. /* things are looking good */
  367. p = buf + 11;
  368. if (s->hit) {
  369. if (s->s2->tmp.cert_length != 0) {
  370. SSLerr(SSL_F_GET_SERVER_HELLO, SSL_R_REUSE_CERT_LENGTH_NOT_ZERO);
  371. return (-1);
  372. }
  373. if (s->s2->tmp.cert_type != 0) {
  374. if (!(s->options & SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG)) {
  375. SSLerr(SSL_F_GET_SERVER_HELLO,
  376. SSL_R_REUSE_CERT_TYPE_NOT_ZERO);
  377. return (-1);
  378. }
  379. }
  380. if (s->s2->tmp.csl != 0) {
  381. SSLerr(SSL_F_GET_SERVER_HELLO, SSL_R_REUSE_CIPHER_LIST_NOT_ZERO);
  382. return (-1);
  383. }
  384. } else {
  385. # ifdef undef
  386. /* very bad */
  387. memset(s->session->session_id, 0,
  388. SSL_MAX_SSL_SESSION_ID_LENGTH_IN_BYTES);
  389. s->session->session_id_length = 0;
  390. */
  391. # endif
  392. /*
  393. * we need to do this in case we were trying to reuse a client
  394. * session but others are already reusing it. If this was a new
  395. * 'blank' session ID, the session-id length will still be 0
  396. */
  397. if (s->session->session_id_length > 0) {
  398. if (!ssl_get_new_session(s, 0)) {
  399. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  400. return (-1);
  401. }
  402. }
  403. if (ssl2_set_certificate(s, s->s2->tmp.cert_type,
  404. s->s2->tmp.cert_length, p) <= 0) {
  405. ssl2_return_error(s, SSL2_PE_BAD_CERTIFICATE);
  406. return (-1);
  407. }
  408. p += s->s2->tmp.cert_length;
  409. if (s->s2->tmp.csl == 0) {
  410. ssl2_return_error(s, SSL2_PE_NO_CIPHER);
  411. SSLerr(SSL_F_GET_SERVER_HELLO, SSL_R_NO_CIPHER_LIST);
  412. return (-1);
  413. }
  414. /*
  415. * We have just received a list of ciphers back from the server. We
  416. * need to get the ones that match, then select the one we want the
  417. * most :-).
  418. */
  419. /* load the ciphers */
  420. sk = ssl_bytes_to_cipher_list(s, p, s->s2->tmp.csl,
  421. &s->session->ciphers);
  422. p += s->s2->tmp.csl;
  423. if (sk == NULL) {
  424. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  425. SSLerr(SSL_F_GET_SERVER_HELLO, ERR_R_MALLOC_FAILURE);
  426. return (-1);
  427. }
  428. (void)sk_SSL_CIPHER_set_cmp_func(sk, ssl_cipher_ptr_id_cmp);
  429. /* get the array of ciphers we will accept */
  430. cl = SSL_get_ciphers(s);
  431. (void)sk_SSL_CIPHER_set_cmp_func(cl, ssl_cipher_ptr_id_cmp);
  432. /*
  433. * If server preference flag set, choose the first
  434. * (highest priority) cipher the server sends, otherwise
  435. * client preference has priority.
  436. */
  437. if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE) {
  438. prio = sk;
  439. allow = cl;
  440. } else {
  441. prio = cl;
  442. allow = sk;
  443. }
  444. /*
  445. * In theory we could have ciphers sent back that we don't want to
  446. * use but that does not matter since we will check against the list
  447. * we originally sent and for performance reasons we should not
  448. * bother to match the two lists up just to check.
  449. */
  450. for (i = 0; i < sk_SSL_CIPHER_num(prio); i++) {
  451. if (sk_SSL_CIPHER_find(allow, sk_SSL_CIPHER_value(prio, i)) >= 0)
  452. break;
  453. }
  454. if (i >= sk_SSL_CIPHER_num(prio)) {
  455. ssl2_return_error(s, SSL2_PE_NO_CIPHER);
  456. SSLerr(SSL_F_GET_SERVER_HELLO, SSL_R_NO_CIPHER_MATCH);
  457. return (-1);
  458. }
  459. s->session->cipher = sk_SSL_CIPHER_value(prio, i);
  460. if (s->session->peer != NULL) { /* can't happen */
  461. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  462. SSLerr(SSL_F_GET_SERVER_HELLO, ERR_R_INTERNAL_ERROR);
  463. return (-1);
  464. }
  465. s->session->peer = s->session->sess_cert->peer_key->x509;
  466. /* peer_key->x509 has been set by ssl2_set_certificate. */
  467. CRYPTO_add(&s->session->peer->references, 1, CRYPTO_LOCK_X509);
  468. }
  469. if (s->session->sess_cert == NULL
  470. || s->session->peer != s->session->sess_cert->peer_key->x509)
  471. /* can't happen */
  472. {
  473. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  474. SSLerr(SSL_F_GET_SERVER_HELLO, ERR_R_INTERNAL_ERROR);
  475. return (-1);
  476. }
  477. s->s2->conn_id_length = s->s2->tmp.conn_id_length;
  478. if (s->s2->conn_id_length > sizeof s->s2->conn_id) {
  479. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  480. SSLerr(SSL_F_GET_SERVER_HELLO, SSL_R_SSL2_CONNECTION_ID_TOO_LONG);
  481. return -1;
  482. }
  483. memcpy(s->s2->conn_id, p, s->s2->tmp.conn_id_length);
  484. return (1);
  485. }
  486. static int client_hello(SSL *s)
  487. {
  488. unsigned char *buf;
  489. unsigned char *p, *d;
  490. /* CIPHER **cipher;*/
  491. int i, n, j;
  492. buf = (unsigned char *)s->init_buf->data;
  493. if (s->state == SSL2_ST_SEND_CLIENT_HELLO_A) {
  494. if ((s->session == NULL) || (s->session->ssl_version != s->version)) {
  495. if (!ssl_get_new_session(s, 0)) {
  496. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  497. return (-1);
  498. }
  499. }
  500. /* else use the pre-loaded session */
  501. p = buf; /* header */
  502. d = p + 9; /* data section */
  503. *(p++) = SSL2_MT_CLIENT_HELLO; /* type */
  504. s2n(SSL2_VERSION, p); /* version */
  505. n = j = 0;
  506. n = ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s), d, 0);
  507. d += n;
  508. if (n == 0) {
  509. SSLerr(SSL_F_CLIENT_HELLO, SSL_R_NO_CIPHERS_AVAILABLE);
  510. return (-1);
  511. }
  512. s2n(n, p); /* cipher spec num bytes */
  513. if ((s->session->session_id_length > 0) &&
  514. (s->session->session_id_length <=
  515. SSL2_MAX_SSL_SESSION_ID_LENGTH)) {
  516. i = s->session->session_id_length;
  517. s2n(i, p); /* session id length */
  518. memcpy(d, s->session->session_id, (unsigned int)i);
  519. d += i;
  520. } else {
  521. s2n(0, p);
  522. }
  523. s->s2->challenge_length = SSL2_CHALLENGE_LENGTH;
  524. s2n(SSL2_CHALLENGE_LENGTH, p); /* challenge length */
  525. /*
  526. * challenge id data
  527. */
  528. if (RAND_pseudo_bytes(s->s2->challenge, SSL2_CHALLENGE_LENGTH) <= 0)
  529. return -1;
  530. memcpy(d, s->s2->challenge, SSL2_CHALLENGE_LENGTH);
  531. d += SSL2_CHALLENGE_LENGTH;
  532. s->state = SSL2_ST_SEND_CLIENT_HELLO_B;
  533. s->init_num = d - buf;
  534. s->init_off = 0;
  535. }
  536. /* SSL2_ST_SEND_CLIENT_HELLO_B */
  537. return (ssl2_do_write(s));
  538. }
  539. static int client_master_key(SSL *s)
  540. {
  541. unsigned char *buf;
  542. unsigned char *p, *d;
  543. int clear, enc, karg, i;
  544. SSL_SESSION *sess;
  545. const EVP_CIPHER *c;
  546. const EVP_MD *md;
  547. buf = (unsigned char *)s->init_buf->data;
  548. if (s->state == SSL2_ST_SEND_CLIENT_MASTER_KEY_A) {
  549. if (!ssl_cipher_get_evp(s->session, &c, &md, NULL)) {
  550. ssl2_return_error(s, SSL2_PE_NO_CIPHER);
  551. SSLerr(SSL_F_CLIENT_MASTER_KEY,
  552. SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS);
  553. return (-1);
  554. }
  555. sess = s->session;
  556. p = buf;
  557. d = p + 10;
  558. *(p++) = SSL2_MT_CLIENT_MASTER_KEY; /* type */
  559. i = ssl_put_cipher_by_char(s, sess->cipher, p);
  560. p += i;
  561. /* make key_arg data */
  562. i = EVP_CIPHER_iv_length(c);
  563. sess->key_arg_length = i;
  564. if (i > SSL_MAX_KEY_ARG_LENGTH) {
  565. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  566. SSLerr(SSL_F_CLIENT_MASTER_KEY, ERR_R_INTERNAL_ERROR);
  567. return -1;
  568. }
  569. if (i > 0)
  570. if (RAND_pseudo_bytes(sess->key_arg, i) <= 0)
  571. return -1;
  572. /* make a master key */
  573. i = EVP_CIPHER_key_length(c);
  574. sess->master_key_length = i;
  575. if (i > 0) {
  576. if (i > (int)sizeof(sess->master_key)) {
  577. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  578. SSLerr(SSL_F_CLIENT_MASTER_KEY, ERR_R_INTERNAL_ERROR);
  579. return -1;
  580. }
  581. if (RAND_bytes(sess->master_key, i) <= 0) {
  582. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  583. return (-1);
  584. }
  585. }
  586. if (sess->cipher->algorithm2 & SSL2_CF_8_BYTE_ENC)
  587. enc = 8;
  588. else if (SSL_C_IS_EXPORT(sess->cipher))
  589. enc = 5;
  590. else
  591. enc = i;
  592. if ((int)i < enc) {
  593. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  594. SSLerr(SSL_F_CLIENT_MASTER_KEY, SSL_R_CIPHER_TABLE_SRC_ERROR);
  595. return (-1);
  596. }
  597. clear = i - enc;
  598. s2n(clear, p);
  599. memcpy(d, sess->master_key, (unsigned int)clear);
  600. d += clear;
  601. enc = ssl_rsa_public_encrypt(sess->sess_cert, enc,
  602. &(sess->master_key[clear]), d,
  603. (s->
  604. s2->ssl2_rollback) ? RSA_SSLV23_PADDING
  605. : RSA_PKCS1_PADDING);
  606. if (enc <= 0) {
  607. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  608. SSLerr(SSL_F_CLIENT_MASTER_KEY, SSL_R_PUBLIC_KEY_ENCRYPT_ERROR);
  609. return (-1);
  610. }
  611. # ifdef PKCS1_CHECK
  612. if (s->options & SSL_OP_PKCS1_CHECK_1)
  613. d[1]++;
  614. if (s->options & SSL_OP_PKCS1_CHECK_2)
  615. sess->master_key[clear]++;
  616. # endif
  617. s2n(enc, p);
  618. d += enc;
  619. karg = sess->key_arg_length;
  620. s2n(karg, p); /* key arg size */
  621. if (karg > (int)sizeof(sess->key_arg)) {
  622. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  623. SSLerr(SSL_F_CLIENT_MASTER_KEY, ERR_R_INTERNAL_ERROR);
  624. return -1;
  625. }
  626. memcpy(d, sess->key_arg, (unsigned int)karg);
  627. d += karg;
  628. s->state = SSL2_ST_SEND_CLIENT_MASTER_KEY_B;
  629. s->init_num = d - buf;
  630. s->init_off = 0;
  631. }
  632. /* SSL2_ST_SEND_CLIENT_MASTER_KEY_B */
  633. return (ssl2_do_write(s));
  634. }
  635. static int client_finished(SSL *s)
  636. {
  637. unsigned char *p;
  638. if (s->state == SSL2_ST_SEND_CLIENT_FINISHED_A) {
  639. p = (unsigned char *)s->init_buf->data;
  640. *(p++) = SSL2_MT_CLIENT_FINISHED;
  641. if (s->s2->conn_id_length > sizeof s->s2->conn_id) {
  642. SSLerr(SSL_F_CLIENT_FINISHED, ERR_R_INTERNAL_ERROR);
  643. return -1;
  644. }
  645. memcpy(p, s->s2->conn_id, (unsigned int)s->s2->conn_id_length);
  646. s->state = SSL2_ST_SEND_CLIENT_FINISHED_B;
  647. s->init_num = s->s2->conn_id_length + 1;
  648. s->init_off = 0;
  649. }
  650. return (ssl2_do_write(s));
  651. }
  652. /* read the data and then respond */
  653. static int client_certificate(SSL *s)
  654. {
  655. unsigned char *buf;
  656. unsigned char *p, *d;
  657. int i;
  658. unsigned int n;
  659. int cert_ch_len;
  660. unsigned char *cert_ch;
  661. buf = (unsigned char *)s->init_buf->data;
  662. /*
  663. * We have a cert associated with the SSL, so attach it to the session if
  664. * it does not have one
  665. */
  666. if (s->state == SSL2_ST_SEND_CLIENT_CERTIFICATE_A) {
  667. i = ssl2_read(s, (char *)&(buf[s->init_num]),
  668. SSL2_MAX_CERT_CHALLENGE_LENGTH + 2 - s->init_num);
  669. if (i < (SSL2_MIN_CERT_CHALLENGE_LENGTH + 2 - s->init_num))
  670. return (ssl2_part_read(s, SSL_F_CLIENT_CERTIFICATE, i));
  671. s->init_num += i;
  672. if (s->msg_callback) {
  673. /* REQUEST-CERTIFICATE */
  674. s->msg_callback(0, s->version, 0, buf, (size_t)s->init_num, s,
  675. s->msg_callback_arg);
  676. }
  677. /* type=buf[0]; */
  678. /* type eq x509 */
  679. if (buf[1] != SSL2_AT_MD5_WITH_RSA_ENCRYPTION) {
  680. ssl2_return_error(s, SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE);
  681. SSLerr(SSL_F_CLIENT_CERTIFICATE, SSL_R_BAD_AUTHENTICATION_TYPE);
  682. return (-1);
  683. }
  684. if ((s->cert == NULL) ||
  685. (s->cert->key->x509 == NULL) ||
  686. (s->cert->key->privatekey == NULL)) {
  687. s->state = SSL2_ST_X509_GET_CLIENT_CERTIFICATE;
  688. } else
  689. s->state = SSL2_ST_SEND_CLIENT_CERTIFICATE_C;
  690. }
  691. cert_ch = buf + 2;
  692. cert_ch_len = s->init_num - 2;
  693. if (s->state == SSL2_ST_X509_GET_CLIENT_CERTIFICATE) {
  694. X509 *x509 = NULL;
  695. EVP_PKEY *pkey = NULL;
  696. /*
  697. * If we get an error we need to ssl->rwstate=SSL_X509_LOOKUP;
  698. * return(error); We should then be retried when things are ok and we
  699. * can get a cert or not
  700. */
  701. i = 0;
  702. if (s->ctx->client_cert_cb != NULL) {
  703. i = s->ctx->client_cert_cb(s, &(x509), &(pkey));
  704. }
  705. if (i < 0) {
  706. s->rwstate = SSL_X509_LOOKUP;
  707. return (-1);
  708. }
  709. s->rwstate = SSL_NOTHING;
  710. if ((i == 1) && (pkey != NULL) && (x509 != NULL)) {
  711. s->state = SSL2_ST_SEND_CLIENT_CERTIFICATE_C;
  712. if (!SSL_use_certificate(s, x509) || !SSL_use_PrivateKey(s, pkey)) {
  713. i = 0;
  714. }
  715. X509_free(x509);
  716. EVP_PKEY_free(pkey);
  717. } else if (i == 1) {
  718. if (x509 != NULL)
  719. X509_free(x509);
  720. if (pkey != NULL)
  721. EVP_PKEY_free(pkey);
  722. SSLerr(SSL_F_CLIENT_CERTIFICATE,
  723. SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
  724. i = 0;
  725. }
  726. if (i == 0) {
  727. /*
  728. * We have no client certificate to respond with so send the
  729. * correct error message back
  730. */
  731. s->state = SSL2_ST_SEND_CLIENT_CERTIFICATE_B;
  732. p = buf;
  733. *(p++) = SSL2_MT_ERROR;
  734. s2n(SSL2_PE_NO_CERTIFICATE, p);
  735. s->init_off = 0;
  736. s->init_num = 3;
  737. /* Write is done at the end */
  738. }
  739. }
  740. if (s->state == SSL2_ST_SEND_CLIENT_CERTIFICATE_B) {
  741. return (ssl2_do_write(s));
  742. }
  743. if (s->state == SSL2_ST_SEND_CLIENT_CERTIFICATE_C) {
  744. EVP_MD_CTX ctx;
  745. /*
  746. * ok, now we calculate the checksum do it first so we can reuse buf
  747. * :-)
  748. */
  749. p = buf;
  750. EVP_MD_CTX_init(&ctx);
  751. EVP_SignInit_ex(&ctx, s->ctx->rsa_md5, NULL);
  752. EVP_SignUpdate(&ctx, s->s2->key_material, s->s2->key_material_length);
  753. EVP_SignUpdate(&ctx, cert_ch, (unsigned int)cert_ch_len);
  754. n = i2d_X509(s->session->sess_cert->peer_key->x509, &p);
  755. EVP_SignUpdate(&ctx, buf, (unsigned int)n);
  756. p = buf;
  757. d = p + 6;
  758. *(p++) = SSL2_MT_CLIENT_CERTIFICATE;
  759. *(p++) = SSL2_CT_X509_CERTIFICATE;
  760. n = i2d_X509(s->cert->key->x509, &d);
  761. s2n(n, p);
  762. if (!EVP_SignFinal(&ctx, d, &n, s->cert->key->privatekey)) {
  763. /*
  764. * this is not good. If things have failed it means there so
  765. * something wrong with the key. We will continue with a 0 length
  766. * signature
  767. */
  768. }
  769. EVP_MD_CTX_cleanup(&ctx);
  770. s2n(n, p);
  771. d += n;
  772. s->state = SSL2_ST_SEND_CLIENT_CERTIFICATE_D;
  773. s->init_num = d - buf;
  774. s->init_off = 0;
  775. }
  776. /* if (s->state == SSL2_ST_SEND_CLIENT_CERTIFICATE_D) */
  777. return (ssl2_do_write(s));
  778. }
  779. static int get_server_verify(SSL *s)
  780. {
  781. unsigned char *p;
  782. int i, n, len;
  783. p = (unsigned char *)s->init_buf->data;
  784. if (s->state == SSL2_ST_GET_SERVER_VERIFY_A) {
  785. i = ssl2_read(s, (char *)&(p[s->init_num]), 1 - s->init_num);
  786. if (i < (1 - s->init_num))
  787. return (ssl2_part_read(s, SSL_F_GET_SERVER_VERIFY, i));
  788. s->init_num += i;
  789. s->state = SSL2_ST_GET_SERVER_VERIFY_B;
  790. if (*p != SSL2_MT_SERVER_VERIFY) {
  791. if (p[0] != SSL2_MT_ERROR) {
  792. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  793. SSLerr(SSL_F_GET_SERVER_VERIFY, SSL_R_READ_WRONG_PACKET_TYPE);
  794. } else {
  795. SSLerr(SSL_F_GET_SERVER_VERIFY, SSL_R_PEER_ERROR);
  796. /* try to read the error message */
  797. i = ssl2_read(s, (char *)&(p[s->init_num]), 3 - s->init_num);
  798. return ssl2_part_read(s, SSL_F_GET_SERVER_VERIFY, i);
  799. }
  800. return (-1);
  801. }
  802. }
  803. p = (unsigned char *)s->init_buf->data;
  804. len = 1 + s->s2->challenge_length;
  805. n = len - s->init_num;
  806. i = ssl2_read(s, (char *)&(p[s->init_num]), n);
  807. if (i < n)
  808. return (ssl2_part_read(s, SSL_F_GET_SERVER_VERIFY, i));
  809. if (s->msg_callback) {
  810. /* SERVER-VERIFY */
  811. s->msg_callback(0, s->version, 0, p, len, s, s->msg_callback_arg);
  812. }
  813. p += 1;
  814. if (CRYPTO_memcmp(p, s->s2->challenge, s->s2->challenge_length) != 0) {
  815. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  816. SSLerr(SSL_F_GET_SERVER_VERIFY, SSL_R_CHALLENGE_IS_DIFFERENT);
  817. return (-1);
  818. }
  819. return (1);
  820. }
  821. static int get_server_finished(SSL *s)
  822. {
  823. unsigned char *buf;
  824. unsigned char *p;
  825. int i, n, len;
  826. buf = (unsigned char *)s->init_buf->data;
  827. p = buf;
  828. if (s->state == SSL2_ST_GET_SERVER_FINISHED_A) {
  829. i = ssl2_read(s, (char *)&(buf[s->init_num]), 1 - s->init_num);
  830. if (i < (1 - s->init_num))
  831. return (ssl2_part_read(s, SSL_F_GET_SERVER_FINISHED, i));
  832. s->init_num += i;
  833. if (*p == SSL2_MT_REQUEST_CERTIFICATE) {
  834. s->state = SSL2_ST_SEND_CLIENT_CERTIFICATE_A;
  835. return (1);
  836. } else if (*p != SSL2_MT_SERVER_FINISHED) {
  837. if (p[0] != SSL2_MT_ERROR) {
  838. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  839. SSLerr(SSL_F_GET_SERVER_FINISHED,
  840. SSL_R_READ_WRONG_PACKET_TYPE);
  841. } else {
  842. SSLerr(SSL_F_GET_SERVER_FINISHED, SSL_R_PEER_ERROR);
  843. /* try to read the error message */
  844. i = ssl2_read(s, (char *)&(p[s->init_num]), 3 - s->init_num);
  845. return ssl2_part_read(s, SSL_F_GET_SERVER_VERIFY, i);
  846. }
  847. return (-1);
  848. }
  849. s->state = SSL2_ST_GET_SERVER_FINISHED_B;
  850. }
  851. len = 1 + SSL2_SSL_SESSION_ID_LENGTH;
  852. n = len - s->init_num;
  853. i = ssl2_read(s, (char *)&(buf[s->init_num]), n);
  854. if (i < n) {
  855. /*
  856. * XXX could be shorter than SSL2_SSL_SESSION_ID_LENGTH,
  857. * that's the maximum
  858. */
  859. return (ssl2_part_read(s, SSL_F_GET_SERVER_FINISHED, i));
  860. }
  861. s->init_num += i;
  862. if (s->msg_callback) {
  863. /* SERVER-FINISHED */
  864. s->msg_callback(0, s->version, 0, buf, (size_t)s->init_num, s,
  865. s->msg_callback_arg);
  866. }
  867. if (!s->hit) { /* new session */
  868. /* new session-id */
  869. /*
  870. * Make sure we were not trying to re-use an old SSL_SESSION or bad
  871. * things can happen
  872. */
  873. /* ZZZZZZZZZZZZZ */
  874. s->session->session_id_length = SSL2_SSL_SESSION_ID_LENGTH;
  875. memcpy(s->session->session_id, p + 1, SSL2_SSL_SESSION_ID_LENGTH);
  876. } else {
  877. if (!(s->options & SSL_OP_MICROSOFT_SESS_ID_BUG)) {
  878. if ((s->session->session_id_length >
  879. sizeof s->session->session_id)
  880. || (0 !=
  881. memcmp(buf + 1, s->session->session_id,
  882. (unsigned int)s->session->session_id_length))) {
  883. ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
  884. SSLerr(SSL_F_GET_SERVER_FINISHED,
  885. SSL_R_SSL_SESSION_ID_IS_DIFFERENT);
  886. return (-1);
  887. }
  888. }
  889. }
  890. s->state = SSL_ST_OK;
  891. return (1);
  892. }
  893. /* loads in the certificate from the server */
  894. int ssl2_set_certificate(SSL *s, int type, int len, const unsigned char *data)
  895. {
  896. STACK_OF(X509) *sk = NULL;
  897. EVP_PKEY *pkey = NULL;
  898. SESS_CERT *sc = NULL;
  899. int i;
  900. X509 *x509 = NULL;
  901. int ret = 0;
  902. x509 = d2i_X509(NULL, &data, (long)len);
  903. if (x509 == NULL) {
  904. SSLerr(SSL_F_SSL2_SET_CERTIFICATE, ERR_R_X509_LIB);
  905. goto err;
  906. }
  907. if ((sk = sk_X509_new_null()) == NULL || !sk_X509_push(sk, x509)) {
  908. SSLerr(SSL_F_SSL2_SET_CERTIFICATE, ERR_R_MALLOC_FAILURE);
  909. goto err;
  910. }
  911. i = ssl_verify_cert_chain(s, sk);
  912. if ((s->verify_mode != SSL_VERIFY_NONE) && (i <= 0)) {
  913. SSLerr(SSL_F_SSL2_SET_CERTIFICATE, SSL_R_CERTIFICATE_VERIFY_FAILED);
  914. goto err;
  915. }
  916. ERR_clear_error(); /* but we keep s->verify_result */
  917. s->session->verify_result = s->verify_result;
  918. /* server's cert for this session */
  919. sc = ssl_sess_cert_new();
  920. if (sc == NULL) {
  921. ret = -1;
  922. goto err;
  923. }
  924. if (s->session->sess_cert)
  925. ssl_sess_cert_free(s->session->sess_cert);
  926. s->session->sess_cert = sc;
  927. sc->peer_pkeys[SSL_PKEY_RSA_ENC].x509 = x509;
  928. sc->peer_key = &(sc->peer_pkeys[SSL_PKEY_RSA_ENC]);
  929. pkey = X509_get_pubkey(x509);
  930. x509 = NULL;
  931. if (pkey == NULL) {
  932. SSLerr(SSL_F_SSL2_SET_CERTIFICATE,
  933. SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY);
  934. goto err;
  935. }
  936. if (pkey->type != EVP_PKEY_RSA) {
  937. SSLerr(SSL_F_SSL2_SET_CERTIFICATE, SSL_R_PUBLIC_KEY_NOT_RSA);
  938. goto err;
  939. }
  940. if (!ssl_set_peer_cert_type(sc, SSL2_CT_X509_CERTIFICATE))
  941. goto err;
  942. ret = 1;
  943. err:
  944. sk_X509_free(sk);
  945. X509_free(x509);
  946. EVP_PKEY_free(pkey);
  947. return (ret);
  948. }
  949. static int ssl_rsa_public_encrypt(SESS_CERT *sc, int len, unsigned char *from,
  950. unsigned char *to, int padding)
  951. {
  952. EVP_PKEY *pkey = NULL;
  953. int i = -1;
  954. if ((sc == NULL) || (sc->peer_key->x509 == NULL) ||
  955. ((pkey = X509_get_pubkey(sc->peer_key->x509)) == NULL)) {
  956. SSLerr(SSL_F_SSL_RSA_PUBLIC_ENCRYPT, SSL_R_NO_PUBLICKEY);
  957. return (-1);
  958. }
  959. if (pkey->type != EVP_PKEY_RSA) {
  960. SSLerr(SSL_F_SSL_RSA_PUBLIC_ENCRYPT, SSL_R_PUBLIC_KEY_IS_NOT_RSA);
  961. goto end;
  962. }
  963. /* we have the public key */
  964. i = RSA_public_encrypt(len, from, to, pkey->pkey.rsa, padding);
  965. if (i < 0)
  966. SSLerr(SSL_F_SSL_RSA_PUBLIC_ENCRYPT, ERR_R_RSA_LIB);
  967. end:
  968. EVP_PKEY_free(pkey);
  969. return (i);
  970. }
  971. #else /* !OPENSSL_NO_SSL2 */
  972. # if PEDANTIC
  973. static void *dummy = &dummy;
  974. # endif
  975. #endif