You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

588 lines
19 KiB

  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.]
  56. */
  57. /* ====================================================================
  58. * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
  59. *
  60. * Redistribution and use in source and binary forms, with or without
  61. * modification, are permitted provided that the following conditions
  62. * are met:
  63. *
  64. * 1. Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. *
  67. * 2. Redistributions in binary form must reproduce the above copyright
  68. * notice, this list of conditions and the following disclaimer in
  69. * the documentation and/or other materials provided with the
  70. * distribution.
  71. *
  72. * 3. All advertising materials mentioning features or use of this
  73. * software must display the following acknowledgment:
  74. * "This product includes software developed by the OpenSSL Project
  75. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  76. *
  77. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  78. * endorse or promote products derived from this software without
  79. * prior written permission. For written permission, please contact
  80. * openssl-core@openssl.org.
  81. *
  82. * 5. Products derived from this software may not be called "OpenSSL"
  83. * nor may "OpenSSL" appear in their names without prior written
  84. * permission of the OpenSSL Project.
  85. *
  86. * 6. Redistributions of any form whatsoever must retain the following
  87. * acknowledgment:
  88. * "This product includes software developed by the OpenSSL Project
  89. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  90. *
  91. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  92. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  93. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  94. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  95. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  96. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  97. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  98. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  99. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  100. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  101. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  102. * OF THE POSSIBILITY OF SUCH DAMAGE.
  103. * ====================================================================
  104. *
  105. * This product includes cryptographic software written by Eric Young
  106. * (eay@cryptsoft.com). This product includes software written by Tim
  107. * Hudson (tjh@cryptsoft.com).
  108. *
  109. */
  110. /* ====================================================================
  111. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  112. *
  113. * Portions of the attached software ("Contribution") are developed by
  114. * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
  115. *
  116. * The Contribution is licensed pursuant to the OpenSSL open source
  117. * license provided above.
  118. *
  119. * ECC cipher suite support in OpenSSL originally written by
  120. * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
  121. *
  122. */
  123. /* ====================================================================
  124. * Copyright 2005 Nokia. All rights reserved.
  125. *
  126. * The portions of the attached software ("Contribution") is developed by
  127. * Nokia Corporation and is licensed pursuant to the OpenSSL open source
  128. * license.
  129. *
  130. * The Contribution, originally written by Mika Kousa and Pasi Eronen of
  131. * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
  132. * support (see RFC 4279) to OpenSSL.
  133. *
  134. * No patent licenses or other rights except those expressly stated in
  135. * the OpenSSL open source license shall be deemed granted or received
  136. * expressly, by implication, estoppel, or otherwise.
  137. *
  138. * No assurances are provided by Nokia that the Contribution does not
  139. * infringe the patent or other intellectual property rights of any third
  140. * party or that the license provides you with all the necessary rights
  141. * to make use of the Contribution.
  142. *
  143. * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
  144. * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
  145. * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
  146. * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
  147. * OTHERWISE. */
  148. #include <openssl/ssl.h>
  149. #include <assert.h>
  150. #include <stdio.h>
  151. #include <string.h>
  152. #include <openssl/buf.h>
  153. #include <openssl/dh.h>
  154. #include <openssl/digest.h>
  155. #include <openssl/err.h>
  156. #include <openssl/md5.h>
  157. #include <openssl/mem.h>
  158. #include <openssl/obj.h>
  159. #include "internal.h"
  160. const SSL3_ENC_METHOD SSLv3_enc_data = {
  161. ssl3_prf,
  162. tls1_setup_key_block,
  163. tls1_generate_master_secret,
  164. tls1_change_cipher_state,
  165. ssl3_final_finish_mac,
  166. ssl3_cert_verify_mac,
  167. SSL3_MD_CLIENT_FINISHED_CONST, 4,
  168. SSL3_MD_SERVER_FINISHED_CONST, 4,
  169. ssl3_alert_code,
  170. tls1_export_keying_material,
  171. 0,
  172. };
  173. int ssl3_supports_cipher(const SSL_CIPHER *cipher) {
  174. return 1;
  175. }
  176. int ssl3_set_handshake_header(SSL *s, int htype, unsigned long len) {
  177. uint8_t *p = (uint8_t *)s->init_buf->data;
  178. *(p++) = htype;
  179. l2n3(len, p);
  180. s->init_num = (int)len + SSL3_HM_HEADER_LENGTH;
  181. s->init_off = 0;
  182. /* Add the message to the handshake hash. */
  183. return ssl3_update_handshake_hash(s, (uint8_t *)s->init_buf->data,
  184. s->init_num);
  185. }
  186. int ssl3_handshake_write(SSL *s) { return ssl3_do_write(s, SSL3_RT_HANDSHAKE); }
  187. int ssl3_new(SSL *s) {
  188. SSL3_STATE *s3;
  189. s3 = OPENSSL_malloc(sizeof *s3);
  190. if (s3 == NULL) {
  191. goto err;
  192. }
  193. memset(s3, 0, sizeof *s3);
  194. EVP_MD_CTX_init(&s3->handshake_hash);
  195. EVP_MD_CTX_init(&s3->handshake_md5);
  196. s->s3 = s3;
  197. /* Set the version to the highest supported version for TLS. This controls the
  198. * initial state of |s->enc_method| and what the API reports as the version
  199. * prior to negotiation.
  200. *
  201. * TODO(davidben): This is fragile and confusing. */
  202. s->version = TLS1_2_VERSION;
  203. return 1;
  204. err:
  205. return 0;
  206. }
  207. void ssl3_free(SSL *s) {
  208. if (s == NULL || s->s3 == NULL) {
  209. return;
  210. }
  211. ssl3_cleanup_key_block(s);
  212. ssl_read_buffer_clear(s);
  213. ssl_write_buffer_clear(s);
  214. DH_free(s->s3->tmp.dh);
  215. EC_KEY_free(s->s3->tmp.ecdh);
  216. sk_X509_NAME_pop_free(s->s3->tmp.ca_names, X509_NAME_free);
  217. OPENSSL_free(s->s3->tmp.certificate_types);
  218. OPENSSL_free(s->s3->tmp.peer_ellipticcurvelist);
  219. OPENSSL_free(s->s3->tmp.peer_psk_identity_hint);
  220. DH_free(s->s3->tmp.peer_dh_tmp);
  221. EC_KEY_free(s->s3->tmp.peer_ecdh_tmp);
  222. ssl3_free_handshake_buffer(s);
  223. ssl3_free_handshake_hash(s);
  224. OPENSSL_free(s->s3->alpn_selected);
  225. OPENSSL_cleanse(s->s3, sizeof *s->s3);
  226. OPENSSL_free(s->s3);
  227. s->s3 = NULL;
  228. }
  229. int SSL_session_reused(const SSL *ssl) {
  230. return ssl->hit;
  231. }
  232. int SSL_total_renegotiations(const SSL *ssl) {
  233. return ssl->s3->total_renegotiations;
  234. }
  235. int SSL_num_renegotiations(const SSL *ssl) {
  236. return SSL_total_renegotiations(ssl);
  237. }
  238. int SSL_CTX_need_tmp_RSA(const SSL_CTX *ctx) {
  239. return 0;
  240. }
  241. int SSL_need_rsa(const SSL *ssl) {
  242. return 0;
  243. }
  244. int SSL_CTX_set_tmp_rsa(SSL_CTX *ctx, const RSA *rsa) {
  245. return 1;
  246. }
  247. int SSL_set_tmp_rsa(SSL *ssl, const RSA *rsa) {
  248. return 1;
  249. }
  250. int SSL_CTX_set_tmp_dh(SSL_CTX *ctx, const DH *dh) {
  251. DH_free(ctx->cert->dh_tmp);
  252. ctx->cert->dh_tmp = DHparams_dup(dh);
  253. if (ctx->cert->dh_tmp == NULL) {
  254. OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
  255. return 0;
  256. }
  257. return 1;
  258. }
  259. int SSL_set_tmp_dh(SSL *ssl, const DH *dh) {
  260. DH_free(ssl->cert->dh_tmp);
  261. ssl->cert->dh_tmp = DHparams_dup(dh);
  262. if (ssl->cert->dh_tmp == NULL) {
  263. OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
  264. return 0;
  265. }
  266. return 1;
  267. }
  268. int SSL_CTX_set_tmp_ecdh(SSL_CTX *ctx, const EC_KEY *ec_key) {
  269. if (ec_key == NULL || EC_KEY_get0_group(ec_key) == NULL) {
  270. OPENSSL_PUT_ERROR(SSL, ERR_R_PASSED_NULL_PARAMETER);
  271. return 0;
  272. }
  273. ctx->cert->ecdh_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key));
  274. return 1;
  275. }
  276. int SSL_set_tmp_ecdh(SSL *ssl, const EC_KEY *ec_key) {
  277. if (ec_key == NULL || EC_KEY_get0_group(ec_key) == NULL) {
  278. OPENSSL_PUT_ERROR(SSL, ERR_R_PASSED_NULL_PARAMETER);
  279. return 0;
  280. }
  281. ssl->cert->ecdh_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key));
  282. return 1;
  283. }
  284. int SSL_CTX_enable_tls_channel_id(SSL_CTX *ctx) {
  285. ctx->tlsext_channel_id_enabled = 1;
  286. return 1;
  287. }
  288. int SSL_enable_tls_channel_id(SSL *ssl) {
  289. ssl->tlsext_channel_id_enabled = 1;
  290. return 1;
  291. }
  292. int SSL_CTX_set1_tls_channel_id(SSL_CTX *ctx, EVP_PKEY *private_key) {
  293. ctx->tlsext_channel_id_enabled = 1;
  294. if (EVP_PKEY_id(private_key) != EVP_PKEY_EC ||
  295. EVP_PKEY_bits(private_key) != 256) {
  296. OPENSSL_PUT_ERROR(SSL, SSL_R_CHANNEL_ID_NOT_P256);
  297. return 0;
  298. }
  299. EVP_PKEY_free(ctx->tlsext_channel_id_private);
  300. ctx->tlsext_channel_id_private = EVP_PKEY_up_ref(private_key);
  301. return 1;
  302. }
  303. int SSL_set1_tls_channel_id(SSL *ssl, EVP_PKEY *private_key) {
  304. EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(private_key);
  305. if (ec_key == NULL ||
  306. EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key)) !=
  307. NID_X9_62_prime256v1) {
  308. OPENSSL_PUT_ERROR(SSL, SSL_R_CHANNEL_ID_NOT_P256);
  309. return 0;
  310. }
  311. EVP_PKEY_free(ssl->tlsext_channel_id_private);
  312. ssl->tlsext_channel_id_private = EVP_PKEY_up_ref(private_key);
  313. ssl->tlsext_channel_id_enabled = 1;
  314. return 1;
  315. }
  316. size_t SSL_get_tls_channel_id(SSL *ssl, uint8_t *out, size_t max_out) {
  317. if (!ssl->s3->tlsext_channel_id_valid) {
  318. return 0;
  319. }
  320. memcpy(out, ssl->s3->tlsext_channel_id, (max_out < 64) ? max_out : 64);
  321. return 64;
  322. }
  323. int SSL_set_tlsext_host_name(SSL *ssl, const char *name) {
  324. OPENSSL_free(ssl->tlsext_hostname);
  325. ssl->tlsext_hostname = NULL;
  326. if (name == NULL) {
  327. return 1;
  328. }
  329. if (strlen(name) > TLSEXT_MAXLEN_host_name) {
  330. OPENSSL_PUT_ERROR(SSL, SSL_R_SSL3_EXT_INVALID_SERVERNAME);
  331. return 0;
  332. }
  333. ssl->tlsext_hostname = BUF_strdup(name);
  334. if (ssl->tlsext_hostname == NULL) {
  335. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  336. return 0;
  337. }
  338. return 1;
  339. }
  340. size_t SSL_get0_certificate_types(SSL *ssl, const uint8_t **out_types) {
  341. if (ssl->server || !ssl->s3->tmp.cert_req) {
  342. *out_types = NULL;
  343. return 0;
  344. }
  345. *out_types = ssl->s3->tmp.certificate_types;
  346. return ssl->s3->tmp.num_certificate_types;
  347. }
  348. int SSL_CTX_set1_curves(SSL_CTX *ctx, const int *curves, size_t curves_len) {
  349. return tls1_set_curves(&ctx->tlsext_ellipticcurvelist,
  350. &ctx->tlsext_ellipticcurvelist_length, curves,
  351. curves_len);
  352. }
  353. int SSL_set1_curves(SSL *ssl, const int *curves, size_t curves_len) {
  354. return tls1_set_curves(&ssl->tlsext_ellipticcurvelist,
  355. &ssl->tlsext_ellipticcurvelist_length, curves,
  356. curves_len);
  357. }
  358. int SSL_CTX_set_tlsext_servername_callback(
  359. SSL_CTX *ctx, int (*callback)(SSL *ssl, int *out_alert, void *arg)) {
  360. ctx->tlsext_servername_callback = callback;
  361. return 1;
  362. }
  363. int SSL_CTX_set_tlsext_servername_arg(SSL_CTX *ctx, void *arg) {
  364. ctx->tlsext_servername_arg = arg;
  365. return 1;
  366. }
  367. int SSL_CTX_get_tlsext_ticket_keys(SSL_CTX *ctx, void *out, size_t len) {
  368. if (out == NULL) {
  369. return 48;
  370. }
  371. if (len != 48) {
  372. OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_TICKET_KEYS_LENGTH);
  373. return 0;
  374. }
  375. uint8_t *out_bytes = out;
  376. memcpy(out_bytes, ctx->tlsext_tick_key_name, 16);
  377. memcpy(out_bytes + 16, ctx->tlsext_tick_hmac_key, 16);
  378. memcpy(out_bytes + 32, ctx->tlsext_tick_aes_key, 16);
  379. return 1;
  380. }
  381. int SSL_CTX_set_tlsext_ticket_keys(SSL_CTX *ctx, const void *in, size_t len) {
  382. if (in == NULL) {
  383. return 48;
  384. }
  385. if (len != 48) {
  386. OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_TICKET_KEYS_LENGTH);
  387. return 0;
  388. }
  389. const uint8_t *in_bytes = in;
  390. memcpy(ctx->tlsext_tick_key_name, in_bytes, 16);
  391. memcpy(ctx->tlsext_tick_hmac_key, in_bytes + 16, 16);
  392. memcpy(ctx->tlsext_tick_aes_key, in_bytes + 32, 16);
  393. return 1;
  394. }
  395. int SSL_CTX_set_tlsext_ticket_key_cb(
  396. SSL_CTX *ctx, int (*callback)(SSL *ssl, uint8_t *key_name, uint8_t *iv,
  397. EVP_CIPHER_CTX *ctx, HMAC_CTX *hmac_ctx,
  398. int encrypt)) {
  399. ctx->tlsext_ticket_key_cb = callback;
  400. return 1;
  401. }
  402. struct ssl_cipher_preference_list_st *ssl_get_cipher_preferences(SSL *s) {
  403. if (s->cipher_list != NULL) {
  404. return s->cipher_list;
  405. }
  406. if (s->version >= TLS1_1_VERSION && s->ctx != NULL &&
  407. s->ctx->cipher_list_tls11 != NULL) {
  408. return s->ctx->cipher_list_tls11;
  409. }
  410. if (s->version >= TLS1_VERSION && s->ctx != NULL &&
  411. s->ctx->cipher_list_tls10 != NULL) {
  412. return s->ctx->cipher_list_tls10;
  413. }
  414. if (s->ctx != NULL && s->ctx->cipher_list != NULL) {
  415. return s->ctx->cipher_list;
  416. }
  417. return NULL;
  418. }
  419. const SSL_CIPHER *ssl3_choose_cipher(
  420. SSL *s, STACK_OF(SSL_CIPHER) *clnt,
  421. struct ssl_cipher_preference_list_st *server_pref) {
  422. const SSL_CIPHER *c, *ret = NULL;
  423. STACK_OF(SSL_CIPHER) *srvr = server_pref->ciphers, *prio, *allow;
  424. size_t i;
  425. int ok;
  426. size_t cipher_index;
  427. uint32_t alg_k, alg_a, mask_k, mask_a;
  428. /* in_group_flags will either be NULL, or will point to an array of bytes
  429. * which indicate equal-preference groups in the |prio| stack. See the
  430. * comment about |in_group_flags| in the |ssl_cipher_preference_list_st|
  431. * struct. */
  432. const uint8_t *in_group_flags;
  433. /* group_min contains the minimal index so far found in a group, or -1 if no
  434. * such value exists yet. */
  435. int group_min = -1;
  436. if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE) {
  437. prio = srvr;
  438. in_group_flags = server_pref->in_group_flags;
  439. allow = clnt;
  440. } else {
  441. prio = clnt;
  442. in_group_flags = NULL;
  443. allow = srvr;
  444. }
  445. ssl_get_compatible_server_ciphers(s, &mask_k, &mask_a);
  446. for (i = 0; i < sk_SSL_CIPHER_num(prio); i++) {
  447. c = sk_SSL_CIPHER_value(prio, i);
  448. ok = 1;
  449. /* Check the TLS version. */
  450. if (SSL_CIPHER_get_min_version(c) > ssl3_version_from_wire(s, s->version)) {
  451. ok = 0;
  452. }
  453. alg_k = c->algorithm_mkey;
  454. alg_a = c->algorithm_auth;
  455. ok = ok && (alg_k & mask_k) && (alg_a & mask_a);
  456. if (ok && sk_SSL_CIPHER_find(allow, &cipher_index, c)) {
  457. if (in_group_flags != NULL && in_group_flags[i] == 1) {
  458. /* This element of |prio| is in a group. Update the minimum index found
  459. * so far and continue looking. */
  460. if (group_min == -1 || (size_t)group_min > cipher_index) {
  461. group_min = cipher_index;
  462. }
  463. } else {
  464. if (group_min != -1 && (size_t)group_min < cipher_index) {
  465. cipher_index = group_min;
  466. }
  467. ret = sk_SSL_CIPHER_value(allow, cipher_index);
  468. break;
  469. }
  470. }
  471. if (in_group_flags != NULL && in_group_flags[i] == 0 && group_min != -1) {
  472. /* We are about to leave a group, but we found a match in it, so that's
  473. * our answer. */
  474. ret = sk_SSL_CIPHER_value(allow, group_min);
  475. break;
  476. }
  477. }
  478. return ret;
  479. }
  480. int ssl3_get_req_cert_type(SSL *s, uint8_t *p) {
  481. int ret = 0;
  482. const uint8_t *sig;
  483. size_t i, siglen;
  484. int have_rsa_sign = 0;
  485. int have_ecdsa_sign = 0;
  486. /* get configured sigalgs */
  487. siglen = tls12_get_psigalgs(s, &sig);
  488. for (i = 0; i < siglen; i += 2, sig += 2) {
  489. switch (sig[1]) {
  490. case TLSEXT_signature_rsa:
  491. have_rsa_sign = 1;
  492. break;
  493. case TLSEXT_signature_ecdsa:
  494. have_ecdsa_sign = 1;
  495. break;
  496. }
  497. }
  498. if (have_rsa_sign) {
  499. p[ret++] = SSL3_CT_RSA_SIGN;
  500. }
  501. /* ECDSA certs can be used with RSA cipher suites as well so we don't need to
  502. * check for SSL_kECDH or SSL_kECDHE. */
  503. if (s->version >= TLS1_VERSION && have_ecdsa_sign) {
  504. p[ret++] = TLS_CT_ECDSA_SIGN;
  505. }
  506. return ret;
  507. }
  508. /* If we are using default SHA1+MD5 algorithms switch to new SHA256 PRF and
  509. * handshake macs if required. */
  510. uint32_t ssl_get_algorithm_prf(SSL *s) {
  511. uint32_t algorithm_prf = s->s3->tmp.new_cipher->algorithm_prf;
  512. if (s->enc_method->enc_flags & SSL_ENC_FLAG_SHA256_PRF &&
  513. algorithm_prf == SSL_HANDSHAKE_MAC_DEFAULT) {
  514. return SSL_HANDSHAKE_MAC_SHA256;
  515. }
  516. return algorithm_prf;
  517. }