summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-11-01 20:37:42 +0000
committertb <>2023-11-01 20:37:42 +0000
commit9502a579475daabba44f561af5927b9423bfd082 (patch)
tree096fff81e30ca03dd34347beb2f73d664206a18b
parent718563113a50e94a6425cdd51e05876a3d29a3ba (diff)
downloadopenbsd-9502a579475daabba44f561af5927b9423bfd082.tar.gz
openbsd-9502a579475daabba44f561af5927b9423bfd082.tar.bz2
openbsd-9502a579475daabba44f561af5927b9423bfd082.zip
Add X509_ALGOR_set0_by_nid()
X509_ALGOR_set0() is annoyingly unergonomic since it takes an ASN1_OBJECT rather than a nid. This means that almost all callers call OBJ_obj2nid() and they often do this inline without error checking so that the resulting X509_ALGOR object is corrupted and may lead to incorrect encodings. Provide an internal alternative X509_ALGOR_set0_by_nid() that takes a nid instead of an ASN1_OBJECT and performs proper error checking. This will be used to convert callers of X509_ALGOR_set0() in the library. ok jsing
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c31
-rw-r--r--src/lib/libcrypto/x509/x509_local.h4
2 files changed, 33 insertions, 2 deletions
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
index 76b78028ad..5ad1263b27 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.36 2023/11/01 20:26:24 tb Exp $ */ 1/* $OpenBSD: x_algor.c,v 1.37 2023/11/01 20:37:42 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 */
@@ -159,6 +159,19 @@ X509_ALGOR_set0_obj(X509_ALGOR *alg, ASN1_OBJECT *aobj)
159} 159}
160 160
161static int 161static int
162X509_ALGOR_set_obj_by_nid(X509_ALGOR *alg, int nid)
163{
164 ASN1_OBJECT *aobj;
165
166 if ((aobj = OBJ_nid2obj(nid)) == NULL)
167 return 0;
168 if (!X509_ALGOR_set0_obj(alg, aobj))
169 return 0;
170
171 return 1;
172}
173
174static int
162X509_ALGOR_set0_parameter(X509_ALGOR *alg, int parameter_type, 175X509_ALGOR_set0_parameter(X509_ALGOR *alg, int parameter_type,
163 void *parameter_value) 176 void *parameter_value)
164{ 177{
@@ -181,6 +194,22 @@ X509_ALGOR_set0_parameter(X509_ALGOR *alg, int parameter_type,
181} 194}
182 195
183int 196int
197X509_ALGOR_set0_by_nid(X509_ALGOR *alg, int nid, int parameter_type,
198 void *parameter_value)
199{
200 if (alg == NULL)
201 return 0;
202
203 if (!X509_ALGOR_set_obj_by_nid(alg, nid))
204 return 0;
205
206 if (!X509_ALGOR_set0_parameter(alg, parameter_type, parameter_value))
207 return 0;
208
209 return 1;
210}
211
212int
184X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int parameter_type, 213X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int parameter_type,
185 void *parameter_value) 214 void *parameter_value)
186{ 215{
diff --git a/src/lib/libcrypto/x509/x509_local.h b/src/lib/libcrypto/x509/x509_local.h
index 44fe6ad805..63082d1b19 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.10 2023/10/11 13:05:18 tb Exp $ */ 1/* $OpenBSD: x509_local.h,v 1.11 2023/11/01 20:37:42 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 */
@@ -380,6 +380,8 @@ int x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int quiet);
380int name_cmp(const char *name, const char *cmp); 380int name_cmp(const char *name, const char *cmp);
381 381
382int X509_ALGOR_set_evp_md(X509_ALGOR *alg, const EVP_MD *md); 382int X509_ALGOR_set_evp_md(X509_ALGOR *alg, const EVP_MD *md);
383int X509_ALGOR_set0_by_nid(X509_ALGOR *alg, int nid, int parameter_type,
384 void *parameter_value);
383 385
384int X509_policy_check(const STACK_OF(X509) *certs, 386int X509_policy_check(const STACK_OF(X509) *certs,
385 const STACK_OF(ASN1_OBJECT) *user_policies, unsigned long flags, 387 const STACK_OF(ASN1_OBJECT) *user_policies, unsigned long flags,