Skip to content

Commit

Permalink
Add compat code for X509_get_extension_flags() which is needed for
Browse files Browse the repository at this point in the history
libressl 3.4.
  • Loading branch information
cjeker committed Apr 7, 2022
1 parent 2b9ba5e commit f0b1a4f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
4 changes: 4 additions & 0 deletions compat/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 69 additions & 0 deletions compat/x509_purp.c
Original file line number Diff line number Diff line change
@@ -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 ([email protected]) 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
* [email protected].
*
* 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
* ([email protected]). This product includes software written by Tim
* Hudson ([email protected]).
*
*/

#include <openssl/x509v3.h>

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;
}
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions include/openssl/x509v3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Public domain
* openssl/x509v3.h compatibility shim
*/

#include_next <openssl/x509v3.h>

#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

0 comments on commit f0b1a4f

Please sign in to comment.