SQLite3MultipleCiphers icon indicating copy to clipboard operation
SQLite3MultipleCiphers copied to clipboard

`syscall` is deprecated on `iOS`, `tvOS`, `watchOS`

Open 05nelsonm opened this issue 5 months ago • 6 comments
trafficstars

sqlite3mc.c:280110:7: error: 'syscall' is deprecated: first deprecated in iOS 10.0 - syscall(2) is unsupported; please switch to a supported interface. For SYS_kdebug_trace use kdebug_signpost(). [-Werror,-Wdeprecated-declarations]
  if (syscall(SYS_getentropy, buf, n) == 0)
      ^
/Applications/Xcode_16.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk/usr/include/unistd.h:740:6: note: 'syscall' has been explicitly marked deprecated here
int      syscall(int, ...);
         ^
1 error generated.

Maybe use instead CCRandomGenerateBytes when #ifdef __APPLE__?

05nelsonm avatar Jun 15 '25 12:06 05nelsonm

#if defined(__APPLE__)
#include <CommonCrypto/CommonRandom.h>
#endif

static size_t entropy(void* buf, size_t n)
{
#if defined(__APPLE__)
  if (CCRandomGenerateBytes(buf, n) == kCCSuccess)
    return n;
#elif defined(__linux__) && defined(SYS_getrandom)
  if (syscall(SYS_getrandom, buf, n, 0) == n)
    return n;
#elif defined(SYS_getentropy)
  if (syscall(SYS_getentropy, buf, n) == 0)
    return n;
#endif
  return read_urandom(buf, n);
}

Would also mean you can remove the link on security framework

05nelsonm avatar Jun 15 '25 13:06 05nelsonm

Checks regarding availability of cryptographically secure random bytes on Apple platforms has been improved already in commits https://github.com/utelle/SQLite3MultipleCiphers/commit/8d0f02065fad3dacdfbb0bcbe59bd344d5d038bf and https://github.com/utelle/SQLite3MultipleCiphers/commit/0e4224de5339e1c0abe15b1ae89cae45ec8dee27. That is, the next release of SQLite3 Multiple Ciphers should compile without issues again on Apple platforms.

Maybe use instead CCRandomGenerateBytes when #ifdef APPLE?

Currently the function SecRandomCopyBytes() is used on Apple platforms where available - yes, it requires to link against the Security Framework, however, it is clearly documented from which platform versions onwards the function is available.

I will check whether CCRandomGenerateBytes() could be a preferrable alternative. In the header CommonRandom.h one finds the line API_AVAILABLE(macos(10.10), ios(8.0)); Other platforms like tvOS or watchOS are not mentioned. Therefore it is unclear whether it is guaranteed that this function is really available on all Apple platforms.

utelle avatar Jun 15 '25 19:06 utelle

Yes, CCRandomGenerateBytes is available on those platforms. I am using that now for all apple targets in KotlinCrypto/random

Also, using my code above to patch the latest version and it compiles correctly with all tests passing. Rust getrandom also uses that API for those devices.

05nelsonm avatar Jun 15 '25 19:06 05nelsonm

Yes, CCRandomGenerateBytes is available on those platforms. I am using that now for all apple targets in KotlinCrypto/random

In the meantime I found this interesting blog post about Randomness on Apple Platforms. Accoding to this article at least on macOS the function SecRandomCopyBytes() uses - indirectly - CCRandomGenerateBytes() under the hood.

So, it really seems to be the simplest approach to use CCRandomGenerateBytes() directly, as it comes with the additional advantage to avoid the necessity to link against the Security Framework.

Also, using my code above to patch the latest version and it compiles correctly with all tests passing. Rust getrandom also uses that API for those devices.

Ok, I will adjust the SQLite3 Multiple Ciphers code accordingly.

utelle avatar Jun 15 '25 19:06 utelle

I modified the code accordingly (see commit 36cfaa4f0ac52e97984d44807fc7ec8c6df38088), and the next release will include this change. However, it may take a few days until the next release will be done.

utelle avatar Jun 15 '25 21:06 utelle

I modified the code accordingly (see commit 36cfaa4), and the next release will include this change. However, it may take a few days until the next release will be done.

Dope. I appreciate ya.

05nelsonm avatar Jun 15 '25 22:06 05nelsonm

Release 2.2.0 fixes the issue. Closing...

utelle avatar Jul 04 '25 18:07 utelle

@05nelsonm This should have been done conditionally. Otherwise wxsqlite3 is broken now: https://github.com/utelle/wxsqlite3/issues/127

barracuda156 avatar Jul 17 '25 18:07 barracuda156