diff --git a/compat/Makefile.am b/compat/Makefile.am index 83595cd..03f7109 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -98,3 +98,7 @@ if !HAVE_ASN1_TIME_TM_CMP libcompat_la_SOURCES += a_time_tm.c endif endif + +if !HAVE_X509_GET_EXTENSION_FLAGS +libcompat_la_SOURCES += x509_purp.c +endif diff --git a/compat/x509_purp.c b/compat/x509_purp.c new file mode 100644 index 0000000..aaef3df --- /dev/null +++ b/compat/x509_purp.c @@ -0,0 +1,69 @@ +/* $OpenBSD: x509_purp.c,v 1.13 2021/11/04 23:52:34 beck Exp $ */ +/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL + * project 2001. + */ +/* ==================================================================== + * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include + +uint32_t +X509_get_extension_flags(X509 *x) +{ + /* Call for side-effect of computing hash and caching extensions */ + if (X509_check_purpose(x, -1, -1) != 1) + return 0; + + return x->ex_flags; +} diff --git a/configure.ac b/configure.ac index e5b5a8f..5956063 100644 --- a/configure.ac +++ b/configure.ac @@ -265,9 +265,10 @@ AC_CHECK_HEADERS([openssl/cms.h openssl/err.h openssl/evp.h openssl/ssl.h openss AC_CHECK_LIB([crypto], [ASN1_STRING_get0_data], [], [AC_MSG_ERROR([OpenSSL libraries required])]) AC_CHECK_FUNCS([X509_up_ref], [], [AC_MSG_ERROR([OpenSSL libraries required])]) -AC_CHECK_FUNCS([ASN1_time_parse ASN1_time_tm_cmp]) +AC_CHECK_FUNCS([ASN1_time_parse ASN1_time_tm_cmp X509_get_extension_flags]) AM_CONDITIONAL([HAVE_ASN1_TIME_PARSE], [test "x$ac_cv_func_ASN1_time_parse" = xyes]) AM_CONDITIONAL([HAVE_ASN1_TIME_TM_CMP], [test "x$ac_cv_func_ASN1_time_tm_cmp" = xyes]) +AM_CONDITIONAL([HAVE_X509_GET_EXTENSION_FLAGS], [test "x$ac_cv_func_X509_get_extension_flags" = xyes]) AC_CHECK_HEADERS([tls.h], [], [AC_MSG_ERROR([LibreSSL libtls headers required])]) AC_SEARCH_LIBS([tls_read],[tls-standalone tls retls], [], [AC_MSG_ERROR([LibreSSL libtls library required])], [-lssl -lcrypto]) diff --git a/include/Makefile.am b/include/Makefile.am index 810f109..d821cd8 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -6,6 +6,7 @@ noinst_HEADERS += sys/tree.h noinst_HEADERS += sys/types.h noinst_HEADERS += sys/wait.h noinst_HEADERS += openssl/asn1.h +noinst_HEADERS += openssl/x509v3.h noinst_HEADERS += imsg.h noinst_HEADERS += poll.h noinst_HEADERS += sha2.h diff --git a/include/openssl/x509v3.h b/include/openssl/x509v3.h new file mode 100644 index 0000000..5623397 --- /dev/null +++ b/include/openssl/x509v3.h @@ -0,0 +1,15 @@ +/* + * Public domain + * openssl/x509v3.h compatibility shim + */ + +#include_next + +#ifndef LIBCOMPAT_OPENSSL_X509V3_H +#define LIBCOMPAT_OPENSSL_X509V3_H + +#ifndef HAVE_X509_GET_EXTENSION_FLAGS +uint32_t X509_get_extension_flags(X509 *x); +#endif + +#endif