summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2021-11-01 20:53:08 +0000
committertb <>2021-11-01 20:53:08 +0000
commitb1d784eb6c4f1df06e96cfc40e2434cf76165cbe (patch)
treecbf2de4e6ef2a9e9d9281e6e60c30149cd648fd1 /src/lib
parent95589e2e9b8cb0aa7ceb0bdf1ad9af358f6564db (diff)
downloadopenbsd-b1d784eb6c4f1df06e96cfc40e2434cf76165cbe.tar.gz
openbsd-b1d784eb6c4f1df06e96cfc40e2434cf76165cbe.tar.bz2
openbsd-b1d784eb6c4f1df06e96cfc40e2434cf76165cbe.zip
Move the now internal X.509-related structs into x509_lcl.h.
Garbage collect the now unused LIBRESSL_CRYPTO_INTERNAL and LIBRESSL_OPAQUE_X509. Include "x509_lcl.h" where needed and fix a couple of unnecessary reacharounds. ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/Makefile6
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c6
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c4
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c4
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c4
-rw-r--r--src/lib/libcrypto/asn1/t_req.c4
-rw-r--r--src/lib/libcrypto/asn1/t_spki.c4
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c3
-rw-r--r--src/lib/libcrypto/asn1/t_x509a.c7
-rw-r--r--src/lib/libcrypto/asn1/x_attrib.c4
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c3
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c4
-rw-r--r--src/lib/libcrypto/asn1/x_name.c3
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c3
-rw-r--r--src/lib/libcrypto/asn1/x_req.c4
-rw-r--r--src/lib/libcrypto/asn1/x_sig.c4
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c4
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c4
-rw-r--r--src/lib/libcrypto/cms/cms_lib.c5
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_cl.c4
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ext.c4
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_srv.c4
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_vfy.c4
-rw-r--r--src/lib/libcrypto/opensslfeatures.h2
-rw-r--r--src/lib/libcrypto/ossl_typ.h7
-rw-r--r--src/lib/libcrypto/pkcs12/p12_attr.c4
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mutl.c4
-rw-r--r--src/lib/libcrypto/pkcs12/p12_npas.c4
-rw-r--r--src/lib/libcrypto/pkcs12/p12_p8d.c4
-rw-r--r--src/lib/libcrypto/pkcs12/p12_p8e.c4
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c4
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c3
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_smime.c4
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c3
-rw-r--r--src/lib/libcrypto/ts/ts_lib.c4
-rw-r--r--src/lib/libcrypto/ts/ts_rsp_sign.c4
-rw-r--r--src/lib/libcrypto/ts/ts_rsp_verify.c4
-rw-r--r--src/lib/libcrypto/x509/by_dir.c5
-rw-r--r--src/lib/libcrypto/x509/by_file.c4
-rw-r--r--src/lib/libcrypto/x509/by_mem.c4
-rw-r--r--src/lib/libcrypto/x509/pcy_cache.c3
-rw-r--r--src/lib/libcrypto/x509/pcy_map.c3
-rw-r--r--src/lib/libcrypto/x509/pcy_tree.c3
-rw-r--r--src/lib/libcrypto/x509/x509.h216
-rw-r--r--src/lib/libcrypto/x509/x509_addr.c4
-rw-r--r--src/lib/libcrypto/x509/x509_asid.c4
-rw-r--r--src/lib/libcrypto/x509/x509_att.c4
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c4
-rw-r--r--src/lib/libcrypto/x509/x509_conf.c4
-rw-r--r--src/lib/libcrypto/x509/x509_crld.c4
-rw-r--r--src/lib/libcrypto/x509/x509_ext.c4
-rw-r--r--src/lib/libcrypto/x509/x509_internal.h4
-rw-r--r--src/lib/libcrypto/x509/x509_lcl.h317
-rw-r--r--src/lib/libcrypto/x509/x509_lib.c3
-rw-r--r--src/lib/libcrypto/x509/x509_ncons.c4
-rw-r--r--src/lib/libcrypto/x509/x509_obj.c4
-rw-r--r--src/lib/libcrypto/x509/x509_prn.c4
-rw-r--r--src/lib/libcrypto/x509/x509_purp.c4
-rw-r--r--src/lib/libcrypto/x509/x509_r2x.c4
-rw-r--r--src/lib/libcrypto/x509/x509_req.c4
-rw-r--r--src/lib/libcrypto/x509/x509_set.c4
-rw-r--r--src/lib/libcrypto/x509/x509_skey.c4
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c4
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c4
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c4
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.h162
-rw-r--r--src/lib/libcrypto/x509/x509_vpm.c3
-rw-r--r--src/lib/libcrypto/x509/x509cset.c6
-rw-r--r--src/lib/libcrypto/x509/x509name.c4
-rw-r--r--src/lib/libcrypto/x509/x509rset.c4
-rw-r--r--src/lib/libcrypto/x509/x509type.c4
-rw-r--r--src/lib/libcrypto/x509/x_all.c4
72 files changed, 521 insertions, 451 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile
index f626c16e91..3f4014409d 100644
--- a/src/lib/libcrypto/Makefile
+++ b/src/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.48 2021/10/31 16:51:16 tb Exp $ 1# $OpenBSD: Makefile,v 1.49 2021/11/01 20:53:08 tb Exp $
2 2
3LIB= crypto 3LIB= crypto
4LIBREBUILD=y 4LIBREBUILD=y
@@ -18,7 +18,7 @@ CFLAGS+= -Wall -Wundef
18.if ${COMPILER_VERSION:L} == "clang" 18.if ${COMPILER_VERSION:L} == "clang"
19CFLAGS+= -Werror 19CFLAGS+= -Werror
20.endif 20.endif
21CFLAGS+= -DLIBRESSL_INTERNAL -DLIBRESSL_CRYPTO_INTERNAL 21CFLAGS+= -DLIBRESSL_INTERNAL
22 22
23.if !defined(NOPIC) 23.if !defined(NOPIC)
24CFLAGS+= -DDSO_DLFCN -DHAVE_DLFCN_H -DHAVE_FUNOPEN 24CFLAGS+= -DDSO_DLFCN -DHAVE_DLFCN_H -DHAVE_FUNOPEN
@@ -29,7 +29,7 @@ CFLAGS+= -DOPENSSL_NO_HW_PADLOCK # XXX enable this?
29 29
30CFLAGS+= -I${LCRYPTO_SRC} 30CFLAGS+= -I${LCRYPTO_SRC}
31CFLAGS+= -I${LCRYPTO_SRC}/asn1 -I${LCRYPTO_SRC}/bn -I${LCRYPTO_SRC}/evp 31CFLAGS+= -I${LCRYPTO_SRC}/asn1 -I${LCRYPTO_SRC}/bn -I${LCRYPTO_SRC}/evp
32CFLAGS+= -I${LCRYPTO_SRC}/modes 32CFLAGS+= -I${LCRYPTO_SRC}/modes -I${LCRYPTO_SRC}/x509
33 33
34# XXX FIXME ecdsa and ec should be merged 34# XXX FIXME ecdsa and ec should be merged
35CFLAGS+= -I${LCRYPTO_SRC}/ecdsa 35CFLAGS+= -I${LCRYPTO_SRC}/ecdsa
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
index 4e3deccfda..3b66ea8d36 100644
--- a/src/lib/libcrypto/asn1/a_strex.c
+++ b/src/lib/libcrypto/asn1/a_strex.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_strex.c,v 1.28 2018/05/19 10:46:28 tb Exp $ */ 1/* $OpenBSD: a_strex.c,v 1.29 2021/11/01 20:53:08 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 */
@@ -513,7 +513,7 @@ do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n, int indent,
513 else 513 else
514 ent = X509_NAME_get_entry(n, i); 514 ent = X509_NAME_get_entry(n, i);
515 if (prev != -1) { 515 if (prev != -1) {
516 if (prev == ent->set) { 516 if (prev == X509_NAME_ENTRY_set(ent)) {
517 if (!io_ch(arg, sep_mv, sep_mv_len)) 517 if (!io_ch(arg, sep_mv, sep_mv_len))
518 return -1; 518 return -1;
519 outlen += sep_mv_len; 519 outlen += sep_mv_len;
@@ -526,7 +526,7 @@ do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n, int indent,
526 outlen += indent; 526 outlen += indent;
527 } 527 }
528 } 528 }
529 prev = ent->set; 529 prev = X509_NAME_ENTRY_set(ent);
530 fn = X509_NAME_ENTRY_get_object(ent); 530 fn = X509_NAME_ENTRY_get_object(ent);
531 val = X509_NAME_ENTRY_get_data(ent); 531 val = X509_NAME_ENTRY_get_data(ent);
532 fn_nid = OBJ_obj2nid(fn); 532 fn_nid = OBJ_obj2nid(fn);
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
index 6c7031677d..89adcd5b11 100644
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ b/src/lib/libcrypto/asn1/n_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: n_pkey.c,v 1.32 2018/08/05 13:35:45 bcook Exp $ */ 1/* $OpenBSD: n_pkey.c,v 1.33 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -69,6 +69,8 @@
69#include <openssl/rsa.h> 69#include <openssl/rsa.h>
70#include <openssl/x509.h> 70#include <openssl/x509.h>
71 71
72#include "x509_lcl.h"
73
72#ifndef OPENSSL_NO_RC4 74#ifndef OPENSSL_NO_RC4
73 75
74typedef struct netscape_pkey_st { 76typedef struct netscape_pkey_st {
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
index d2f8e6b055..18659a6f40 100644
--- a/src/lib/libcrypto/asn1/p8_pkey.c
+++ b/src/lib/libcrypto/asn1/p8_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p8_pkey.c,v 1.19 2018/08/24 20:17:33 tb Exp $ */ 1/* $OpenBSD: p8_pkey.c,v 1.20 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -62,6 +62,8 @@
62#include <openssl/asn1t.h> 62#include <openssl/asn1t.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65#include "x509_lcl.h"
66
65/* Minor tweak to operation: zero private key data */ 67/* Minor tweak to operation: zero private key data */
66static int 68static int
67pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) 69pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
index 057b8fe311..b7f94a8644 100644
--- a/src/lib/libcrypto/asn1/t_crl.c
+++ b/src/lib/libcrypto/asn1/t_crl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_crl.c,v 1.18 2019/05/12 15:56:31 tb Exp $ */ 1/* $OpenBSD: t_crl.c,v 1.19 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -66,6 +66,8 @@
66#include <openssl/x509.h> 66#include <openssl/x509.h>
67#include <openssl/x509v3.h> 67#include <openssl/x509v3.h>
68 68
69#include "x509_lcl.h"
70
69int 71int
70X509_CRL_print_fp(FILE *fp, X509_CRL *x) 72X509_CRL_print_fp(FILE *fp, X509_CRL *x)
71{ 73{
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
index a9b14fed73..320eaff9c0 100644
--- a/src/lib/libcrypto/asn1/t_req.c
+++ b/src/lib/libcrypto/asn1/t_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_req.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: t_req.c,v 1.20 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -74,6 +74,8 @@
74#include <openssl/rsa.h> 74#include <openssl/rsa.h>
75#endif 75#endif
76 76
77#include "x509_lcl.h"
78
77int 79int
78X509_REQ_print_fp(FILE *fp, X509_REQ *x) 80X509_REQ_print_fp(FILE *fp, X509_REQ *x)
79{ 81{
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c
index 7f1ed129cf..56c0956ceb 100644
--- a/src/lib/libcrypto/asn1/t_spki.c
+++ b/src/lib/libcrypto/asn1/t_spki.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_spki.c,v 1.12 2021/08/24 15:23:03 tb Exp $ */ 1/* $OpenBSD: t_spki.c,v 1.13 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -71,6 +71,8 @@
71#include <openssl/rsa.h> 71#include <openssl/rsa.h>
72#endif 72#endif
73 73
74#include "x509_lcl.h"
75
74/* Print out an SPKI */ 76/* Print out an SPKI */
75 77
76int 78int
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
index 42b00a729a..d1655a1785 100644
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_x509.c,v 1.34 2021/07/26 16:54:20 tb Exp $ */ 1/* $OpenBSD: t_x509.c,v 1.35 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -78,6 +78,7 @@
78#endif 78#endif
79 79
80#include "asn1_locl.h" 80#include "asn1_locl.h"
81#include "x509_lcl.h"
81 82
82int 83int
83X509_print_fp(FILE *fp, X509 *x) 84X509_print_fp(FILE *fp, X509 *x)
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c
index b0346fa681..6745318b9c 100644
--- a/src/lib/libcrypto/asn1/t_x509a.c
+++ b/src/lib/libcrypto/asn1/t_x509a.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_x509a.c,v 1.9 2021/07/10 17:45:16 schwarze Exp $ */ 1/* $OpenBSD: t_x509a.c,v 1.10 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -62,8 +62,9 @@
62#include <openssl/evp.h> 62#include <openssl/evp.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65/* X509_CERT_AUX and string set routines 65#include "x509_lcl.h"
66 */ 66
67/* X509_CERT_AUX and string set routines */
67 68
68int 69int
69X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent) 70X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c
index 04816eab77..a40edc1f1d 100644
--- a/src/lib/libcrypto/asn1/x_attrib.c
+++ b/src/lib/libcrypto/asn1/x_attrib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_attrib.c,v 1.14 2020/06/04 21:21:03 schwarze Exp $ */ 1/* $OpenBSD: x_attrib.c,v 1.15 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -62,6 +62,8 @@
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65#include "x509_lcl.h"
66
65/* X509_ATTRIBUTE: this has the following form: 67/* X509_ATTRIBUTE: this has the following form:
66 * 68 *
67 * typedef struct x509_attributes_st 69 * typedef struct x509_attributes_st
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
index bc1783dbfb..bfc01a2284 100644
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_crl.c,v 1.34 2019/03/13 20:34:00 tb Exp $ */ 1/* $OpenBSD: x_crl.c,v 1.35 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -66,6 +66,7 @@
66#include <openssl/x509v3.h> 66#include <openssl/x509v3.h>
67 67
68#include "asn1_locl.h" 68#include "asn1_locl.h"
69#include "x509_lcl.h"
69 70
70static int X509_REVOKED_cmp(const X509_REVOKED * const *a, 71static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
71 const X509_REVOKED * const *b); 72 const X509_REVOKED * const *b);
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c
index bb3dffc821..aba8973632 100644
--- a/src/lib/libcrypto/asn1/x_exten.c
+++ b/src/lib/libcrypto/asn1/x_exten.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_exten.c,v 1.16 2015/07/24 15:09:52 jsing Exp $ */ 1/* $OpenBSD: x_exten.c,v 1.17 2021/11/01 20:53:08 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 */
@@ -61,6 +61,8 @@
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/asn1t.h> 62#include <openssl/asn1t.h>
63 63
64#include "x509_lcl.h"
65
64static const ASN1_TEMPLATE X509_EXTENSION_seq_tt[] = { 66static const ASN1_TEMPLATE X509_EXTENSION_seq_tt[] = {
65 { 67 {
66 .offset = offsetof(X509_EXTENSION, object), 68 .offset = offsetof(X509_EXTENSION, object),
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
index 0961ee33eb..4563a51348 100644
--- a/src/lib/libcrypto/asn1/x_name.c
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_name.c,v 1.35 2021/07/04 11:38:37 schwarze Exp $ */ 1/* $OpenBSD: x_name.c,v 1.36 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -65,6 +65,7 @@
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66 66
67#include "asn1_locl.h" 67#include "asn1_locl.h"
68#include "x509_lcl.h"
68 69
69typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY; 70typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY;
70DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY) 71DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY)
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
index ea67419cb2..cb16d03301 100644
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_pubkey.c,v 1.27 2018/03/17 14:55:39 jsing Exp $ */ 1/* $OpenBSD: x_pubkey.c,v 1.28 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -72,6 +72,7 @@
72#endif 72#endif
73 73
74#include "asn1_locl.h" 74#include "asn1_locl.h"
75#include "x509_lcl.h"
75 76
76/* Minor tweak to operation: free up EVP_PKEY */ 77/* Minor tweak to operation: free up EVP_PKEY */
77static int 78static int
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
index eb5210aef6..38e3790bf4 100644
--- a/src/lib/libcrypto/asn1/x_req.c
+++ b/src/lib/libcrypto/asn1/x_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_req.c,v 1.17 2018/02/22 16:50:30 jsing Exp $ */ 1/* $OpenBSD: x_req.c,v 1.18 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -61,6 +61,8 @@
61#include <openssl/asn1t.h> 61#include <openssl/asn1t.h>
62#include <openssl/x509.h> 62#include <openssl/x509.h>
63 63
64#include "x509_lcl.h"
65
64/* X509_REQ_INFO is handled in an unusual way to get round 66/* X509_REQ_INFO is handled in an unusual way to get round
65 * invalid encodings. Some broken certificate requests don't 67 * invalid encodings. Some broken certificate requests don't
66 * encode the attributes field if it is empty. This is in 68 * encode the attributes field if it is empty. This is in
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c
index dc3af45f6d..6a842da5f0 100644
--- a/src/lib/libcrypto/asn1/x_sig.c
+++ b/src/lib/libcrypto/asn1/x_sig.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_sig.c,v 1.12 2021/10/23 11:41:50 tb Exp $ */ 1/* $OpenBSD: x_sig.c,v 1.13 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -61,6 +61,8 @@
61#include <openssl/asn1t.h> 61#include <openssl/asn1t.h>
62#include <openssl/x509.h> 62#include <openssl/x509.h>
63 63
64#include "x509_lcl.h"
65
64static const ASN1_TEMPLATE X509_SIG_seq_tt[] = { 66static const ASN1_TEMPLATE X509_SIG_seq_tt[] = {
65 { 67 {
66 .offset = offsetof(X509_SIG, algor), 68 .offset = offsetof(X509_SIG, algor),
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
index ebe09a6099..713ffbbb11 100644
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ b/src/lib/libcrypto/asn1/x_x509.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_x509.c,v 1.28 2021/10/23 11:56:10 tb Exp $ */ 1/* $OpenBSD: x_x509.c,v 1.29 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -65,6 +65,8 @@
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66#include <openssl/x509v3.h> 66#include <openssl/x509v3.h>
67 67
68#include "x509_lcl.h"
69
68static const ASN1_AUX X509_CINF_aux = { 70static const ASN1_AUX X509_CINF_aux = {
69 .flags = ASN1_AFLG_ENCODING, 71 .flags = ASN1_AFLG_ENCODING,
70 .enc_offset = offsetof(X509_CINF, enc), 72 .enc_offset = offsetof(X509_CINF, enc),
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
index d5364cb07b..572178157a 100644
--- a/src/lib/libcrypto/asn1/x_x509a.c
+++ b/src/lib/libcrypto/asn1/x_x509a.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_x509a.c,v 1.16 2021/10/31 16:28:50 tb Exp $ */ 1/* $OpenBSD: x_x509a.c,v 1.17 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -62,6 +62,8 @@
62#include <openssl/evp.h> 62#include <openssl/evp.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65#include "x509_lcl.h"
66
65/* X509_CERT_AUX routines. These are used to encode additional 67/* X509_CERT_AUX routines. These are used to encode additional
66 * user modifiable data about a certificate. This data is 68 * user modifiable data about a certificate. This data is
67 * appended to the X509 encoding when the *_X509_AUX routines 69 * appended to the X509 encoding when the *_X509_AUX routines
diff --git a/src/lib/libcrypto/cms/cms_lib.c b/src/lib/libcrypto/cms/cms_lib.c
index b6580dd6f5..21adef7aec 100644
--- a/src/lib/libcrypto/cms/cms_lib.c
+++ b/src/lib/libcrypto/cms/cms_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_lib.c,v 1.14 2019/08/12 18:13:13 jsing Exp $ */ 1/* $OpenBSD: cms_lib.c,v 1.15 2021/11/01 20:53:08 tb Exp $ */
2/* 2/*
3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
4 * project. 4 * project.
@@ -59,8 +59,9 @@
59#include <openssl/bio.h> 59#include <openssl/bio.h>
60#include <openssl/asn1.h> 60#include <openssl/asn1.h>
61#include <openssl/cms.h> 61#include <openssl/cms.h>
62#include "cms_lcl.h"
63 62
63#include "cms_lcl.h"
64#include "x509_lcl.h"
64 65
65CMS_ContentInfo * 66CMS_ContentInfo *
66d2i_CMS_ContentInfo(CMS_ContentInfo **a, const unsigned char **in, long len) 67d2i_CMS_ContentInfo(CMS_ContentInfo **a, const unsigned char **in, long len)
diff --git a/src/lib/libcrypto/ocsp/ocsp_cl.c b/src/lib/libcrypto/ocsp/ocsp_cl.c
index 677a1b35dd..da4b5ad04c 100644
--- a/src/lib/libcrypto/ocsp/ocsp_cl.c
+++ b/src/lib/libcrypto/ocsp/ocsp_cl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_cl.c,v 1.18 2021/10/24 13:50:14 tb Exp $ */ 1/* $OpenBSD: ocsp_cl.c,v 1.19 2021/11/01 20:53:08 tb Exp $ */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL 2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */ 3 * project. */
4 4
@@ -136,7 +136,7 @@ OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert)
136 136
137 if (!sk_X509_push(sig->certs, cert)) 137 if (!sk_X509_push(sig->certs, cert))
138 return 0; 138 return 0;
139 CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509); 139 X509_up_ref(cert);
140 return 1; 140 return 1;
141} 141}
142 142
diff --git a/src/lib/libcrypto/ocsp/ocsp_ext.c b/src/lib/libcrypto/ocsp/ocsp_ext.c
index eb51cfbff5..c48843492d 100644
--- a/src/lib/libcrypto/ocsp/ocsp_ext.c
+++ b/src/lib/libcrypto/ocsp/ocsp_ext.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_ext.c,v 1.18 2018/05/14 23:47:10 tb Exp $ */ 1/* $OpenBSD: ocsp_ext.c,v 1.19 2021/11/01 20:53:08 tb Exp $ */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL 2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */ 3 * project. */
4 4
@@ -70,6 +70,8 @@
70#include <openssl/x509.h> 70#include <openssl/x509.h>
71#include <openssl/x509v3.h> 71#include <openssl/x509v3.h>
72 72
73#include "x509_lcl.h"
74
73/* Standard wrapper functions for extensions */ 75/* Standard wrapper functions for extensions */
74 76
75/* OCSP request extensions */ 77/* OCSP request extensions */
diff --git a/src/lib/libcrypto/ocsp/ocsp_srv.c b/src/lib/libcrypto/ocsp/ocsp_srv.c
index a9e0aaab2f..5c9ac4d807 100644
--- a/src/lib/libcrypto/ocsp/ocsp_srv.c
+++ b/src/lib/libcrypto/ocsp/ocsp_srv.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_srv.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: ocsp_srv.c,v 1.11 2021/11/01 20:53:08 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 2001. 3 * project 2001.
4 */ 4 */
@@ -213,7 +213,7 @@ OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert)
213 213
214 if (!sk_X509_push(resp->certs, cert)) 214 if (!sk_X509_push(resp->certs, cert))
215 return 0; 215 return 0;
216 CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509); 216 X509_up_ref(cert);
217 return 1; 217 return 1;
218} 218}
219 219
diff --git a/src/lib/libcrypto/ocsp/ocsp_vfy.c b/src/lib/libcrypto/ocsp/ocsp_vfy.c
index e92b5d7326..67d45605ff 100644
--- a/src/lib/libcrypto/ocsp/ocsp_vfy.c
+++ b/src/lib/libcrypto/ocsp/ocsp_vfy.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_vfy.c,v 1.16 2021/10/24 13:50:14 tb Exp $ */ 1/* $OpenBSD: ocsp_vfy.c,v 1.17 2021/11/01 20:53:08 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 */
@@ -60,6 +60,8 @@
60#include <openssl/err.h> 60#include <openssl/err.h>
61#include <string.h> 61#include <string.h>
62 62
63#include "x509_lcl.h"
64
63static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs, 65static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs,
64 STACK_OF(X509) *certs, X509_STORE *st, unsigned long flags); 66 STACK_OF(X509) *certs, X509_STORE *st, unsigned long flags);
65static X509 *ocsp_find_signer_sk(STACK_OF(X509) *certs, OCSP_RESPID *id); 67static X509 *ocsp_find_signer_sk(STACK_OF(X509) *certs, OCSP_RESPID *id);
diff --git a/src/lib/libcrypto/opensslfeatures.h b/src/lib/libcrypto/opensslfeatures.h
index f16e25e782..49a5f15b59 100644
--- a/src/lib/libcrypto/opensslfeatures.h
+++ b/src/lib/libcrypto/opensslfeatures.h
@@ -6,8 +6,6 @@
6#define LIBRESSL_HAS_TLS1_3 6#define LIBRESSL_HAS_TLS1_3
7#define LIBRESSL_HAS_DTLS1_2 7#define LIBRESSL_HAS_DTLS1_2
8 8
9#define LIBRESSL_OPAQUE_X509
10
11#define OPENSSL_THREADS 9#define OPENSSL_THREADS
12 10
13#define OPENSSL_NO_BUF_FREELISTS 11#define OPENSSL_NO_BUF_FREELISTS
diff --git a/src/lib/libcrypto/ossl_typ.h b/src/lib/libcrypto/ossl_typ.h
index 234fdca1ea..99f120644f 100644
--- a/src/lib/libcrypto/ossl_typ.h
+++ b/src/lib/libcrypto/ossl_typ.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ossl_typ.h,v 1.13 2015/09/30 04:10:07 doug Exp $ */ 1/* $OpenBSD: ossl_typ.h,v 1.14 2021/11/01 20:53:08 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -127,6 +127,11 @@ typedef struct X509_pubkey_st X509_PUBKEY;
127typedef struct x509_store_st X509_STORE; 127typedef struct x509_store_st X509_STORE;
128typedef struct x509_store_ctx_st X509_STORE_CTX; 128typedef struct x509_store_ctx_st X509_STORE_CTX;
129 129
130typedef struct x509_object_st X509_OBJECT;
131typedef struct x509_lookup_st X509_LOOKUP;
132typedef struct x509_lookup_method_st X509_LOOKUP_METHOD;
133typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM;
134
130typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO; 135typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO;
131 136
132typedef struct v3_ext_ctx X509V3_CTX; 137typedef struct v3_ext_ctx X509V3_CTX;
diff --git a/src/lib/libcrypto/pkcs12/p12_attr.c b/src/lib/libcrypto/pkcs12/p12_attr.c
index e8e340a2e2..dc38b7c897 100644
--- a/src/lib/libcrypto/pkcs12/p12_attr.c
+++ b/src/lib/libcrypto/pkcs12/p12_attr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_attr.c,v 1.13 2021/07/09 14:07:59 tb Exp $ */ 1/* $OpenBSD: p12_attr.c,v 1.14 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -60,6 +60,8 @@
60 60
61#include <openssl/pkcs12.h> 61#include <openssl/pkcs12.h>
62 62
63#include "x509_lcl.h"
64
63/* Add a local keyid to a safebag */ 65/* Add a local keyid to a safebag */
64 66
65int 67int
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c
index d45ab078fd..14ded8532d 100644
--- a/src/lib/libcrypto/pkcs12/p12_mutl.c
+++ b/src/lib/libcrypto/pkcs12/p12_mutl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_mutl.c,v 1.24 2021/07/09 14:08:00 tb Exp $ */ 1/* $OpenBSD: p12_mutl.c,v 1.25 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -68,6 +68,8 @@
68#include <openssl/hmac.h> 68#include <openssl/hmac.h>
69#include <openssl/pkcs12.h> 69#include <openssl/pkcs12.h>
70 70
71#include "x509_lcl.h"
72
71/* Generate a MAC */ 73/* Generate a MAC */
72int 74int
73PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, 75PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c
index d6b12edab3..62ec368af7 100644
--- a/src/lib/libcrypto/pkcs12/p12_npas.c
+++ b/src/lib/libcrypto/pkcs12/p12_npas.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_npas.c,v 1.13 2018/05/13 14:22:34 tb Exp $ */ 1/* $OpenBSD: p12_npas.c,v 1.14 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -63,6 +63,8 @@
63#include <openssl/err.h> 63#include <openssl/err.h>
64#include <openssl/pkcs12.h> 64#include <openssl/pkcs12.h>
65 65
66#include "x509_lcl.h"
67
66/* PKCS#12 password change routine */ 68/* PKCS#12 password change routine */
67 69
68static int newpass_p12(PKCS12 *p12, const char *oldpass, const char *newpass); 70static int newpass_p12(PKCS12 *p12, const char *oldpass, const char *newpass);
diff --git a/src/lib/libcrypto/pkcs12/p12_p8d.c b/src/lib/libcrypto/pkcs12/p12_p8d.c
index 0286d4acf5..ce1b28bc29 100644
--- a/src/lib/libcrypto/pkcs12/p12_p8d.c
+++ b/src/lib/libcrypto/pkcs12/p12_p8d.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_p8d.c,v 1.7 2018/05/13 14:28:14 tb Exp $ */ 1/* $OpenBSD: p12_p8d.c,v 1.8 2021/11/01 20:53:08 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 2001. 3 * project 2001.
4 */ 4 */
@@ -60,6 +60,8 @@
60 60
61#include <openssl/pkcs12.h> 61#include <openssl/pkcs12.h>
62 62
63#include "x509_lcl.h"
64
63PKCS8_PRIV_KEY_INFO * 65PKCS8_PRIV_KEY_INFO *
64PKCS8_decrypt(const X509_SIG *p8, const char *pass, int passlen) 66PKCS8_decrypt(const X509_SIG *p8, const char *pass, int passlen)
65{ 67{
diff --git a/src/lib/libcrypto/pkcs12/p12_p8e.c b/src/lib/libcrypto/pkcs12/p12_p8e.c
index 5e3fc6486a..7f5f61d69f 100644
--- a/src/lib/libcrypto/pkcs12/p12_p8e.c
+++ b/src/lib/libcrypto/pkcs12/p12_p8e.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_p8e.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: p12_p8e.c,v 1.9 2021/11/01 20:53:08 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 2001. 3 * project 2001.
4 */ 4 */
@@ -61,6 +61,8 @@
61#include <openssl/err.h> 61#include <openssl/err.h>
62#include <openssl/pkcs12.h> 62#include <openssl/pkcs12.h>
63 63
64#include "x509_lcl.h"
65
64X509_SIG * 66X509_SIG *
65PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, const char *pass, 67PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, const char *pass,
66 int passlen, unsigned char *salt, int saltlen, int iter, 68 int passlen, unsigned char *salt, int saltlen, int iter,
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
index 81a72f6815..6d921e5cff 100644
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_doit.c,v 1.44 2019/10/04 18:03:55 tb Exp $ */ 1/* $OpenBSD: pk7_doit.c,v 1.45 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -65,6 +65,8 @@
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66#include <openssl/x509v3.h> 66#include <openssl/x509v3.h>
67 67
68#include "x509_lcl.h"
69
68static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype, 70static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
69 void *value); 71 void *value);
70static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid); 72static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid);
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
index afcc179240..24cb0fe4c6 100644
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ b/src/lib/libcrypto/pkcs7/pk7_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_lib.c,v 1.21 2020/01/21 10:18:52 inoguchi Exp $ */ 1/* $OpenBSD: pk7_lib.c,v 1.22 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -63,6 +63,7 @@
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65#include "asn1_locl.h" 65#include "asn1_locl.h"
66#include "x509_lcl.h"
66 67
67long 68long
68PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg) 69PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg)
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c
index bf9f2dd82a..f11d23e30d 100644
--- a/src/lib/libcrypto/pkcs7/pk7_smime.c
+++ b/src/lib/libcrypto/pkcs7/pk7_smime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_smime.c,v 1.22 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: pk7_smime.c,v 1.23 2021/11/01 20:53:08 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. 3 * project.
4 */ 4 */
@@ -64,6 +64,8 @@
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65#include <openssl/x509v3.h> 65#include <openssl/x509v3.h>
66 66
67#include "x509_lcl.h"
68
67static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si); 69static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
68 70
69PKCS7 * 71PKCS7 *
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
index d205046bd3..9ee61a381c 100644
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_sign.c,v 1.32 2021/05/14 18:03:42 tb Exp $ */ 1/* $OpenBSD: rsa_sign.c,v 1.33 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -66,6 +66,7 @@
66#include <openssl/x509.h> 66#include <openssl/x509.h>
67 67
68#include "rsa_locl.h" 68#include "rsa_locl.h"
69#include "x509_lcl.h"
69 70
70/* Size of an SSL signature: MD5+SHA1 */ 71/* Size of an SSL signature: MD5+SHA1 */
71#define SSL_SIG_LENGTH 36 72#define SSL_SIG_LENGTH 36
diff --git a/src/lib/libcrypto/ts/ts_lib.c b/src/lib/libcrypto/ts/ts_lib.c
index 293564118f..cdfa9db351 100644
--- a/src/lib/libcrypto/ts/ts_lib.c
+++ b/src/lib/libcrypto/ts/ts_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_lib.c,v 1.10 2015/09/10 14:29:22 jsing Exp $ */ 1/* $OpenBSD: ts_lib.c,v 1.11 2021/11/01 20:53:08 tb Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -64,6 +64,8 @@
64#include <openssl/ts.h> 64#include <openssl/ts.h>
65#include <openssl/x509v3.h> 65#include <openssl/x509v3.h>
66 66
67#include "x509_lcl.h"
68
67/* Local function declarations. */ 69/* Local function declarations. */
68 70
69/* Function definitions. */ 71/* Function definitions. */
diff --git a/src/lib/libcrypto/ts/ts_rsp_sign.c b/src/lib/libcrypto/ts/ts_rsp_sign.c
index 6125fdd4be..828407aa4b 100644
--- a/src/lib/libcrypto/ts/ts_rsp_sign.c
+++ b/src/lib/libcrypto/ts/ts_rsp_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_rsp_sign.c,v 1.23 2019/07/03 03:24:04 deraadt Exp $ */ 1/* $OpenBSD: ts_rsp_sign.c,v 1.24 2021/11/01 20:53:08 tb Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -65,6 +65,8 @@
65#include <openssl/pkcs7.h> 65#include <openssl/pkcs7.h>
66#include <openssl/ts.h> 66#include <openssl/ts.h>
67 67
68#include "x509_lcl.h"
69
68/* Private function declarations. */ 70/* Private function declarations. */
69 71
70static ASN1_INTEGER *def_serial_cb(struct TS_resp_ctx *, void *); 72static ASN1_INTEGER *def_serial_cb(struct TS_resp_ctx *, void *);
diff --git a/src/lib/libcrypto/ts/ts_rsp_verify.c b/src/lib/libcrypto/ts/ts_rsp_verify.c
index 46704dfd2b..2e72ff47ae 100644
--- a/src/lib/libcrypto/ts/ts_rsp_verify.c
+++ b/src/lib/libcrypto/ts/ts_rsp_verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_rsp_verify.c,v 1.21 2021/07/02 11:15:08 schwarze Exp $ */ 1/* $OpenBSD: ts_rsp_verify.c,v 1.22 2021/11/01 20:53:08 tb Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -64,6 +64,8 @@
64#include <openssl/pkcs7.h> 64#include <openssl/pkcs7.h>
65#include <openssl/ts.h> 65#include <openssl/ts.h>
66 66
67#include "x509_lcl.h"
68
67/* Private function declarations. */ 69/* Private function declarations. */
68 70
69static int TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted, 71static int TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted,
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c
index 04eada8ad0..0ff60644f5 100644
--- a/src/lib/libcrypto/x509/by_dir.c
+++ b/src/lib/libcrypto/x509/by_dir.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: by_dir.c,v 1.39 2018/08/05 14:17:12 bcook Exp $ */ 1/* $OpenBSD: by_dir.c,v 1.40 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,6 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <sys/stat.h>
59#include <sys/types.h> 60#include <sys/types.h>
60 61
61#include <errno.h> 62#include <errno.h>
@@ -70,7 +71,7 @@
70#include <openssl/lhash.h> 71#include <openssl/lhash.h>
71#include <openssl/x509.h> 72#include <openssl/x509.h>
72 73
73# include <sys/stat.h> 74#include "x509_lcl.h"
74 75
75typedef struct lookup_dir_hashes_st { 76typedef struct lookup_dir_hashes_st {
76 unsigned long hash; 77 unsigned long hash;
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c
index b2c8ef6cfa..f719636412 100644
--- a/src/lib/libcrypto/x509/by_file.c
+++ b/src/lib/libcrypto/x509/by_file.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: by_file.c,v 1.21 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: by_file.c,v 1.22 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -67,6 +67,8 @@
67#include <openssl/lhash.h> 67#include <openssl/lhash.h>
68#include <openssl/x509.h> 68#include <openssl/x509.h>
69 69
70#include "x509_lcl.h"
71
70static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, 72static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
71 long argl, char **ret); 73 long argl, char **ret);
72 74
diff --git a/src/lib/libcrypto/x509/by_mem.c b/src/lib/libcrypto/x509/by_mem.c
index 34d4040d84..272877f843 100644
--- a/src/lib/libcrypto/x509/by_mem.c
+++ b/src/lib/libcrypto/x509/by_mem.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: by_mem.c,v 1.4 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: by_mem.c,v 1.5 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -68,6 +68,8 @@
68#include <openssl/lhash.h> 68#include <openssl/lhash.h>
69#include <openssl/x509.h> 69#include <openssl/x509.h>
70 70
71#include "x509_lcl.h"
72
71static int by_mem_ctrl(X509_LOOKUP *, int, const char *, long, char **); 73static int by_mem_ctrl(X509_LOOKUP *, int, const char *, long, char **);
72 74
73static X509_LOOKUP_METHOD x509_mem_lookup = { 75static X509_LOOKUP_METHOD x509_mem_lookup = {
diff --git a/src/lib/libcrypto/x509/pcy_cache.c b/src/lib/libcrypto/x509/pcy_cache.c
index 896ba7d59e..debca30286 100644
--- a/src/lib/libcrypto/x509/pcy_cache.c
+++ b/src/lib/libcrypto/x509/pcy_cache.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pcy_cache.c,v 1.1 2020/06/04 15:19:31 jsing Exp $ */ 1/* $OpenBSD: pcy_cache.c,v 1.2 2021/11/01 20:53:08 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 2004. 3 * project 2004.
4 */ 4 */
@@ -60,6 +60,7 @@
60#include <openssl/x509v3.h> 60#include <openssl/x509v3.h>
61 61
62#include "pcy_int.h" 62#include "pcy_int.h"
63#include "x509_lcl.h"
63 64
64static int policy_data_cmp(const X509_POLICY_DATA * const *a, 65static int policy_data_cmp(const X509_POLICY_DATA * const *a,
65 const X509_POLICY_DATA * const *b); 66 const X509_POLICY_DATA * const *b);
diff --git a/src/lib/libcrypto/x509/pcy_map.c b/src/lib/libcrypto/x509/pcy_map.c
index 287a430c2c..f2e5d32552 100644
--- a/src/lib/libcrypto/x509/pcy_map.c
+++ b/src/lib/libcrypto/x509/pcy_map.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pcy_map.c,v 1.1 2020/06/04 15:19:31 jsing Exp $ */ 1/* $OpenBSD: pcy_map.c,v 1.2 2021/11/01 20:53:08 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 2004. 3 * project 2004.
4 */ 4 */
@@ -60,6 +60,7 @@
60#include <openssl/x509v3.h> 60#include <openssl/x509v3.h>
61 61
62#include "pcy_int.h" 62#include "pcy_int.h"
63#include "x509_lcl.h"
63 64
64/* Set policy mapping entries in cache. 65/* Set policy mapping entries in cache.
65 * Note: this modifies the passed POLICY_MAPPINGS structure 66 * Note: this modifies the passed POLICY_MAPPINGS structure
diff --git a/src/lib/libcrypto/x509/pcy_tree.c b/src/lib/libcrypto/x509/pcy_tree.c
index d0f7cd1ada..284c08e66a 100644
--- a/src/lib/libcrypto/x509/pcy_tree.c
+++ b/src/lib/libcrypto/x509/pcy_tree.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pcy_tree.c,v 1.1 2020/06/04 15:19:31 jsing Exp $ */ 1/* $OpenBSD: pcy_tree.c,v 1.2 2021/11/01 20:53:08 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 2004. 3 * project 2004.
4 */ 4 */
@@ -60,6 +60,7 @@
60#include <openssl/x509v3.h> 60#include <openssl/x509v3.h>
61 61
62#include "pcy_int.h" 62#include "pcy_int.h"
63#include "x509_lcl.h"
63 64
64/* Enable this to print out the complete policy tree at various point during 65/* Enable this to print out the complete policy tree at various point during
65 * evaluation. 66 * evaluation.
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h
index 9a44bf30aa..4624628bf8 100644
--- a/src/lib/libcrypto/x509/x509.h
+++ b/src/lib/libcrypto/x509/x509.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509.h,v 1.86 2021/11/01 08:14:36 tb Exp $ */ 1/* $OpenBSD: x509.h,v 1.87 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -139,171 +139,33 @@ typedef struct X509_val_st {
139 ASN1_TIME *notAfter; 139 ASN1_TIME *notAfter;
140} X509_VAL; 140} X509_VAL;
141 141
142#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
143struct X509_pubkey_st {
144 X509_ALGOR *algor;
145 ASN1_BIT_STRING *public_key;
146 EVP_PKEY *pkey;
147};
148
149typedef struct X509_sig_st {
150 X509_ALGOR *algor;
151 ASN1_OCTET_STRING *digest;
152} X509_SIG;
153
154typedef struct X509_name_entry_st {
155 ASN1_OBJECT *object;
156 ASN1_STRING *value;
157 int set;
158 int size; /* temp variable */
159} X509_NAME_ENTRY;
160#else
161typedef struct X509_sig_st X509_SIG; 142typedef struct X509_sig_st X509_SIG;
143
162typedef struct X509_name_entry_st X509_NAME_ENTRY; 144typedef struct X509_name_entry_st X509_NAME_ENTRY;
163#endif
164 145
165DECLARE_STACK_OF(X509_NAME_ENTRY) 146DECLARE_STACK_OF(X509_NAME_ENTRY)
166 147
167#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
168/* we always keep X509_NAMEs in 2 forms. */
169struct X509_name_st {
170 STACK_OF(X509_NAME_ENTRY) *entries;
171 int modified; /* true if 'bytes' needs to be built */
172#ifndef OPENSSL_NO_BUFFER
173 BUF_MEM *bytes;
174#else
175 char *bytes;
176#endif
177/* unsigned long hash; Keep the hash around for lookups */
178 unsigned char *canon_enc;
179 int canon_enclen;
180} /* X509_NAME */;
181#endif
182
183DECLARE_STACK_OF(X509_NAME) 148DECLARE_STACK_OF(X509_NAME)
184 149
185#define X509_EX_V_NETSCAPE_HACK 0x8000 150#define X509_EX_V_NETSCAPE_HACK 0x8000
186#define X509_EX_V_INIT 0x0001 151#define X509_EX_V_INIT 0x0001
187#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
188typedef struct X509_extension_st {
189 ASN1_OBJECT *object;
190 ASN1_BOOLEAN critical;
191 ASN1_OCTET_STRING *value;
192} X509_EXTENSION;
193#else
194typedef struct X509_extension_st X509_EXTENSION; 152typedef struct X509_extension_st X509_EXTENSION;
195#endif
196 153
197typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; 154typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS;
198 155
199DECLARE_STACK_OF(X509_EXTENSION) 156DECLARE_STACK_OF(X509_EXTENSION)
200 157
201/* a sequence of these are used */
202#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
203typedef struct x509_attributes_st {
204 ASN1_OBJECT *object;
205 int single; /* 0 for a set, 1 for a single item (which is wrong) */
206 union {
207 char *ptr;
208/* 0 */ STACK_OF(ASN1_TYPE) *set;
209/* 1 */ ASN1_TYPE *single;
210 } value;
211} X509_ATTRIBUTE;
212#else
213typedef struct x509_attributes_st X509_ATTRIBUTE; 158typedef struct x509_attributes_st X509_ATTRIBUTE;
214#endif
215 159
216DECLARE_STACK_OF(X509_ATTRIBUTE) 160DECLARE_STACK_OF(X509_ATTRIBUTE)
217 161
218
219#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
220typedef struct X509_req_info_st {
221 ASN1_ENCODING enc;
222 ASN1_INTEGER *version;
223 X509_NAME *subject;
224 X509_PUBKEY *pubkey;
225 /* d=2 hl=2 l= 0 cons: cont: 00 */
226 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
227} X509_REQ_INFO;
228
229typedef struct X509_req_st {
230 X509_REQ_INFO *req_info;
231 X509_ALGOR *sig_alg;
232 ASN1_BIT_STRING *signature;
233 int references;
234} X509_REQ;
235
236typedef struct x509_cinf_st {
237 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
238 ASN1_INTEGER *serialNumber;
239 X509_ALGOR *signature;
240 X509_NAME *issuer;
241 X509_VAL *validity;
242 X509_NAME *subject;
243 X509_PUBKEY *key;
244 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
245 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
246 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
247 ASN1_ENCODING enc;
248} X509_CINF;
249#else
250typedef struct X509_req_info_st X509_REQ_INFO; 162typedef struct X509_req_info_st X509_REQ_INFO;
251typedef struct X509_req_st X509_REQ;
252typedef struct x509_cinf_st X509_CINF;
253#endif
254 163
255/* This stuff is certificate "auxiliary info" 164typedef struct X509_req_st X509_REQ;
256 * it contains details which are useful in certificate
257 * stores and databases. When used this is tagged onto
258 * the end of the certificate itself
259 */
260 165
261#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
262typedef struct x509_cert_aux_st {
263 STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
264 STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
265 ASN1_UTF8STRING *alias; /* "friendly name" */
266 ASN1_OCTET_STRING *keyid; /* key id of private key */
267 STACK_OF(X509_ALGOR) *other; /* other unspecified info */
268} X509_CERT_AUX;
269#else
270typedef struct x509_cert_aux_st X509_CERT_AUX; 166typedef struct x509_cert_aux_st X509_CERT_AUX;
271#endif
272 167
273struct x509_st; 168typedef struct x509_cinf_st X509_CINF;
274
275#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
276struct x509_st {
277 X509_CINF *cert_info;
278 X509_ALGOR *sig_alg;
279 ASN1_BIT_STRING *signature;
280 int valid;
281 int references;
282 char *name;
283 CRYPTO_EX_DATA ex_data;
284 /* These contain copies of various extension values */
285 long ex_pathlen;
286 long ex_pcpathlen;
287 unsigned long ex_flags;
288 unsigned long ex_kusage;
289 unsigned long ex_xkusage;
290 unsigned long ex_nscert;
291 ASN1_OCTET_STRING *skid;
292 AUTHORITY_KEYID *akid;
293 X509_POLICY_CACHE *policy_cache;
294 STACK_OF(DIST_POINT) *crldp;
295 STACK_OF(GENERAL_NAME) *altname;
296 NAME_CONSTRAINTS *nc;
297#ifndef OPENSSL_NO_RFC3779
298 STACK_OF(IPAddressFamily) *rfc3779_addr;
299 struct ASIdentifiers_st *rfc3779_asid;
300#endif
301#ifndef OPENSSL_NO_SHA
302 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
303#endif
304 X509_CERT_AUX *aux;
305} /* X509 */;
306#endif
307 169
308DECLARE_STACK_OF(X509) 170DECLARE_STACK_OF(X509)
309 171
@@ -322,6 +184,7 @@ DECLARE_STACK_OF(X509_TRUST)
322 184
323/* standard trust ids */ 185/* standard trust ids */
324 186
187/* OpenSSL changed this to 0 */
325#define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */ 188#define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */
326 189
327#define X509_TRUST_COMPAT 1 190#define X509_TRUST_COMPAT 1
@@ -422,66 +285,13 @@ DECLARE_STACK_OF(X509_TRUST)
422 XN_FLAG_FN_LN | \ 285 XN_FLAG_FN_LN | \
423 XN_FLAG_FN_ALIGN) 286 XN_FLAG_FN_ALIGN)
424 287
425#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
426struct x509_revoked_st {
427 ASN1_INTEGER *serialNumber;
428 ASN1_TIME *revocationDate;
429 STACK_OF(X509_EXTENSION) /* optional */ *extensions;
430 /* Set up if indirect CRL */
431 STACK_OF(GENERAL_NAME) *issuer;
432 /* Revocation reason */
433 int reason;
434 int sequence; /* load sequence */
435};
436#endif
437
438DECLARE_STACK_OF(X509_REVOKED) 288DECLARE_STACK_OF(X509_REVOKED)
439 289
440#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
441typedef struct X509_crl_info_st {
442 ASN1_INTEGER *version;
443 X509_ALGOR *sig_alg;
444 X509_NAME *issuer;
445 ASN1_TIME *lastUpdate;
446 ASN1_TIME *nextUpdate;
447 STACK_OF(X509_REVOKED) *revoked;
448 STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
449 ASN1_ENCODING enc;
450} X509_CRL_INFO;
451#else
452typedef struct X509_crl_info_st X509_CRL_INFO; 290typedef struct X509_crl_info_st X509_CRL_INFO;
453#endif
454
455#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
456struct X509_crl_st {
457 /* actual signature */
458 X509_CRL_INFO *crl;
459 X509_ALGOR *sig_alg;
460 ASN1_BIT_STRING *signature;
461 int references;
462 int flags;
463 /* Copies of various extensions */
464 AUTHORITY_KEYID *akid;
465 ISSUING_DIST_POINT *idp;
466 /* Convenient breakdown of IDP */
467 int idp_flags;
468 int idp_reasons;
469 /* CRL and base CRL numbers for delta processing */
470 ASN1_INTEGER *crl_number;
471 ASN1_INTEGER *base_crl_number;
472#ifndef OPENSSL_NO_SHA
473 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
474#endif
475 STACK_OF(GENERAL_NAMES) *issuers;
476 const X509_CRL_METHOD *meth;
477 void *meth_data;
478} /* X509_CRL */;
479#endif
480 291
481DECLARE_STACK_OF(X509_CRL) 292DECLARE_STACK_OF(X509_CRL)
482 293
483typedef struct private_key_st 294typedef struct private_key_st {
484 {
485 int version; 295 int version;
486 /* The PKCS#8 data types */ 296 /* The PKCS#8 data types */
487 X509_ALGOR *enc_algor; 297 X509_ALGOR *enc_algor;
@@ -499,7 +309,7 @@ typedef struct private_key_st
499 EVP_CIPHER_INFO cipher; 309 EVP_CIPHER_INFO cipher;
500 310
501 int references; 311 int references;
502 } X509_PKEY; 312} X509_PKEY;
503 313
504#ifndef OPENSSL_NO_EVP 314#ifndef OPENSSL_NO_EVP
505typedef struct X509_info_st { 315typedef struct X509_info_st {
@@ -561,18 +371,6 @@ typedef struct PBKDF2PARAM_st {
561 X509_ALGOR *prf; 371 X509_ALGOR *prf;
562} PBKDF2PARAM; 372} PBKDF2PARAM;
563 373
564
565/* PKCS#8 private key info structure */
566
567#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
568struct pkcs8_priv_key_info_st {
569 ASN1_INTEGER *version;
570 X509_ALGOR *pkeyalg;
571 ASN1_OCTET_STRING *pkey;
572 STACK_OF(X509_ATTRIBUTE) *attributes;
573};
574#endif
575
576#ifdef __cplusplus 374#ifdef __cplusplus
577} 375}
578#endif 376#endif
diff --git a/src/lib/libcrypto/x509/x509_addr.c b/src/lib/libcrypto/x509/x509_addr.c
index 313896167b..ddb0e4af12 100644
--- a/src/lib/libcrypto/x509/x509_addr.c
+++ b/src/lib/libcrypto/x509/x509_addr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_addr.c,v 1.18 2021/10/25 11:55:27 tb Exp $ */ 1/* $OpenBSD: x509_addr.c,v 1.19 2021/11/01 20:53:08 tb Exp $ */
2/* 2/*
3 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. 3 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * 4 *
@@ -24,6 +24,8 @@
24#include <openssl/x509.h> 24#include <openssl/x509.h>
25#include <openssl/x509v3.h> 25#include <openssl/x509v3.h>
26 26
27#include "x509_lcl.h"
28
27#ifndef OPENSSL_NO_RFC3779 29#ifndef OPENSSL_NO_RFC3779
28 30
29/* 31/*
diff --git a/src/lib/libcrypto/x509/x509_asid.c b/src/lib/libcrypto/x509/x509_asid.c
index d990bc0158..d2247e09c1 100644
--- a/src/lib/libcrypto/x509/x509_asid.c
+++ b/src/lib/libcrypto/x509/x509_asid.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_asid.c,v 1.18 2021/10/25 11:55:27 tb Exp $ */ 1/* $OpenBSD: x509_asid.c,v 1.19 2021/11/01 20:53:08 tb Exp $ */
2/* 2/*
3 * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. 3 * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * 4 *
@@ -26,6 +26,8 @@
26#include <openssl/x509.h> 26#include <openssl/x509.h>
27#include <openssl/x509v3.h> 27#include <openssl/x509v3.h>
28 28
29#include "x509_lcl.h"
30
29#ifndef OPENSSL_NO_RFC3779 31#ifndef OPENSSL_NO_RFC3779
30 32
31static const ASN1_TEMPLATE ASRange_seq_tt[] = { 33static const ASN1_TEMPLATE ASRange_seq_tt[] = {
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c
index 1479b918c7..38aa063143 100644
--- a/src/lib/libcrypto/x509/x509_att.c
+++ b/src/lib/libcrypto/x509/x509_att.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_att.c,v 1.17 2018/05/18 19:21:33 tb Exp $ */ 1/* $OpenBSD: x509_att.c,v 1.18 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -66,6 +66,8 @@
66#include <openssl/x509.h> 66#include <openssl/x509.h>
67#include <openssl/x509v3.h> 67#include <openssl/x509v3.h>
68 68
69#include "x509_lcl.h"
70
69int 71int
70X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x) 72X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x)
71{ 73{
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c
index 6d6e840899..134a082730 100644
--- a/src/lib/libcrypto/x509/x509_cmp.c
+++ b/src/lib/libcrypto/x509/x509_cmp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_cmp.c,v 1.35 2019/03/13 20:34:00 tb Exp $ */ 1/* $OpenBSD: x509_cmp.c,v 1.36 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -68,6 +68,8 @@
68#include <openssl/x509.h> 68#include <openssl/x509.h>
69#include <openssl/x509v3.h> 69#include <openssl/x509v3.h>
70 70
71#include "x509_lcl.h"
72
71int 73int
72X509_issuer_and_serial_cmp(const X509 *a, const X509 *b) 74X509_issuer_and_serial_cmp(const X509 *a, const X509 *b)
73{ 75{
diff --git a/src/lib/libcrypto/x509/x509_conf.c b/src/lib/libcrypto/x509/x509_conf.c
index 8bf2d10b9f..cd703fc156 100644
--- a/src/lib/libcrypto/x509/x509_conf.c
+++ b/src/lib/libcrypto/x509/x509_conf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_conf.c,v 1.1 2020/06/04 15:19:31 jsing Exp $ */ 1/* $OpenBSD: x509_conf.c,v 1.2 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -66,6 +66,8 @@
66#include <openssl/x509.h> 66#include <openssl/x509.h>
67#include <openssl/x509v3.h> 67#include <openssl/x509v3.h>
68 68
69#include "x509_lcl.h"
70
69static int v3_check_critical(const char **value); 71static int v3_check_critical(const char **value);
70static int v3_check_generic(const char **value); 72static int v3_check_generic(const char **value);
71static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, 73static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
diff --git a/src/lib/libcrypto/x509/x509_crld.c b/src/lib/libcrypto/x509/x509_crld.c
index ff60a880fa..6b6f795378 100644
--- a/src/lib/libcrypto/x509/x509_crld.c
+++ b/src/lib/libcrypto/x509/x509_crld.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_crld.c,v 1.1 2020/06/04 15:19:31 jsing Exp $ */ 1/* $OpenBSD: x509_crld.c,v 1.2 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -65,6 +65,8 @@
65#include <openssl/err.h> 65#include <openssl/err.h>
66#include <openssl/x509v3.h> 66#include <openssl/x509v3.h>
67 67
68#include "x509_lcl.h"
69
68static void *v2i_crld(const X509V3_EXT_METHOD *method, 70static void *v2i_crld(const X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); 71 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
70static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, 72static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out,
diff --git a/src/lib/libcrypto/x509/x509_ext.c b/src/lib/libcrypto/x509/x509_ext.c
index 21374a26e2..1445951199 100644
--- a/src/lib/libcrypto/x509/x509_ext.c
+++ b/src/lib/libcrypto/x509/x509_ext.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_ext.c,v 1.12 2018/05/18 19:28:27 tb Exp $ */ 1/* $OpenBSD: x509_ext.c,v 1.13 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -65,6 +65,8 @@
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66#include <openssl/x509v3.h> 66#include <openssl/x509v3.h>
67 67
68#include "x509_lcl.h"
69
68int 70int
69X509_CRL_get_ext_count(const X509_CRL *x) 71X509_CRL_get_ext_count(const X509_CRL *x)
70{ 72{
diff --git a/src/lib/libcrypto/x509/x509_internal.h b/src/lib/libcrypto/x509/x509_internal.h
index 90fafccae0..7ca67a853b 100644
--- a/src/lib/libcrypto/x509/x509_internal.h
+++ b/src/lib/libcrypto/x509/x509_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_internal.h,v 1.13 2021/10/26 09:09:53 beck Exp $ */ 1/* $OpenBSD: x509_internal.h,v 1.14 2021/11/01 20:53:08 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2020 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2020 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -22,6 +22,8 @@
22 22
23#include <openssl/x509_verify.h> 23#include <openssl/x509_verify.h>
24 24
25#include "x509_lcl.h"
26
25/* Hard limits on structure size and number of signature checks. */ 27/* Hard limits on structure size and number of signature checks. */
26#define X509_VERIFY_MAX_CHAINS 8 /* Max validated chains */ 28#define X509_VERIFY_MAX_CHAINS 8 /* Max validated chains */
27#define X509_VERIFY_MAX_CHAIN_CERTS 32 /* Max depth of a chain */ 29#define X509_VERIFY_MAX_CHAIN_CERTS 32 /* Max depth of a chain */
diff --git a/src/lib/libcrypto/x509/x509_lcl.h b/src/lib/libcrypto/x509/x509_lcl.h
index 3e83b66dd6..1b352aee78 100644
--- a/src/lib/libcrypto/x509/x509_lcl.h
+++ b/src/lib/libcrypto/x509/x509_lcl.h
@@ -56,8 +56,325 @@
56 * 56 *
57 */ 57 */
58 58
59#ifndef HEADER_X509_LCL_H
60#define HEADER_X509_LCL_H
61
59__BEGIN_HIDDEN_DECLS 62__BEGIN_HIDDEN_DECLS
60 63
64struct X509_pubkey_st {
65 X509_ALGOR *algor;
66 ASN1_BIT_STRING *public_key;
67 EVP_PKEY *pkey;
68};
69
70struct X509_sig_st {
71 X509_ALGOR *algor;
72 ASN1_OCTET_STRING *digest;
73} /* X509_SIG */;
74
75struct X509_name_entry_st {
76 ASN1_OBJECT *object;
77 ASN1_STRING *value;
78 int set;
79 int size; /* temp variable */
80} /* X509_NAME_ENTRY */;
81
82/* we always keep X509_NAMEs in 2 forms. */
83struct X509_name_st {
84 STACK_OF(X509_NAME_ENTRY) *entries;
85 int modified; /* true if 'bytes' needs to be built */
86#ifndef OPENSSL_NO_BUFFER
87 BUF_MEM *bytes;
88#else
89 char *bytes;
90#endif
91/* unsigned long hash; Keep the hash around for lookups */
92 unsigned char *canon_enc;
93 int canon_enclen;
94} /* X509_NAME */;
95
96struct X509_extension_st {
97 ASN1_OBJECT *object;
98 ASN1_BOOLEAN critical;
99 ASN1_OCTET_STRING *value;
100} /* X509_EXTENSION */;
101
102struct x509_attributes_st {
103 ASN1_OBJECT *object;
104 int single; /* 0 for a set, 1 for a single item (which is wrong) */
105 union {
106 char *ptr;
107/* 0 */ STACK_OF(ASN1_TYPE) *set;
108/* 1 */ ASN1_TYPE *single;
109 } value;
110} /* X509_ATTRIBUTE */;
111
112struct X509_req_info_st {
113 ASN1_ENCODING enc;
114 ASN1_INTEGER *version;
115 X509_NAME *subject;
116 X509_PUBKEY *pubkey;
117 /* d=2 hl=2 l= 0 cons: cont: 00 */
118 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
119} /* X509_REQ_INFO */;
120
121struct X509_req_st {
122 X509_REQ_INFO *req_info;
123 X509_ALGOR *sig_alg;
124 ASN1_BIT_STRING *signature;
125 int references;
126} /* X509_REQ */;
127
128/*
129 * This stuff is certificate "auxiliary info" it contains details which are
130 * useful in certificate stores and databases. When used this is tagged onto
131 * the end of the certificate itself.
132 */
133struct x509_cert_aux_st {
134 STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
135 STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
136 ASN1_UTF8STRING *alias; /* "friendly name" */
137 ASN1_OCTET_STRING *keyid; /* key id of private key */
138 STACK_OF(X509_ALGOR) *other; /* other unspecified info */
139} /* X509_CERT_AUX */;
140
141struct x509_cinf_st {
142 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
143 ASN1_INTEGER *serialNumber;
144 X509_ALGOR *signature;
145 X509_NAME *issuer;
146 X509_VAL *validity;
147 X509_NAME *subject;
148 X509_PUBKEY *key;
149 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
150 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
151 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
152 ASN1_ENCODING enc;
153} /* X509_CINF */;
154
155struct x509_st {
156 X509_CINF *cert_info;
157 X509_ALGOR *sig_alg;
158 ASN1_BIT_STRING *signature;
159 int valid;
160 int references;
161 char *name;
162 CRYPTO_EX_DATA ex_data;
163 /* These contain copies of various extension values */
164 long ex_pathlen;
165 long ex_pcpathlen;
166 unsigned long ex_flags;
167 unsigned long ex_kusage;
168 unsigned long ex_xkusage;
169 unsigned long ex_nscert;
170 ASN1_OCTET_STRING *skid;
171 AUTHORITY_KEYID *akid;
172 X509_POLICY_CACHE *policy_cache;
173 STACK_OF(DIST_POINT) *crldp;
174 STACK_OF(GENERAL_NAME) *altname;
175 NAME_CONSTRAINTS *nc;
176#ifndef OPENSSL_NO_RFC3779
177 STACK_OF(IPAddressFamily) *rfc3779_addr;
178 struct ASIdentifiers_st *rfc3779_asid;
179#endif
180#ifndef OPENSSL_NO_SHA
181 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
182#endif
183 X509_CERT_AUX *aux;
184} /* X509 */;
185
186struct x509_revoked_st {
187 ASN1_INTEGER *serialNumber;
188 ASN1_TIME *revocationDate;
189 STACK_OF(X509_EXTENSION) /* optional */ *extensions;
190 /* Set up if indirect CRL */
191 STACK_OF(GENERAL_NAME) *issuer;
192 /* Revocation reason */
193 int reason;
194 int sequence; /* load sequence */
195};
196
197struct X509_crl_info_st {
198 ASN1_INTEGER *version;
199 X509_ALGOR *sig_alg;
200 X509_NAME *issuer;
201 ASN1_TIME *lastUpdate;
202 ASN1_TIME *nextUpdate;
203 STACK_OF(X509_REVOKED) *revoked;
204 STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
205 ASN1_ENCODING enc;
206} /* X509_CRL_INFO */;
207
208struct X509_crl_st {
209 /* actual signature */
210 X509_CRL_INFO *crl;
211 X509_ALGOR *sig_alg;
212 ASN1_BIT_STRING *signature;
213 int references;
214 int flags;
215 /* Copies of various extensions */
216 AUTHORITY_KEYID *akid;
217 ISSUING_DIST_POINT *idp;
218 /* Convenient breakdown of IDP */
219 int idp_flags;
220 int idp_reasons;
221 /* CRL and base CRL numbers for delta processing */
222 ASN1_INTEGER *crl_number;
223 ASN1_INTEGER *base_crl_number;
224#ifndef OPENSSL_NO_SHA
225 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
226#endif
227 STACK_OF(GENERAL_NAMES) *issuers;
228 const X509_CRL_METHOD *meth;
229 void *meth_data;
230} /* X509_CRL */;
231
232struct pkcs8_priv_key_info_st {
233 ASN1_INTEGER *version;
234 X509_ALGOR *pkeyalg;
235 ASN1_OCTET_STRING *pkey;
236 STACK_OF(X509_ATTRIBUTE) *attributes;
237};
238
239struct x509_object_st {
240 /* one of the above types */
241 int type;
242 union {
243 char *ptr;
244 X509 *x509;
245 X509_CRL *crl;
246 EVP_PKEY *pkey;
247 } data;
248} /* X509_OBJECT */;
249
250struct x509_lookup_method_st {
251 const char *name;
252 int (*new_item)(X509_LOOKUP *ctx);
253 void (*free)(X509_LOOKUP *ctx);
254 int (*init)(X509_LOOKUP *ctx);
255 int (*shutdown)(X509_LOOKUP *ctx);
256 int (*ctrl)(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
257 char **ret);
258 int (*get_by_subject)(X509_LOOKUP *ctx, int type, X509_NAME *name,
259 X509_OBJECT *ret);
260 int (*get_by_issuer_serial)(X509_LOOKUP *ctx, int type, X509_NAME *name,
261 ASN1_INTEGER *serial,X509_OBJECT *ret);
262 int (*get_by_fingerprint)(X509_LOOKUP *ctx, int type,
263 const unsigned char *bytes, int len, X509_OBJECT *ret);
264 int (*get_by_alias)(X509_LOOKUP *ctx, int type, const char *str,
265 int len, X509_OBJECT *ret);
266} /* X509_LOOKUP_METHOD */;
267
268struct X509_VERIFY_PARAM_st {
269 char *name;
270 time_t check_time; /* Time to use */
271 unsigned long inh_flags; /* Inheritance flags */
272 unsigned long flags; /* Various verify flags */
273 int purpose; /* purpose to check untrusted certificates */
274 int trust; /* trust setting to check */
275 int depth; /* Verify depth */
276 STACK_OF(ASN1_OBJECT) *policies; /* Permissible policies */
277 X509_VERIFY_PARAM_ID *id; /* opaque ID data */
278} /* X509_VERIFY_PARAM */;
279
280/*
281 * This is used to hold everything. It is used for all certificate
282 * validation. Once we have a certificate chain, the 'verify'
283 * function is then called to actually check the cert chain.
284 */
285struct x509_store_st {
286 /* The following is a cache of trusted certs */
287 int cache; /* if true, stash any hits */
288 STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */
289
290 /* These are external lookup methods */
291 STACK_OF(X509_LOOKUP) *get_cert_methods;
292
293 X509_VERIFY_PARAM *param;
294
295 /* Callbacks for various operations */
296 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
297 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
298 int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */
299 int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
300 int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
301 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
302 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
303 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
304 STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm);
305 STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm);
306 int (*cleanup)(X509_STORE_CTX *ctx);
307
308 CRYPTO_EX_DATA ex_data;
309 int references;
310} /* X509_STORE */;
311
312/* This is the functions plus an instance of the local variables. */
313struct x509_lookup_st {
314 int init; /* have we been started */
315 int skip; /* don't use us. */
316 X509_LOOKUP_METHOD *method; /* the functions */
317 char *method_data; /* method data */
318
319 X509_STORE *store_ctx; /* who owns us */
320} /* X509_LOOKUP */;
321
322/*
323 * This is used when verifying cert chains. Since the gathering of the cert
324 * chain can take some time (and has to be 'retried'), this needs to be kept
325 * and passed around.
326 */
327struct x509_store_ctx_st {
328 X509_STORE *ctx;
329 int current_method; /* used when looking up certs */
330
331 /* The following are set by the caller */
332 X509 *cert; /* The cert to check */
333 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */
334 STACK_OF(X509_CRL) *crls; /* set of CRLs passed in */
335
336 X509_VERIFY_PARAM *param;
337 void *other_ctx; /* Other info for use with get_issuer() */
338
339 /* Callbacks for various operations */
340 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
341 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
342 int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */
343 int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
344 int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
345 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
346 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
347 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
348 int (*check_policy)(X509_STORE_CTX *ctx);
349 STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm);
350 STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm);
351 int (*cleanup)(X509_STORE_CTX *ctx);
352
353 /* The following is built up */
354 int valid; /* if 0, rebuild chain */
355 int last_untrusted; /* XXX: number of untrusted certs in chain!!! */
356 STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */
357 X509_POLICY_TREE *tree; /* Valid policy tree */
358
359 int explicit_policy; /* Require explicit policy value */
360
361 /* When something goes wrong, this is why */
362 int error_depth;
363 int error;
364 X509 *current_cert;
365 X509 *current_issuer; /* cert currently being tested as valid issuer */
366 X509_CRL *current_crl; /* current CRL */
367
368 int current_crl_score; /* score of current CRL */
369 unsigned int current_reasons; /* Reason mask */
370
371 X509_STORE_CTX *parent; /* For CRL path validation: parent context */
372
373 CRYPTO_EX_DATA ex_data;
374} /* X509_STORE_CTX */;
375
61int x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int quiet); 376int x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int quiet);
62 377
63__END_HIDDEN_DECLS 378__END_HIDDEN_DECLS
379
380#endif /* !HEADER_X509_LCL_H */
diff --git a/src/lib/libcrypto/x509/x509_lib.c b/src/lib/libcrypto/x509/x509_lib.c
index 211d0adfee..a518d5b950 100644
--- a/src/lib/libcrypto/x509/x509_lib.c
+++ b/src/lib/libcrypto/x509/x509_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_lib.c,v 1.2 2020/09/14 11:35:32 beck Exp $ */ 1/* $OpenBSD: x509_lib.c,v 1.3 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -64,6 +64,7 @@
64#include <openssl/x509v3.h> 64#include <openssl/x509v3.h>
65 65
66#include "ext_dat.h" 66#include "ext_dat.h"
67#include "x509_lcl.h"
67 68
68static STACK_OF(X509V3_EXT_METHOD) *ext_list = NULL; 69static STACK_OF(X509V3_EXT_METHOD) *ext_list = NULL;
69 70
diff --git a/src/lib/libcrypto/x509/x509_ncons.c b/src/lib/libcrypto/x509/x509_ncons.c
index 1621f98617..613527005a 100644
--- a/src/lib/libcrypto/x509/x509_ncons.c
+++ b/src/lib/libcrypto/x509/x509_ncons.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_ncons.c,v 1.4 2020/09/16 18:12:06 beck Exp $ */ 1/* $OpenBSD: x509_ncons.c,v 1.5 2021/11/01 20:53:08 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. 3 * project.
4 */ 4 */
@@ -64,6 +64,8 @@
64#include <openssl/err.h> 64#include <openssl/err.h>
65#include <openssl/x509v3.h> 65#include <openssl/x509v3.h>
66 66
67#include "x509_lcl.h"
68
67static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, 69static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method,
68 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); 70 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
69static int i2r_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, 71static int i2r_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method,
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c
index 5c53799020..58ffa3a2f2 100644
--- a/src/lib/libcrypto/x509/x509_obj.c
+++ b/src/lib/libcrypto/x509/x509_obj.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_obj.c,v 1.18 2018/05/18 18:19:31 tb Exp $ */ 1/* $OpenBSD: x509_obj.c,v 1.19 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -65,6 +65,8 @@
65#include <openssl/objects.h> 65#include <openssl/objects.h>
66#include <openssl/x509.h> 66#include <openssl/x509.h>
67 67
68#include "x509_lcl.h"
69
68char * 70char *
69X509_NAME_oneline(const X509_NAME *a, char *buf, int len) 71X509_NAME_oneline(const X509_NAME *a, char *buf, int len)
70{ 72{
diff --git a/src/lib/libcrypto/x509/x509_prn.c b/src/lib/libcrypto/x509/x509_prn.c
index 5c15cc390f..4977051d4a 100644
--- a/src/lib/libcrypto/x509/x509_prn.c
+++ b/src/lib/libcrypto/x509/x509_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_prn.c,v 1.1 2020/06/04 15:19:32 jsing Exp $ */ 1/* $OpenBSD: x509_prn.c,v 1.2 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -62,6 +62,8 @@
62#include <openssl/conf.h> 62#include <openssl/conf.h>
63#include <openssl/x509v3.h> 63#include <openssl/x509v3.h>
64 64
65#include "x509_lcl.h"
66
65/* Extension printing routines */ 67/* Extension printing routines */
66 68
67static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, 69static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag,
diff --git a/src/lib/libcrypto/x509/x509_purp.c b/src/lib/libcrypto/x509/x509_purp.c
index 8a5f6704a2..67a7b51fb1 100644
--- a/src/lib/libcrypto/x509/x509_purp.c
+++ b/src/lib/libcrypto/x509/x509_purp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_purp.c,v 1.11 2021/10/29 12:11:13 tb Exp $ */ 1/* $OpenBSD: x509_purp.c,v 1.12 2021/11/01 20:53:08 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 2001. 3 * project 2001.
4 */ 4 */
@@ -65,6 +65,8 @@
65#include <openssl/x509v3.h> 65#include <openssl/x509v3.h>
66#include <openssl/x509_vfy.h> 66#include <openssl/x509_vfy.h>
67 67
68#include "x509_lcl.h"
69
68#define V1_ROOT (EXFLAG_V1|EXFLAG_SS) 70#define V1_ROOT (EXFLAG_V1|EXFLAG_SS)
69#define ku_reject(x, usage) \ 71#define ku_reject(x, usage) \
70 (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage))) 72 (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage)))
diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c
index 525163bc3e..143d0f1aa0 100644
--- a/src/lib/libcrypto/x509/x509_r2x.c
+++ b/src/lib/libcrypto/x509/x509_r2x.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_r2x.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: x509_r2x.c,v 1.12 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -66,6 +66,8 @@
66#include <openssl/objects.h> 66#include <openssl/objects.h>
67#include <openssl/x509.h> 67#include <openssl/x509.h>
68 68
69#include "x509_lcl.h"
70
69X509 * 71X509 *
70X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) 72X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
71{ 73{
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
index c81fe4a3a9..556e32b317 100644
--- a/src/lib/libcrypto/x509/x509_req.c
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_req.c,v 1.23 2021/10/23 11:56:10 tb Exp $ */ 1/* $OpenBSD: x509_req.c,v 1.24 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -70,6 +70,8 @@
70#include <openssl/pem.h> 70#include <openssl/pem.h>
71#include <openssl/x509.h> 71#include <openssl/x509.h>
72 72
73#include "x509_lcl.h"
74
73X509_REQ * 75X509_REQ *
74X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) 76X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
75{ 77{
diff --git a/src/lib/libcrypto/x509/x509_set.c b/src/lib/libcrypto/x509/x509_set.c
index c4ce8e5674..5784f2203e 100644
--- a/src/lib/libcrypto/x509/x509_set.c
+++ b/src/lib/libcrypto/x509/x509_set.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_set.c,v 1.19 2021/11/01 08:14:36 tb Exp $ */ 1/* $OpenBSD: x509_set.c,v 1.20 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -63,6 +63,8 @@
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65 65
66#include "x509_lcl.h"
67
66const STACK_OF(X509_EXTENSION) * 68const STACK_OF(X509_EXTENSION) *
67X509_get0_extensions(const X509 *x) 69X509_get0_extensions(const X509 *x)
68{ 70{
diff --git a/src/lib/libcrypto/x509/x509_skey.c b/src/lib/libcrypto/x509/x509_skey.c
index a906427378..58bb66bc05 100644
--- a/src/lib/libcrypto/x509/x509_skey.c
+++ b/src/lib/libcrypto/x509/x509_skey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_skey.c,v 1.1 2020/06/04 15:19:32 jsing Exp $ */ 1/* $OpenBSD: x509_skey.c,v 1.2 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -62,6 +62,8 @@
62#include <openssl/err.h> 62#include <openssl/err.h>
63#include <openssl/x509v3.h> 63#include <openssl/x509v3.h>
64 64
65#include "x509_lcl.h"
66
65static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, 67static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
66 X509V3_CTX *ctx, char *str); 68 X509V3_CTX *ctx, char *str);
67 69
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c
index 1a60e5a3cf..72d616a106 100644
--- a/src/lib/libcrypto/x509/x509_trs.c
+++ b/src/lib/libcrypto/x509/x509_trs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_trs.c,v 1.24 2021/07/23 20:50:28 schwarze Exp $ */ 1/* $OpenBSD: x509_trs.c,v 1.25 2021/11/01 20:53:08 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 1999. 3 * project 1999.
4 */ 4 */
@@ -62,6 +62,8 @@
62#include <openssl/err.h> 62#include <openssl/err.h>
63#include <openssl/x509v3.h> 63#include <openssl/x509v3.h>
64 64
65#include "x509_lcl.h"
66
65static int tr_cmp(const X509_TRUST * const *a, const X509_TRUST * const *b); 67static int tr_cmp(const X509_TRUST * const *a, const X509_TRUST * const *b);
66static void trtable_free(X509_TRUST *p); 68static void trtable_free(X509_TRUST *p);
67 69
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
index 524d5511ed..9aefb8d99d 100644
--- a/src/lib/libcrypto/x509/x509_v3.c
+++ b/src/lib/libcrypto/x509/x509_v3.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_v3.c,v 1.17 2018/05/19 10:54:40 tb Exp $ */ 1/* $OpenBSD: x509_v3.c,v 1.18 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -66,6 +66,8 @@
66#include <openssl/x509.h> 66#include <openssl/x509.h>
67#include <openssl/x509v3.h> 67#include <openssl/x509v3.h>
68 68
69#include "x509_lcl.h"
70
69int 71int
70X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x) 72X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x)
71{ 73{
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c
index 4c3fe7f3e3..664474139c 100644
--- a/src/lib/libcrypto/x509/x509_vfy.c
+++ b/src/lib/libcrypto/x509/x509_vfy.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_vfy.c,v 1.92 2021/10/26 15:14:18 job Exp $ */ 1/* $OpenBSD: x509_vfy.c,v 1.93 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -76,8 +76,6 @@
76#include "asn1_locl.h" 76#include "asn1_locl.h"
77#include "vpm_int.h" 77#include "vpm_int.h"
78#include "x509_internal.h" 78#include "x509_internal.h"
79#include "x509_lcl.h"
80#include "x509_internal.h"
81 79
82/* CRL score values */ 80/* CRL score values */
83 81
diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h
index 61ea11b71a..133ffda337 100644
--- a/src/lib/libcrypto/x509/x509_vfy.h
+++ b/src/lib/libcrypto/x509/x509_vfy.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_vfy.h,v 1.45 2021/11/01 08:14:36 tb Exp $ */ 1/* $OpenBSD: x509_vfy.h,v 1.46 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -100,173 +100,17 @@ typedef enum {
100 X509_LU_CRL, 100 X509_LU_CRL,
101} X509_LOOKUP_TYPE; 101} X509_LOOKUP_TYPE;
102 102
103#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
104typedef struct x509_object_st {
105 /* one of the above types */
106 int type;
107 union {
108 char *ptr;
109 X509 *x509;
110 X509_CRL *crl;
111 EVP_PKEY *pkey;
112 } data;
113} X509_OBJECT;
114#else
115typedef struct x509_object_st X509_OBJECT;
116#endif
117
118typedef struct x509_lookup_st X509_LOOKUP;
119 103
120DECLARE_STACK_OF(X509_LOOKUP) 104DECLARE_STACK_OF(X509_LOOKUP)
121DECLARE_STACK_OF(X509_OBJECT) 105DECLARE_STACK_OF(X509_OBJECT)
106DECLARE_STACK_OF(X509_VERIFY_PARAM)
122 107
123#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509) 108/* unused in OpenSSL */
124/* This is a static that defines the function interface */
125typedef struct x509_lookup_method_st {
126 const char *name;
127 int (*new_item)(X509_LOOKUP *ctx);
128 void (*free)(X509_LOOKUP *ctx);
129 int (*init)(X509_LOOKUP *ctx);
130 int (*shutdown)(X509_LOOKUP *ctx);
131 int (*ctrl)(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
132 char **ret);
133 int (*get_by_subject)(X509_LOOKUP *ctx, int type, X509_NAME *name,
134 X509_OBJECT *ret);
135 int (*get_by_issuer_serial)(X509_LOOKUP *ctx, int type, X509_NAME *name,
136 ASN1_INTEGER *serial,X509_OBJECT *ret);
137 int (*get_by_fingerprint)(X509_LOOKUP *ctx, int type,
138 const unsigned char *bytes, int len, X509_OBJECT *ret);
139 int (*get_by_alias)(X509_LOOKUP *ctx, int type, const char *str,
140 int len, X509_OBJECT *ret);
141} X509_LOOKUP_METHOD;
142
143typedef struct X509_VERIFY_PARAM_ID_st X509_VERIFY_PARAM_ID; 109typedef struct X509_VERIFY_PARAM_ID_st X509_VERIFY_PARAM_ID;
144 110
145/* This structure hold all parameters associated with a verify operation
146 * by including an X509_VERIFY_PARAM structure in related structures the
147 * parameters used can be customized
148 */
149
150typedef struct X509_VERIFY_PARAM_st {
151 char *name;
152 time_t check_time; /* Time to use */
153 unsigned long inh_flags; /* Inheritance flags */
154 unsigned long flags; /* Various verify flags */
155 int purpose; /* purpose to check untrusted certificates */
156 int trust; /* trust setting to check */
157 int depth; /* Verify depth */
158 STACK_OF(ASN1_OBJECT) *policies; /* Permissible policies */
159 X509_VERIFY_PARAM_ID *id; /* opaque ID data */
160} X509_VERIFY_PARAM;
161#else
162typedef struct x509_lookup_method_st X509_LOOKUP_METHOD;
163typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM;
164#endif
165
166DECLARE_STACK_OF(X509_VERIFY_PARAM)
167
168#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
169/*
170 * This is used to hold everything. It is used for all certificate
171 * validation. Once we have a certificate chain, the 'verify'
172 * function is then called to actually check the cert chain.
173 */
174struct x509_store_st {
175 /* The following is a cache of trusted certs */
176 int cache; /* if true, stash any hits */
177 STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */
178
179 /* These are external lookup methods */
180 STACK_OF(X509_LOOKUP) *get_cert_methods;
181
182 X509_VERIFY_PARAM *param;
183
184 /* Callbacks for various operations */
185 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
186 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
187 int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */
188 int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
189 int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
190 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
191 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
192 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
193 STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm);
194 STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm);
195 int (*cleanup)(X509_STORE_CTX *ctx);
196
197 CRYPTO_EX_DATA ex_data;
198 int references;
199} /* X509_STORE */;
200#endif
201 111
202int X509_STORE_set_depth(X509_STORE *store, int depth); 112int X509_STORE_set_depth(X509_STORE *store, int depth);
203 113
204#if defined(LIBRESSL_CRYPTO_INTERNAL) || !defined(LIBRESSL_OPAQUE_X509)
205/* This is the functions plus an instance of the local variables. */
206struct x509_lookup_st {
207 int init; /* have we been started */
208 int skip; /* don't use us. */
209 X509_LOOKUP_METHOD *method; /* the functions */
210 char *method_data; /* method data */
211
212 X509_STORE *store_ctx; /* who owns us */
213} /* X509_LOOKUP */;
214
215/*
216 * This is used when verifying cert chains. Since the gathering of the cert
217 * chain can take some time (and has to be 'retried'), this needs to be kept
218 * and passed around.
219 */
220struct x509_store_ctx_st {
221 X509_STORE *ctx;
222 int current_method; /* used when looking up certs */
223
224 /* The following are set by the caller */
225 X509 *cert; /* The cert to check */
226 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */
227 STACK_OF(X509_CRL) *crls; /* set of CRLs passed in */
228
229 X509_VERIFY_PARAM *param;
230 void *other_ctx; /* Other info for use with get_issuer() */
231
232 /* Callbacks for various operations */
233 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
234 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
235 int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */
236 int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
237 int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
238 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
239 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
240 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
241 int (*check_policy)(X509_STORE_CTX *ctx);
242 STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm);
243 STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm);
244 int (*cleanup)(X509_STORE_CTX *ctx);
245
246 /* The following is built up */
247 int valid; /* if 0, rebuild chain */
248 int last_untrusted; /* XXX: number of untrusted certs in chain!!! */
249 STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */
250 X509_POLICY_TREE *tree; /* Valid policy tree */
251
252 int explicit_policy; /* Require explicit policy value */
253
254 /* When something goes wrong, this is why */
255 int error_depth;
256 int error;
257 X509 *current_cert;
258 X509 *current_issuer; /* cert currently being tested as valid issuer */
259 X509_CRL *current_crl; /* current CRL */
260
261 int current_crl_score; /* score of current CRL */
262 unsigned int current_reasons; /* Reason mask */
263
264 X509_STORE_CTX *parent; /* For CRL path validation: parent context */
265
266 CRYPTO_EX_DATA ex_data;
267} /* X509_STORE_CTX */;
268#endif
269
270void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); 114void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);
271 115
272#define X509_STORE_CTX_set_app_data(ctx,data) \ 116#define X509_STORE_CTX_set_app_data(ctx,data) \
diff --git a/src/lib/libcrypto/x509/x509_vpm.c b/src/lib/libcrypto/x509/x509_vpm.c
index 42ea6e72c9..13171e40f5 100644
--- a/src/lib/libcrypto/x509/x509_vpm.c
+++ b/src/lib/libcrypto/x509/x509_vpm.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_vpm.c,v 1.27 2021/09/30 18:23:46 jsing Exp $ */ 1/* $OpenBSD: x509_vpm.c,v 1.28 2021/11/01 20:53:08 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 2004. 3 * project 2004.
4 */ 4 */
@@ -67,6 +67,7 @@
67#include <openssl/x509v3.h> 67#include <openssl/x509v3.h>
68 68
69#include "vpm_int.h" 69#include "vpm_int.h"
70#include "x509_lcl.h"
70 71
71/* X509_VERIFY_PARAM functions */ 72/* X509_VERIFY_PARAM functions */
72 73
diff --git a/src/lib/libcrypto/x509/x509cset.c b/src/lib/libcrypto/x509/x509cset.c
index 98fbdc2025..b3af77d90e 100644
--- a/src/lib/libcrypto/x509/x509cset.c
+++ b/src/lib/libcrypto/x509/x509cset.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509cset.c,v 1.15 2021/10/23 11:56:10 tb Exp $ */ 1/* $OpenBSD: x509cset.c,v 1.16 2021/11/01 20:53:08 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 2001. 3 * project 2001.
4 */ 4 */
@@ -63,8 +63,10 @@
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65 65
66#include "x509_lcl.h"
67
66int 68int
67X509_CRL_up_ref(X509_CRL *x) 69X509_CRL_up_ref(X509_CRL *x)
68{ 70{
69 int refs = CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL); 71 int refs = CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL);
70 return (refs > 1) ? 1 : 0; 72 return (refs > 1) ? 1 : 0;
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c
index 3649d6ab7c..878d787846 100644
--- a/src/lib/libcrypto/x509/x509name.c
+++ b/src/lib/libcrypto/x509/x509name.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509name.c,v 1.26 2018/05/30 15:35:45 tb Exp $ */ 1/* $OpenBSD: x509name.c,v 1.27 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -66,6 +66,8 @@
66#include <openssl/stack.h> 66#include <openssl/stack.h>
67#include <openssl/x509.h> 67#include <openssl/x509.h>
68 68
69#include "x509_lcl.h"
70
69int 71int
70X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) 72X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len)
71{ 73{
diff --git a/src/lib/libcrypto/x509/x509rset.c b/src/lib/libcrypto/x509/x509rset.c
index dabeda2a64..a2dd9e4cd2 100644
--- a/src/lib/libcrypto/x509/x509rset.c
+++ b/src/lib/libcrypto/x509/x509rset.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509rset.c,v 1.8 2021/10/21 16:47:01 tb Exp $ */ 1/* $OpenBSD: x509rset.c,v 1.9 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -63,6 +63,8 @@
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65 65
66#include "x509_lcl.h"
67
66int 68int
67X509_REQ_set_version(X509_REQ *x, long version) 69X509_REQ_set_version(X509_REQ *x, long version)
68{ 70{
diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c
index 315a5c2326..1748ee5110 100644
--- a/src/lib/libcrypto/x509/x509type.c
+++ b/src/lib/libcrypto/x509/x509type.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509type.c,v 1.13 2018/05/30 15:59:33 tb Exp $ */ 1/* $OpenBSD: x509type.c,v 1.14 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -62,6 +62,8 @@
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65#include "x509_lcl.h"
66
65int 67int
66X509_certificate_type(const X509 *x, const EVP_PKEY *pkey) 68X509_certificate_type(const X509 *x, const EVP_PKEY *pkey)
67{ 69{
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c
index 36c12b80e5..c06e74c915 100644
--- a/src/lib/libcrypto/x509/x_all.c
+++ b/src/lib/libcrypto/x509/x_all.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_all.c,v 1.23 2016/12/30 15:24:51 jsing Exp $ */ 1/* $OpenBSD: x_all.c,v 1.24 2021/11/01 20:53:08 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -73,6 +73,8 @@
73#include <openssl/rsa.h> 73#include <openssl/rsa.h>
74#endif 74#endif
75 75
76#include "x509_lcl.h"
77
76X509 * 78X509 *
77d2i_X509_bio(BIO *bp, X509 **x509) 79d2i_X509_bio(BIO *bp, X509 **x509)
78{ 80{