From 17c026699844e54b9796d3ca6a7585ad895630f0 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 22 Oct 2023 17:26:53 +0000 Subject: [PATCH] Lower android min sdk version to 26, and use libuv's random code. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4569 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- Makefile | 4 ++-- src/android/AndroidManifest.xml | 2 +- src/bcrypt.js.c | 32 +++++--------------------------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index b36057cc..a8026430 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ CFLAGS += \ ANDROID_BUILD_TOOLS := $(ANDROID_SDK)/build-tools/34.0.0 ANDROID_PLATFORM := $(ANDROID_SDK)/platforms/android-33 ANDROID_NDK ?= $(ANDROID_SDK)/ndk/26.0.10792818 -ANDROID_MIN_SDK_VERSION := 28 +ANDROID_MIN_SDK_VERSION := 26 ANDROID_ARMV7A_TARGETS := \ out/androiddebug-armv7a/tildefriends \ @@ -691,7 +691,7 @@ release-apk: out/TildeFriends-arm-release.apk out/TildeFriends-x86-release.apk .PHONY: release-apk releaseapkgo: out/TildeFriends-arm-release.apk - @adb install $< + @adb install -r $< @adb shell am start com.unprompted.tildefriends/.MainActivity .PHONY: releaseapkgo diff --git a/src/android/AndroidManifest.xml b/src/android/AndroidManifest.xml index 39d021cc..bf6279cb 100644 --- a/src/android/AndroidManifest.xml +++ b/src/android/AndroidManifest.xml @@ -3,7 +3,7 @@ package="com.unprompted.tildefriends" android:versionCode="12" android:versionName="0.0.12-wip"> - + diff --git a/src/bcrypt.js.c b/src/bcrypt.js.c index 2e59793a..7a0f3dd8 100644 --- a/src/bcrypt.js.c +++ b/src/bcrypt.js.c @@ -1,23 +1,12 @@ #include "bcrypt.js.h" +#include "task.h" + #include "ow-crypt.h" #include "quickjs.h" -#if defined(_WIN32) -#define WIN32_LEAN_AND_MEAN -#include -extern BOOLEAN NTAPI SystemFunction036(PVOID Buffer, ULONG BufferLength); -#elif __APPLE__ -#include -#if TARGET_OS_IPHONE -#include -#else -#include -#endif -#else -#include -#endif +#include JSValue _crypt_hashpw(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); @@ -49,19 +38,8 @@ JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSVa int length = 0; JS_ToInt32(context, &length, argv[0]); char buffer[16]; -#if defined(_WIN32) - ssize_t bytes = SystemFunction036(buffer, sizeof(buffer)) ? sizeof(buffer) : 0; -#elif defined(__APPLE__) && TARGET_OS_IPHONE - ssize_t bytes = CCRandomGenerateBytes(buffer, sizeof(buffer)) == kCCSuccess ? sizeof(buffer) : 0; -#elif defined(__APPLE__) && !TARGET_OS_IPHONE - ssize_t bytes = 0; - if (getentropy(buffer, sizeof(buffer)) == 0) - { - bytes = sizeof(buffer); - } -#else - ssize_t bytes = getrandom(buffer, sizeof(buffer), 0); -#endif + tf_task_t* task = tf_task_get(context); + size_t bytes = uv_random(tf_task_get_loop(task), &(uv_random_t) { 0 }, buffer, sizeof(buffer), 0, NULL) == 0 ? sizeof(buffer) : 0; char output[7 + 22 + 1]; char* salt = crypt_gensalt_rn("$2b$", length, buffer, bytes, output, sizeof(output)); JSValue result = JS_NewString(context, salt);