diff options
| author | Simone Basso <bassosimone@gmail.com> | 2016-12-10 20:58:04 +0100 |
|---|---|---|
| committer | Simone Basso <bassosimone@gmail.com> | 2016-12-10 20:58:04 +0100 |
| commit | a206997ad9b7ebd4bb383b10212f02e26f924e56 (patch) | |
| tree | 6162707ac972ff2d4092d6242e1b55087c85b5b3 | |
| parent | 6fa2d21ba57b83c6148a8aa03a362ca9e771fe21 (diff) | |
| download | portable-a206997ad9b7ebd4bb383b10212f02e26f924e56.tar.gz portable-a206997ad9b7ebd4bb383b10212f02e26f924e56.tar.bz2 portable-a206997ad9b7ebd4bb383b10212f02e26f924e56.zip | |
Sync getentropy() checks with use-builtin-arc4random checks
Without this, we actually fail to build a library that includes the
bultin getentropy when compiling for 10.11 on 10.12.
| -rw-r--r-- | m4/check-libc.m4 | 43 | ||||
| -rw-r--r-- | m4/check-os-options.m4 | 27 |
2 files changed, 40 insertions, 30 deletions
diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index 856495e..466a70e 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 | |||
| @@ -54,52 +54,37 @@ AC_CACHE_CHECK([for getentropy], ac_cv_func_getentropy, [ | |||
| 54 | #include <sys/types.h> | 54 | #include <sys/types.h> |
| 55 | #include <unistd.h> | 55 | #include <unistd.h> |
| 56 | 56 | ||
| 57 | #ifdef __APPLE__ | ||
| 58 | # include <AvailabilityMacros.h> | ||
| 59 | # include <TargetConditionals.h> | ||
| 60 | |||
| 61 | # if (TARGET_OS_IPHONE || TARGET_OS_SIMULATOR) | ||
| 62 | |||
| 63 | /* | 57 | /* |
| 64 | * As of iOS 10.1, getentropy() as a system call is defined but is not | 58 | * Explanation: |
| 65 | * declared in sys/random.h and submitting an App that links to getentropy() | ||
| 66 | * leads to the App store rejecting the App because: | ||
| 67 | * | 59 | * |
| 68 | * > The app references non-public symbols in $appname: _getentropy | 60 | * - iOS <= 10.1 fails because of missing sys/random.h |
| 69 | * | 61 | * |
| 70 | * Disabling the check for getentropy() and thus enabling libressl own | 62 | * - in macOS 10.12 getentropy is not tagged as introduced in |
| 71 | * emulation of that fixes the issue. | 63 | * 10.12 so we cannot use it for target < 10.12 |
| 72 | */ | 64 | */ |
| 73 | # error "As far as we know, getentropy() is not usable on iOS" | 65 | #ifdef __APPLE__ |
| 66 | # include <AvailabilityMacros.h> | ||
| 67 | # include <TargetConditionals.h> | ||
| 74 | 68 | ||
| 69 | # if (TARGET_OS_IPHONE || TARGET_OS_SIMULATOR) | ||
| 70 | # include <sys/random.h> /* Not available as of iOS <= 10.1 */ | ||
| 75 | # else | 71 | # else |
| 76 | 72 | ||
| 77 | /* | 73 | # include <sys/random.h> /* Pre 10.12 systems should die here */ |
| 78 | * Before macOS 10.12 getentropy() was not available. In 10.12 however it | 74 | |
| 79 | * seems to be not marked for retro-compatibility and thus we cannot cross | 75 | /* Based on: https://gitweb.torproject.org/tor.git/commit/?id=16fcbd21 */ |
| 80 | * compile targeting, e.g., 10.12 unless we disable getentropy(). | ||
| 81 | * | ||
| 82 | * To test, | ||
| 83 | * | ||
| 84 | * export CFLAGS="-mmacosx-version-min=10.11" | ||
| 85 | * ./configure | ||
| 86 | * # ensure that getentropy() is not found | ||
| 87 | * | ||
| 88 | * Based on: https://gitweb.torproject.org/tor.git/commit/?id=https://gitweb.torproject.org/tor.git/commit/?id=16fcbd21c963a9a65bf55024680c8323c8b7175d | ||
| 89 | */ | ||
| 90 | # ifndef MAC_OS_X_VERSION_10_12 | 76 | # ifndef MAC_OS_X_VERSION_10_12 |
| 91 | # define MAC_OS_X_VERSION_10_12 101200 | 77 | # define MAC_OS_X_VERSION_10_12 101200 /* Robustness */ |
| 92 | # endif | 78 | # endif |
| 93 | # if defined(MAC_OS_X_VERSION_MIN_REQUIRED) | 79 | # if defined(MAC_OS_X_VERSION_MIN_REQUIRED) |
| 94 | # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 | 80 | # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 |
| 95 | # error "Running on Mac OSX 10.11 or earlier" | 81 | # error "Targeting on Mac OSX 10.11 or earlier" |
| 96 | # endif | 82 | # endif |
| 97 | # endif | 83 | # endif |
| 98 | 84 | ||
| 99 | # endif | 85 | # endif |
| 100 | #endif /* __APPLE__ */ | 86 | #endif /* __APPLE__ */ |
| 101 | ]], [[ | 87 | ]], [[ |
| 102 | extern int getentropy(void *, size_t); | ||
| 103 | char buffer; | 88 | char buffer; |
| 104 | (void)getentropy(&buffer, sizeof (buffer)); | 89 | (void)getentropy(&buffer, sizeof (buffer)); |
| 105 | ]])], | 90 | ]])], |
diff --git a/m4/check-os-options.m4 b/m4/check-os-options.m4 index ed7320a..1a7b940 100644 --- a/m4/check-os-options.m4 +++ b/m4/check-os-options.m4 | |||
| @@ -17,18 +17,43 @@ case $host_os in | |||
| 17 | *darwin*) | 17 | *darwin*) |
| 18 | HOST_OS=darwin | 18 | HOST_OS=darwin |
| 19 | HOST_ABI=macosx | 19 | HOST_ABI=macosx |
| 20 | # | ||
| 21 | # Don't use arc4random on systems before 10.12 because of | ||
| 20 | # weak seed on failure to open /dev/random, based on latest | 22 | # weak seed on failure to open /dev/random, based on latest |
| 21 | # public source: | 23 | # public source: |
| 22 | # http://www.opensource.apple.com/source/Libc/Libc-997.90.3/gen/FreeBSD/arc4random.c | 24 | # http://www.opensource.apple.com/source/Libc/Libc-997.90.3/gen/FreeBSD/arc4random.c |
| 25 | # | ||
| 26 | # We use the presence of getentropy() to detect 10.12. The | ||
| 27 | # following check take into account that: | ||
| 28 | # | ||
| 29 | # - iOS <= 10.1 fails because of missing getentropy and | ||
| 30 | # hence they miss sys/random.h | ||
| 31 | # | ||
| 32 | # - in macOS 10.12 getentropy is not tagged as introduced in | ||
| 33 | # 10.12 so we cannot use it for target < 10.12 | ||
| 34 | # | ||
| 23 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | 35 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ |
| 36 | #include <AvailabilityMacros.h> | ||
| 24 | #include <unistd.h> | 37 | #include <unistd.h> |
| 25 | #include <sys/random.h> | 38 | #include <sys/random.h> /* Systems without getentropy() should die here */ |
| 39 | |||
| 40 | /* Based on: https://gitweb.torproject.org/tor.git/commit/?id=16fcbd21 */ | ||
| 41 | #ifndef MAC_OS_X_VERSION_10_12 | ||
| 42 | # define MAC_OS_X_VERSION_10_12 101200 | ||
| 43 | #endif | ||
| 44 | #if defined(MAC_OS_X_VERSION_MIN_REQUIRED) | ||
| 45 | # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 | ||
| 46 | # error "Running on Mac OSX 10.11 or earlier" | ||
| 47 | # endif | ||
| 48 | #endif | ||
| 26 | ]], [[ | 49 | ]], [[ |
| 27 | char buf[1]; getentropy(buf, 1); | 50 | char buf[1]; getentropy(buf, 1); |
| 28 | ]])], | 51 | ]])], |
| 29 | [ USE_BUILTIN_ARC4RANDOM=no ], | 52 | [ USE_BUILTIN_ARC4RANDOM=no ], |
| 30 | [ USE_BUILTIN_ARC4RANDOM=yes ] | 53 | [ USE_BUILTIN_ARC4RANDOM=yes ] |
| 31 | ) | 54 | ) |
| 55 | AC_MSG_CHECKING([whether to use builtin arc4random]) | ||
| 56 | AC_MSG_RESULT([$USE_BUILTIN_ARC4RANDOM]) | ||
| 32 | # Not available on iOS | 57 | # Not available on iOS |
| 33 | AC_CHECK_HEADER([arpa/telnet.h], [], [BUILD_NC=no]) | 58 | AC_CHECK_HEADER([arpa/telnet.h], [], [BUILD_NC=no]) |
| 34 | ;; | 59 | ;; |
