sync with OpenBSD -current

This commit is contained in:
purplerain 2024-03-26 02:17:23 +00:00
parent fa20b4dfa4
commit 56a087cff9
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
61 changed files with 2001 additions and 1682 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: x509_cmp.c,v 1.43 2024/02/18 15:45:42 tb Exp $ */
/* $OpenBSD: x509_cmp.c,v 1.44 2024/03/25 03:41:16 joshua Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -91,34 +91,35 @@ unsigned long
X509_issuer_and_serial_hash(X509 *a)
{
unsigned long ret = 0;
EVP_MD_CTX ctx;
EVP_MD_CTX *md_ctx;
unsigned char md[16];
char *f;
char *f = NULL;
EVP_MD_CTX_legacy_clear(&ctx);
f = X509_NAME_oneline(a->cert_info->issuer, NULL, 0);
if (f == NULL)
if ((md_ctx = EVP_MD_CTX_new()) == NULL)
goto err;
if (!EVP_DigestInit_ex(&ctx, EVP_md5(), NULL))
if ((f = X509_NAME_oneline(a->cert_info->issuer, NULL, 0)) == NULL)
goto err;
if (!EVP_DigestUpdate(&ctx, (unsigned char *)f, strlen(f)))
if (!EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL))
goto err;
free(f);
f = NULL;
if (!EVP_DigestUpdate(&ctx,
if (!EVP_DigestUpdate(md_ctx, (unsigned char *)f, strlen(f)))
goto err;
if (!EVP_DigestUpdate(md_ctx,
(unsigned char *)a->cert_info->serialNumber->data,
(unsigned long)a->cert_info->serialNumber->length))
goto err;
if (!EVP_DigestFinal_ex(&ctx, &(md[0]), NULL))
if (!EVP_DigestFinal_ex(md_ctx, &(md[0]), NULL))
goto err;
ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) |
((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)) &
0xffffffffL;
err:
EVP_MD_CTX_cleanup(&ctx);
EVP_MD_CTX_free(md_ctx);
free(f);
return (ret);
return ret;
}
LCRYPTO_ALIAS(X509_issuer_and_serial_hash);
#endif
@ -285,24 +286,27 @@ LCRYPTO_ALIAS(X509_NAME_hash);
unsigned long
X509_NAME_hash_old(X509_NAME *x)
{
EVP_MD_CTX md_ctx;
EVP_MD_CTX *md_ctx;
unsigned long ret = 0;
unsigned char md[16];
if ((md_ctx = EVP_MD_CTX_new()) == NULL)
return ret;
/* Make sure X509_NAME structure contains valid cached encoding */
i2d_X509_NAME(x, NULL);
EVP_MD_CTX_legacy_clear(&md_ctx);
if (EVP_DigestInit_ex(&md_ctx, EVP_md5(), NULL) &&
EVP_DigestUpdate(&md_ctx, x->bytes->data, x->bytes->length) &&
EVP_DigestFinal_ex(&md_ctx, md, NULL))
if (EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL) &&
EVP_DigestUpdate(md_ctx, x->bytes->data, x->bytes->length) &&
EVP_DigestFinal_ex(md_ctx, md, NULL))
ret = (((unsigned long)md[0]) |
((unsigned long)md[1] << 8L) |
((unsigned long)md[2] << 16L) |
((unsigned long)md[3] << 24L)) &
0xffffffffL;
EVP_MD_CTX_cleanup(&md_ctx);
return (ret);
EVP_MD_CTX_free(md_ctx);
return ret;
}
LCRYPTO_ALIAS(X509_NAME_hash_old);
#endif

View file

