summaryrefslogtreecommitdiff
path: root/src/lib/libssl/t1_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/t1_lib.c')
-rw-r--r--src/lib/libssl/t1_lib.c135
1 files changed, 132 insertions, 3 deletions
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
index 20f576e796..d40768560c 100644
--- a/src/lib/libssl/t1_lib.c
+++ b/src/lib/libssl/t1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t1_lib.c,v 1.58 2014/09/27 11:01:06 jsing Exp $ */ 1/* $OpenBSD: t1_lib.c,v 1.59 2014/09/30 15:40:09 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -110,11 +110,13 @@
110 */ 110 */
111 111
112#include <stdio.h> 112#include <stdio.h>
113#include <openssl/objects.h> 113
114#include <openssl/evp.h> 114#include <openssl/evp.h>
115#include <openssl/hmac.h> 115#include <openssl/hmac.h>
116#include <openssl/objects.h>
116#include <openssl/ocsp.h> 117#include <openssl/ocsp.h>
117#include <openssl/rand.h> 118#include <openssl/rand.h>
119
118#include "ssl_locl.h" 120#include "ssl_locl.h"
119 121
120static int tls_decrypt_ticket(SSL *s, const unsigned char *tick, int ticklen, 122static int tls_decrypt_ticket(SSL *s, const unsigned char *tick, int ticklen,
@@ -406,6 +408,134 @@ tls1_check_curve(SSL *s, const unsigned char *p, size_t len)
406 return (0); 408 return (0);
407} 409}
408 410
411/* For an EC key set TLS ID and required compression based on parameters. */
412static int
413tls1_set_ec_id(unsigned char *curve_id, unsigned char *comp_id, EC_KEY *ec)
414{
415 const EC_GROUP *grp;
416 const EC_METHOD *meth;
417 int is_prime = 0;
418 int nid, id;
419
420 if (ec == NULL)
421 return (0);
422
423 if (EC_KEY_get0_public_key(ec) == NULL)
424 return (0);
425
426 /* Determine if it is a prime field. */
427 if ((grp = EC_KEY_get0_group(ec)) == NULL)
428 return (0);
429 if ((meth = EC_GROUP_method_of(grp)) == NULL)
430 return (0);
431 if (EC_METHOD_get_field_type(meth) == NID_X9_62_prime_field)
432 is_prime = 1;
433
434 /* Determine curve ID. */
435 nid = EC_GROUP_get_curve_name(grp);
436 id = tls1_ec_nid2curve_id(nid);
437
438 /* If we have an ID set it, otherwise set arbitrary explicit curve. */
439 if (id != 0) {
440 curve_id[0] = 0;
441 curve_id[1] = (unsigned char)id;
442 } else {
443 curve_id[0] = 0xff;
444 curve_id[1] = is_prime ? 0x01 : 0x02;
445 }
446
447 /* Specify the compression identifier. */
448 if (comp_id != NULL) {
449 if (EC_KEY_get_conv_form(ec) == POINT_CONVERSION_COMPRESSED) {
450 *comp_id = is_prime ?
451 TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime :
452 TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2;
453 } else {
454 *comp_id = TLSEXT_ECPOINTFORMAT_uncompressed;
455 }
456 }
457 return (1);
458}
459
460/* Check that an EC key is compatible with extensions. */
461static int
462tls1_check_ec_key(SSL *s, unsigned char *curve_id, unsigned char *comp_id)
463{
464 const unsigned char *p;
465 size_t plen, i;
466
467 /*
468 * Check point formats extension if present, otherwise everything
469 * is supported (see RFC4492).
470 */
471 if (comp_id != NULL && s->session->tlsext_ecpointformatlist != NULL) {
472 p = s->session->tlsext_ecpointformatlist;
473 plen = s->session->tlsext_ecpointformatlist_length;
474 for (i = 0; i < plen; i++, p++) {
475 if (*comp_id == *p)
476 break;
477 }
478 if (i == plen)
479 return (0);
480 }
481
482 /*
483 * Check curve list if present, otherwise everything is supported.
484 */
485 if (s->session->tlsext_ellipticcurvelist != NULL) {
486 p = s->session->tlsext_ellipticcurvelist;
487 plen = s->session->tlsext_ellipticcurvelist_length;
488 for (i = 0; i < plen; i += 2, p += 2) {
489 if (p[0] == curve_id[0] && p[1] == curve_id[1])
490 break;
491 }
492 if (i == plen)
493 return (0);
494 }
495
496 return (1);
497}
498
499/* Check EC server key is compatible with client extensions. */
500int
501tls1_check_ec_server_key(SSL *s)
502{
503 CERT_PKEY *cpk = s->cert->pkeys + SSL_PKEY_ECC;
504 unsigned char comp_id, curve_id[2];
505 EVP_PKEY *pkey;
506 int rv;
507
508 if (cpk->x509 == NULL || cpk->privatekey == NULL)
509 return (0);
510 if ((pkey = X509_get_pubkey(cpk->x509)) == NULL)
511 return (0);
512 rv = tls1_set_ec_id(curve_id, &comp_id, pkey->pkey.ec);
513 EVP_PKEY_free(pkey);
514 if (rv != 1)
515 return (0);
516
517 return tls1_check_ec_key(s, curve_id, &comp_id);
518}
519
520/* Check EC temporary key is compatible with client extensions. */
521int
522tls1_check_ec_tmp_key(SSL *s)
523{
524 EC_KEY *ec = s->cert->ecdh_tmp;
525 unsigned char curve_id[2];
526
527 if (ec == NULL) {
528 if (s->cert->ecdh_tmp_cb != NULL)
529 return (1);
530 else
531 return (0);
532 }
533 if (tls1_set_ec_id(curve_id, NULL, ec) != 1)
534 return (0);
535
536 return tls1_check_ec_key(s, curve_id, NULL);
537}
538
409/* 539/*
410 * List of supported signature algorithms and hashes. Should make this 540 * List of supported signature algorithms and hashes. Should make this
411 * customisable at some point, for now include everything we support. 541 * customisable at some point, for now include everything we support.
@@ -2132,4 +2262,3 @@ tls1_process_sigalgs(SSL *s, const unsigned char *data, int dsize)
2132 c->pkeys[SSL_PKEY_ECC].digest = EVP_sha1(); 2262 c->pkeys[SSL_PKEY_ECC].digest = EVP_sha1();
2133 return 1; 2263 return 1;
2134} 2264}
2135