Skip to content

Commit

Permalink
Add various stubs needed for secd
Browse files Browse the repository at this point in the history
  • Loading branch information
facekapow committed Sep 21, 2023
1 parent bcb8fcd commit d4fbcb2
Show file tree
Hide file tree
Showing 26 changed files with 286 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ if (COMPONENT_cli OR COMPONENT_dev_gui_common)
add_subdirectory(external/libnetwork)
add_subdirectory(libMobileGestalt)
add_subdirectory(external/MITKerberosShim)
add_subdirectory(MobileKeyBag)
endif()

if (COMPONENT_iokitd)
Expand Down
10 changes: 10 additions & 0 deletions src/MobileKeyBag/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
project(MobileKeyBag)

add_darling_static_library(MobileKeyBag
SOURCES
src/MobileKeyBag.c
)

target_include_directories(MobileKeyBag PUBLIC
include
)
20 changes: 20 additions & 0 deletions src/MobileKeyBag/include/MobileKeyBag/MobileKeyBag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _MOBILE_KEY_BAG_H_
#define _MOBILE_KEY_BAG_H_

#include <CoreFoundation/CoreFoundation.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct __MKBKeyBagHandle* MKBKeyBagHandleRef;

int MKBKeyBagCreateWithData(CFDataRef keybagBlob, MKBKeyBagHandleRef* newHandle);
int MKBKeyBagGetAKSHandle(MKBKeyBagHandleRef keybag, int32_t* handle);
int MKBKeyBagUnlock(MKBKeyBagHandleRef keybag, CFDataRef passcode);

#ifdef __cplusplus
}
#endif

#endif // _MOBILE_KEY_BAG_H_
17 changes: 17 additions & 0 deletions src/MobileKeyBag/src/MobileKeyBag.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <MobileKeyBag/MobileKeyBag.h>
#include <stdio.h>

int MKBKeyBagCreateWithData(CFDataRef keybagBlob, MKBKeyBagHandleRef* newHandle) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return -1;
};

int MKBKeyBagGetAKSHandle(MKBKeyBagHandleRef keybag, int32_t* handle) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return -1;
};

int MKBKeyBagUnlock(MKBKeyBagHandleRef keybag, CFDataRef passcode) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return -1;
};
2 changes: 2 additions & 0 deletions src/frameworks/CloudKit/include/CloudKit/CKContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@

@interface CKContainer : NSObject

+ (instancetype)containerWithIdentifier: (NSString*)identifier;

@end
28 changes: 28 additions & 0 deletions src/frameworks/CloudKit/include/CloudKit/CKContainer_Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of Darling.
*
* Copyright (C) 2023 Darling Developers
*
* Darling is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Darling is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/

#import <CloudKit/CKContainer.h>

typedef void (^CKContainerDeviceIDCompletionHandler)(NSString* deviceID, NSError* error);

@interface CKContainer (Private)

- (void)fetchCurrentDeviceIDWithCompletionHandler: (CKContainerDeviceIDCompletionHandler)completionHandler;

@end
12 changes: 11 additions & 1 deletion src/libacm/acmstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@
ACMContextRef ACMContextCreateWithExternalForm(const void *externalForm, size_t dataLength) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return NULL;
}
}

ACMStatus ACMContextDelete(ACMContextRef context, bool destroyContext) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return -1;
}

