diff options
author | tb <> | 2023-10-11 13:05:18 +0000 |
---|---|---|
committer | tb <> | 2023-10-11 13:05:18 +0000 |
commit | efb854ab4bf78936b0cf08b3a4b4c549b541086e (patch) | |
tree | 091c51644d03df4dc1339b318989121b1c000dbe /src/lib | |
parent | 347f3b343ad2e57cfeb77195b304d2ac6fe0abd6 (diff) | |
download | openbsd-efb854ab4bf78936b0cf08b3a4b4c549b541086e.tar.gz openbsd-efb854ab4bf78936b0cf08b3a4b4c549b541086e.tar.bz2 openbsd-efb854ab4bf78936b0cf08b3a4b4c549b541086e.zip |
Add internal version of X509_ALGOR_set_md()
X509_ALGOR_set_md() is a void function that cannot easily be error checked.
The caller has to jump through hoops to make sure this function doesn't
fail. Prepare replacing this internally with X509_ALGOR_set_evp_md(), which
allows error checking. There is one slight change of behavior: if the EVP_MD
object passed in does not have an OID known to the library, then this new
API fails.
It is unclear what the library should do with such an object and people
who use EVP_MD_meth_new() need to know what they are doing anyway and they
are better off teaching the lib about the OID if they're going to be
messing with certs.
Oh, and the prototype is in x509_local.h because the rest of this API is
in x509.h despite being implemented in asn1/.
ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/asn1/x_algor.c | 20 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509_local.h | 4 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c index a638337939..092ad80d2d 100644 --- a/src/lib/libcrypto/asn1/x_algor.c +++ b/src/lib/libcrypto/asn1/x_algor.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x_algor.c,v 1.26 2023/10/11 12:51:07 tb Exp $ */ | 1 | /* $OpenBSD: x_algor.c,v 1.27 2023/10/11 13:05:18 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -192,17 +192,25 @@ X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype, const void **ppval, | |||
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | /* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */ | 195 | int |
196 | 196 | X509_ALGOR_set_evp_md(X509_ALGOR *alg, const EVP_MD *md) | |
197 | void | ||
198 | X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) | ||
199 | { | 197 | { |
198 | ASN1_OBJECT *aobj; | ||
200 | int param_type = V_ASN1_NULL; | 199 | int param_type = V_ASN1_NULL; |
201 | 200 | ||
202 | if ((EVP_MD_flags(md) & EVP_MD_FLAG_DIGALGID_ABSENT) != 0) | 201 | if ((EVP_MD_flags(md) & EVP_MD_FLAG_DIGALGID_ABSENT) != 0) |
203 | param_type = V_ASN1_UNDEF; | 202 | param_type = V_ASN1_UNDEF; |
204 | 203 | ||
205 | X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL); | 204 | if ((aobj = OBJ_nid2obj(EVP_MD_type(md))) == NULL) |
205 | return 0; | ||
206 | |||
207 | return X509_ALGOR_set0(alg, aobj, param_type, NULL); | ||
208 | } | ||
209 | |||
210 | void | ||
211 | X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) | ||
212 | { | ||
213 | (void)X509_ALGOR_set_evp_md(alg, md); | ||
206 | } | 214 | } |
207 | 215 | ||
208 | int | 216 | int |
diff --git a/src/lib/libcrypto/x509/x509_local.h b/src/lib/libcrypto/x509/x509_local.h index f00a55bac8..44fe6ad805 100644 --- a/src/lib/libcrypto/x509/x509_local.h +++ b/src/lib/libcrypto/x509/x509_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_local.h,v 1.9 2023/05/28 05:25:24 tb Exp $ */ | 1 | /* $OpenBSD: x509_local.h,v 1.10 2023/10/11 13:05:18 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2013. | 3 | * project 2013. |
4 | */ | 4 | */ |
@@ -379,6 +379,8 @@ int x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int quiet); | |||
379 | 379 | ||
380 | int name_cmp(const char *name, const char *cmp); | 380 | int name_cmp(const char *name, const char *cmp); |
381 | 381 | ||
382 | int X509_ALGOR_set_evp_md(X509_ALGOR *alg, const EVP_MD *md); | ||
383 | |||
382 | int X509_policy_check(const STACK_OF(X509) *certs, | 384 | int X509_policy_check(const STACK_OF(X509) *certs, |
383 | const STACK_OF(ASN1_OBJECT) *user_policies, unsigned long flags, | 385 | const STACK_OF(ASN1_OBJECT) *user_policies, unsigned long flags, |
384 | X509 **out_current_cert); | 386 | X509 **out_current_cert); |