@ -1,4 +1,4 @@
/* $OpenBSD: x509_trs.c,v 1.49 2024/03/25 00:46:57 tb Exp $ */
/* $OpenBSD: x509_trs.c,v 1.54 2024/03/25 04:03:26 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 1999.
*/
@ -68,18 +68,12 @@
#include "x509_internal.h"
#include "x509_local.h"
typedef struct x509_trust_st {
int trust;
int (*check_trust)(struct x509_trust_st *, X509 *);
int nid;
} X509_TRUST;
static int
obj_trust(int id, X509 *x)
obj_trust(int id, const X509 *x)
{
const X509_CERT_AUX *aux;
ASN1_OBJECT *obj;
int i, nid;
X509_CERT_AUX *aux;
if ((aux = x->aux) == NULL)
return X509_TRUST_UNTRUSTED;
@ -102,90 +96,39 @@ obj_trust(int id, X509 *x)
}
static int
trust_compat(X509_TRUST *trust, X509 *x)
trust_compat(int nid, const X509 *x)
{
/* Extensions already cached in X509_check_trust(). */
if (x->ex_flags & EXFLAG_SS)
if ((x->ex_flags & EXFLAG_SS) != 0)
return X509_TRUST_TRUSTED;
else
return X509_TRUST_UNTRUSTED;
}
static int
trust_1oidany(X509_TRUST *trust, X509 *x)
{
if (x->aux && (x->aux->trust || x->aux->reject))
return obj_trust(trust->nid, x);
/* we don't have any trust settings: for compatibility
* we return trusted if it is self signed
*/
return trust_compat(trust, x);
}
static int
trust_1oid(X509_TRUST *trust, X509 *x)
{
if (x->aux)
return obj_trust(trust->nid, x);
return X509_TRUST_UNTRUSTED;
}
/* WARNING: the following table should be kept in order of trust
* and without any gaps so we can just subtract the minimum trust
* value to get an index into the table
*/
static int
trust_1oidany(int nid, const X509 *x)
{
/* Inspect the certificate's trust settings if there are any. */
if (x->aux != NULL && (x->aux->trust != NULL || x->aux->reject != NULL))
return obj_trust(nid, x);
static const X509_TRUST trstandard[] = {
{
.trust = X509_TRUST_COMPAT,
.check_trust = trust_compat,
},
{
.trust = X509_TRUST_SSL_CLIENT,
.check_trust = trust_1oidany,
.nid = NID_client_auth,
},
{
.trust = X509_TRUST_SSL_SERVER,
.check_trust = trust_1oidany,
.nid = NID_server_auth,
},
{
.trust = X509_TRUST_EMAIL,
.check_trust = trust_1oidany,
.nid = NID_email_protect,
},
{
.trust = X509_TRUST_OBJECT_SIGN,
.check_trust = trust_1oidany,
.nid = NID_code_sign,
},
{
.trust = X509_TRUST_OCSP_SIGN,
.check_trust = trust_1oid,
.nid = NID_OCSP_sign,
},
{
.trust = X509_TRUST_OCSP_REQUEST,
.check_trust = trust_1oid,
.nid = NID_ad_OCSP,
},
{
.trust = X509_TRUST_TSA,
.check_trust = trust_1oidany,
.nid = NID_time_stamp,
},
};
/* For compatibility we return trusted if the cert is self signed. */
return trust_compat(NID_undef, x);
}
#define X509_TRUST_COUNT (sizeof(trstandard) / sizeof(trstandard[0]))
static int
trust_1oid(int nid, const X509 *x)
{
if (x->aux != NULL)
return obj_trust(nid, x);
CTASSERT(X509_TRUST_MIN == 1 && X509_TRUST_MAX == X509_TRUST_COUNT);
return X509_TRUST_UNTRUSTED;
}
int
X509_check_trust(X509 *x, int trust_id, int flags)
{
const X509_TRUST *trust;
int idx;
int rv;
if (trust_id == -1)
return 1;
@ -194,29 +137,39 @@ X509_check_trust(X509 *x, int trust_id, int flags)
if (!x509v3_cache_extensions(x))
return X509_TRUST_UNTRUSTED;
/*
* XXX beck/jsing This enables self signed certs to be trusted for
* an unspecified id/trust flag value (this is NOT the
* X509_TRUST_DEFAULT), which was the longstanding
* openssl behaviour. boringssl does not have this behaviour.
*
* This should be revisited, but changing the default "not default"
* may break things.
*/
if (trust_id == 0) {
int rv;
switch (trust_id) {
case 0:
/*
* XXX beck/jsing This enables self signed certs to be trusted
* for an unspecified id/trust flag value (this is NOT the
* X509_TRUST_DEFAULT), which was the longstanding openssl
* behaviour. boringssl does not have this behaviour.
*
* This should be revisited, but changing the default
* "not default" may break things.
*/
rv = obj_trust(NID_anyExtendedKeyUsage, x);
if (rv != X509_TRUST_UNTRUSTED)
return rv;
return trust_compat(NULL, x);
}
if (trust_id < X509_TRUST_MIN || trust_id > X509_TRUST_MAX)
return trust_compat(NID_undef, x);
case X509_TRUST_COMPAT:
return trust_compat(NID_undef, x);
case X509_TRUST_SSL_CLIENT:
return trust_1oidany(NID_client_auth, x);
case X509_TRUST_SSL_SERVER:
return trust_1oidany(NID_server_auth, x);
case X509_TRUST_EMAIL:
return trust_1oidany(NID_email_protect, x);
case X509_TRUST_OBJECT_SIGN:
return trust_1oidany(NID_code_sign, x);
case X509_TRUST_OCSP_SIGN:
return trust_1oid(NID_OCSP_sign, x);
case X509_TRUST_OCSP_REQUEST:
return trust_1oid(NID_ad_OCSP, x);
case X509_TRUST_TSA:
return trust_1oidany(NID_time_stamp, x);
default:
return obj_trust(trust_id, x);
idx = trust_id - X509_TRUST_MIN;
trust = &trstandard[idx];
return trust->check_trust((X509_TRUST *)trust, x);
}
}
LCRYPTO_ALIAS(X509_check_trust);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: x509rset.c,v 1.12 2023/02/16 08:38:17 tb Exp $ */
/* $OpenBSD: x509rset.c,v 1.14 2024/03/25 12:10:57 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*