Patch equal preference

This commit is contained in:
2018-05-23 23:53:45 +09:00
parent ef253190c7
commit 568c1175f2
15 changed files with 407 additions and 157 deletions
+79 -11
View File
@@ -1108,6 +1108,71 @@ int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm)
return X509_VERIFY_PARAM_set1(ssl->param, vpm);
}
void ssl_cipher_preference_list_free(struct ssl_cipher_preference_list_st
*cipher_list)
{
sk_SSL_CIPHER_free(cipher_list->ciphers);
OPENSSL_free(cipher_list->in_group_flags);
OPENSSL_free(cipher_list);
}
struct ssl_cipher_preference_list_st*
ssl_cipher_preference_list_dup(struct ssl_cipher_preference_list_st
*cipher_list)
{
struct ssl_cipher_preference_list_st* ret = NULL;
size_t n = sk_SSL_CIPHER_num(cipher_list->ciphers);
ret = OPENSSL_malloc(sizeof(struct ssl_cipher_preference_list_st));
if (!ret)
goto err;
ret->ciphers = NULL;
ret->in_group_flags = NULL;
ret->ciphers = sk_SSL_CIPHER_dup(cipher_list->ciphers);
if (!ret->ciphers)
goto err;
ret->in_group_flags = OPENSSL_malloc(n);
if (!ret->in_group_flags)
goto err;
memcpy(ret->in_group_flags, cipher_list->in_group_flags, n);
return ret;
err:
if (ret->ciphers)
sk_SSL_CIPHER_free(ret->ciphers);
if (ret)
OPENSSL_free(ret);
return NULL;
}
struct ssl_cipher_preference_list_st*
ssl_cipher_preference_list_from_ciphers(STACK_OF(SSL_CIPHER) *ciphers)
{
struct ssl_cipher_preference_list_st* ret = NULL;
size_t n = sk_SSL_CIPHER_num(ciphers);
ret = OPENSSL_malloc(sizeof(struct ssl_cipher_preference_list_st));
if (!ret)
goto err;
ret->ciphers = NULL;
ret->in_group_flags = NULL;
ret->ciphers = sk_SSL_CIPHER_dup(ciphers);
if (!ret->ciphers)
goto err;
ret->in_group_flags = OPENSSL_malloc(n);
if (!ret->in_group_flags)
goto err;
memset(ret->in_group_flags, 0, n);
return ret;
err:
if (ret->ciphers)
sk_SSL_CIPHER_free(ret->ciphers);
if (ret)
OPENSSL_free(ret);
return NULL;
}
X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx)
{
return ctx->param;
@@ -1148,7 +1213,8 @@ void SSL_free(SSL *s)
BUF_MEM_free(s->init_buf);
/* add extra stuff */
sk_SSL_CIPHER_free(s->cipher_list);
if (s->cipher_list != NULL)
ssl_cipher_preference_list_free(s->cipher_list);
sk_SSL_CIPHER_free(s->cipher_list_by_id);
sk_SSL_CIPHER_free(s->tls13_ciphersuites);
@@ -2431,9 +2497,9 @@ STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s)
{
if (s != NULL) {
if (s->cipher_list != NULL) {
return s->cipher_list;
return (s->cipher_list->ciphers);
} else if ((s->ctx != NULL) && (s->ctx->cipher_list != NULL)) {
return s->ctx->cipher_list;
return (s->ctx->cipher_list->ciphers);
}
}
return NULL;
@@ -2507,8 +2573,8 @@ const char *SSL_get_cipher_list(const SSL *s, int n)
* preference */
STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx)
{
if (ctx != NULL)
return ctx->cipher_list;
if (ctx != NULL && ctx->cipher_list != NULL)
return ctx->cipher_list->ciphers;
return NULL;
}
@@ -2932,7 +2998,7 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)
ret->tls13_ciphersuites,
&ret->cipher_list, &ret->cipher_list_by_id,
SSL_DEFAULT_CIPHER_LIST, ret->cert)
|| sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {
|| sk_SSL_CIPHER_num(ret->cipher_list->ciphers) <= 0) {
SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_LIBRARY_HAS_NO_CIPHERS);
goto err2;
}
@@ -3095,7 +3161,7 @@ void SSL_CTX_free(SSL_CTX *a)
#ifndef OPENSSL_NO_CT
CTLOG_STORE_free(a->ctlog_store);
#endif
sk_SSL_CIPHER_free(a->cipher_list);
ssl_cipher_preference_list_free(a->cipher_list);
sk_SSL_CIPHER_free(a->cipher_list_by_id);
sk_SSL_CIPHER_free(a->tls13_ciphersuites);
ssl_cert_free(a->cert);
@@ -3747,13 +3813,15 @@ SSL *SSL_dup(SSL *s)
/* dup the cipher_list and cipher_list_by_id stacks */
if (s->cipher_list != NULL) {
if ((ret->cipher_list = sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
ret->cipher_list = ssl_cipher_preference_list_dup(s->cipher_list);
if (ret->cipher_list == NULL)
goto err;
}
if (s->cipher_list_by_id != NULL)
if ((ret->cipher_list_by_id = sk_SSL_CIPHER_dup(s->cipher_list_by_id))
== NULL)
if (s->cipher_list_by_id != NULL) {
ret->cipher_list_by_id = sk_SSL_CIPHER_dup(s->cipher_list_by_id);
if (ret->cipher_list_by_id == NULL)
goto err;
}
/* Dup the client_CA list */
if (s->ca_names != NULL) {