Skip to content

Instantly share code, notes, and snippets.

@knightsc
Created June 11, 2019 21:08
Show Gist options
  • Save knightsc/6924056923d50613e8ae94dad5e5ac2f to your computer and use it in GitHub Desktop.
Save knightsc/6924056923d50613e8ae94dad5e5ac2f to your computer and use it in GitHub Desktop.
Quick XPC client for the teslad daemon which exposes CCDServiceInterface protocol
//
// main.m
// TeslaClient
//
// Created by Scott Knight on 6/11/19.
// Copyright © 2019 Scott Knight. All rights reserved.
//
#import <Foundation/Foundation.h>
/*
Needs the following entitlements
<?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>com.apple.managedconfiguration.teslad-access</key>
<true/>
</dict>
</plist>
In order to grant yourself this entitlement you need to do the following:
1. Disable SIP
2. Disable AMFID (sudo nvram boot-args="amfi_get_out_of_my_way=0x1")
*/
@protocol CCDServiceInterface
-(void)provisionallyEnrollWithNonce:(NSString *)nonce completionBlock:(void (^)(bool finished, NSDictionary *dict, NSError *error))completionBlock;
-(void)fetchConfigurationWithCompletionBlock:(void (^)(bool finished, NSDictionary *dict, NSError *error))completionBlock;
-(void)unenrollWithCompletionBlock:(void (^)(bool finished, NSDictionary *dict, NSError *error))completionBlock;
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:@"com.apple.managedconfiguration.teslad"\
options:0x1000];
NSXPCInterface *interface = [NSXPCInterface interfaceWithProtocol:@protocol(CCDServiceInterface)];
[connection setRemoteObjectInterface:interface];
[connection setInvalidationHandler:^{
NSLog(@"TeslaClient invalidation handler!");
}];
[connection setInterruptionHandler:^{
NSLog(@"TeslaClient interruption handler!");
}];
[connection resume];
[[connection remoteObjectProxy] provisionallyEnrollWithNonce:@"nonce" completionBlock:^(bool finished, NSDictionary *dict, NSError *error) {
NSLog(@"provisionallyEnrollWithNonce:completionBlock:");
}];
// [[connection remoteObjectProxy] fetchConfigurationWithCompletionBlock:^(bool finished, NSDictionary *dict, NSError *error) {
// NSLog(@"fetchConfigurationWithCompletionBlock:");
// }];
//
// [[connection remoteObjectProxy] unenrollWithCompletionBlock:^(bool finished, NSDictionary *dict, NSError *error) {
// NSLog(@"unenrollWithCompletionBlock:");
// }];
[[NSRunLoop currentRunLoop] run];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment