mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Compare commits
370
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26882d4ed4 | ||
|
|
1b926c85f5 | ||
|
|
c7c90d4d1d | ||
|
|
8ffb4956de | ||
|
|
e1c565f6ce | ||
|
|
5a2bd7421a | ||
|
|
07b044dd8f | ||
|
|
cd9495214d | ||
|
|
be3fb5caf2 | ||
|
|
3b500aeaa3 | ||
|
|
cc1e43c115 | ||
|
|
07dfc86c47 | ||
|
|
22e130d10b | ||
|
|
75dfdd8279 | ||
|
|
27448add37 | ||
|
|
3b78c78702 | ||
|
|
a8ec752c51 | ||
|
|
464142c73d | ||
|
|
baa26a1b19 | ||
|
|
513158dfcc | ||
|
|
901683d837 | ||
|
|
10d24078cc | ||
|
|
9944f000f8 | ||
|
|
bf96a6e066 | ||
|
|
8fb9c83adf | ||
|
|
d662b67a58 | ||
|
|
0b682d3349 | ||
|
|
9561d522e3 | ||
|
|
f60b60b08f | ||
|
|
a85db747f1 | ||
|
|
9cc9f51d7c | ||
|
|
bb9ee3c59b | ||
|
|
4cb4ab8954 | ||
|
|
ab82c70aef | ||
|
|
eb9f4c303a | ||
|
|
e3c4a702f4 | ||
|
|
039a46c96a | ||
|
|
f711abe9de | ||
|
|
dfecd4d2fa | ||
|
|
fddbadb114 | ||
|
|
bfdce8d232 | ||
|
|
3111483cb2 | ||
|
|
f5282705b4 | ||
|
|
4c9397d752 | ||
|
|
43184ea0bf | ||
|
|
866bb8245f | ||
|
|
65f473b237 | ||
|
|
0c8b7f1d25 | ||
|
|
06520272ee | ||
|
|
602ac871b8 | ||
|
|
1b5e938423 | ||
|
|
d21a303b2e | ||
|
|
2e048a8601 | ||
|
|
da1748f7bd | ||
|
|
54bbaee7f5 | ||
|
|
8bba4d21fc | ||
|
|
6283992215 | ||
|
|
dfff98d19e | ||
|
|
0ca9d34f42 | ||
|
|
5f47ce3dea | ||
|
|
470e3734b9 | ||
|
|
397467e6d7 | ||
|
|
3695ae6059 | ||
|
|
544df06b72 | ||
|
|
239693a91b | ||
|
|
4022e128d3 | ||
|
|
6bdaeab2c6 | ||
|
|
82718ca77f | ||
|
|
84c442c3eb | ||
|
|
848eb7955e | ||
|
|
d7cead40be | ||
|
|
eac1a41dba | ||
|
|
4bde9854f7 | ||
|
|
0909f0db81 | ||
|
|
cdd373b800 | ||
|
|
66589042db | ||
|
|
6b715b7c37 | ||
|
|
0a5add74f8 | ||
|
|
02d0d749a0 | ||
|
|
65eb63f1d7 | ||
|
|
d4d4c68ad2 | ||
|
|
1c32cc7fcb | ||
|
|
79589c3e2b | ||
|
|
d39fc1d75e | ||
|
|
a38e8c4607 | ||
|
|
d5b0804b4a | ||
|
|
c3c1b1af99 | ||
|
|
4aff5912a5 | ||
|
|
3d0e7a26f1 | ||
|
|
891afd44c7 | ||
|
|
489ae19e74 | ||
|
|
0e162c98be | ||
|
|
cf8e5163b6 | ||
|
|
c8f6eca09a | ||
|
|
dbfb300931 | ||
|
|
eeab95936a | ||
|
|
04dbde7b8d | ||
|
|
c1e7c09886 | ||
|
|
c15b9da2a7 | ||
|
|
80264da368 | ||
|
|
a5725cf443 | ||
|
|
22bc73be59 | ||
|
|
989589524b | ||
|
|
dcf59b1f8a | ||
|
|
a64af3517c | ||
|
|
cfd963002f | ||
|
|
7233bb93e7 | ||
|
|
f2fc729b69 | ||
|
|
7c7e924ed4 | ||
|
|
640ba1b737 | ||
|
|
215b7db5a1 | ||
|
|
4fec1b7301 | ||
|
|
7c84c537a5 | ||
|
|
a3a0ec7e2f | ||
|
|
7ea72a2af4 | ||
|
|
752849d727 | ||
|
|
360575c611 | ||
|
|
bfccdabfa2 | ||
|
|
4f47fb02db | ||
|
|
7962e95fd9 | ||
|
|
2629a05e48 | ||
|
|
a56ca505ea | ||
|
|
17d78dfc0f | ||
|
|
23a24f17ec | ||
|
|
1ac42dcd5b | ||
|
|
8199aee292 | ||
|
|
b3e5f7b000 | ||
|
|
dd12653c29 | ||
|
|
c7f1a75f95 | ||
|
|
7c5adb11ac | ||
|
|
cae2068a44 | ||
|
|
d95a0d5c92 | ||
|
|
1ff3ed7fad | ||
|
|
b7793249e0 | ||
|
|
e26f1dab23 | ||
|
|
8a9963bf04 | ||
|
|
0b14472ede | ||
|
|
d0e054fc54 | ||
|
|
df718b0c4c | ||
|
|
1690ce6cbc | ||
|
|
a746675f53 | ||
|
|
13cadf0118 | ||
|
|
6c3ce5cb97 | ||
|
|
372d75cc09 | ||
|
|
6468ea2bb5 | ||
|
|
c49df15f13 | ||
|
|
0090aa227b | ||
|
|
e9ab9d09a5 | ||
|
|
9c13919fd8 | ||
|
|
6d7753ea66 | ||
|
|
b9fa2f43b7 | ||
|
|
2c1125a86a | ||
|
|
d37d85b812 | ||
|
|
388915c8d0 | ||
|
|
e33a10638d | ||
|
|
d1d71dc127 | ||
|
|
4ed56d5961 | ||
|
|
1ab5ad82b5 | ||
|
|
d01298c9ce | ||
|
|
a242035c74 | ||
|
|
8f19f6a8cc | ||
|
|
9568732f78 | ||
|
|
f49295b054 | ||
|
|
aff67ceda8 | ||
|
|
c8d5d18ce0 | ||
|
|
f1167b3649 | ||
|
|
3077864a3e | ||
|
|
2db0d8cb37 | ||
|
|
0d16b459a5 | ||
|
|
4c3e202d2e | ||
|
|
96d162c7e5 | ||
|
|
01b48d44e8 | ||
|
|
c39f7df513 | ||
|
|
ec15362770 | ||
|
|
962878b843 | ||
|
|
9d8909c38d | ||
|
|
99a00a2c17 | ||
|
|
1d2b74e39d | ||
|
|
b097e64b56 | ||
|
|
28a245dd53 | ||
|
|
4eabf002c5 | ||
|
|
ae4af4d61f | ||
|
|
dd9c7d0e1c | ||
|
|
7ab8823757 | ||
|
|
dd287029db | ||
|
|
6ec6007091 | ||
|
|
985be854c4 | ||
|
|
8129cc1c03 | ||
|
|
dddba708d2 | ||
|
|
2596a54935 | ||
|
|
794a90a5e2 | ||
|
|
9e7c3463e0 | ||
|
|
ed40ef1267 | ||
|
|
b9a4917f81 | ||
|
|
1081dcdda1 | ||
|
|
3a497ddcbd | ||
|
|
8f6c7ccdeb | ||
|
|
0e9d96a303 | ||
|
|
531b767c0b | ||
|
|
0cfedd4516 | ||
|
|
8f01babdd3 | ||
|
|
5dab9c40ab | ||
|
|
f2dd8fe371 | ||
|
|
5d0e5dd407 | ||
|
|
39fb433131 | ||
|
|
e68a2621ed | ||
|
|
cb6545d601 | ||
|
|
6dbbf08654 | ||
|
|
d5222353e6 | ||
|
|
2657a41d55 | ||
|
|
08d3ff747d | ||
|
|
fedb22e224 | ||
|
|
8293c3c6ae | ||
|
|
181f813b01 | ||
|
|
a10a974609 | ||
|
|
f8572f79cb | ||
|
|
2b54753090 | ||
|
|
2db2fffab9 | ||
|
|
035bfc4919 | ||
|
|
48fc202f36 | ||
|
|
28ff3069ff | ||
|
|
795ce1278d | ||
|
|
6ac853271d | ||
|
|
7e5e91888f | ||
|
|
b0d29ae798 | ||
|
|
09bbf9fdc6 | ||
|
|
f2bd7ea2b2 | ||
|
|
35deefdc0c | ||
|
|
3e53979236 | ||
|
|
f8971098be | ||
|
|
efd1840f35 | ||
|
|
17dbdf98e1 | ||
|
|
79f110a17b | ||
|
|
5ab0baf84c | ||
|
|
578dac0ad7 | ||
|
|
920b5bac5e | ||
|
|
9ae7224a47 | ||
|
|
685be61bc3 | ||
|
|
9be76d3d5a | ||
|
|
fc1960966a | ||
|
|
7248e40fda | ||
|
|
b8d37346a6 | ||
|
|
2769221117 | ||
|
|
6317a6c74f | ||
|
|
f785c7177c | ||
|
|
cd78595c63 | ||
|
|
4fd2a7b15f | ||
|
|
186bbb83d5 | ||
|
|
0cc8a2f16a | ||
|
|
0eb1caeec5 | ||
|
|
7138663f86 | ||
|
|
b767285be0 | ||
|
|
5886c2b9b9 | ||
|
|
f9b534a6b6 | ||
|
|
5a586d393a | ||
|
|
b3cc7aed8a | ||
|
|
deb8ea8cc1 | ||
|
|
4a3cc18dc3 | ||
|
|
75404f6d83 | ||
|
|
954ed60ecb | ||
|
|
ecb5257b2b | ||
|
|
fb18c1e542 | ||
|
|
99f5573619 | ||
|
|
1edfcaba71 | ||
|
|
fc3221c5d2 | ||
|
|
26db6982b3 | ||
|
|
f550b92f72 | ||
|
|
5f5fe1b5f9 | ||
|
|
6027f2852a | ||
|
|
60c2f16c9d | ||
|
|
5ae7fa7212 | ||
|
|
614b2cc1f3 | ||
|
|
6500bf8c2f | ||
|
|
3e060d4a7b | ||
|
|
5286371cb7 | ||
|
|
2a802447a3 | ||
|
|
c40b42deb1 | ||
|
|
5d9f41142b | ||
|
|
d540c6a1b9 | ||
|
|
e63bcbc047 | ||
|
|
4f65e14ee8 | ||
|
|
fdca1ce6cf | ||
|
|
c3255ed3a7 | ||
|
|
9b6346516e | ||
|
|
e1f13ebcad | ||
|
|
420be06ba0 | ||
|
|
c7beba948d | ||
|
|
639b6df47b | ||
|
|
c9a9cba167 | ||
|
|
9f01fd303c | ||
|
|
1ff1577108 | ||
|
|
74f2ea540e | ||
|
|
2652be32f7 | ||
|
|
5118f2b27f | ||
|
|
b97b60b611 | ||
|
|
3c793482c8 | ||
|
|
89b4bcde61 | ||
|
|
3690dd028a | ||
|
|
52e2ef88eb | ||
|
|
d81633a7d3 | ||
|
|
a9e20c7d0a | ||
|
|
03a9f57704 | ||
|
|
2f8df626d7 | ||
|
|
f5cb6988ed | ||
|
|
2bfab80998 | ||
|
|
4fa2a37798 | ||
|
|
888a7f48a6 | ||
|
|
82726c4386 | ||
|
|
a5b23cdbee | ||
|
|
b19120f5cd | ||
|
|
4b0a037685 | ||
|
|
8dadd0003e | ||
|
|
457319f217 | ||
|
|
0480b9bb25 | ||
|
|
4390eb9eb2 | ||
|
|
f5c8314c88 | ||
|
|
1b209e6726 | ||
|
|
a4373e4e0f | ||
|
|
d430c33bf4 | ||
|
|
7ef4635d8c | ||
|
|
deb4be7a1b | ||
|
|
5f1bc6b612 | ||
|
|
1cde8110df | ||
|
|
1926b7bfa6 | ||
|
|
f80907fa2c | ||
|
|
091a86f672 | ||
|
|
208b0dc49a | ||
|
|
5acf3989d2 | ||
|
|
5529a3610d | ||
|
|
920ff7f83f | ||
|
|
5ff1488f0c | ||
|
|
c0c1c51d8d | ||
|
|
5139179487 | ||
|
|
f50cbce0e8 | ||
|
|
14f1d3520a | ||
|
|
9c4729ed4a | ||
|
|
f04a61e159 | ||
|
|
80d8758fc2 | ||
|
|
081301d590 | ||
|
|
397370297b | ||
|
|
b30dcd979f | ||
|
|
ee123edd74 | ||
|
|
984625cc7e | ||
|
|
7b6e7957c6 | ||
|
|
2815514c23 | ||
|
|
49eaa4c5cc | ||
|
|
09bcee7280 | ||
|
|
49ea08b284 | ||
|
|
f9dc70ade2 | ||
|
|
6fb3eee91b | ||
|
|
19be83b15f | ||
|
|
d90529ccaa | ||
|
|
623b7b6bda | ||
|
|
65bcb3815e | ||
|
|
d5cd95e0ef | ||
|
|
b9150d2938 | ||
|
|
1006326157 | ||
|
|
68856e074b | ||
|
|
a86bdb2fa8 | ||
|
|
92e00baafb | ||
|
|
98ea3e3d57 | ||
|
|
c094a38231 | ||
|
|
6df898f9b7 | ||
|
|
7f51a4e344 | ||
|
|
8ad1f57672 | ||
|
|
8b88183c7d | ||
|
|
d036d3e3ae | ||
|
|
8b13eb5dcf | ||
|
|
ba5b7341fa | ||
|
|
9453761aef |
No files matched your search
@@ -16,4 +16,4 @@ assignees: ''
|
||||
|
||||
## Version
|
||||
|
||||
[please specify versions of Sparkle this is applicable to; note new pull requests must be developed and landed in 2.x development branch first and the 1.x (master) branch is feature-frozen]
|
||||
[please specify versions of Sparkle this is applicable to; note new pull requests must be developed and landed in 2.x development branch first]
|
||||
@@ -5,7 +5,7 @@ Fixes # (issue)
|
||||
## Checklist:
|
||||
|
||||
- [ ] My change is being tested and reviewed against the Sparkle 2.x branch. New changes must be developed on the 2.x development branch first.
|
||||
- [ ] My change is being backported to master branch (Sparkle 1.x). Please create a separate pull request for 1.x, should it be backported. Note 1.x is feature frozen and is only taking bug fixes, localization updates, and critical OS adoption enhancements.
|
||||
- [ ] My change is being backported to master branch (Sparkle 1.x), if deemed necessary. Please create a separate pull request for 1.x, should it be backported.
|
||||
- [ ] I have reviewed and commented my code, particularly in hard-to-understand areas.
|
||||
|
||||
## Type of change
|
||||
|
||||
@@ -10,58 +10,38 @@ jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
xcode: ['xcode12.5', 'xcode13']
|
||||
include:
|
||||
- xcode: 'xcode12.5'
|
||||
xcode-path: '/Applications/Xcode_12.5.app/Contents/Developer'
|
||||
upload-dist: true
|
||||
- xcode: 'xcode13'
|
||||
xcode-path: '/Applications/Xcode_13.0.app/Contents/Developer'
|
||||
upload-dist: false # In Beta, so no upload
|
||||
|
||||
xcode: ['/Applications/Xcode_12.2.app/Contents/Developer', '/Applications/Xcode_11.7.app/Contents/Developer']
|
||||
name: Build and Test Sparkle
|
||||
runs-on: macos-11
|
||||
runs-on: macos-10.15
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
- name: Build Unit Tests
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
DEVELOPER_DIR: ${{ matrix.xcode }}
|
||||
run: |
|
||||
xcodebuild build-for-testing -project Sparkle.xcodeproj -scheme Distribution -enableCodeCoverage YES -derivedDataPath build
|
||||
- name: Run Unit Tests
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
DEVELOPER_DIR: ${{ matrix.xcode }}
|
||||
run: |
|
||||
xcodebuild test-without-building -project Sparkle.xcodeproj -scheme Distribution -enableCodeCoverage YES -derivedDataPath build
|
||||
- name: Build UI Tests
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
DEVELOPER_DIR: ${{ matrix.xcode }}
|
||||
run: |
|
||||
xcodebuild build-for-testing -project Sparkle.xcodeproj -scheme UITests -configuration Debug -derivedDataPath build
|
||||
- name: Run UI Tests
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
DEVELOPER_DIR: ${{ matrix.xcode }}
|
||||
run: |
|
||||
xcodebuild test-without-building -project Sparkle.xcodeproj -scheme UITests -configuration Debug -derivedDataPath build
|
||||
- name: Build Release Distribution
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
run: |
|
||||
xcodebuild build -project Sparkle.xcodeproj -scheme Distribution -configuration Release -derivedDataPath build
|
||||
- name: Archive Test Results
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: build-logs
|
||||
path: build/Logs
|
||||
- name: Upload Distribution
|
||||
if: ${{ success() && matrix.upload-dist }}
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Sparkle-distribution-${{ matrix.xcode }}.tar.xz
|
||||
path: build/Build/Products/Release/sparkle-dist.tar.xz
|
||||
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// AgentConnection.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/17/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol AgentConnectionDelegate <NSObject>
|
||||
|
||||
- (void)agentConnectionDidInitiate;
|
||||
- (void)agentConnectionDidInvalidate;
|
||||
|
||||
@end
|
||||
|
||||
@protocol SPUInstallerAgentProtocol;
|
||||
|
||||
@interface AgentConnection : NSObject
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)bundleIdentifier delegate:(id<AgentConnectionDelegate>)delegate;
|
||||
|
||||
- (void)startListener;
|
||||
- (void)invalidate;
|
||||
|
||||
@property (nonatomic, readonly, nullable) id<SPUInstallerAgentProtocol> agent;
|
||||
@property (nonatomic, readonly) BOOL connected;
|
||||
@property (nonatomic, nullable) NSError *invalidationError;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,116 +0,0 @@
|
||||
//
|
||||
// AgentConnection.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/17/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AgentConnection.h"
|
||||
#import "SPUMessageTypes.h"
|
||||
#import "SPUInstallerAgentProtocol.h"
|
||||
#import "SUInstallerAgentInitiationProtocol.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface AgentConnection () <NSXPCListenerDelegate, SUInstallerAgentInitiationProtocol>
|
||||
|
||||
@property (nonatomic) NSXPCListener *xpcListener;
|
||||
@property (nonatomic, nullable) NSXPCConnection *activeConnection;
|
||||
@property (nonatomic, nullable) id<SPUInstallerAgentProtocol> agent;
|
||||
@property (nonatomic, weak) id<AgentConnectionDelegate> delegate;
|
||||
@property (nonatomic) BOOL connected;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AgentConnection
|
||||
|
||||
@synthesize xpcListener = _xpcListener;
|
||||
@synthesize activeConnection = _activeConnection;
|
||||
@synthesize agent = _agent;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize connected = _connected;
|
||||
@synthesize invalidationError = _invalidationError;
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)bundleIdentifier delegate:(id<AgentConnectionDelegate>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
// Agents should always be the one that connect to daemons due to how mach bootstraps work
|
||||
// For this reason, we are the ones that are creating a listener, not the agent
|
||||
_xpcListener = [[NSXPCListener alloc] initWithMachServiceName:SPUProgressAgentServiceNameForBundleIdentifier(bundleIdentifier)];
|
||||
_xpcListener.delegate = self;
|
||||
_delegate = delegate;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startListener
|
||||
{
|
||||
[self.xpcListener resume];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
self.delegate = nil;
|
||||
|
||||
[self.activeConnection invalidate];
|
||||
self.activeConnection = nil;
|
||||
|
||||
[self.xpcListener invalidate];
|
||||
self.xpcListener = nil;
|
||||
}
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
|
||||
{
|
||||
if (self.activeConnection != nil) {
|
||||
[newConnection invalidate];
|
||||
return NO;
|
||||
}
|
||||
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerAgentInitiationProtocol)];
|
||||
newConnection.exportedObject = self;
|
||||
|
||||
newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SPUInstallerAgentProtocol)];
|
||||
|
||||
self.activeConnection = newConnection;
|
||||
|
||||
__weak AgentConnection *weakSelf = self;
|
||||
newConnection.interruptionHandler = ^{
|
||||
[weakSelf.activeConnection invalidate];
|
||||
};
|
||||
|
||||
newConnection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.delegate agentConnectionDidInvalidate];
|
||||
});
|
||||
};
|
||||
|
||||
[newConnection resume];
|
||||
|
||||
self.agent = newConnection.remoteObjectProxy;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)connectionDidInitiateWithReply:(void (^)(void))acknowledgement
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.connected = YES;
|
||||
|
||||
[self.delegate agentConnectionDidInitiate];
|
||||
self.delegate = nil;
|
||||
});
|
||||
|
||||
acknowledgement();
|
||||
}
|
||||
|
||||
- (void)connectionWillInvalidateWithError:(NSError *)error
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.invalidationError = error;
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,24 +0,0 @@
|
||||
//
|
||||
// AppInstaller.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/7/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUUnarchiverProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface AppInstaller : NSObject
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName;
|
||||
|
||||
- (void)start;
|
||||
|
||||
- (void)cleanupAndExitWithStatus:(int)status error:(NSError * _Nullable)error __attribute__((noreturn));
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,633 +0,0 @@
|
||||
//
|
||||
// AppInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/7/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppInstaller.h"
|
||||
#import "TerminationListener.h"
|
||||
#import "SUInstaller.h"
|
||||
#import "SUUpdateValidator.h"
|
||||
#import "SULog.h"
|
||||
#import "SULog+NSError.h"
|
||||
#import "SUHost.h"
|
||||
#import "SULocalizations.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
#import "SPUMessageTypes.h"
|
||||
#import "SPUSecureCoding.h"
|
||||
#import "SPUInstallationInputData.h"
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUFileManager.h"
|
||||
#import "SPUInstallationInfo.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SUInstallerCommunicationProtocol.h"
|
||||
#import "AgentConnection.h"
|
||||
#import "SPUInstallerAgentProtocol.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SPULocalCacheDirectory.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
#define FIRST_UPDATER_MESSAGE_TIMEOUT 7ull
|
||||
#define RETRIEVE_PROCESS_IDENTIFIER_TIMEOUT 5ull
|
||||
|
||||
/*!
|
||||
* Show display progress UI after a delay from starting the final part of the installation.
|
||||
* This should be long enough so that we don't show progress for very fast installations, but
|
||||
* short enough so that we don't leave the user wondering why nothing is happening.
|
||||
*/
|
||||
static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
@interface AppInstaller () <NSXPCListenerDelegate, SUInstallerCommunicationProtocol, AgentConnectionDelegate>
|
||||
|
||||
@property (nonatomic) NSXPCListener* xpcListener;
|
||||
@property (nonatomic) NSXPCConnection *activeConnection;
|
||||
@property (nonatomic) id<SUInstallerCommunicationProtocol> communicator;
|
||||
@property (nonatomic) AgentConnection *agentConnection;
|
||||
@property (nonatomic) BOOL receivedUpdaterPong;
|
||||
|
||||
@property (nonatomic, strong) TerminationListener *terminationListener;
|
||||
|
||||
@property (nonatomic) SUUpdateValidator *updateValidator;
|
||||
|
||||
@property (nonatomic, readonly, copy) NSString *hostBundleIdentifier;
|
||||
@property (nonatomic, readonly) NSString *homeDirectory;
|
||||
@property (nonatomic, readonly) NSString *userName;
|
||||
@property (nonatomic) SUHost *host;
|
||||
@property (nonatomic, copy) NSString *updateDirectoryPath;
|
||||
@property (nonatomic, copy) NSString *downloadName;
|
||||
@property (nonatomic, copy) NSString *decryptionPassword;
|
||||
@property (nonatomic, strong) SUSignatures *signatures;
|
||||
@property (nonatomic, copy) NSString *relaunchPath;
|
||||
@property (nonatomic, copy) NSString *installationType;
|
||||
@property (nonatomic, assign) BOOL shouldRelaunch;
|
||||
@property (nonatomic, assign) BOOL shouldShowUI;
|
||||
|
||||
@property (nonatomic) id<SUInstallerProtocol> installer;
|
||||
@property (nonatomic) BOOL willCompleteInstallation;
|
||||
@property (nonatomic) BOOL receivedInstallationData;
|
||||
@property (nonatomic) BOOL finishedValidation;
|
||||
@property (nonatomic) BOOL agentInitiatedConnection;
|
||||
|
||||
@property (nonatomic) dispatch_queue_t installerQueue;
|
||||
@property (nonatomic) BOOL performedStage1Installation;
|
||||
@property (nonatomic) BOOL performedStage2Installation;
|
||||
@property (nonatomic) BOOL performedStage3Installation;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AppInstaller
|
||||
|
||||
@synthesize xpcListener = _xpcListener;
|
||||
@synthesize activeConnection = _activeConnection;
|
||||
@synthesize communicator = _communicator;
|
||||
@synthesize agentConnection = _agentConnection;
|
||||
@synthesize receivedUpdaterPong = _receivedUpdaterPong;
|
||||
@synthesize hostBundleIdentifier = _hostBundleIdentifier;
|
||||
@synthesize homeDirectory = _homeDirectory;
|
||||
@synthesize userName = _userName;
|
||||
@synthesize terminationListener = _terminationListener;
|
||||
@synthesize updateValidator = _updateValidator;
|
||||
@synthesize host = _host;
|
||||
@synthesize updateDirectoryPath = _updateDirectoryPath;
|
||||
@synthesize downloadName = _downloadName;
|
||||
@synthesize decryptionPassword = _decryptionPassword;
|
||||
@synthesize signatures = _signatures;
|
||||
@synthesize relaunchPath = _relaunchPath;
|
||||
@synthesize installationType = _installationType;
|
||||
@synthesize shouldRelaunch = _shouldRelaunch;
|
||||
@synthesize shouldShowUI = _shouldShowUI;
|
||||
@synthesize installer = _installer;
|
||||
@synthesize willCompleteInstallation = _willCompleteInstallation;
|
||||
@synthesize receivedInstallationData = _receivedInstallationData;
|
||||
@synthesize installerQueue = _installerQueue;
|
||||
@synthesize performedStage1Installation = _performedStage1Installation;
|
||||
@synthesize performedStage2Installation = _performedStage2Installation;
|
||||
@synthesize performedStage3Installation = _performedStage3Installation;
|
||||
@synthesize finishedValidation = _finishedValidation;
|
||||
@synthesize agentInitiatedConnection = _agentInitiatedConnection;
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
_hostBundleIdentifier = [hostBundleIdentifier copy];
|
||||
|
||||
_homeDirectory = [homeDirectory copy];
|
||||
_userName = [userName copy];
|
||||
|
||||
_xpcListener = [[NSXPCListener alloc] initWithMachServiceName:SPUInstallerServiceNameForBundleIdentifier(hostBundleIdentifier)];
|
||||
_xpcListener.delegate = self;
|
||||
|
||||
_agentConnection = [[AgentConnection alloc] initWithHostBundleIdentifier:hostBundleIdentifier delegate:self];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
|
||||
{
|
||||
if (self.activeConnection != nil) {
|
||||
SULog(SULogLevelDefault, @"Rejecting multiple connections...");
|
||||
[newConnection invalidate];
|
||||
return NO;
|
||||
}
|
||||
|
||||
self.activeConnection = newConnection;
|
||||
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
newConnection.exportedObject = self;
|
||||
|
||||
newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
|
||||
__weak AppInstaller *weakSelf = self;
|
||||
newConnection.interruptionHandler = ^{
|
||||
[weakSelf.activeConnection invalidate];
|
||||
};
|
||||
|
||||
newConnection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
AppInstaller *strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
if (strongSelf.activeConnection != nil && !strongSelf.willCompleteInstallation) {
|
||||
[strongSelf cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Invalidation on remote port being called, and installation is not close enough to completion!" }]];
|
||||
}
|
||||
strongSelf.communicator = nil;
|
||||
strongSelf.activeConnection = nil;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
[newConnection resume];
|
||||
|
||||
self.communicator = newConnection.remoteObjectProxy;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
[self.xpcListener resume];
|
||||
[self.agentConnection startListener];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(FIRST_UPDATER_MESSAGE_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (!self.receivedInstallationData) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Timeout: installation data was never received" }]];
|
||||
}
|
||||
|
||||
if (!self.agentConnection.connected) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Timeout: agent connection was never initiated" }]];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)extractAndInstallUpdate
|
||||
{
|
||||
[self.communicator handleMessageWithIdentifier:SPUExtractionStarted data:[NSData data]];
|
||||
|
||||
NSString *archivePath = [self.updateDirectoryPath stringByAppendingPathComponent:self.downloadName];
|
||||
id<SUUnarchiverProtocol> unarchiver = [SUUnarchiver unarchiverForPath:archivePath updatingHostBundlePath:self.host.bundlePath decryptionPassword:self.decryptionPassword expectingInstallationType:self.installationType];
|
||||
|
||||
NSError *unarchiverError = nil;
|
||||
BOOL success = NO;
|
||||
if (!unarchiver) {
|
||||
unarchiverError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"No valid unarchiver was found for %@", archivePath] }];
|
||||
|
||||
success = NO;
|
||||
} else {
|
||||
self.updateValidator = [[SUUpdateValidator alloc] initWithDownloadPath:archivePath signatures:self.signatures host:self.host];
|
||||
|
||||
// Delta & package updates will require validation before extraction
|
||||
// Normal application updates are a bit more lenient allowing developers to change one of apple dev ID or DSA keys
|
||||
BOOL needsPrevalidation = [[unarchiver class] mustValidateBeforeExtraction] || ![self.installationType isEqualToString:SPUInstallationTypeApplication];
|
||||
|
||||
if (needsPrevalidation) {
|
||||
success = [self.updateValidator validateDownloadPathWithError:&unarchiverError];
|
||||
} else {
|
||||
success = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
[self unarchiverDidFailWithError:unarchiverError];
|
||||
} else {
|
||||
[unarchiver
|
||||
unarchiveWithCompletionBlock:^(NSError * _Nullable error) {
|
||||
if (error != nil) {
|
||||
[self unarchiverDidFailWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to unarchive %@", archivePath], NSUnderlyingErrorKey: (NSError * _Nonnull)error }]];
|
||||
} else {
|
||||
[self.communicator handleMessageWithIdentifier:SPUValidationStarted data:[NSData data]];
|
||||
|
||||
NSError *validationError = nil;
|
||||
BOOL validationSuccess = [self.updateValidator validateWithUpdateDirectory:self.updateDirectoryPath error:&validationError];
|
||||
|
||||
if (!validationSuccess) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Update validation was a failure", NSUnderlyingErrorKey: validationError }]];
|
||||
} else {
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationStartedStage1 data:[NSData data]];
|
||||
|
||||
self.finishedValidation = YES;
|
||||
if (self.agentInitiatedConnection) {
|
||||
[self retrieveProcessIdentifierAndStartInstallation];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
progressBlock:^(double progress) {
|
||||
if (sizeof(progress) == sizeof(uint64_t)) {
|
||||
uint64_t progressValue = CFSwapInt64HostToLittle(*(uint64_t *)&progress);
|
||||
NSData *data = [NSData dataWithBytes:&progressValue length:sizeof(progressValue)];
|
||||
|
||||
[self.communicator handleMessageWithIdentifier:SPUExtractedArchiveWithProgress data:data];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)clearUpdateDirectory
|
||||
{
|
||||
if (self.updateDirectoryPath != nil) {
|
||||
NSError *theError = nil;
|
||||
if (![[[SUFileManager alloc] init] removeItemAtURL:[NSURL fileURLWithPath:self.updateDirectoryPath] error:&theError]) {
|
||||
SULog(SULogLevelError, @"Couldn't remove update folder: %@.", theError);
|
||||
}
|
||||
self.updateDirectoryPath = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFailWithError:(NSError *)error
|
||||
{
|
||||
SULog(SULogLevelError, @"Failed to unarchive file");
|
||||
SULogError(error);
|
||||
|
||||
// No longer need update validator until next possible extraction (eg: if initial delta update fails)
|
||||
self.updateValidator = nil;
|
||||
|
||||
// Client could try update again with different inputs
|
||||
// Eg: one common case is if a delta update fails, client may want to fall back to regular update
|
||||
// We really only need to set updateDirectoryPath to nil since that's the field we check if we've received installation data,
|
||||
// but may as well set other fields to nil too
|
||||
[self clearUpdateDirectory];
|
||||
self.downloadName = nil;
|
||||
self.decryptionPassword = nil;
|
||||
self.signatures = nil;
|
||||
self.relaunchPath = nil;
|
||||
self.host = nil;
|
||||
|
||||
NSData *archivedError = SPUArchiveRootObjectSecurely(error);
|
||||
[self.communicator handleMessageWithIdentifier:SPUArchiveExtractionFailed data:archivedError != nil ? archivedError : [NSData data]];
|
||||
}
|
||||
|
||||
- (void)agentConnectionDidInitiate
|
||||
{
|
||||
self.agentInitiatedConnection = YES;
|
||||
if (self.finishedValidation) {
|
||||
[self retrieveProcessIdentifierAndStartInstallation];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)agentConnectionDidInvalidate
|
||||
{
|
||||
if (!self.finishedValidation || !self.agentInitiatedConnection) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey: @"Error: Agent connection invalidated before installation began" }];
|
||||
|
||||
NSError *agentError = self.agentConnection.invalidationError;
|
||||
if (agentError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = agentError;
|
||||
}
|
||||
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:userInfo]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)retrieveProcessIdentifierAndStartInstallation
|
||||
{
|
||||
// We use the relaunch path for the bundle to listen for termination instead of the host path
|
||||
// For a plug-in this makes a big difference; we want to wait until the app hosting the plug-in terminates
|
||||
// Otherwise for an app, the relaunch path and host path should be identical
|
||||
|
||||
[self.agentConnection.agent registerApplicationBundlePath:self.relaunchPath reply:^(NSNumber * _Nullable processIdentifier) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.terminationListener = [[TerminationListener alloc] initWithProcessIdentifier:processIdentifier];
|
||||
[self startInstallation];
|
||||
});
|
||||
}];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(RETRIEVE_PROCESS_IDENTIFIER_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (self.terminationListener == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Timeout error: failed to retreive process identifier from agent" }]];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
{
|
||||
if (identifier == SPUInstallationData && self.updateDirectoryPath == nil) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Mark that we have received the installation data
|
||||
// Do not rely on eg: self.ipdateDirectoryPath != nil because we may set it to nil again if an early stage fails (i.e, archive extraction)
|
||||
self.receivedInstallationData = YES;
|
||||
|
||||
SPUInstallationInputData *installationData = (SPUInstallationInputData *)SPUUnarchiveRootObjectSecurely(data, [SPUInstallationInputData class]);
|
||||
if (installationData == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to unarchive input installation data" }]];
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *installationType = installationData.installationType;
|
||||
if (!SPUValidInstallationType(installationType)) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Received invalid installation type: %@", installationType] }]];
|
||||
return;
|
||||
}
|
||||
|
||||
NSBundle *hostBundle = [NSBundle bundleWithPath:installationData.hostBundlePath];
|
||||
|
||||
NSString *bundleIdentifier = hostBundle.bundleIdentifier;
|
||||
if (bundleIdentifier == nil || ![bundleIdentifier isEqualToString:self.hostBundleIdentifier]) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Failed to match host bundle identifiers %@ and %@", self.hostBundleIdentifier, bundleIdentifier] }]];
|
||||
return;
|
||||
}
|
||||
|
||||
// This will be important later
|
||||
if (installationData.relaunchPath == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to obtain relaunch path from installation data" }]];
|
||||
return;
|
||||
}
|
||||
|
||||
// This installation path is specific to sparkle and the bundle identifier
|
||||
NSString *rootCacheInstallationPath = [[SPULocalCacheDirectory cachePathForBundleIdentifier:bundleIdentifier] stringByAppendingPathComponent:@"Installation"];
|
||||
|
||||
[SPULocalCacheDirectory removeOldItemsInDirectory:rootCacheInstallationPath];
|
||||
|
||||
NSString *cacheInstallationPath = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:rootCacheInstallationPath];
|
||||
if (cacheInstallationPath == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Failed to create installation cache directory in %@", rootCacheInstallationPath] }]];
|
||||
return;
|
||||
}
|
||||
|
||||
// Move the download archive to somewhere where probably only we will be touching it
|
||||
// This prevents eg: if a bug exists in the updater that removes files we are trying to install
|
||||
// When this tool is ran as root, we are moving it into a directory that only root will have access to
|
||||
NSURL *downloadURL = [[NSURL fileURLWithPath:installationData.updateDirectoryPath] URLByAppendingPathComponent:installationData.downloadName];
|
||||
|
||||
NSURL *downloadDestinationURL = [[NSURL fileURLWithPath:cacheInstallationPath] URLByAppendingPathComponent:installationData.downloadName];
|
||||
|
||||
NSError *moveError = nil;
|
||||
if (![[[SUFileManager alloc] init] moveItemAtURL:downloadURL toURL:downloadDestinationURL error:&moveError]) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to move download archive to new location", NSUnderlyingErrorKey: moveError }]];
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the downloaded archive we moved over is a regular file and not a symbolic link placed by an attacker
|
||||
NSError *attributesError = nil;
|
||||
NSString *downloadDestinationPath = downloadDestinationURL.path;
|
||||
if (downloadDestinationPath == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Failed to retrieve download archive path from %@", downloadDestinationURL] }]];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
NSDictionary<NSString *, id> *archiveAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:downloadDestinationPath error:&attributesError];
|
||||
|
||||
if (archiveAttributes == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Failed to retrieve download archive attributes from %@", downloadDestinationPath] }]];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (![(NSString *)archiveAttributes[NSFileType] isEqualToString:NSFileTypeRegular]) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Received bad archive file type: %@", archiveAttributes[NSFileType]] }]];
|
||||
return;
|
||||
}
|
||||
|
||||
// Carry these properities separately rather than using the SUInstallationInputData object
|
||||
// Some of our properties may slightly differ than our input and we don't want to make the mistake of using one of those
|
||||
self.installationType = installationType;
|
||||
self.relaunchPath = installationData.relaunchPath;
|
||||
self.downloadName = installationData.downloadName;
|
||||
self.signatures = installationData.signatures;
|
||||
self.updateDirectoryPath = cacheInstallationPath;
|
||||
self.host = [[SUHost alloc] initWithBundle:hostBundle];
|
||||
|
||||
[self extractAndInstallUpdate];
|
||||
});
|
||||
} else if (identifier == SPUSentUpdateAppcastItemData) {
|
||||
SUAppcastItem *updateItem = (SUAppcastItem *)SPUUnarchiveRootObjectSecurely(data, [SUAppcastItem class]);
|
||||
if (updateItem != nil) {
|
||||
SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem canSilentlyInstall:[self.installer canInstallSilently]];
|
||||
|
||||
NSData *archivedData = SPUArchiveRootObjectSecurely(installationInfo);
|
||||
if (archivedData != nil) {
|
||||
[self.agentConnection.agent registerInstallationInfoData:archivedData];
|
||||
}
|
||||
}
|
||||
} else if (identifier == SPUResumeInstallationToStage2 && data.length == sizeof(uint8_t) * 2) {
|
||||
// Because anyone can ask us to resume the installation, it may be wise to think about backwards compatibility here if IPC changes
|
||||
uint8_t relaunch = *((const uint8_t *)data.bytes);
|
||||
uint8_t showsUI = *((const uint8_t *)data.bytes + 1);
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// This flag has an impact on interactive type installations and showing UI progress during non-interactive installations
|
||||
self.shouldShowUI = (BOOL)showsUI;
|
||||
// Don't test if the application was alive initially, leave that to the progress agent if we decide to relaunch
|
||||
self.shouldRelaunch = (BOOL)relaunch;
|
||||
|
||||
if (self.performedStage1Installation) {
|
||||
// Resume the installation if we aren't done with stage 2 yet, and remind the client we are prepared to relaunch
|
||||
dispatch_async(self.installerQueue, ^{
|
||||
[self performStage2InstallationIfNeeded];
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (identifier == SPUCancelInstallation) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:0 error:nil];
|
||||
});
|
||||
} else if (identifier == SPUUpdaterAlivePong) {
|
||||
self.receivedUpdaterPong = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startInstallation
|
||||
{
|
||||
self.willCompleteInstallation = YES;
|
||||
|
||||
self.installerQueue = dispatch_queue_create("org.sparkle-project.sparkle.installer", DISPATCH_QUEUE_SERIAL);
|
||||
|
||||
dispatch_async(self.installerQueue, ^{
|
||||
NSError *installerError = nil;
|
||||
id <SUInstallerProtocol> installer = [SUInstaller installerForHost:self.host expectedInstallationType:self.installationType updateDirectory:self.updateDirectoryPath homeDirectory:self.homeDirectory userName:self.userName error:&installerError];
|
||||
|
||||
if (installer == nil) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to create installer instance", NSUnderlyingErrorKey: installerError }]];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
NSError *firstStageError = nil;
|
||||
if (![installer performInitialInstallation:&firstStageError]) {
|
||||
self.installer = nil;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to start installer", NSUnderlyingErrorKey: firstStageError }]];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t canPerformSilentInstall = (uint8_t)[installer canInstallSilently];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.installer = installer;
|
||||
|
||||
uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated;
|
||||
|
||||
uint8_t sendInformation[] = {canPerformSilentInstall, targetTerminated};
|
||||
|
||||
NSData *sendData = [NSData dataWithBytes:sendInformation length:sizeof(sendInformation)];
|
||||
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage1 data:sendData];
|
||||
|
||||
self.performedStage1Installation = YES;
|
||||
|
||||
// Stage 2 can still be run before we finish installation
|
||||
// if the updater requests for it before the app is terminated
|
||||
[self finishInstallationAfterHostTermination];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
- (void)performStage2InstallationIfNeeded
|
||||
{
|
||||
if (self.performedStage2Installation) {
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL performedSecondStage = self.shouldShowUI || [self.installer canInstallSilently];
|
||||
if (performedSecondStage) {
|
||||
self.performedStage2Installation = YES;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated;
|
||||
|
||||
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage2 data:sendData];
|
||||
|
||||
// Don't check if the target is already terminated, leave that to the progress agent
|
||||
// We could be slightly off if there were multiple instances running
|
||||
[self.agentConnection.agent sendTerminationSignal];
|
||||
});
|
||||
} else {
|
||||
self.installer = nil;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to resume installer on stage 2 because installation cannot be installed silently" }]];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)finishInstallationAfterHostTermination
|
||||
{
|
||||
[self.terminationListener startListeningWithCompletion:^(BOOL success) {
|
||||
if (!success) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to listen for application termination" }]];
|
||||
return;
|
||||
}
|
||||
|
||||
// Show our installer progress UI tool if only after a certain amount of time passes,
|
||||
// and if our installer is silent (i.e, doesn't show progress on its own)
|
||||
__block BOOL shouldShowUIProgress = YES;
|
||||
if (self.shouldShowUI && [self.installer canInstallSilently]) {
|
||||
// Ask the updater if it is still alive
|
||||
// If they are, we will receive a pong response back
|
||||
// Reset if we received a pong just to be on the safe side
|
||||
self.receivedUpdaterPong = NO;
|
||||
[self.communicator handleMessageWithIdentifier:SPUUpdaterAlivePing data:[NSData data]];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUDisplayProgressTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
// Make sure we're still eligible for showing the installer progress
|
||||
// Also if the updater process is still alive, showing the progress should not be our duty
|
||||
// if the communicator object is nil, the updater definitely isn't alive. However, if it is not nil,
|
||||
// this does not necessarily mean the updater is alive, so we should also check if we got a recent response back from the updater
|
||||
if (shouldShowUIProgress && (!self.receivedUpdaterPong || self.communicator == nil)) {
|
||||
[self.agentConnection.agent showProgress];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dispatch_async(self.installerQueue, ^{
|
||||
[self performStage2InstallationIfNeeded];
|
||||
|
||||
if (!self.performedStage2Installation) {
|
||||
// We failed and we're going to exit shortly
|
||||
return;
|
||||
}
|
||||
|
||||
NSError *thirdStageError = nil;
|
||||
if (![self.installer performFinalInstallationProgressBlock:nil error:&thirdStageError]) {
|
||||
[self.installer performCleanup];
|
||||
self.installer = nil;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to finalize installation", NSUnderlyingErrorKey: thirdStageError }]];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
self.performedStage3Installation = YES;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Make sure to stop our displayed progress before we move onto cleanup & relaunch
|
||||
// This will also stop the agent from broadcasting the status info service, which we want to do before
|
||||
// we relaunch the app because the relaunched app could check the service upon launch..
|
||||
[self.agentConnection.agent stopProgress];
|
||||
shouldShowUIProgress = NO;
|
||||
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage3 data:[NSData data]];
|
||||
|
||||
if (self.shouldRelaunch) {
|
||||
// This will also signal to the agent that it will terminate soon
|
||||
[self.agentConnection.agent relaunchApplication];
|
||||
}
|
||||
|
||||
[self.installer performCleanup];
|
||||
|
||||
[self cleanupAndExitWithStatus:EXIT_SUCCESS error:nil];
|
||||
});
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)cleanupAndExitWithStatus:(int)status error:(NSError * _Nullable)error __attribute__((noreturn))
|
||||
{
|
||||
if (error != nil) {
|
||||
SULogError(error);
|
||||
|
||||
NSData *errorData = SPUArchiveRootObjectSecurely((NSError * _Nonnull)error);
|
||||
if (errorData != nil) {
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallerError data:errorData];
|
||||
}
|
||||
}
|
||||
|
||||
// It's nice to tell the other end we're invalidating
|
||||
|
||||
[self.activeConnection invalidate];
|
||||
self.activeConnection = nil;
|
||||
|
||||
[self.xpcListener invalidate];
|
||||
self.xpcListener = nil;
|
||||
|
||||
[self.agentConnection invalidate];
|
||||
self.agentConnection = nil;
|
||||
|
||||
[self clearUpdateDirectory];
|
||||
|
||||
exit(status);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,26 +0,0 @@
|
||||
//
|
||||
// SPUInstallationInfo.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SUAppcastItem;
|
||||
|
||||
@interface SPUInstallationInfo : NSObject <NSSecureCoding>
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentyInstall;
|
||||
|
||||
@property (nonatomic, readonly) SUAppcastItem *appcastItem;
|
||||
@property (nonatomic, readonly) BOOL canSilentlyInstall;
|
||||
|
||||
@property (nonatomic) BOOL systemDomain;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// SPUInstallationInfo.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SPUInstallationInfo.h"
|
||||
#import "SUAppcastItem.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
static NSString *SUAppcastItemKey = @"SUAppcastItem";
|
||||
static NSString *SUCanSilentlyInstallKey = @"SUCanSilentlyInstall";
|
||||
static NSString *SUSystemDomainKey = @"SUSystemDomain";
|
||||
|
||||
@implementation SPUInstallationInfo
|
||||
|
||||
@synthesize appcastItem = _appcastItem;
|
||||
@synthesize canSilentlyInstall = _canSilentlyInstall;
|
||||
@synthesize systemDomain = _systemDomain;
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_appcastItem = appcastItem;
|
||||
_canSilentlyInstall = canSilentlyInstall;
|
||||
_systemDomain = systemDomain;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall
|
||||
{
|
||||
return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:NO];
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)decoder
|
||||
{
|
||||
SUAppcastItem *appcastItem = [decoder decodeObjectOfClass:[SUAppcastItem class] forKey:SUAppcastItemKey];
|
||||
if (appcastItem == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
BOOL canSilentlyInstall = [decoder decodeBoolForKey:SUCanSilentlyInstallKey];
|
||||
BOOL systemDomain = [decoder decodeBoolForKey:SUSystemDomainKey];
|
||||
return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:systemDomain];
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeObject:self.appcastItem forKey:SUAppcastItemKey];
|
||||
[coder encodeBool:self.canSilentlyInstall forKey:SUCanSilentlyInstallKey];
|
||||
[coder encodeBool:self.systemDomain forKey:SUSystemDomainKey];
|
||||
}
|
||||
|
||||
+ (BOOL)supportsSecureCoding
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// SPUInstallationInputData.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/24/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class SUSignatures;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SPUInstallationInputData : NSObject <NSSecureCoding>
|
||||
|
||||
/*
|
||||
* relaunchPath - path to application bundle to relaunch and listen for termination
|
||||
* hostBundlePath - path to host bundle to update & replace
|
||||
* updateDirectoryPath - path to update directory (i.e, temporary directory containing the new update archive)
|
||||
* downloadName - name of update archive in update directory
|
||||
* signatures - signatures for the update that came from the appcast item
|
||||
* decryptionPassword - optional decryption password for dmg archives
|
||||
*/
|
||||
- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadName:(NSString *)downloadName installationType:(NSString *)installationType signatures:(SUSignatures * _Nullable)signatures decryptionPassword:(nullable NSString *)decryptionPassword;
|
||||
|
||||
@property (nonatomic, copy, readonly) NSString *relaunchPath;
|
||||
@property (nonatomic, copy, readonly) NSString *hostBundlePath;
|
||||
@property (nonatomic, copy, readonly) NSString *updateDirectoryPath;
|
||||
@property (nonatomic, copy, readonly) NSString *downloadName;
|
||||
@property (nonatomic, copy, readonly) NSString *installationType;
|
||||
@property (nonatomic, readonly, nullable) SUSignatures *signatures; // nullable because although not using signatures is deprecated, it's still supported
|
||||
@property (nonatomic, copy, readonly, nullable) NSString *decryptionPassword;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,106 +0,0 @@
|
||||
//
|
||||
// SPUInstallationInputData.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/24/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SPUInstallationInputData.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SUSignatures.h"
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
static NSString *SURelaunchPathKey = @"SURelaunchPath";
|
||||
static NSString *SUHostBundlePathKey = @"SUHostBundlePath";
|
||||
static NSString *SUUpdateDirectoryPathKey = @"SUUpdateDirectoryPath";
|
||||
static NSString *SUDownloadNameKey = @"SUDownloadName";
|
||||
static NSString *SUSignaturesKey = @"SUSignatures";
|
||||
static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword";
|
||||
static NSString *SUInstallationTypeKey = @"SUInstallationType";
|
||||
|
||||
@implementation SPUInstallationInputData
|
||||
|
||||
@synthesize relaunchPath = _relaunchPath;
|
||||
@synthesize hostBundlePath = _hostBundlePath;
|
||||
@synthesize updateDirectoryPath = _updateDirectoryPath;
|
||||
@synthesize downloadName = _downloadName;
|
||||
@synthesize signatures = _signatures;
|
||||
@synthesize decryptionPassword = _decryptionPassword;
|
||||
@synthesize installationType = _installationType;
|
||||
|
||||
- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadName:(NSString *)downloadName installationType:(NSString *)installationType signatures:(SUSignatures * _Nullable)signatures decryptionPassword:(nullable NSString *)decryptionPassword
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_relaunchPath = [relaunchPath copy];
|
||||
_hostBundlePath = [hostBundlePath copy];
|
||||
_updateDirectoryPath = [updateDirectoryPath copy];
|
||||
_downloadName = [downloadName copy];
|
||||
|
||||
_installationType = [installationType copy];
|
||||
assert(SPUValidInstallationType(_installationType));
|
||||
|
||||
_signatures = signatures;
|
||||
_decryptionPassword = [decryptionPassword copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)decoder
|
||||
{
|
||||
NSString *relaunchPath = [decoder decodeObjectOfClass:[NSString class] forKey:SURelaunchPathKey];
|
||||
if (relaunchPath == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *hostBundlePath = [decoder decodeObjectOfClass:[NSString class] forKey:SUHostBundlePathKey];
|
||||
if (hostBundlePath == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *updateDirectoryPath = [decoder decodeObjectOfClass:[NSString class] forKey:SUUpdateDirectoryPathKey];
|
||||
if (updateDirectoryPath == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *downloadName = [decoder decodeObjectOfClass:[NSString class] forKey:SUDownloadNameKey];
|
||||
if (downloadName == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *installationType = [decoder decodeObjectOfClass:[NSString class] forKey:SUInstallationTypeKey];
|
||||
if (!SPUValidInstallationType(installationType)) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
SUSignatures *signatures = [decoder decodeObjectOfClass:[SUSignatures class] forKey:SUSignaturesKey];
|
||||
if (signatures == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *decryptionPassword = [decoder decodeObjectOfClass:[NSString class] forKey:SUDecryptionPasswordKey];
|
||||
|
||||
return [self initWithRelaunchPath:relaunchPath hostBundlePath:hostBundlePath updateDirectoryPath:updateDirectoryPath downloadName:downloadName installationType:installationType signatures:signatures decryptionPassword:decryptionPassword];
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeObject:self.relaunchPath forKey:SURelaunchPathKey];
|
||||
[coder encodeObject:self.hostBundlePath forKey:SUHostBundlePathKey];
|
||||
[coder encodeObject:self.updateDirectoryPath forKey:SUUpdateDirectoryPathKey];
|
||||
[coder encodeObject:self.installationType forKey:SUInstallationTypeKey];
|
||||
[coder encodeObject:self.downloadName forKey:SUDownloadNameKey];
|
||||
[coder encodeObject:self.signatures forKey:SUSignaturesKey];
|
||||
if (self.decryptionPassword != nil) {
|
||||
[coder encodeObject:self.decryptionPassword forKey:SUDecryptionPasswordKey];
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)supportsSecureCoding
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// SPUMessageTypes.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/11/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Order matters; higher stages have higher values.
|
||||
typedef NS_ENUM(int32_t, SPUInstallerMessageType)
|
||||
{
|
||||
SPUInstallerNotStarted = 0,
|
||||
SPUExtractionStarted = 1,
|
||||
SPUExtractedArchiveWithProgress = 2,
|
||||
SPUArchiveExtractionFailed = 3,
|
||||
SPUValidationStarted = 4,
|
||||
SPUInstallationStartedStage1 = 5,
|
||||
SPUInstallationFinishedStage1 = 6,
|
||||
SPUInstallationFinishedStage2 = 7,
|
||||
SPUInstallationFinishedStage3 = 8,
|
||||
SPUUpdaterAlivePing = 9,
|
||||
SPUInstallerError = 10
|
||||
};
|
||||
|
||||
typedef NS_ENUM(int32_t, SPUUpdaterMessageType)
|
||||
{
|
||||
SPUInstallationData = 0,
|
||||
SPUSentUpdateAppcastItemData = 1,
|
||||
SPUResumeInstallationToStage2 = 2,
|
||||
SPUUpdaterAlivePong = 3,
|
||||
SPUCancelInstallation = 4
|
||||
};
|
||||
|
||||
BOOL SPUInstallerMessageTypeIsLegal(SPUInstallerMessageType oldMessageType, SPUInstallerMessageType newMessageType);
|
||||
|
||||
// Used by framework to communicate to installer (Autoupdate)
|
||||
NSString *SPUInstallerServiceNameForBundleIdentifier(NSString *bundleIdentifier);
|
||||
|
||||
// Used by framework to communicate to progress agent tool (Updater)
|
||||
NSString *SPUStatusInfoServiceNameForBundleIdentifier(NSString *bundleIdentifier);
|
||||
|
||||
// Used by progress agent tool to communicate to installer (Autoupdate)
|
||||
NSString *SPUProgressAgentServiceNameForBundleIdentifier(NSString *bundleIdentifier);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,85 +0,0 @@
|
||||
//
|
||||
// SPUMessageTypes.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/11/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SPUMessageTypes.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
// Tags added to the bundle identifier which is used as Mach service names
|
||||
// These should be very short because of length restrictions
|
||||
#define SPARKLE_INSTALLER_TAG @"-spki"
|
||||
#define SPARKLE_STATUS_TAG @"-spks"
|
||||
#define SPARKLE_PROGRESS_TAG @"-spkp"
|
||||
|
||||
// macOS 10.8 couldn't handle service names that are >= 64 characters,
|
||||
// but 10.9 raised this to >= 128 characters
|
||||
#define MAX_SERVICE_NAME_LENGTH 127u
|
||||
|
||||
BOOL SPUInstallerMessageTypeIsLegal(SPUInstallerMessageType oldMessageType, SPUInstallerMessageType newMessageType)
|
||||
{
|
||||
BOOL legal;
|
||||
switch (newMessageType) {
|
||||
case SPUInstallerNotStarted:
|
||||
legal = (oldMessageType == SPUInstallerNotStarted);
|
||||
break;
|
||||
case SPUExtractionStarted:
|
||||
legal = (oldMessageType == SPUInstallerNotStarted);
|
||||
break;
|
||||
case SPUExtractedArchiveWithProgress:
|
||||
case SPUArchiveExtractionFailed:
|
||||
legal = (oldMessageType == SPUExtractionStarted || oldMessageType == SPUExtractedArchiveWithProgress);
|
||||
break;
|
||||
case SPUValidationStarted:
|
||||
legal = (oldMessageType == SPUExtractionStarted || oldMessageType == SPUExtractedArchiveWithProgress);
|
||||
break;
|
||||
case SPUInstallationStartedStage1:
|
||||
legal = (oldMessageType == SPUValidationStarted);
|
||||
break;
|
||||
case SPUInstallationFinishedStage1:
|
||||
legal = (oldMessageType == SPUInstallationStartedStage1);
|
||||
break;
|
||||
case SPUInstallationFinishedStage2:
|
||||
legal = (oldMessageType == SPUInstallationFinishedStage1);
|
||||
break;
|
||||
case SPUInstallationFinishedStage3:
|
||||
legal = (oldMessageType == SPUInstallationFinishedStage2);
|
||||
break;
|
||||
case SPUInstallerError:
|
||||
case SPUUpdaterAlivePing:
|
||||
// Having this state being dependent on other installation states would make the complicate our logic
|
||||
// So just always allow these type of messages
|
||||
legal = YES;
|
||||
break;
|
||||
}
|
||||
return legal;
|
||||
}
|
||||
|
||||
static NSString *SPUServiceNameWithTag(NSString *tagName, NSString *bundleIdentifier)
|
||||
{
|
||||
NSString *serviceName = [bundleIdentifier stringByAppendingString:tagName];
|
||||
NSUInteger length = MIN(serviceName.length, MAX_SERVICE_NAME_LENGTH);
|
||||
// If the service name is too long, cut off the beginning rather than cutting off the end
|
||||
// This should lead to a more unique name
|
||||
return [serviceName substringFromIndex:serviceName.length - length];
|
||||
}
|
||||
|
||||
NSString *SPUInstallerServiceNameForBundleIdentifier(NSString *bundleIdentifier)
|
||||
{
|
||||
return SPUServiceNameWithTag(SPARKLE_INSTALLER_TAG, bundleIdentifier);
|
||||
}
|
||||
|
||||
NSString *SPUStatusInfoServiceNameForBundleIdentifier(NSString *bundleIdentifier)
|
||||
{
|
||||
return SPUServiceNameWithTag(SPARKLE_STATUS_TAG, bundleIdentifier);
|
||||
}
|
||||
|
||||
NSString *SPUProgressAgentServiceNameForBundleIdentifier(NSString *bundleIdentifier)
|
||||
{
|
||||
return SPUServiceNameWithTag(SPARKLE_PROGRESS_TAG, bundleIdentifier);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
//
|
||||
// SUCodeSigningVerifier.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 7/5/12.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef SUCODESIGNINGVERIFIER_H
|
||||
#define SUCODESIGNINGVERIFIER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SUCodeSigningVerifier : NSObject
|
||||
+ (BOOL)codeSignatureAtBundleURL:(NSURL *)oldBundleURL matchesSignatureAtBundleURL:(NSURL *)newBundleURL error:(NSError **)error;
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundleURL error:(NSError **)error;
|
||||
+ (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundleURL;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,21 +0,0 @@
|
||||
//
|
||||
// SUFlatPackageUnarchiver.h
|
||||
// Autoupdate
|
||||
//
|
||||
// Created by Mayur Pawashe on 1/30/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUUnarchiverProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// An unarchiver for flat packages that doesn't really do any unarchiving
|
||||
@interface SUFlatPackageUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithFlatPackagePath:(NSString *)flatPackagePath expectingInstallationType:(NSString *)installationType;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,67 +0,0 @@
|
||||
//
|
||||
// SUFlatPackageUnarchiver.m
|
||||
// Autoupdate
|
||||
//
|
||||
// Created by Mayur Pawashe on 1/30/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUFlatPackageUnarchiver.h"
|
||||
#import "SUUnarchiverNotifier.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUFlatPackageUnarchiver ()
|
||||
|
||||
@property (nonatomic, readonly) NSString *flatPackagePath;
|
||||
@property (nonatomic, readonly) NSString *expectedInstallationType;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUFlatPackageUnarchiver
|
||||
|
||||
@synthesize flatPackagePath = _flatPackagePath;
|
||||
@synthesize expectedInstallationType = _expectedInstallationType;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return [path.pathExtension isEqualToString:@"pkg"] || [path.pathExtension isEqualToString:@"mpkg"];
|
||||
}
|
||||
|
||||
+ (BOOL)mustValidateBeforeExtraction
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFlatPackagePath:(NSString *)flatPackagePath expectingInstallationType:(NSString *)installationType
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_flatPackagePath = [flatPackagePath copy];
|
||||
_expectedInstallationType = [installationType copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock
|
||||
{
|
||||
SUUnarchiverNotifier *notifier = [[SUUnarchiverNotifier alloc] initWithCompletionBlock:completionBlock progressBlock:progressBlock];
|
||||
|
||||
// Flat packages must use guided package installs, not interactive
|
||||
BOOL isDirectory = NO;
|
||||
if (![self.expectedInstallationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not have guided installation type but %@ instead", self.expectedInstallationType]}]];
|
||||
} else if (![[NSFileManager defaultManager] fileExistsAtPath:self.flatPackagePath isDirectory:&isDirectory] || isDirectory) {
|
||||
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not exist at %@", self.flatPackagePath]}]];
|
||||
} else {
|
||||
[notifier notifyProgress:1.0];
|
||||
[notifier notifySuccess];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.flatPackagePath]; }
|
||||
|
||||
@end
|
||||
@@ -1,87 +0,0 @@
|
||||
//
|
||||
// SUGuidedPackageInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Graham Miln on 14/05/2010.
|
||||
// Copyright 2010 Dragon Systems Software Limited. All rights reserved.
|
||||
//
|
||||
|
||||
#import <sys/stat.h>
|
||||
#import "SUGuidedPackageInstaller.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUGuidedPackageInstaller ()
|
||||
|
||||
@property (nonatomic, readonly, copy) NSString *packagePath;
|
||||
@property (nonatomic, readonly, copy) NSString *homeDirectory;
|
||||
@property (nonatomic, readonly, copy) NSString *userName;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUGuidedPackageInstaller
|
||||
|
||||
@synthesize packagePath = _packagePath;
|
||||
@synthesize homeDirectory = _homeDirectory;
|
||||
@synthesize userName = _userName;
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_packagePath = [packagePath copy];
|
||||
_homeDirectory = [homeDirectory copy];
|
||||
_userName = [userName copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)performInitialInstallation:(NSError * __autoreleasing *)__unused error
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performFinalInstallationProgressBlock:(nullable void(^)(double))__unused cb error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
// This command *must* be run as root
|
||||
NSString *installerPath = @"/usr/sbin/installer";
|
||||
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
task.launchPath = installerPath;
|
||||
task.arguments = @[@"-pkg", self.packagePath, @"-target", @"/"];
|
||||
// Set the $HOME and $USER variables so pre/post install scripts reference the correct user environment
|
||||
task.environment = @{@"HOME": self.homeDirectory, @"USER": self.userName};
|
||||
task.standardError = [NSPipe pipe];
|
||||
task.standardOutput = [NSPipe pipe];
|
||||
|
||||
BOOL success = YES;
|
||||
@try {
|
||||
[task launch];
|
||||
[task waitUntilExit];
|
||||
if (task.terminationStatus != EXIT_SUCCESS) {
|
||||
success = NO;
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Guided package installer returned non-zero exit status (%d)", task.terminationStatus] }];
|
||||
}
|
||||
}
|
||||
} @catch (NSException *) {
|
||||
success = NO;
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Guided package installer task threw an exception"] }];
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
- (void)performCleanup
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL)canInstallSilently
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,38 +0,0 @@
|
||||
//
|
||||
// SUInstallerProtocol.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/12/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUInstallerProtocol <NSObject>
|
||||
|
||||
// Any installation work can be done prior to user application being terminated and relaunched
|
||||
// No UI should occur during this stage (i.e, do not show package installer apps, etc..)
|
||||
// Should be able to be called from non-main thread
|
||||
- (BOOL)performInitialInstallation:(NSError **)error;
|
||||
|
||||
// Any installation work after the user application has has been terminated. This is where the final installation work can be done.
|
||||
// After this stage is done, the user application may be relaunched.
|
||||
// Should be able to be called from non-main thread
|
||||
- (BOOL)performFinalInstallationProgressBlock:(nullable void(^)(double))cb error:(NSError **)error;
|
||||
|
||||
// Any clean up work can be done here
|
||||
// This is work that may be performed after the user application may have been updated / relaunched,
|
||||
// or after an error occurred in the previous stages.
|
||||
// Should be able to be called from any thread
|
||||
- (void)performCleanup;
|
||||
|
||||
// Indicates whether or not this installer can install the update silently in the background, without hindering the user
|
||||
// If this returns NO, then the installation can fail if the user did not directly request for the install to occur.
|
||||
// Should be thread safe
|
||||
- (BOOL)canInstallSilently;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,313 +0,0 @@
|
||||
//
|
||||
// SUPlainInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUFileManager.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SUHost.h"
|
||||
#import "SULog.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUPlainInstaller ()
|
||||
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic, copy, readonly) NSString *bundlePath;
|
||||
@property (nonatomic, copy, readonly) NSString *installationPath;
|
||||
|
||||
@property (nonatomic) NSURL *temporaryOldDirectory;
|
||||
// We get an obj-c warning if we use 'newTemporaryDirectory' name about new + ownership stuff, so use 'temporaryNewDirectory' instead
|
||||
@property (nonatomic) NSURL *temporaryNewDirectory;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUPlainInstaller
|
||||
|
||||
@synthesize host = _host;
|
||||
@synthesize bundlePath = _bundlePath;
|
||||
@synthesize installationPath = _installationPath;
|
||||
@synthesize temporaryOldDirectory = _temporaryOldDirectory;
|
||||
@synthesize temporaryNewDirectory = _temporaryNewDirectory;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host bundlePath:(NSString *)bundlePath installationPath:(NSString *)installationPath
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_host = host;
|
||||
_bundlePath = [bundlePath copy];
|
||||
_installationPath = [installationPath copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
// Returns the bundle version from the specified host that is appropriate to use as a filename, or nil if we're unable to retrieve one
|
||||
- (NSString *)bundleVersionAppropriateForFilenameFromHost:(SUHost *)host
|
||||
{
|
||||
NSString *bundleVersion = [host objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey];
|
||||
NSString *trimmedVersion = @"";
|
||||
|
||||
if (bundleVersion != nil) {
|
||||
NSMutableCharacterSet *validCharacters = [NSMutableCharacterSet alphanumericCharacterSet];
|
||||
[validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]];
|
||||
|
||||
trimmedVersion = [bundleVersion stringByTrimmingCharactersInSet:[validCharacters invertedSet]];
|
||||
}
|
||||
|
||||
return trimmedVersion.length > 0 ? trimmedVersion : nil;
|
||||
}
|
||||
|
||||
- (BOOL)startInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL *)newURL withHost:(SUHost *)host progressBlock:(nullable void(^)(double))progress error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
if (installationURL == nil || newURL == nil) {
|
||||
// this really shouldn't happen but just in case
|
||||
SULog(SULogLevelError, @"Failed to perform installation because either installation URL (%@) or new URL (%@) is nil", installationURL, newURL);
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to perform installation because the paths to install at and from are not valid" }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(1/10.0);
|
||||
}
|
||||
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
|
||||
// Update the access time of our entire application before moving it into a temporary directory
|
||||
// The system periodically cleans up files by looking at the mod & access times, so we have to make sure they're up to date
|
||||
// They could be potentially be preserved when archiving an application, but also an update could just be sitting on the system for a long time
|
||||
// before being installed
|
||||
if (![fileManager updateAccessTimeOfItemAtRootURL:newURL error:error]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to recursively update new application's modification time before moving into temporary directory" }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Create a temporary directory for our new app that resides on our destination's volume
|
||||
NSString *preferredName = [installationURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingString:@" (Incomplete Update)"];
|
||||
NSURL *installationDirectory = installationURL.URLByDeletingLastPathComponent;
|
||||
NSURL *tempNewDirectoryURL = [fileManager makeTemporaryDirectoryWithPreferredName:preferredName appropriateForDirectoryURL:installationDirectory error:error];
|
||||
|
||||
if (tempNewDirectoryURL == nil) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to make new temporary directory" }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
self.temporaryNewDirectory = tempNewDirectoryURL;
|
||||
|
||||
if (progress) {
|
||||
progress(2/10.0);
|
||||
}
|
||||
|
||||
// Move the new app to our temporary directory
|
||||
NSString *newURLLastPathComponent = newURL.lastPathComponent;
|
||||
NSURL *newTempURL = [tempNewDirectoryURL URLByAppendingPathComponent:newURLLastPathComponent];
|
||||
if (![fileManager moveItemAtURL:newURL toURL:newTempURL error:error]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to move the new app from %@ to its temp directory at %@", newURL.path, newTempURL.path] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(3/10.0);
|
||||
}
|
||||
|
||||
// Release our new app from quarantine
|
||||
NSError *quarantineError = nil;
|
||||
if (![fileManager releaseItemFromQuarantineAtRootURL:newTempURL error:&quarantineError]) {
|
||||
// Not big enough of a deal to fail the entire installation
|
||||
SULog(SULogLevelError, @"Failed to release quarantine at %@ with error %@", newTempURL.path, quarantineError);
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(4/10.0);
|
||||
}
|
||||
|
||||
NSURL *oldURL = [NSURL fileURLWithPath:host.bundlePath];
|
||||
if (oldURL == nil) {
|
||||
// this really shouldn't happen but just in case
|
||||
SULog(SULogLevelError, @"Failed to construct URL from bundle path: %@", host.bundlePath);
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to perform installation because a path could not be constructed for the old installation" }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Try to preserve Finder Tags
|
||||
NSArray *resourceTags = nil;
|
||||
BOOL retrievedResourceTags = [oldURL getResourceValue:&resourceTags forKey:NSURLTagNamesKey error:NULL];
|
||||
if (retrievedResourceTags && resourceTags.count > 0) {
|
||||
[newTempURL setResourceValue:resourceTags forKey:NSURLTagNamesKey error:NULL];
|
||||
}
|
||||
|
||||
// We must leave moving the app to its destination as the final step in installing it, so that
|
||||
// it's not possible our new app can be left in an incomplete state at the final destination
|
||||
|
||||
NSError *changeOwnerAndGroupError = nil;
|
||||
if (![fileManager changeOwnerAndGroupOfItemAtRootURL:newTempURL toMatchURL:oldURL error:&changeOwnerAndGroupError]) {
|
||||
// Not a fatal error
|
||||
SULog(SULogLevelError, @"Failed to change owner and group of new app at %@ to match old app at %@", newTempURL.path, oldURL.path);
|
||||
SULog(SULogLevelError, @"Error: %@", changeOwnerAndGroupError);
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(5/10.0);
|
||||
}
|
||||
|
||||
NSError *touchError = nil;
|
||||
if (![fileManager updateModificationAndAccessTimeOfItemAtURL:newTempURL error:&touchError]) {
|
||||
// Not a fatal error, but a pretty unfortunate one
|
||||
SULog(SULogLevelError, @"Failed to update modification and access time of new app at %@", newTempURL.path);
|
||||
SULog(SULogLevelError, @"Error: %@", touchError);
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(6/10.0);
|
||||
}
|
||||
|
||||
// First try replacing the application atomically
|
||||
NSError *replaceError = nil;
|
||||
BOOL replacedApp;
|
||||
if (@available(macOS 10.13, *)) {
|
||||
// If the app is normalized and the installation path differs, go through the old swap path
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME && ![oldURL.path isEqual:installationURL.path]) {
|
||||
replacedApp = NO;
|
||||
} else {
|
||||
// Note: in my experience, a clone of the app may still be left at newTempURL
|
||||
// This is OK though because we will be cleaning up the temporary directory later in -performCleanup:
|
||||
replacedApp = [fileManager replaceItemAtURL:installationURL withItemAtURL:newTempURL error:&replaceError];
|
||||
}
|
||||
} else {
|
||||
replacedApp = NO;
|
||||
}
|
||||
|
||||
if (!replacedApp) {
|
||||
// Otherwise swap out the old and new applications using the legacy path
|
||||
|
||||
if (replaceError != nil) {
|
||||
SULog(SULogLevelDefault, @"Invoking fallback from failing to replace original item with error: %@", replaceError);
|
||||
}
|
||||
|
||||
// Decide on a destination name we should use for the older app when we move it around the file system
|
||||
NSString *oldDestinationName = oldURL.lastPathComponent.stringByDeletingPathExtension;
|
||||
NSString *oldDestinationNameWithPathExtension = oldURL.lastPathComponent;
|
||||
|
||||
// Create a temporary directory for our old app that resides on its volume
|
||||
NSURL *oldDirectoryURL = oldURL.URLByDeletingLastPathComponent;
|
||||
NSURL *tempOldDirectoryURL = (oldDirectoryURL != nil) ? [fileManager makeTemporaryDirectoryWithPreferredName:oldDestinationName appropriateForDirectoryURL:oldDirectoryURL error:error] : nil;
|
||||
if (tempOldDirectoryURL == nil) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to create temporary directory for old app at %@", oldURL.path] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
self.temporaryOldDirectory = tempOldDirectoryURL;
|
||||
|
||||
if (progress) {
|
||||
progress(7/10.0);
|
||||
}
|
||||
|
||||
// Move the old app to the temporary directory
|
||||
NSURL *oldTempURL = [tempOldDirectoryURL URLByAppendingPathComponent:oldDestinationNameWithPathExtension];
|
||||
if (![fileManager moveItemAtURL:oldURL toURL:oldTempURL error:error]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to move the old app at %@ to a temporary location at %@", oldURL.path, oldTempURL.path] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(8/10.0);
|
||||
}
|
||||
|
||||
// Move the new app to its final destination
|
||||
if (![fileManager moveItemAtURL:newTempURL toURL:installationURL error:error]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to move new app at %@ to final destination %@", newTempURL.path, installationURL.path] }];
|
||||
}
|
||||
|
||||
// Attempt to restore our old app back the way it was on failure
|
||||
[fileManager moveItemAtURL:oldTempURL toURL:oldURL error:NULL];
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(9/10.0);
|
||||
}
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(10/10.0);
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performInitialInstallation:(NSError * __autoreleasing *)error
|
||||
{
|
||||
// Prevent malicious downgrades
|
||||
// Note that we may not be able to do this for package installations, hence this code being done here
|
||||
NSString *hostVersion = [self.host version];
|
||||
|
||||
NSBundle *bundle = [NSBundle bundleWithPath:self.bundlePath];
|
||||
SUHost *updateHost = [[SUHost alloc] initWithBundle:bundle];
|
||||
NSString *updateVersion = [updateHost objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey];
|
||||
|
||||
id<SUVersionComparison> comparator = [[SUStandardVersionComparator alloc] init];
|
||||
if (!updateVersion || [comparator compareVersion:hostVersion toVersion:updateVersion] == NSOrderedDescending) {
|
||||
|
||||
if (error != NULL) {
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"For security reasons, updates that downgrade version of the application are not allowed. Refusing to downgrade app from version %@ to %@. Aborting update.", hostVersion, updateVersion];
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performFinalInstallationProgressBlock:(nullable void(^)(double))cb error:(NSError *__autoreleasing*)error
|
||||
{
|
||||
// Note: we must do most installation work in the third stage due to relying on our application sitting in temporary directories.
|
||||
// It must not be possible for our update to sit in temporary directories for a very long time.
|
||||
return [self startInstallationToURL:[NSURL fileURLWithPath:self.installationPath] fromUpdateAtURL:[NSURL fileURLWithPath:self.bundlePath] withHost:self.host progressBlock:cb error:error];
|
||||
}
|
||||
|
||||
- (void)performCleanup
|
||||
{
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
|
||||
if (self.temporaryNewDirectory != nil) {
|
||||
[fileManager removeItemAtURL:self.temporaryNewDirectory error:NULL];
|
||||
}
|
||||
|
||||
if (self.temporaryOldDirectory != nil) {
|
||||
[fileManager removeItemAtURL:self.temporaryOldDirectory error:NULL];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)canInstallSilently
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,21 +0,0 @@
|
||||
//
|
||||
// SUStatusInfoProtocol.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUStatusInfoProtocol
|
||||
|
||||
- (void)probeStatusInfoWithReply:(void (^)(NSData * _Nullable installationInfoData))reply;
|
||||
|
||||
- (void)probeStatusConnectivityWithReply:(void (^)(void))reply;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,26 +0,0 @@
|
||||
//
|
||||
// StatusInfo.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUStatusInfoProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface StatusInfo : NSObject <SUStatusInfoProtocol>
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)bundleIdentifier;
|
||||
|
||||
@property (nonatomic, nullable) NSData *installationInfoData;
|
||||
|
||||
- (void)startListener;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,69 +0,0 @@
|
||||
//
|
||||
// StatusInfo.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "StatusInfo.h"
|
||||
#import "SPUMessageTypes.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface StatusInfo () <NSXPCListenerDelegate>
|
||||
|
||||
@property (nonatomic) NSXPCListener *xpcListener;
|
||||
|
||||
@end
|
||||
|
||||
@implementation StatusInfo
|
||||
|
||||
@synthesize xpcListener = _xpcListener;
|
||||
@synthesize installationInfoData = _installationInfoData;
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)bundleIdentifier
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_xpcListener = [[NSXPCListener alloc] initWithMachServiceName:SPUStatusInfoServiceNameForBundleIdentifier(bundleIdentifier)];
|
||||
_xpcListener.delegate = self;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startListener
|
||||
{
|
||||
[self.xpcListener resume];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
[self.xpcListener invalidate];
|
||||
self.xpcListener = nil;
|
||||
}
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
|
||||
{
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUStatusInfoProtocol)];
|
||||
newConnection.exportedObject = self;
|
||||
|
||||
[newConnection resume];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)probeStatusInfoWithReply:(void (^)(NSData * _Nullable))reply
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
reply(self.installationInfoData);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)probeStatusConnectivityWithReply:(void (^)(void))reply
|
||||
{
|
||||
reply();
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,24 +0,0 @@
|
||||
//
|
||||
// TerminationListener.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/7/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TerminationListener : NSObject
|
||||
|
||||
- (instancetype)initWithProcessIdentifier:(NSNumber * _Nullable)processIdentifier;
|
||||
|
||||
@property (nonatomic, readonly) BOOL terminated;
|
||||
|
||||
// If the process identifier provided was nil, then the completion block will invoke immediately with a YES success
|
||||
- (void)startListeningWithCompletion:(void (^)(BOOL success))completionBlock;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,131 +0,0 @@
|
||||
//
|
||||
// TerminationListener.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/7/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TerminationListener.h"
|
||||
#import "SULog.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface TerminationListener ()
|
||||
|
||||
@property (nonatomic, readonly, nullable) NSNumber *processIdentifier;
|
||||
@property (nonatomic) BOOL watchedTermination;
|
||||
@property (nonatomic, copy) void (^completionBlock)(BOOL);
|
||||
|
||||
@end
|
||||
|
||||
@implementation TerminationListener
|
||||
|
||||
@synthesize completionBlock = _completionBlock;
|
||||
@synthesize processIdentifier = _processIdentifier;
|
||||
@synthesize watchedTermination = _watchedTermination;
|
||||
|
||||
- (instancetype)initWithProcessIdentifier:(NSNumber * _Nullable)processIdentifier
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_processIdentifier = processIdentifier;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)terminated
|
||||
{
|
||||
return (self.watchedTermination || self.processIdentifier == nil) ? YES : (kill(self.processIdentifier.intValue, 0) != 0);
|
||||
}
|
||||
|
||||
- (void)invokeCompletionWithSuccess:(BOOL)success
|
||||
{
|
||||
if (self.completionBlock != nil) {
|
||||
self.completionBlock(success);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startListeningWithCompletion:(void (^)(BOOL))completionBlock
|
||||
{
|
||||
self.completionBlock = completionBlock;
|
||||
|
||||
if (self.processIdentifier == nil) {
|
||||
[self invokeCompletionWithSuccess:YES];
|
||||
return;
|
||||
}
|
||||
|
||||
// Use kqueues to determine when the process will terminate
|
||||
// As described in https://developer.apple.com/library/mac/technotes/tn2050/_index.html#//apple_ref/doc/uid/DTS10003081-CH1-SUBSECTION10
|
||||
// By using kqueues, we can stay away from using AppKit in case we ever decide to abandon it
|
||||
|
||||
pid_t processIdentifier = self.processIdentifier.intValue;
|
||||
int queue = kqueue();
|
||||
if (queue == -1) {
|
||||
SULog(SULogLevelError, @"Failed to create kqueue() due to error %d: %@", errno, @(strerror(errno)));
|
||||
[self invokeCompletionWithSuccess:NO];
|
||||
return;
|
||||
}
|
||||
|
||||
struct kevent changes;
|
||||
EV_SET(&changes, processIdentifier, EVFILT_PROC, EV_ADD | EV_RECEIPT, NOTE_EXIT, 0, NULL);
|
||||
|
||||
if (kevent(queue, &changes, 1, &changes, 1, NULL) == -1) {
|
||||
SULog(SULogLevelError, @"Failed to invoke kevent() due to error %d: %@", errno, @(strerror(errno)));
|
||||
[self invokeCompletionWithSuccess:NO];
|
||||
return;
|
||||
}
|
||||
|
||||
// We will assume this terminationListener will never be deallocated
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcast-qual"
|
||||
CFFileDescriptorContext context = { 0, (void *)CFBridgingRetain(self), NULL, NULL, NULL };
|
||||
#pragma clang diagnostic pop
|
||||
CFFileDescriptorRef noteExitKQueueRef = CFFileDescriptorCreate(NULL, queue, true, noteExitKQueueCallback, &context);
|
||||
if (noteExitKQueueRef == NULL) {
|
||||
SULog(SULogLevelError, @"Failed to create file descriptor via CFFileDescriptorCreate()");
|
||||
CFRelease((__bridge CFTypeRef)(self));
|
||||
[self invokeCompletionWithSuccess:NO];
|
||||
return;
|
||||
}
|
||||
|
||||
CFRunLoopSourceRef runLoopSource = CFFileDescriptorCreateRunLoopSource(NULL, noteExitKQueueRef, 0);
|
||||
if (runLoopSource == NULL) {
|
||||
SULog(SULogLevelError, @"Failed to create runLoopSource via CFFileDescriptorCreateRunLoopSource()");
|
||||
CFRelease((__bridge CFTypeRef)(self));
|
||||
[self invokeCompletionWithSuccess:NO];
|
||||
return;
|
||||
}
|
||||
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
|
||||
CFRelease(runLoopSource);
|
||||
|
||||
CFFileDescriptorEnableCallBacks(noteExitKQueueRef, kCFFileDescriptorReadCallBack);
|
||||
|
||||
// Make sure we didn't set the listener callback to a dead PID
|
||||
// If we did, we could hang forever. To avoid this, we check if the process has terminated *after* we set up the callback
|
||||
// If we tried to do this check before setting the callback, we could run into an issue where the process can terminate after our check
|
||||
// but before setting the callback
|
||||
if ([self terminated]) {
|
||||
[self invokeCompletionWithSuccess:YES];
|
||||
}
|
||||
}
|
||||
|
||||
static void noteExitKQueueCallback(CFFileDescriptorRef file, CFOptionFlags __unused callBackTypes, void *info)
|
||||
{
|
||||
struct kevent event;
|
||||
kevent(CFFileDescriptorGetNativeDescriptor(file), NULL, 0, &event, 1, NULL);
|
||||
|
||||
TerminationListener *self = CFBridgingRelease(info);
|
||||
self.watchedTermination = YES;
|
||||
[self invokeCompletionWithSuccess:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,36 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "AppInstaller.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
int main(int __unused argc, const char __unused *argv[])
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
NSArray<NSString *> *args = [[NSProcessInfo processInfo] arguments];
|
||||
if (args.count != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
NSString *hostBundleIdentifier = args[1];
|
||||
NSString *homeDirectory = args[2];
|
||||
NSString *userName = args[3];
|
||||
|
||||
AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostBundleIdentifier:hostBundleIdentifier homeDirectory:homeDirectory userName:userName];
|
||||
[appInstaller start];
|
||||
|
||||
// Ignore SIGTERM because we are going to catch it ourselves
|
||||
signal(SIGTERM, SIG_IGN);
|
||||
|
||||
dispatch_source_t sigtermSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
|
||||
dispatch_source_set_event_handler(sigtermSource, ^{
|
||||
[appInstaller cleanupAndExitWithStatus:SIGTERM error:nil];
|
||||
});
|
||||
dispatch_resume(sigtermSource);
|
||||
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,48 +1,3 @@
|
||||
# 2.0.0
|
||||
|
||||
* Support for Sandboxed Applications (Zorg)
|
||||
* Support for writing custom user interfaces (Zorg)
|
||||
* Support for updating external Sparkle-based bundles (Zorg)
|
||||
* Added command line utility to update Sparkle-based bundles (Zorg)
|
||||
* More modern architecture
|
||||
* Moves extraction, validation, and installation into a submitted launchd agent/daemon with XPC communication (Zorg)
|
||||
* Features faster installs with shorter update/relaunch times (Zorg)
|
||||
* Provides more robust installs that need to request user authorization (Zorg)
|
||||
* Adoption of atomic-safe bundle replacing updates leveraging APFS (#1801) (Zorg)
|
||||
* API Changes
|
||||
* Introduced new SPUStandardUpdaterController, SPUUpdater, SPUUserDriver classes/protocols (Zorg)
|
||||
* Decoupled AppKit and UI logic in the framework from core functionality (Zorg)
|
||||
* Ensure (most) API / ABI compatibility with Sparkle 1.x; you can likely test Sparkle 2 in an existing app without any changes (Zorg)
|
||||
* Deprecated SUUpdater, albeit it is still functional for testing and transitional purposes (Zorg)
|
||||
* Delegation methods may have been removed or added to the newer updater API. Please review `SPUUpdaterDelegate` if using `SPUUpdater`. (Zorg)
|
||||
* Updater Changes
|
||||
* Automatic silent and manual update alert prompts are now merged together
|
||||
* Updates will attempt to install even if the user quits the application without relaunching the application update explicitly (Zorg)
|
||||
* Updates can be downloaded in the background automatically but later prompt the user to install them, particularly if Sparkle doesn't have sufficient permission to install them without the user's permission (Zorg)
|
||||
* Authorization now occurs before launching the installer and before terminating the application, which can be canceled by the user cleanly (Zorg)
|
||||
* Sparkle uses the icon of the bundle to update for its authorization dialog. A 32x32 image representation of the icon is needed. (Zorg)
|
||||
* Sudden termination for silent automatic updates isn't disabled anymore (Zorg)
|
||||
* Policy Changes
|
||||
* Distributing updates without EdDSA signing the archives is now deprecated (Zorg)
|
||||
* Package based updates that are zipped or archived must add sparkle:installationType="package" to the appcast item enclosure (Zorg)
|
||||
* System profiler privacy and transparency (#1690) (Martin Pilkington)
|
||||
* Support getting app icon from asset catalog (#1694) (Charles Srstka)
|
||||
* Don't hide update alert window now on deactivation (#1804) (Zorg)
|
||||
* Raise minimum system version to 10.11 (Zorg)
|
||||
* Special thanks to developers using early builds of this release in production and contributors for keeping this running (Kornel, Jonas Zaugg, Gwynne Raskind, Jordan Rose, Tony Arnold, Bryan Jones, Christian Tietze, Jakob Egger, and many more)
|
||||
|
||||
Please visit [Sparkle's website](http://sparkle-project.org) for more information on documentation and migration.
|
||||
|
||||
# 1.26.0
|
||||
|
||||
* Flat package support from #1745 (Zorg)
|
||||
* Correct generate_appcast -s command line argument usage help (Lance Lovette)
|
||||
* Fix -f command line argument handling (Lance Lovette)
|
||||
* Fix progress for guided pkg install (Zorg)
|
||||
* Fix XQuartz update failing because NSLog caused issues (Zorg)
|
||||
* Update localization (Vojtěch Koňařík)
|
||||
* Various fixes to SPM logic (Jonas Zaugg)
|
||||
|
||||
# 1.25.0
|
||||
|
||||
* Raise minimum system version to 10.9 (Kornel)
|
||||
@@ -70,7 +25,6 @@ Please visit [Sparkle's website](http://sparkle-project.org) for more informatio
|
||||
* Add phased rollouts feature to automatic update driver too (Zorg)
|
||||
* Remove hiding skip button and retitling later button (Zorg)
|
||||
* Deprecate installUpdatesIfAvailable (Zorg)
|
||||
* Apply custom headers to app download (Geraint White)
|
||||
|
||||
# 1.24.0
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
// Generate Appcast only
|
||||
|
||||
#include "ConfigSwift.xcconfig"
|
||||
|
||||
SWIFT_OBJC_BRIDGING_HEADER = $(PRODUCT_NAME)/Bridging-Header.h
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_TOOL=1
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "ConfigBinaryDelta.xcconfig"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
#include "ConfigBinaryDelta.xcconfig"
|
||||
@@ -2,23 +2,21 @@
|
||||
|
||||
SPARKLE_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle
|
||||
SPARKLE_RELAUNCH_TOOL_NAME = Autoupdate
|
||||
SPARKLE_INSTALLER_PROGRESS_TOOL_NAME = Updater
|
||||
SPARKLE_FILEOP_TOOL_NAME = fileop
|
||||
|
||||
// Set to 0 to only build all non-UI bits
|
||||
SPARKLE_BUILD_UI_BITS = 1
|
||||
SPARKLE_APPEND_VERSION_NUMBER = 1
|
||||
|
||||
// Sparkle usually doesn't allow downgrades as they're usually accidental, but
|
||||
// if your app has a downgrade function or URL handler, turn this on
|
||||
SPARKLE_AUTOMATED_DOWNGRADES = 0
|
||||
|
||||
// If your app file on disk is named "MyApp 1.1b4", Sparkle usually updates it
|
||||
// in place, giving you an app named 1.1b4 that is actually 1.2. Turn the
|
||||
// following on to always reset the name back to "MyApp"
|
||||
// If you are using this option to change the name of your app, you should
|
||||
// disable the option again when you no longer need it
|
||||
// Note this option is only supported for regular application updates and not plug-ins
|
||||
// following on to always reset the name back to "MyApp":
|
||||
SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0
|
||||
|
||||
SPARKLE_ICON_NAME = AppIcon
|
||||
|
||||
SPARKLE_VERSION_MAJOR = 2
|
||||
SPARKLE_VERSION_MINOR = 0
|
||||
SPARKLE_VERSION_MAJOR = 1
|
||||
SPARKLE_VERSION_MINOR = 25
|
||||
SPARKLE_VERSION_PATCH = 0
|
||||
SPARKLE_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)
|
||||
|
||||
@@ -28,28 +26,20 @@ ENABLE_STRICT_OBJC_MSGSEND = YES
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = YES
|
||||
GCC_INLINES_ARE_PRIVATE_EXTERN = YES
|
||||
ARCHS = $(ARCHS_STANDARD)
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.9
|
||||
PRODUCT_NAME = ${TARGET_NAME}
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle.${PRODUCT_NAME:rfc1034identifier}
|
||||
|
||||
XPC_SERVICE_BUNDLE_ID_PREFIX = org.sparkle-project
|
||||
INSTALLER_CONNECTION_BUNDLE_ID = ${XPC_SERVICE_BUNDLE_ID_PREFIX}.InstallerConnection
|
||||
INSTALLER_STATUS_BUNDLE_ID = ${XPC_SERVICE_BUNDLE_ID_PREFIX}.InstallerStatus
|
||||
INSTALLER_LAUNCHER_BUNDLE_ID = ${XPC_SERVICE_BUNDLE_ID_PREFIX}.InstallerLauncher
|
||||
DOWNLOADER_BUNDLE_ID = ${XPC_SERVICE_BUNDLE_ID_PREFIX}.Downloader
|
||||
GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_AUTOMATED_DOWNGRADES=$(SPARKLE_AUTOMATED_DOWNGRADES) SPARKLE_APPEND_VERSION_NUMBER=$(SPARKLE_APPEND_VERSION_NUMBER) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_FILEOP_TOOL_NAME=\"$(SPARKLE_FILEOP_TOOL_NAME)\"
|
||||
|
||||
GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_BUILD_UI_BITS=$(SPARKLE_BUILD_UI_BITS) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" CURRENT_PROJECT_VERSION=\"$(CURRENT_PROJECT_VERSION)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_NAME=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)\" SPARKLE_ICON_NAME=\"$(SPARKLE_ICON_NAME)\" INSTALLER_LAUNCHER_BUNDLE_ID=\"${INSTALLER_LAUNCHER_BUNDLE_ID}\" INSTALLER_CONNECTION_BUNDLE_ID=\"${INSTALLER_CONNECTION_BUNDLE_ID}\" INSTALLER_STATUS_BUNDLE_ID=\"${INSTALLER_STATUS_BUNDLE_ID}\" DOWNLOADER_BUNDLE_ID=\"${DOWNLOADER_BUNDLE_ID}\"
|
||||
|
||||
CODE_SIGN_IDENTITY = -
|
||||
SDKROOT = macosx
|
||||
ENABLE_HARDENED_RUNTIME = YES
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES
|
||||
GCC_ENABLE_PASCAL_STRINGS = NO
|
||||
GCC_NO_COMMON_BLOCKS = YES
|
||||
COMBINE_HIDPI_IMAGES = NO
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
COMBINE_HIDPI_IMAGES = NO;
|
||||
|
||||
// Enable warnings
|
||||
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES
|
||||
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
||||
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES
|
||||
@@ -65,7 +55,7 @@ CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
|
||||
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES
|
||||
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO
|
||||
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES
|
||||
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES
|
||||
@@ -96,4 +86,4 @@ GCC_WARN_UNUSED_VARIABLE = YES
|
||||
WARNING_CFLAGS_EXTRA = -Wno-custom-atomic-properties -Wno-implicit-atomic-properties
|
||||
|
||||
// Turn on all warnings, then disable a few which are almost impossible to avoid
|
||||
WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-arc-repeated-use-of-weak -Wno-auto-import -Wno-gnu-zero-variadic-macro-arguments -Wno-format-non-iso $(WARNING_CFLAGS_EXTRA)
|
||||
WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-arc-repeated-use-of-weak -Wno-auto-import -Wno-gnu-zero-variadic-macro-arguments $(WARNING_CFLAGS_EXTRA)
|
||||
@@ -1,12 +0,0 @@
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON)
|
||||
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
GCC_GENERATE_TEST_COVERAGE_FILES = YES
|
||||
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES
|
||||
@@ -11,8 +11,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = s
|
||||
DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON) DEBUG=0
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON)
|
||||
DEAD_CODE_STRIPPING = YES
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = NO
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES
|
||||
COPY_PHASE_STRIP = NO
|
||||
@@ -1,8 +0,0 @@
|
||||
// Downloader
|
||||
|
||||
INFOPLIST_FILE = Downloader/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${DOWNLOADER_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${DOWNLOADER_BUNDLE_ID}
|
||||
CODE_SIGN_ENTITLEMENTS = Downloader/${DOWNLOADER_BUNDLE_ID}.entitlements
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_DOWNLOADER_SERVICE=1
|
||||
@@ -1,2 +0,0 @@
|
||||
// Downloader Debug
|
||||
#include "ConfigDownloader.xcconfig"
|
||||
@@ -0,0 +1,5 @@
|
||||
// Fileop tool only
|
||||
|
||||
PRODUCT_NAME = $(SPARKLE_FILEOP_TOOL_NAME)
|
||||
SKIP_INSTALL = YES
|
||||
CLANG_ENABLE_MODULES = NO
|
||||
@@ -7,11 +7,7 @@ WRAPPER_EXTENSION = framework
|
||||
FRAMEWORK_VERSION = A
|
||||
INFOPLIST_FILE = Sparkle/Sparkle-Info.plist
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BUILDING_SPARKLE=1
|
||||
OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey
|
||||
SKIP_INSTALL = YES
|
||||
DEFINES_MODULE = YES
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${SPARKLE_BUNDLE_IDENTIFIER}
|
||||
|
||||
// As long as we don't ourselves depend upon any Frameworks that are incompatible
|
||||
// with Application Extensions, then we should allow frameworks that require
|
||||
// compatibility to be able to link with us.
|
||||
APPLICATION_EXTENSION_API_ONLY = YES
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "ConfigFramework.xcconfig"
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Generate Appcast only
|
||||
|
||||
#include "ConfigSwift.xcconfig"
|
||||
|
||||
SWIFT_OBJC_BRIDGING_HEADER = generate_appcast/Appcast-Bridging-Header.h
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
PRODUCT_NAME = generate_appcast
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Generate Appcast Debug
|
||||
|
||||
#include "CommandLineTool-Shared.xcconfig"
|
||||
#include "ConfigGenerateAppcast.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Generate Appcast Release
|
||||
|
||||
#include "CommandLineTool-Shared.xcconfig"
|
||||
#include "ConfigGenerateAppcast.xcconfig"
|
||||
#include "ConfigSwiftRelease.xcconfig"
|
||||
@@ -0,0 +1,7 @@
|
||||
// Generate Appcast only
|
||||
|
||||
#include "ConfigSwift.xcconfig"
|
||||
|
||||
SWIFT_OBJC_BRIDGING_HEADER = generate_keys/Bridging-Header.h
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
PRODUCT_NAME = generate_keys
|
||||
@@ -0,0 +1,4 @@
|
||||
// Generate Appcast Debug
|
||||
|
||||
#include "ConfigGenerateKeys.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
@@ -0,0 +1,4 @@
|
||||
// Generate Appcast Release
|
||||
|
||||
#include "ConfigGenerateKeys.xcconfig"
|
||||
#include "ConfigSwiftRelease.xcconfig"
|
||||
@@ -1,6 +0,0 @@
|
||||
// InstallerConnection
|
||||
|
||||
INFOPLIST_FILE = InstallerConnection/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${INSTALLER_CONNECTION_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${INSTALLER_CONNECTION_BUNDLE_ID}
|
||||
@@ -1,3 +0,0 @@
|
||||
// InstallerConnection Debug
|
||||
|
||||
#include "ConfigInstallerConnection.xcconfig"
|
||||
@@ -1,6 +0,0 @@
|
||||
// Installer Launcher
|
||||
|
||||
INFOPLIST_FILE = InstallerLauncher/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${INSTALLER_LAUNCHER_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${INSTALLER_LAUNCHER_BUNDLE_ID}
|
||||
@@ -1,2 +0,0 @@
|
||||
// Installer Launcher Debug
|
||||
#include "ConfigInstallerLauncher.xcconfig"
|
||||
@@ -1,7 +0,0 @@
|
||||
// Installer Progress only
|
||||
|
||||
INFOPLIST_FILE = Sparkle/InstallerProgress/InstallerProgress-Info.plist
|
||||
PRODUCT_NAME = $(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE=0
|
||||
SKIP_INSTALL = YES
|
||||
CLANG_ENABLE_MODULES = NO
|
||||
@@ -1,6 +0,0 @@
|
||||
// InstallerStatus
|
||||
|
||||
INFOPLIST_FILE = InstallerStatus/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${INSTALLER_STATUS_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${INSTALLER_STATUS_BUNDLE_ID}
|
||||
@@ -1,3 +0,0 @@
|
||||
// InstallerStatus Debug
|
||||
|
||||
#include "ConfigInstallerStatus.xcconfig"
|
||||
@@ -1,5 +1,8 @@
|
||||
// Relaunch Tool only
|
||||
|
||||
INFOPLIST_FILE = Sparkle/Autoupdate/Autoupdate-Info.plist
|
||||
PRODUCT_NAME = $(SPARKLE_RELAUNCH_TOOL_NAME)
|
||||
SKIP_INSTALL = YES
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon
|
||||
CLANG_ENABLE_MODULES = NO
|
||||
OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey
|
||||
@@ -0,0 +1 @@
|
||||
#include "ConfigRelaunch.xcconfig"
|
||||
@@ -0,0 +1 @@
|
||||
#include "ConfigRelaunch.xcconfig"
|
||||
@@ -1,7 +0,0 @@
|
||||
// sparkle command line tool only
|
||||
|
||||
INFOPLIST_FILE = sparkle-cli/Info.plist
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.sparkle-cli
|
||||
PRODUCT_NAME = sparkle
|
||||
LD_RUNPATH_SEARCH_PATHS = @executable_path/../Frameworks/
|
||||
ENABLE_HARDENED_RUNTIME = NO
|
||||
@@ -1,2 +1,2 @@
|
||||
SWIFT_VERSION = 5
|
||||
SWIFT_VERSION = 4.2
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
|
||||
@@ -1,2 +1 @@
|
||||
SWIFT_OPTIMIZATION_LEVEL = -O
|
||||
SWIFT_COMPILATION_MODE = wholemodule
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Owholemodule
|
||||
@@ -1,9 +1,9 @@
|
||||
// Test Application
|
||||
// Test Application only
|
||||
|
||||
INFOPLIST_FILE = TestApplication/TestApplication-Info.plist
|
||||
WRAPPER_EXTENSION = app
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = $(SPARKLE_ICON_NAME)
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon
|
||||
LD_RUNPATH_SEARCH_PATHS = @executable_path/../Frameworks
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.SparkleTestApp
|
||||
CODE_SIGN_ENTITLEMENTS = TestApplication/Sparkle-Test-App.entitlements
|
||||
ENABLE_HARDENED_RUNTIME = NO
|
||||
CODE_SIGN_IDENTITY = -
|
||||
@@ -1,2 +1,2 @@
|
||||
// Test Application Debug
|
||||
#include "ConfigTestApp.xcconfig"
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// Test Application Helper
|
||||
|
||||
INFOPLIST_FILE = TestAppHelper/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
LD_RUNPATH_SEARCH_PATHS = @executable_path/../../../../Frameworks
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.TestAppHelper
|
||||
ENABLE_HARDENED_RUNTIME = NO
|
||||
@@ -1,2 +0,0 @@
|
||||
// Test Application Helper Debug
|
||||
#include "ConfigTestAppHelper.xcconfig"
|
||||
@@ -0,0 +1 @@
|
||||
#include "ConfigTestApp.xcconfig"
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
INFOPLIST_FILE = UITests/UITests-Info.plist
|
||||
WRAPPER_EXTENSION = xctest
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
ENABLE_HARDENED_RUNTIME = NO
|
||||
|
||||
FRAMEWORK_SEARCH_PATHS = $(inherited) $(DEVELOPER_FRAMEWORKS_DIR)
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "ConfigUITest.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
|
||||
GCC_GENERATE_TEST_COVERAGE_FILES = NO
|
||||
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO
|
||||
@@ -9,6 +9,6 @@ GCC_SYMBOLS_PRIVATE_EXTERN = NO
|
||||
WARNING_CFLAGS = $(inherited) -Wno-variadic-macros -Wno-gnu-zero-variadic-macro-arguments
|
||||
FRAMEWORK_SEARCH_PATHS = $(inherited) $(DEVELOPER_FRAMEWORKS_DIR)
|
||||
LD_RUNPATH_SEARCH_PATHS = @loader_path/../Frameworks
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.9
|
||||
CLANG_ENABLE_MODULES = YES
|
||||
SWIFT_OBJC_BRIDGING_HEADER = Tests/Sparkle Unit Tests-Bridging-Header.h
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_TESTS=1
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "ConfigUnitTest.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
|
||||
GCC_GENERATE_TEST_COVERAGE_FILES = NO
|
||||
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO
|
||||
@@ -1,93 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os, sys, subprocess, tempfile, pathlib
|
||||
|
||||
PRODUCT_BUNDLE_ID_MACRO = "$(PRODUCT_BUNDLE_IDENTIFIER)"
|
||||
|
||||
def log_message(message):
|
||||
sys.stderr.write(message + "\n")
|
||||
|
||||
#Surround a token with double quotes if it has a space in it
|
||||
def sanitize(argument):
|
||||
return ('"' + argument + '"' if ' ' in argument else argument)
|
||||
|
||||
def _codesign_service(identity, path, entitlements_path=None):
|
||||
command = ["codesign", "-o", "runtime", "-fs", identity, path] + ([] if entitlements_path is None else ["--entitlements", entitlements_path])
|
||||
log_message(" ".join(map(sanitize, command)))
|
||||
|
||||
process = subprocess.Popen(command, stdout=subprocess.PIPE)
|
||||
process.communicate()
|
||||
if process.returncode != 0:
|
||||
log_message("Error: Failed to codesign %s" % (path))
|
||||
sys.exit(1)
|
||||
|
||||
def codesign_service(service_name, identity, path, entitlements_path=None):
|
||||
#Sign the auxiliary executables (if any)
|
||||
executables_path = os.path.join(path, "Contents/MacOS/")
|
||||
if os.path.exists(executables_path):
|
||||
for executable in os.listdir(executables_path):
|
||||
if executable != service_name:
|
||||
_codesign_service(identity, os.path.join(executables_path, executable), entitlements_path)
|
||||
|
||||
#Sign the service bundle
|
||||
_codesign_service(identity, path, entitlements_path)
|
||||
|
||||
# Returns entitlements back with a bundle id applied if needed
|
||||
def applied_entitlements_path(entitlements_path, bundle_id, temp_dir):
|
||||
entitlements_str = pathlib.Path(entitlements_path).read_text()
|
||||
if PRODUCT_BUNDLE_ID_MACRO in entitlements_str:
|
||||
if bundle_id is None:
|
||||
return None
|
||||
else:
|
||||
new_entitlements_str = entitlements_str.replace(PRODUCT_BUNDLE_ID_MACRO, bundle_id)
|
||||
new_entitlements_path = os.path.join(temp_dir, os.path.basename(entitlements_path))
|
||||
pathlib.Path(new_entitlements_path).write_text(new_entitlements_str)
|
||||
return new_entitlements_path
|
||||
else:
|
||||
return entitlements_path
|
||||
|
||||
def print_usage():
|
||||
log_message("Usage:\n\t%s code-signing-identity [-b app-bundle-id] service1 service2 ..." % (sys.argv[0]))
|
||||
log_message("Example:\n\t%s \"Developer ID Application\" ./XPCServices/org.sparkle-project.InstallerLauncher.xpc" % (sys.argv[0]))
|
||||
log_message("")
|
||||
log_message("Use this script to sign XPC Services to include in your Sandboxed application.")
|
||||
log_message("")
|
||||
log_message("bundle-id is optional and only needs to be provided when signing InstallerConnection and InstallerStatus services. Most applications do not need to use these services and can provide additional entitlements to their application instead.")
|
||||
log_message("")
|
||||
log_message("This script may not be needed for common development workflows. Please visit https://sparkle-project.org/documentation/sandboxing/ for more details and instructions.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3:
|
||||
print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
signing_identity = sys.argv[1]
|
||||
remaining_args = sys.argv[2:]
|
||||
bundle_id = None
|
||||
if remaining_args[0] == '-b':
|
||||
if len(remaining_args) < 3:
|
||||
# We need the bundle-id and at least one XPC Service to sign
|
||||
print_usage()
|
||||
sys.exit(1)
|
||||
else:
|
||||
bundle_id = remaining_args[1]
|
||||
services = remaining_args[2:]
|
||||
else:
|
||||
services = remaining_args
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
for service in services:
|
||||
parent, child = os.path.split(service)
|
||||
service_name = os.path.splitext(child)[0]
|
||||
entitlements_path = os.path.join(parent, service_name + ".entitlements")
|
||||
if os.path.exists(entitlements_path):
|
||||
service_entitlements_path = applied_entitlements_path(entitlements_path, bundle_id, temp_dir)
|
||||
if service_entitlements_path is None:
|
||||
print_usage()
|
||||
log_message("")
|
||||
log_message("Error: Bundle ID must be specified for signing %s. As noted in the usage above, you probably don't need to embed this service." % (service_name))
|
||||
sys.exit(1)
|
||||
else:
|
||||
service_entitlements_path = None
|
||||
|
||||
codesign_service(service_name, signing_identity, service, service_entitlements_path)
|
||||
@@ -12,6 +12,3 @@ ALWAYS_SEARCH_USER_PATHS = NO
|
||||
|
||||
// Disable Warnings - this is a third-party project, and we'll trust that the maintainers know what they're doing.
|
||||
WARNING_CFLAGS = $(inherited) -Wno-cast-qual -Wno-conversion -Wno-sign-conversion
|
||||
|
||||
// Disable dead stores analyzer warning
|
||||
CLANG_ANALYZER_DEADCODE_DEADSTORES = NO
|
||||
@@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Create symlinks to our helper tools in Sparkle and SparkleCore framework bundles
|
||||
# so URLForAuxiliaryExecutable: will pick up the tools. Doing this is supported in the Code Signing in Depth guide.
|
||||
|
||||
FRAMEWORK_PATH="${TARGET_BUILD_DIR}"/"${FULL_PRODUCT_NAME}"
|
||||
|
||||
ln -h -f -s "Versions/Current/""${SPARKLE_RELAUNCH_TOOL_NAME}" "${FRAMEWORK_PATH}"/"${SPARKLE_RELAUNCH_TOOL_NAME}"
|
||||
ln -h -f -s "Versions/Current/""${SPARKLE_INSTALLER_PROGRESS_TOOL_NAME}".app "${FRAMEWORK_PATH}"/"${SPARKLE_INSTALLER_PROGRESS_TOOL_NAME}".app
|
||||
@@ -14,38 +14,22 @@ if [ "$ACTION" = "" ] ; then
|
||||
rm -rf "$CONFIGURATION_BUILD_DIR/staging"
|
||||
rm -rf "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
rm -f "Sparkle-$CURRENT_PROJECT_VERSION.tar.xz"
|
||||
rm -f "Sparkle-$CURRENT_PROJECT_VERSION.tar.bz2"
|
||||
rm -f "Sparkle-for-Swift-Package-Manager.zip"
|
||||
|
||||
mkdir -p "$CONFIGURATION_BUILD_DIR/staging"
|
||||
mkdir -p "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
cp "$SRCROOT/CHANGELOG" "$SRCROOT/LICENSE" "$SRCROOT/INSTALL" "$SRCROOT/Resources/SampleAppcast.xml" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp "$SRCROOT/CHANGELOG" "$SRCROOT/LICENSE" "$SRCROOT/INSTALL" "$SRCROOT/Resources/SampleAppcast.xml" "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
cp "$SRCROOT/CHANGELOG" "$SRCROOT/LICENSE" "$SRCROOT/Resources/SampleAppcast.xml" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp "$SRCROOT/CHANGELOG" "$SRCROOT/LICENSE" "$SRCROOT/Resources/SampleAppcast.xml" "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
cp -R "$SRCROOT/bin" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp "$CONFIGURATION_BUILD_DIR/BinaryDelta" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp "$CONFIGURATION_BUILD_DIR/generate_appcast" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp "$CONFIGURATION_BUILD_DIR/generate_keys" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp "$CONFIGURATION_BUILD_DIR/sign_update" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp "$SRCROOT/Configurations/codesign_xpc_service.py" "$CONFIGURATION_BUILD_DIR/staging/bin/codesign_xpc_service"
|
||||
chmod 0755 "$CONFIGURATION_BUILD_DIR/staging/bin/codesign_xpc_service"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle Test App.app" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle Test App.app" "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/sparkle.app" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/sparkle.app" "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle.framework" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle.xcframework" "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
|
||||
mkdir -p "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/$INSTALLER_LAUNCHER_BUNDLE_ID.xpc" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/$DOWNLOADER_BUNDLE_ID.xpc" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/$INSTALLER_CONNECTION_BUNDLE_ID.xpc" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/$INSTALLER_STATUS_BUNDLE_ID.xpc" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
|
||||
cp "$SRCROOT/Downloader/$DOWNLOADER_BUNDLE_ID.entitlements" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
cp "$SRCROOT/InstallerConnection/$INSTALLER_CONNECTION_BUNDLE_ID.entitlements" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
cp "$SRCROOT/InstallerStatus/$INSTALLER_STATUS_BUNDLE_ID.entitlements" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
|
||||
# Only copy dSYMs for Release builds, but don't check for the presence of the actual files
|
||||
# because missing dSYMs in a release build SHOULD trigger a build failure
|
||||
if [ "$CONFIGURATION" = "Release" ] ; then
|
||||
@@ -55,61 +39,13 @@ if [ "$ACTION" = "" ] ; then
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/sign_update.dSYM" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle Test App.app.dSYM" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle Test App.app.dSYM" "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/sparkle.app.dSYM" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/sparkle.app.dSYM" "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle.framework.dSYM" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/$INSTALLER_LAUNCHER_BUNDLE_ID.xpc.dSYM" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/$DOWNLOADER_BUNDLE_ID.xpc.dSYM" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/$INSTALLER_CONNECTION_BUNDLE_ID.xpc.dSYM" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/$INSTALLER_STATUS_BUNDLE_ID.xpc.dSYM" "$CONFIGURATION_BUILD_DIR/staging/XPCServices"
|
||||
fi
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/staging/bin" "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/staging/XPCServices" "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
|
||||
cd "$CONFIGURATION_BUILD_DIR/staging"
|
||||
|
||||
if [ -x "$(command -v xz)" ]; then
|
||||
XZ_EXISTS=1
|
||||
else
|
||||
XZ_EXISTS=0
|
||||
fi
|
||||
|
||||
rm -rf "/tmp/sparkle-extract"
|
||||
mkdir -p "/tmp/sparkle-extract"
|
||||
|
||||
# Sorted file list groups similar files together, which improves tar compression
|
||||
if [ "$XZ_EXISTS" -eq 1 ] ; then
|
||||
find . \! -type d | rev | sort | rev | tar cv --files-from=- | xz -9 > "../Sparkle-$CURRENT_PROJECT_VERSION.tar.xz"
|
||||
|
||||
# Copy archived distribution for CI
|
||||
cp -f "../Sparkle-$CURRENT_PROJECT_VERSION.tar.xz" "../sparkle-dist.tar.xz"
|
||||
|
||||
# Extract archive for testing binary validity
|
||||
tar -xf "../Sparkle-$CURRENT_PROJECT_VERSION.tar.xz" -C "/tmp/sparkle-extract"
|
||||
else
|
||||
# Fallback to bz2 compression if xz utility is not available
|
||||
find . \! -type d | rev | sort | rev | tar cjvf "../Sparkle-$CURRENT_PROJECT_VERSION.tar.bz2" --files-from=-
|
||||
|
||||
# Extract archive for testing binary validity
|
||||
tar -xf "../Sparkle-$CURRENT_PROJECT_VERSION.tar.bz2" -C "/tmp/sparkle-extract"
|
||||
fi
|
||||
|
||||
# Test code signing validity of the extracted products
|
||||
# This guards against our archives being corrupt / created incorrectly
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/Sparkle.framework"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/XPCServices/org.sparkle-project.Downloader.xpc"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/XPCServices/org.sparkle-project.InstallerConnection.xpc"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/XPCServices/org.sparkle-project.InstallerLauncher.xpc"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/XPCServices/org.sparkle-project.InstallerStatus.xpc"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/sparkle.app"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/Sparkle Test App.app"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/bin/BinaryDelta"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/bin/generate_appcast"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/bin/sign_update"
|
||||
codesign --verify -vvv --deep "/tmp/sparkle-extract/bin/generate_keys"
|
||||
|
||||
rm -rf "/tmp/sparkle-extract"
|
||||
find . \! -type d | rev | sort | rev | tar cv --files-from=- | xz -9 > "../Sparkle-$CURRENT_PROJECT_VERSION.tar.xz"
|
||||
rm -rf "$CONFIGURATION_BUILD_DIR/staging"
|
||||
|
||||
# Generate zip containing the xcframework for SPM
|
||||
@@ -121,7 +57,7 @@ if [ "$ACTION" = "" ] ; then
|
||||
if [ "$CI" != true ]; then
|
||||
# Get latest git tag
|
||||
cd "$SRCROOT"
|
||||
latest_git_tag=$(git describe --tags --abbrev=0)
|
||||
latest_git_tag=$(git describe --abbrev=0)
|
||||
# Check semantic versioning
|
||||
if [[ $latest_git_tag =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
|
||||
echo "Tag $latest_git_tag follows semantic versioning"
|
||||
@@ -149,10 +85,5 @@ if [ "$ACTION" = "" ] ; then
|
||||
else
|
||||
echo "warning: Xcode version $XCODE_VERSION_ACTUAL does not support computing checksums for Swift Packages. Please update the Package manifest manually."
|
||||
fi
|
||||
|
||||
if [ "$XZ_EXISTS" -eq 1 ] ; then
|
||||
echo "WARNING: xz compression is used for official releases but bz2 is being used instead because xz tool is not installed on your system."
|
||||
fi
|
||||
|
||||
rm -rf "$CONFIGURATION_BUILD_DIR/staging-spm"
|
||||
fi
|
||||
@@ -2,7 +2,7 @@
|
||||
set -e
|
||||
|
||||
# Convenience script to automatically commit Package.swift after updating the checksum and move the latest tag
|
||||
latest_git_tag=$(git describe --abbrev=0) # gets the latest tag name
|
||||
latest_git_tag=$(git describe --abbrev=0 --tags) # gets the latest tag name
|
||||
commits_since_tag=$(git rev-list ${latest_git_tag}.. --count)
|
||||
if [ "$commits_since_tag" -gt 0 ]; then
|
||||
# If there have been commits since the latest tag, it's highly likely that we did not intend to do a full release
|
||||
@@ -15,12 +15,9 @@ else
|
||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
echo "Package.swift has not been committed and tag has not been moved."
|
||||
else
|
||||
long_message=$(git tag -n99 -l $latest_git_tag) # gets corresponding message
|
||||
long_message=${long_message/$latest_git_tag} # trims tag name
|
||||
long_message="$(echo -e "${long_message}" | sed -e 's/^[[:space:]]*//')" # trim leading whitespace
|
||||
git add Package.swift
|
||||
git commit -m "Update Package.swift"
|
||||
git tag -fa $latest_git_tag -m "${long_message}"
|
||||
git tag -f $latest_git_tag
|
||||
echo "Package.swift committed and tag '$latest_git_tag' moved."
|
||||
fi
|
||||
fi
|
||||
@@ -9,7 +9,7 @@ if [ -z "$SRCROOT" ] || \
|
||||
[ -z "$BUILT_PRODUCTS_DIR" ] || \
|
||||
[ -z "$INFOPLIST_PATH" ] || \
|
||||
[ -z "$CURRENT_PROJECT_VERSION" ]; then
|
||||
echo "$0: Must be run from Xcode!" 1>&2
|
||||
echo "$0: Must be run from Xcode!" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
# Design Practices
|
||||
|
||||
## XPC Services
|
||||
|
||||
XPC services in Sparkle are all optional, so the code involved in the services needs to be usable directly from the framework as well. For this to work well, if the class used in the XPC service takes a delegate, it must not be weakly referenced, so the retain cycle will have to be broken explicitly (via an explicit added invalidate method). dealloc also must not be implemented (do cleanup in custom invalidate method). As one may tell, a couple of the services are simply proxies (InstallerConnection, InstallerStatus), and I wish that didn't have to be the case -- it would be a burden to require a developer to set up a temporary exception with a specific bundle ID, and unsure how long that approach would work for in the future.
|
||||
|
||||
The protocols used in XPC services must also not adopt other protocols (i.e, one protocol inheriting from another protocol). This is because the XPC protocol decoder on older supported systems doesn't properly handle this case, and won't be able to find that methods exist on a class.
|
||||
|
||||
## Singletons
|
||||
|
||||
Singletons and other global mutable variables have been either removed entirely or completely avoided with an exception to backwards compatibility. They have no place in a well architectured framework.
|
||||
|
||||
`SPUUpdater` doesn't maintain singleton instances and can now be properly deconstructed. Note because a caller is not expected to explicitly invalidate an updater, this means that the updater needs to avoid geting into a retain cycle. Intermediate clasess were created for the update cycle and schedule timer to avoid just this.
|
||||
|
||||
One may argue that we shouldn't allow multiple live updaters running at the same bundle simutaneously, but I disagree and I think that is missing the point. It also does not account for updaters running external to the process. For example, it may be perfectly reasonable to start an update from `sparkle-cli` that defers the installation until quit, and have the application that is being updated be able to resume that installation and relaunch immediately.
|
||||
|
||||
The original `SUUpdater` may have also been created to assist plug-ins and other non-app bundles. My advice there is in order to be truely safe, you must not inject a framework like Sparkle into the host application anyway. An external tool that is bundled like `sparkle-cli` may be more appropriate to use here.
|
||||
|
||||
## Extensibility
|
||||
|
||||
This fork does not support subclassing classes internal (not exported) to Sparkle anymore. Doing so would be almost impossible to maintain into the future. Subclassing in general has been banned in this fork. Composition is prefered everywhere, even amongst the internal update drivers which were rewritten to follow a protocol oriented approach. The reason why composition is preferred is because it's easier to follow the flow of logic.
|
||||
|
||||
I hope the user driver API gives enough extensibility without someone wanting to create another fork.
|
||||
|
||||
## Delegation
|
||||
|
||||
Newer classes, other than assisting backwards compatibility, that support delegation don't pass the delegator around anymore. Doing so has some [bad consequences](https://zgcoder.net/ramblings/avoid-passing-the-delegator) and makes code hard to maintain.
|
||||
|
||||
Optional delegate methods that have return types need to be optional or have known default values for primitive types.
|
||||
|
||||
You may notice that the delegate and user driver are not accessible as properties from `SPUUpdater`. This is intentional. The methods that belong to these types aren't meaningful to any caller except from internal classes.
|
||||
|
||||
## Decoupling
|
||||
|
||||
Two software components should not directly know about each other. Preferrably they wouldn't know about each other at all, but if they must, they can use the delegation pattern with a declared protocol.
|
||||
|
||||
See `Documentation/graph-of-sparkle.png` for a graph of how the code looks like currently. This was generated via [objc_dep](https://github.com/nst/objc_dep) (great tool). Note that there are no red edges which would mean that two nodes know of each other.
|
||||
|
||||
## Attributes
|
||||
|
||||
`nonatomic` should really be used wherever possible with regards to obj-c properties (`atomic` is a bad default). `readonly` should be used wherever possible as well, which also implies that only ivar access should be used in initializers. `NS_ASSUME_NONNULL_BEGIN` and `NS_ASSUME_NONNULL_END` should be used around new headers whenever possible. AppKit prevention guards should be used for any non-UI class whenever possible.
|
||||
@@ -1,137 +0,0 @@
|
||||
# Details on Installer IPC & Security
|
||||
|
||||
## Important components:
|
||||
|
||||
* The bundle to update & replace
|
||||
* The application to listen for termination & to relaunch. This can be the same bundle as the one being updated, but this doesn't have to be the case (eg: the bundle being updated could be a plug-in that is hosted by another application).
|
||||
* The updater that lives in Sparkle.framework - this schedules & downloads updates and starts the installer. This updater's life can be tied to the application's lifetime, but this doesn't have to be the case.
|
||||
* The installer (Autoupdate) which does all the extraction, validation, and installation work. This program is submitted by the updater and is run as a launchd agent or daemon, depending on the type of installation and if elevated permissions are needed to perform the update.
|
||||
* The progress or agent application which hosts the installation status service and is also responsible for showing UI if the installation takes a sufficiently long period of time, as well as responsible for launching the new update.
|
||||
|
||||
## After downloading the update:
|
||||
|
||||
### Launching the Installer
|
||||
SPUCoreBasedUpdateDriver invokes SPUInstallerDriver's extraction method which invokes SUInstallerLauncher's launch installer method. The launcher can be inside a XPC service or running inside the updater/sparkle framework itself. The launcher XPC bundle includes a copy of the installer and agent application in its bundle so it can compute the path to them itself (instead of relying on the updater to pass the paths), which is for security trust reasons.
|
||||
|
||||
First, the launcher makes sure that if the updater delegate doesn't allow interaction, that installation can be done without interaction. If it can't, then the launcher fails. If the updater driver that invoked the launcher doesn't allow for interaction (in particular, the automatic/silent update driver does not allow interaction), then the launcher fails with a hint to try again with interaction enabled (in particular, with a UI based update driver). If this happens, the updater keeps a reference to the downloaded update and appcast item that is used for resuming with a UI based update driver later. The launcher in this case is telling that authorization can only be done if interaction is allowed from the driver, so the user can enter their password to start up the installer as root to install over a location that requires such privileges.
|
||||
|
||||
The launcher then looks for the installer and agent application first in its bundle's auxiliary directory path, and then its resources path. If the launcher is running inside a XPC service, the tools will be in the auxiliary path location, which allows the developer using the service to also code sign the tools. Once those paths are found, the launcher copies the progress agent application to a temporary cache location. The installer is not copied because it is a plain single executable that does not rely on external relative depedencies, whereas the agent application relies on bundle resources. This is important to consider because the old application may be moved around and removed when the installation process occurs. Leaving the installer inside its bundle also could leave it in a place the user doesn't necessarily have write privileges to.
|
||||
|
||||
The installer is first submitted. If it requires root privileges, it will ask for an admin user name and password. How it determines if root privileges are necessary is based on:
|
||||
|
||||
* If the installation type from the appcast is an interactive package based installer, then no root privileges are necessary because the package installer will ask for them. Note this type of installation is deprecated however.
|
||||
* If the installation type from the appcast is a guided or regular package based installer, then root privileges are necessary because the system installer utility has to run as root.
|
||||
* Otherwise the installation type is a normal application update, and root privileges are only needed if write permission or changing the owner/group is currently insufficient.
|
||||
|
||||
The installer makes sure, after extraction, that the expected installation type from the appcast matches the type of installation found within the archive. So this hint from the appcast is not just trusted implicitly.
|
||||
|
||||
If the user cancels submitting the installer on authorization (if it's required), the launcher aborts the installation process silently. If everything does alright, the progress agent application is submitted next. If either of the submissions fail, the installation fails and aborts, otherwise the launcher succeeds and its job is done. Note before the submissions are done, the jobs are removed from launchd, and the jobs are submitted in a way that act as "one-time" jobs. If they fail or succeed, the jobs aren't restarted, and the jobs aren't installed in a system location for launchd to attempt launching again.
|
||||
|
||||
The only argument passed to the installer is the host bundle identifier of the bundle to update. This bundle identifier is used so that the installer and updater know what Mach service to connect to for IPC. Everything else to the installer is sent via a XPC connection. The host bundle path is passed to the progress agent, which is just used for obtaining the bundle identifier, and for UI purposes (eg: displaying app icon and name when the app needs to show progress). The type of domain the installer is running in (user vs system) is also passed to the progress agent application so it can know which domain to use to connect to the installer.
|
||||
|
||||
### Timeouts
|
||||
|
||||
Upon starting the progress agent, it tries to establish a connection to the installer and send a "hello" message expecting a reply back. If a reply isn't received back within a certain threshold, the agent application aborts (unless it's already planning to terminate in the near future after relaunching the new update).
|
||||
|
||||
If the installer doesn't receive the "hello" message from the agent in a certain threshold, the installer aborts. If the installer doesn't receive the installation input data from the data in a certain threshold also, it aborts there too. If the installer aborts and the agent is connected to the installer, the agent will abort as well.
|
||||
|
||||
When the updater attempts to set up a connection to the installer, after a certain threshold, if the installation hasn't progressed from not beginning (i.e, extraction hasn't begun), then the updater aborts the installation.
|
||||
|
||||
Note, we don't have a "version tag" for the installer or agent because they are either bundled inside the framework or in the XPC service, and the XPC service already has a version check of its own.
|
||||
|
||||
### Installation Data
|
||||
After the installer launches, the updater creates a connection to the installer and sends installation data to the installer using the `SPUInstallationData` message. This data includes the bundle application path to relaunch, the path to the bundle to update and replace, DSA signature from the appcast item, decryption password for dmg if available, the path to the downloaded directory and name of the downloaded item, and the type of expected installation.
|
||||
|
||||
The installer takes note of all this information, but it moves the downloaded item into a update directory it chooses for itself. This is for two reasons:
|
||||
|
||||
1. If the installer is running at a higher level than the process that submitted it (eg: sandboxed -> user, or user -> root), it make sense from a security perspective to move the file into its own support directory. This could prevent an attacker from manipulating the download while the installer is using it.
|
||||
2. The updater, or another updater running, or someone else probably won't accidently remove the downloaded item if the installer decides to 'own' it.
|
||||
|
||||
After the installer moves the downloaded item, it makes sure the item is not a symbolic link. If it is a non-regular file, the installer aborts, causing the updater to abort as well. Note this check is done after the move rather than before due to potential race conditions an attacker could create.
|
||||
|
||||
### Update Extraction
|
||||
After the installer receives the input installation data, it starts extracting the update. The installer first sends a `SPUExtractionStarted` message.
|
||||
|
||||
If the unarchiver requires DSA validation before extraction (binary delta archives do) or if the expected installation type is a package type, then before starting the unarchiver, validation is checked to make sure the signature for the archive is valid. If the signature is not valid, then a `SPUArchiveExtractionFailed` message is sent to the updater (see below on what happens after that). We can't require validation before extracting for normal application updates because they allow changes to DSA keys. Delta updates are fine however because if those fail, then a full update can be tried.
|
||||
|
||||
After extraction starts, one or more `SPUExtractedArchiveWithProgress` messages indicating the unarchival progress are sent back to the updater. On failure, the installer will send `SPUArchiveExtractionFailed`. In the updater, if the update is a delta update and extraction fails, then the full archive is downloaded and we go back to the "Sending Installation Data" section to re-send the data and begin extraction again. If the update is not a delta update and extraction fails on the other hand, then the updater aborts causing the installer to abort as well.
|
||||
|
||||
### Post Validation
|
||||
If the unarchiving succeeds, a `SPUValidationStarted` message is sent back to the updater, and the installer begins post validating the update.
|
||||
|
||||
If validation was already done before extraction, just the code signature is checked on the extracted bundle to make sure it's valid (if there's a code signature on the bundle). This is just a consistency check to make sure the developer didn't make a careless erorr.
|
||||
|
||||
If validation fails, the installer aborts, causing the updater to abort the update as well. Otherwise, the installer sends a message `SPUInstallationStartedStage1` to the updater and begins the installation.
|
||||
|
||||
### Retrieving Process Identifier
|
||||
|
||||
If the installer hasn't made a connection to the agent yet within the time threshold, the installer waits until a connection is made. Otherwise, the installer asks the agent for the process identifier of the application bundle that it wants to wait for termination. If the installer doesn't get a response within a certain threshold, the installer aborts.
|
||||
|
||||
When the installer gets the process identifier, it begins the installation. At this point on, the installer will try to perform the installation even if the connection to the updater or the connection to the agent invalidates.
|
||||
|
||||
### Starting the Installation
|
||||
|
||||
The installer figures out what kind of installer to use (regular, guided pkg, interactive pkg) based on the type of file inside the archive. If the type of file doesn't match the expected installation type from the input installation data, then the installer aborts causing the updater to abort as well.
|
||||
|
||||
Once the type of installer is found, the first stage of installation is performed:
|
||||
|
||||
* Regular application installer 1st stage: Makes sure this update is not a downgrade.
|
||||
* Guided Package installer 1st stage: Does nothing.
|
||||
* Interactive Package installer (deprecated) 1st stage: Makes sure /usr/bin/open utility is available.
|
||||
|
||||
If the first stage fails, the installer aborts causing the updater to abort the update.
|
||||
|
||||
Otherwise a `SPUInstallationFinishedStage1` message is sent back to the updater along with some data. This data includes whether the application bundle to relaunch is currently terminated, and whether the installation at later stages can be performed silently (that is, with no user interaction allowed). If we reach here, only the interactive package installer can't be performed silently.
|
||||
|
||||
The installer then listens and waits for the target application to relaunch terminates. If it is already terminated, then it resumes to stage 2 and 3 of the installation immediately on the assumption that the installer does not have permission to show UI interaction to the user. Thus if the installer has to show user interaction here and hasn't received an OK from the updater (it won't if the target application is already terminated), the install will fail. If the target is already terminated, the installer will also assume that the target should not be relaunched after installation.
|
||||
|
||||
### Installation Waiting Period
|
||||
The updater receives `SPUInstallationFinishedStage1` message. The updater sends a message `SPUSentUpdateAppcastItemData` with the appcast data in case the updater may request for it later (due to installer resumability, discussed later). It also reads if the target has already been terminated (implying that the installer will continue installing the update immediately), and if the installation will be done silently.
|
||||
|
||||
For UI based update drivers, the updater tells the user driver to show that the application is ready to be relaunched - the user can continue to install & relaunch the app. The user driver is only alerted however if the installation isn't happening immediately (that is, if the target application to relaunch is still alive). The user driver can decide whether to a) install b) install & relaunch or c) delay installation. If installation is delayed, it can be resumed later, or if the target application terminates, the installer will try to continue installation if it is capable to without user interaction.
|
||||
|
||||
For automatic based drivers, if the update is not going to be installed immediately and if it can be installed silently, the updater's delegate has a choice to handle the immediate installation of the update. If the delegate handles the installation, it can invoke a block that will trigger the automatic update driver to tell the installer to resume to stage 2 as detailed in step the "Continue to Installation" section - except without displaying any user interface and by relaunching the application afterwards. If the delegate handles the immediate installation, the automatic update driver will not abort, it will just leave the driver running until the installer requests for the app to be terminated later. This means the update can't be resumed later and the user driver won't be involved.
|
||||
|
||||
Otherwise if the updater delegate doesn't handle immediate installation for automatic based drivers (assuming still the update is not going to be installed immediately), the update driver is aborted; the installer will still wait for the target to terminate however. If the update cannot be silently installed or if the update is marked as critical from the appcast, the update procedure is actually 'resumed' as a scheduled UI based update driver immediately. The update driver can also be 'resumed' later when the user initiates for an update manually or when a long duration (I think a week) has passed by without the user terminating the application. Note automatic based drivers are unable to do a resume, so only UI based ones can.
|
||||
|
||||
If an update driver is resumed (which cannot happen if the target applicaton is already terminated by the way), then the updater first requests the installer for the appcast item data that the installer received before. The updater does this by creating a temporary distinct connection for the purpose of querying for the installation status. The connection will give up if a short timeout passes. If the updater fails to retrieve resume data, it assumes that there's no update to resume and will start back from the beginning. The updater can use this data for showing release notes, etc. Note the updater and target application don't have to live in the same process, and the updater could choose to terminate and resume later as a new process - so having the installer keep the appcast item data is nice.
|
||||
|
||||
Afterwards the resumed update driver then allows the user driver to decide whether to a) install the update now, b) install & relaunch the update, or to c) delay the update installation and abort the update driver. Note we are now back to the same options discussed earlier.
|
||||
|
||||
### Continue to Installation
|
||||
If the user driver decides to install the update, it sends a `SPUResumeInstallationToStage2` message to the installer and supplies whether the update should be relaunched, and whether user interface can be displayed. The user driver specifies that the user interface can be displayed as long as the updater delegate allows interaction. If the updater's delegate handles immediate installation in the automatic based update driver, UI cannot be displayed there too.
|
||||
|
||||
The installer receives `SPUResumeInstallationToStage2` and reads whether it should relaunch the target application and whether it can show UI (thus be allowed to show user interaction). The installer then resumes to stage 2 of the installation if it has not been performed already (that is if the target app already terminated). Note if the installer doesn't receive this message before the target application terminates, then the installer will not relaunch or show UI and resume stage 2 & 3 by itself. Again not displaying UI is only an issue for interactive based package installers which are deprecated.
|
||||
|
||||
If the 2nd stage succeeds, the installer sends a `SPUInstallationFinishedStage2` message back to the updater, including if the target application has already terminated at this time. If the target application has not already been terminated, the installer sends a request to the progress agent to *terminate* the application. By *terminate*, we mean sending an Apple quit event, allowing the application or user to possibly cancel or delay termination.
|
||||
|
||||
The updater receives a `SPUInstallationFinishedStage2` message, and reads if the target application had already been terminated. If the target application has not already terminated, the updater tells the user driver to show that the application is being sent a termination request.
|
||||
|
||||
### Showing Progress
|
||||
|
||||
When the target application is terminated, if the updater allowed the installer to show UI progress and the installation type doesn't show progress on its own (only interactive package installer shows progress on its own), then the installer sends a `SPUUpdaterAlivePing` message to the updater. If the updater is still alive by now and receives the message, the updater will then send back a `SPUUpdaterAlivePong` message. This lets the installer know that the updater is still active after the target application is terminated, and whether the installer should later be responsible for displaying updater progress or not if a short time passes by, and the installation is still not finished. If the updater is still not alive, then the installer should be responsible for showing progress if otherwise allowed.
|
||||
|
||||
If the installer decides to show progress, it sends a message to the progress agent to show progress UI. Under most circumstances, the installation will finish faster than this point is reached however (exceptions may be potentially large updates with many scattered files, guided package installers, and updates over a remote network mount). If the connection to the updater is still connected after this short time passes (eg: like with sparkle-cli), then it's the updater's job to show progress instead.
|
||||
|
||||
### Finishing the Installation
|
||||
The installer starts stage 3 of the installation after the target application is terminated as well. The third stage does the final installation for updating and replacing the new updated bundle.
|
||||
|
||||
If the third stage fails, then the installer aborts, causing the updater driver to abort if it's still running. The target application is not ever relaunched on failure.
|
||||
|
||||
Otherwise if the third stage succeeds, the installer sends a message to the agent to stop showing progress. The agent uses this hint to acknowledge that it should stop broadcasting the status info service for the updater. If the connection to the updater is still alive, a `SPUInstallationFinishedStage3` message is sent back to the updater and the updater driver silently aborts the update.
|
||||
|
||||
The installer then sends a message to the agent to relaunch the new application if the installer was requested to relaunch it. This also signals to the agent that it will terminate shortly. If the installer decides not to relaunch the update, the agent will terminate when its connection to the installer invalidates. The installer lastly does cleanup work by removing its update directory it was using and exits.
|
||||
|
||||
When the progress agent exits, it cleans up by removing itself from disk. The installer doesn't do that because the installer isn't copied to another location in the first place.
|
||||
|
||||
## Notes:
|
||||
|
||||
* Performing an update as the root user is not currently supported. The command line driver (minorly) and the agent application link to AppKit, and running the agent as a different user (i.e, dropping from root -> logged in user) is not particularly the most elegant idea.
|
||||
|
||||
* We use IPC in such a way that the installer process does not trust the updater process, which is why the installer does extraction, validation, and installation -- all in a single process. The launcher portion of code (which could be running as a XPC service) also does not trust the updater for determining the paths to the installer and agent tool. This portion of code does not check the code signing signature of the installer or agent though for reasons explained in the code.
|
||||
|
||||
* We have timeouts and ping/pong messages in various cases because we don't want to trust the other end very much for communicating back quickly. On older systems in my testing (eg: 10.8), connection invalidation events don't even get sent to the other end when interacting with launchd, possibly due a bug that is outputted in Console.app.
|
||||
|
||||
* When we terminate the application before doing final installation work, we send an Apple quit event to all running application instances we find under the agent's GUI login session. This does not include running instances from other logged in sessions -- that may require authenticating all the time, so trade off is not worthwhile. Also currently the installer only handles a single process identifier to watch for until termination, and certainly doesn't handle the case if more instances are launched afterwards. Note all of this only applies to instances being launched from the same bundle path, and the consequence may rarely be updating a bundle when a running instance is still left alive.
|
||||
|
||||
* SMJobBless() would be interesting to explore and perhaps more suitable for sparkle-cli than ordinary application updaters because using this API is less approriate for one-off installations. There may be some issues to take account of though (eg: http://www.openradar.me/20446733). Furthermore, the installer would have to change to persist rather than be a one-time install, and may have to handle mutliple connections for installing multiple bundles simutaneously.
|
||||
@@ -1,35 +0,0 @@
|
||||
# Security
|
||||
|
||||
First, some references I've found to be quite useful:
|
||||
|
||||
* WWDC 2010 video on "Creating Secure Applications" - [asciiwwdc](http://asciiwwdc.com/2010/sessions/204?q=security).
|
||||
* [EvenBetterAuthorizationExample](https://developer.apple.com/library/mac/samplecode/EvenBetterAuthorizationSample/Introduction/Intro.html) sample code by Apple for showing off privileged authorization as well as in sandboxed applications.
|
||||
* Apple's [Daemons and Agents Technote](https://developer.apple.com/library/mac/technotes/tn2083/_index.html). Outdated and before XPC existed, but insightful.
|
||||
|
||||
This fork puts a huge emphasis on splitting Sparkle into several components to achieve privilege separation.
|
||||
|
||||
* User Driver (Application; AppKit permitted)
|
||||
* Updater Scheduler (Framework)
|
||||
* XPC Services (Instead of some portions of Framework)
|
||||
* Progress Agent (Application; AppKit permitted)
|
||||
* Installer (Agent and Daemon safe)
|
||||
|
||||
These achieve privilege separation, because at least theoretically, they can all be placed into different processes from one another, although in practice the user driver and updater framework will likely be in the same process.
|
||||
|
||||
For XPC Services, it's significant to understand they can be used independent of sandboxing (although I wouldn't recommend this personally). Besides privilege separation, they also have an impact on fault tolerance and termination.
|
||||
|
||||
XPC Services also act inside an application bundle namespace, which is one of many reasons why they aren't bundled inside the framework. We have code that detects whether or not services are available inside the main bundle. This is simpler and more efficient than attempting to create a connection and wait for a timeout. We don't have *any* checks for seeing if the "current process" is sandboxed; doing so is a rather broken behavior. The XPC Services are important, not the sandboxing.
|
||||
|
||||
I said above that XPC services are looked up in the main bundle. One may think this assumption doesn't hold for helpers or plug-ins inside applications. My response to that is they probably don't need the services, and they probably shoudn't be injecting Sparkle inside the host application anyway due to unintended conflicts and other consequences. A more appropriate approach may be to bundle a separate tool such as the sparkle command line utility.
|
||||
|
||||
The `InstallerLauncher` XPC service needs a `JoinExistingSession` key set to `YES` otherwise authorization will not work properly, and even less so on older systems. It took me forever to debug this, so it's worth mentioning.
|
||||
|
||||
When developing this fork, I still had a huge hole in the privilege separation even after supporting XPC Services and sandboxing. I fixed that by removing references to `AuthorizationExecuteWithPrivileges` and submitting a launchd agent/daemon for the installer. This is overlooked, but absolutely essential for our model to be secure.
|
||||
|
||||
When communicating to a launchd job, we've several options to use for IPC such as BSD Sockets, Mach ports, XPC (note: XPC is an IPC API and is != "XPC Services"), and file IO. The technote I linked above describes why Mach ports have user namespace issues and why BSD sockets may be preferred over them. However, now, XPC which allows you to choose which domain to look up is the simplest, best, and most modern choice. It's crucial in any event we don't have a daemon (running in system domain) try to *connect* to something in the user domain. Our launchd tasks should also be connected to rather than the other way around. As for communication via file IO, I just wouldn't go anywhere close to trusting such a model mixing in system and user running processes.
|
||||
|
||||
For sending Obj-C objects across the wire, we use `SPUSecureCoding` because Cocoa doesn't support sending objects securely out of the box unless working with XPC Services. It's very important the objects implement `NSSecureCoding` and whitelist types that are expected to be decoded, as well as whitelist types inside collections before decoding them.
|
||||
|
||||
The installer handles extraction, validation, and installation of the update. This was the main reason why other forks were rejected from being secure. The point to be stressed anyway is that these all need to be done in the same process; they can't be handed off by some other process. This is also why removing references to `AuthorizationExecuteWithPrivileges` is crucial as well.
|
||||
|
||||
Note that the installer does *not* handle downloading. That is handled by the updater framework. This is ideal because downloading can be done without disrupting the user, allowing it to be done silently without presenting an authorization dialog. The downloading portion of code can also be stuck into a XPC service with just an entitlement for allowing incoming connections. This also means for secure installations the installer cannot know (or trust) what protocol the update was downloaded from (i.e: http vs https). A good installer will not care, which is why applying updates without a DSA signature/key is now deprecated (reminder that Apple's code signature checks are not intended for complete integrity).
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.2 MiB |
@@ -1,38 +0,0 @@
|
||||
<?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>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<false/>
|
||||
</dict>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Sparkle Project. All rights reserved.</string>
|
||||
<key>XPCService</key>
|
||||
<dict>
|
||||
<key>ServiceType</key>
|
||||
<string>Application</string>
|
||||
<key>RunLoopType</key>
|
||||
<string>NSRunLoop</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,280 +0,0 @@
|
||||
//
|
||||
// SPUDownloader.m
|
||||
// Downloader
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/1/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SPUDownloader.h"
|
||||
#import "SPUDownloaderDelegate.h"
|
||||
#import "SPULocalCacheDirectory.h"
|
||||
#import "SPUURLRequest.h"
|
||||
#import "SPUDownloadData.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
typedef NS_ENUM(NSUInteger, SPUDownloadMode)
|
||||
{
|
||||
SPUDownloadModePersistent,
|
||||
SPUDownloadModeTemporary
|
||||
};
|
||||
|
||||
static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
|
||||
@interface SPUDownloader () <NSURLSessionDownloadDelegate>
|
||||
|
||||
// Delegate is intentionally strongly referenced; see header
|
||||
@property (nonatomic) id <SPUDownloaderDelegate> delegate;
|
||||
@property (nonatomic) NSURLSessionDownloadTask *download;
|
||||
@property (nonatomic) NSURLSession *downloadSession;
|
||||
@property (nonatomic, copy) NSString *bundleIdentifier;
|
||||
@property (nonatomic, copy) NSString *desiredFilename;
|
||||
@property (nonatomic, copy) NSString *downloadFilename;
|
||||
@property (nonatomic) BOOL disabledAutomaticTermination;
|
||||
@property (nonatomic) SPUDownloadMode mode;
|
||||
@property (nonatomic) BOOL receivedExpectedBytes;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUDownloader
|
||||
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize download = _download;
|
||||
@synthesize downloadSession = _downloadSession;
|
||||
@synthesize bundleIdentifier = _bundleIdentifier;
|
||||
@synthesize desiredFilename = _desiredFilename;
|
||||
@synthesize downloadFilename = _downloadFilename;
|
||||
@synthesize disabledAutomaticTermination = _disabledAutomaticTermination;
|
||||
@synthesize mode = _mode;
|
||||
@synthesize receivedExpectedBytes = _receivedExpectedBytes;
|
||||
|
||||
- (instancetype)initWithDelegate:(id <SPUDownloaderDelegate>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_delegate = delegate;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startDownloadWithRequest:(SPUURLRequest *)request
|
||||
{
|
||||
self.downloadSession = [NSURLSession
|
||||
sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
|
||||
delegate:self
|
||||
delegateQueue:[NSOperationQueue mainQueue]];
|
||||
self.download = [self.downloadSession downloadTaskWithRequest:request.request];
|
||||
[self.download resume];
|
||||
}
|
||||
|
||||
// Don't implement dealloc - make the client call cleanup, which is the only way to remove the reference cycle from the delegate anyway
|
||||
|
||||
- (void)startPersistentDownloadWithRequest:(SPUURLRequest *)request bundleIdentifier:(NSString *)bundleIdentifier desiredFilename:(NSString *)desiredFilename
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.download == nil && self.delegate != nil) {
|
||||
// Prevent service from automatically terminating while downloading the update asynchronously without any reply blocks
|
||||
[[NSProcessInfo processInfo] disableAutomaticTermination:SUDownloadingReason];
|
||||
self.disabledAutomaticTermination = YES;
|
||||
|
||||
self.mode = SPUDownloadModePersistent;
|
||||
self.desiredFilename = desiredFilename;
|
||||
self.bundleIdentifier = bundleIdentifier;
|
||||
|
||||
[self startDownloadWithRequest:request];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)startTemporaryDownloadWithRequest:(SPUURLRequest *)request
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.download == nil && self.delegate != nil) {
|
||||
// Prevent service from automatically terminating while downloading the update asynchronously without any reply blocks
|
||||
[[NSProcessInfo processInfo] disableAutomaticTermination:SUDownloadingReason];
|
||||
self.disabledAutomaticTermination = YES;
|
||||
|
||||
self.mode = SPUDownloadModeTemporary;
|
||||
[self startDownloadWithRequest:request];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)enableAutomaticTermination
|
||||
{
|
||||
if (self.disabledAutomaticTermination) {
|
||||
[[NSProcessInfo processInfo] enableAutomaticTermination:SUDownloadingReason];
|
||||
self.disabledAutomaticTermination = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)rootPersistentDownloadCachePathForBundleIdentifier:(NSString *)bundleIdentifier
|
||||
{
|
||||
return [[SPULocalCacheDirectory cachePathForBundleIdentifier:bundleIdentifier] stringByAppendingPathComponent:@"PersistentDownloads"];
|
||||
}
|
||||
|
||||
- (void)removeDownloadDirectory:(NSString *)directoryName bundleIdentifier:(NSString *)bundleIdentifier
|
||||
{
|
||||
// Only take the directory name and compute most of the base path ourselves
|
||||
// This way we do not have to send/trust an absolute path
|
||||
// The downloader instance that creates this temp directory isn't necessarily the same as the one
|
||||
// that clears it (eg upon skipping an already downloaded update), so we can't just preserve it here too
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSString *rootPersistentDownloadCachePath = [self rootPersistentDownloadCachePathForBundleIdentifier:bundleIdentifier];
|
||||
if (rootPersistentDownloadCachePath != nil) {
|
||||
NSString *sanitizedDirectoryName = directoryName.lastPathComponent;
|
||||
NSString *tempDir = [rootPersistentDownloadCachePath stringByAppendingPathComponent:sanitizedDirectoryName];
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtPath:tempDir error:NULL];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)_cleanup
|
||||
{
|
||||
[self enableAutomaticTermination];
|
||||
[self.download cancel];
|
||||
[self.downloadSession finishTasksAndInvalidate];
|
||||
self.download = nil;
|
||||
self.downloadSession = nil;
|
||||
self.delegate = nil;
|
||||
|
||||
if (self.mode == SPUDownloadModeTemporary && self.downloadFilename != nil)
|
||||
{
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:NULL];
|
||||
self.downloadFilename = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cleanup:(void (^)(void))completionHandler
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self _cleanup];
|
||||
|
||||
completionHandler();
|
||||
});
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession *)__unused session downloadTask:(NSURLSessionDownloadTask *)__unused downloadTask didFinishDownloadingToURL:(NSURL *)location
|
||||
{
|
||||
if (self.mode == SPUDownloadModeTemporary)
|
||||
{
|
||||
self.downloadFilename = location.path;
|
||||
[self downloadDidFinish]; // file is already in a system temp dir
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove our old caches path so we don't start accumulating files in there
|
||||
NSString *rootPersistentDownloadCachePath = [self rootPersistentDownloadCachePathForBundleIdentifier:self.bundleIdentifier];
|
||||
|
||||
[SPULocalCacheDirectory removeOldItemsInDirectory:rootPersistentDownloadCachePath];
|
||||
|
||||
NSString *tempDir = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:rootPersistentDownloadCachePath];
|
||||
if (tempDir == nil)
|
||||
{
|
||||
// Okay, something's really broken with this user's file structure.
|
||||
[self.download cancel];
|
||||
self.download = nil;
|
||||
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.", tempDir] }];
|
||||
|
||||
[self.delegate downloaderDidFailWithError:error];
|
||||
} else {
|
||||
NSString *downloadFileName = self.desiredFilename;
|
||||
NSString *downloadFileNameDirectory = [tempDir stringByAppendingPathComponent:downloadFileName];
|
||||
|
||||
NSError *createError = nil;
|
||||
if (![[NSFileManager defaultManager] createDirectoryAtPath:downloadFileNameDirectory withIntermediateDirectories:NO attributes:nil error:&createError]) {
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a download file name %@ directory inside temporary directory for the update download at %@.", downloadFileName, downloadFileNameDirectory] }];
|
||||
|
||||
[self.delegate downloaderDidFailWithError:error];
|
||||
} else {
|
||||
NSString *name = self.download.response.suggestedFilename;
|
||||
if (!name) {
|
||||
name = location.lastPathComponent; // This likely contains nothing useful to identify the file (e.g. CFNetworkDownload_87LVIz.tmp)
|
||||
}
|
||||
NSString *toPath = [downloadFileNameDirectory stringByAppendingPathComponent:name];
|
||||
NSString *fromPath = location.path; // suppress moveItemAtPath: non-null warning
|
||||
NSError *error = nil;
|
||||
if ([[NSFileManager defaultManager] moveItemAtPath:fromPath toPath:toPath error:&error]) {
|
||||
self.downloadFilename = toPath;
|
||||
[self.delegate downloaderDidSetDestinationName:name temporaryDirectory:downloadFileNameDirectory];
|
||||
[self downloadDidFinish];
|
||||
} else {
|
||||
[self.delegate downloaderDidFailWithError:error];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession *)__unused session downloadTask:(NSURLSessionDownloadTask *)__unused downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)__unused totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
|
||||
{
|
||||
|
||||
if (self.mode == SPUDownloadModePersistent && totalBytesExpectedToWrite > 0 && !self.receivedExpectedBytes) {
|
||||
self.receivedExpectedBytes = YES;
|
||||
[self.delegate downloaderDidReceiveExpectedContentLength:totalBytesExpectedToWrite];
|
||||
}
|
||||
|
||||
if (self.mode == SPUDownloadModePersistent && bytesWritten >= 0) {
|
||||
[self.delegate downloaderDidReceiveDataOfLength:(uint64_t)bytesWritten];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish
|
||||
{
|
||||
assert(self.downloadFilename != nil);
|
||||
|
||||
SPUDownloadData *downloadData = nil;
|
||||
if (self.mode == SPUDownloadModeTemporary) {
|
||||
NSData *data = [NSData dataWithContentsOfFile:self.downloadFilename];
|
||||
if (data != nil) {
|
||||
NSURLResponse *response = self.download.response;
|
||||
assert(response != nil);
|
||||
|
||||
NSURL *responseURL = response.URL;
|
||||
if (responseURL == nil) {
|
||||
responseURL = self.download.currentRequest.URL;
|
||||
}
|
||||
if (responseURL == nil) {
|
||||
responseURL = self.download.originalRequest.URL;
|
||||
}
|
||||
assert(responseURL != nil);
|
||||
|
||||
downloadData = [[SPUDownloadData alloc] initWithData:data URL:responseURL textEncodingName:response.textEncodingName MIMEType:response.MIMEType];
|
||||
}
|
||||
}
|
||||
|
||||
self.download = nil;
|
||||
|
||||
switch (self.mode) {
|
||||
case SPUDownloadModeTemporary:
|
||||
if (downloadData != nil) {
|
||||
[self.delegate downloaderDidFinishWithTemporaryDownloadData:downloadData];
|
||||
} else {
|
||||
[self.delegate downloaderDidFailWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read temporary downloaded data from %@", self.downloadFilename]}]];
|
||||
}
|
||||
|
||||
[self _cleanup];
|
||||
break;
|
||||
case SPUDownloadModePersistent:
|
||||
[self.delegate downloaderDidFinishWithTemporaryDownloadData:nil];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession *)__unused session task:(NSURLSessionTask *)__unused task didCompleteWithError:(NSError *)error
|
||||
{
|
||||
self.download = nil;
|
||||
if (error != nil) {
|
||||
[self.delegate downloaderDidFailWithError:error];
|
||||
}
|
||||
}
|
||||
|
||||
// NSURLDownload has a [downlaod:shouldDecodeSourceDataOfMIMEType:] to determine if the data should be decoded.
|
||||
// This does not exist for NSURLSessionDownloadTask and appears unnecessary. Data tasks will decode data, but not download tasks.
|
||||
|
||||
@end
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// main.m
|
||||
// PersistentDownloader
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/1/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SPUDownloader.h"
|
||||
#import "SPUDownloaderDelegate.h"
|
||||
|
||||
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
|
||||
@end
|
||||
|
||||
@implementation ServiceDelegate
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
|
||||
// This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
|
||||
|
||||
// Configure the connection.
|
||||
// First, set the interface that the exported object implements.
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SPUDownloaderProtocol)];
|
||||
|
||||
// Then set remote object interface
|
||||
newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SPUDownloaderDelegate)];
|
||||
|
||||
// Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
|
||||
SPUDownloader *exportedObject = [[SPUDownloader alloc] initWithDelegate:newConnection.remoteObjectProxy];
|
||||
newConnection.exportedObject = exportedObject;
|
||||
|
||||
// Resuming the connection allows the system to deliver more incoming messages.
|
||||
[newConnection resume];
|
||||
|
||||
// Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int main(int __unused argc, const char * __unused argv[])
|
||||
{
|
||||
// Create the delegate for the service.
|
||||
ServiceDelegate *delegate = [ServiceDelegate new];
|
||||
|
||||
// Set up the one NSXPCListener for this service. It will handle all incoming connections.
|
||||
NSXPCListener *listener = [NSXPCListener serviceListener];
|
||||
listener.delegate = delegate;
|
||||
|
||||
// Resuming the serviceListener starts this service. This method does not return.
|
||||
[listener resume];
|
||||
return 0;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?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.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,5 +0,0 @@
|
||||
For integration and usage, please visit Sparkle's Documentation:
|
||||
https://sparkle-project.org/documentation/
|
||||
|
||||
For integrating XPC Services in a Sandboxed Application, please visit:
|
||||
https://sparkle-project.org/documentation/sandboxing/
|
||||
@@ -1,31 +0,0 @@
|
||||
<?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>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Sparkle Project. All rights reserved.</string>
|
||||
<key>XPCService</key>
|
||||
<dict>
|
||||
<key>ServiceType</key>
|
||||
<string>Application</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,19 +0,0 @@
|
||||
//
|
||||
// SUInstallerCommunicationProtocol.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/9/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUInstallerCommunicationProtocol
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,22 +0,0 @@
|
||||
//
|
||||
// SUInstallerConnection.h
|
||||
// InstallerConnection
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/9/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerConnectionProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection.
|
||||
@interface SUInstallerConnection : NSObject <SUInstallerConnectionProtocol>
|
||||
|
||||
// Due to XPC reasons, this delegate is strongly referenced, until it's invalidated
|
||||
- (instancetype)initWithDelegate:(id<SUInstallerCommunicationProtocol>)delegate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,115 +0,0 @@
|
||||
//
|
||||
// SUInstallerConnection.m
|
||||
// InstallerConnection
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/9/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUInstallerConnection.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection Keep Alive";
|
||||
|
||||
@interface SUInstallerConnection () <SUInstallerCommunicationProtocol>
|
||||
|
||||
// Intentionally not weak for XPC reasons
|
||||
@property (nonatomic) id<SUInstallerCommunicationProtocol> delegate;
|
||||
|
||||
@property (nonatomic) BOOL disabledAutomaticTermination;
|
||||
@property (nonatomic, copy) void (^invalidationBlock)(void);
|
||||
@property (nonatomic) NSXPCConnection *connection;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUInstallerConnection
|
||||
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize disabledAutomaticTermination = _disabledAutomaticTermination;
|
||||
@synthesize invalidationBlock = _invalidationBlock;
|
||||
@synthesize connection = _connection;
|
||||
|
||||
- (instancetype)initWithDelegate:(id<SUInstallerCommunicationProtocol>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_delegate = delegate;
|
||||
|
||||
// If we are a XPC service, protect it from being terminated until the invalidation handler is set
|
||||
_disabledAutomaticTermination = YES;
|
||||
[[NSProcessInfo processInfo] disableAutomaticTermination:SUInstallerConnectionKeepAliveReason];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)enableAutomaticTermination
|
||||
{
|
||||
if (self.disabledAutomaticTermination) {
|
||||
[[NSProcessInfo processInfo] enableAutomaticTermination:SUInstallerConnectionKeepAliveReason];
|
||||
self.disabledAutomaticTermination = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler
|
||||
{
|
||||
self.invalidationBlock = invalidationHandler;
|
||||
|
||||
// No longer needed because of invalidation callback
|
||||
[self enableAutomaticTermination];
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
NSXPCConnectionOptions options = systemDomain ? NSXPCConnectionPrivileged : 0;
|
||||
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:serviceName options:options];
|
||||
|
||||
connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
connection.exportedObject = self.delegate;
|
||||
|
||||
connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
|
||||
self.connection = connection;
|
||||
|
||||
__weak SUInstallerConnection *weakSelf = self;
|
||||
self.connection.interruptionHandler = ^{
|
||||
[weakSelf.connection invalidate];
|
||||
};
|
||||
|
||||
self.connection.invalidationHandler = ^{
|
||||
SUInstallerConnection *strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
strongSelf.connection = nil;
|
||||
[strongSelf invalidate];
|
||||
}
|
||||
};
|
||||
|
||||
[self.connection resume];
|
||||
}
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
{
|
||||
[(id<SUInstallerCommunicationProtocol>)self.connection.remoteObjectProxy handleMessageWithIdentifier:identifier data:data];
|
||||
}
|
||||
|
||||
// This method can be called by us or from a remote
|
||||
- (void)invalidate
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.connection invalidate];
|
||||
self.connection = nil;
|
||||
|
||||
if (self.invalidationBlock != nil) {
|
||||
self.invalidationBlock();
|
||||
self.invalidationBlock = nil;
|
||||
}
|
||||
|
||||
// Break the retain cycle
|
||||
self.delegate = nil;
|
||||
|
||||
[self enableAutomaticTermination];
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,28 +0,0 @@
|
||||
//
|
||||
// SUInstallerConnectionProtocol.h
|
||||
// InstallerConnection
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/9/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerCommunicationProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUInstallerConnectionProtocol
|
||||
|
||||
// This method is declared in SUInstallerCommunicationProtocol too
|
||||
// the XPC decoder on macOS 10.8 doesn't follow protocols that adopt other protocols, which is why this protocol doesn't adopt SUInstallerCommunicationProtocol
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data;
|
||||
|
||||
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler;
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,21 +0,0 @@
|
||||
//
|
||||
// SUXPCInstallerConnection.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerConnectionProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUXPCInstallerConnection : NSObject <SUInstallerConnectionProtocol>
|
||||
|
||||
// Due to XPC reasons, this delegate is strongly referenced, until it's invalidated
|
||||
- (instancetype)initWithDelegate:(id<SUInstallerCommunicationProtocol>)delegate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,92 +0,0 @@
|
||||
//
|
||||
// SUXPCInstallerConnection.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUXPCInstallerConnection.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUXPCInstallerConnection ()
|
||||
|
||||
@property (nonatomic) NSXPCConnection *connection;
|
||||
@property (nonatomic) id<SUInstallerCommunicationProtocol> delegate; // intentionally not weak for XPC reasons
|
||||
@property (nonatomic, copy) void (^invalidationBlock)(void);
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUXPCInstallerConnection
|
||||
|
||||
@synthesize connection = _connection;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize invalidationBlock = _invalidationBlock;
|
||||
|
||||
- (instancetype)initWithDelegate:(id<SUInstallerCommunicationProtocol>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_connection = [[NSXPCConnection alloc] initWithServiceName:@INSTALLER_CONNECTION_BUNDLE_ID];
|
||||
_connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerConnectionProtocol)];
|
||||
|
||||
__weak SUXPCInstallerConnection *weakSelf = self;
|
||||
_connection.invalidationHandler = ^{
|
||||
[weakSelf invokeInvalidation];
|
||||
};
|
||||
|
||||
_connection.interruptionHandler = ^{
|
||||
[weakSelf invokeInvalidation];
|
||||
[weakSelf.connection invalidate];
|
||||
};
|
||||
|
||||
_delegate = delegate;
|
||||
|
||||
_connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
_connection.exportedObject = _delegate;
|
||||
|
||||
[_connection resume];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler
|
||||
{
|
||||
self.invalidationBlock = invalidationHandler;
|
||||
|
||||
__weak SUXPCInstallerConnection *weakSelf = self;
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy setInvalidationHandler:^{
|
||||
[weakSelf invokeInvalidation];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy setServiceName:serviceName systemDomain:systemDomain];
|
||||
}
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
{
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy handleMessageWithIdentifier:identifier data:data];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy invalidate];
|
||||
[self.connection invalidate];
|
||||
self.connection = nil;
|
||||
}
|
||||
|
||||
- (void)invokeInvalidation
|
||||
{
|
||||
if (self.invalidationBlock != nil) {
|
||||
self.invalidationBlock();
|
||||
self.invalidationBlock = nil;
|
||||
}
|
||||
// Break our retain cycle
|
||||
self.delegate = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// main.m
|
||||
// InstallerConnection
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/9/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerConnection.h"
|
||||
#import "SUInstallerCommunicationProtocol.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
|
||||
@end
|
||||
|
||||
@implementation ServiceDelegate
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
|
||||
// This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
|
||||
|
||||
// Configure the connection.
|
||||
// First, set the interface that the exported object implements.
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerConnectionProtocol)];
|
||||
newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
|
||||
SUInstallerConnection *exportedObject = [[SUInstallerConnection alloc] initWithDelegate:newConnection.remoteObjectProxy];
|
||||
|
||||
newConnection.exportedObject = exportedObject;
|
||||
|
||||
// Resuming the connection allows the system to deliver more incoming messages.
|
||||
[newConnection resume];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int main(int __unused argc, const char * __unused argv[])
|
||||
{
|
||||
// Create the delegate for the service.
|
||||
ServiceDelegate *delegate = [ServiceDelegate new];
|
||||
|
||||
// Set up the one NSXPCListener for this service. It will handle all incoming connections.
|
||||
NSXPCListener *listener = [NSXPCListener serviceListener];
|
||||
listener.delegate = delegate;
|
||||
|
||||
// Resuming the serviceListener starts this service. This method does not return.
|
||||
[listener resume];
|
||||
return 0;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<?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.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.temporary-exception.mach-lookup.global-name</key>
|
||||
<array>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)-spki</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,33 +0,0 @@
|
||||
<?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>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Sparkle Project. All rights reserved.</string>
|
||||
<key>XPCService</key>
|
||||
<dict>
|
||||
<key>ServiceType</key>
|
||||
<string>Application</string>
|
||||
<key>JoinExistingSession</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// SUInstallerLauncher.h
|
||||
// InstallerLauncher
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/1/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerLauncherProtocol.h"
|
||||
|
||||
// Non-sandboxed XPC service used for launching our installer
|
||||
// This is necessary for sandboxed applications
|
||||
@interface SUInstallerLauncher : NSObject <SUInstallerLauncherProtocol>
|
||||
@end
|
||||
@@ -1,471 +0,0 @@
|
||||
//
|
||||
// SUInstallerLauncher.m
|
||||
// InstallerLauncher
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/1/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUInstallerLauncher.h"
|
||||
#import "SUFileManager.h"
|
||||
#import "SULog.h"
|
||||
#import "SPUMessageTypes.h"
|
||||
#import "SUBundleIcon.h"
|
||||
#import "SPULocalCacheDirectory.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SUHost.h"
|
||||
#import <ImageIO/ImageIO.h>
|
||||
#import <ServiceManagement/ServiceManagement.h>
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUInstallerLauncher
|
||||
|
||||
- (BOOL)submitProgressToolAtPath:(NSString *)progressToolPath withHostBundle:(NSBundle *)hostBundle inSystemDomainForInstaller:(BOOL)inSystemDomainForInstaller
|
||||
{
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
|
||||
NSURL *progressToolURL = [NSURL fileURLWithPath:progressToolPath];
|
||||
|
||||
NSError *quarantineError = nil;
|
||||
if (![fileManager releaseItemFromQuarantineAtRootURL:progressToolURL error:&quarantineError]) {
|
||||
// This may or may not be a fatal error depending on if the process is sandboxed or not
|
||||
SULog(SULogLevelError, @"Failed to release quarantine on installer at %@ with error %@", progressToolPath, quarantineError);
|
||||
}
|
||||
|
||||
NSString *executablePath = [[NSBundle bundleWithURL:progressToolURL] executablePath];
|
||||
assert(executablePath != nil);
|
||||
|
||||
NSString *hostBundlePath = hostBundle.bundlePath;
|
||||
assert(hostBundlePath != nil);
|
||||
|
||||
NSString *hostBundleIdentifier = hostBundle.bundleIdentifier;
|
||||
assert(hostBundleIdentifier != nil);
|
||||
|
||||
NSArray<NSString *> *arguments = @[executablePath, hostBundlePath, @(inSystemDomainForInstaller).stringValue];
|
||||
|
||||
// The progress tool can only be ran as the logged in user, not as root
|
||||
CFStringRef domain = kSMDomainUserLaunchd;
|
||||
NSString *label = [NSString stringWithFormat:@"%@-sparkle-progress", hostBundleIdentifier];
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
Boolean submittedJob = false;
|
||||
OSStatus createStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth);
|
||||
if (createStatus == errAuthorizationSuccess) {
|
||||
// Try to remove the job from launchd if it is already running
|
||||
// We could invoke SMJobCopyDictionary() first to see if the job exists, but I'd rather avoid
|
||||
// using it because the headers indicate it may be removed one day without any replacement
|
||||
CFErrorRef removeError = NULL;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (!SMJobRemove(domain, (__bridge CFStringRef)(label), auth, true, &removeError)) {
|
||||
#pragma clang diagnostic pop
|
||||
if (removeError != NULL) {
|
||||
// It's normal for a job to not be found, so this is not an interesting error
|
||||
if (CFErrorGetCode(removeError) != kSMErrorJobNotFound) {
|
||||
SULog(SULogLevelError, @"Remove error: %@", removeError);
|
||||
}
|
||||
CFRelease(removeError);
|
||||
}
|
||||
}
|
||||
|
||||
NSMutableDictionary *jobDictionary = [[NSMutableDictionary alloc] init];
|
||||
jobDictionary[@"Label"] = label;
|
||||
jobDictionary[@"ProgramArguments"] = arguments;
|
||||
jobDictionary[@"EnableTransactions"] = @NO;
|
||||
jobDictionary[@"KeepAlive"] = @{@"SuccessfulExit" : @NO};
|
||||
jobDictionary[@"RunAtLoad"] = @NO;
|
||||
jobDictionary[@"NICE"] = @0;
|
||||
jobDictionary[@"LaunchOnlyOnce"] = @YES;
|
||||
jobDictionary[@"MachServices"] = @{SPUStatusInfoServiceNameForBundleIdentifier(hostBundleIdentifier) : @YES};
|
||||
|
||||
CFErrorRef submitError = NULL;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// SMJobSubmit is deprecated but is the only way to submit a non-permanent
|
||||
// helper and allows us to submit to user domain without requiring authorization
|
||||
submittedJob = SMJobSubmit(domain, (__bridge CFDictionaryRef)(jobDictionary), auth, &submitError);
|
||||
#pragma clang diagnostic pop
|
||||
if (!submittedJob) {
|
||||
if (submitError != NULL) {
|
||||
SULog(SULogLevelError, @"Submit progress error: %@", submitError);
|
||||
CFRelease(submitError);
|
||||
}
|
||||
}
|
||||
|
||||
AuthorizationFree(auth, kAuthorizationFlagDefaults);
|
||||
}
|
||||
|
||||
return (submittedJob == true);
|
||||
}
|
||||
|
||||
- (SUInstallerLauncherStatus)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle updaterIdentifier:(NSString *)updaterIdentifier authorizationPrompt:(NSString *)authorizationPrompt inSystemDomain:(BOOL)systemDomain
|
||||
{
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
|
||||
// No need to release the quarantine for this utility
|
||||
// In fact, we shouldn't because the tool may be located at a path we should not be writing too.
|
||||
|
||||
NSString *hostBundleIdentifier = hostBundle.bundleIdentifier;
|
||||
assert(hostBundleIdentifier != nil);
|
||||
|
||||
NSString *homeDirectory = NSHomeDirectory();
|
||||
assert(homeDirectory != nil);
|
||||
|
||||
NSString *userName = NSUserName();
|
||||
assert(userName != nil);
|
||||
|
||||
// The first argument has to be the path to the program, and the second is a host identifier so that the installer knows what mach services to host
|
||||
// The third and forth arguments are for home directory and user name which only pkg installer scripts may need
|
||||
// We intentionally do not pass any more arguments. Anything else should be done via IPC.
|
||||
// This is compatible to SMJobBless() which does not allow arguments
|
||||
// Even though we aren't using that function for now, it'd be wise to not decrease compatibility to it
|
||||
|
||||
NSArray<NSString *> *arguments = @[installerPath, hostBundleIdentifier, homeDirectory, userName];
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus createStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth);
|
||||
if (createStatus != errAuthorizationSuccess) {
|
||||
auth = NULL;
|
||||
SULog(SULogLevelError, @"Failed to create authorization reference: %d", createStatus);
|
||||
}
|
||||
|
||||
BOOL canceledAuthorization = NO;
|
||||
BOOL failedToUseSystemDomain = NO;
|
||||
if (auth != NULL && systemDomain) {
|
||||
// See Apple's 'EvenBetterAuthorizationSample' sample code and
|
||||
// https://developer.apple.com/library/mac/technotes/tn2095/_index.html#//apple_ref/doc/uid/DTS10003110-CH1-SECTION7
|
||||
// We can set a custom right name for authenticating as an administrator
|
||||
// Using this right rather than using something like kSMRightModifySystemDaemons allows us to present a better worded prompt
|
||||
// Note the right name is cached, so if we want to change the authorization
|
||||
// prompt, we may need to change the right name. I have found no good way around this :|
|
||||
NSString *sparkleAuthTag = @"sparkle2-auth"; // this needs to change if auth wording changes
|
||||
NSString *rightNameString;
|
||||
if ([hostBundleIdentifier isEqualToString:updaterIdentifier]) {
|
||||
// Application bundle is likely updating itself
|
||||
rightNameString = [NSString stringWithFormat:@"%@.%@", hostBundleIdentifier, sparkleAuthTag];
|
||||
} else {
|
||||
// Updater is likely updating a bundle that is not itself
|
||||
rightNameString = [NSString stringWithFormat:@"%@.%@.%@", updaterIdentifier, hostBundleIdentifier, sparkleAuthTag];
|
||||
}
|
||||
|
||||
const char *rightName = rightNameString.UTF8String;
|
||||
assert(rightName != NULL);
|
||||
|
||||
OSStatus getRightResult = AuthorizationRightGet(rightName, NULL);
|
||||
if (getRightResult == errAuthorizationDenied) {
|
||||
if (AuthorizationRightSet(auth, rightName, (__bridge CFTypeRef _Nonnull)(@(kAuthorizationRuleAuthenticateAsAdmin)), (__bridge CFStringRef _Nullable)(authorizationPrompt), NULL, NULL) != errAuthorizationSuccess) {
|
||||
SULog(SULogLevelError, @"Failed to make auth right set");
|
||||
}
|
||||
}
|
||||
|
||||
AuthorizationItem right = { .name = rightName, .valueLength = 0, .value = NULL, .flags = 0 };
|
||||
AuthorizationRights rights = { .count = 1, .items = &right };
|
||||
|
||||
AuthorizationFlags flags = (AuthorizationFlags)(kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed);
|
||||
|
||||
AuthorizationItem iconAuthorizationItem = {.name = kAuthorizationEnvironmentIcon, .valueLength = 0, .value = NULL, .flags = 0};
|
||||
AuthorizationEnvironment authorizationEnvironment = {.count = 0, .items = NULL};
|
||||
|
||||
// Find a 32x32 image representation of the icon, and write out a PNG version of it to a temporary location
|
||||
// Then use the icon (if one is available) for the authorization prompt
|
||||
// NSImage is not used because it relies on AppKit
|
||||
NSURL *tempIconDestinationURL = nil;
|
||||
NSURL *iconURL = [SUBundleIcon iconURLForHost:[[SUHost alloc] initWithBundle:hostBundle]];
|
||||
if (iconURL != nil) {
|
||||
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)iconURL, (CFDictionaryRef)@{});
|
||||
if (imageSource != NULL) {
|
||||
size_t imageCount = CGImageSourceGetCount(imageSource);
|
||||
for (size_t imageIndex = 0; imageIndex < imageCount; imageIndex++) {
|
||||
CFDictionaryRef cfProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, imageIndex, (CFDictionaryRef)@{});
|
||||
NSDictionary *properties = CFBridgingRelease(cfProperties);
|
||||
|
||||
NSNumber *pixelWidth = properties[(const NSString *)kCGImagePropertyPixelWidth];
|
||||
NSNumber *pixelHeight = properties[(const NSString *)kCGImagePropertyPixelHeight];
|
||||
|
||||
// If we don't find a 32x32 image representation, then we don't provide an icon
|
||||
// Don't try to make up with it by eg: converting an image representation to this size
|
||||
// The app developer should be providing the icon representation.
|
||||
// The authorization API may not take other size dimensions.
|
||||
NSNumber *targetDimension = @32;
|
||||
if ([pixelWidth isKindOfClass:[NSNumber class]] && [pixelHeight isKindOfClass:[NSNumber class]] && [pixelWidth isEqualToNumber:targetDimension] && [pixelHeight isEqualToNumber:targetDimension]) {
|
||||
|
||||
// Use /tmp rather than NSTemporaryDirectory() or SUFileManager's temp directory function because we want:
|
||||
// a) no spaces in the path (SU/NSFileManager fails here)
|
||||
// b) short file path that does not exceed a small threshold (NSTemporaryDirectory() fails here)
|
||||
// These limitations only apply to older systems (eg: macOS 10.8)
|
||||
// The file also needs to be placed in a system readable place such as /tmp
|
||||
// See https://github.com/sparkle-project/Sparkle/issues/347#issuecomment-149523848 for more info
|
||||
char pathBuffer[] = "/tmp/XXXXXX.png";
|
||||
int tempIconFile = mkstemps(pathBuffer, strlen(".png"));
|
||||
if (tempIconFile == -1) {
|
||||
SULog(SULogLevelError, @"Failed to open temp icon from path buffer with error: %d", errno);
|
||||
} else {
|
||||
close(tempIconFile);
|
||||
|
||||
NSString *path = [[NSString alloc] initWithUTF8String:pathBuffer];
|
||||
tempIconDestinationURL = [NSURL fileURLWithPath:path];
|
||||
|
||||
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)tempIconDestinationURL, kUTTypePNG, 1, NULL);
|
||||
if (imageDestination != NULL) {
|
||||
CGImageDestinationAddImageFromSource(imageDestination, imageSource, imageIndex, (CFDictionaryRef)@{});
|
||||
if (CGImageDestinationFinalize(imageDestination)) {
|
||||
iconAuthorizationItem.valueLength = strlen(pathBuffer);
|
||||
iconAuthorizationItem.value = pathBuffer;
|
||||
|
||||
authorizationEnvironment.count = 1;
|
||||
authorizationEnvironment.items = &iconAuthorizationItem;
|
||||
}
|
||||
|
||||
CFRelease(imageDestination);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(imageSource);
|
||||
}
|
||||
}
|
||||
|
||||
// This should prompt up the authorization dialog if necessary
|
||||
OSStatus copyStatus = AuthorizationCopyRights(auth, &rights, &authorizationEnvironment, flags, NULL);
|
||||
if (copyStatus != errAuthorizationSuccess) {
|
||||
failedToUseSystemDomain = YES;
|
||||
|
||||
if (copyStatus == errAuthorizationCanceled) {
|
||||
canceledAuthorization = YES;
|
||||
} else {
|
||||
SULog(SULogLevelError, @"Failed copying system domain rights: %d", copyStatus);
|
||||
}
|
||||
}
|
||||
|
||||
if (tempIconDestinationURL != nil) {
|
||||
[fileManager removeItemAtURL:tempIconDestinationURL error:NULL];
|
||||
}
|
||||
}
|
||||
|
||||
Boolean submittedJob = false;
|
||||
if (!canceledAuthorization && !failedToUseSystemDomain && auth != NULL) {
|
||||
CFStringRef domain = (systemDomain ? kSMDomainSystemLaunchd : kSMDomainUserLaunchd);
|
||||
NSString *label = [NSString stringWithFormat:@"%@-sparkle-updater", hostBundleIdentifier];
|
||||
|
||||
// Try to remove the job from launchd if it is already running
|
||||
// We could invoke SMJobCopyDictionary() first to see if the job exists, but I'd rather avoid
|
||||
// using it because the headers indicate it may be removed one day without any replacement
|
||||
CFErrorRef removeError = NULL;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (!SMJobRemove(domain, (__bridge CFStringRef)(label), auth, true, &removeError)) {
|
||||
#pragma clang diagnostic pop
|
||||
if (removeError != NULL) {
|
||||
// It's normal for a job to not be found, so this is not an interesting error
|
||||
if (CFErrorGetCode(removeError) != kSMErrorJobNotFound) {
|
||||
SULog(SULogLevelError, @"Remove job error: %@", removeError);
|
||||
}
|
||||
CFRelease(removeError);
|
||||
}
|
||||
}
|
||||
|
||||
NSDictionary *jobDictionary = @{@"Label" : label, @"ProgramArguments" : arguments, @"EnableTransactions" : @NO, @"KeepAlive" : @{@"SuccessfulExit" : @NO}, @"RunAtLoad" : @NO, @"Nice" : @0, @"LaunchOnlyOnce": @YES, @"MachServices" : @{SPUInstallerServiceNameForBundleIdentifier(hostBundleIdentifier) : @YES, SPUProgressAgentServiceNameForBundleIdentifier(hostBundleIdentifier) : @YES}};
|
||||
|
||||
CFErrorRef submitError = NULL;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// SMJobSubmit is deprecated but is the only way to submit a non-permanent
|
||||
// helper and allows us to submit to user domain without requiring authorization
|
||||
submittedJob = SMJobSubmit(domain, (__bridge CFDictionaryRef)(jobDictionary), auth, &submitError);
|
||||
#pragma clang diagnostic pop
|
||||
if (!submittedJob) {
|
||||
if (submitError != NULL) {
|
||||
SULog(SULogLevelError, @"Submit error: %@", submitError);
|
||||
CFRelease(submitError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (auth != NULL) {
|
||||
AuthorizationFree(auth, kAuthorizationFlagDefaults);
|
||||
}
|
||||
|
||||
SUInstallerLauncherStatus status;
|
||||
if (submittedJob == true) {
|
||||
status = SUInstallerLauncherSuccess;
|
||||
} else if (canceledAuthorization) {
|
||||
status = SUInstallerLauncherCanceled;
|
||||
} else {
|
||||
status = SUInstallerLauncherFailure;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
- (NSString *)pathForBundledTool:(NSString *)toolName extension:(NSString *)extension inBundle:(NSBundle *)bundle
|
||||
{
|
||||
// If the path extension is empty, we don't want to add a "." at the end
|
||||
NSString *nameWithExtension = (extension.length > 0) ? [toolName stringByAppendingPathExtension:extension] : toolName;
|
||||
assert(nameWithExtension != nil);
|
||||
|
||||
NSURL *auxiliaryToolURL = [bundle URLForAuxiliaryExecutable:nameWithExtension];
|
||||
assert(auxiliaryToolURL != nil);
|
||||
|
||||
NSURL *resolvedAuxiliaryToolURL = [auxiliaryToolURL URLByResolvingSymlinksInPath];
|
||||
assert(resolvedAuxiliaryToolURL != nil);
|
||||
|
||||
return resolvedAuxiliaryToolURL.path;
|
||||
}
|
||||
|
||||
static BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType)
|
||||
{
|
||||
BOOL needsAuthorization;
|
||||
if ([installationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
needsAuthorization = YES;
|
||||
} else if ([installationType isEqualToString:SPUInstallationTypeInteractivePackage]) {
|
||||
needsAuthorization = NO;
|
||||
} else {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
BOOL hasWritability = [fileManager isWritableFileAtPath:path] && [fileManager isWritableFileAtPath:[path stringByDeletingLastPathComponent]];
|
||||
if (!hasWritability) {
|
||||
needsAuthorization = YES;
|
||||
} else {
|
||||
// Just because we have writability access does not mean we can set the correct owner/group
|
||||
// Test if we can set the owner/group on a temporarily created file
|
||||
// If we can, then we can probably perform an update without authorization
|
||||
|
||||
NSString *tempFilename = @"permission_test" ;
|
||||
|
||||
SUFileManager *suFileManager = [[SUFileManager alloc] init];
|
||||
NSURL *tempDirectoryURL = [suFileManager makeTemporaryDirectoryWithPreferredName:tempFilename appropriateForDirectoryURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:NULL];
|
||||
|
||||
if (tempDirectoryURL == nil) {
|
||||
// I don't imagine this ever happening but in case it does, requesting authorization may be the better option
|
||||
needsAuthorization = YES;
|
||||
} else {
|
||||
NSURL *tempFileURL = [tempDirectoryURL URLByAppendingPathComponent:tempFilename];
|
||||
if (![[NSData data] writeToURL:tempFileURL atomically:NO]) {
|
||||
// Obvious indicator we may need authorization
|
||||
needsAuthorization = YES;
|
||||
} else {
|
||||
needsAuthorization = ![suFileManager changeOwnerAndGroupOfItemAtRootURL:tempFileURL toMatchURL:[NSURL fileURLWithPath:path] error:NULL];
|
||||
}
|
||||
|
||||
[suFileManager removeItemAtURL:tempDirectoryURL error:NULL];
|
||||
}
|
||||
}
|
||||
}
|
||||
return needsAuthorization;
|
||||
}
|
||||
|
||||
|
||||
// Note: do not pass untrusted information such as paths to the installer and progress agent tools, when we can find them ourselves here
|
||||
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath updaterIdentifier:(NSString *)updaterIdentifier authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
BOOL needsSystemAuthorization = SPUNeedsSystemAuthorizationAccess(hostBundlePath, installationType);
|
||||
|
||||
NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath];
|
||||
if (hostBundle == nil) {
|
||||
SULog(SULogLevelError, @"InstallerLauncher failed to create bundle at %@", hostBundlePath);
|
||||
SULog(SULogLevelError, @"Please make sure InstallerLauncher is not sandboxed and do not sign your app by passing --deep. Check: codesign -d --entitlements :- \"%@\"", NSBundle.mainBundle.bundlePath);
|
||||
SULog(SULogLevelError, @"More information regarding sandboxing: https://sparkle-project.org/documentation/sandboxing/");
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
if (needsSystemAuthorization && !allowingUpdaterInteraction) {
|
||||
SULog(SULogLevelError, @"Updater is not allowing interaction to the launcher.");
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!allowingUpdaterInteraction && [installationType isEqualToString:SPUInstallationTypeInteractivePackage]) {
|
||||
SULog(SULogLevelError, @"Updater is not allowing interaction to the launcher for performing an interactive type package installation.");
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
// if we need to use the system domain and we aren't allowed interaction, then try sometime later when interaction is allowed
|
||||
if (needsSystemAuthorization && !allowingDriverInteraction) {
|
||||
completionHandler(SUInstallerLauncherAuthorizeLater, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *hostBundleIdentifier = hostBundle.bundleIdentifier;
|
||||
assert(hostBundleIdentifier != nil);
|
||||
|
||||
// We could be inside the InstallerLauncher XPC bundle or in the Sparkle.framework bundle if no XPC service is used
|
||||
NSBundle *ourBundle = [NSBundle bundleForClass:[self class]];
|
||||
|
||||
// Note we do not have to copy this tool out of the bundle it's in because it's a utility with no dependencies.
|
||||
// Furthermore, we can keep the tool at a place that may not necessarily be writable.
|
||||
NSString *installerPath = [self pathForBundledTool:@""SPARKLE_RELAUNCH_TOOL_NAME extension:@"" inBundle:ourBundle];
|
||||
if (installerPath == nil) {
|
||||
SULog(SULogLevelError, @"Error: Cannot submit installer because the installer could not be located");
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
// We do however have to copy the progress tool app somewhere safe due to its external depedencies
|
||||
NSString *progressToolResourcePath = [self pathForBundledTool:@""SPARKLE_INSTALLER_PROGRESS_TOOL_NAME extension:@"app" inBundle:ourBundle];
|
||||
|
||||
if (progressToolResourcePath == nil) {
|
||||
SULog(SULogLevelError, @"Error: Cannot submit progress tool because the progress tool could not be located");
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
// It may be tempting here to validate/match the signature of the installer and progress tool, however this is not very reliable
|
||||
// We can't compare the signature of this framework/XPC service (depending how it's run) to the host bundle because
|
||||
// they could be different (eg: take a look at sparkle-cli). We also can't easily tell if the signature of the service/framework is the same as the bundle it's inside.
|
||||
// The service/framework also need not even be signed in the first place. We'll just assume for now the original bundle hasn't been tampered with
|
||||
|
||||
NSString *rootLauncherCachePath = [[SPULocalCacheDirectory cachePathForBundleIdentifier:hostBundleIdentifier] stringByAppendingPathComponent:@"Launcher"];
|
||||
|
||||
[SPULocalCacheDirectory removeOldItemsInDirectory:rootLauncherCachePath];
|
||||
|
||||
NSString *launcherCachePath = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:rootLauncherCachePath];
|
||||
if (launcherCachePath == nil) {
|
||||
SULog(SULogLevelError, @"Failed to create cache directory for progress tool in %@", rootLauncherCachePath);
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *progressToolPath = [launcherCachePath stringByAppendingPathComponent:@""SPARKLE_INSTALLER_PROGRESS_TOOL_NAME@".app"];
|
||||
|
||||
NSError *copyError = nil;
|
||||
// SUFileManager is more reliable for copying files around
|
||||
if (![[[SUFileManager alloc] init] copyItemAtURL:[NSURL fileURLWithPath:progressToolResourcePath] toURL:[NSURL fileURLWithPath:progressToolPath] error:©Error]) {
|
||||
SULog(SULogLevelError, @"Failed to copy progress tool to cache: %@", copyError);
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
SUInstallerLauncherStatus installerStatus = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle updaterIdentifier:updaterIdentifier authorizationPrompt:authorizationPrompt inSystemDomain:needsSystemAuthorization];
|
||||
|
||||
BOOL submittedProgressTool = NO;
|
||||
if (installerStatus == SUInstallerLauncherSuccess) {
|
||||
submittedProgressTool = [self submitProgressToolAtPath:progressToolPath withHostBundle:hostBundle inSystemDomainForInstaller:needsSystemAuthorization];
|
||||
|
||||
if (!submittedProgressTool) {
|
||||
SULog(SULogLevelError, @"Failed to submit progress tool job");
|
||||
}
|
||||
} else if (installerStatus == SUInstallerLauncherFailure) {
|
||||
SULog(SULogLevelError, @"Failed to submit installer job");
|
||||
SULog(SULogLevelError, @"If your application is sandboxed please follow steps at: https://sparkle-project.org/documentation/sandboxing/");
|
||||
}
|
||||
|
||||
if (installerStatus == SUInstallerLauncherCanceled) {
|
||||
completionHandler(installerStatus, needsSystemAuthorization);
|
||||
} else {
|
||||
completionHandler(submittedProgressTool ? SUInstallerLauncherSuccess : SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)checkIfApplicationInstallationRequiresAuthorizationWithHostBundlePath:(NSString *)hostBundlePath reply:(void(^)(BOOL))reply
|
||||
{
|
||||
// No need to execute on main queue
|
||||
reply(SPUNeedsSystemAuthorizationAccess(hostBundlePath, SPUInstallationTypeApplication));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// SUInstallerLauncherProtocol.h
|
||||
// InstallerLauncher
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/1/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerLauncherStatus.h"
|
||||
|
||||
@protocol SUInstallerLauncherProtocol
|
||||
|
||||
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath updaterIdentifier:(NSString *)updaterBundleIdentifier authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler;
|
||||
|
||||
- (void)checkIfApplicationInstallationRequiresAuthorizationWithHostBundlePath:(NSString *)hostBundlePath reply:(void(^)(BOOL requiresAuthorization))reply;
|
||||
|
||||
@end
|
||||
@@ -1,17 +0,0 @@
|
||||
//
|
||||
// SUInstallerLauncherStatus.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/18/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
typedef NS_ENUM(NSUInteger, SUInstallerLauncherStatus)
|
||||
{
|
||||
SUInstallerLauncherSuccess = 0,
|
||||
SUInstallerLauncherCanceled = 1,
|
||||
SUInstallerLauncherAuthorizeLater = 3,
|
||||
SUInstallerLauncherFailure = 4
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// main.m
|
||||
// InstallerLauncher
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/1/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerLauncher.h"
|
||||
|
||||
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
|
||||
@end
|
||||
|
||||
@implementation ServiceDelegate
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
|
||||
// This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
|
||||
|
||||
// Configure the connection.
|
||||
// First, set the interface that the exported object implements.
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerLauncherProtocol)];
|
||||
|
||||
// Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
|
||||
SUInstallerLauncher *exportedObject = [SUInstallerLauncher new];
|
||||
newConnection.exportedObject = exportedObject;
|
||||
|
||||
// Resuming the connection allows the system to deliver more incoming messages.
|
||||
[newConnection resume];
|
||||
|
||||
// Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int main(int __unused argc, const char * __unused argv[])
|
||||
{
|
||||
// Create the delegate for the service.
|
||||
ServiceDelegate *delegate = [ServiceDelegate new];
|
||||
|
||||
// Set up the one NSXPCListener for this service. It will handle all incoming connections.
|
||||
NSXPCListener *listener = [NSXPCListener serviceListener];
|
||||
listener.delegate = delegate;
|
||||
|
||||
// Resuming the serviceListener starts this service. This method does not return.
|
||||
[listener resume];
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?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>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Sparkle Project. All rights reserved.</string>
|
||||
<key>XPCService</key>
|
||||
<dict>
|
||||
<key>ServiceType</key>
|
||||
<string>Application</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// SUInstallerStatus.h
|
||||
// InstallerStatus
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerStatusProtocol.h"
|
||||
|
||||
// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection.
|
||||
@interface SUInstallerStatus : NSObject <SUInstallerStatusProtocol>
|
||||
|
||||
@end
|
||||
@@ -1,79 +0,0 @@
|
||||
//
|
||||
// SUInstallerStatus.m
|
||||
// InstallerStatus
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUInstallerStatus.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUInstallerStatus ()
|
||||
|
||||
@property (nonatomic, copy) void (^invalidationBlock)(void);
|
||||
@property (nonatomic) NSXPCConnection *connection;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUInstallerStatus
|
||||
|
||||
@synthesize invalidationBlock = _invalidationBlock;
|
||||
@synthesize connection = _connection;
|
||||
|
||||
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler
|
||||
{
|
||||
self.invalidationBlock = invalidationHandler;
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName
|
||||
{
|
||||
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:serviceName options:(NSXPCConnectionOptions)0];
|
||||
|
||||
connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUStatusInfoProtocol)];
|
||||
|
||||
self.connection = connection;
|
||||
|
||||
__weak SUInstallerStatus *weakSelf = self;
|
||||
self.connection.interruptionHandler = ^{
|
||||
[weakSelf.connection invalidate];
|
||||
};
|
||||
|
||||
self.connection.invalidationHandler = ^{
|
||||
SUInstallerStatus *strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
strongSelf.connection = nil;
|
||||
[strongSelf invalidate];
|
||||
}
|
||||
};
|
||||
|
||||
[self.connection resume];
|
||||
}
|
||||
|
||||
- (void)probeStatusInfoWithReply:(void (^)(NSData * _Nullable installationInfoData))reply
|
||||
{
|
||||
[(id<SUStatusInfoProtocol>)self.connection.remoteObjectProxy probeStatusInfoWithReply:reply];
|
||||
}
|
||||
|
||||
- (void)probeStatusConnectivityWithReply:(void (^)(void))reply
|
||||
{
|
||||
[(id<SUStatusInfoProtocol>)self.connection.remoteObjectProxy probeStatusConnectivityWithReply:reply];
|
||||
}
|
||||
|
||||
// This method can be called by us or from a remote
|
||||
- (void)invalidate
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.connection invalidate];
|
||||
self.connection = nil;
|
||||
|
||||
if (self.invalidationBlock != nil) {
|
||||
self.invalidationBlock();
|
||||
self.invalidationBlock = nil;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// SUInstallerStatusProtocol.h
|
||||
// InstallerStatus
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUStatusInfoProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// The protocol that this service will vend as its API. This header file will also need to be visible to the process hosting the service.
|
||||
@protocol SUInstallerStatusProtocol
|
||||
|
||||
// Even though this is declared in SUStatusInfoProtocol, we should declare it here because macOS 10.8 doesn't traverse adopted protocols,
|
||||
// which is why this protocol doesn't adopt SUStatusInfoProtocol
|
||||
- (void)probeStatusInfoWithReply:(void (^)(NSData * _Nullable installationInfoData))reply;
|
||||
|
||||
// Even though this is declared in SUStatusInfoProtocol, we should declare it here because macOS 10.8 doesn't traverse adopted protocols,
|
||||
// which is why this protocol doesn't adopt SUStatusInfoProtocol
|
||||
- (void)probeStatusConnectivityWithReply:(void (^)(void))reply;
|
||||
|
||||
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler;
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,14 +0,0 @@
|
||||
//
|
||||
// SUXPCInstallerStatus.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerStatusProtocol.h"
|
||||
|
||||
@interface SUXPCInstallerStatus : NSObject <SUInstallerStatusProtocol>
|
||||
|
||||
@end
|
||||
Loaded 100 of 491 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user