ACMStatus ACMContextRemovePassphraseCredentialsByPurposeAndScope(const ACMContextRef context, ACMPassphrasePurpose purpose, ACMScope scope) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return -1;
}
29 changes: 19 additions & 10 deletions src/libaks/include/libaks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <IOKit/IOReturn.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -63,7 +64,18 @@ enum {
// i'm 99.9999999...% sure this is a typo in Security, but whatever
#define kSKSReturnNoPermission kAKSReturnNoPermission

typedef int32_t keyclass_t;
typedef enum _aks_keyclass_enum {
key_class_none,
key_class_ak,
key_class_ck,
key_class_dk,
key_class_aku,
key_class_cku,
key_class_dku,
key_class_akpu, // implied to exist by some Security code (`SecDbBackupmanager.m`)
key_class_f, // ditto (`server.c` for `secd` executable)
key_class_last,
} keyclass_t;

// i know it's a pointer, but it seems to be used opaquely, so not much more information
// oh, it's also a CF type (deduced because it's used with `__bridge_retained` in Objective-C code)
Expand All @@ -81,16 +93,10 @@ kern_return_t aks_load_bag(const void* data, int length, keybag_handle_t* handle
kern_return_t aks_lock_bag(keybag_handle_t handle);

typedef enum _aks_key_type_enum {
key_class_none,
key_type_none, // assuming `0` is reserved as `none`
key_type_sym,
key_class_ak,
key_class_ck,
key_class_dk,
key_class_aku,
key_class_cku,
key_class_dku,
key_class_akpu, // implied to exist by some Security code (`SecDbBackupmanager.m`)
key_class_last,
key_type_asym_ec_p256, // implied to exist by some Security code (`server.c` for `secd` executable)
key_type_last, // assuming same convention as `_aks_keyclass_enum`
} aks_key_type_t;

// 4096-bit = 512-byte; i *think* that's the maximum key length?
Expand All @@ -111,6 +117,7 @@ kern_return_t aks_generation(keybag_handle_t handle, generation_option_t option,

const uint8_t * aks_ref_key_get_blob(aks_ref_key_t refkey, size_t *out_blob_len);
const uint8_t * aks_ref_key_get_external_data(aks_ref_key_t refkey, size_t *out_external_data_len);
const uint8_t * aks_ref_key_get_public_key(aks_ref_key_t refkey, size_t* out_pub_key_len);

int aks_ref_key_create(keybag_handle_t handle, keyclass_t key_class, aks_key_type_t type, const uint8_t *params, size_t params_len, aks_ref_key_t *ot);
int aks_ref_key_create_with_blob(keybag_handle_t keybag, const uint8_t *ref_key_blob, size_t ref_key_blob_len, aks_ref_key_t* handle);
Expand All @@ -125,6 +132,8 @@ kern_return_t aks_unwrap_key(const uint8_t *source, uint32_t textLength, keyclas

int aks_operation_optional_params(const uint8_t * access_groups, size_t access_groups_len, const uint8_t * external_data, size_t external_data_len, const void * acm_handle, int acm_handle_len, void ** out_der, size_t * out_der_len);

bool hwaes_key_available(void);

#ifdef __cplusplus
}
#endif
Expand Down
70 changes: 70 additions & 0 deletions src/libaks/libaks.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,73 @@ const uint8_t * aks_ref_key_get_external_data(aks_ref_key_t refkey, size_t *out_
printf("STUB %s\n", __PRETTY_FUNCTION__);
return NULL;
}

kern_return_t aks_generation(keybag_handle_t handle, generation_option_t option, uint32_t* current) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

kern_return_t aks_get_bag_uuid(keybag_handle_t handle, uuid_t uuid) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

kern_return_t aks_lock_bag(keybag_handle_t handle) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

int aks_operation_optional_params(const uint8_t * access_groups, size_t access_groups_len, const uint8_t * external_data, size_t external_data_len, const void * acm_handle, int acm_handle_len, void ** out_der, size_t * out_der_len) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

int aks_ref_key_create(keybag_handle_t handle, keyclass_t key_class, aks_key_type_t type, const uint8_t *params, size_t params_len, aks_ref_key_t *ot) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

int aks_ref_key_create_with_blob(keybag_handle_t keybag, const uint8_t *ref_key_blob, size_t ref_key_blob_len, aks_ref_key_t* handle) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

int aks_ref_key_encrypt(aks_ref_key_t handle, const uint8_t *der_params, size_t der_params_len, const void *data, size_t data_len, void **out_der, size_t *out_der_len) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

int aks_ref_key_decrypt(aks_ref_key_t handle, const uint8_t *der_params, size_t der_params_len, const void *data, size_t data_len, void **out_der, size_t *out_der_len) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

int aks_ref_key_free(aks_ref_key_t* refkey) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

int aks_ref_key_delete(aks_ref_key_t handle, const uint8_t *der_params, size_t der_params_len) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

const uint8_t * aks_ref_key_get_public_key(aks_ref_key_t refkey, size_t* out_pub_key_len) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return NULL;
}

kern_return_t aks_wrap_key(const uint8_t *source, uint32_t textLength, keyclass_t keyclass, keybag_handle_t keybag, uint8_t *data, int *dest_len, keyclass_t *actual_class) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

kern_return_t aks_unwrap_key(const uint8_t *source, uint32_t textLength, keyclass_t keyclass, keybag_handle_t keybag, uint8_t *data, int *dest_len) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return kAKSReturnError;
}

bool hwaes_key_available(void) {
printf("STUB %s\n", __PRETTY_FUNCTION__);
return false;
}
12 changes: 12 additions & 0 deletions src/private-frameworks/AuthKit/include/AuthKit/AKAccountManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ You should have received a copy of the GNU General Public License
along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/

#import <Foundation/Foundation.h>

#import <Accounts/ACAccount.h>

typedef NS_ENUM(NSUInteger, AKAppleIDSecurityLevel) {
AKAppleIDSecurityLevelHSA2,
};

@interface AKAccountManager : NSObject

- (NSString*)altDSIDForAccount: (ACAccount*)account;
- (ACAccount*)authKitAccountWithAltDSID: (NSString*)altDSID;
- (AKAppleIDSecurityLevel)securityLevelForAccount: (ACAccount*)account;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ You should have received a copy of the GNU General Public License
along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/

#import <Foundation/Foundation.h>

@interface AKAnisetteData : NSObject

@property(readonly) NSString* machineID;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ You should have received a copy of the GNU General Public License
along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/

#import <Foundation/Foundation.h>

#import <AuthKit/AKAnisetteData.h>

@interface AKAnisetteProvisioningController : NSObject

- (AKAnisetteData*)anisetteDataWithError: (NSError**)error;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ You should have received a copy of the GNU General Public License
along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/

#import <Foundation/Foundation.h>

#import <AuthKit/AKDeviceListRequestContext.h>
#import <AuthKit/AKRemoteDevice.h>

@interface AKAppleIDAuthenticationController : NSObject

- (void)fetchDeviceListWithContext: (AKDeviceListRequestContext*)context completion: (void(^)(NSArray<AKRemoteDevice*>*, NSError*))handler;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <Foundation/Foundation.h>

@interface AKDeviceListRequestContext : NSObject

@property(copy) NSArray<NSString*>* services;
@property(copy) NSString* altDSID;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <Foundation/Foundation.h>

@interface AKRemoteDevice : NSObject

@property(readonly) NSString* machineId;
@property(readonly) NSString* serialNumber;

@end
2 changes: 2 additions & 0 deletions src/private-frameworks/AuthKit/include/AuthKit/AuthKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ void* _AKTrafficLogSubsystem(void);
#import <AuthKit/AKAppleIDAuthenticationContext.h>
#import <AuthKit/AKAccountManager.h>
#import <AuthKit/AKAppleIDAuthenticationDaemonInterface.h>
#import <AuthKit/AKDeviceListRequestContext.h>
#import <AuthKit/AKRemoteDevice.h>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import <AuthKit/AuthKit.h>
13 changes: 13 additions & 0 deletions src/private-frameworks/AuthKit/src/AKDeviceListRequestContext.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import <AuthKit/AKDeviceListRequestContext.h>

@implementation AKDeviceListRequestContext

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
return [NSMethodSignature signatureWithObjCTypes: "v@:"];
}

