-
Notifications
You must be signed in to change notification settings - Fork 20
openssl
Link : https://github.com/openssl/openssl/commit/0324ffc5d5d393111288eca2c9d67f2141ed65f5
Description: Fix PEM certificate loading that sometimes fails
At crypto/pem/pem_lib.c
@@ -806,7 +806,7 @@ static int get_header_and_data(BIO *bp, BIO **header, BIO **data, char *name,
{
BIO *tmp = *header;
char *linebuf, *p;
+ int len, line, ret = 0, end = 0, prev_partial_line_read = 0, partial_line_read = 0;
- int len, line, ret = 0, end = 0;
/* 0 if not seen (yet), 1 if reading header, 2 if finished header */
enum header_status got_header = MAYBE_HEADER;
unsigned int flags_mask;
@@ -833,8 +833,6 @@ static int get_header_and_data(BIO *bp, BIO **header, BIO **data, char *name,
* has been read. Keep the previous value to ignore newlines that
* appear due to reading a line up until the char before the newline.
*/
+ prev_partial_line_read = partial_line_read;
+ partial_line_read = len == LINESIZE-1 && linebuf[LINESIZE-2] != '\n';
if (got_header == MAYBE_HEADER) {
if (memchr(linebuf, ':', len) != NULL)
@@ -850,15 +848,13 @@ static int get_header_and_data(BIO *bp, BIO **header, BIO **data, char *name,
* If previous line has been read only partially this newline is a
* regular newline at the end of a line and not an empty line.
*/
+ if (!prev_partial_line_read) {
+ if (got_header == POST_HEADER) {
+ /* Another blank line is an error. */
+ PEMerr(PEM_F_GET_HEADER_AND_DATA, PEM_R_BAD_END_LINE);
+ goto err;
+ }
+ got_header = POST_HEADER;
+ tmp = *data;
- if (got_header == POST_HEADER) {
- /* Another blank line is an error. */
- PEMerr(PEM_F_GET_HEADER_AND_DATA, PEM_R_BAD_END_LINE);
- goto err;
}
- got_header = POST_HEADER;
- tmp = *data;
continue;
}
Tags
#Memory-error
#Omission
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/082c041b4233b17b80129d4ac6b33a28014442b0
Description: Avoid using rounding errors in range check
At crypto/bio/b_print.c
@@ -640,8 +640,7 @@ fmtfp(char **sbuffer,
* of ULONG_MAX to avoid using imprecise floating point values.
* The second condition is necessary to catch NaN values.
*/
+ if (ufvalue >= (double)(ULONG_MAX - 65535) + 65536.0
+ || !(ufvalue == ufvalue) /* NaN */) {
- if (ufvalue > ULONG_MAX) {
/* Number too big */
return 0;
}
Tags
#Logical-error
#Invalid-condition
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/0ec738433e522c96c7edfe4c9ffdc76d4dfef00a
Description: Multiple fixes for getting pub key from legacy DH PKEY
At crypto/evp/ctrl_params_translate.c
@@ -1564,7 +1564,6 @@ static int get_payload_public_key(enum state state,
ctx->p2 = NULL;
switch (EVP_PKEY_get_base_id(pkey)) {
#ifndef OPENSSL_NO_DH
+ case EVP_PKEY_DHX:
case EVP_PKEY_DH:
switch (ctx->params->data_type) {
case OSSL_PARAM_OCTET_STRING:
Tags
#Etc
#Single-line
#Added
Link : https://github.com/openssl/openssl/commit/105c83150f15af3f78ea0758859062842bdbe30e
Description: Procduce correct sign for result of BN_mod()
At crypto/bn/bn_div.c
@@ -268,7 +268,7 @@ int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,
BIGNUM *tmp, *snum, *sdiv, *res;
BN_ULONG *resp, *wnum, *wnumtop;
BN_ULONG d0, d1;
+ int num_n, div_n, num_neg;
- int num_n, div_n;
assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);
@@ -326,8 +326,7 @@ int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,
/* Setup quotient */
if (!bn_wexpand(res, loop))
goto err;
+ num_neg = num->neg;
+ res->neg = (num_neg ^ divisor->neg);
- res->neg = (num->neg ^ divisor->neg);
res->top = loop;
res->flags |= BN_FLG_FIXED_TOP;
resp = &(res->d[loop]);
@@ -443,7 +442,7 @@ int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,
*--resp = q;
}
/* snum holds remainder, it's as wide as divisor */
+ snum->neg = num_neg;
- snum->neg = num->neg;
snum->top = div_n;
snum->flags |= BN_FLG_FIXED_TOP;
if (rm != NULL)
Tags
#Logical-error
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/199df4a93f74617612abd9419ad6cf00d9c34bc3
Description: Check_sig_alg_match()
At crypto/x509/v3_purp.c
@@ -362,20 +362,18 @@ static int setup_crldp(X509 *x)
}
/* Check that issuer public key algorithm matches subject signature algorithm */
+static int check_sig_alg_match(const EVP_PKEY *issuer_key, const X509 *subject)
-static int check_sig_alg_match(const EVP_PKEY *pkey, const X509 *subject)
{
+ int signer_nid, subj_sig_nid;
- int pkey_nid;
+ if (issuer_key == NULL)
- if (pkey == NULL)
return X509_V_ERR_NO_ISSUER_PUBLIC_KEY;
+ signer_nid = EVP_PKEY_base_id(issuer_key);
if (OBJ_find_sigid_algs(OBJ_obj2nid(subject->cert_info.signature.algorithm),
+ NULL, &subj_sig_nid) == 0)
+ return X509_V_ERR_UNSUPPORTED_SIGNATURE_ALGORITHM;
+ if (signer_nid == EVP_PKEY_type(subj_sig_nid)
+ || (signer_nid == NID_rsaEncryption && subj_sig_nid == NID_rsassaPss))
+ return X509_V_OK;
+ return X509_V_ERR_SIGNATURE_ALGORITHM_MISMATCH;
- NULL, &pkey_nid) == 0)
- return X509_V_ERR_UNSUPPORTED_SIGNATURE_ALGORITHM;
- if (EVP_PKEY_type(pkey_nid) != EVP_PKEY_base_id(pkey))
- return X509_V_ERR_SIGNATURE_ALGORITHM_MISMATCH;
- return X509_V_OK;
}
#define V1_ROOT (EXFLAG_V1|EXFLAG_SS)
Tags
#Etc
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/1c49be8673713d2ceb03a63be03531d9b28a46bd
Description: Fix DH/DHX named groups to not overwrite the private key length.
At crypto/dh/dh_group_params.c
@@ -34,6 +34,7 @@ static DH *dh_param_init(OSSL_LIB_CTX *libctx, const DH_NAMED_GROUP *group)
ossl_ffc_named_group_set_pqg(&dh->params, group);
dh->params.nid = ossl_ffc_named_group_get_uid(group);
- dh->length = BN_num_bits(dh->params.q);
dh->dirty_cnt++;
return dh;
}
@@ -75,6 +76,7 @@ void ossl_dh_cache_named_group(DH *dh)
dh->params.q = (BIGNUM *)ossl_ffc_named_group_get_q(group);
/* cache the nid */
dh->params.nid = ossl_ffc_named_group_get_uid(group);
- dh->length = BN_num_bits(dh->params.q);
dh->dirty_cnt++;
}
}
Tags
#Logical-error
#Multi-line
#Removed
Link : https://github.com/openssl/openssl/commit/254957f768a61c91c14d89566224173d0831c2ce
Description: Allow small RSA exponents in the default provider
At crypto/rsa/rsa_sp800_56b_check.c
@@ -222,17 +222,25 @@ int ossl_rsa_check_private_exponent(const RSA *rsa, int nbits, BN_CTX *ctx)
* Check exponent is odd.
* For FIPS also check the bit length is in the range [17..256]
*/
-#ifndef FIPS_MODULE
-static int bn_is_three(const BIGNUM *bn)
-{
- BIGNUM *num = BN_dup(bn);
- int ret = (num != NULL && BN_sub_word(num, 3) && BN_is_zero(num));
- BN_free(num);
- return ret;
-}
-#endif /* FIPS_MODULE */
int ossl_rsa_check_public_exponent(const BIGNUM *e)
{
+#ifdef FIPS_MODULE
int bitlen;
-#ifndef FIPS_MODULE
- if (bn_is_three(e))
- return 1;
-#endif /* FIPS_MODULE */
bitlen = BN_num_bits(e);
return (BN_is_odd(e) && bitlen > 16 && bitlen < 257);
+#else
+ /* Allow small exponents larger than 1 for legacy purposes */
+ return BN_is_odd(e) && BN_cmp(e, BN_value_one()) > 0;
+#endif /* FIPS_MODULE */
}
/*
Tags
#Etc
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/34ed73339602c361d09fe4233d65cef996356239
Description: Fix CTRL API for the digest size.
At crypto/evp/ctrl_params_translate.c
@@ -2097,9 +2097,6 @@ static const struct translation_st evp_pkey_ctx_translations[] = {
* SipHash
* ======
*/
+ { SET, -1, -1, EVP_PKEY_OP_TYPE_SIG,
+ EVP_PKEY_CTRL_SET_DIGEST_SIZE, "digestsize", NULL,
+ OSSL_MAC_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL },
/*-
* TLS1-PRF
Tags
#Omission
#Multi-line
#Added
Link : https://github.com/openssl/openssl/commit/38145fba0a5f6163743f007dd6c9ba1a1e07e4f4
Description: Fix DSA/DH so that legacy keys can still be generated by the default provider
At crypto/ffc/ffc_params_validate.c
@@ -99,11 +99,6 @@ int ffc_params_simple_validate(OPENSSL_CTX *libctx, FFC_PARAMS *params, int type
params->flags = FFC_PARAM_FLAG_VALIDATE_G;
params->gindex = FFC_UNVERIFIABLE_GINDEX;
+#ifndef FIPS_MODULE
+ if (save_flags & FFC_PARAM_FLAG_VALIDATE_LEGACY)
+ ret = ffc_params_FIPS186_2_validate(libctx, params, type, &res, NULL);
+ else
+#endif
ret = ffc_params_FIPS186_4_validate(libctx, params, type, &res, NULL);
params->flags = save_flags;
params->gindex = save_gindex;
Tags
#Omission
#Multi-line
#Added
Link : https://github.com/openssl/openssl/commit/3a37ddde911fe735c73121a8a561451cc719fc91
Description: Fix DSA EVP_PKEY_param_check() when defaults are used for param generation.
At crypto/ffc/ffc_params_validate.c
@@ -152,12 +152,8 @@ int ossl_ffc_params_full_validate(OSSL_LIB_CTX *libctx, const FFC_PARAMS *params
res, NULL);
#else
if (params->seed != NULL) {
+ if (params->flags & FFC_PARAM_FLAG_VALIDATE_LEGACY)
+ return ossl_ffc_params_FIPS186_2_validate(libctx, params, paramstype,
+ res, NULL);
+ else
+ return ossl_ffc_params_FIPS186_4_validate(libctx, params, paramstype,
+ res, NULL);
- return ossl_ffc_params_FIPS186_4_validate(libctx, params, paramstype,
- res, NULL);
} else {
int ret = 0;
At include/crypto/dsa.h
@@ -17,7 +17,6 @@
#define DSA_PARAMGEN_TYPE_FIPS_186_4 0 /* Use FIPS186-4 standard */
#define DSA_PARAMGEN_TYPE_FIPS_186_2 1 /* Use legacy FIPS186-2 standard */
+#define DSA_PARAMGEN_TYPE_FIPS_DEFAULT 2
DSA *ossl_dsa_new(OSSL_LIB_CTX *libctx);
void ossl_dsa_set0_libctx(DSA *d, OSSL_LIB_CTX *libctx);
At providers/implementations/keymgmt/dsa_kmgmt.c
@@ -78,7 +78,7 @@ static const DSA_GENTYPE_NAME2ID dsatype2id[]=
#ifdef FIPS_MODULE
{ "default", DSA_PARAMGEN_TYPE_FIPS_186_4 },
#else
+ { "default", DSA_PARAMGEN_TYPE_FIPS_DEFAULT },
- { "default", DSA_PARAMGEN_TYPE_FIPS_186_2 },
#endif
{ "fips186_4", DSA_PARAMGEN_TYPE_FIPS_186_4 },
{ "fips186_2", DSA_PARAMGEN_TYPE_FIPS_186_2 },
@@ -382,7 +382,7 @@ static void *dsa_gen_init(void *provctx, int selection,
#ifdef FIPS_MODULE
gctx->gen_type = DSA_PARAMGEN_TYPE_FIPS_186_4;
#else
+ gctx->gen_type = DSA_PARAMGEN_TYPE_FIPS_DEFAULT;
- gctx->gen_type = DSA_PARAMGEN_TYPE_FIPS_186_2;
#endif
gctx->gindex = -1;
gctx->pcounter = -1;
@@ -527,10 +527,7 @@ static void *dsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg)
if (dsa == NULL)
return NULL;
+ if (gctx->gen_type == DSA_PARAMGEN_TYPE_FIPS_DEFAULT)
+ gctx->gen_type = (gctx->pbits >= 2048 ? DSA_PARAMGEN_TYPE_FIPS_186_4 :
+ DSA_PARAMGEN_TYPE_FIPS_186_2);
gctx->cb = osslcb;
gctx->cbarg = cbarg;
gencb = BN_GENCB_new();
Tags
#Invalid-condition
#Logical-error
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/3bed88a3970605a2ff817065f93b08e965d89e5f
Description: Restore rejection of expired trusted (root) certificate
At crypto/x509/x509_cmp.c
@@ -142,8 +142,6 @@ int X509_cmp(const X509 *a, const X509 *b)
{
int rv;
+ if (a == b) /* for efficiency */
+ return 0;
/* ensure hash is valid */
if (X509_check_purpose((X509 *)a, -1, 0) != 1)
return -2;
At crypto/x509/x509_vfy.c
@@ -303,16 +303,8 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
return ret;
}
+static int sk_X509_contains(STACK_OF(X509) *sk, X509 *cert)
+{
+ int i, n = sk_X509_num(sk);
+ for (i = 0; i < n; i++)
+ if (X509_cmp(sk_X509_value(sk, i), cert) == 0)
+ return 1;
+ return 0;
+}
/*
* Find in given STACK_OF(X509) sk a non-expired issuer cert (if any) of given cert x.
* The issuer must not be the same as x and must not yet be in ctx->chain, where the
@@ -329,9 +319,7 @@ static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x)
* Below check 'issuer != x' is an optimization and safety precaution:
* Candidate issuer cert cannot be the same as the subject cert 'x'.
*/
+ if (issuer != x && ctx->check_issued(ctx, x, issuer)
+ && (((x->ex_flags & EXFLAG_SI) != 0 && sk_X509_num(ctx->chain) == 1)
+ || !sk_X509_contains(ctx->chain, issuer))) {
- if (issuer != x && ctx->check_issued(ctx, x, issuer)) {
rv = issuer;
if (x509_check_cert_time(ctx, rv, -1))
break;
@@ -341,9 +329,20 @@ static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x)
}
/* Check that the given certificate 'x' is issued by the certificate 'issuer' */
+static int check_issued(ossl_unused X509_STORE_CTX *ctx, X509 *x, X509 *issuer)
-static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer)
{
+ return x509_likely_issued(issuer, x) == X509_V_OK;
- if (x509_likely_issued(issuer, x) != X509_V_OK)
- return 0;
- if ((x->ex_flags & EXFLAG_SI) == 0 || sk_X509_num(ctx->chain) != 1) {
- int i;
- X509 *ch;
- for (i = 0; i < sk_X509_num(ctx->chain); i++) {
- ch = sk_X509_value(ctx->chain, i);
- if (ch == issuer || X509_cmp(ch, issuer) == 0)
- return 0;
- }
- }
- return 1;
}
/* Alternative lookup method: look from a STACK stored in other_ctx */
Tags
#Omission
#Invalid-condition
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/4516bf7422223a47f98931c1315985bd9dc303af
Description: Instantiate the DRBGs upon first use.
At crypto/rand/rand_lib.c
@@ -469,11 +469,6 @@ static EVP_RAND_CTX *rand_new_drbg(OPENSSL_CTX *libctx, EVP_RAND_CTX *parent,
EVP_RAND_CTX_free(ctx);
return NULL;
}
+ if (!EVP_RAND_instantiate(ctx, 0, 0, NULL, 0)) {
+ RANDerr(0, RAND_R_ERROR_INSTANTIATING_DRBG);
+ EVP_RAND_CTX_free(ctx);
+ return NULL;
+ }
return ctx;
}
Tags
#Omission
#Multi-line
#Added
Link : https://github.com/openssl/openssl/commit/45c236ad1f1c881281017941a0e7126735a190e8
Description: Add RSA SHA512 truncated digest support
At crypto/rsa/rsa_pmeth.c
@@ -382,8 +382,6 @@ static int check_padding_md(const EVP_MD *md, int padding)
case NID_sha256:
case NID_sha384:
case NID_sha512:
+ case NID_sha512_224:
+ case NID_sha512_256:
case NID_md5:
case NID_md5_sha1:
case NID_md2:
At include/openssl/core_names.h
@@ -94,8 +94,6 @@ extern "C" {
#define OSSL_DIGEST_NAME_SHA2_256 "SHA2-256"
#define OSSL_DIGEST_NAME_SHA2_384 "SHA2-384"
#define OSSL_DIGEST_NAME_SHA2_512 "SHA2-512"
+#define OSSL_DIGEST_NAME_SHA2_512_224 "SHA2-512/224"
+#define OSSL_DIGEST_NAME_SHA2_512_256 "SHA2-512/256"
#define OSSL_DIGEST_NAME_MD2 "MD2"
#define OSSL_DIGEST_NAME_MD4 "MD4"
#define OSSL_DIGEST_NAME_MDC2 "MDC2"
At providers/common/der/der_rsa.c.in
@@ -62,8 +62,6 @@ int DER_w_algorithmIdentifier_RSA_with(WPACKET *pkt, int tag,
MD_CASE(sha256);
MD_CASE(sha384);
MD_CASE(sha512);
+ MD_CASE(sha512_224);
+ MD_CASE(sha512_256);
MD_CASE(sha3_224);
MD_CASE(sha3_256);
MD_CASE(sha3_384);
At providers/implementations/signature/rsa.c
@@ -129,8 +129,6 @@ static int rsa_get_md_nid(const EVP_MD *md)
{ NID_sha256, OSSL_DIGEST_NAME_SHA2_256 },
{ NID_sha384, OSSL_DIGEST_NAME_SHA2_384 },
{ NID_sha512, OSSL_DIGEST_NAME_SHA2_512 },
+ { NID_sha512_224, OSSL_DIGEST_NAME_SHA2_512_224 },
+ { NID_sha512_256, OSSL_DIGEST_NAME_SHA2_512_256 },
{ NID_md5, OSSL_DIGEST_NAME_MD5 },
{ NID_md5_sha1, OSSL_DIGEST_NAME_MD5_SHA1 },
{ NID_md2, OSSL_DIGEST_NAME_MD2 },
Tags
#Omission
#Multi-line
#Added
Link : https://github.com/openssl/openssl/commit/4bb73d5409c056a878f526280f86cc3c01f8cd68
Description: Add a NULL check to EVP_PKEY_assign
At crypto/evp/p_lib.c
@@ -709,7 +709,7 @@ int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key)
int alias = type;
#ifndef OPENSSL_NO_EC
+ if ((key != NULL) && (EVP_PKEY_type(type) == EVP_PKEY_EC)) {
- if (EVP_PKEY_type(type) == EVP_PKEY_EC) {
const EC_GROUP *group = EC_KEY_get0_group(key);
if (group != NULL && EC_GROUP_get_curve_name(group) == NID_sm2)
Tags
#Invalid-condition
#Single-line
#Modified
Link : https://github.com/openssl/openssl/commit/4dd009180a06ad973620c5beec28f2a6839c16ca
Description: Fix a regression in find_issuer()
At crypto/x509/x509_vfy.c
@@ -328,12 +328,12 @@ static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x)
for (i = 0; i < sk_X509_num(sk); i++) {
issuer = sk_X509_value(sk, i);
+ if (ctx->check_issued(ctx, x, issuer)
- if (issuer != x && ctx->check_issued(ctx, x, issuer)
&& (((x->ex_flags & EXFLAG_SI) != 0 && sk_X509_num(ctx->chain) == 1)
|| !sk_X509_contains(ctx->chain, issuer))) {
+ if (x509_check_cert_time(ctx, issuer, -1))
+ return issuer;
rv = issuer;
- if (x509_check_cert_time(ctx, rv, -1))
- break;
}
}
return rv;
Tags
#Invalid-condition
#Logical-error
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/4e4ae84056133c863860e27ceedae8bd3fb0a402
Description: Fix NULL access in ssl_build_cert_chain() when ctx is NULL.
At ssl/ssl_cert.c
@@ -878,7 +878,7 @@ int ssl_build_cert_chain(SSL *s, SSL_CTX *ctx, int flags)
untrusted = cpk->chain;
}
+ xs_ctx = X509_STORE_CTX_new_ex(real_ctx->libctx, real_ctx->propq);
- xs_ctx = X509_STORE_CTX_new_ex(real_ctx->libctx, ctx->propq);
if (xs_ctx == NULL) {
ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE);
goto err;
Tags
#Omission
#Single-line
#Modified
Link : https://github.com/openssl/openssl/commit/5a9dbfc58ab280ec426ed013f5aed5a5660b938a
Description: Clear flags better when clearing errors.
At crypto/err/err_local.h
@@ -27,7 +27,6 @@ static ossl_inline void err_clear_data(ERR_STATE *es, size_t i, int deall)
es->err_data_flags[i] = 0;
} else if (es->err_data[i] != NULL) {
es->err_data[i][0] = '\0';
+ es->err_data_flags[i] = ERR_TXT_MALLOCED;
}
} else {
es->err_data[i] = NULL;
@@ -69,8 +68,6 @@ static ossl_inline void err_set_debug(ERR_STATE *es, size_t i,
static ossl_inline void err_set_data(ERR_STATE *es, size_t i,
void *data, size_t datasz, int flags)
{
+ if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
+ OPENSSL_free(es->err_data[i]);
es->err_data[i] = data;
es->err_data_size[i] = datasz;
es->err_data_flags[i] = flags;
Tags
#Logical-error
#Omission
#Multi-line
#Added
Link : https://github.com/openssl/openssl/commit/604b86d8d360e36fc2fc0d1611d05bf38699d297
Description: Enhanced integer parsing in OSSL_PARAM_allocate_from_text
At crypto/params_from_text.c
@@ -28,7 +28,6 @@ static int prepare_from_text(const OSSL_PARAM *paramdefs, const char *key,
size_t *buf_n, BIGNUM **tmpbn, int *found)
{
const OSSL_PARAM *p;
+ size_t buf_bits;
/*
* ishex is used to translate legacy style string controls in hex format
@@ -51,7 +50,7 @@ static int prepare_from_text(const OSSL_PARAM *paramdefs, const char *key,
if (*ishex)
BN_hex2bn(tmpbn, value);
else
+ BN_asc2bn(tmpbn, value);
- BN_dec2bn(tmpbn, value);
if (*tmpbn == NULL)
return 0;
@@ -67,21 +66,18 @@ static int prepare_from_text(const OSSL_PARAM *paramdefs, const char *key,
* actually have to add 1: -3 - 1 = -4, |-3| = 3 + 1 = 4.
*/
if (p->data_type == OSSL_PARAM_INTEGER && BN_is_negative(*tmpbn)
+ && !BN_add_word(*tmpbn, 1)) {
- && !BN_sub_word(*tmpbn, 1)) {
return 0;
}
+ buf_bits = (size_t)BN_num_bits(*tmpbn);
+ *buf_n = (buf_bits + 7) / 8;
- *buf_n = BN_num_bytes(*tmpbn);
/*
* TODO(v3.0) is this the right way to do this? This code expects
* a zero data size to simply mean "arbitrary size".
*/
if (p->data_size > 0) {
+ if (buf_bits > p->data_size * 8
+ || (p->data_type == OSSL_PARAM_INTEGER
+ && buf_bits == p->data_size * 8)) {
- if (*buf_n >= p->data_size) {
ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_TOO_SMALL_BUFFER);
/* Since this is a different error, we don't break */
return 0;
@@ -190,11 +186,11 @@ int OSSL_PARAM_allocate_from_text(OSSL_PARAM *to,
if (!prepare_from_text(paramdefs, key, value, value_n,
¶mdef, &ishex, &buf_n, &tmpbn, found))
+ goto err;
- return 0;
if ((buf = OPENSSL_zalloc(buf_n > 0 ? buf_n : 1)) == NULL) {
ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
+ goto err;
- return 0;
}
ok = construct_from_text(to, paramdef, value, value_n, ishex,
@@ -203,7 +199,4 @@ int OSSL_PARAM_allocate_from_text(OSSL_PARAM *to,
if (!ok)
OPENSSL_free(buf);
return ok;
+ err:
+ BN_free(tmpbn);
+ return 0;
}
Tags
#Memory-error
#Invalid-condition
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/6e417f951c64f4643cdc62c370badf46d5fe485e
Description: Fix coverity issue: CID 1466485
At crypto/store/store_lib.c
@@ -272,10 +272,6 @@ int OSSL_STORE_find(OSSL_STORE_CTX *ctx, const OSSL_STORE_SEARCH *search)
ERR_raise(ERR_LIB_OSSL_STORE, OSSL_STORE_R_LOADING_STARTED);
return 0;
}
+ if (search == NULL) {
+ ERR_raise(ERR_LIB_OSSL_STORE, ERR_R_PASSED_NULL_PARAMETER);
+ return 0;
+ }
if (ctx->fetched_loader != NULL) {
OSSL_PARAM_BLD *bld;
Tags
#Omission
#Multi-line
#Added
Link : https://github.com/openssl/openssl/commit/78539b250b05d0721da775bf4eddc096bde5ecaa
Description: Duplicate the pctx to allow multiple calls
At crypto/evp/m_sigver.c
@@ -400,7 +400,7 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
size_t *siglen)
{
int sctx = 0, r = 0;
+ EVP_PKEY_CTX *dctx, *pctx = ctx->pctx;
- EVP_PKEY_CTX *pctx = ctx->pctx;
if (pctx == NULL
|| pctx->operation != EVP_PKEY_OP_SIGNCTX
@@ -408,19 +408,8 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
|| pctx->op.sig.signature == NULL)
goto legacy;
+ if (sigret == NULL || (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) != 0)
+ return pctx->op.sig.signature->digest_sign_final(pctx->op.sig.algctx,
+ sigret, siglen,
+ SIZE_MAX);
+ dctx = EVP_PKEY_CTX_dup(pctx);
+ if (dctx == NULL)
+ return 0;
+
+ r = dctx->op.sig.signature->digest_sign_final(dctx->op.sig.algctx,
+ sigret, siglen,
+ SIZE_MAX);
+ EVP_PKEY_CTX_free(dctx);
+ return r;
- return pctx->op.sig.signature->digest_sign_final(pctx->op.sig.algctx,
- sigret, siglen, SIZE_MAX);
legacy:
if (pctx == NULL || pctx->pmeth == NULL) {
@@ -440,7 +429,7 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE)
r = pctx->pmeth->signctx(pctx, sigret, siglen, ctx);
else {
+ dctx = EVP_PKEY_CTX_dup(pctx);
- EVP_PKEY_CTX *dctx = EVP_PKEY_CTX_dup(pctx);
if (dctx == NULL)
return 0;
r = dctx->pmeth->signctx(dctx, sigret, siglen, ctx);
@@ -526,7 +516,7 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
int r = 0;
unsigned int mdlen = 0;
int vctx = 0;
+ EVP_PKEY_CTX *dctx, *pctx = ctx->pctx;
- EVP_PKEY_CTX *pctx = ctx->pctx;
if (pctx == NULL
|| pctx->operation != EVP_PKEY_OP_VERIFYCTX
@@ -534,17 +524,8 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
|| pctx->op.sig.signature == NULL)
goto legacy;
+ if ((ctx->flags & EVP_MD_CTX_FLAG_FINALISE) != 0)
+ return pctx->op.sig.signature->digest_verify_final(pctx->op.sig.algctx,
+ sig, siglen);
+ dctx = EVP_PKEY_CTX_dup(pctx);
+ if (dctx == NULL)
+ return 0;
+
+ r = dctx->op.sig.signature->digest_verify_final(dctx->op.sig.algctx,
+ sig, siglen);
+ EVP_PKEY_CTX_free(dctx);
+ return r;
- return pctx->op.sig.signature->digest_verify_final(pctx->op.sig.algctx,
- sig, siglen);
legacy:
if (pctx == NULL || pctx->pmeth == NULL) {
Tags
#Logical-error
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/85407b77543a2d4330dbb40f6b8520ea0894a716
Description: Fix double free in EVP_PKEY_CTX_dup()
At crypto/evp/pmeth_lib.c
@@ -500,7 +500,6 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
= pctx->op.kex.exchange->dupctx(pctx->op.kex.algctx);
if (rctx->op.kex.algctx == NULL) {
EVP_KEYEXCH_free(rctx->op.kex.exchange);
+ rctx->op.kex.exchange = NULL;
goto err;
}
return rctx;
@@ -518,7 +517,6 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
= pctx->op.sig.signature->dupctx(pctx->op.sig.algctx);
if (rctx->op.sig.algctx == NULL) {
EVP_SIGNATURE_free(rctx->op.sig.signature);
+ rctx->op.sig.signature = NULL;
goto err;
}
return rctx;
@@ -536,7 +534,6 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
= pctx->op.ciph.cipher->dupctx(pctx->op.ciph.algctx);
if (rctx->op.ciph.algctx == NULL) {
EVP_ASYM_CIPHER_free(rctx->op.ciph.cipher);
+ rctx->op.ciph.cipher = NULL;
goto err;
}
return rctx;
@@ -554,7 +551,6 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
= pctx->op.encap.kem->dupctx(pctx->op.encap.algctx);
if (rctx->op.encap.algctx == NULL) {
EVP_KEM_free(rctx->op.encap.kem);
+ rctx->op.encap.kem = NULL;
goto err;
}
return rctx;
Tags
#Logical-error
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/9afc6c54314f94c0dcb4168d01554497bfaeae4f
Description: Fix the check for suitable groups and TLSv1.3
At ssl/statem/extensions_clnt.c
@@ -234,7 +234,7 @@ EXT_RETURN tls_construct_ctos_supported_groups(SSL *s, WPACKET *pkt,
}
}
if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {
+ if (added == 0)
- if (added == 0 || (tls13added == 0 && max_version == TLS1_3_VERSION))
SSLfatal_data(s, SSL_AD_INTERNAL_ERROR, SSL_R_NO_SUITABLE_GROUPS,
"No groups enabled for max supported SSL/TLS version");
else
@@ -242,12 +242,7 @@ EXT_RETURN tls_construct_ctos_supported_groups(SSL *s, WPACKET *pkt,
return EXT_RETURN_FAIL;
}
+ if (tls13added == 0 && max_version == TLS1_3_VERSION) {
+ SSLfatal_data(s, SSL_AD_INTERNAL_ERROR, SSL_R_NO_SUITABLE_GROUPS,
+ "No groups enabled for max supported SSL/TLS version");
+ return EXT_RETURN_FAIL;
+ }
return EXT_RETURN_SENT;
}
Tags
#Invalid-condition
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/c6b09ea0fe23a572a781681b3c1f436e8b0932fe
Description: Fix change in behaviour of EVP_PKEY_CTRL_RSA_KEYGEN_BITS
At crypto/rsa/rsa_local.h
@@ -14,6 +14,7 @@
#include "crypto/rsa.h"
#define RSA_MAX_PRIME_NUM 5
-#define RSA_MIN_MODULUS_BITS 512
typedef struct rsa_prime_info_st {
BIGNUM *r;
At include/crypto/rsa.h
@@ -16,8 +16,7 @@
# include <openssl/x509.h>
# include "crypto/types.h"
+#define RSA_MIN_MODULUS_BITS 512
typedef struct rsa_pss_params_30_st {
int hash_algorithm_nid;
struct {
At providers/implementations/keymgmt/rsa_kmgmt.c
@@ -19,7 +19,6 @@
#include <openssl/err.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
+#include <openssl/proverr.h>
#include "prov/implementations.h"
#include "prov/providercommon.h"
#include "prov/provider_ctx.h"
@@ -474,14 +473,9 @@ static int rsa_gen_set_params(void *genctx, const OSSL_PARAM params[])
if (params == NULL)
return 1;
+ if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_BITS)) != NULL) {
+ if (!OSSL_PARAM_get_size_t(p, &gctx->nbits))
+ return 0;
+ if (gctx->nbits < RSA_MIN_MODULUS_BITS) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SIZE_TOO_SMALL);
+ return 0;
+ }
+ }
- if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_BITS)) != NULL
- && !OSSL_PARAM_get_size_t(p, &gctx->nbits))
- return 0;
if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_PRIMES)) != NULL
&& !OSSL_PARAM_get_size_t(p, &gctx->primes))
return 0;
Tags
#Invalid-condition
#Omission
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/d29d7a7ff22e8e3be1c8bbdb8edd3ab9c72ed021
Description: Fix i2d_PKCS8PrivateKey_nid_bio() regression.
At crypto/pem/pem_pk8.c
@@ -99,7 +99,7 @@ static int do_pk8pkey(BIO *bp, const EVP_PKEY *x, int isder, int nid,
* (e.g. NID_pbe_WithSHA1And2_Key_TripleDES_CBC). Just use the legacy
* path if the NID is passed.
*/
+ if (nid == -1 && OSSL_ENCODER_CTX_get_num_encoders(ctx) != 0) {
- if (OSSL_ENCODER_CTX_get_num_encoders(ctx) != 0) {
ret = 1;
if (enc != NULL) {
ret = 0;
Tags
#Invalid-condition
#Single-line
#Modified
Link : https://github.com/openssl/openssl/commit/da5f770ae31e0df17b1b8a143d13fee805d8deb3
Description: Fix PKCS12_create() so that a fetch error is not added to the error stack.
At crypto/pkcs12/p12_sbag.c
@@ -212,11 +212,9 @@ PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt_ex(int pbe_nid,
EVP_CIPHER *pbe_ciph_fetch = NULL;
X509_SIG *p8;
+ ERR_set_mark();
pbe_ciph = pbe_ciph_fetch = EVP_CIPHER_fetch(ctx, OBJ_nid2sn(pbe_nid), propq);
if (pbe_ciph == NULL)
pbe_ciph = EVP_get_cipherbynid(pbe_nid);
+ ERR_pop_to_mark();
if (pbe_ciph != NULL)
pbe_nid = -1;
Tags
#Omission
#Multi-line
#Added
Link : https://github.com/openssl/openssl/commit/dfccfde06562ac87fe5e5f9401ba86cad050d9a2
Description: Inherit hostflags verify params even without hosts
At crypto/x509/x509_vpm.c
@@ -199,7 +199,6 @@ int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *dest,
return 0;
}
+ x509_verify_param_copy(hostflags, 0);
if (test_x509_verify_param_copy(hosts, NULL)) {
sk_OPENSSL_STRING_pop_free(dest->hosts, str_free);
Tags
#Logical-error
#Single-line
#Added
Link : https://github.com/openssl/openssl/commit/e0f69c3598b61c47fbfe9d4e7d44ed671c334ef5
Description: Fix state name abbreviation
At ssl/ssl_stat.c
@@ -137,9 +137,9 @@ const char *SSL_state_string(const SSL *s)
case TLS_ST_CW_NEXT_PROTO:
return "TWNP";
case TLS_ST_BEFORE:
+ return "PINIT";
- return "PINIT ";
case TLS_ST_OK:
+ return "SSLOK";
- return "SSLOK ";
case TLS_ST_CW_CLNT_HELLO:
return "TWCH";
case TLS_ST_CR_SRVR_HELLO:
@@ -201,7 +201,7 @@ const char *SSL_state_string(const SSL *s)
case TLS_ST_CR_CERT_VRFY:
return "TRSCV";
case TLS_ST_SW_CERT_VRFY:
+ return "TWSCV";
- return "TRSCV";
case TLS_ST_CR_HELLO_REQ:
return "TRHR";
case TLS_ST_SW_KEY_UPDATE:
@@ -221,7 +221,7 @@ const char *SSL_state_string(const SSL *s)
case TLS_ST_SR_END_OF_EARLY_DATA:
return "TWEOED";
default:
+ return "UNKWN";
- return "UNKWN ";
}
}
Tags
#Invalid-format-string
#Multi-line
#Modified
Link : https://github.com/openssl/openssl/commit/ee46dfbf2c117a9532f887b478c9c65d8f30d50c
Description: Fix copying of libctx and propq using new ASN1_OP_DUP_POST cb operation
At crypto/asn1/a_dup.c
@@ -9,7 +9,7 @@
#include <stdio.h>
#include "internal/cryptlib.h"
+#include <openssl/asn1t.h>
-#include <openssl/asn1.h>
#ifndef NO_OLD_ASN1
@@ -48,26 +48,17 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, const void *x)
void *ASN1_item_dup(const ASN1_ITEM *it, const void *x)
{
+ ASN1_aux_cb *asn1_cb = NULL;
unsigned char *b = NULL;
const unsigned char *p;
long i;
+ ASN1_VALUE *ret;
- void *ret;
if (x == NULL)
return NULL;
+ if (it->itype == ASN1_ITYPE_SEQUENCE || it->itype == ASN1_ITYPE_CHOICE
+ || it->itype == ASN1_ITYPE_NDEF_SEQUENCE) {
+ const ASN1_AUX *aux = it->funcs;
+ asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
+ }
+ if (asn1_cb != NULL
+ && !asn1_cb(ASN1_OP_DUP_PRE, (ASN1_VALUE **)&x, it, NULL))
+ goto auxerr;
i = ASN1_item_i2d(x, &b, it);
if (b == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
@@ -76,14 +64,8 @@ void *ASN1_item_dup(const ASN1_ITEM *it, const void *x)
p = b;
ret = ASN1_item_d2i(NULL, &p, i, it);
OPENSSL_free(b);
+ if (asn1_cb != NULL
+ && !asn1_cb(ASN1_OP_DUP_POST, &ret, it, (void *)x))
+ goto auxerr;
return ret;
+ auxerr:
+ ERR_raise_data(ERR_LIB_ASN1, ASN1_R_AUX_ERROR, "Type=%s", it->sname);
+ return NULL;
}
At crypto/x509/x_x509.c
@@ -97,17 +97,8 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
ASN1_OCTET_STRING_free(ret->distinguishing_id);
break;
+ case ASN1_OP_DUP_POST:
+ {
+ X509 *old = exarg;
+ ret->libctx = old->libctx;
+ ret->propq = old->propq;
+ }
+ break;
+ default:
+ break;
}
return 1;
At include/openssl/asn1t.h.in
@@ -746,8 +746,6 @@ typedef struct ASN1_STREAM_ARG_st {
# define ASN1_OP_STREAM_POST 11
# define ASN1_OP_DETACHED_PRE 12
# define ASN1_OP_DETACHED_POST 13
+# define ASN1_OP_DUP_PRE 14
+# define ASN1_OP_DUP_POST 15
/* Macro to implement a primitive type */
# define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)