Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
wifipw_test: wifid's way of keeping a network's password, outside wifid
vcvkke4eb32256266
diff --git a/userland/build.sh b/userland/build.shindex fbfe17a..c0d28cd 100755--- a/userland/build.sh+++ b/userland/build.sh@@ -117,6 +117,10 @@ if [ -d $IOS/rootfs/usr/lib ]; then$DYN -framework CoreFoundation -framework Security -o obj/keychain_test src/keychain_test.c &&{ ${LDID:-ldid} -Ssrc/keychain_test.entitlements obj/keychain_test 2>/dev/null ||echo "build.sh: no ldid: keychain_test is unsigned, and the keychain will refuse it (-34018)"; }+ # (and wifid's way of keeping a network's password, by wifid's name: src/wifipw_test.c)+ $DYN -framework CoreFoundation -framework Security -o obj/wifipw_test src/wifipw_test.c &&+ { ${LDID:-ldid} -Ssrc/wifipw_test.entitlements obj/wifipw_test 2>/dev/null ||+ echo "build.sh: no ldid: wifipw_test is unsigned, and the keychain will refuse it (-34018)"; }# our library for inside stock iOS programs (the jobs in INJECT are started with it)$DYN -dynamiclib -install_name /redwood/lib/libredwood.dylib -framework CoreFoundation -framework IOKit -lobjc \-o obj/libredwood.dylib src/inject.c@@ -176,6 +180,7 @@ for scale, name in ((1, "icon.png"), (2, "[email protected]"), (3, "[email protected]")):[ -f obj/cpu_test ] && cp obj/cpu_test root/bin/ # (a prebuilt/ from before this program has none)[ -f obj/net_test ] && cp obj/net_test root/bin/[ -f obj/keychain_test ] && cp obj/keychain_test root/bin/+ [ -f obj/wifipw_test ] && cp obj/wifipw_test root/bin/for f in $EXTRA; do cp "$f" root/bin/; donemkdir -p root/libcp obj/libredwood.dylib obj/libredwood-sb.dylib root/lib/diff --git a/userland/rc.jobs.wifipw b/userland/rc.jobs.wifipwnew file mode 100644index 0000000..0806a6c--- /dev/null+++ b/userland/rc.jobs.wifipw@@ -0,0 +1,8 @@+# Commands run by the launchd job com.redwood.demo (see com.redwood.demo.plist).+# wifid's way of keeping a network's password (RC_JOBS=rc.jobs.wifipw, with WIFID=1 and+# OSLOG="com.apple.wifid com.apple.securityd" for their side): once the system has settled, a made-up+# network's password into the keychain the way wifid puts it there, back, and away again; then+# keychain_test's own item for comparison.+/redwood/bin/net_test wait 40+/redwood/bin/wifipw_test+/redwood/bin/keychain_testdiff --git a/userland/src/wifipw_test.c b/userland/src/wifipw_test.cnew file mode 100644index 0000000..6948b04--- /dev/null+++ b/userland/src/wifipw_test.c@@ -0,0 +1,92 @@+/*+ * wifipw_test: what wifid does with a network's password when Settings joins it, done here the same+ * way: MobileWiFi's WiFiSecuritySetPassword() into the keychain, WiFiSecurityCopyPassword() back+ * (what Auto-Join asks before it joins a known network on its own), WiFiSecurityRemovePassword()+ * (what "Forget This Network" does). The network is a made-up one ("hackios-wifipw-test") with a+ * made-up password, neither printed in full. Signed with wifipw_test.entitlements: wifid's name+ * and its right to the system keychain, as the keychain answers a program by those.+ * MobileWiFi's own os_log lines ("__WiFiSecuritySetPassword:[...] Error result -25291") say the+ * keychain's answer; they are printed on the console as well (OS_ACTIVITY_DT_MODE).+ */+#include <CoreFoundation/CoreFoundation.h>+#include <Security/Security.h>+#include <dlfcn.h>+#include <stdio.h>+#include <stdlib.h>+#include <unistd.h>++#define SSID CFSTR("hackios-wifipw-test")+#define SECRET CFSTR("not-a-real-password")++static CFStringRef (*copy_password)(CFStringRef ssid);++static void+read_back(const char *when)+{+ CFStringRef pw = copy_password(SSID);++ printf("wifipw_test: %s: WiFiSecurityCopyPassword: %s\n", when,+ pw == NULL ? "nothing" : CFEqual(pw, SECRET) ? "THE SAME PASSWORD" : "another password");+ if (pw != NULL)+ CFRelease(pw);+}++int+main(int argc, char **argv)+{+ void *mw;+ Boolean (*set_password)(CFStringRef ssid, CFStringRef password);+ Boolean (*remove_password)(CFStringRef ssid);+ CFMutableDictionaryRef q;+ CFTypeRef attrs = NULL;+ OSStatus status;++ (void)argc;+ if (getenv("OS_ACTIVITY_DT_MODE") == NULL) {+ /* os_log decides where it prints when the process starts */+ setenv("OS_ACTIVITY_DT_MODE", "YES", 1);+ execv(argv[0], argv);+ }+ setvbuf(stdout, NULL, _IOLBF, 0);+ mw = dlopen("/System/Library/PrivateFrameworks/MobileWiFi.framework/MobileWiFi", RTLD_NOW);+ set_password = mw ? dlsym(mw, "WiFiSecuritySetPassword") : NULL;+ copy_password = mw ? dlsym(mw, "WiFiSecurityCopyPassword") : NULL;+ remove_password = mw ? dlsym(mw, "WiFiSecurityRemovePassword") : NULL;+ if (set_password == NULL || copy_password == NULL || remove_password == NULL) {+ printf("wifipw_test: MobileWiFi or its functions not found: %s\n", dlerror());+ return 1;+ }+ read_back("before");+ printf("wifipw_test: WiFiSecuritySetPassword: %s\n", set_password(SSID, SECRET) ? "yes" : "NO");+ read_back("after");++ /* the item itself, as the keychain has it: wifid's service name, the network's name for account */+ q = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);+ CFDictionarySetValue(q, kSecClass, kSecClassGenericPassword);+ CFDictionarySetValue(q, kSecAttrService, CFSTR("AirPort"));+ CFDictionarySetValue(q, kSecAttrAccount, SSID);+ CFDictionarySetValue(q, kSecAttrSynchronizable, kSecAttrSynchronizableAny);+ CFDictionarySetValue(q, kSecReturnAttributes, kCFBooleanTrue);+ status = SecItemCopyMatching(q, &attrs);+ printf("wifipw_test: the item (service AirPort): %d\n", (int)status);+ if (attrs != NULL && CFGetTypeID(attrs) == CFDictionaryGetTypeID()) {+ CFTypeRef group = CFDictionaryGetValue(attrs, kSecAttrAccessGroup);+ CFTypeRef cls = CFDictionaryGetValue(attrs, kSecAttrAccessible);+ CFTypeRef sync = CFDictionaryGetValue(attrs, kSecAttrSynchronizable);+ char g[64] = "?", c[16] = "?";++ if (group != NULL && CFGetTypeID(group) == CFStringGetTypeID())+ CFStringGetCString(group, g, sizeof(g), kCFStringEncodingUTF8);+ if (cls != NULL && CFGetTypeID(cls) == CFStringGetTypeID())+ CFStringGetCString(cls, c, sizeof(c), kCFStringEncodingUTF8);+ printf("wifipw_test: its access group %s, protection class %s, synchronizable %s\n", g, c,+ sync == NULL ? "?" : CFEqual(sync, kCFBooleanTrue) ? "yes" : "no");+ }+ if (attrs != NULL)+ CFRelease(attrs);+ CFRelease(q);++ printf("wifipw_test: WiFiSecurityRemovePassword: %s\n", remove_password(SSID) ? "yes" : "NO");+ read_back("after removing");+ return 0;+}diff --git a/userland/src/wifipw_test.entitlements b/userland/src/wifipw_test.entitlementsnew file mode 100644index 0000000..87f5a01--- /dev/null+++ b/userland/src/wifipw_test.entitlements@@ -0,0 +1,10 @@+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>application-identifier</key>+ <string>com.apple.wifid</string>+ <key>com.apple.private.system-keychain</key>+ <true/>+</dict>+</plist>