Merge branch '1672-stop-leaking-external-headers-and-symbols-to-the-public-api-isc/safe.h' into 'master'

Make isc_safe API to not leak OpenSSL symbols

See merge request isc-projects/bind9!3215
This commit is contained in:
Ondřej Surý 2020-03-12 19:07:51 +00:00
commit b04eda7212
7 changed files with 38 additions and 6 deletions

View file

@ -60,7 +60,7 @@ OBJS = pk11.@O@ pk11_result.@O@ \
parseint.@O@ portset.@O@ queue.@O@ quota.@O@ \
radix.@O@ random.@O@ ratelimiter.@O@ \
region.@O@ regex.@O@ result.@O@ rwlock.@O@ \
serial.@O@ siphash.@O@ sockaddr.@O@ stats.@O@ \
safe.@O@ serial.@O@ siphash.@O@ sockaddr.@O@ stats.@O@ \
string.@O@ symtab.@O@ task.@O@ taskpool.@O@ \
tm.@O@ timer.@O@ version.@O@ \
${UNIXOBJS} ${THREADOBJS}
@ -77,7 +77,7 @@ SRCS = pk11.c pk11_result.c \
netaddr.c netscope.c nonce.c openssl_shim.c pool.c \
parseint.c portset.c queue.c quota.c radix.c random.c \
ratelimiter.c region.c regex.c result.c rwlock.c \
serial.c siphash.c sockaddr.c stats.c string.c \
safe.c serial.c siphash.c sockaddr.c stats.c string.c \
symtab.c task.c taskpool.c timer.c \
tm.c version.c

View file

@ -16,11 +16,10 @@
#include <isc/lang.h>
#include <openssl/crypto.h>
ISC_LANG_BEGINDECLS
#define isc_safe_memequal(s1, s2, n) !CRYPTO_memcmp(s1, s2, n)
int
isc_safe_memequal(const void *, const void *, size_t);
/*%<
* Returns true iff. two blocks of memory are equal, otherwise
@ -28,7 +27,9 @@ ISC_LANG_BEGINDECLS
*
*/
#define isc_safe_memwipe(ptr, len) OPENSSL_cleanse(ptr, len)
void
isc_safe_memwipe(void *, size_t);
/*%<
* Clear the memory of length `len` pointed to by `ptr`.
*

24
lib/isc/safe.c Normal file
View file

@ -0,0 +1,24 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#include <openssl/crypto.h>
#include <isc/safe.h>
int
isc_safe_memequal(const void *s1, const void *s2, size_t len) {
return (!CRYPTO_memcmp(s1, s2, len));
}
void
isc_safe_memwipe(void *ptr, size_t len) {
OPENSSL_cleanse(ptr, len);
}

View file

@ -541,6 +541,8 @@ isc_rwlock_lock
isc_rwlock_trylock
isc_rwlock_tryupgrade
isc_rwlock_unlock
isc_safe_memequal
isc_safe_memwipe
isc_serial_eq
isc_serial_ge
isc_serial_gt

View file

@ -584,6 +584,9 @@
<ClCompile Include="..\rwlock.c">
<Filter>Library Source Files</Filter>
</ClCompile>
<ClCompile Include="..\safe.c">
<Filter>Library Source Files</Filter>
</ClCompile>
<ClCompile Include="..\serial.c">
<Filter>Library Source Files</Filter>
</ClCompile>

View file

@ -464,6 +464,7 @@ copy InstallFiles ..\Build\Release\
<ClCompile Include="..\region.c" />
<ClCompile Include="..\result.c" />
<ClCompile Include="..\rwlock.c" />
<ClCompile Include="..\safe.c" />
<ClCompile Include="..\serial.c" />
<ClCompile Include="..\siphash.c" />
<ClCompile Include="..\sockaddr.c" />

View file

@ -2284,6 +2284,7 @@
./lib/isc/region.c C 2002,2004,2005,2007,2016,2018,2019,2020
./lib/isc/result.c C 1998,1999,2000,2001,2003,2004,2005,2007,2008,2012,2014,2015,2016,2017,2018,2019,2020
./lib/isc/rwlock.c C 1998,1999,2000,2001,2003,2004,2005,2007,2009,2011,2012,2015,2016,2017,2018,2019,2020
./lib/isc/safe.c C 2020
./lib/isc/serial.c C 1999,2000,2001,2004,2005,2007,2016,2018,2019,2020
./lib/isc/siphash.c C 2019,2020
./lib/isc/sockaddr.c C 1999,2000,2001,2002,2003,2004,2005,2006,2007,2010,2011,2012,2014,2015,2016,2017,2018,2019,2020