Activated Curve25519 support for ECDHE cipher suites.
This commit is contained in:
parent
693d2a0085
commit
3655193439
30 changed files with 750 additions and 341 deletions
|
|
@ -211,6 +211,23 @@ extern const hash_function hash_functions[];
|
|||
*/
|
||||
unsigned parse_hash_functions(const char *arg);
|
||||
|
||||
/*
|
||||
* Get a curve name (by ID). If the curve ID is not known, this returns
|
||||
* NULL.
|
||||
*/
|
||||
const char *get_curve_name(int id);
|
||||
|
||||
/*
|
||||
* Get a curve name (by ID). The name is written in the provided buffer
|
||||
* (zero-terminated). If the curve ID is not known, the name is
|
||||
* "unknown (***)" where "***" is the decimal value of the identifier.
|
||||
* If the name does not fit in the provided buffer, then dst[0] is set
|
||||
* to 0 (unless len is 0, in which case nothing is written), and -1 is
|
||||
* returned. Otherwise, the name is written in dst[] (with a terminating
|
||||
* 0), and this function returns 0.
|
||||
*/
|
||||
int get_curve_name_ext(int id, char *dst, size_t len);
|
||||
|
||||
/*
|
||||
* Type for a known cipher suite.
|
||||
*/
|
||||
|
|
@ -270,6 +287,11 @@ const char *get_suite_name(unsigned suite);
|
|||
*/
|
||||
int get_suite_name_ext(unsigned suite, char *dst, size_t len);
|
||||
|
||||
/*
|
||||
* Tell whether a cipher suite uses ECDHE key exchange.
|
||||
*/
|
||||
int uses_ecdhe(unsigned suite);
|
||||
|
||||
/*
|
||||
* Print out all known names (for protocol versions, cipher suites...).
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -319,13 +319,19 @@ cc_choose(const br_ssl_client_certificate_class **pctx,
|
|||
|
||||
static uint32_t
|
||||
cc_do_keyx(const br_ssl_client_certificate_class **pctx,
|
||||
unsigned char *data, size_t len)
|
||||
unsigned char *data, size_t *len)
|
||||
{
|
||||
ccert_context *zc;
|
||||
size_t xoff, xlen;
|
||||
uint32_t r;
|
||||
|
||||
zc = (ccert_context *)pctx;
|
||||
return br_ec_prime_i31.mul(data, len, zc->sk->key.ec.x,
|
||||
r = br_ec_all_m15.mul(data, *len, zc->sk->key.ec.x,
|
||||
zc->sk->key.ec.xlen, zc->sk->key.ec.curve);
|
||||
xoff = br_ec_all_m15.xoff(zc->sk->key.ec.curve, &xlen);
|
||||
memmove(data, data + xoff, xlen);
|
||||
*len = xlen;
|
||||
return r;
|
||||
}
|
||||
|
||||
static size_t
|
||||
|
|
@ -392,7 +398,7 @@ cc_do_sign(const br_ssl_client_certificate_class **pctx,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
sig_len = br_ecdsa_i31_sign_asn1(&br_ec_prime_i31,
|
||||
sig_len = br_ecdsa_i31_sign_asn1(&br_ec_all_m15,
|
||||
hc, hv, &zc->sk->key.ec, data);
|
||||
if (sig_len == 0) {
|
||||
if (zc->verbose) {
|
||||
|
|
@ -957,17 +963,17 @@ do_client(int argc, char *argv[])
|
|||
br_ssl_client_set_rsapub(&cc, &br_rsa_i31_public);
|
||||
}
|
||||
if ((req & REQ_ECDHE_RSA) != 0) {
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_prime_i31);
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_all_m15);
|
||||
br_ssl_engine_set_rsavrfy(&cc.eng,
|
||||
&br_rsa_i31_pkcs1_vrfy);
|
||||
}
|
||||
if ((req & REQ_ECDHE_ECDSA) != 0) {
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_prime_i31);
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_all_m15);
|
||||
br_ssl_engine_set_ecdsa(&cc.eng,
|
||||
&br_ecdsa_i31_vrfy_asn1);
|
||||
}
|
||||
if ((req & REQ_ECDH) != 0) {
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_prime_i31);
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_all_m15);
|
||||
}
|
||||
}
|
||||
if (fallback) {
|
||||
|
|
@ -1001,7 +1007,7 @@ do_client(int argc, char *argv[])
|
|||
}
|
||||
br_x509_minimal_set_rsa(&xc, &br_rsa_i31_pkcs1_vrfy);
|
||||
br_x509_minimal_set_ecdsa(&xc,
|
||||
&br_ec_prime_i31, &br_ecdsa_i31_vrfy_asn1);
|
||||
&br_ec_all_m15, &br_ecdsa_i31_vrfy_asn1);
|
||||
|
||||
/*
|
||||
* If there is no provided trust anchor, then certificate validation
|
||||
|
|
|
|||
120
tools/names.c
120
tools/names.c
|
|
@ -271,6 +271,111 @@ const cipher_suite cipher_suites[] = {
|
|||
{ NULL, 0, 0, NULL }
|
||||
};
|
||||
|
||||
static struct {
|
||||
int id;
|
||||
const char *name;
|
||||
} curves[] = {
|
||||
{ BR_EC_sect163k1,
|
||||
"sect163k1" },
|
||||
{ BR_EC_sect163r1,
|
||||
"sect163r1" },
|
||||
{ BR_EC_sect163r2,
|
||||
"sect163r2" },
|
||||
{ BR_EC_sect193r1,
|
||||
"sect193r1" },
|
||||
{ BR_EC_sect193r2,
|
||||
"sect193r2" },
|
||||
{ BR_EC_sect233k1,
|
||||
"sect233k1" },
|
||||
{ BR_EC_sect233r1,
|
||||
"sect233r1" },
|
||||
{ BR_EC_sect239k1,
|
||||
"sect239k1" },
|
||||
{ BR_EC_sect283k1,
|
||||
"sect283k1" },
|
||||
{ BR_EC_sect283r1,
|
||||
"sect283r1" },
|
||||
{ BR_EC_sect409k1,
|
||||
"sect409k1" },
|
||||
{ BR_EC_sect409r1,
|
||||
"sect409r1" },
|
||||
{ BR_EC_sect571k1,
|
||||
"sect571k1" },
|
||||
{ BR_EC_sect571r1,
|
||||
"sect571r1" },
|
||||
{ BR_EC_secp160k1,
|
||||
"secp160k1" },
|
||||
{ BR_EC_secp160r1,
|
||||
"secp160r1" },
|
||||
{ BR_EC_secp160r2,
|
||||
"secp160r2" },
|
||||
{ BR_EC_secp192k1,
|
||||
"secp192k1" },
|
||||
{ BR_EC_secp192r1,
|
||||
"secp192r1" },
|
||||
{ BR_EC_secp224k1,
|
||||
"secp224k1" },
|
||||
{ BR_EC_secp224r1,
|
||||
"secp224r1" },
|
||||
{ BR_EC_secp256k1,
|
||||
"secp256k1" },
|
||||
{ BR_EC_secp256r1,
|
||||
"secp256r1 (P-256)" },
|
||||
{ BR_EC_secp384r1,
|
||||
"secp384r1 (P-384)" },
|
||||
{ BR_EC_secp521r1,
|
||||
"secp521r1 (P-521)" },
|
||||
{ BR_EC_brainpoolP256r1,
|
||||
"brainpoolP256r1" },
|
||||
{ BR_EC_brainpoolP384r1,
|
||||
"brainpoolP384r1" },
|
||||
{ BR_EC_brainpoolP512r1,
|
||||
"brainpoolP512r1" },
|
||||
{ BR_EC_curve25519,
|
||||
"Curve25519" },
|
||||
{ BR_EC_curve448,
|
||||
"Curve448" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
/* see brssl.h */
|
||||
const char *
|
||||
get_curve_name(int id)
|
||||
{
|
||||
size_t u;
|
||||
|
||||
for (u = 0; curves[u].name; u ++) {
|
||||
if (curves[u].id == id) {
|
||||
return curves[u].name;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* see brssl.h */
|
||||
int
|
||||
get_curve_name_ext(int id, char *dst, size_t len)
|
||||
{
|
||||
const char *name;
|
||||
char tmp[30];
|
||||
size_t n;
|
||||
|
||||
name = get_curve_name(id);
|
||||
if (name == NULL) {
|
||||
sprintf(tmp, "unknown (%d)", id);
|
||||
name = tmp;
|
||||
}
|
||||
n = 1 + strlen(name);
|
||||
if (n > len) {
|
||||
if (len > 0) {
|
||||
dst[0] = 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
memcpy(dst, name, n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* see brssl.h */
|
||||
const char *
|
||||
get_suite_name(unsigned suite)
|
||||
|
|
@ -309,6 +414,21 @@ get_suite_name_ext(unsigned suite, char *dst, size_t len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* see brssl.h */
|
||||
int
|
||||
uses_ecdhe(unsigned suite)
|
||||
{
|
||||
size_t u;
|
||||
|
||||
for (u = 0; cipher_suites[u].name; u ++) {
|
||||
if (cipher_suites[u].suite == suite) {
|
||||
return (cipher_suites[u].req
|
||||
& (REQ_ECDHE_RSA | REQ_ECDHE_ECDSA)) != 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* see brssl.h */
|
||||
void
|
||||
list_names(void)
|
||||
|
|
|
|||
|
|
@ -440,19 +440,25 @@ choose_ok:
|
|||
|
||||
static uint32_t
|
||||
sp_do_keyx(const br_ssl_server_policy_class **pctx,
|
||||
unsigned char *data, size_t len)
|
||||
unsigned char *data, size_t *len)
|
||||
{
|
||||
policy_context *pc;
|
||||
uint32_t r;
|
||||
size_t xoff, xlen;
|
||||
|
||||
pc = (policy_context *)pctx;
|
||||
switch (pc->sk->key_type) {
|
||||
case BR_KEYTYPE_RSA:
|
||||
return br_rsa_ssl_decrypt(
|
||||
&br_rsa_i31_private, &pc->sk->key.rsa,
|
||||
data, len);
|
||||
data, *len);
|
||||
case BR_KEYTYPE_EC:
|
||||
return br_ec_prime_i31.mul(data, len, pc->sk->key.ec.x,
|
||||
r = br_ec_all_m15.mul(data, *len, pc->sk->key.ec.x,
|
||||
pc->sk->key.ec.xlen, pc->sk->key.ec.curve);
|
||||
xoff = br_ec_all_m15.xoff(pc->sk->key.ec.curve, &xlen);
|
||||
memmove(data, data + xoff, xlen);
|
||||
*len = xlen;
|
||||
return r;
|
||||
default:
|
||||
fprintf(stderr, "ERROR: unknown private key type (%d)\n",
|
||||
(int)pc->sk->key_type);
|
||||
|
|
@ -551,7 +557,7 @@ sp_do_sign(const br_ssl_server_policy_class **pctx,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
sig_len = br_ecdsa_i31_sign_asn1(&br_ec_prime_i31,
|
||||
sig_len = br_ecdsa_i31_sign_asn1(&br_ec_all_m15,
|
||||
hc, hv, &pc->sk->key.ec, data);
|
||||
if (sig_len == 0) {
|
||||
if (pc->verbose) {
|
||||
|
|
@ -923,7 +929,7 @@ do_server(int argc, char *argv[])
|
|||
break;
|
||||
case BR_KEYTYPE_EC:
|
||||
curve = sk->key.ec.curve;
|
||||
supp = br_ec_prime_i31.supported_curves;
|
||||
supp = br_ec_all_m15.supported_curves;
|
||||
if (curve > 31 || !((supp >> curve) & 1)) {
|
||||
fprintf(stderr, "ERROR: private key curve (%d)"
|
||||
" is not supported\n", curve);
|
||||
|
|
@ -1047,7 +1053,7 @@ do_server(int argc, char *argv[])
|
|||
&br_sslrec_out_cbc_vtable);
|
||||
}
|
||||
if ((req & (REQ_ECDHE_RSA | REQ_ECDHE_ECDSA)) != 0) {
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_prime_i31);
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_all_m15);
|
||||
}
|
||||
}
|
||||
br_ssl_engine_set_suites(&cc.eng, suite_ids, num_suites);
|
||||
|
|
@ -1120,11 +1126,11 @@ do_server(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
br_ssl_engine_set_rsavrfy(&cc.eng, &br_rsa_i31_pkcs1_vrfy);
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_prime_i31);
|
||||
br_ssl_engine_set_ec(&cc.eng, &br_ec_all_m15);
|
||||
br_ssl_engine_set_ecdsa(&cc.eng, &br_ecdsa_i31_vrfy_asn1);
|
||||
br_x509_minimal_set_rsa(&xc, &br_rsa_i31_pkcs1_vrfy);
|
||||
br_x509_minimal_set_ecdsa(&xc,
|
||||
&br_ec_prime_i31, &br_ecdsa_i31_vrfy_asn1);
|
||||
&br_ec_all_m15, &br_ecdsa_i31_vrfy_asn1);
|
||||
br_ssl_engine_set_x509(&cc.eng, &xc.vtable);
|
||||
br_ssl_server_set_trust_anchor_names_alt(&cc,
|
||||
&VEC_ELT(anchors, 0), VEC_LEN(anchors));
|
||||
|
|
|
|||
|
|
@ -239,6 +239,13 @@ run_ssl_engine(br_ssl_engine_context *cc, int fd, unsigned flags)
|
|||
get_suite_name_ext(
|
||||
cc->session.cipher_suite, csn, sizeof csn);
|
||||
fprintf(stderr, " cipher suite: %s\n", csn);
|
||||
if (uses_ecdhe(cc->session.cipher_suite)) {
|
||||
get_curve_name_ext(
|
||||
br_ssl_engine_get_ecdhe_curve(cc),
|
||||
csn, sizeof csn);
|
||||
fprintf(stderr,
|
||||
" ECDHE curve: %s\n", csn);
|
||||
}
|
||||
fprintf(stderr, " secure renegotiation: %s\n",
|
||||
cc->reneg == 1 ? "no" : "yes");
|
||||
pname = br_ssl_engine_get_selected_protocol(cc);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue