]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Stop leaking OpenSSL types and defines in the isc/safe.h
authorOndřej Surý <ondrej@isc.org>
Wed, 11 Mar 2020 20:23:17 +0000 (21:23 +0100)
committerOndřej Surý <ondrej@isc.org>
Tue, 28 Apr 2020 14:27:39 +0000 (16:27 +0200)
The two "functions" that isc/safe.h declared before were actually simple
defines to matching OpenSSL functions.  The downside of the approach was
enforcing all users of the libisc library to explicitly list the include
path to OpenSSL and link with -lcrypto.  By hiding the specific
implementation into the private namespace changing the defines into
simple functions, we no longer enforce this.  In the long run, this
might also allow us to switch cryptographic library implementation
without affecting the downstream users.

(cherry picked from commit ab827ab5bf7bdd65f0c672c43c3fdbe16a5e7d70)

lib/isc/Makefile.in
lib/isc/include/isc/safe.h
lib/isc/safe.c [new file with mode: 0644]
lib/isc/win32/libisc.def.in
lib/isc/win32/libisc.vcxproj.filters.in
lib/isc/win32/libisc.vcxproj.in
util/copyrights

index 0fb50fa9da6fa4accb3f7c95b20687459722c3a5..94ba35d348de89d4e520070f119b8802695f7a2c 100644 (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}
@@ -78,7 +78,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
 
index 7fbcd60f86a22dcab75facba329ea6683e1fa2bb..3c4784114dd28992d66ec953cce351fccb66694d 100644 (file)
 
 #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`.
  *
diff --git a/lib/isc/safe.c b/lib/isc/safe.c
new file mode 100644 (file)
index 0000000..91f397a
--- /dev/null
@@ -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);
+}
index 9fca245fd6e0d5a879139c762cb84526b37516e6..476d29735fe212228559b33989454b42ce2625f0 100644 (file)
@@ -545,6 +545,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
index 188f0dbdb4dd107a3dba8a51d1c631c058bf8794..70007dc05c950d936285ea4b27148bbaa1074151 100644 (file)
     <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>
index 8cb752a814cd18e65a309dc1a019892d278bd15c..4e170c8338464bcb02dbf47968e01e9a92c95e5d 100644 (file)
@@ -467,6 +467,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" />
index 51206088c4cae559f5c04e50e45c8885c418f887..4848808c2f8d4e9838d9732cb0cf9037ceb44bb1 100644 (file)
 ./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