From 3d235e595168fc6a5eac0accd47a9e60b25cfa2f Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Fri, 17 Sep 2021 15:44:09 +0100 Subject: [PATCH] openweave: fix build to work with latest base builder (#6463) * openweave: fix build to work with latest base builder * openweave: deploy true fix * openweave: cleanup --- projects/openweave/Dockerfile | 7 ++--- projects/openweave/build.sh | 11 ++++++++ projects/openweave/patch.diff | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 projects/openweave/patch.diff diff --git a/projects/openweave/Dockerfile b/projects/openweave/Dockerfile index 99533e81d..2c940a4e7 100644 --- a/projects/openweave/Dockerfile +++ b/projects/openweave/Dockerfile @@ -14,11 +14,7 @@ # ################################################################################ -# Using Ubuntu 16.04 because of breakage on Ubuntu 20.04. -# See https://github.com/google/oss-fuzz/issues/6291 for more details. -FROM gcr.io/oss-fuzz-base/base-builder:xenial -# Delete line above and uncomment line below to upgrade to 20.04. -# FROM gcr.io/oss-fuzz-base/base-builder +FROM gcr.io/oss-fuzz-base/base-builder RUN apt-get update && apt-get install -y python3-pip python-setuptools bridge-utils \ libglib2.0-dev libdbus-1-dev libudev-dev \ libical-dev libreadline-dev udev \ @@ -28,3 +24,4 @@ RUN cpan -i Text::Template RUN git clone --depth 1 https://github.com/openweave/openweave-core WORKDIR $SRC/openweave-core COPY build.sh $SRC/ +COPY patch.diff $SRC/ diff --git a/projects/openweave/build.sh b/projects/openweave/build.sh index e97a742fe..9b366d2ba 100755 --- a/projects/openweave/build.sh +++ b/projects/openweave/build.sh @@ -15,6 +15,8 @@ # ################################################################################ +git apply --ignore-space-change --ignore-whitespace $SRC/patch.diff + function copy_lib { local fuzzer_path=$1 @@ -35,7 +37,16 @@ fi ./bootstrap # java fails with Source option 6 is no longer supported. Use 7 or later. ./configure --disable-java --enable-fuzzing --disable-shared + +# patch bluez +sed -i 's/sys\/socket.h>/sys\/socket.h>\n#include /g' ./third_party/bluez/repo/tools/l2test.c +sed -i 's/sys\/stat.h>/sys\/stat.h>\n#include /g' ./third_party/bluez/repo/tools/rctest.c + +# OpenSSL now declares RAND_bytes so we must patch +find ./src/test-apps/fuzz/ -name "FuzzP*.cpp" -exec sed -i 's/RAND_bytes/RAND_bytes2/g' {} \; + make -j$(nproc) + find src/test-apps/fuzz/ -type f -executable -name "Fuzz*" | while read i; do patchelf --set-rpath '$ORIGIN/lib' ${i} copy_lib ${i} libglib diff --git a/projects/openweave/patch.diff b/projects/openweave/patch.diff new file mode 100644 index 000000000..c1ce5201a --- /dev/null +++ b/projects/openweave/patch.diff @@ -0,0 +1,48 @@ +diff --git a/src/lib/support/crypto/WeaveRNG-OpenSSL.cpp b/src/lib/support/crypto/WeaveRNG-OpenSSL.cpp +index 7a6cb42..c05caae 100644 +--- a/src/lib/support/crypto/WeaveRNG-OpenSSL.cpp ++++ b/src/lib/support/crypto/WeaveRNG-OpenSSL.cpp +@@ -53,8 +53,9 @@ WEAVE_ERROR InitSecureRandomDataSource(nl::Weave::Crypto::EntropyFunct entropyFu + + WEAVE_ERROR GetSecureRandomData(uint8_t *buf, uint16_t len) + { +- if (RAND_bytes((unsigned char *)buf, (int)len) != 1) +- return WEAVE_ERROR_RANDOM_DATA_UNAVAILABLE; ++ //if (RAND_bytes((unsigned char *)buf, (int)len) != 1) ++ // return WEAVE_ERROR_RANDOM_DATA_UNAVAILABLE; ++ memset((unsigned char *)buf, 'A', (int)len); + + return WEAVE_NO_ERROR; + } +diff --git a/src/tools/weave/CertUtils.cpp b/src/tools/weave/CertUtils.cpp +index 2bd8097..a1dce36 100644 +--- a/src/tools/weave/CertUtils.cpp ++++ b/src/tools/weave/CertUtils.cpp +@@ -695,8 +695,9 @@ bool SetCertSerialNumber(X509 *cert) + ASN1_INTEGER *snInt = X509_get_serialNumber(cert); + + // Generate a random value to be used as the serial number. +- if (!RAND_bytes(reinterpret_cast(&rnd), sizeof(rnd))) +- ReportOpenSSLErrorAndExit("RAND_bytes", res = false); ++ //if (!RAND_bytes(reinterpret_cast(&rnd), sizeof(rnd))) ++ // ReportOpenSSLErrorAndExit("RAND_bytes", res = false); ++ memset(reinterpret_cast(&rnd), 'A', sizeof(rnd)); + + // Avoid negative numbers. + rnd &= 0x7FFFFFFFFFFFFFFF; +diff --git a/src/tools/weave/Cmd_GenProvisioningData.cpp b/src/tools/weave/Cmd_GenProvisioningData.cpp +index 85ca2e2..bd5c18b 100644 +--- a/src/tools/weave/Cmd_GenProvisioningData.cpp ++++ b/src/tools/weave/Cmd_GenProvisioningData.cpp +@@ -543,8 +543,9 @@ char *GeneratePairingCode(uint32_t pairingCodeLen) + } + + // Generate random data for the pairing code, excluding the check digit at the end. +- if (!RAND_bytes((uint8_t *)pairingCode, pairingCodeLen - 1)) +- ReportOpenSSLErrorAndExit("Failed to get random data", pairingCode = NULL); ++ //if (!RAND_bytes((uint8_t *)pairingCode, pairingCodeLen - 1)) ++ // ReportOpenSSLErrorAndExit("Failed to get random data", pairingCode = NULL); ++ memset((uint8_t *)pairingCode, 'A', pairingCodeLen - 1); + + // Convert the random data to characters in the range 0-9, A-H, J-N, P, R-Y (base-32 alphanumeric, excluding I, O, Q and Z). + for (uint32_t i = 0; i < pairingCodeLen - 1; i++)