- (void)forwardInvocation:(NSInvocation *)anInvocation {
NSLog(@"Stub called: %@ in %@", NSStringFromSelector([anInvocation selector]), [self class]);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#include <Foundation/Foundation.h>

@class TPPBPeerStableInfo;

extern TPPBPeerStableInfo* const TPPBPeerStableInfo_UserControllableViewStatus_UNKNOWN;

@interface TPPBPeerStableInfo : NSObject

@end
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@

#include <Foundation/Foundation.h>

#import <TrustedPeers/TPPBPeerStableInfo.h>

@class TPSyncingPolicy;

@interface TPPolicy : NSObject

- (TPSyncingPolicy*)syncingPolicyForModel: (NSString*)model syncUserControllableViews: (TPPBPeerStableInfo*)stableInfo error: (NSError**)error;

@end

@interface TPSyncingPolicy : TPPolicy

- (NSString*)mapDictionaryToView: (NSDictionary*)dictionary;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

#include <Foundation/Foundation.h>

#import <TrustedPeers/TPPolicy.h>

@interface TPPolicyDocument : NSObject

+ (instancetype)policyDocWithHash: (NSString*)hash data: (NSData*)data;

- (TPPolicy*)policyWithSecrets: (NSDictionary*)secrets decrypter: (id)decrypter error: (NSError**)error;

@end
2 changes: 2 additions & 0 deletions src/private-frameworks/TrustedPeers/src/TPPBPeerStableInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#import <TrustedPeers/TPPBPeerStableInfo.h>

TPPBPeerStableInfo* const TPPBPeerStableInfo_UserControllableViewStatus_UNKNOWN = nil;

@implementation TPPBPeerStableInfo

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
Expand Down
Loading

0 comments on commit d4fbcb2

Please sign in to comment.