mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c94eac3673 | ||
|
|
acea9b0d1d | ||
|
|
3b15ab08e1 | ||
|
|
02d5d44ffd | ||
|
|
1daba4d60f | ||
|
|
910f6a5966 | ||
|
|
5ed577fe78 | ||
|
|
d37bea0e67 | ||
|
|
5ca9c2fbbe | ||
|
|
bc1dc3ebf1 | ||
|
|
b9f6e9c8ae | ||
|
|
a30d745158 | ||
|
|
aa916f4bfe | ||
|
|
b820e4f288 | ||
|
|
2beaa9602c | ||
|
|
4953a96658 | ||
|
|
d47560283c | ||
|
|
b57ca4769c | ||
|
|
01b1ce7b9c | ||
|
|
32e59c6ea4 | ||
|
|
941a65f78f | ||
|
|
bd046ab1ad | ||
|
|
ebfb5f82b2 | ||
|
|
8039ce9862 | ||
|
|
26818ca11d | ||
|
|
1dcb87cc44 | ||
|
|
313daa4711 | ||
|
|
86278a2f32 | ||
|
|
a91749781d | ||
|
|
b52291cfc6 | ||
|
|
d5d9824b6c | ||
|
|
d487361cb9 | ||
|
|
5e906948f3 | ||
|
|
48ab89338b | ||
|
|
1c09a01ef9 | ||
|
|
4094dc3e83 | ||
|
|
d25e96f220 | ||
|
|
12531b635d | ||
|
|
bb645e9832 | ||
|
|
e24212f797 | ||
|
|
6b97e4a533 | ||
|
|
3956a27bd0 | ||
|
|
8a4578fe4d | ||
|
|
3c7b0805e1 | ||
|
|
d81139830e | ||
|
|
b6b704ea55 | ||
|
|
77fc6ca681 | ||
|
|
46c22e2bbf | ||
|
|
92d7b9f68f | ||
|
|
6b6b6b2405 | ||
|
|
b854b01e6a | ||
|
|
61e16cf276 | ||
|
|
e7088fc788 | ||
|
|
54aa6f2cc2 | ||
|
|
acf758e485 | ||
|
|
ceedfba634 | ||
|
|
addedeac13 | ||
|
|
eedb0ff0dd | ||
|
|
67a7bc3d62 | ||
|
|
65d7c38ab6 | ||
|
|
5b786043c2 | ||
|
|
ca23238d59 | ||
|
|
fc1870cbd2 | ||
|
|
659aec4eaf | ||
|
|
88a197a7f0 | ||
|
|
9119d287ab | ||
|
|
7797a8f58c | ||
|
|
1f0da95e59 | ||
|
|
84a2feb0ad | ||
|
|
bbe75fc6f2 | ||
|
|
9c8e08b7ae | ||
|
|
371c51fe5a | ||
|
|
feb2ad4b64 | ||
|
|
1e75acb963 | ||
|
|
b3c69f8b8c | ||
|
|
5cd9bdccf6 | ||
|
|
12eede4123 | ||
|
|
9633a57c6c | ||
|
|
ab389260be | ||
|
|
abf70ab8dc | ||
|
|
67ebc6ff74 | ||
|
|
1e14f7d7b6 | ||
|
|
5bd4c1ecb6 | ||
|
|
406f3da615 | ||
|
|
302eb082d6 | ||
|
|
16b75653dc | ||
|
|
fc8176a229 | ||
|
|
502c7fb6db | ||
|
|
71f747aec1 | ||
|
|
aebb767cfb | ||
|
|
04b1514452 | ||
|
|
22f9c96a1f | ||
|
|
78b08a0bee | ||
|
|
6fc58a1025 | ||
|
|
dbd2b9b30a |
No files matched your search
@@ -1,45 +0,0 @@
|
||||
AccessModifierOffset: -4
|
||||
AlignEscapedNewlinesLeft: true
|
||||
AlignTrailingComments: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackParameters: true
|
||||
BreakBeforeBinaryOperators: true
|
||||
BreakBeforeBraces: Linux
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
ColumnLimit: 0
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: false
|
||||
#DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
#ForEachMacros: foreach,Q_FOREACH
|
||||
IndentCaseLabels: true
|
||||
IndentFunctionDeclarationAfterType: true
|
||||
IndentWidth: 4
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
Language: Cpp
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: All
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
#PointerAlignment: Right
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
name: Enhancements and Bug Fixes
|
||||
about: Found a bug? Want to implement a new feature? Something else?
|
||||
title: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
|
||||
If this is a question or an idea, please consider posting in Discussions first:
|
||||
https://github.com/sparkle-project/Sparkle/discussions
|
||||
|
||||
Otherwise the answer to your issue may already be in Console.app on your computer.
|
||||
Please use Console.app and search for Sparkle.
|
||||
|
||||
Please try troubleshooting steps:
|
||||
https://github.com/sparkle-project/Sparkle#troubleshooting
|
||||
|
||||
For security sensitive issues, please file them at https://github.com/sparkle-project/Sparkle/security
|
||||
|
||||
-->
|
||||
|
||||
## Summary
|
||||
|
||||
[provide general summary to the issue or enhancement and its rationale]
|
||||
|
||||
## Possible Fix
|
||||
|
||||
[not obligatory, but suggest fixes or reasons for the bug]
|
||||
|
||||
## Version
|
||||
|
||||
[please specify versions of Sparkle this is applicable to]
|
||||
@@ -1,35 +0,0 @@
|
||||
---
|
||||
name: Sparkle doesn't work in my app
|
||||
about: Problems with integration, unexpected errors using Sparkle
|
||||
title: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
|
||||
The answer to your issue is probably already in Console.app on your computer.
|
||||
Please use Console.app and search for Sparkle.
|
||||
|
||||
Please try troubleshooting steps:
|
||||
https://github.com/sparkle-project/Sparkle#troubleshooting
|
||||
|
||||
-->
|
||||
|
||||
### Description of the problem
|
||||
|
||||
|
||||
### Do you use Sandboxing in your app?
|
||||
|
||||
### Version of `Sparkle.framework` in the latest version of your app
|
||||
|
||||
### Version of `Sparkle.framework` in the old version of app that your users have (or N/A)
|
||||
|
||||
### Sparkle's output from Console.app
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
### Steps to reproduce the behavior
|
||||
|
||||
[The more information provided and pasted verbatim, the easier it will be to diagnose an issue. If you can provide the affected application/binary and XML feed to reproduce an issue, share them]
|
||||
@@ -1,21 +0,0 @@
|
||||
(Insert summary of your pull request here)
|
||||
|
||||
Fixes # (issue)
|
||||
|
||||
## Misc Checklist
|
||||
|
||||
- [ ] My change requires a documentation update on [Sparkle's website repository](https://github.com/sparkle-project/sparkle-project.github.io)
|
||||
- [ ] My change requires changes to generate_appcast, generate_keys, or sign_update
|
||||
|
||||
## Testing
|
||||
|
||||
I tested and verified my change by using one or multiple of these methods:
|
||||
|
||||
- [ ] Sparkle Test App
|
||||
- [ ] Unit Tests
|
||||
- [ ] My own app
|
||||
- [ ] Other (please specify)
|
||||
|
||||
(Describe all the cases that were tested)
|
||||
|
||||
macOS version tested: [place version here]
|
||||
@@ -1,113 +0,0 @@
|
||||
name: Build & Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ 2.x, master ]
|
||||
pull_request:
|
||||
branches: [ 2.x, master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
xcode: ['xcode26.2', 'xcode16.4']
|
||||
include:
|
||||
- xcode: 'xcode16.4'
|
||||
xcode-path: '/Applications/Xcode_16.4.app/Contents/Developer'
|
||||
upload-dist: false
|
||||
run-analyzer: false
|
||||
macos: 'macos-15'
|
||||
- xcode: 'xcode26.2'
|
||||
xcode-path: '/Applications/Xcode_26.2.app/Contents/Developer'
|
||||
upload-dist: true
|
||||
run-analyzer: true
|
||||
macos: 'macos-26'
|
||||
|
||||
name: Build and Test Sparkle
|
||||
runs-on: ${{ matrix.macos }}
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
- name: Build Unit Tests
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
run: |
|
||||
xcodebuild build-for-testing -project Sparkle.xcodeproj -scheme Distribution -enableCodeCoverage YES -derivedDataPath build
|
||||
- name: Run Unit Tests
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
run: |
|
||||
xcodebuild test-without-building -project Sparkle.xcodeproj -scheme Distribution -enableCodeCoverage YES -derivedDataPath build
|
||||
- name: Build UI Tests
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
run: |
|
||||
xcodebuild build-for-testing -project Sparkle.xcodeproj -scheme UITests -configuration Debug -derivedDataPath build
|
||||
- name: Run UI Tests
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
run: |
|
||||
xcodebuild test-without-building -project Sparkle.xcodeproj -scheme UITests -configuration Debug -derivedDataPath build
|
||||
|
||||
- name: Analyze Sparkle
|
||||
if: ${{ matrix.run-analyzer && github.event_name == 'pull_request' }}
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
run: |
|
||||
xcodebuild analyze -project Sparkle.xcodeproj -quiet -scheme Sparkle -configuration Release -derivedDataPath analyze > analyze_output.txt
|
||||
|
||||
- name: Find Analyzed Warnings
|
||||
if: ${{ success() && matrix.run-analyzer && github.event_name == 'pull_request' }}
|
||||
id: findwarnings
|
||||
env:
|
||||
DEVELOPER_DIR: ${{ matrix.xcode-path }}
|
||||
run: |
|
||||
if grep -q "warning:" analyze_output.txt; then
|
||||
echo "analyzestatus=0" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "analyzestatus=1" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Extract Analyzed Warnings
|
||||
if: ${{ success() && matrix.run-analyzer && github.event_name == 'pull_request' && steps.findwarnings.outputs.analyzestatus == '0' }}
|
||||
id: warnings
|
||||
run: |
|
||||
{
|
||||
echo 'content<<EOF'
|
||||
cat analyze_output.txt
|
||||
echo 'EOF'
|
||||
} >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Post Analyzed Warnings
|
||||
if: ${{ success() && matrix.run-analyzer && github.event_name == 'pull_request' && steps.findwarnings.outputs.analyzestatus == '0' }}
|
||||
uses: mshick/add-pr-comment@v2
|
||||
with:
|
||||
allow-repeats: false
|
||||
message: "``` ${{ steps.warnings.outputs.content }} ```"
|
||||
|
||||
- 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@v4
|
||||
with:
|
||||
name: build-logs
|
||||
path: |
|
||||
build/Logs
|
||||
~/Library/Logs/DiagnosticReports
|
||||
- name: Upload Distribution
|
||||
if: ${{ success() && matrix.upload-dist }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Sparkle-distribution-${{ matrix.xcode }}.tar.xz
|
||||
path: build/Build/Products/Release/sparkle_dist.tar.xz
|
||||
@@ -1,101 +0,0 @@
|
||||
name: "Create Draft Release"
|
||||
|
||||
env:
|
||||
BUILDDIR: "build"
|
||||
DEVELOPER_DIR: "/Applications/Xcode_26.2.app/Contents/Developer"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
marketingVersion:
|
||||
description: "Marketing Version"
|
||||
required: true
|
||||
default: ""
|
||||
|
||||
prereleaseSuffix:
|
||||
description: "Pre-release Suffix"
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
buildVersion:
|
||||
description: "Product Build"
|
||||
required: true
|
||||
default: ""
|
||||
|
||||
concurrency:
|
||||
group: publish-release-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: "Publish binaries for release"
|
||||
runs-on: macos-26
|
||||
|
||||
steps:
|
||||
- name: "Checkout sources"
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }}
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
|
||||
- name: "Extract latest changes from CHANGELOG"
|
||||
run: |
|
||||
./Configurations/generate_latest_changes.py > latest-changes.txt
|
||||
|
||||
- name: "Overwrite project versions in project"
|
||||
run: |
|
||||
IFS='.' read major minor patch <<< "${{ github.event.inputs.marketingVersion }}"
|
||||
sed -E -i '' "s/SPARKLE_VERSION_MAJOR =.+/SPARKLE_VERSION_MAJOR = $major/g" ./Configurations/ConfigCommon.xcconfig
|
||||
sed -E -i '' "s/SPARKLE_VERSION_MINOR =.+/SPARKLE_VERSION_MINOR = $minor/g" ./Configurations/ConfigCommon.xcconfig
|
||||
sed -E -i '' "s/SPARKLE_VERSION_PATCH =.+/SPARKLE_VERSION_PATCH = $patch/g" ./Configurations/ConfigCommon.xcconfig
|
||||
|
||||
if [[ ! -z "${{ github.event.inputs.prereleaseSuffix }}" ]]; then
|
||||
sed -E -i '' "s/SPARKLE_VERSION_SUFFIX =.*/SPARKLE_VERSION_SUFFIX = ${{ github.event.inputs.prereleaseSuffix }}/g" ./Configurations/ConfigCommon.xcconfig
|
||||
else
|
||||
sed -E -i '' "s/SPARKLE_VERSION_SUFFIX =.*/SPARKLE_VERSION_SUFFIX =/g" ./Configurations/ConfigCommon.xcconfig
|
||||
fi
|
||||
|
||||
sed -E -i '' "s/CURRENT_PROJECT_VERSION =.+/CURRENT_PROJECT_VERSION = ${{ github.event.inputs.buildVersion }}/g" ./Configurations/ConfigCommon.xcconfig
|
||||
git add ./Configurations/ConfigCommon.xcconfig
|
||||
|
||||
- name: "Determine if this is a pre-release version"
|
||||
run: |
|
||||
if [[ ! -z "${{ github.event.inputs.prereleaseSuffix }}" ]]; then
|
||||
echo "PRERELEASE_VERSION=true" >> $GITHUB_ENV
|
||||
else
|
||||
echo "PRERELEASE_VERSION=false" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: "Set up git and create tag"
|
||||
run: |
|
||||
git config user.name Sparkle-Bot
|
||||
git config user.email sparkle.project.bot@gmail.com
|
||||
git tag "${{ github.event.inputs.marketingVersion }}${{ github.event.inputs.prereleaseSuffix }}"
|
||||
|
||||
- name: "Build release distribution"
|
||||
run: make release
|
||||
env:
|
||||
GITHUB_ACTOR: ${{ github.actor }}
|
||||
GITHUB_REPOSITORY: ${{ github.repository }}
|
||||
GITHUB_TOKEN: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }}
|
||||
|
||||
- name: "Push the updated package description"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }}
|
||||
run: git push
|
||||
|
||||
- name: "Draft a release"
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
draft: true
|
||||
prerelease: ${{ env.PRERELEASE_VERSION }}
|
||||
target_commitish: ${{ github.ref_name }}
|
||||
name: "${{ github.event.inputs.marketingVersion }}${{ github.event.inputs.prereleaseSuffix }}"
|
||||
tag_name: "${{ github.event.inputs.marketingVersion }}${{ github.event.inputs.prereleaseSuffix }}"
|
||||
fail_on_unmatched_files: true
|
||||
token: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }}
|
||||
body_path: latest-changes.txt
|
||||
files: |
|
||||
build/Build/Products/Release/Sparkle-*.tar.xz
|
||||
build/Build/Products/Release/Sparkle-for-Swift-Package-Manager.zip
|
||||
+7
-36
@@ -1,4 +1,5 @@
|
||||
build/
|
||||
# Xcode
|
||||
build/*
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
@@ -7,41 +8,11 @@ build/
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata
|
||||
*.xccheckout
|
||||
*.xcworkspace
|
||||
!default.xcworkspace
|
||||
xcuserdata/
|
||||
profile
|
||||
*.moved-aside
|
||||
DerivedData
|
||||
*.xcuserstate
|
||||
|
||||
## Ignore incredibly annoying .DS_Store files
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear on external disk
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
# With Carthage, if Sparkle is included as a Git submodule (e.g. with the
|
||||
# --use-submodules option), the main module's .gitignore can't reach all the
|
||||
# way inside the submodule to ignore the added Carthage/Build symlink, and Git
|
||||
# keeps complaining about untracked changes in the submodule forever, which
|
||||
# is very annoying. To avoid that issue, ignore here in Sparkle instead.
|
||||
Carthage/Build
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Swift Package Manager
|
||||
/.build
|
||||
.swiftpm
|
||||
@@ -1,20 +0,0 @@
|
||||
excluded:
|
||||
- Vendor
|
||||
disabled_rules:
|
||||
- opening_brace
|
||||
- empty_parentheses_with_trailing_closure
|
||||
- function_body_length
|
||||
- line_length
|
||||
- cyclomatic_complexity
|
||||
- large_tuple
|
||||
|
||||
# Rule-specific config
|
||||
trailing_comma:
|
||||
mandatory_comma: true
|
||||
force_try:
|
||||
severity: warning
|
||||
force_cast:
|
||||
severity: warning
|
||||
identifier_name:
|
||||
min_length:
|
||||
warning: 2
|
||||
@@ -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;
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @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,141 +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"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SULog.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface AgentConnection () <NSXPCListenerDelegate, SUInstallerAgentInitiationProtocol>
|
||||
|
||||
@end
|
||||
|
||||
@implementation AgentConnection
|
||||
{
|
||||
NSXPCListener *_xpcListener;
|
||||
NSXPCConnection *_activeConnection;
|
||||
__weak id<AgentConnectionDelegate> _delegate;
|
||||
}
|
||||
|
||||
@synthesize agent = _agent;
|
||||
@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
|
||||
{
|
||||
[_xpcListener resume];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
_delegate = nil;
|
||||
|
||||
[_activeConnection invalidate];
|
||||
// Don't need to set _activeConnection to nil, we don't expect new connections
|
||||
|
||||
[_xpcListener invalidate];
|
||||
_xpcListener = nil;
|
||||
}
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
|
||||
{
|
||||
if (_activeConnection != nil) {
|
||||
SULog(SULogLevelError, @"Error: Rejecting new connection for agent due already having an active connection");
|
||||
|
||||
[newConnection invalidate];
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Hardening but not critical for security
|
||||
NSError *validationError = nil;
|
||||
SUValidateConnectionStatus validationStatus = [SUCodeSigningVerifier validateConnection:newConnection error:&validationError];
|
||||
switch (validationStatus) {
|
||||
case SUValidateConnectionStatusSetCodeSigningRequirementSuccess:
|
||||
break;
|
||||
case SUValidateConnectionStatusSetNoRequirementSuccess:
|
||||
break;
|
||||
case SUValidateConnectionStatusAPIFailure:
|
||||
case SUValidateConnectionStatusCodeSigningRequirementFailure:
|
||||
case SUValidateConectionNoSupportedValidationMethodFailure:
|
||||
SULog(SULogLevelError, @"Error: Rejecting new connection for agent due to failing validation of XPC connection with status %lu and error: %@", validationStatus, validationError.localizedDescription);
|
||||
|
||||
[newConnection invalidate];
|
||||
return NO;
|
||||
}
|
||||
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerAgentInitiationProtocol)];
|
||||
newConnection.exportedObject = self;
|
||||
|
||||
newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SPUInstallerAgentProtocol)];
|
||||
|
||||
_activeConnection = newConnection;
|
||||
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
newConnection.interruptionHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf->_activeConnection invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
newConnection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf->_delegate agentConnectionDidInvalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
_agent = newConnection.remoteObjectProxy;
|
||||
[newConnection resume];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)connectionDidInitiateWithReply:(void (^)(void))acknowledgement
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->_connected = YES;
|
||||
|
||||
[self->_delegate agentConnectionDidInitiate];
|
||||
});
|
||||
|
||||
if (acknowledgement != NULL) {
|
||||
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
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @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,821 +0,0 @@
|
||||
//
|
||||
// AppInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/7/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppInstaller.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"
|
||||
#import "SPUVerifierInformation.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import <os/lock.h>
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
#define FIRST_UPDATER_MESSAGE_TIMEOUT 18ull
|
||||
#define RETRIEVE_PROCESS_IDENTIFIER_TIMEOUT 8ull
|
||||
|
||||
/**
|
||||
* 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>
|
||||
@end
|
||||
|
||||
@implementation AppInstaller
|
||||
{
|
||||
NSXPCListener* _xpcListener;
|
||||
// Must be synchronized with _newConnectionLock
|
||||
// Set from new connection handler, and also set/read from main thread
|
||||
NSXPCConnection *_activeConnection;
|
||||
|
||||
id<SUInstallerCommunicationProtocol> _communicator;
|
||||
AgentConnection *_agentConnection;
|
||||
|
||||
SUUpdateValidator *_updateValidator;
|
||||
|
||||
NSString *_hostBundleIdentifier;
|
||||
NSString *_homeDirectory;
|
||||
NSString *_userName;
|
||||
SUHost *_host;
|
||||
NSString *_updateDirectoryPath;
|
||||
NSString *_extractionDirectory;
|
||||
NSString *_downloadName;
|
||||
NSString *_decryptionPassword;
|
||||
SUSignatures *_signatures;
|
||||
NSString *_relaunchPath;
|
||||
NSString *_installationType;
|
||||
SPUVerifierInformation *_verifierInformation;
|
||||
|
||||
id<SUInstallerProtocol> _installer;
|
||||
|
||||
dispatch_queue_t _installerQueue;
|
||||
|
||||
os_unfair_lock _newConnectionLock;
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
// Must be synchronized with _newConnectionLock
|
||||
// Set from new connection handler, read from main thread
|
||||
BOOL _connectionCodeSigningValidationSkipped;
|
||||
#endif
|
||||
|
||||
BOOL _shouldRelaunch;
|
||||
BOOL _shouldShowUI;
|
||||
|
||||
BOOL _receivedUpdaterPong;
|
||||
|
||||
BOOL _willCompleteInstallation;
|
||||
BOOL _receivedInstallationData;
|
||||
BOOL _finishedValidation;
|
||||
BOOL _agentInitiatedConnection;
|
||||
|
||||
// Setting _performedStage1Installation on main thread must be synchronzied with reading it from new connection handler
|
||||
BOOL _performedStage1Installation;
|
||||
|
||||
BOOL _performedStage2Installation;
|
||||
BOOL _performedStage3Installation;
|
||||
|
||||
BOOL _targetTerminated;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
_newConnectionLock = OS_UNFAIR_LOCK_INIT;
|
||||
|
||||
_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
|
||||
{
|
||||
os_unfair_lock_lock(&_newConnectionLock);
|
||||
{
|
||||
if (_activeConnection != nil) {
|
||||
os_unfair_lock_unlock(&_newConnectionLock);
|
||||
|
||||
SULog(SULogLevelError, @"Error: Rejecting multiple XPC connections for installer...");
|
||||
|
||||
[newConnection invalidate];
|
||||
return NO;
|
||||
}
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
BOOL connectionCodeSigningValidationSkipped = NO;
|
||||
#endif
|
||||
|
||||
// It's safe to allow any connections once stage 1 installation is complete
|
||||
// This is to allow general updaters to resume the installation.
|
||||
if (!_performedStage1Installation) {
|
||||
BOOL passesValidation;
|
||||
NSError *validationError = nil;
|
||||
SUValidateConnectionStatus status = [SUCodeSigningVerifier validateConnection:newConnection error:&validationError];
|
||||
switch (status) {
|
||||
case SUValidateConnectionStatusSetCodeSigningRequirementSuccess:
|
||||
passesValidation = YES;
|
||||
break;
|
||||
case SUValidateConnectionStatusSetNoRequirementSuccess:
|
||||
passesValidation = YES;
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
connectionCodeSigningValidationSkipped = YES;
|
||||
#endif
|
||||
break;
|
||||
case SUValidateConnectionStatusAPIFailure:
|
||||
case SUValidateConnectionStatusCodeSigningRequirementFailure:
|
||||
case SUValidateConectionNoSupportedValidationMethodFailure:
|
||||
passesValidation = NO;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!passesValidation) {
|
||||
os_unfair_lock_unlock(&_newConnectionLock);
|
||||
|
||||
SULog(SULogLevelError, @"Error: Rejecting new connection for installer due to failing validation of XPC connection with status %lu and error: %@", status, validationError.localizedDescription);
|
||||
[newConnection invalidate];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
_connectionCodeSigningValidationSkipped = connectionCodeSigningValidationSkipped;
|
||||
#endif
|
||||
_activeConnection = newConnection;
|
||||
}
|
||||
os_unfair_lock_unlock(&_newConnectionLock);
|
||||
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
newConnection.exportedObject = self;
|
||||
|
||||
newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
newConnection.interruptionHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
os_unfair_lock_lock(&strongSelf->_newConnectionLock);
|
||||
NSXPCConnection *activeConnection = strongSelf->_activeConnection;
|
||||
os_unfair_lock_unlock(&strongSelf->_newConnectionLock);
|
||||
|
||||
[activeConnection invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
newConnection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__typeof__(self) 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;
|
||||
|
||||
os_unfair_lock_lock(&strongSelf->_newConnectionLock);
|
||||
strongSelf->_activeConnection = nil;
|
||||
os_unfair_lock_unlock(&strongSelf->_newConnectionLock);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// _communicator is used only on main thread
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->_communicator = newConnection.remoteObjectProxy;
|
||||
[newConnection resume];
|
||||
});
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
[_xpcListener resume];
|
||||
[_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 SPU_OBJC_DIRECT
|
||||
{
|
||||
[_communicator handleMessageWithIdentifier:SPUExtractionStarted data:[NSData data]];
|
||||
|
||||
NSString *archivePath = [_updateDirectoryPath stringByAppendingPathComponent:_downloadName];
|
||||
|
||||
id<SUUnarchiverProtocol> unarchiver = [SUUnarchiver unarchiverForPath:archivePath extractionDirectory:_extractionDirectory updatingHostBundlePath:_host.bundlePath decryptionPassword:_decryptionPassword expectingInstallationType:_installationType];
|
||||
|
||||
NSError *prevalidationError = nil;
|
||||
BOOL success = NO;
|
||||
if (!unarchiver) {
|
||||
prevalidationError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"No valid unarchiver was found for %@", archivePath] }];
|
||||
|
||||
success = NO;
|
||||
} else {
|
||||
NSError *fileAttributesError = nil;
|
||||
NSDictionary<NSFileAttributeKey, id> *archiveFileAttributes = [NSFileManager.defaultManager attributesOfItemAtPath:archivePath error:&fileAttributesError];
|
||||
if (archiveFileAttributes == nil) {
|
||||
SULog(SULogLevelError, @"Failed to retrieve file attributes from archive: %@.", fileAttributesError);
|
||||
} else {
|
||||
_verifierInformation.actualContentLength = (uint64_t)(archiveFileAttributes.fileSize);
|
||||
}
|
||||
|
||||
_updateValidator = [[SUUpdateValidator alloc] initWithDownloadPath:archivePath signatures:_signatures host:_host verifierInformation:_verifierInformation];
|
||||
|
||||
// More uncommon archives types (.aar, .yaa) need SUVerifyUpdateBeforeExtraction
|
||||
BOOL verifyBeforeExtraction = [_host boolForInfoDictionaryKey:SUVerifyUpdateBeforeExtractionKey];
|
||||
if (!verifyBeforeExtraction && unarchiver.needsVerifyBeforeExtractionKey) {
|
||||
prevalidationError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Extracting %@ archives require setting %@ to YES in the old app. Please visit https://sparkle-project.org/documentation/customization/ for more information.", archivePath.pathExtension, SUVerifyUpdateBeforeExtractionKey] }];
|
||||
|
||||
success = NO;
|
||||
} else {
|
||||
// Delta, package updates, and apps with SUVerifyUpdateBeforeExtraction will require validation before extraction
|
||||
// Otherwise normal application updates are a bit more lenient allowing developers to change one of apple dev ID or EdDSA keys after extraction
|
||||
BOOL archiveTypeMustValidateBeforeExtraction = [[unarchiver class] mustValidateBeforeExtraction];
|
||||
BOOL needsPrevalidation = verifyBeforeExtraction || archiveTypeMustValidateBeforeExtraction || ![_installationType isEqualToString:SPUInstallationTypeApplication];
|
||||
|
||||
if (needsPrevalidation) {
|
||||
// EdDSA signing is required, so host must have public keys
|
||||
if (![_updateValidator validateHostHasPublicKeys:&prevalidationError]) {
|
||||
success = NO;
|
||||
} else {
|
||||
// Falling back on code signing for prevalidation requires SUVerifyUpdateBeforeExtraction
|
||||
// and that update is a regular app update, and not a delta update
|
||||
BOOL fallbackOnCodeSigning = (verifyBeforeExtraction && !archiveTypeMustValidateBeforeExtraction && [_installationType isEqualToString:SPUInstallationTypeApplication]);
|
||||
|
||||
success = [_updateValidator validateDownloadPathWithFallbackOnCodeSigning:fallbackOnCodeSigning error:&prevalidationError];
|
||||
}
|
||||
} else {
|
||||
success = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
[self unarchiverDidFailWithError:prevalidationError];
|
||||
} 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->_extractionDirectory 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];
|
||||
}
|
||||
} waitForCleanup:NO];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)clearUpdateDirectory SPU_OBJC_DIRECT
|
||||
{
|
||||
if (_updateDirectoryPath != nil) {
|
||||
NSError *theError = nil;
|
||||
if (![[[SUFileManager alloc] init] removeItemAtURL:[NSURL fileURLWithPath:_updateDirectoryPath] error:&theError]) {
|
||||
SULog(SULogLevelError, @"Couldn't remove update folder: %@.", theError);
|
||||
}
|
||||
_updateDirectoryPath = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFailWithError:(NSError *)error SPU_OBJC_DIRECT
|
||||
{
|
||||
SULog(SULogLevelError, @"Failed to unarchive file");
|
||||
SULogError(error);
|
||||
|
||||
// No longer need update validator until next possible extraction (eg: if initial delta update fails)
|
||||
_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];
|
||||
_downloadName = nil;
|
||||
_extractionDirectory = nil;
|
||||
_decryptionPassword = nil;
|
||||
_signatures = nil;
|
||||
_relaunchPath = nil;
|
||||
_host = nil;
|
||||
|
||||
NSData *archivedError = SPUArchiveRootObjectSecurely(error);
|
||||
[_communicator handleMessageWithIdentifier:SPUArchiveExtractionFailed data:archivedError != nil ? archivedError : [NSData data]];
|
||||
}
|
||||
|
||||
- (void)agentConnectionDidInitiate
|
||||
{
|
||||
_agentInitiatedConnection = YES;
|
||||
if (_finishedValidation) {
|
||||
[self retrieveProcessIdentifierAndStartInstallation];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)agentConnectionDidInvalidate
|
||||
{
|
||||
if (!_finishedValidation || !_agentInitiatedConnection || !_targetTerminated) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey: @"Error: Agent connection invalidated before installation began" }];
|
||||
|
||||
NSError *agentError = _agentConnection.invalidationError;
|
||||
if (agentError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = agentError;
|
||||
}
|
||||
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:userInfo]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)retrieveProcessIdentifierAndStartInstallation SPU_OBJC_DIRECT
|
||||
{
|
||||
// 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
|
||||
|
||||
__block BOOL receivedResponse = NO;
|
||||
[_agentConnection.agent registerApplicationBundlePath:_relaunchPath reply:^(BOOL targetTerminated) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
receivedResponse = YES;
|
||||
|
||||
if (!targetTerminated) {
|
||||
[self->_agentConnection.agent listenForTerminationWithCompletion:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->_targetTerminated = YES;
|
||||
|
||||
if (self->_performedStage1Installation) {
|
||||
[self finishInstallationAfterHostTermination];
|
||||
}
|
||||
});
|
||||
}];
|
||||
} else {
|
||||
self->_targetTerminated = YES;
|
||||
}
|
||||
|
||||
[self startInstallation];
|
||||
});
|
||||
}];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(RETRIEVE_PROCESS_IDENTIFIER_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (!receivedResponse) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Timeout error: failed to retrieve process identifier from agent" }]];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
{
|
||||
if (identifier == SPUInstallationData && _updateDirectoryPath == nil) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Mark that we have received the installation data
|
||||
// Do not rely on eg: self->_updateDirectoryPath != nil because we may set it to nil again if an early stage fails (i.e, archive extraction)
|
||||
self->_receivedInstallationData = YES;
|
||||
|
||||
SPUInstallationInputData *installationData = (data != nil) ? (SPUInstallationInputData *)SPUUnarchiveRootObjectSecurely(data, [SPUInstallationInputData class]) : nil;
|
||||
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;
|
||||
}
|
||||
|
||||
// Resolve the bookmark data for the downloaded update
|
||||
// See "Share file access between processes with URL bookmarks" in https://developer.apple.com/documentation/security/app_sandbox/accessing_files_from_the_macos_app_sandbox
|
||||
BOOL isStale = NO;
|
||||
NSError *bookmarkError = nil;
|
||||
NSURL *downloadURL = [NSURL URLByResolvingBookmarkData:installationData.updateURLBookmarkData options:NSURLBookmarkResolutionWithoutUI relativeToURL:nil bookmarkDataIsStale:&isStale error:&bookmarkError];
|
||||
if (downloadURL == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to resolve bookmark data from downloaded update", NSUnderlyingErrorKey: bookmarkError }]];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate the download URL before moving it
|
||||
{
|
||||
NSArray<NSString *> *downloadURLPathComponents = downloadURL.URLByResolvingSymlinksInPath.pathComponents;
|
||||
if (downloadURLPathComponents == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to retrieve path components from download URL" }]];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ([downloadURLPathComponents containsObject:@".."]) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: download URL path components contains '..' which is unsafe" }]];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (![downloadURLPathComponents containsObject:@SPARKLE_BUNDLE_IDENTIFIER] || ![downloadURLPathComponents containsObject:@"PersistentDownloads"]) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: download URL path components does not contain PersistentDownloads or "@SPARKLE_BUNDLE_IDENTIFIER }]];
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isStale) {
|
||||
SULog(SULogLevelError, @"Error: bookmark data for update download is stale.. but still continuing.");
|
||||
}
|
||||
|
||||
NSString *originalDownloadName = downloadURL.lastPathComponent;
|
||||
if (originalDownloadName == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to retrieve download name from download URL" }]];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Randomize the download name if possible
|
||||
// This adds better security if there are any vulnerabilities in extracting/executing archives
|
||||
// which allow writing in unexpected locations. For zip/tar/dmg archives we may also extract them before
|
||||
// performing signing validation (due to key rotation).
|
||||
NSString *downloadName;
|
||||
NSString *randomizedUUIDString = [[NSUUID UUID] UUIDString];
|
||||
if (randomizedUUIDString != nil) {
|
||||
// Find the real path extension of the download name
|
||||
// We cannot use -[NSString pathExtension] because it may not give us the full path extension
|
||||
// E.g. for "foo.tar.xz" we need "tar.xz", not "xz"
|
||||
NSString *downloadPathExtension;
|
||||
NSRange pathExtensionDelimiterRange = [originalDownloadName rangeOfString:@"."];
|
||||
if (pathExtensionDelimiterRange.location == NSNotFound) {
|
||||
downloadPathExtension = @"";
|
||||
} else {
|
||||
downloadPathExtension = [originalDownloadName substringFromIndex:pathExtensionDelimiterRange.location + 1];
|
||||
}
|
||||
|
||||
NSString *randomizedDownloadName = [randomizedUUIDString stringByAppendingPathExtension:downloadPathExtension];
|
||||
if (randomizedDownloadName != nil) {
|
||||
downloadName = randomizedDownloadName;
|
||||
} else {
|
||||
downloadName = originalDownloadName;
|
||||
}
|
||||
} else {
|
||||
downloadName = originalDownloadName;
|
||||
}
|
||||
|
||||
// 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 *downloadDestinationURL = [[NSURL fileURLWithPath:cacheInstallationPath] URLByAppendingPathComponent: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;
|
||||
}
|
||||
|
||||
NSString *extractionDirectory = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:cacheInstallationPath];
|
||||
if (extractionDirectory == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Failed to create installation extraction directory in %@", cacheInstallationPath] }]];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Carry these properties 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 = downloadName;
|
||||
self->_signatures = installationData.signatures;
|
||||
self->_updateDirectoryPath = cacheInstallationPath;
|
||||
self->_extractionDirectory = extractionDirectory;
|
||||
self->_decryptionPassword = installationData.decryptionPassword;
|
||||
self->_host = [[SUHost alloc] initWithBundle:hostBundle];
|
||||
self->_verifierInformation = [[SPUVerifierInformation alloc] initWithExpectedVersion:installationData.expectedVersion expectedContentLength:installationData.expectedContentLength];
|
||||
|
||||
[self extractAndInstallUpdate];
|
||||
});
|
||||
} else if (identifier == SPUSentUpdateAppcastItemData) {
|
||||
SUAppcastItem *updateItem = (data != nil) ? (SUAppcastItem *)SPUUnarchiveRootObjectSecurely(data, [SUAppcastItem class]) : nil;
|
||||
if (updateItem != nil) {
|
||||
SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem];
|
||||
|
||||
NSData *archivedData = SPUArchiveRootObjectSecurely(installationInfo);
|
||||
if (archivedData != nil) {
|
||||
[_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 showing UI progress during 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, ^{
|
||||
if (!self->_performedStage2Installation) {
|
||||
[self performStage2Installation];
|
||||
} else if (!self->_performedStage3Installation) {
|
||||
// If we already performed the 2nd stage, re-purpose this request to re-try sending another termination signal
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// 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 if (identifier == SPUCancelInstallation) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:0 error:nil];
|
||||
});
|
||||
} else if (identifier == SPUUpdaterAlivePong) {
|
||||
_receivedUpdaterPong = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startInstallation SPU_OBJC_DIRECT
|
||||
{
|
||||
_willCompleteInstallation = YES;
|
||||
|
||||
dispatch_queue_attr_t queuePriority = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INITIATED, 0);
|
||||
|
||||
_installerQueue = dispatch_queue_create("org.sparkle-project.sparkle.installer", queuePriority);
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
os_unfair_lock_lock(&_newConnectionLock);
|
||||
BOOL connectionCodeSigningValidationSkipped = self->_connectionCodeSigningValidationSkipped;
|
||||
os_unfair_lock_unlock(&_newConnectionLock);
|
||||
#else
|
||||
BOOL connectionCodeSigningValidationSkipped = NO;
|
||||
#endif
|
||||
|
||||
dispatch_async(_installerQueue, ^{
|
||||
NSError *installerError = nil;
|
||||
id <SUInstallerProtocol> installer = [SUInstaller installerForHost:self->_host expectedInstallationType:self->_installationType updateDirectory:self->_extractionDirectory connectionCodeSigningValidationSkipped:connectionCodeSigningValidationSkipped 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;
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->_installer = installer;
|
||||
|
||||
os_unfair_lock_lock(&self->_newConnectionLock);
|
||||
self->_performedStage1Installation = YES;
|
||||
os_unfair_lock_unlock(&self->_newConnectionLock);
|
||||
|
||||
uint8_t targetTerminated = (uint8_t)self->_targetTerminated;
|
||||
|
||||
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
|
||||
|
||||
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage1 data:sendData];
|
||||
|
||||
if (self->_targetTerminated) {
|
||||
// Stage 2 can still be run before we finish installation
|
||||
// if the updater requests for it before the app is terminated
|
||||
[self finishInstallationAfterHostTermination];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
- (void)performStage2Installation SPU_OBJC_DIRECT
|
||||
{
|
||||
_performedStage2Installation = YES;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
uint8_t targetTerminated = (uint8_t)self->_targetTerminated;
|
||||
|
||||
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];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)finishInstallationAfterHostTermination SPU_OBJC_DIRECT
|
||||
{
|
||||
assert(self->_targetTerminated);
|
||||
|
||||
// Show our installer progress UI tool if only after a certain amount of time passes
|
||||
__block BOOL shouldShowUIProgress = YES;
|
||||
if (self->_shouldShowUI) {
|
||||
// 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, ^{
|
||||
if (!self->_performedStage2Installation) {
|
||||
[self performStage2Installation];
|
||||
}
|
||||
|
||||
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) {
|
||||
[_communicator handleMessageWithIdentifier:SPUInstallerError data:errorData];
|
||||
}
|
||||
}
|
||||
|
||||
// It's nice to tell the other end we're invalidating
|
||||
|
||||
os_unfair_lock_lock(&_newConnectionLock);
|
||||
|
||||
NSXPCConnection *activeConnection = _activeConnection;
|
||||
_activeConnection = nil;
|
||||
|
||||
os_unfair_lock_unlock(&_newConnectionLock);
|
||||
|
||||
[activeConnection invalidate];
|
||||
|
||||
[_xpcListener invalidate];
|
||||
_xpcListener = nil;
|
||||
|
||||
[_agentConnection invalidate];
|
||||
_agentConnection = nil;
|
||||
|
||||
[self clearUpdateDirectory];
|
||||
|
||||
exit(status);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,19 +0,0 @@
|
||||
//
|
||||
// SPUDeltaArchive.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/29/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol SPUDeltaArchiveProtocol;
|
||||
@class SPUDeltaArchiveHeader;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Opens patch file for reading and decodes the archive header
|
||||
id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFile, SPUDeltaArchiveHeader * _Nullable __autoreleasing * _Nullable outHeader);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,124 +0,0 @@
|
||||
//
|
||||
// SPUDeltaArchive.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/29/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SPUDeltaArchive.h"
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
#import "SPUSparkleDeltaArchive.h"
|
||||
#import "SPUXarDeltaArchive.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
SPUDeltaCompressionMode SPUDeltaCompressionModeDefault = (SPUDeltaCompressionMode)UINT8_MAX;
|
||||
|
||||
id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFile, SPUDeltaArchiveHeader * _Nullable __autoreleasing * _Nullable outHeader)
|
||||
{
|
||||
id<SPUDeltaArchiveProtocol> sparkleArchive = [[SPUSparkleDeltaArchive alloc] initWithPatchFileForReading:patchFile];
|
||||
|
||||
SPUDeltaArchiveHeader *header = [sparkleArchive readHeader];
|
||||
if (header == nil) {
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
NSError *archiveError = sparkleArchive.error;
|
||||
if (archiveError != nil && [archiveError.domain isEqualToString:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN] && archiveError.code == SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_MAGIC) {
|
||||
// Retry with XAR archive if the magic value is unexpected
|
||||
[sparkleArchive close];
|
||||
|
||||
id<SPUDeltaArchiveProtocol> xarArchive = [[SPUXarDeltaArchive alloc] initWithPatchFileForReading:patchFile];
|
||||
|
||||
SPUDeltaArchiveHeader *xarHeader = [xarArchive readHeader];
|
||||
if (outHeader != NULL) {
|
||||
*outHeader = xarHeader;
|
||||
}
|
||||
return xarArchive;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (outHeader != NULL) {
|
||||
*outHeader = nil;
|
||||
}
|
||||
return sparkleArchive;
|
||||
}
|
||||
} else {
|
||||
if (outHeader != NULL) {
|
||||
*outHeader = header;
|
||||
}
|
||||
return sparkleArchive;
|
||||
}
|
||||
}
|
||||
|
||||
@implementation SPUDeltaArchiveItem
|
||||
|
||||
@synthesize relativeFilePath = _relativeFilePath;
|
||||
@synthesize itemFilePath = _itemFilePath;
|
||||
@synthesize clonedRelativePath = _clonedRelativePath;
|
||||
@synthesize sourcePath = _sourcePath;
|
||||
@synthesize commands = _commands;
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
@synthesize xarContext = _xarContext;
|
||||
#endif
|
||||
@synthesize mode = _mode;
|
||||
@synthesize codedDataLength = _codedDataLength;
|
||||
|
||||
- (instancetype)initWithRelativeFilePath:(NSString *)relativeFilePath commands:(SPUDeltaItemCommands)commands mode:(uint16_t)mode
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_relativeFilePath = [relativeFilePath copy];
|
||||
_commands = commands;
|
||||
_mode = mode;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUDeltaArchiveHeader
|
||||
{
|
||||
unsigned char _beforeTreeHash[BINARY_DELTA_HASH_LENGTH];
|
||||
unsigned char _afterTreeHash[BINARY_DELTA_HASH_LENGTH];
|
||||
}
|
||||
|
||||
@synthesize compression = _compression;
|
||||
@synthesize compressionLevel = _compressionLevel;
|
||||
@synthesize fileSystemCompression = _fileSystemCompression;
|
||||
@synthesize majorVersion = _majorVersion;
|
||||
@synthesize minorVersion = _minorVersion;
|
||||
@synthesize bundleCreationDate = _bundleCreationDate;
|
||||
|
||||
- (instancetype)initWithCompression:(SPUDeltaCompressionMode)compression compressionLevel:(uint8_t)compressionLevel fileSystemCompression:(bool)fileSystemCompression majorVersion:(uint16_t)majorVersion minorVersion:(uint16_t)minorVersion beforeTreeHash:(const unsigned char *)beforeTreeHash afterTreeHash:(const unsigned char *)afterTreeHash bundleCreationDate:(nullable NSDate *)bundleCreationDate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
_compression = compression;
|
||||
_compressionLevel = compressionLevel;
|
||||
_fileSystemCompression = fileSystemCompression;
|
||||
|
||||
_majorVersion = majorVersion;
|
||||
_minorVersion = minorVersion;
|
||||
|
||||
memcpy(_beforeTreeHash, beforeTreeHash, sizeof(_beforeTreeHash));
|
||||
memcpy(_afterTreeHash, afterTreeHash, sizeof(_afterTreeHash));
|
||||
|
||||
_bundleCreationDate = bundleCreationDate;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (unsigned char *)beforeTreeHash
|
||||
{
|
||||
return _beforeTreeHash;
|
||||
}
|
||||
|
||||
- (unsigned char *)afterTreeHash
|
||||
{
|
||||
return _afterTreeHash;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,113 +0,0 @@
|
||||
//
|
||||
// SPUDeltaArchiveProtocol.h
|
||||
// Autoupdate
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/28/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SPUDeltaCompressionMode.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Attributes for an item we extract/write to the archive
|
||||
|
||||
// Note: BinaryDiff cannot coexist together with Delete
|
||||
typedef NS_ENUM(uint8_t, SPUDeltaItemCommands) {
|
||||
SPUDeltaItemCommandEndMarker = 0,
|
||||
SPUDeltaItemCommandDelete = (1u << 0),
|
||||
SPUDeltaItemCommandExtract = (1u << 1),
|
||||
SPUDeltaItemCommandModifyPermissions = (1u << 2),
|
||||
SPUDeltaItemCommandBinaryDiff = (1u << 3),
|
||||
SPUDeltaItemCommandClone = (1u << 4),
|
||||
};
|
||||
|
||||
// Represents header for our archive
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUDeltaArchiveHeader : NSObject
|
||||
|
||||
- (instancetype)initWithCompression:(SPUDeltaCompressionMode)compression compressionLevel:(uint8_t)compressionLevel fileSystemCompression:(bool)fileSystemCompression majorVersion:(uint16_t)majorVersion minorVersion:(uint16_t)minorVersion beforeTreeHash:(const unsigned char *)beforeTreeHash afterTreeHash:(const unsigned char *)afterTreeHash bundleCreationDate:(nullable NSDate *)bundleCreationDate;
|
||||
|
||||
@property (nonatomic, readonly) SPUDeltaCompressionMode compression;
|
||||
@property (nonatomic, readonly) uint8_t compressionLevel;
|
||||
@property (nonatomic, readonly) bool fileSystemCompression;
|
||||
@property (nonatomic, readonly) uint16_t majorVersion;
|
||||
@property (nonatomic, readonly) uint16_t minorVersion;
|
||||
@property (nonatomic, readonly) unsigned char *beforeTreeHash;
|
||||
@property (nonatomic, readonly) unsigned char *afterTreeHash;
|
||||
@property (nonatomic, readonly, nullable) NSDate *bundleCreationDate;
|
||||
|
||||
@end
|
||||
|
||||
// Represents an item we read or write to in our delta archive
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUDeltaArchiveItem : NSObject
|
||||
|
||||
- (instancetype)initWithRelativeFilePath:(NSString *)relativeFilePath commands:(SPUDeltaItemCommands)commands mode:(uint16_t)mode;
|
||||
|
||||
// The relative file path of the item, eg /Contents/MacOS/Foo
|
||||
@property (nonatomic, readonly) NSString *relativeFilePath;
|
||||
// For extraction, the path where the item will be extracted. For creation, the path to the item to add to the archive.
|
||||
@property (nonatomic, nullable) NSString *itemFilePath;
|
||||
// The relative file path of the originating item for clones. This may be null.
|
||||
// For example, if /Contents/Resources/hello/foo.txt moves to /Contents/Resources/hello2/foo.txt, the former is the relative path
|
||||
@property (nonatomic, nullable) NSString *clonedRelativePath;
|
||||
// The source path of the item to extract file metadata from such as file size.
|
||||
@property (nonatomic, nullable) NSString *sourcePath;
|
||||
// The commands that describe the actions to take for this item.
|
||||
@property (nonatomic, readonly) SPUDeltaItemCommands commands;
|
||||
// Provided change in permissions for item or tracking file mode for the item
|
||||
@property (nonatomic) uint16_t mode;
|
||||
|
||||
// Private properties
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
// xar_file context for Xar delta archiver
|
||||
@property (nonatomic, nullable) const void *xarContext;
|
||||
#endif
|
||||
// Tracking length of item's data in data section, when encoding items and when extracting items
|
||||
@property (nonatomic) uint64_t codedDataLength;
|
||||
|
||||
@end
|
||||
|
||||
// A protocol for reading and writing binary delta patches
|
||||
// Operations must be done in order. The header must first be read or written before any other operations.
|
||||
// For reading, file items cannot be extracted out of order.
|
||||
@protocol SPUDeltaArchiveProtocol <NSObject>
|
||||
|
||||
@property (nonatomic, readonly, class) BOOL maySupportSafeExtraction;
|
||||
|
||||
// If non-nil, there was an error with reading or writing data from the archive
|
||||
@property (nonatomic, readonly, nullable) NSError *error;
|
||||
|
||||
// Closes file for reading/writing, called in -dealloc if it's not called manually
|
||||
- (void)close;
|
||||
|
||||
// For reading
|
||||
|
||||
// Retrieves metadata for the archive including major/minor version and expected bundle hashes
|
||||
- (nullable SPUDeltaArchiveHeader *)readHeader;
|
||||
|
||||
// Enumerate through items in the patch file and read the path, attributes, permissions (if permission attribute is available), and way to stop enumeration
|
||||
- (void)enumerateItems:(void (^)(SPUDeltaArchiveItem *item, BOOL *stop))itemHandler;
|
||||
|
||||
// Extract a file item from the patch file to a destination file
|
||||
// The item's physical file path must be set as a destination
|
||||
- (BOOL)extractItem:(SPUDeltaArchiveItem *)item;
|
||||
|
||||
// ------------
|
||||
|
||||
// For writing
|
||||
|
||||
// Set metadata for archive including major/minor version and expected bundle hashes
|
||||
- (void)writeHeader:(SPUDeltaArchiveHeader *)header;
|
||||
|
||||
// Add item to patch file
|
||||
// Physical file path must be provided if there is an extract or binary delta attribute
|
||||
// Permissions are used only if there is a modify permissions attribute
|
||||
- (void)addItem:(SPUDeltaArchiveItem *)item;
|
||||
|
||||
// Finishes encoding items after having added all of them
|
||||
- (void)finishEncodingItems;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,22 +0,0 @@
|
||||
//
|
||||
// SPUDeltaCompressionMode.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 1/3/22.
|
||||
// Copyright © 2022 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// Compression mode to use during patch creation
|
||||
typedef NS_ENUM(uint8_t, SPUDeltaCompressionMode) {
|
||||
SPUDeltaCompressionModeNone = 0,
|
||||
SPUDeltaCompressionModeBzip2,
|
||||
SPUDeltaCompressionModeLZMA,
|
||||
SPUDeltaCompressionModeLZFSE,
|
||||
SPUDeltaCompressionModeLZ4,
|
||||
SPUDeltaCompressionModeZLIB
|
||||
};
|
||||
|
||||
// For Swift access
|
||||
extern SPUDeltaCompressionMode SPUDeltaCompressionModeDefault;
|
||||
@@ -1,25 +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;
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUInstallationInfo : NSObject <NSSecureCoding>
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem;
|
||||
|
||||
@property (nonatomic, readonly) SUAppcastItem *appcastItem;
|
||||
|
||||
@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 systemDomain = _systemDomain;
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_appcastItem = appcastItem;
|
||||
_systemDomain = systemDomain;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem
|
||||
{
|
||||
return [self initWithAppcastItem:appcastItem systemDomain:NO];
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)decoder
|
||||
{
|
||||
SUAppcastItem *appcastItem = [decoder decodeObjectOfClass:[SUAppcastItem class] forKey:SUAppcastItemKey];
|
||||
if (appcastItem == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
BOOL systemDomain = [decoder decodeBoolForKey:SUSystemDomainKey];
|
||||
return [self initWithAppcastItem:appcastItem systemDomain:systemDomain];
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeObject:_appcastItem forKey:SUAppcastItemKey];
|
||||
[coder encodeBool:_systemDomain forKey:SUSystemDomainKey];
|
||||
|
||||
// Installation types can always be silently installed for newer versions of Sparkle
|
||||
// Still encode this key to maintain backwards compatibility with older Sparkle clients
|
||||
[coder encodeBool:YES forKey:SUCanSilentlyInstallKey];
|
||||
}
|
||||
|
||||
+ (BOOL)supportsSecureCoding
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,40 +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
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @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
|
||||
* expectedVersion - optional expected version of the new update
|
||||
* expectedContentLength - optional expected content length of the new download archive
|
||||
*/
|
||||
- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateURLBookmarkData:(NSData *)updateURLBookmarkData installationType:(NSString *)installationType signatures:(SUSignatures * _Nullable)signatures decryptionPassword:(nullable NSString *)decryptionPassword expectedVersion:(NSString *)expectedVersion expectedContentLength:(uint64_t)expectedContentLength;
|
||||
|
||||
@property (nonatomic, copy, readonly) NSString *relaunchPath;
|
||||
@property (nonatomic, copy, readonly) NSString *hostBundlePath;
|
||||
@property (nonatomic, copy, readonly) NSData *updateURLBookmarkData;
|
||||
@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;
|
||||
@property (nonatomic, copy, readonly, nullable) NSString *expectedVersion;
|
||||
@property (nonatomic, readonly) uint64_t expectedContentLength;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,111 +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 *SUUpdateURLBookmarkDataKey = @"SUUpdateURLBookmarkData";
|
||||
static NSString *SUSignaturesKey = @"SUSignatures";
|
||||
static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword";
|
||||
static NSString *SUInstallationTypeKey = @"SUInstallationType";
|
||||
static NSString *SUExpectedVersionKey = @"SUExpectedVersion";
|
||||
static NSString *SUExpectedContentLength = @"SUExpectedContentLength";
|
||||
|
||||
@implementation SPUInstallationInputData
|
||||
|
||||
@synthesize relaunchPath = _relaunchPath;
|
||||
@synthesize hostBundlePath = _hostBundlePath;
|
||||
@synthesize updateURLBookmarkData = _updateURLBookmarkData;
|
||||
@synthesize signatures = _signatures;
|
||||
@synthesize decryptionPassword = _decryptionPassword;
|
||||
@synthesize installationType = _installationType;
|
||||
@synthesize expectedVersion = _expectedVersion;
|
||||
@synthesize expectedContentLength = _expectedContentLength;
|
||||
|
||||
- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateURLBookmarkData:(NSData *)updateURLBookmarkData installationType:(NSString *)installationType signatures:(SUSignatures * _Nullable)signatures decryptionPassword:(nullable NSString *)decryptionPassword expectedVersion:(nonnull NSString *)expectedVersion expectedContentLength:(uint64_t)expectedContentLength
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_relaunchPath = [relaunchPath copy];
|
||||
_hostBundlePath = [hostBundlePath copy];
|
||||
_updateURLBookmarkData = updateURLBookmarkData;
|
||||
|
||||
_installationType = [installationType copy];
|
||||
assert(SPUValidInstallationType(_installationType));
|
||||
|
||||
_signatures = signatures;
|
||||
_decryptionPassword = [decryptionPassword copy];
|
||||
|
||||
_expectedVersion = [expectedVersion copy];
|
||||
_expectedContentLength = expectedContentLength;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
NSData *updateURLBookmarkData = [decoder decodeObjectOfClass:[NSData class] forKey:SUUpdateURLBookmarkDataKey];
|
||||
if (updateURLBookmarkData == 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];
|
||||
|
||||
NSString *expectedVersion = [decoder decodeObjectOfClass:[NSString class] forKey:SUExpectedVersionKey];
|
||||
uint64_t expectedContentLength = (uint64_t)[decoder decodeInt64ForKey:SUExpectedContentLength];
|
||||
|
||||
return [self initWithRelaunchPath:relaunchPath hostBundlePath:hostBundlePath updateURLBookmarkData:updateURLBookmarkData installationType:installationType signatures:signatures decryptionPassword:decryptionPassword expectedVersion:expectedVersion expectedContentLength:expectedContentLength];
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeObject:_relaunchPath forKey:SURelaunchPathKey];
|
||||
[coder encodeObject:_hostBundlePath forKey:SUHostBundlePathKey];
|
||||
[coder encodeObject:_updateURLBookmarkData forKey:SUUpdateURLBookmarkDataKey];
|
||||
[coder encodeObject:_installationType forKey:SUInstallationTypeKey];
|
||||
[coder encodeObject:_signatures forKey:SUSignaturesKey];
|
||||
if (_decryptionPassword != nil) {
|
||||
[coder encodeObject:_decryptionPassword forKey:SUDecryptionPasswordKey];
|
||||
}
|
||||
if (_expectedVersion != nil) {
|
||||
[coder encodeObject:_expectedVersion forKey:SUExpectedVersionKey];
|
||||
}
|
||||
[coder encodeInt64:(int64_t)_expectedContentLength forKey:SUExpectedContentLength];
|
||||
}
|
||||
|
||||
+ (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,107 +0,0 @@
|
||||
//
|
||||
// SPUSparkleDeltaArchive.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/30/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
#import "SPUDeltaCompressionMode.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN @"Sparkle Delta Archive"
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_MAGIC 1
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_COMPRESSION_VALUE 2
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CHUNK_SIZE 3
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CLONE_LOOKUP 4
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_TOO_MANY_FILES 5
|
||||
#define SPARKLE_DELTA_ARCHIVE_ERROR_CODE_LINK_TOO_LONG 6
|
||||
|
||||
/*
|
||||
Modern container format for binary delta archives.
|
||||
|
||||
Delta archive format has four sections which are the header, the relative file path table, the commands, and the data blobs.
|
||||
|
||||
The relative file path table records all the file paths the archive needs to know about.
|
||||
The commands are the operations to be recorded (eg: extract, clone, binary diff, delete).
|
||||
The commands may additionally have more metadata such as file permission modes, relative path indexes in the case of clones, or file sizes for the data blobs.
|
||||
The data blobs contain all file data from extract and binary diff outputs.
|
||||
|
||||
The implementation design of this archive is such that we do not seek backwards or skip ahead to fetch data.
|
||||
We go through the archive when writing or reading from it in a single pass.
|
||||
|
||||
-- UNCOMPRESSED --
|
||||
|
||||
[ HEADER (part 1) ]
|
||||
magic (length: 4)
|
||||
compression (length: 1)
|
||||
metadata (See format below. length: 1)
|
||||
|
||||
-- METADATA --
|
||||
compressionLevel (bits [0, 4])
|
||||
(bits [5, 6] reserved)
|
||||
fileSystemCompression (bit 7)
|
||||
|
||||
-- COMPRESSED --
|
||||
|
||||
[ HEADER (part 2)]
|
||||
majorVersion (length: 2)
|
||||
minorVersion (length: 2)
|
||||
beforeTreeHash (length: 40)
|
||||
afterTreeHash (length: 40)
|
||||
|
||||
[ RELATIVE_FILE_PATH_TABLE ]
|
||||
sizeOfRelativeFilePathTable (length: 8 bytes)
|
||||
List of null terminated path strings joined together (N paths)
|
||||
|
||||
[ COMMANDS ]
|
||||
[ Command ]
|
||||
Set of command types for entry (length: 1 byte)
|
||||
Additional metadata for command (see below section)
|
||||
(M commands where M <= N paths)
|
||||
(Indexes for commands refer to indexes to relative file path table, excluding extraneous trailing entries in relative path table used for clones)
|
||||
(Last command must be a ZERO COMMAND (a null terminating command))
|
||||
|
||||
[COMMAND METADATA]
|
||||
[COMMAND: DELETE]
|
||||
N/A: no additional data
|
||||
|
||||
[COMMAND: MODIFY_PERMISSIONS]
|
||||
fileMode (length: 2)
|
||||
|
||||
[COMMAND: CLONE_FILE]
|
||||
sourceRelativePathIndex (length: 4)
|
||||
|
||||
[COMMAND: EXTRACT_FILE]
|
||||
dataLength (length: 8 for regular files, 2 for symbolic links, 0 for directories)
|
||||
|
||||
[COMMAND: BINARY_DIFF_FILE]
|
||||
dataLength (length: 8)
|
||||
|
||||
Note: These command types may be OR'd or combined. In those cases, different commands
|
||||
that have the same attribute (eg dataLength) are not repeated. This list of metadata is also
|
||||
in order in what will be encoded/decoded first.
|
||||
|
||||
EXTRACT_FILE and BINARY_DIFF_FILE cannot be combined.
|
||||
CLONE_FILE and EXTRACT_FILE cannot be combined.
|
||||
MODIFY_PERMISSIONS can be combined with either CLONE_FILE, EXTRACT_FILE, BINARY_DIFF_FILE, or just by itself.
|
||||
CLONE_FILE can be combined with BINARY_DIFF_FILE or just by itself.
|
||||
DELETE can be combined with EXTRACT_FILE, or just by itself. It is only combined with EXTRACT_FILE when the file type (regular, directory, or symlink) changes.
|
||||
|
||||
[ DATA_BLOBS ]
|
||||
All raw binary data joined together
|
||||
(P number of blobs where P <= M commands)
|
||||
(Indexes for data blobs correspond to indexes for a filtered list of applicable commands (EXTRACT_FILE, BINARY_DIFF_FILE) that have data content)
|
||||
*/
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUSparkleDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
|
||||
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile;
|
||||
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,28 +0,0 @@
|
||||
//
|
||||
// SPUXarDeltaArchive.h
|
||||
// Autoupdate
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/28/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
#import "SPUDeltaCompressionMode.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Legacy container format for binary delta archives
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUXarDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
|
||||
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile SPU_OBJC_DIRECT;
|
||||
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile SPU_OBJC_DIRECT;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -1,413 +0,0 @@
|
||||
//
|
||||
// SPUXarDeltaArchive.m
|
||||
// Autoupdate
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/28/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
|
||||
#import "SPUXarDeltaArchive.h"
|
||||
#include <xar/xar.h>
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#import <Availability.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 120000
|
||||
#define HAS_XAR_GET_SAFE_PATH 1
|
||||
#else
|
||||
#define HAS_XAR_GET_SAFE_PATH 0
|
||||
#endif
|
||||
|
||||
#if HAS_XAR_GET_SAFE_PATH
|
||||
// This is preferred over xar_get_path (which is deprecated) when it's available
|
||||
// Don't use OS availability for this API
|
||||
extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
#endif
|
||||
|
||||
// Xar attribute keys
|
||||
#define BINARY_DELTA_ATTRIBUTES_KEY "binary-delta-attributes"
|
||||
#define MAJOR_DIFF_VERSION_KEY "major-version"
|
||||
#define MINOR_DIFF_VERSION_KEY "minor-version"
|
||||
#define BEFORE_TREE_SHA1_KEY "before-tree-sha1"
|
||||
#define AFTER_TREE_SHA1_KEY "after-tree-sha1"
|
||||
#define DELETE_KEY "delete"
|
||||
#define EXTRACT_KEY "extract"
|
||||
#define BINARY_DELTA_KEY "binary-delta"
|
||||
#define MODIFY_PERMISSIONS_KEY "mod-permissions"
|
||||
|
||||
// Errors
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN @"Sparkle XAR Archive"
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE 1
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_ADD_FAILURE 2
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_EXTRACT_FAILURE 3
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_UNSUPPORTED_COMPRESSION_FAILURE 4
|
||||
|
||||
@implementation SPUXarDeltaArchive
|
||||
{
|
||||
NSMutableDictionary<NSString *, NSValue *> *_fileTable;
|
||||
NSString *_patchFile;
|
||||
|
||||
xar_t _x;
|
||||
int32_t _xarMode;
|
||||
}
|
||||
|
||||
@synthesize error = _error;
|
||||
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_patchFile = [patchFile copy];
|
||||
_xarMode = WRITE;
|
||||
_fileTable = [NSMutableDictionary dictionary];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_patchFile = [patchFile copy];
|
||||
_xarMode = READ;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self close];
|
||||
}
|
||||
|
||||
- (void)close
|
||||
{
|
||||
if (_x != NULL) {
|
||||
xar_close(_x);
|
||||
_x = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// This indicates if safe extraction is available at compile time (SDK), but not if it's available at runtime.
|
||||
+ (BOOL)maySupportSafeExtraction
|
||||
{
|
||||
return HAS_XAR_GET_SAFE_PATH;
|
||||
}
|
||||
|
||||
- (nullable SPUDeltaArchiveHeader *)readHeader
|
||||
{
|
||||
NSString *patchFile = _patchFile;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// Sparkle's XAR delta archives have been superseded by Sparkle's own format
|
||||
xar_t x = xar_open(patchFile.fileSystemRepresentation, READ);
|
||||
#pragma clang diagnostic pop
|
||||
if (x == NULL) {
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for reading: %@", patchFile] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
_x = x;
|
||||
|
||||
uint16_t majorDiffVersion = SUBinaryDeltaMajorVersionFirst;
|
||||
uint16_t minorDiffVersion = 0;
|
||||
NSString *expectedBeforeHash = nil;
|
||||
NSString *expectedAfterHash = nil;
|
||||
|
||||
xar_subdoc_t subdoc;
|
||||
for (subdoc = xar_subdoc_first(_x); subdoc; subdoc = xar_subdoc_next(subdoc)) {
|
||||
if (strcmp(xar_subdoc_name(subdoc), BINARY_DELTA_ATTRIBUTES_KEY) == 0) {
|
||||
{
|
||||
// available in version 2.0 or later
|
||||
const char *value = NULL;
|
||||
xar_subdoc_prop_get(subdoc, MAJOR_DIFF_VERSION_KEY, &value);
|
||||
if (value != NULL) {
|
||||
majorDiffVersion = (uint16_t)[@(value) intValue];
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// available in version 2.0 or later
|
||||
const char *value = NULL;
|
||||
xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value);
|
||||
if (value != NULL) {
|
||||
minorDiffVersion = (uint16_t)[@(value) intValue];
|
||||
}
|
||||
}
|
||||
|
||||
// available in version 2.0 or later
|
||||
{
|
||||
const char *value = NULL;
|
||||
xar_subdoc_prop_get(subdoc, BEFORE_TREE_SHA1_KEY, &value);
|
||||
if (value != NULL) {
|
||||
expectedBeforeHash = @(value);
|
||||
}
|
||||
}
|
||||
|
||||
// available in version 2.0 or later
|
||||
{
|
||||
const char *value = NULL;
|
||||
xar_subdoc_prop_get(subdoc, AFTER_TREE_SHA1_KEY, &value);
|
||||
if (value != NULL) {
|
||||
expectedAfterHash = @(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char rawExpectedBeforeHash[BINARY_DELTA_HASH_LENGTH] = {0};
|
||||
getRawHashFromDisplayHash(rawExpectedBeforeHash, expectedBeforeHash);
|
||||
|
||||
unsigned char rawExpectedAfterHash[BINARY_DELTA_HASH_LENGTH] = {0};
|
||||
getRawHashFromDisplayHash(rawExpectedAfterHash, expectedAfterHash);
|
||||
|
||||
// I wasn't able to figure out how to retrieve the compression options from xar,
|
||||
// so we will use default flags to indicate the info isn't available
|
||||
return [[SPUDeltaArchiveHeader alloc] initWithCompression:SPUDeltaCompressionModeDefault compressionLevel:0 fileSystemCompression:false majorVersion:majorDiffVersion minorVersion:minorDiffVersion beforeTreeHash:rawExpectedBeforeHash afterTreeHash:rawExpectedAfterHash bundleCreationDate:nil];
|
||||
}
|
||||
|
||||
- (void)writeHeader:(SPUDeltaArchiveHeader *)header
|
||||
{
|
||||
NSString *patchFile = _patchFile;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// Sparkle's XAR delta archives have been superseded by Sparkle's own format
|
||||
xar_t x = xar_open(patchFile.fileSystemRepresentation, WRITE);
|
||||
#pragma clang diagnostic pop
|
||||
if (x == NULL) {
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for writing: %@", patchFile] }];
|
||||
return;
|
||||
}
|
||||
|
||||
_x = x;
|
||||
|
||||
SPUDeltaCompressionMode compression = (header.compression == SPUDeltaCompressionModeDefault ? SPUDeltaCompressionModeBzip2 : header.compression);
|
||||
|
||||
uint8_t compressionLevel;
|
||||
// Only 1 - 9 are valid, 0 is special case to use default level 9
|
||||
if (header.compressionLevel <= 0 || header.compressionLevel > 9) {
|
||||
compressionLevel = 9;
|
||||
} else {
|
||||
compressionLevel = header.compressionLevel;
|
||||
}
|
||||
|
||||
switch (compression) {
|
||||
case SPUDeltaCompressionModeNone:
|
||||
xar_opt_set(x, XAR_OPT_COMPRESSION, XAR_OPT_VAL_NONE);
|
||||
break;
|
||||
case SPUDeltaCompressionModeBzip2: {
|
||||
xar_opt_set(x, XAR_OPT_COMPRESSION, "bzip2");
|
||||
|
||||
char buffer[256] = {0};
|
||||
snprintf(buffer, sizeof(buffer) - 1, "%d", compressionLevel);
|
||||
xar_opt_set(x, XAR_OPT_COMPRESSIONARG, buffer);
|
||||
|
||||
break;
|
||||
}
|
||||
case SPUDeltaCompressionModeLZMA:
|
||||
case SPUDeltaCompressionModeLZFSE:
|
||||
case SPUDeltaCompressionModeLZ4:
|
||||
case SPUDeltaCompressionModeZLIB: {
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_UNSUPPORTED_COMPRESSION_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Version 2 patches only support bzip2 compression."] }];
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
xar_subdoc_t attributes = xar_subdoc_new(x, BINARY_DELTA_ATTRIBUTES_KEY);
|
||||
|
||||
xar_subdoc_prop_set(attributes, MAJOR_DIFF_VERSION_KEY, [[NSString stringWithFormat:@"%u", header.majorVersion] UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, MINOR_DIFF_VERSION_KEY, [[NSString stringWithFormat:@"%u", header.minorVersion] UTF8String]);
|
||||
|
||||
xar_subdoc_prop_set(attributes, BEFORE_TREE_SHA1_KEY, [displayHashFromRawHash(header.beforeTreeHash) UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, AFTER_TREE_SHA1_KEY, [displayHashFromRawHash(header.afterTreeHash) UTF8String]);
|
||||
}
|
||||
|
||||
static xar_file_t xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTable, xar_t x, NSString *relativePath, NSString *filePath)
|
||||
{
|
||||
NSArray<NSString *> *rootRelativePathComponents = relativePath.pathComponents;
|
||||
// Relative path must at least have starting "/" component and one more path component
|
||||
if (rootRelativePathComponents.count < 2) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NSArray<NSString *> *relativePathComponents = [rootRelativePathComponents subarrayWithRange:NSMakeRange(1, rootRelativePathComponents.count - 1)];
|
||||
|
||||
NSUInteger relativePathComponentsCount = relativePathComponents.count;
|
||||
|
||||
// Build parent files as needed until we get to our final file we want to add
|
||||
// So if we get "Contents/Resources/foo.txt", we will first add "Contents" parent,
|
||||
// then "Resources" parent, then "foo.txt" as the final entry we want to add
|
||||
// We store every file we add into a fileTable for easy referencing
|
||||
// Note if a diff has Contents/Resources/foo/ and Contents/Resources/foo/bar.txt,
|
||||
// due to sorting order we will add the foo directory first and won't end up with
|
||||
// misordering bugs
|
||||
xar_file_t lastParent = NULL;
|
||||
for (NSUInteger componentIndex = 0; componentIndex < relativePathComponentsCount; componentIndex++) {
|
||||
NSArray<NSString *> *subpathComponents = [relativePathComponents subarrayWithRange:NSMakeRange(0, componentIndex + 1)];
|
||||
NSString *subpathKey = [subpathComponents componentsJoinedByString:@"/"];
|
||||
|
||||
xar_file_t cachedFile = (xar_file_t)[fileTable[subpathKey] pointerValue];
|
||||
if (cachedFile != NULL) {
|
||||
lastParent = cachedFile;
|
||||
} else {
|
||||
xar_file_t newParent;
|
||||
|
||||
BOOL atLastIndex = (componentIndex == relativePathComponentsCount - 1);
|
||||
|
||||
NSString *lastPathComponent = subpathComponents.lastObject;
|
||||
if (atLastIndex && filePath != nil) {
|
||||
newParent = xar_add_frompath(x, lastParent, lastPathComponent.fileSystemRepresentation, filePath.fileSystemRepresentation);
|
||||
} else {
|
||||
newParent = xar_add_frombuffer(x, lastParent, lastPathComponent.fileSystemRepresentation, "", 1);
|
||||
}
|
||||
|
||||
lastParent = newParent;
|
||||
fileTable[subpathKey] = [NSValue valueWithPointer:newParent];
|
||||
}
|
||||
}
|
||||
return lastParent;
|
||||
}
|
||||
|
||||
- (void)addItem:(SPUDeltaArchiveItem *)item
|
||||
{
|
||||
if (_error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *relativeFilePath = item.relativeFilePath;
|
||||
NSString *filePath = item.itemFilePath;
|
||||
SPUDeltaItemCommands commands = item.commands;
|
||||
uint16_t mode = item.mode;
|
||||
|
||||
xar_file_t newFile = xarAddFile(_fileTable, _x, relativeFilePath, filePath);
|
||||
if (newFile == NULL) {
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_ADD_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to add xar file entry: %@", relativeFilePath] }];
|
||||
return;
|
||||
}
|
||||
|
||||
if ((commands & SPUDeltaItemCommandDelete) != 0) {
|
||||
xar_prop_set(newFile, DELETE_KEY, "true");
|
||||
}
|
||||
|
||||
if ((commands & SPUDeltaItemCommandExtract) != 0) {
|
||||
xar_prop_set(newFile, EXTRACT_KEY, "true");
|
||||
}
|
||||
|
||||
if ((commands & SPUDeltaItemCommandBinaryDiff) != 0) {
|
||||
xar_prop_set(newFile, BINARY_DELTA_KEY, "true");
|
||||
}
|
||||
|
||||
if ((commands & SPUDeltaItemCommandModifyPermissions) != 0) {
|
||||
xar_prop_set(newFile, MODIFY_PERMISSIONS_KEY, [NSString stringWithFormat:@"%u", mode].UTF8String);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)finishEncodingItems
|
||||
{
|
||||
// Items are already encoded when they are extracted prior
|
||||
}
|
||||
|
||||
- (void)enumerateItems:(void (^)(SPUDeltaArchiveItem *, BOOL *))itemHandler
|
||||
{
|
||||
if (_error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL exitedEarly = NO;
|
||||
xar_iter_t iter = xar_iter_new();
|
||||
for (xar_file_t file = xar_file_first(_x, iter); file; file = xar_file_next(iter)) {
|
||||
char *pathCString;
|
||||
#if HAS_XAR_GET_SAFE_PATH
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
||||
if (xar_get_safe_path != NULL) {
|
||||
pathCString = xar_get_safe_path(file);
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
pathCString = xar_get_path(file);
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
if (pathCString == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *relativePath = [[NSString alloc] initWithBytesNoCopy:pathCString length:strlen(pathCString) encoding:NSUTF8StringEncoding freeWhenDone:YES];
|
||||
if (relativePath == nil) {
|
||||
free(pathCString);
|
||||
continue;
|
||||
}
|
||||
|
||||
SPUDeltaItemCommands commands = (SPUDeltaItemCommands)0;
|
||||
{
|
||||
const char *value = NULL;
|
||||
if (xar_prop_get(file, DELETE_KEY, &value) == 0) {
|
||||
commands |= SPUDeltaItemCommandDelete;
|
||||
}
|
||||
}
|
||||
{
|
||||
const char *value = NULL;
|
||||
if (xar_prop_get(file, BINARY_DELTA_KEY, &value) == 0) {
|
||||
commands |= SPUDeltaItemCommandBinaryDiff;
|
||||
}
|
||||
}
|
||||
{
|
||||
const char *value = NULL;
|
||||
if (xar_prop_get(file, EXTRACT_KEY, &value) == 0) {
|
||||
commands |= SPUDeltaItemCommandExtract;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t mode = 0;
|
||||
{
|
||||
const char *value = NULL;
|
||||
if (xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value) == 0) {
|
||||
commands |= SPUDeltaItemCommandModifyPermissions;
|
||||
mode = (uint16_t)[@(value) intValue];
|
||||
}
|
||||
}
|
||||
|
||||
SPUDeltaArchiveItem *item = [[SPUDeltaArchiveItem alloc] initWithRelativeFilePath:relativePath commands:commands mode:mode];
|
||||
item.xarContext = file;
|
||||
|
||||
itemHandler(item, &exitedEarly);
|
||||
if (exitedEarly) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
xar_iter_free(iter);
|
||||
}
|
||||
|
||||
- (BOOL)extractItem:(SPUDeltaArchiveItem *)item
|
||||
{
|
||||
if (_error != nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
assert(item.itemFilePath != nil);
|
||||
assert(item.xarContext != NULL);
|
||||
|
||||
xar_file_t file = (xar_file_t)item.xarContext;
|
||||
if (xar_extract_tofile(_x, file, item.itemFilePath.fileSystemRepresentation) != 0) {
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_EXTRACT_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to extract xar file entry to %@", item.itemFilePath] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,492 +0,0 @@
|
||||
//
|
||||
// SUBinaryDeltaApply.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
#import "SPUDeltaArchive.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#include "bspatch.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#import <sys/stat.h>
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
static BOOL applyBinaryDeltaToFile(NSString *patchFile, NSString *sourceFilePath, NSString *destinationFilePath)
|
||||
{
|
||||
const char *argv[] = {"/usr/bin/bspatch", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation], [patchFile fileSystemRepresentation]};
|
||||
BOOL success = (bspatch(4, argv) == 0);
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
return success;
|
||||
}
|
||||
|
||||
BOOL applyBinaryDelta(NSString *source, NSString *finalDestination, NSString *patchFile, BOOL verbose, void (^progressCallback)(double progress), NSError *__autoreleasing *error)
|
||||
{
|
||||
SPUDeltaArchiveHeader *header = nil;
|
||||
id<SPUDeltaArchiveProtocol> archive = SPUDeltaArchiveReadPatchAndHeader(patchFile, &header);
|
||||
if (archive.error != nil) {
|
||||
if (error != NULL) {
|
||||
*error = archive.error;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
progressCallback(0/7.0);
|
||||
|
||||
SUBinaryDeltaMajorVersion majorDiffVersion = (SUBinaryDeltaMajorVersion)header.majorVersion;
|
||||
uint16_t minorDiffVersion = header.minorVersion;
|
||||
|
||||
unsigned char *expectedBeforeHash = header.beforeTreeHash;
|
||||
unsigned char *expectedAfterHash = header.afterTreeHash;
|
||||
|
||||
if (majorDiffVersion < SUBinaryDeltaMajorVersionFirst) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to identify diff-version %u in delta. Giving up.", majorDiffVersion] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (majorDiffVersion < SUBinaryDeltaMajorVersionFirstSupported) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Applying version %u patches is no longer supported.", majorDiffVersion] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (majorDiffVersion > SUBinaryDeltaMajorVersionLatest) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"A later version is needed to apply this patch (on major version %u, but patch requests version %u).", SUBinaryDeltaMajorVersionLatest, majorDiffVersion] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Reject patches that did not generate valid hierarchical xar container paths
|
||||
// These will not succeed to patch using recent versions of BinaryDelta
|
||||
if ([[archive class] maySupportSafeExtraction] && majorDiffVersion == SUBinaryDeltaMajorVersion2 && minorDiffVersion < 3) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"This patch version (%u.%u) is too old and potentially unsafe to apply. Please re-generate the patch using the latest version of BinaryDelta or generate_appcast. New version %u.%u patches will still be compatible with older versions of Sparkle.", majorDiffVersion, minorDiffVersion, majorDiffVersion, latestMinorVersionForMajorVersion(majorDiffVersion)] }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (expectedBeforeHash == nil || expectedAfterHash == nil) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{ NSLocalizedDescriptionKey: @"Unable to find before-sha1 or after-sha1 metadata in delta. Giving up." }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Applying version %u.%u patch...\n", majorDiffVersion, minorDiffVersion);
|
||||
fprintf(stderr, "Verifying source...");
|
||||
}
|
||||
|
||||
progressCallback(1/7.0);
|
||||
|
||||
unsigned char beforeHash[BINARY_DELTA_HASH_LENGTH] = {0};
|
||||
if (!getRawHashOfTreeWithVersion(beforeHash, source, majorDiffVersion)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to calculate hash of tree %@", source] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (memcmp(beforeHash, expectedBeforeHash, BINARY_DELTA_HASH_LENGTH) != 0) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Source doesn't have expected hash (%@ != %@). Giving up.", displayHashFromRawHash(expectedBeforeHash), displayHashFromRawHash(beforeHash)] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nCopying files...");
|
||||
}
|
||||
|
||||
progressCallback(2/7.0);
|
||||
|
||||
// Make a temporary destination path if necessary
|
||||
// If we want to apply file system compression after we're done applying, we'll need to use a different
|
||||
// temporary path
|
||||
NSString *destination;
|
||||
if (header.fileSystemCompression) {
|
||||
destination = [finalDestination.stringByDeletingLastPathComponent stringByAppendingPathComponent:[NSString stringWithFormat:@".tmp.%@", finalDestination.lastPathComponent]];
|
||||
} else {
|
||||
destination = finalDestination;
|
||||
}
|
||||
|
||||
if (!removeTree(destination)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to remove %@", destination] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
progressCallback(3/7.0);
|
||||
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
|
||||
if (!copyTree(fileManager, source, destination)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to copy %@ to %@", source, destination] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Preserve file creation date only for the root item if the date is recorded
|
||||
// (requires major version 4 or later)
|
||||
NSDate *bundleCreationDate = header.bundleCreationDate;
|
||||
if (bundleCreationDate != nil) {
|
||||
NSError *setFileCreationDateError = nil;
|
||||
if (![fileManager setAttributes:@{NSFileCreationDate: bundleCreationDate} ofItemAtPath:destination error:&setFileCreationDateError]) {
|
||||
fprintf(stderr, "\nWarning: failed to set file creation date: %s", setFileCreationDateError.localizedDescription.UTF8String);
|
||||
}
|
||||
}
|
||||
|
||||
progressCallback(4/7.0);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nPatching...");
|
||||
}
|
||||
|
||||
// Ensure error is cleared out in advance
|
||||
if (error != NULL) {
|
||||
*error = nil;
|
||||
}
|
||||
|
||||
[archive enumerateItems:^(SPUDeltaArchiveItem *item, BOOL *stop) {
|
||||
NSString *relativePath = item.relativeFilePath;
|
||||
|
||||
if ([relativePath.pathComponents containsObject:@".."]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path '%@' contains '..' path component", relativePath] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *sourceFilePath = [source stringByAppendingPathComponent:relativePath];
|
||||
NSString *destinationFilePath = [destination stringByAppendingPathComponent:relativePath];
|
||||
{
|
||||
NSString *destinationParentDirectory = destinationFilePath.stringByDeletingLastPathComponent;
|
||||
NSDictionary<NSFileAttributeKey, id> *destinationParentDirectoryAttributes = [fileManager attributesOfItemAtPath:destinationParentDirectory error:NULL];
|
||||
|
||||
// It is OK for the directory parent to not exist if it has already been removed
|
||||
if (destinationParentDirectoryAttributes != nil) {
|
||||
// But if it does exist, make sure the entry in the parent directory we're looking at is good
|
||||
// If it's inside a symlink, this is not good in any circumstance
|
||||
NSString *fileType = destinationParentDirectoryAttributes[NSFileType];
|
||||
if ([fileType isEqualToString:NSFileTypeSymbolicLink]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to create patch because '%@' cannot be a symbolic link.", destinationParentDirectory] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't use -[NSFileManager fileExistsAtPath:] because it will follow symbolic links
|
||||
BOOL fileExisted = verbose && [fileManager attributesOfItemAtPath:destinationFilePath error:nil];
|
||||
BOOL removedFile = NO;
|
||||
|
||||
// Files that have no property set that we check for will get ignored
|
||||
// This is important because they aren't part of the delta, just part of the directory structure
|
||||
SPUDeltaItemCommands commands = item.commands;
|
||||
if ((commands & SPUDeltaItemCommandDelete) != 0) {
|
||||
if (!removeTree(destinationFilePath)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"delete: failed to remove %@", destination] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
removedFile = YES;
|
||||
}
|
||||
|
||||
if ((commands & SPUDeltaItemCommandClone) != 0 && (commands & SPUDeltaItemCommandBinaryDiff) == 0) {
|
||||
NSString *clonedRelativePath = item.clonedRelativePath;
|
||||
if ([clonedRelativePath.pathComponents containsObject:@".."]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path for clone '%@' contains '..' path component", clonedRelativePath] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *clonedOriginalPath = [source stringByAppendingPathComponent:clonedRelativePath];
|
||||
|
||||
// Ensure there isn't an item already at our destination
|
||||
[fileManager removeItemAtPath:destinationFilePath error:NULL];
|
||||
|
||||
NSError *copyError = nil;
|
||||
if (![fileManager copyItemAtPath:clonedOriginalPath toPath:destinationFilePath error:©Error]) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = copyError;
|
||||
}
|
||||
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n✂️ %s %s -> %s", VERBOSE_CLONED, [clonedRelativePath fileSystemRepresentation], [relativePath fileSystemRepresentation]);
|
||||
}
|
||||
} else if ((commands & SPUDeltaItemCommandBinaryDiff) != 0) {
|
||||
NSString *tempDiffFile = temporaryFilename(@"apply-binary-delta");
|
||||
item.itemFilePath = tempDiffFile;
|
||||
|
||||
if (![archive extractItem:item]) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to extract diffed file to %@", tempDiffFile], NSUnderlyingErrorKey: (NSError * _Nonnull)archive.error }];
|
||||
}
|
||||
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *sourceDiffFilePath;
|
||||
NSString *clonedRelativePath;
|
||||
if ((commands & SPUDeltaItemCommandClone) != 0) {
|
||||
clonedRelativePath = item.clonedRelativePath;
|
||||
if ([clonedRelativePath.pathComponents containsObject:@".."]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path for clone '%@' contains '..' path component", clonedRelativePath] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
sourceDiffFilePath = [source stringByAppendingPathComponent:clonedRelativePath];
|
||||
} else {
|
||||
sourceDiffFilePath = sourceFilePath;
|
||||
clonedRelativePath = nil;
|
||||
}
|
||||
|
||||
// Decide if we need to preserve original file permissions from the original file
|
||||
// applyBinaryDeltaToFile() normally preserves file permissions on the file it's replacing.
|
||||
// However this is not possible if the destination file we're patching is not writable.
|
||||
// We also need to preserve permissions for clones except when we'll be changing permissions later anyway.
|
||||
BOOL needsToCopyFilePermissions;
|
||||
if (![fileManager isWritableFileAtPath:destinationFilePath]) {
|
||||
// Remove the file non-writable we're patching that may cause issues
|
||||
[fileManager removeItemAtPath:destinationFilePath error:NULL];
|
||||
|
||||
// We will need to preserve permissions if there is no need to make permission changes later on
|
||||
needsToCopyFilePermissions = (commands & SPUDeltaItemCommandModifyPermissions) == 0;
|
||||
} else {
|
||||
needsToCopyFilePermissions = ((commands & SPUDeltaItemCommandClone) != 0) && ((commands & SPUDeltaItemCommandModifyPermissions) == 0);
|
||||
}
|
||||
|
||||
if (!applyBinaryDeltaToFile(tempDiffFile, sourceDiffFilePath, destinationFilePath)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to patch %@ to destination %@", sourceFilePath, destinationFilePath] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
if (needsToCopyFilePermissions) {
|
||||
struct stat sourceFileInfo = {0};
|
||||
if (lstat(sourceDiffFilePath.fileSystemRepresentation, &sourceFileInfo) != 0) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to retrieve stat info from %@", sourceFilePath] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
if (chmod(destinationFilePath.fileSystemRepresentation, sourceFileInfo.st_mode) != 0) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteNoPermissionError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to modify permissions (%u) on file %@", sourceFileInfo.st_mode, destinationFilePath] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
if ((commands & SPUDeltaItemCommandClone) != 0) {
|
||||
fprintf(stderr, "\n🔨 %s %s -> %s", VERBOSE_PATCHED, [clonedRelativePath fileSystemRepresentation], [relativePath fileSystemRepresentation]);
|
||||
} else {
|
||||
fprintf(stderr, "\n🔨 %s %s", VERBOSE_PATCHED, [relativePath fileSystemRepresentation]);
|
||||
}
|
||||
}
|
||||
} else if ((commands & SPUDeltaItemCommandExtract) != 0) { // extract and permission modifications don't coexist
|
||||
item.itemFilePath = destinationFilePath;
|
||||
if (![archive extractItem:item]) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to extract file to %@", destinationFilePath], NSUnderlyingErrorKey: (NSError * _Nonnull)archive.error }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
if (fileExisted) {
|
||||
fprintf(stderr, "\n✏️ %s %s", VERBOSE_UPDATED, [relativePath fileSystemRepresentation]);
|
||||
} else {
|
||||
fprintf(stderr, "\n✅ %s %s", VERBOSE_ADDED, [relativePath fileSystemRepresentation]);
|
||||
}
|
||||
}
|
||||
} else if (verbose && removedFile) {
|
||||
fprintf(stderr, "\n❌ %s %s", VERBOSE_DELETED, [relativePath fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
if ((commands & SPUDeltaItemCommandModifyPermissions) != 0) {
|
||||
mode_t mode = (mode_t)item.mode;
|
||||
if (!modifyPermissions(destinationFilePath, mode)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteNoPermissionError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to modify permissions (%u) on file %@", mode, destinationFilePath] }];
|
||||
}
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n👮 %s %s (0%o)", VERBOSE_MODIFIED, [relativePath fileSystemRepresentation], (unsigned int)(mode & PERMISSION_FLAGS));
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
[archive close];
|
||||
|
||||
// Set error from enumerating items if we have encountered an error and haven't set it yet
|
||||
NSError *archiveError = archive.error;
|
||||
if (archiveError != nil) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL && *error == nil) {
|
||||
*error = archiveError;
|
||||
}
|
||||
removeTree(destination);
|
||||
return NO;
|
||||
}
|
||||
|
||||
progressCallback(5/7.0);
|
||||
|
||||
// Re-apply file system compression is requested
|
||||
if (header.fileSystemCompression) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nApplying file system compression...");
|
||||
}
|
||||
|
||||
NSTask *dittoTask = [[NSTask alloc] init];
|
||||
|
||||
dittoTask.executableURL = [NSURL fileURLWithPath:@"/usr/bin/ditto" isDirectory:NO];
|
||||
dittoTask.arguments = @[@"--hfsCompression", destination, finalDestination];
|
||||
|
||||
// If we fail to apply file system compression, we will try falling back to not doing this
|
||||
BOOL failedToApplyFileSystemCompression = NO;
|
||||
|
||||
NSError *launchError = nil;
|
||||
if (![dittoTask launchAndReturnError:&launchError]) {
|
||||
failedToApplyFileSystemCompression = YES;
|
||||
|
||||
fprintf(stderr, "\nWarning: failed to launch ditto task for file compression: %s", launchError.localizedDescription.UTF8String);
|
||||
}
|
||||
|
||||
if (!failedToApplyFileSystemCompression) {
|
||||
[dittoTask waitUntilExit];
|
||||
|
||||
if (dittoTask.terminationStatus != 0) {
|
||||
failedToApplyFileSystemCompression = YES;
|
||||
|
||||
fprintf(stderr, "\nWarning: ditto task for file compression returned exit status %d", dittoTask.terminationStatus);
|
||||
}
|
||||
}
|
||||
|
||||
if (failedToApplyFileSystemCompression) {
|
||||
// Try to replace bundle normally
|
||||
if (![fileManager replaceItemAtURL:[NSURL fileURLWithPath:finalDestination] withItemAtURL:[NSURL fileURLWithPath:destination isDirectory:YES] backupItemName:nil options:(NSFileManagerItemReplacementOptions)0 resultingItemURL:NULL error:error]) {
|
||||
removeTree(destination);
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
// Remove original copy
|
||||
[fileManager removeItemAtURL:[NSURL fileURLWithPath:destination isDirectory:YES] error:NULL];
|
||||
}
|
||||
}
|
||||
|
||||
progressCallback(6/7.0);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nVerifying destination...");
|
||||
}
|
||||
|
||||
unsigned char afterHash[BINARY_DELTA_HASH_LENGTH] = {0};
|
||||
if (!getRawHashOfTreeWithVersion(afterHash, finalDestination, majorDiffVersion)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to calculate hash of tree %@", finalDestination] }];
|
||||
}
|
||||
removeTree(finalDestination);
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (memcmp(afterHash, expectedAfterHash, BINARY_DELTA_HASH_LENGTH) != 0) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Destination doesn't have expected hash (%@ != %@). Giving up.", displayHashFromRawHash(expectedAfterHash), displayHashFromRawHash(afterHash)] }];
|
||||
}
|
||||
removeTree(finalDestination);
|
||||
return NO;
|
||||
}
|
||||
|
||||
progressCallback(7/7.0);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nDone!\n");
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
//
|
||||
// SUBinaryDeltaCommon.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTACOMMON_H
|
||||
#define SUBINARYDELTACOMMON_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SPUDeltaCompressionMode.h"
|
||||
#include <fts.h>
|
||||
|
||||
#define PERMISSION_FLAGS (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX)
|
||||
#define VALID_SYMBOLIC_LINK_PERMISSIONS 0755
|
||||
// Enforcing Sparkle's executable permissions to be valid allows us to perform a preflight test before
|
||||
// downloading delta items
|
||||
#define VALID_SPARKLE_EXECUTABLE_PERMISSIONS 0755
|
||||
|
||||
#define APPLE_CODE_SIGN_XATTR_CODE_DIRECTORY_KEY "com.apple.cs.CodeDirectory"
|
||||
#define APPLE_CODE_SIGN_XATTR_CODE_REQUIREMENTS_KEY "com.apple.cs.CodeRequirements"
|
||||
#define APPLE_CODE_SIGN_XATTR_CODE_SIGNATURE_KEY "com.apple.cs.CodeSignature"
|
||||
|
||||
#define VERBOSE_DELETED "Deleted" // file is deleted from the file system when applying a patch
|
||||
#define VERBOSE_REMOVED "Removed" // file is set to be removed when creating a patch
|
||||
#define VERBOSE_ADDED "Added" // file is added to the patch or file system
|
||||
#define VERBOSE_DIFFED "Diffed" // file is diffed when creating a patch
|
||||
#define VERBOSE_PATCHED "Patched" // file is patched when applying a patch
|
||||
#define VERBOSE_UPDATED "Updated" // file's contents are updated
|
||||
#define VERBOSE_MODIFIED "Modified" // file's metadata is modified
|
||||
#define VERBOSE_CLONED "Cloned" // file is cloned in content from a differently named file
|
||||
|
||||
// Relative path of custom icon data that may be set on a bundle via a resource fork
|
||||
#define CUSTOM_ICON_PATH @"/Icon\r"
|
||||
|
||||
// Changes that break backwards compatibility will have different major versions
|
||||
// Changes that affect creating but not applying patches will have different minor versions
|
||||
typedef NS_ENUM(uint16_t, SUBinaryDeltaMajorVersion)
|
||||
{
|
||||
// Note: support for creating or applying version 1 deltas have been removed
|
||||
SUBinaryDeltaMajorVersion1 = 1,
|
||||
SUBinaryDeltaMajorVersion2 = 2,
|
||||
SUBinaryDeltaMajorVersion3 = 3,
|
||||
SUBinaryDeltaMajorVersion4 = 4,
|
||||
};
|
||||
|
||||
extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionDefault;
|
||||
extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionLatest;
|
||||
extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirst;
|
||||
extern SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirstSupported;
|
||||
|
||||
// Additional compression methods for version 3 or 4 patches that we have for debugging are zlib, bzip2, none
|
||||
#define COMPRESSION_METHOD_ARGUMENT_DESCRIPTION @"The compression method to use for generating delta updates. Supported methods for version 3 delta files are 'lzma' (best compression, slowest), 'lzfse' (good compression, fast), 'lz4' (worse compression, fastest), and 'default'. Note that version 2 delta files only support 'bzip2', and 'default' so other methods will be ignored if version 2 files are being generated. The 'default' compression for version 3 or 4 delta files is currently lzma."
|
||||
|
||||
//#define COMPRESSION_LEVEL_ARGUMENT_DESCRIPTION @"The compression level to use for generating delta updates. This only applies if the compression method used is bzip2 which accepts values from 1 - 9. A special value of 0 will use the default compression level."
|
||||
|
||||
// This is the same as CC_SHA1_DIGEST_LENGTH
|
||||
// Major versions >= 4 use a crc32 hash (using a subset of these bytes) while older versions use a sha1 hash
|
||||
#define BINARY_DELTA_HASH_LENGTH 20
|
||||
|
||||
SPUDeltaCompressionMode deltaCompressionModeFromDescription(NSString *description, BOOL *requestValid);
|
||||
NSString *deltaCompressionStringFromMode(SPUDeltaCompressionMode mode);
|
||||
|
||||
extern int compareFiles(const FTSENT **a, const FTSENT **b);
|
||||
BOOL getRawHashOfTreeWithVersion(void *hashBuffer, NSString *path, uint16_t majorVersion);
|
||||
BOOL getRawHashOfTreeAndFileTablesWithVersion(void *hashBuffer, NSString *path, uint16_t majorVersion, NSMutableDictionary<NSData *, NSMutableArray<NSString *> *> *hashToFileKeyDictionary, NSMutableDictionary<NSString *, NSData *> *fileKeyToHashDictionary);
|
||||
NSString *displayHashFromRawHash(const unsigned char *hash);
|
||||
void getRawHashFromDisplayHash(unsigned char *hash, NSString *hexHash);
|
||||
extern NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion);
|
||||
extern NSString *hashOfTree(NSString *path);
|
||||
extern BOOL removeTree(NSString *path);
|
||||
extern BOOL copyTree(NSFileManager *fileManager, NSString *source, NSString *dest);
|
||||
extern BOOL modifyPermissions(NSString *path, mode_t desiredPermissions);
|
||||
extern NSString *pathRelativeToDirectory(NSString *directory, NSString *path);
|
||||
NSString *temporaryFilename(NSString *base);
|
||||
NSString *temporaryDirectory(NSString *base);
|
||||
NSString *stringWithFileSystemRepresentation(const char*);
|
||||
uint16_t latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion);
|
||||
#endif
|
||||
@@ -1,488 +0,0 @@
|
||||
//
|
||||
// SUBinaryDeltaCommon.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#include <zlib.h> // for crc32()
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <xlocale.h>
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
// Note: the framework bundle version must be bumped, and generate_appcast must be updated to compare it,
|
||||
// when we add/change new major versions and defaults. Unit tests need to be updated to use new versions too.
|
||||
SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionDefault = SUBinaryDeltaMajorVersion4;
|
||||
SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionLatest = SUBinaryDeltaMajorVersion4;
|
||||
SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirst = SUBinaryDeltaMajorVersion1;
|
||||
SUBinaryDeltaMajorVersion SUBinaryDeltaMajorVersionFirstSupported = SUBinaryDeltaMajorVersion2;
|
||||
|
||||
SPUDeltaCompressionMode deltaCompressionModeFromDescription(NSString *requestedDescription, BOOL *requestValid)
|
||||
{
|
||||
// Set to NO later if request was not valid
|
||||
if (requestValid != NULL) {
|
||||
*requestValid = YES;
|
||||
}
|
||||
|
||||
SPUDeltaCompressionMode compression;
|
||||
NSString *description = requestedDescription.lowercaseString;
|
||||
|
||||
if ([description isEqualToString:@"default"]) {
|
||||
compression = SPUDeltaCompressionModeDefault;
|
||||
} else if ([description isEqualToString:@"none"]) {
|
||||
compression = SPUDeltaCompressionModeNone;
|
||||
} else if ([description isEqualToString:@"bzip2"]) {
|
||||
compression = SPUDeltaCompressionModeBzip2;
|
||||
} else if ([description isEqualToString:@"lzma"]) {
|
||||
compression = SPUDeltaCompressionModeLZMA;
|
||||
} else if ([description isEqualToString:@"lzfse"]) {
|
||||
compression = SPUDeltaCompressionModeLZFSE;
|
||||
} else if ([description isEqualToString:@"lz4"]) {
|
||||
compression = SPUDeltaCompressionModeLZ4;
|
||||
} else if ([description isEqualToString:@"zlib"]) {
|
||||
compression = SPUDeltaCompressionModeZLIB;
|
||||
} else {
|
||||
compression = SPUDeltaCompressionModeDefault;
|
||||
|
||||
if (requestValid != NULL) {
|
||||
*requestValid = NO;
|
||||
}
|
||||
}
|
||||
|
||||
return compression;
|
||||
}
|
||||
|
||||
NSString *deltaCompressionStringFromMode(SPUDeltaCompressionMode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case SPUDeltaCompressionModeBzip2:
|
||||
return @"bzip2";
|
||||
case SPUDeltaCompressionModeLZMA:
|
||||
return @"LZMA";
|
||||
case SPUDeltaCompressionModeNone:
|
||||
return @"no";
|
||||
case SPUDeltaCompressionModeLZ4:
|
||||
return @"LZ4";
|
||||
case SPUDeltaCompressionModeLZFSE:
|
||||
return @"LZFSE";
|
||||
case SPUDeltaCompressionModeZLIB:
|
||||
return @"ZLIB";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (mode == SPUDeltaCompressionModeDefault) {
|
||||
return @"default";
|
||||
}
|
||||
|
||||
return @"unknown";
|
||||
}
|
||||
|
||||
int compareFiles(const FTSENT **a, const FTSENT **b)
|
||||
{
|
||||
return strcoll_l((*a)->fts_name, (*b)->fts_name, _c_locale);
|
||||
}
|
||||
|
||||
NSString *pathRelativeToDirectory(NSString *directory, NSString *path)
|
||||
{
|
||||
NSUInteger directoryLength = [directory length];
|
||||
if ([path hasPrefix:directory])
|
||||
return [path substringFromIndex:directoryLength];
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
NSString *stringWithFileSystemRepresentation(const char *input)
|
||||
{
|
||||
return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:input length:strlen(input)];
|
||||
}
|
||||
|
||||
uint16_t latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion)
|
||||
{
|
||||
switch (majorVersion) {
|
||||
case SUBinaryDeltaMajorVersion1:
|
||||
return 2;
|
||||
case SUBinaryDeltaMajorVersion2:
|
||||
return 5;
|
||||
case SUBinaryDeltaMajorVersion3:
|
||||
return 3;
|
||||
case SUBinaryDeltaMajorVersion4:
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSString *temporaryFilename(NSString *base)
|
||||
{
|
||||
NSString *template = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXXXXX", base]];
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
[data appendBytes:template.fileSystemRepresentation length:strlen(template.fileSystemRepresentation) + 1];
|
||||
|
||||
char *buffer = (char *)data.mutableBytes;
|
||||
int fd = mkstemp(buffer);
|
||||
if (fd == -1) {
|
||||
perror("mkstemp");
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (close(fd) != 0) {
|
||||
perror("close");
|
||||
return nil;
|
||||
}
|
||||
|
||||
return stringWithFileSystemRepresentation(buffer);
|
||||
}
|
||||
|
||||
NSString *temporaryDirectory(NSString *base)
|
||||
{
|
||||
NSString *template = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXXXXX", base]];
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
[data appendBytes:template.fileSystemRepresentation length:strlen(template.fileSystemRepresentation) + 1];
|
||||
|
||||
char *buffer = (char *)data.mutableBytes;
|
||||
char *templateResult = mkdtemp(buffer);
|
||||
if (templateResult == NULL) {
|
||||
perror("mkdtemp");
|
||||
return nil;
|
||||
}
|
||||
|
||||
return stringWithFileSystemRepresentation(templateResult);
|
||||
}
|
||||
|
||||
static void sha1HashOfBuffer(unsigned char *hash, const char *buffer, ssize_t bufferLength)
|
||||
{
|
||||
assert(bufferLength >= 0 && bufferLength <= UINT32_MAX);
|
||||
CC_SHA1_CTX hashContext;
|
||||
CC_SHA1_Init(&hashContext);
|
||||
CC_SHA1_Update(&hashContext, buffer, (CC_LONG)bufferLength);
|
||||
CC_SHA1_Final(hash, &hashContext);
|
||||
}
|
||||
|
||||
static BOOL crc32HashOfFileContents(uLong *outChecksum, FTSENT *ent, void *tempBuffer, size_t tempBufferSize)
|
||||
{
|
||||
uLong checksum = *outChecksum;
|
||||
|
||||
if (ent->fts_info == FTS_SL) {
|
||||
char linkDestination[MAXPATHLEN + 1];
|
||||
ssize_t linkDestinationLength = readlink(ent->fts_path, linkDestination, MAXPATHLEN);
|
||||
if (linkDestinationLength < 0) {
|
||||
perror("readlink");
|
||||
return NO;
|
||||
}
|
||||
|
||||
checksum = crc32(checksum, (const Bytef *)linkDestination, (unsigned int)linkDestinationLength);
|
||||
} else if (ent->fts_info == FTS_F) {
|
||||
ssize_t fileSize = ent->fts_statp->st_size;
|
||||
|
||||
uint64_t encodedFileSize = (uint64_t)fileSize;
|
||||
checksum = crc32(checksum, (const Bytef *)&encodedFileSize, sizeof(encodedFileSize));
|
||||
|
||||
if (fileSize > 0) {
|
||||
FILE *file = fopen(ent->fts_path, "rb");
|
||||
if (file == NULL) {
|
||||
perror("fopen");
|
||||
return NO;
|
||||
}
|
||||
|
||||
size_t bytesLeft = (size_t)fileSize;
|
||||
while (bytesLeft > 0) {
|
||||
size_t bytesToConsume = (bytesLeft >= tempBufferSize) ? tempBufferSize : bytesLeft;
|
||||
|
||||
if (fread(tempBuffer, bytesToConsume, 1, file) < 1) {
|
||||
perror("fread");
|
||||
fclose(file);
|
||||
return NO;
|
||||
}
|
||||
|
||||
checksum = crc32(checksum, (const Bytef *)tempBuffer, (uInt)bytesToConsume);
|
||||
|
||||
bytesLeft -= bytesToConsume;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
|
||||
*outChecksum = checksum;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
static BOOL sha1HashOfFileContents(unsigned char *hash, FTSENT *ent, void *tempBuffer, size_t tempBufferSize)
|
||||
{
|
||||
if (ent->fts_info == FTS_SL) {
|
||||
char linkDestination[MAXPATHLEN + 1];
|
||||
ssize_t linkDestinationLength = readlink(ent->fts_path, linkDestination, MAXPATHLEN);
|
||||
if (linkDestinationLength < 0) {
|
||||
perror("readlink");
|
||||
return NO;
|
||||
}
|
||||
|
||||
sha1HashOfBuffer(hash, linkDestination, linkDestinationLength);
|
||||
} else if (ent->fts_info == FTS_F) {
|
||||
ssize_t fileSize = ent->fts_statp->st_size;
|
||||
if (fileSize <= 0) {
|
||||
sha1HashOfBuffer(hash, NULL, 0);
|
||||
} else {
|
||||
FILE *file = fopen(ent->fts_path, "rb");
|
||||
if (file == NULL) {
|
||||
perror("fopen");
|
||||
return NO;
|
||||
}
|
||||
|
||||
CC_SHA1_CTX hashContext;
|
||||
CC_SHA1_Init(&hashContext);
|
||||
|
||||
size_t bytesLeft = (size_t)fileSize;
|
||||
while (bytesLeft > 0) {
|
||||
size_t bytesToConsume = (bytesLeft >= tempBufferSize) ? tempBufferSize : bytesLeft;
|
||||
|
||||
if (fread(tempBuffer, bytesToConsume, 1, file) < 1) {
|
||||
perror("fread");
|
||||
fclose(file);
|
||||
return NO;
|
||||
}
|
||||
|
||||
CC_SHA1_Update(&hashContext, tempBuffer, (CC_LONG)bytesToConsume);
|
||||
bytesLeft -= bytesToConsume;
|
||||
}
|
||||
|
||||
CC_SHA1_Final(hash, &hashContext);
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
} else if (ent->fts_info == FTS_D) {
|
||||
memset(hash, 0xdd, CC_SHA1_DIGEST_LENGTH);
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
BOOL getRawHashOfTreeWithVersion(void *hashBuffer, NSString *path, uint16_t majorVersion)
|
||||
{
|
||||
return getRawHashOfTreeAndFileTablesWithVersion(hashBuffer, path, majorVersion, nil, nil);
|
||||
}
|
||||
|
||||
BOOL getRawHashOfTreeAndFileTablesWithVersion(void *hashBuffer, NSString *path, uint16_t majorVersion, NSMutableDictionary<NSData *, NSMutableArray<NSString *> *> *hashToFileKeyDictionary, NSMutableDictionary<NSString *, NSData *> *fileKeyToHashDictionary)
|
||||
{
|
||||
char pathBuffer[PATH_MAX] = { 0 };
|
||||
if (![path getFileSystemRepresentation:pathBuffer maxLength:sizeof(pathBuffer)]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
const size_t tempBufferSize = 16384;
|
||||
void *tempBuffer = calloc(1, tempBufferSize);
|
||||
if (tempBuffer == NULL) {
|
||||
perror("calloc");
|
||||
return NO;
|
||||
}
|
||||
|
||||
char *const sourcePaths[] = { pathBuffer, 0 };
|
||||
FTS *fts = fts_open(sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
free(tempBuffer);
|
||||
return NO;
|
||||
}
|
||||
|
||||
CC_SHA1_CTX hashContext;
|
||||
const uLong initialCrc32Value = crc32(0L, Z_NULL, 0);
|
||||
uLong crc32ChecksumValue = initialCrc32Value;
|
||||
|
||||
if (majorVersion < SUBinaryDeltaMajorVersion4) {
|
||||
CC_SHA1_Init(&hashContext);
|
||||
}
|
||||
|
||||
// Ensure the path uses filesystem-specific Unicode normalization #1017
|
||||
NSString *normalizedPath = stringWithFileSystemRepresentation(pathBuffer);
|
||||
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D)
|
||||
continue;
|
||||
|
||||
NSString *relativePath = pathRelativeToDirectory(normalizedPath, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
|
||||
// Ignore icon resource fork data
|
||||
if (relativePath.length == 0 || [relativePath isEqualToString:CUSTOM_ICON_PATH]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSData *fileHashKey;
|
||||
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
|
||||
if (ent->fts_info == FTS_D) {
|
||||
// No need to hash any further values for directories
|
||||
// We hash relative file path and file type later
|
||||
fileHashKey = nil;
|
||||
} else {
|
||||
uLong fileContentsChecksum = initialCrc32Value;
|
||||
if (!crc32HashOfFileContents(&fileContentsChecksum, ent, tempBuffer, tempBufferSize)) {
|
||||
fts_close(fts);
|
||||
free(tempBuffer);
|
||||
return NO;
|
||||
}
|
||||
|
||||
uint64_t encodedFileContentsChecksum = fileContentsChecksum;
|
||||
|
||||
crc32ChecksumValue = crc32(crc32ChecksumValue, (const Bytef *)&encodedFileContentsChecksum, sizeof(encodedFileContentsChecksum));
|
||||
|
||||
if (ent->fts_info == FTS_F) {
|
||||
fileHashKey = [NSData dataWithBytes:&encodedFileContentsChecksum length:sizeof(encodedFileContentsChecksum)];
|
||||
} else {
|
||||
fileHashKey = nil;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unsigned char fileHash[CC_SHA1_DIGEST_LENGTH];
|
||||
if (!sha1HashOfFileContents(fileHash, ent, tempBuffer, tempBufferSize)) {
|
||||
fts_close(fts);
|
||||
free(tempBuffer);
|
||||
return NO;
|
||||
}
|
||||
CC_SHA1_Update(&hashContext, fileHash, sizeof(fileHash));
|
||||
|
||||
if (ent->fts_info == FTS_F) {
|
||||
fileHashKey = [NSData dataWithBytes:fileHash length:sizeof(fileHash)];
|
||||
} else {
|
||||
fileHashKey = nil;
|
||||
}
|
||||
}
|
||||
|
||||
// For file hash tables we only track regular files
|
||||
if (fileHashKey != nil) {
|
||||
if (hashToFileKeyDictionary != nil) {
|
||||
if (hashToFileKeyDictionary[fileHashKey] == nil) {
|
||||
hashToFileKeyDictionary[fileHashKey] = [NSMutableArray array];
|
||||
}
|
||||
[hashToFileKeyDictionary[fileHashKey] addObject:relativePath];
|
||||
}
|
||||
|
||||
if (fileKeyToHashDictionary != nil) {
|
||||
fileKeyToHashDictionary[relativePath] = fileHashKey;
|
||||
}
|
||||
}
|
||||
|
||||
const char *relativePathBytes = [relativePath fileSystemRepresentation];
|
||||
|
||||
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
|
||||
crc32ChecksumValue = crc32(crc32ChecksumValue, (const Bytef *)relativePathBytes, (uInt)strlen(relativePathBytes));
|
||||
} else {
|
||||
CC_SHA1_Update(&hashContext, relativePathBytes, (CC_LONG)strlen(relativePathBytes));
|
||||
}
|
||||
|
||||
uint16_t mode = ent->fts_statp->st_mode;
|
||||
uint16_t type = ent->fts_info;
|
||||
uint16_t permissions = mode & PERMISSION_FLAGS;
|
||||
|
||||
// permission of symlinks are 0777 on some linux file systems and can't be changed,
|
||||
// differing from the 0755 macOS default.
|
||||
// hardcoding a value helps avoid differences between filesystems.
|
||||
uint16_t hashedPermissions = (ent->fts_info == FTS_SL) ? VALID_SYMBOLIC_LINK_PERMISSIONS : permissions;
|
||||
|
||||
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
|
||||
crc32ChecksumValue = crc32(crc32ChecksumValue, (const Bytef *)&type, sizeof(type));
|
||||
crc32ChecksumValue = crc32(crc32ChecksumValue, (const Bytef *)&hashedPermissions, sizeof(hashedPermissions));
|
||||
} else {
|
||||
CC_SHA1_Update(&hashContext, &type, sizeof(type));
|
||||
CC_SHA1_Update(&hashContext, &hashedPermissions, sizeof(hashedPermissions));
|
||||
}
|
||||
}
|
||||
|
||||
free(tempBuffer);
|
||||
|
||||
fts_close(fts);
|
||||
|
||||
if (majorVersion >= SUBinaryDeltaMajorVersion4) {
|
||||
uint64_t encodedCrc32ChecksumValue = crc32ChecksumValue;
|
||||
memset(hashBuffer, 0, BINARY_DELTA_HASH_LENGTH);
|
||||
memcpy(hashBuffer, &encodedCrc32ChecksumValue, sizeof(encodedCrc32ChecksumValue));
|
||||
} else {
|
||||
CC_SHA1_Final((unsigned char *)hashBuffer, &hashContext);
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
void getRawHashFromDisplayHash(unsigned char *hash, NSString *hexHash)
|
||||
{
|
||||
const char *hexString = hexHash.UTF8String;
|
||||
if (hexString == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t blockIndex = 0; blockIndex < BINARY_DELTA_HASH_LENGTH; blockIndex++) {
|
||||
const char *currentBlock = hexString + blockIndex * 2;
|
||||
char convertedBlock[3] = {currentBlock[0], currentBlock[1], '\0'};
|
||||
hash[blockIndex] = (unsigned char)strtol(convertedBlock, NULL, 16);
|
||||
}
|
||||
}
|
||||
|
||||
NSString *displayHashFromRawHash(const unsigned char *hash)
|
||||
{
|
||||
char hexHash[BINARY_DELTA_HASH_LENGTH * 2 + 1] = {0};
|
||||
for (size_t i = 0; i < BINARY_DELTA_HASH_LENGTH; i++) {
|
||||
snprintf(hexHash + i * 2, 3, "%02x", hash[i]);
|
||||
}
|
||||
return @(hexHash);
|
||||
}
|
||||
|
||||
NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion)
|
||||
{
|
||||
unsigned char hash[BINARY_DELTA_HASH_LENGTH] = {0};
|
||||
if (!getRawHashOfTreeWithVersion(hash, path, majorVersion)) {
|
||||
return nil;
|
||||
}
|
||||
return displayHashFromRawHash(hash);
|
||||
}
|
||||
|
||||
extern NSString *hashOfTree(NSString *path)
|
||||
{
|
||||
return hashOfTreeWithVersion(path, SUBinaryDeltaMajorVersionLatest);
|
||||
}
|
||||
|
||||
BOOL removeTree(NSString *path)
|
||||
{
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
// Don't use fileExistsForPath: because it will try to follow symbolic links
|
||||
if (![fileManager attributesOfItemAtPath:path error:nil]) {
|
||||
return YES;
|
||||
}
|
||||
return [fileManager removeItemAtPath:path error:nil];
|
||||
}
|
||||
|
||||
BOOL copyTree(NSFileManager *fileManager, NSString *source, NSString *dest)
|
||||
{
|
||||
return [fileManager copyItemAtURL:[NSURL fileURLWithPath:source] toURL:[NSURL fileURLWithPath:dest] error:NULL];
|
||||
}
|
||||
|
||||
BOOL modifyPermissions(NSString *path, mode_t desiredPermissions)
|
||||
{
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSDictionary *attributes = [fileManager attributesOfItemAtPath:path error:nil];
|
||||
if (!attributes) {
|
||||
return NO;
|
||||
}
|
||||
NSNumber *permissions = [attributes objectForKey:NSFilePosixPermissions];
|
||||
if (!permissions) {
|
||||
return NO;
|
||||
}
|
||||
mode_t newMode = ([permissions unsignedShortValue] & ~PERMISSION_FLAGS) | desiredPermissions;
|
||||
int (*changeModeFunc)(const char *, mode_t) = [(NSString *)[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeSymbolicLink] ? lchmod : chmod;
|
||||
if (changeModeFunc([path fileSystemRepresentation], newMode) != 0) {
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// SUBinaryDeltaCreate.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/9/15.
|
||||
// Copyright (c) 2015 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTACREATE_H
|
||||
#define SUBINARYDELTACREATE_H
|
||||
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
|
||||
@class NSString;
|
||||
BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, SPUDeltaCompressionMode compression, uint8_t compressionLevel, BOOL verbose, NSError * __autoreleasing *error);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// SUBinaryDeltaUnarchiver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-03.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTAUNARCHIVER_H
|
||||
#define SUBINARYDELTAUNARCHIVER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUUnarchiverProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#ifndef BUILDING_SPARKLE_TESTS
|
||||
SPU_OBJC_DIRECT_MEMBERS
|
||||
#endif
|
||||
@interface SUBinaryDeltaUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory updateHostBundlePath:(NSString *)updateHostBundlePath;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -1,123 +0,0 @@
|
||||
//
|
||||
// SUBinaryDeltaUnarchiver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-03.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUBinaryDeltaUnarchiver.h"
|
||||
#import "SUUnarchiverNotifier.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import "SULog.h"
|
||||
#import "SUFileManager.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUBinaryDeltaUnarchiver
|
||||
{
|
||||
NSString *_archivePath;
|
||||
NSString *_updateHostBundlePath;
|
||||
NSString *_extractionDirectory;
|
||||
}
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return [[path pathExtension] isEqualToString:@"delta"];
|
||||
}
|
||||
|
||||
+ (BOOL)mustValidateBeforeExtraction
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
// According to https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/MDImporters/Concepts/Troubleshooting.html
|
||||
// We should make sure mdimporter bundles have an up to date time in the event they were delta updated.
|
||||
// We used to invoke mdimport on the bundle but this is not a very good approach.
|
||||
// There's no need to do that for non-delta updates and for updates that contain no mdimporters.
|
||||
// Moreover, updating the timestamp on the mdimporter bundles is what developers have to do anyway when shipping their new update outside of Sparkle
|
||||
// Note: this is used from unit tests
|
||||
+ (void)updateSpotlightImportersAtBundlePath:(NSString *)targetPath
|
||||
#ifndef BUILDING_SPARKLE_TESTS
|
||||
SPU_OBJC_DIRECT
|
||||
#endif
|
||||
{
|
||||
NSURL *targetURL = [NSURL fileURLWithPath:targetPath];
|
||||
// Only recurse if it's actually a directory. Don't recurse into a
|
||||
// root-level symbolic link.
|
||||
NSDictionary *rootAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:targetPath error:nil];
|
||||
NSString *rootType = [rootAttributes objectForKey:NSFileType];
|
||||
|
||||
if ([rootType isEqualToString:NSFileTypeDirectory]) {
|
||||
// The NSDirectoryEnumerator will avoid recursing into any contained
|
||||
// symbolic links, so no further type checks are needed.
|
||||
NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtURL:targetURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil];
|
||||
|
||||
NSMutableArray *filesToUpdate = [[NSMutableArray alloc] init];
|
||||
for (NSURL *file in directoryEnumerator) {
|
||||
if ([file.pathExtension isEqualToString:@"mdimporter"]) {
|
||||
[filesToUpdate addObject:file];
|
||||
}
|
||||
}
|
||||
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
for (NSURL *file in filesToUpdate) {
|
||||
NSError *error = nil;
|
||||
if (![fileManager updateModificationAndAccessTimeOfItemAtURL:file error:&error]) {
|
||||
SULog(SULogLevelError, @"Error: During delta unarchiving, failed to touch %@", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory updateHostBundlePath:(NSString *)updateHostBundlePath
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_archivePath = [archivePath copy];
|
||||
_updateHostBundlePath = [updateHostBundlePath copy];
|
||||
_extractionDirectory = [extractionDirectory copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)needsVerifyBeforeExtractionKey
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock waitForCleanup:(BOOL)__unused waitForCleanup
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
@autoreleasepool {
|
||||
SUUnarchiverNotifier *notifier = [[SUUnarchiverNotifier alloc] initWithCompletionBlock:completionBlock progressBlock:progressBlock];
|
||||
[self extractDeltaWithNotifier:notifier];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)extractDeltaWithNotifier:(SUUnarchiverNotifier *)notifier
|
||||
{
|
||||
NSString *sourcePath = _updateHostBundlePath;
|
||||
NSString *targetPath = [_extractionDirectory stringByAppendingPathComponent:[sourcePath lastPathComponent]];
|
||||
|
||||
NSError *applyDiffError = nil;
|
||||
BOOL success = applyBinaryDelta(sourcePath, targetPath, _archivePath, NO, ^(double progress){
|
||||
[notifier notifyProgress:progress];
|
||||
|
||||
}, &applyDiffError);
|
||||
|
||||
if (success) {
|
||||
[SUBinaryDeltaUnarchiver updateSpotlightImportersAtBundlePath:targetPath];
|
||||
[notifier notifySuccess];
|
||||
}
|
||||
else {
|
||||
[notifier notifyFailureWithError:applyDiffError];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], _archivePath]; }
|
||||
|
||||
@end
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// SUCodeSigningVerifier.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 7/5/12.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef SUCODESIGNINGVERIFIER_H
|
||||
#define SUCODESIGNINGVERIFIER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#ifndef BUILDING_SPARKLE_TESTS
|
||||
#define SUCodeSigningVerifierDefinitionAttribute SPU_OBJC_DIRECT_MEMBERS
|
||||
#else
|
||||
#define SUCodeSigningVerifierDefinitionAttribute __attribute__((objc_runtime_name("SUTestCodeSigningVerifier")))
|
||||
#endif
|
||||
|
||||
typedef NS_ENUM(NSUInteger, SUValidateConnectionStatus) {
|
||||
SUValidateConnectionStatusSetCodeSigningRequirementSuccess = 0,
|
||||
SUValidateConnectionStatusSetNoRequirementSuccess,
|
||||
SUValidateConnectionStatusAPIFailure,
|
||||
SUValidateConnectionStatusCodeSigningRequirementFailure,
|
||||
SUValidateConectionNoSupportedValidationMethodFailure,
|
||||
};
|
||||
|
||||
SUCodeSigningVerifierDefinitionAttribute
|
||||
@interface SUCodeSigningVerifier : NSObject
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)newBundleURL andMatchesSignatureAtBundleURL:(NSURL *)oldBundleURL error:(NSError **)error;
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundleURL checkNestedCode:(BOOL)checkNestedCode error:(NSError **)error;
|
||||
|
||||
// Same as above except does not check for nested code. This method should be used by the framework.
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundleURL error:(NSError *__autoreleasing *)error;
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtDownloadURL:(NSURL *)downloadURL andMatchesDeveloperIDTeamFromOldBundleURL:(NSURL *)oldBundleURL error:(NSError * __autoreleasing *)error;
|
||||
|
||||
+ (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundleURL;
|
||||
|
||||
+ (NSString * _Nullable)teamIdentifierAtURL:(NSURL *)url;
|
||||
+ (NSString * _Nullable)teamIdentifierFromMainExecutable;
|
||||
|
||||
+ (SUValidateConnectionStatus)validateConnection:(NSXPCConnection *)connection error:(NSError * __autoreleasing *)error;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -1,527 +0,0 @@
|
||||
//
|
||||
// SUCodeSigningVerifier.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 7/5/12.
|
||||
//
|
||||
//
|
||||
|
||||
#include <Security/CodeSigning.h>
|
||||
#include <Security/SecCode.h>
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SULog.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface NSXPCConnection (Private)
|
||||
|
||||
@property (nonatomic, readonly) audit_token_t auditToken;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUCodeSigningVerifier
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)newBundleURL andMatchesSignatureAtBundleURL:(NSURL *)oldBundleURL error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
OSStatus result;
|
||||
SecRequirementRef requirement = NULL;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
SecStaticCodeRef oldCode = NULL;
|
||||
CFErrorRef cfError = NULL;
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)oldBundleURL, kSecCSDefaultFlags, &oldCode);
|
||||
if (result != noErr) {
|
||||
if (error != NULL) {
|
||||
NSString *errorMessage =
|
||||
(result == errSecCSUnsigned) ?
|
||||
[NSString stringWithFormat:@"Bundle is not code signed: %@", oldBundleURL.path] :
|
||||
[NSString stringWithFormat:@"Failed to get static code (%d): %@", result, oldBundleURL.path];
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
}
|
||||
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecCodeCopyDesignatedRequirement(oldCode, kSecCSDefaultFlags, &requirement);
|
||||
if (result != noErr) {
|
||||
NSString *message = [NSString stringWithFormat:@"Failed to copy designated requirement. Code Signing OSStatus code: %d", result];
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
}
|
||||
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)newBundleURL, kSecCSDefaultFlags, &staticCode);
|
||||
if (result != noErr) {
|
||||
NSString *message = [NSString stringWithFormat:@"Failed to get static code %d", result];
|
||||
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
}
|
||||
|
||||
goto finally;
|
||||
}
|
||||
|
||||
// Note that kSecCSCheckNestedCode may not work with pre-Mavericks code signing.
|
||||
// See https://github.com/sparkle-project/Sparkle/issues/376#issuecomment-48824267 and https://developer.apple.com/library/mac/technotes/tn2206
|
||||
// Additionally, there are several reasons to stay away from deep verification and to prefer EdDSA signing the download archive instead.
|
||||
// See https://github.com/sparkle-project/Sparkle/pull/523#commitcomment-17549302 and https://github.com/sparkle-project/Sparkle/issues/543
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, kSecCSCheckAllArchitectures, requirement, &cfError);
|
||||
|
||||
if (result != errSecSuccess) {
|
||||
NSError *underlyingError;
|
||||
if (cfError != NULL) {
|
||||
NSError *tmpError = CFBridgingRelease(cfError);
|
||||
underlyingError = tmpError;
|
||||
} else {
|
||||
underlyingError = nil;
|
||||
}
|
||||
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
||||
if (underlyingError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = underlyingError;
|
||||
}
|
||||
|
||||
if (result == errSecCSUnsigned) {
|
||||
NSString *message = @"The host app is signed, but the new version of the app is not signed using Apple Code Signing. Please ensure that the new app is signed and that archiving did not corrupt the signature.";
|
||||
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
if (error != NULL) {
|
||||
userInfo[NSLocalizedDescriptionKey] = message;
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:[userInfo copy]];
|
||||
}
|
||||
} else if (result == errSecCSReqFailed) {
|
||||
CFStringRef requirementString = nil;
|
||||
NSString *initialMessage;
|
||||
if (SecRequirementCopyString(requirement, kSecCSDefaultFlags, &requirementString) == noErr) {
|
||||
initialMessage = [NSString stringWithFormat:@"Code signature of the new version doesn't match the old version: %@. Please ensure that old and new app is signed using exactly the same certificate.", requirementString];
|
||||
|
||||
SULog(SULogLevelError, @"%@", initialMessage);
|
||||
CFRelease(requirementString);
|
||||
} else {
|
||||
initialMessage = @"Code signature of new version doesn't match the old version. Please ensure that old and new app is signed using exactly the same certificate.";
|
||||
}
|
||||
|
||||
NSDictionary *oldInfo = [self logSigningInfoForCode:oldCode label:@"old info"];
|
||||
NSDictionary *newInfo = [self logSigningInfoForCode:staticCode label:@"new info"];
|
||||
|
||||
if (error != NULL) {
|
||||
userInfo[NSLocalizedDescriptionKey] = [NSString stringWithFormat:@"%@ old info: %@. new info: %@", initialMessage, oldInfo, newInfo];
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:[userInfo copy]];
|
||||
}
|
||||
} else {
|
||||
if (error != NULL) {
|
||||
userInfo[NSLocalizedDescriptionKey] = @"Error: Old app bundle code signing signature failed to match new bundle code signature";
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:[userInfo copy]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
finally:
|
||||
if (oldCode) CFRelease(oldCode);
|
||||
if (staticCode) CFRelease(staticCode);
|
||||
if (requirement) CFRelease(requirement);
|
||||
return (result == noErr);
|
||||
}
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundleURL error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
return [self codeSignatureIsValidAtBundleURL:bundleURL checkNestedCode:NO error:error];
|
||||
}
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundleURL checkNestedCode:(BOOL)checkNestedCode error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
OSStatus result;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
CFErrorRef cfError = NULL;
|
||||
// See also code further below where kSecCSCheckNestedCode may be added
|
||||
SecCSFlags flags = kSecCSCheckAllArchitectures;
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)bundleURL, kSecCSDefaultFlags, &staticCode);
|
||||
if (result != noErr) {
|
||||
SULog(SULogLevelError, @"Failed to get static code %d", result);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to get static code for verifying code signature: %d", result] }];
|
||||
}
|
||||
|
||||
goto finally;
|
||||
}
|
||||
|
||||
// See in -codeSignatureIsValidAtBundleURL:andMatchesSignatureAtBundleURL:error: for why kSecCSCheckNestedCode is not always passed
|
||||
if (checkNestedCode) {
|
||||
flags |= kSecCSCheckNestedCode;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, flags, NULL, &cfError);
|
||||
|
||||
if (result != errSecSuccess) {
|
||||
NSError *underlyingError;
|
||||
if (cfError != NULL) {
|
||||
NSError *tmpError = CFBridgingRelease(cfError);
|
||||
underlyingError = tmpError;
|
||||
} else {
|
||||
underlyingError = nil;
|
||||
}
|
||||
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
||||
if (underlyingError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = underlyingError;
|
||||
}
|
||||
|
||||
if (result == errSecCSUnsigned) {
|
||||
NSString *message = [NSString stringWithFormat:@"Error: The app is not signed using Apple Code Signing. %@", bundleURL];
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
if (error != NULL) {
|
||||
userInfo[NSLocalizedDescriptionKey] = message;
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:[userInfo copy]];
|
||||
}
|
||||
} else if (result == errSecCSReqFailed) {
|
||||
if (error != NULL) {
|
||||
NSDictionary *newInfo = [self logSigningInfoForCode:staticCode label:@"new info"];
|
||||
|
||||
NSString *message = [NSString stringWithFormat:@"Error: The app failed Apple Code Signing checks: %@ - new info: %@", bundleURL, newInfo];
|
||||
|
||||
userInfo[NSLocalizedDescriptionKey] = message;
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:[userInfo copy]];
|
||||
}
|
||||
} else {
|
||||
if (error != NULL) {
|
||||
NSString *message = [NSString stringWithFormat:@"Error: The app failed Apple Code Signing checks: %@", bundleURL];
|
||||
|
||||
userInfo[NSLocalizedDescriptionKey] = message;
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:[userInfo copy]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
finally:
|
||||
if (staticCode) CFRelease(staticCode);
|
||||
return (result == noErr);
|
||||
}
|
||||
|
||||
static id valueOrNSNull(id value) {
|
||||
return value ? value : [NSNull null];
|
||||
}
|
||||
|
||||
+ (NSDictionary *)codeSignatureInfoForCode:(SecStaticCodeRef)code SPU_OBJC_DIRECT
|
||||
{
|
||||
CFDictionaryRef signingInfo = nil;
|
||||
const SecCSFlags flags = (SecCSFlags) (kSecCSSigningInformation | kSecCSRequirementInformation | kSecCSDynamicInformation | kSecCSContentInformation);
|
||||
if (SecCodeCopySigningInformation(code, flags, &signingInfo) == noErr) {
|
||||
NSDictionary *signingDict = CFBridgingRelease(signingInfo);
|
||||
NSMutableDictionary *relevantInfo = [NSMutableDictionary dictionary];
|
||||
for (NSString *key in @[@"format", @"identifier", @"requirements", @"teamid", @"signing-time"]) {
|
||||
[relevantInfo setObject:valueOrNSNull([signingDict objectForKey:key]) forKey:key];
|
||||
}
|
||||
NSDictionary *infoPlist = [signingDict objectForKey:@"info-plist"];
|
||||
[relevantInfo setObject:valueOrNSNull([infoPlist objectForKey:@"CFBundleShortVersionString"]) forKey:@"version"];
|
||||
[relevantInfo setObject:valueOrNSNull([infoPlist objectForKey:(__bridge NSString *)kCFBundleVersionKey]) forKey:@"build"];
|
||||
return [relevantInfo copy];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)logSigningInfoForCode:(SecStaticCodeRef)code label:(NSString*)label SPU_OBJC_DIRECT
|
||||
{
|
||||
NSDictionary *relevantInfo = [self codeSignatureInfoForCode:code];
|
||||
SULog(SULogLevelDefault, @"%@: %@", label, relevantInfo);
|
||||
return relevantInfo;
|
||||
}
|
||||
|
||||
+ (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundleURL
|
||||
{
|
||||
OSStatus result;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)bundleURL, kSecCSDefaultFlags, &staticCode);
|
||||
if (result == errSecCSUnsigned) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
SecRequirementRef requirement = NULL;
|
||||
result = SecCodeCopyDesignatedRequirement(staticCode, kSecCSDefaultFlags, &requirement);
|
||||
if (staticCode) {
|
||||
CFRelease(staticCode);
|
||||
}
|
||||
if (requirement) {
|
||||
CFRelease(requirement);
|
||||
}
|
||||
if (result == errSecCSUnsigned) {
|
||||
return NO;
|
||||
}
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
static NSString * _Nullable SUTeamIdentifierFromCode(SecStaticCodeRef staticCode)
|
||||
{
|
||||
CFDictionaryRef cfSigningInformation = NULL;
|
||||
OSStatus copySigningInfoCode = SecCodeCopySigningInformation(staticCode, kSecCSSigningInformation,
|
||||
&cfSigningInformation);
|
||||
|
||||
NSDictionary *signingInformation = CFBridgingRelease(cfSigningInformation);
|
||||
|
||||
if (copySigningInfoCode != noErr) {
|
||||
SULog(SULogLevelError, @"Failed to get signing information for retrieving team identifier: %d", copySigningInfoCode);
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Note this will return nil for ad-hoc or unsigned binaries
|
||||
return signingInformation[(NSString *)kSecCodeInfoTeamIdentifier];
|
||||
}
|
||||
|
||||
+ (NSString * _Nullable)teamIdentifierAtURL:(NSURL *)url
|
||||
{
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
OSStatus staticCodeResult = SecStaticCodeCreateWithPath((__bridge CFURLRef)url, kSecCSDefaultFlags, &staticCode);
|
||||
if (staticCodeResult != errSecSuccess) {
|
||||
SULog(SULogLevelError, @"Failed to get static code for retrieving team identifier: %d", staticCodeResult);
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *teamIdentifier = SUTeamIdentifierFromCode(staticCode);
|
||||
|
||||
if (staticCode != NULL) {
|
||||
CFRelease(staticCode);
|
||||
}
|
||||
|
||||
return teamIdentifier;
|
||||
}
|
||||
|
||||
+ (NSString * _Nullable)teamIdentifierFromMainExecutable
|
||||
{
|
||||
SecCodeRef code = NULL;
|
||||
OSStatus result = SecCodeCopySelf(kSecCSDefaultFlags, &code);
|
||||
if (result != errSecSuccess) {
|
||||
SULog(SULogLevelError, @"Failed to get code for retrieving team identifier of main executable: %d", result);
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *teamIdentifier = SUTeamIdentifierFromCode(code);
|
||||
|
||||
CFRelease(code);
|
||||
|
||||
return teamIdentifier;
|
||||
}
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtDownloadURL:(NSURL *)downloadURL andMatchesDeveloperIDTeamFromOldBundleURL:(NSURL *)oldBundleURL error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
NSString *teamIdentifier = nil;
|
||||
NSString *requirementString = nil;
|
||||
SecRequirementRef requirement = NULL;
|
||||
SecStaticCodeRef oldStaticCode = NULL;
|
||||
SecStaticCodeRef downloadStaticCode = NULL;
|
||||
OSStatus result;
|
||||
|
||||
NSError *resultError = nil;
|
||||
CFErrorRef cfError = NULL;
|
||||
|
||||
NSString *commonErrorMessage = @"The download archive cannot be validated with Apple Developer ID code signing as fallback (after (Ed)DSA verification has failed)";
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)oldBundleURL, kSecCSDefaultFlags, &oldStaticCode);
|
||||
if (result != errSecSuccess) {
|
||||
NSString *errorMessage =
|
||||
(result == errSecCSUnsigned) ?
|
||||
[NSString stringWithFormat:@"%@. The original app is not code signed: %@", commonErrorMessage, oldBundleURL.path] :
|
||||
[NSString stringWithFormat:@"%@. The static code could not be retrieved from the original app (%d): %@", commonErrorMessage, result, oldBundleURL.path];
|
||||
|
||||
resultError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
|
||||
goto finally;
|
||||
}
|
||||
|
||||
teamIdentifier = SUTeamIdentifierFromCode(oldStaticCode);
|
||||
if (teamIdentifier == nil) {
|
||||
resultError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"%@. The team identifier could not be retrieved from the original app: %@", commonErrorMessage, oldBundleURL.path] }];
|
||||
|
||||
goto finally;
|
||||
}
|
||||
|
||||
// Create a designated requirement with developer ID signing with this team ID
|
||||
// Validate it against code signing check of this archive
|
||||
// CertificateIssuedByApple = anchor apple generic
|
||||
// IssuerIsDeveloperID = certificate 1[field.1.2.840.113635.100.6.2.6]
|
||||
// LeafIsDeveloperIDApp = certificate leaf[field.1.2.840.113635.100.6.1.13]
|
||||
// DeveloperIDTeamID = certificate leaf[subject.OU]
|
||||
// https://developer.apple.com/documentation/technotes/tn3127-inside-code-signing-requirements#Xcode-designated-requirement-for-Developer-ID-code
|
||||
requirementString = [NSString stringWithFormat:@"anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] and certificate leaf[field.1.2.840.113635.100.6.1.13] and certificate leaf[subject.OU] = \"%@\"", teamIdentifier];
|
||||
|
||||
result = SecRequirementCreateWithString((__bridge CFStringRef)requirementString, kSecCSDefaultFlags, &requirement);
|
||||
if (result != errSecSuccess) {
|
||||
resultError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"%@. The designated requirement string with a Developer ID requirement with team identifier '%@' could not be created with error %d", commonErrorMessage, teamIdentifier, result] }];
|
||||
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)downloadURL, kSecCSDefaultFlags, &downloadStaticCode);
|
||||
if (result != errSecSuccess) {
|
||||
NSString *message = [NSString stringWithFormat:@"%@. The static code could not be retrieved from the download archive with error %d. The download archive may not be Apple code signed.", commonErrorMessage, result];
|
||||
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
resultError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCheckValidityWithErrors(downloadStaticCode, kSecCSDefaultFlags, requirement, &cfError);
|
||||
if (result != errSecSuccess) {
|
||||
NSError *underlyingError;
|
||||
if (cfError != NULL) {
|
||||
NSError *tmpError = CFBridgingRelease(cfError);
|
||||
underlyingError = tmpError;
|
||||
} else {
|
||||
underlyingError = nil;
|
||||
}
|
||||
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
||||
if (underlyingError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = underlyingError;
|
||||
}
|
||||
|
||||
if (result == errSecCSUnsigned) {
|
||||
NSString *message = [NSString stringWithFormat:@"%@. The download archive is not Apple code signed.", commonErrorMessage];
|
||||
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
userInfo[NSLocalizedDescriptionKey] = message;
|
||||
|
||||
resultError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:[userInfo copy]];
|
||||
} else if (result == errSecCSReqFailed) {
|
||||
NSString *initialMessage = [NSString stringWithFormat:@"%@. The Apple code signature of new downloaded archive is either not Developer ID code signed, or doesn't have a Team ID that matches the old app version (%@). Please ensure that the archive and app are signed using the same Developer ID certificate.", commonErrorMessage, teamIdentifier];
|
||||
|
||||
NSDictionary *oldInfo = [self logSigningInfoForCode:oldStaticCode label:@"old info"];
|
||||
NSDictionary *newInfo = [self logSigningInfoForCode:downloadStaticCode label:@"new info"];
|
||||
|
||||
userInfo[NSLocalizedDescriptionKey] = [NSString stringWithFormat:@"%@ old info: %@. new info: %@", initialMessage, oldInfo, newInfo];
|
||||
|
||||
resultError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:[userInfo copy]];
|
||||
} else {
|
||||
userInfo[NSLocalizedDescriptionKey] = [NSString stringWithFormat:@"%@. The downloaded archive code signing signature failed to validate with an unknown error (%d).", commonErrorMessage, result];
|
||||
|
||||
resultError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:[userInfo copy]];
|
||||
}
|
||||
|
||||
goto finally;
|
||||
}
|
||||
|
||||
finally:
|
||||
|
||||
if (oldStaticCode != NULL) {
|
||||
CFRelease(oldStaticCode);
|
||||
}
|
||||
|
||||
if (requirement != NULL) {
|
||||
CFRelease(requirement);
|
||||
}
|
||||
|
||||
if (downloadStaticCode != NULL) {
|
||||
CFRelease(downloadStaticCode);
|
||||
}
|
||||
|
||||
if (resultError != nil && error != NULL) {
|
||||
*error = resultError;
|
||||
}
|
||||
|
||||
return (resultError == nil);
|
||||
}
|
||||
|
||||
+ (SUValidateConnectionStatus)validateConnection:(NSXPCConnection *)connection error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
// Check if code signing requirement is required
|
||||
NSString *hostTeamIdentifier = [self teamIdentifierFromMainExecutable];
|
||||
if (hostTeamIdentifier == nil) {
|
||||
return SUValidateConnectionStatusSetNoRequirementSuccess;
|
||||
}
|
||||
|
||||
// Build the default team ID signing requirement
|
||||
NSString *codeSigningRequirement = [NSString stringWithFormat:@"(anchor apple generic and certificate leaf[subject.OU] = \"%@\")", hostTeamIdentifier];
|
||||
|
||||
if (@available(macOS 13.0, *)) {
|
||||
[connection setCodeSigningRequirement:codeSigningRequirement];
|
||||
|
||||
return SUValidateConnectionStatusSetCodeSigningRequirementSuccess;
|
||||
}
|
||||
|
||||
// Fall back to audit token on older OS's
|
||||
if ([connection respondsToSelector:@selector(auditToken)]) {
|
||||
audit_token_t auditToken = [connection auditToken];
|
||||
NSData *auditTokenData = [NSData dataWithBytes:&auditToken length:sizeof(auditToken)];
|
||||
|
||||
NSDictionary *attributes = @{
|
||||
(NSString *)kSecGuestAttributeAudit: auditTokenData
|
||||
};
|
||||
|
||||
SecCodeRef code = NULL;
|
||||
OSStatus result = SecCodeCopyGuestWithAttributes(NULL, (__bridge CFDictionaryRef _Nullable)(attributes), kSecCSDefaultFlags, &code);
|
||||
if (result != errSecSuccess) {
|
||||
CFRelease(code);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"The client connection could not be validated because SecCodeCopyGuestWithAttributes() failed with error %d", result] }];
|
||||
}
|
||||
|
||||
return SUValidateConnectionStatusAPIFailure;
|
||||
}
|
||||
|
||||
// Check if the client is code signed with our signing requirement
|
||||
|
||||
SecRequirementRef requirement = NULL;
|
||||
result = SecRequirementCreateWithString((__bridge CFStringRef)codeSigningRequirement, kSecCSDefaultFlags, &requirement);
|
||||
|
||||
if (result != errSecSuccess) {
|
||||
CFRelease(code);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"The client connection could not be validated because SecRequirementCreateWithString() failed with error %d", result] }];
|
||||
}
|
||||
|
||||
return SUValidateConnectionStatusAPIFailure;
|
||||
}
|
||||
|
||||
CFErrorRef cfError = NULL;
|
||||
// This is not a static code, so we don't pass kSecCSCheckAllArchitectures
|
||||
result = SecCodeCheckValidityWithErrors(code, kSecCSDefaultFlags, requirement, &cfError);
|
||||
|
||||
CFRelease(requirement);
|
||||
requirement = NULL;
|
||||
|
||||
if (result != errSecSuccess) {
|
||||
NSError *cfBridgedError = (NSError *)CFBridgingRelease(cfError);
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInsufficientSigningError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"The client connection could not be validated because validating the code signature failed with error %d (%@). Does the app meet the designated requirement: %@", result, cfBridgedError.localizedDescription, codeSigningRequirement] }];
|
||||
}
|
||||
|
||||
[self logSigningInfoForCode:code label:@"Client"];
|
||||
|
||||
CFRelease(code);
|
||||
|
||||
return SUValidateConnectionStatusCodeSigningRequirementFailure;
|
||||
}
|
||||
|
||||
CFRelease(code);
|
||||
|
||||
return SUValidateConnectionStatusSetCodeSigningRequirementSuccess;
|
||||
}
|
||||
|
||||
// Not much we can do if auditToken is not supported. This code should not be reached though.
|
||||
return SUValidateConectionNoSupportedValidationMethodFailure;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,27 +0,0 @@
|
||||
//
|
||||
// SUDiskImageUnarchiver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 6/16/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUDISKIMAGEUNARCHIVER_H
|
||||
#define SUDISKIMAGEUNARCHIVER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUUnarchiverProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUDiskImageUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory decryptionPassword:(nullable NSString *)decryptionPassword;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -1,325 +0,0 @@
|
||||
//
|
||||
// SUDiskImageUnarchiver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 6/16/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUDiskImageUnarchiver.h"
|
||||
#import "SUUnarchiverNotifier.h"
|
||||
#import "SULog.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUDiskImageUnarchiver () <NSFileManagerDelegate>
|
||||
@end
|
||||
|
||||
@implementation SUDiskImageUnarchiver
|
||||
{
|
||||
NSString *_archivePath;
|
||||
NSString *_decryptionPassword;
|
||||
NSString *_extractionDirectory;
|
||||
|
||||
SUUnarchiverNotifier *_notifier;
|
||||
double _currentExtractionProgress;
|
||||
double _fileProgressIncrement;
|
||||
}
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return [[path pathExtension] isEqualToString:@"dmg"];
|
||||
}
|
||||
|
||||
+ (BOOL)mustValidateBeforeExtraction
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory decryptionPassword:(nullable NSString *)decryptionPassword
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_archivePath = [archivePath copy];
|
||||
_decryptionPassword = [decryptionPassword copy];
|
||||
_extractionDirectory = [extractionDirectory copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)needsVerifyBeforeExtractionKey
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock waitForCleanup:(BOOL)waitForCleanup
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
SUUnarchiverNotifier *notifier = [[SUUnarchiverNotifier alloc] initWithCompletionBlock:completionBlock progressBlock:progressBlock];
|
||||
[self extractDMGWithNotifier:notifier waitForCleanup:waitForCleanup];
|
||||
});
|
||||
}
|
||||
|
||||
static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *itemPath)
|
||||
{
|
||||
NSUInteger fileCount = 0;
|
||||
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:itemPath];
|
||||
for (NSString * __unused currentFile in dirEnum) {
|
||||
fileCount++;
|
||||
}
|
||||
|
||||
return fileCount;
|
||||
}
|
||||
|
||||
- (BOOL)fileManager:(NSFileManager *)fileManager shouldCopyItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL
|
||||
{
|
||||
_currentExtractionProgress += _fileProgressIncrement;
|
||||
[_notifier notifyProgress:_currentExtractionProgress];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// Called on a non-main thread.
|
||||
- (void)extractDMGWithNotifier:(SUUnarchiverNotifier *)notifier waitForCleanup:(BOOL)waitForCleanup SPU_OBJC_DIRECT
|
||||
{
|
||||
@autoreleasepool {
|
||||
BOOL mountedSuccessfully = NO;
|
||||
|
||||
// get a unique mount point path
|
||||
NSString *mountPoint = nil;
|
||||
NSFileManager *manager;
|
||||
NSError *error = nil;
|
||||
NSArray *contents = nil;
|
||||
do {
|
||||
NSString *uuidString = [[NSUUID UUID] UUIDString];
|
||||
mountPoint = [@"/Volumes" stringByAppendingPathComponent:uuidString];
|
||||
}
|
||||
// Note: this check does not follow symbolic links, which is what we want
|
||||
while ([[NSURL fileURLWithPath:mountPoint] checkResourceIsReachableAndReturnError:NULL]);
|
||||
|
||||
NSMutableData *inputData = [NSMutableData data];
|
||||
|
||||
// Prepare stdin data for passwords and license agreements
|
||||
{
|
||||
// If no password is supplied, we will still be asked a password.
|
||||
// In that case we respond with an empty password.
|
||||
NSData *decryptionPasswordData = [_decryptionPassword dataUsingEncoding:NSUTF8StringEncoding];
|
||||
if (decryptionPasswordData != nil) {
|
||||
[inputData appendData:decryptionPasswordData];
|
||||
}
|
||||
|
||||
// From the hdiutil docs:
|
||||
// read a null-terminated passphrase from standard input
|
||||
//
|
||||
// Add the null terminator
|
||||
[inputData appendBytes:"\0" length:1];
|
||||
|
||||
// Append prompt data for license agreements
|
||||
[inputData appendBytes:"yes\n" length:4];
|
||||
}
|
||||
|
||||
// Finder doesn't verify disk images anymore beyond the code signing signature (if available)
|
||||
// Opt out of the old CRC checksum checks
|
||||
// Also always pass -stdinpass so we gracefully handle password protected disk images even if we aren't expecting them
|
||||
NSArray *arguments = @[@"attach", _archivePath, @"-mountpoint", mountPoint, @"-noverify", @"-nobrowse", @"-noautoopen", @"-stdinpass"];
|
||||
|
||||
NSData *output = nil;
|
||||
NSInteger taskResult = -1;
|
||||
|
||||
NSURL *mountPointURL = [NSURL fileURLWithPath:mountPoint isDirectory:YES];
|
||||
NSURL *extractionDirectoryURL = [NSURL fileURLWithPath:_extractionDirectory isDirectory:YES];
|
||||
NSMutableArray<NSString *> *itemsToExtract = [NSMutableArray array];
|
||||
NSUInteger totalFileExtractionCount = 0;
|
||||
|
||||
BOOL success = YES;
|
||||
|
||||
{
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
task.launchPath = @"/usr/bin/hdiutil";
|
||||
task.currentDirectoryPath = @"/";
|
||||
task.arguments = arguments;
|
||||
|
||||
NSPipe *inputPipe = [NSPipe pipe];
|
||||
NSPipe *outputPipe = [NSPipe pipe];
|
||||
|
||||
task.standardInput = inputPipe;
|
||||
task.standardOutput = outputPipe;
|
||||
|
||||
NSFileHandle *fileStdHandle = outputPipe.fileHandleForReading;
|
||||
NSMutableData *currentOutput = [NSMutableData data];
|
||||
|
||||
fileStdHandle.readabilityHandler = ^(NSFileHandle *file) {
|
||||
[currentOutput appendData:file.availableData];
|
||||
};
|
||||
|
||||
dispatch_semaphore_t terminationSemaphore = dispatch_semaphore_create(0);
|
||||
task.terminationHandler = ^(NSTask *__unused terminatingTask) {
|
||||
fileStdHandle.readabilityHandler = nil;
|
||||
|
||||
dispatch_semaphore_signal(terminationSemaphore);
|
||||
};
|
||||
|
||||
if (![task launchAndReturnError:&error]) {
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
if (@available(macOS 10.15, *)) {
|
||||
if (![inputPipe.fileHandleForWriting writeData:inputData error:&error]) {
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
else
|
||||
{
|
||||
@try {
|
||||
[inputPipe.fileHandleForWriting writeData:inputData];
|
||||
} @catch (NSException *) {
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[inputPipe.fileHandleForWriting closeFile];
|
||||
|
||||
dispatch_semaphore_wait(terminationSemaphore, DISPATCH_TIME_FOREVER);
|
||||
output = [currentOutput copy];
|
||||
|
||||
taskResult = task.terminationStatus;
|
||||
}
|
||||
|
||||
if (taskResult != 0) {
|
||||
NSString *resultStr = output ? [[NSString alloc] initWithData:output encoding:NSUTF8StringEncoding] : nil;
|
||||
SULog(SULogLevelError, @"hdiutil failed with code: %ld data: <<%@>>", (long)taskResult, resultStr);
|
||||
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed due to hdiutil returning %ld status: %@", (long)taskResult, resultStr]}];
|
||||
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
mountedSuccessfully = YES;
|
||||
|
||||
// Mounting can take some time, so increment progress
|
||||
_currentExtractionProgress = 0.1;
|
||||
[notifier notifyProgress:_currentExtractionProgress];
|
||||
|
||||
// Now that we've mounted it, we need to copy out its contents.
|
||||
manager = [[NSFileManager alloc] init];
|
||||
contents = [manager contentsOfDirectoryAtPath:mountPoint error:&error];
|
||||
if (contents == nil) {
|
||||
SULog(SULogLevelError, @"Couldn't enumerate contents of archive mounted at %@: %@", mountPoint, error);
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
// Sparkle can support installing pkg files, app bundles, and other bundle types for plug-ins
|
||||
// We must not filter any of those out
|
||||
for (NSString *item in contents) {
|
||||
NSURL *fromPathURL = [mountPointURL URLByAppendingPathComponent:item];
|
||||
|
||||
NSString *lastPathComponent = fromPathURL.lastPathComponent;
|
||||
|
||||
// Ignore hidden files
|
||||
if ([lastPathComponent hasPrefix:@"."]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore aliases
|
||||
NSNumber *aliasFlag = nil;
|
||||
if ([fromPathURL getResourceValue:&aliasFlag forKey:NSURLIsAliasFileKey error:NULL] && aliasFlag.boolValue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore symbolic links
|
||||
NSNumber *symbolicFlag = nil;
|
||||
if ([fromPathURL getResourceValue:&symbolicFlag forKey:NSURLIsSymbolicLinkKey error:NULL] && symbolicFlag.boolValue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ensure file is readable
|
||||
NSNumber *isReadableFlag = nil;
|
||||
if ([fromPathURL getResourceValue:&isReadableFlag forKey:NSURLIsReadableKey error:NULL] && !isReadableFlag.boolValue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSNumber *isDirectoryFlag = nil;
|
||||
if (![fromPathURL getResourceValue:&isDirectoryFlag forKey:NSURLIsDirectoryKey error:NULL]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BOOL isDirectory = isDirectoryFlag.boolValue;
|
||||
NSString *pathExtension = fromPathURL.pathExtension;
|
||||
|
||||
if (isDirectory) {
|
||||
// Skip directory types that aren't bundles or regular directories
|
||||
if ([pathExtension isEqualToString:@"rtfd"]) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// The only non-directory files we care about are (m)pkg files
|
||||
if (![pathExtension isEqualToString:@"pkg"] && ![pathExtension isEqualToString:@"mpkg"]) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDirectory) {
|
||||
totalFileExtractionCount += fileCountForDirectory(manager, fromPathURL.path);
|
||||
} else {
|
||||
totalFileExtractionCount++;
|
||||
}
|
||||
|
||||
[itemsToExtract addObject:item];
|
||||
}
|
||||
|
||||
_fileProgressIncrement = (0.99 - _currentExtractionProgress) / (double)totalFileExtractionCount;
|
||||
_notifier = notifier;
|
||||
|
||||
// Copy all items we want to extract and notify of progress
|
||||
manager.delegate = self;
|
||||
for (NSString *item in itemsToExtract) {
|
||||
NSURL *fromURL = [mountPointURL URLByAppendingPathComponent:item];
|
||||
NSURL *toURL = [extractionDirectoryURL URLByAppendingPathComponent:item];
|
||||
|
||||
if (![manager copyItemAtURL:fromURL toURL:toURL error:&error]) {
|
||||
SULog(SULogLevelError, @"Failed to copy '%@' to '%@' with error: %@", fromURL.path, toURL.path, error);
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
|
||||
[notifier notifyProgress:1.0];
|
||||
|
||||
goto finally;
|
||||
|
||||
reportError:
|
||||
success = NO;
|
||||
|
||||
finally:
|
||||
if (mountedSuccessfully) {
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
task.launchPath = @"/usr/bin/hdiutil";
|
||||
task.arguments = @[@"detach", mountPoint, @"-force"];
|
||||
task.standardOutput = [NSPipe pipe];
|
||||
task.standardError = [NSPipe pipe];
|
||||
|
||||
NSError *launchCleanupError = nil;
|
||||
if (![task launchAndReturnError:&launchCleanupError]) {
|
||||
SULog(SULogLevelError, @"Failed to unmount %@", mountPoint);
|
||||
SULog(SULogLevelError, @"Error: %@", launchCleanupError);
|
||||
} else if (waitForCleanup) {
|
||||
[task waitUntilExit];
|
||||
}
|
||||
} else {
|
||||
SULog(SULogLevelError, @"Can't mount DMG %@", _archivePath);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
[notifier notifySuccess];
|
||||
} else {
|
||||
[notifier notifyFailureWithError:error];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], _archivePath]; }
|
||||
|
||||
@end
|
||||
@@ -1,27 +0,0 @@
|
||||
//
|
||||
// SUFlatPackageUnarchiver.h
|
||||
// Autoupdate
|
||||
//
|
||||
// Created by Mayur Pawashe on 1/30/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUUnarchiverProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// An unarchiver for flat packages that doesn't really do any unarchiving
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUFlatPackageUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithFlatPackagePath:(NSString *)flatPackagePath extractionDirectory:(NSString *)extractionDirectory expectingInstallationType:(NSString *)installationType;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -1,84 +0,0 @@
|
||||
//
|
||||
// SUFlatPackageUnarchiver.m
|
||||
// Autoupdate
|
||||
//
|
||||
// Created by Mayur Pawashe on 1/30/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import "SUFlatPackageUnarchiver.h"
|
||||
#import "SUUnarchiverNotifier.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUFlatPackageUnarchiver
|
||||
{
|
||||
NSString *_flatPackagePath;
|
||||
NSString *_expectedInstallationType;
|
||||
NSString *_extractionDirectory;
|
||||
}
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return [path.pathExtension isEqualToString:@"pkg"] || [path.pathExtension isEqualToString:@"mpkg"];
|
||||
}
|
||||
|
||||
+ (BOOL)mustValidateBeforeExtraction
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFlatPackagePath:(NSString *)flatPackagePath extractionDirectory:(NSString *)extractionDirectory expectingInstallationType:(NSString *)installationType
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_flatPackagePath = [flatPackagePath copy];
|
||||
_expectedInstallationType = [installationType copy];
|
||||
_extractionDirectory = [extractionDirectory copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)needsVerifyBeforeExtractionKey
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock waitForCleanup:(BOOL)__unused waitForCleanup
|
||||
{
|
||||
SUUnarchiverNotifier *notifier = [[SUUnarchiverNotifier alloc] initWithCompletionBlock:completionBlock progressBlock:progressBlock];
|
||||
|
||||
// Flat packages must use guided package installs, not interactive
|
||||
BOOL isDirectory = NO;
|
||||
if (![_expectedInstallationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not have guided installation type but %@ instead", _expectedInstallationType]}]];
|
||||
} else if (![[NSFileManager defaultManager] fileExistsAtPath:_flatPackagePath isDirectory:&isDirectory] || isDirectory) {
|
||||
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not exist at %@", _flatPackagePath]}]];
|
||||
} else {
|
||||
// Copying the flat package should be very fast, especially on APFS
|
||||
NSError *copyError = nil;
|
||||
if (![[NSFileManager defaultManager] copyItemAtPath:_flatPackagePath toPath:[_extractionDirectory stringByAppendingPathComponent:_flatPackagePath.lastPathComponent] error:©Error]) {
|
||||
NSMutableDictionary *userInfoDictionary = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package (%@) cannot be copied to extraction directory (%@)", _flatPackagePath, _extractionDirectory]}];
|
||||
|
||||
if (copyError != nil) {
|
||||
userInfoDictionary[NSUnderlyingErrorKey] = copyError;
|
||||
}
|
||||
|
||||
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:userInfoDictionary]];
|
||||
} else {
|
||||
[notifier notifyProgress:1.0];
|
||||
[notifier notifySuccess];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], _flatPackagePath]; }
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// SUGuidedPackageInstaller.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Graham Miln on 14/05/2010.
|
||||
// Copyright 2010 Dragon Systems Software Limited. All rights reserved.
|
||||
//
|
||||
|
||||
/**
|
||||
# Sparkle Guided Installations
|
||||
|
||||
A guided installation allows Sparkle to download and install a package (pkg) or multi-package (mpkg) without user interaction.
|
||||
|
||||
The installer package is installed using macOS's built-in command line installer, `/usr/sbin/installer`. No installation interface is shown to the user.
|
||||
|
||||
A guided installation can be started by applications other than the application being replaced. This is particularly useful where helper applications or agents are used.
|
||||
*/
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerProtocol.h"
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUGuidedPackageInstaller : NSObject <SUInstallerProtocol>
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,87 +0,0 @@
|
||||
//
|
||||
// SUGuidedPackageInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Graham Miln on 14/05/2010.
|
||||
// Copyright 2010 Dragon Systems Software Limited. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import <sys/stat.h>
|
||||
#import "SUGuidedPackageInstaller.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUGuidedPackageInstaller
|
||||
{
|
||||
NSString *_packagePath;
|
||||
NSString *_homeDirectory;
|
||||
NSString *_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", _packagePath, @"-target", @"/"];
|
||||
// Set the $HOME and $USER variables so pre/post install scripts reference the correct user environment
|
||||
task.environment = @{@"HOME": _homeDirectory, @"USER": _userName};
|
||||
task.standardError = nil;
|
||||
task.standardOutput = nil;
|
||||
|
||||
NSError *launchError = nil;
|
||||
if (![task launchAndReturnError:&launchError]) {
|
||||
if (error != NULL) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey: @"Guided package installer failed to launch" }];
|
||||
|
||||
if (launchError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = launchError;
|
||||
}
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:userInfo];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
[task waitUntilExit];
|
||||
|
||||
if (task.terminationStatus != EXIT_SUCCESS) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Guided package installer returned non-zero exit status (%d)", task.terminationStatus] }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)performCleanup
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,28 +0,0 @@
|
||||
//
|
||||
// SUInstaller.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SUHost;
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUInstaller : NSObject
|
||||
|
||||
+ (nullable id<SUInstallerProtocol>)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory connectionCodeSigningValidationSkipped:(BOOL)connectionCodeSigningValidationSkipped homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName error:(NSError **)error;
|
||||
|
||||
+ (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage:(BOOL *)isPackagePtr isGuided:(nullable BOOL *)isGuidedPtr
|
||||
#endif
|
||||
;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,296 +0,0 @@
|
||||
//
|
||||
// SUInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUInstaller.h"
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUGuidedPackageInstaller.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SUNormalization.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUInstaller
|
||||
|
||||
+ (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr
|
||||
#endif
|
||||
{
|
||||
NSParameterAssert(inUpdateFolder);
|
||||
NSParameterAssert(host);
|
||||
|
||||
// Search subdirectories for the application
|
||||
NSString *currentFile,
|
||||
*newAppDownloadPath = nil,
|
||||
*bundleFileName = [[host bundlePath] lastPathComponent],
|
||||
*alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]];
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
NSString *fallbackPackagePath = nil;
|
||||
|
||||
BOOL isPackage = NO;
|
||||
BOOL isGuided = YES;
|
||||
#endif
|
||||
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:inUpdateFolder];
|
||||
NSString *bundleFileNameNoExtension = [bundleFileName stringByDeletingPathExtension];
|
||||
|
||||
while ((currentFile = [dirEnum nextObject])) {
|
||||
NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile];
|
||||
|
||||
// Ignore all symbolic links and aliases
|
||||
{
|
||||
NSURL *currentPathURL = [NSURL fileURLWithPath:currentPath];
|
||||
|
||||
NSNumber *symbolicLinkFlag = nil;
|
||||
[currentPathURL getResourceValue:&symbolicLinkFlag forKey:NSURLIsSymbolicLinkKey error:NULL];
|
||||
if (symbolicLinkFlag.boolValue) {
|
||||
// NSDirectoryEnumerator won't recurse into symlinked directories
|
||||
continue;
|
||||
}
|
||||
|
||||
NSNumber *aliasFlag = nil;
|
||||
[currentPathURL getResourceValue:&aliasFlag forKey:NSURLIsAliasFileKey error:NULL];
|
||||
|
||||
if (aliasFlag.boolValue) {
|
||||
NSNumber *directoryFlag = nil;
|
||||
[currentPathURL getResourceValue:&directoryFlag forKey:NSURLIsDirectoryKey error:NULL];
|
||||
|
||||
// Some DMGs have symlinks into /Applications! That's no good!
|
||||
if (directoryFlag.boolValue) {
|
||||
[dirEnum skipDescendents];
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
NSString *currentFilename = [currentFile lastPathComponent];
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
NSString *currentExtension = [currentFile pathExtension];
|
||||
NSString *currentFilenameNoExtension = [currentFilename stringByDeletingPathExtension];
|
||||
#endif
|
||||
if ([currentFilename isEqualToString:bundleFileName] ||
|
||||
[currentFilename isEqualToString:alternateBundleFileName]) // We found one!
|
||||
{
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage = NO;
|
||||
#endif
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
} else if ([currentExtension isEqualToString:@"pkg"] ||
|
||||
[currentExtension isEqualToString:@"mpkg"]) {
|
||||
if ([currentFilenameNoExtension isEqualToString:bundleFileNameNoExtension]) {
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
} else {
|
||||
// Remember any other non-matching packages we have seen should we need to use one of them as a fallback.
|
||||
fallbackPackagePath = currentPath;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
// Try matching on bundle identifiers in case the user has changed the name of the host app
|
||||
NSBundle *incomingBundle = [NSBundle bundleWithPath:currentPath];
|
||||
NSString *hostBundleIdentifier = host.bundle.bundleIdentifier;
|
||||
if (incomingBundle && [incomingBundle.bundleIdentifier isEqualToString:hostBundleIdentifier]) {
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage = NO;
|
||||
#endif
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
// We don't have a valid path. Try to use the fallback package.
|
||||
|
||||
if (newAppDownloadPath == nil && fallbackPackagePath != nil) {
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = fallbackPackagePath;
|
||||
}
|
||||
|
||||
if (isPackage) {
|
||||
// Guided (or now "normal") installs used to be opt-in (i.e, Sparkle would detect foo.sparkle_guided.pkg or foo.sparkle_guided.mpkg),
|
||||
// Interactive installs are no longer supported, so isGuided = NO will later turn into an error
|
||||
|
||||
// foo.app -> foo.sparkle_interactive.pkg or foo.sparkle_interactive.mpkg
|
||||
if ([[[newAppDownloadPath stringByDeletingPathExtension] pathExtension] isEqualToString:@"sparkle_interactive"]) {
|
||||
isGuided = NO;
|
||||
}
|
||||
}
|
||||
|
||||
if (isPackagePtr)
|
||||
*isPackagePtr = isPackage;
|
||||
if (isGuidedPtr)
|
||||
*isGuidedPtr = isGuided;
|
||||
|
||||
#endif
|
||||
|
||||
if (!newAppDownloadPath) {
|
||||
SULog(SULogLevelError, @"Searched %@ for %@.(app%@)", inUpdateFolder, bundleFileNameNoExtension,
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
@"|pkg"
|
||||
#else
|
||||
@""
|
||||
#endif
|
||||
);
|
||||
}
|
||||
return newAppDownloadPath;
|
||||
}
|
||||
|
||||
+ (nullable id<SUInstallerProtocol>)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory connectionCodeSigningValidationSkipped:(BOOL)connectionCodeSigningValidationSkipped homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
BOOL isPackage = NO;
|
||||
BOOL isGuided = NO;
|
||||
#endif
|
||||
|
||||
NSString *newDownloadPath = [self installSourcePathInUpdateFolder:updateDirectory forHost:host
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage:&isPackage isGuided:&isGuided
|
||||
#endif
|
||||
];
|
||||
|
||||
if (newDownloadPath == nil) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
if (isPackage && connectionCodeSigningValidationSkipped) {
|
||||
// Package updates cannot update arbitrary bundles if code signing validation on the connection was skipped
|
||||
// (This means our helper is not code signed with an Apple issued certificate).
|
||||
// In this case, the main executable must be owned by root and the host must contain our installer tool
|
||||
|
||||
NSString *installerExecutablePath = NSBundle.mainBundle.executableURL.URLByResolvingSymlinksInPath.path;
|
||||
if (installerExecutablePath == nil) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"The "@SPARKLE_RELAUNCH_TOOL_NAME" executable path failed to be retrieved, which is an internal error that shouldn't happen. Please try to update using a production build of your app." }];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *hostBundlePath = host.bundle.bundleURL.URLByResolvingSymlinksInPath.path;
|
||||
if (hostBundlePath == nil) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"The host bundle path to update to be retrieved, which is an internal error that shouldn't happen. Please try to update using a production build of your app." }];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSError *attributesError = nil;
|
||||
NSDictionary<NSFileAttributeKey, id> *fileAttributes = [NSFileManager.defaultManager attributesOfItemAtPath:installerExecutablePath error:&attributesError];
|
||||
|
||||
if (fileAttributes == nil) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"File attributes failed to be retrieved from the "@SPARKLE_RELAUNCH_TOOL_NAME" executable, which is an internal error that shouldn't happen. Please try to update using a production build of your app." }];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSNumber *installerOwnerID = fileAttributes[NSFileOwnerAccountID];
|
||||
if (installerOwnerID == nil) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"File owner ID failed to be retrieved from the "@SPARKLE_RELAUNCH_TOOL_NAME" executable, which is an internal error that shouldn't happen. Please try to update using a production build of your app." }];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Check our helper is owned by root
|
||||
if (![installerOwnerID isEqual:@(0)]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Due to security, updating apps with package installers is disabled when '%@' is not signed with the same Team ID as your app, and "@SPARKLE_RELAUNCH_TOOL_NAME" is not owned by root (this specific case) or not residing in '%@'. Please either test an exported & production build of your app, or for development, code sign your app and Sparkle's embedded helpers with the same team: https://sparkle-project.org/documentation/sandboxing#code-signing", installerExecutablePath, hostBundlePath] }];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSArray<NSString *> *installerExecutablePathComponents = installerExecutablePath.pathComponents;
|
||||
NSArray<NSString *> *hostBundlePathComponents = hostBundlePath.pathComponents;
|
||||
|
||||
if (installerExecutablePathComponents.count <= hostBundlePathComponents.count) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Due to security, updating apps with package installers is disabled when '%@' is not signed with the same Team ID as your app, and "@SPARKLE_RELAUNCH_TOOL_NAME" is not owned by root or not residing in '%@' (this specific case). Please either test an exported & production build of your app, or for development, code sign your app and Sparkle's embedded helpers with the same team: https://sparkle-project.org/documentation/sandboxing#code-signing", installerExecutablePath, hostBundlePath] }];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Check out helper resides inside the host app to be updated
|
||||
if (![[installerExecutablePathComponents subarrayWithRange:NSMakeRange(0, hostBundlePathComponents.count)] isEqualToArray:hostBundlePathComponents]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Due to security, updating apps with package installers is disabled when '%@' is not signed with the same Team ID as your app, and "@SPARKLE_RELAUNCH_TOOL_NAME" is not owned by root or not residing in '%@' (this specific case). Please either test an exported & production build of your app, or for development, code sign your app and Sparkle's embedded helpers with the same team: https://sparkle-project.org/documentation/sandboxing#code-signing", installerExecutablePath, hostBundlePath] }];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void)connectionCodeSigningValidationSkipped;
|
||||
#endif
|
||||
|
||||
// Make sure we find the type of installer that we were expecting to find
|
||||
// We shouldn't implicitly trust the installation type fed into here from the appcast because the installation type helps us determine
|
||||
// ahead of time whether or not this installer tool should be ran as root or not
|
||||
id <SUInstallerProtocol> installer = nil;
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
if (isPackage && isGuided) {
|
||||
if (![expectedInstallationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found guided package installer but '%@=%@' was probably missing in the appcast item enclosure", SUAppcastAttributeInstallationType, SPUInstallationTypeGuidedPackage] }];
|
||||
}
|
||||
} else {
|
||||
installer = [[SUGuidedPackageInstaller alloc] initWithPackagePath:newDownloadPath homeDirectory:homeDirectory userName:userName];
|
||||
}
|
||||
} else if (isPackage) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: @"Found interactive package installer (with 'sparkle_interactive' in the filename) but these are no longer supported. Please remove 'sparkle_interactive' from the filename." }];
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (![expectedInstallationType isEqualToString:SPUInstallationTypeApplication]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found regular application update but expected '%@=%@' from the appcast item enclosure instead", SUAppcastAttributeInstallationType, expectedInstallationType] }];
|
||||
}
|
||||
} else {
|
||||
NSString *normalizedInstallationPath = nil;
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) {
|
||||
normalizedInstallationPath = SUNormalizedInstallationPath(host);
|
||||
}
|
||||
|
||||
// If we have a normalized path, we'll install to "#{CFBundleName}.app", but only if that path doesn't already exist. If we're "Foo 4.2.app," and there's a "Foo.app" in this directory, we don't want to overwrite it! But if there's no "Foo.app," we'll take that name.
|
||||
// Otherwise if there's no normalized path (the more likely case), we'll just use the host bundle's path
|
||||
// Check progress agent app which computes normalized path too according to these rules
|
||||
NSString *installationPath;
|
||||
if (normalizedInstallationPath != nil && ![[NSFileManager defaultManager] fileExistsAtPath:normalizedInstallationPath]) {
|
||||
installationPath = normalizedInstallationPath;
|
||||
} else {
|
||||
installationPath = host.bundlePath;
|
||||
}
|
||||
|
||||
installer = [[SUPlainInstaller alloc] initWithHost:host bundlePath:newDownloadPath installationPath:installationPath];
|
||||
}
|
||||
}
|
||||
|
||||
return installer;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,33 +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;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,27 +0,0 @@
|
||||
//
|
||||
// SUPipedUnarchiver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 6/16/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUPIPEDUNARCHIVER_H
|
||||
#define SUPIPEDUNARCHIVER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUUnarchiverProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUPipedUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -1,381 +0,0 @@
|
||||
//
|
||||
// SUPipedUnarchiver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 6/16/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUPipedUnarchiver.h"
|
||||
#import "SUUnarchiverNotifier.h"
|
||||
#import "SULog.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUPipedUnarchiver
|
||||
{
|
||||
NSString *_archivePath;
|
||||
NSString *_extractionDirectory;
|
||||
}
|
||||
|
||||
// pipingData == NO is only supported for zip archives
|
||||
static NSArray<NSString *> * _Nullable argumentsConformingToTypeOfPath(NSString *path, BOOL pipingData, NSString * __autoreleasing *outCommand)
|
||||
{
|
||||
NSArray <NSString *> *extractTGZ = @[@"/usr/bin/tar", @"-zxC"];
|
||||
NSArray <NSString *> *extractTBZ = @[@"/usr/bin/tar", @"-jxC"];
|
||||
NSArray <NSString *> *extractTXZ = extractTGZ;
|
||||
|
||||
// Note: keep this list in sync with generate_appcast's unarchiveUpdates()
|
||||
NSMutableDictionary <NSString *, NSArray<NSString *> *> *extractCommandDictionary =
|
||||
[@{
|
||||
@".zip" : (pipingData ? @[@"/usr/bin/ditto", @"-x", @"-k", @"-"] : @[@"/usr/bin/ditto", @"-x", @"-k", path]),
|
||||
@".tar" : @[@"/usr/bin/tar", @"-xC"],
|
||||
@".tar.gz" : extractTGZ,
|
||||
@".tgz" : extractTGZ,
|
||||
@".tar.bz2" : extractTBZ,
|
||||
@".tbz" : extractTBZ,
|
||||
@".tar.xz" : extractTXZ,
|
||||
@".txz" : extractTXZ,
|
||||
@".tar.lzma" : extractTXZ,
|
||||
} mutableCopy];
|
||||
|
||||
// At least the latest versions of 10.15 understand how to extract aar files
|
||||
// Versions before 10.15 do not understand extracting newly created aar files
|
||||
// Note encrypted aea files are supported in macOS 12 onwards, if we ever want to support those one day
|
||||
if (@available(macOS 10.15.7, *)) {
|
||||
NSString *appleArchiveCommand;
|
||||
if (@available(macOS 11, *)) {
|
||||
appleArchiveCommand = @"/usr/bin/aa";
|
||||
} else {
|
||||
// In 10.15 the utility was named yaa, which was later renamed to aar
|
||||
appleArchiveCommand = @"/usr/bin/yaa";
|
||||
}
|
||||
|
||||
NSArray <NSString *> *extractAppleArchive = @[appleArchiveCommand, @"extract", @"-d"];
|
||||
|
||||
[extractCommandDictionary addEntriesFromDictionary:@{
|
||||
@".aar" : extractAppleArchive,
|
||||
@".yaa" : extractAppleArchive,
|
||||
}];
|
||||
}
|
||||
|
||||
NSString *lastPathComponent = [path lastPathComponent];
|
||||
for (NSString *currentType in extractCommandDictionary)
|
||||
{
|
||||
if ([lastPathComponent hasSuffix:currentType]) {
|
||||
NSArray<NSString *> *commandAndArguments = [extractCommandDictionary objectForKey:currentType];
|
||||
if (outCommand != NULL) {
|
||||
*outCommand = commandAndArguments.firstObject;
|
||||
}
|
||||
|
||||
return [commandAndArguments subarrayWithRange:NSMakeRange(1, commandAndArguments.count - 1)];
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return argumentsConformingToTypeOfPath(path, YES, NULL) != nil;
|
||||
}
|
||||
|
||||
+ (BOOL)mustValidateBeforeExtraction
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_archivePath = [archivePath copy];
|
||||
_extractionDirectory = [extractionDirectory copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)needsVerifyBeforeExtractionKey
|
||||
{
|
||||
return ([_archivePath hasSuffix:@".aar"] || [_archivePath hasSuffix:@".yaa"]);
|
||||
}
|
||||
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock waitForCleanup:(BOOL)__unused waitForCleanup
|
||||
{
|
||||
NSString *command = nil;
|
||||
NSArray<NSString *> *arguments = argumentsConformingToTypeOfPath(_archivePath, YES, &command);
|
||||
assert(arguments != nil);
|
||||
assert(command != nil);
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
@autoreleasepool {
|
||||
SUUnarchiverNotifier *notifier = [[SUUnarchiverNotifier alloc] initWithCompletionBlock:completionBlock progressBlock:progressBlock];
|
||||
NSError *extractError = nil;
|
||||
if ([self extractArchivePipingData:YES command:command arguments:arguments notifier:notifier error:&extractError]) {
|
||||
[notifier notifySuccess];
|
||||
} else {
|
||||
// If we fail due to an IO PIPE write failure for zip files,
|
||||
// we may re-attempt extracting the archive without piping archive data
|
||||
// (and without fine grained progress reporting).
|
||||
// This is to workaround a bug in ditto which causes extraction to fail when piping data for
|
||||
// some types of constructed zip files.
|
||||
// Note this bug is fixed on macOS 15+, so this workaround is not needed there.
|
||||
// https://github.com/sparkle-project/Sparkle/issues/2544
|
||||
BOOL useNonPipingWorkaround;
|
||||
if (@available(macOS 15, *)) {
|
||||
useNonPipingWorkaround = NO;
|
||||
} else {
|
||||
NSError *underlyingError = extractError.userInfo[NSUnderlyingErrorKey];
|
||||
|
||||
useNonPipingWorkaround = [self->_archivePath.pathExtension isEqualToString:@"zip"] && ([extractError.domain isEqualToString:SUSparkleErrorDomain] && extractError.code == SUUnarchivingError && [underlyingError.domain isEqualToString:NSPOSIXErrorDomain] && underlyingError.code == EPIPE);
|
||||
}
|
||||
|
||||
if (!useNonPipingWorkaround) {
|
||||
[notifier notifyFailureWithError:extractError];
|
||||
} else {
|
||||
// Re-create the extraction directory, then try extracting without piping
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
|
||||
NSURL *extractionDirectoryURL = [NSURL fileURLWithPath:self->_extractionDirectory isDirectory:YES];
|
||||
|
||||
NSError *removeError = nil;
|
||||
if (![fileManager removeItemAtURL:extractionDirectoryURL error:&removeError]) {
|
||||
SULog(SULogLevelError, @"Failed to remove extraction directory path for non-piping workaround with error: %@", removeError);
|
||||
|
||||
[notifier notifyFailureWithError:extractError];
|
||||
} else {
|
||||
NSError *createError = nil;
|
||||
if (![fileManager createDirectoryAtPath:self->_extractionDirectory withIntermediateDirectories:NO attributes:nil error:&createError]) {
|
||||
SULog(SULogLevelError, @"Failed to create new extraction directory path for non-piping workaround with error: %@", createError);
|
||||
|
||||
[notifier notifyFailureWithError:extractError];
|
||||
} else {
|
||||
// The ditto command will be the same so no need to fetch it again
|
||||
NSArray<NSString *> *nonPipingArguments = argumentsConformingToTypeOfPath(self->_archivePath, NO, NULL);
|
||||
assert(nonPipingArguments != nil);
|
||||
|
||||
NSError *nonPipingExtractError = nil;
|
||||
if ([self extractArchivePipingData:NO command:command arguments:nonPipingArguments notifier:notifier error:&nonPipingExtractError]) {
|
||||
[notifier notifySuccess];
|
||||
} else {
|
||||
[notifier notifyFailureWithError:nonPipingExtractError];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// This method abstracts the types that use a command line tool piping data from stdin.
|
||||
- (BOOL)extractArchivePipingData:(BOOL)pipingData command:(NSString *)command arguments:(NSArray*)args notifier:(SUUnarchiverNotifier *)notifier error:(NSError * __autoreleasing *)outError SPU_OBJC_DIRECT
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
NSString *destination = _extractionDirectory;
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
|
||||
if (pipingData) {
|
||||
SULog(SULogLevelDefault, @"Extracting using '%@' '%@' < '%@' '%@'", command, [args componentsJoinedByString:@"' '"], _archivePath, destination);
|
||||
} else {
|
||||
SULog(SULogLevelDefault, @"Extracting using '%@' '%@' '%@'", command, [args componentsJoinedByString:@"' '"], destination);
|
||||
}
|
||||
|
||||
// Get expected file size for piping the archive
|
||||
NSUInteger expectedLength;
|
||||
if (pipingData) {
|
||||
NSDictionary *attributes = [fileManager attributesOfItemAtPath:_archivePath error:nil];
|
||||
expectedLength = [(NSNumber *)[attributes objectForKey:NSFileSize] unsignedIntegerValue];
|
||||
|
||||
if (expectedLength == 0) {
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, archive '%@' is empty", _archivePath]}];
|
||||
|
||||
if (outError != NULL) {
|
||||
*outError = error;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
expectedLength = 0;
|
||||
}
|
||||
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
|
||||
NSPipe *pipe;
|
||||
if (pipingData) {
|
||||
pipe = [NSPipe pipe];
|
||||
[task setStandardInput:pipe];
|
||||
} else {
|
||||
pipe = nil;
|
||||
}
|
||||
|
||||
[task setStandardError:[NSFileHandle fileHandleWithStandardError]];
|
||||
[task setStandardOutput:[NSFileHandle fileHandleWithStandardOutput]];
|
||||
[task setLaunchPath:command];
|
||||
[task setArguments:[args arrayByAddingObject:destination]];
|
||||
|
||||
NSError *launchError = nil;
|
||||
if (![task launchAndReturnError:&launchError]) {
|
||||
if (outError != NULL) {
|
||||
*outError = launchError;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSError *underlyingOutError = nil;
|
||||
NSUInteger bytesWritten = 0;
|
||||
|
||||
if (pipingData) {
|
||||
NSFileHandle *archiveInput = [NSFileHandle fileHandleForReadingAtPath:_archivePath];
|
||||
|
||||
NSFileHandle *archiveOutput = [pipe fileHandleForWriting];
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
BOOL hasIOErrorMethods;
|
||||
if (@available(macOS 10.15, *)) {
|
||||
hasIOErrorMethods = YES;
|
||||
} else {
|
||||
hasIOErrorMethods = NO;
|
||||
}
|
||||
#endif
|
||||
|
||||
do {
|
||||
NSData *data;
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
if (!hasIOErrorMethods) {
|
||||
@try {
|
||||
data = [archiveInput readDataOfLength:256*1024];
|
||||
} @catch (NSException *exception) {
|
||||
SULog(SULogLevelError, @"Failed to read data from archive with exception reason %@", exception.reason);
|
||||
data = nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
NSError *readError = nil;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wpartial-availability"
|
||||
data = [archiveInput readDataUpToLength:256*1024 error:&readError];
|
||||
#pragma clang diagnostic pop
|
||||
if (data == nil) {
|
||||
SULog(SULogLevelError, @"Failed to read data from archive with error %@", readError);
|
||||
underlyingOutError = readError;
|
||||
}
|
||||
}
|
||||
|
||||
NSUInteger len = [data length];
|
||||
if (len == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
NSError *writeError = nil;
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
if (!hasIOErrorMethods) {
|
||||
@try {
|
||||
[archiveOutput writeData:data];
|
||||
} @catch (NSException *exception) {
|
||||
SULog(SULogLevelError, @"Failed to write data to pipe with exception reason %@", exception.reason);
|
||||
|
||||
if ([exception.name isEqualToString:NSFileHandleOperationException]) {
|
||||
NSError *underlyingFileHandleError = exception.userInfo[@"NSFileHandleOperationExceptionUnderlyingError"];
|
||||
NSError *underlyingPOSIXError = underlyingFileHandleError.userInfo[NSUnderlyingErrorKey];
|
||||
|
||||
underlyingOutError = underlyingPOSIXError;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wpartial-availability"
|
||||
if (![archiveOutput writeData:data error:&writeError]) {
|
||||
#pragma clang diagnostic pop
|
||||
SULog(SULogLevelError, @"Failed to write data to pipe with error %@", writeError);
|
||||
|
||||
NSError *underlyingPOSIXError = writeError.userInfo[NSUnderlyingErrorKey];
|
||||
|
||||
underlyingOutError = underlyingPOSIXError;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bytesWritten += len;
|
||||
|
||||
[notifier notifyProgress:(double)bytesWritten / (double)expectedLength];
|
||||
}
|
||||
while(bytesWritten < expectedLength);
|
||||
|
||||
if (@available(macOS 10.15, *)) {
|
||||
NSError *archiveOutputCloseError = nil;
|
||||
if (![archiveOutput closeAndReturnError:&archiveOutputCloseError]) {
|
||||
SULog(SULogLevelError, @"Failed to close pipe with error %@", archiveOutputCloseError);
|
||||
}
|
||||
}
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
else
|
||||
{
|
||||
[archiveOutput closeFile];
|
||||
}
|
||||
#endif
|
||||
|
||||
if (@available(macOS 10.15, *)) {
|
||||
NSError *archiveInputCloseError = nil;
|
||||
if (![archiveInput closeAndReturnError:&archiveInputCloseError]) {
|
||||
SULog(SULogLevelError, @"Failed to close archive input with error %@", archiveInputCloseError);
|
||||
}
|
||||
}
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
else
|
||||
{
|
||||
[archiveInput closeFile];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[task waitUntilExit];
|
||||
|
||||
if ([task terminationStatus] != 0) {
|
||||
NSMutableDictionary *userInfo = [@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, command '%@' returned %d", command, [task terminationStatus]]} mutableCopy];
|
||||
|
||||
if (underlyingOutError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = underlyingOutError;
|
||||
}
|
||||
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:[userInfo copy]];
|
||||
|
||||
if (outError != NULL) {
|
||||
*outError = error;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (!pipingData) {
|
||||
[notifier notifyProgress:1.0];
|
||||
} else if (bytesWritten != expectedLength) {
|
||||
// Don't set underlying error in this case
|
||||
// This may fail due to a write PIPE error but we don't currently support extracting archives that have
|
||||
// extraneous data leftover because these may be corrupt.
|
||||
// We don't want to later workaround extraction by not piping the data.
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, command '%@' got only %ld of %ld bytes", command, (long)bytesWritten, (long)expectedLength]}];
|
||||
|
||||
if (outError != NULL) {
|
||||
*outError = error;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], _archivePath]; }
|
||||
|
||||
@end
|
||||
@@ -1,24 +0,0 @@
|
||||
//
|
||||
// SUPlainInstaller.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerProtocol.h"
|
||||
|
||||
@class SUHost;
|
||||
@protocol SUVersionComparison;
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUPlainInstaller : NSObject <SUInstallerProtocol>
|
||||
|
||||
/**
|
||||
@param host The current (old) bundle host
|
||||
@param bundlePath The path to the new bundle that will be installed.
|
||||
@param installationPath The path the new bundlePath will be installed to.
|
||||
*/
|
||||
- (instancetype)initWithHost:(SUHost *)host bundlePath:(NSString *)bundlePath installationPath:(NSString *)installationPath;
|
||||
|
||||
@end
|
||||
@@ -1,409 +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"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUPlainInstaller
|
||||
{
|
||||
SUHost *_host;
|
||||
NSString *_bundlePath;
|
||||
NSString *_installationPath;
|
||||
NSURL *_temporaryOldDirectory;
|
||||
// We get an obj-c warning if we use 'newTemporaryDirectory' name about new + ownership stuff, so use 'temporaryNewDirectory' instead
|
||||
NSURL *_temporaryNewDirectory;
|
||||
|
||||
BOOL _newAndOldBundlesOnSameVolume;
|
||||
BOOL _canPerformSafeAtomicSwap;
|
||||
}
|
||||
|
||||
- (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;
|
||||
}
|
||||
|
||||
- (void)_performInitialInstallationWithFileManager:(SUFileManager *)fileManager oldBundleURL:(NSURL *)oldBundleURL newBundleURL:(NSURL *)newBundleURL performGatekeeperScan:(BOOL)performGatekeeperScan progressBlock:(nullable void(^)(double))progress SPU_OBJC_DIRECT
|
||||
{
|
||||
// Release our new app from quarantine
|
||||
NSError *quarantineError = nil;
|
||||
if (![fileManager releaseItemFromQuarantineAtRootURL:newBundleURL error:&quarantineError]) {
|
||||
// Not big enough of a deal to fail the entire installation
|
||||
SULog(SULogLevelError, @"Failed to release quarantine at %@ with error %@", newBundleURL.path, quarantineError);
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(5/11.0);
|
||||
}
|
||||
|
||||
// Try to preserve Finder Tags
|
||||
NSArray *resourceTags = nil;
|
||||
BOOL retrievedResourceTags = [oldBundleURL getResourceValue:&resourceTags forKey:NSURLTagNamesKey error:NULL];
|
||||
if (retrievedResourceTags && resourceTags.count > 0) {
|
||||
[newBundleURL setResourceValue:resourceTags forKey:NSURLTagNamesKey error:NULL];
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(6/11.0);
|
||||
}
|
||||
|
||||
// Update owner and group (if possible)
|
||||
NSError *changeOwnerAndGroupError = nil;
|
||||
if (![fileManager changeOwnerAndGroupOfItemAtRootURL:newBundleURL toMatchURL:oldBundleURL error:&changeOwnerAndGroupError]) {
|
||||
// Not a fatal error
|
||||
SULog(SULogLevelError, @"Failed to change owner and group of new app at %@ to match old app at %@", newBundleURL.path, oldBundleURL.path);
|
||||
SULog(SULogLevelError, @"Error: %@", changeOwnerAndGroupError);
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(7/11.0);
|
||||
}
|
||||
|
||||
// Register the new bundle with LaunchServices and the system
|
||||
NSError *touchError = nil;
|
||||
if (![fileManager updateModificationAndAccessTimeOfItemAtURL:newBundleURL error:&touchError]) {
|
||||
// Not a fatal error, but a pretty unfortunate one
|
||||
SULog(SULogLevelError, @"Failed to update modification and access time of new app at %@", newBundleURL.path);
|
||||
SULog(SULogLevelError, @"Error: %@", touchError);
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(8/11.0);
|
||||
}
|
||||
|
||||
if (performGatekeeperScan) {
|
||||
// Perform a Gatekeeper scan to pre-warm the app launch
|
||||
// This avoids users seeing a "Verifying..." dialog when the installed update is launched
|
||||
// Note the tool we use to perform the Gatekeeper scan (gktool) is technically available on macOS 14.0,
|
||||
// however there are some potential bugs/issues with performing a Gatekeeper scan on versions before 14.4:
|
||||
// https://github.com/sparkle-project/Sparkle/issues/2491
|
||||
if (@available(macOS 14.4, *)) {
|
||||
// Only perform Gatekeeper scan if we're updating an app bundle
|
||||
NSString *newBundlePath = newBundleURL.path;
|
||||
if ([newBundlePath.pathExtension caseInsensitiveCompare:@"app"] == NSOrderedSame) {
|
||||
NSURL *gktoolURL = [NSURL fileURLWithPath:@"/usr/bin/gktool" isDirectory:NO];
|
||||
if ([gktoolURL checkResourceIsReachableAndReturnError:NULL]) {
|
||||
NSTask *gatekeeperScanTask = [[NSTask alloc] init];
|
||||
gatekeeperScanTask.executableURL = gktoolURL;
|
||||
gatekeeperScanTask.arguments = @[@"scan", newBundlePath];
|
||||
|
||||
NSError *taskError;
|
||||
if (![gatekeeperScanTask launchAndReturnError:&taskError]) {
|
||||
// Not a fatal error
|
||||
SULog(SULogLevelError, @"Failed to perform GateKeeper scan on '%@' with error %@", newBundlePath, taskError);
|
||||
} else {
|
||||
[gatekeeperScanTask waitUntilExit];
|
||||
|
||||
if (gatekeeperScanTask.terminationStatus != 0) {
|
||||
SULog(SULogLevelError, @"gktool failed and returned exit status %d", gatekeeperScanTask.terminationStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)startInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL *)newURL withHost:(SUHost *)host progressBlock:(nullable void(^)(double))progress error:(NSError * __autoreleasing *)error SPU_OBJC_DIRECT
|
||||
{
|
||||
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/11.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 (!_newAndOldBundlesOnSameVolume) {
|
||||
NSError *accessTimeError = nil;
|
||||
if (![fileManager updateAccessTimeOfItemAtRootURL:newURL error:&accessTimeError]) {
|
||||
if (error != NULL) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey: @"Failed to recursively update new application's modification time before moving into temporary directory" }];
|
||||
|
||||
if (accessTimeError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = accessTimeError;
|
||||
}
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:userInfo];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(2/11.0);
|
||||
}
|
||||
|
||||
NSURL *tempNewDirectoryURL;
|
||||
if (!_newAndOldBundlesOnSameVolume) {
|
||||
// Create a temporary directory for our new app that resides on our destination's volume
|
||||
// We use oldURL here instead of installationURL because in the case of normalization, installationURL may not exist
|
||||
// And we don't want to use either of the URL's parent directories because the parent directory could be on a different volume
|
||||
tempNewDirectoryURL = [fileManager makeTemporaryDirectoryAppropriateForDirectoryURL:oldURL error:error];
|
||||
if (tempNewDirectoryURL == nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
_temporaryNewDirectory = tempNewDirectoryURL;
|
||||
} else {
|
||||
tempNewDirectoryURL = nil;
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(3/11.0);
|
||||
}
|
||||
|
||||
// Move the new app to our temporary directory if needed
|
||||
NSURL *newFinalURL;
|
||||
if (!_newAndOldBundlesOnSameVolume) {
|
||||
NSString *newURLLastPathComponent = newURL.lastPathComponent;
|
||||
newFinalURL = [tempNewDirectoryURL URLByAppendingPathComponent:newURLLastPathComponent];
|
||||
NSError *newTempMoveError = nil;
|
||||
if (![fileManager moveItemAtURL:newURL toURL:newFinalURL error:&newTempMoveError]) {
|
||||
if (error != NULL) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to move the new app from %@ to its temp directory at %@", newURL.path, newFinalURL.path] }];
|
||||
|
||||
if (newTempMoveError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = newTempMoveError;
|
||||
}
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:userInfo];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
newFinalURL = newURL;
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(4/11.0);
|
||||
}
|
||||
|
||||
if (!_newAndOldBundlesOnSameVolume) {
|
||||
// If we're updating a bundle on another volume, the install process can be pretty slow.
|
||||
// In this case let's get out of the way and skip the Gatekeeper scan
|
||||
[self _performInitialInstallationWithFileManager:fileManager oldBundleURL:oldURL newBundleURL:newFinalURL performGatekeeperScan:NO progressBlock:progress];
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(9/11.0);
|
||||
}
|
||||
|
||||
// First try swapping the application atomically
|
||||
NSError *swapError = nil;
|
||||
BOOL swappedApp;
|
||||
// If we can not safely perform an atomic swap, or if the app is normalized and the installation path differs, go through the old swap path
|
||||
if (!_canPerformSafeAtomicSwap || (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME && ![oldURL.path isEqual:installationURL.path])) {
|
||||
swappedApp = NO;
|
||||
} else {
|
||||
// We will be cleaning up the temporary directory later in -performCleanup:
|
||||
// We don't want to clean it up now because it can take some time
|
||||
swappedApp = [fileManager swapItemAtURL:installationURL withItemAtURL:newFinalURL error:&swapError];
|
||||
}
|
||||
|
||||
if (!swappedApp) {
|
||||
// Otherwise swap out the old and new applications using the legacy path
|
||||
|
||||
if (swapError != nil) {
|
||||
SULog(SULogLevelDefault, @"Invoking fallback from failing to replace original item with error: %@", swapError);
|
||||
}
|
||||
|
||||
// Create a temporary directory for our old app that resides on its volume
|
||||
NSURL *tempOldDirectoryURL = [fileManager makeTemporaryDirectoryAppropriateForDirectoryURL:oldURL error:error];
|
||||
if (tempOldDirectoryURL == nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
_temporaryOldDirectory = tempOldDirectoryURL;
|
||||
|
||||
if (progress) {
|
||||
progress(10/11.0);
|
||||
}
|
||||
|
||||
NSString *oldURLFilename = oldURL.lastPathComponent;
|
||||
if (oldURLFilename == nil) {
|
||||
// this really shouldn't happen..
|
||||
SULog(SULogLevelError, @"Failed to retrieve last path component from old URL: %@", oldURL.path);
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to perform installation because the last path component of the old installation URL could not be constructed." }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Move the old app to the temporary directory
|
||||
NSURL *oldTempURL = [tempOldDirectoryURL URLByAppendingPathComponent:oldURLFilename];
|
||||
NSError *oldMoveError = nil;
|
||||
if (![fileManager moveItemAtURL:oldURL toURL:oldTempURL error:&oldMoveError]) {
|
||||
if (error != NULL) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to move the old app at %@ to a temporary location at %@", oldURL.path, oldTempURL.path] }];
|
||||
|
||||
if (oldMoveError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = oldMoveError;
|
||||
}
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:userInfo];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
progress(10.5/11.0);
|
||||
}
|
||||
|
||||
// Move the new app to its final destination
|
||||
NSError *installMoveError = nil;
|
||||
if (![fileManager moveItemAtURL:newFinalURL toURL:installationURL error:&installMoveError]) {
|
||||
if (error != NULL) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to move new app at %@ to final destination %@", newFinalURL.path, installationURL.path] }];
|
||||
|
||||
if (installMoveError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = installMoveError;
|
||||
}
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:userInfo];
|
||||
}
|
||||
|
||||
// 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(11/11.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 = [_host version];
|
||||
|
||||
NSBundle *bundle = [NSBundle bundleWithPath:_bundlePath];
|
||||
SUHost *updateHost = [[SUHost alloc] initWithBundle:bundle];
|
||||
NSString *updateVersion = [updateHost objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey ofClass:NSString.class];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
|
||||
BOOL updateHasCustomUpdateSecurityPolicy = NO;
|
||||
if (@available(macOS 13.0, *)) {
|
||||
// If the new update is notarized / developer ID code signed and Autoupdate is not signed with the same Team ID as the new update,
|
||||
// then we may run into Privacy & Security prompt issues from the OS
|
||||
// which think we are modifying the update (but we're not)
|
||||
// To avoid these, we skip the gatekeeper scan and skip performing an atomic swap during install
|
||||
// If the update has a custom update security policy, the same team ID policy may not apply,
|
||||
// so in that case we will also skip performing an atomic swap
|
||||
|
||||
updateHasCustomUpdateSecurityPolicy = updateHost.hasUpdateSecurityPolicy;
|
||||
if (updateHasCustomUpdateSecurityPolicy) {
|
||||
// We don't handle working around a custom update security policy
|
||||
_canPerformSafeAtomicSwap = NO;
|
||||
} else {
|
||||
NSString *installerTeamIdentifier = [SUCodeSigningVerifier teamIdentifierFromMainExecutable];
|
||||
NSString *bundleTeamIdentifier = [SUCodeSigningVerifier teamIdentifierAtURL:bundle.bundleURL];
|
||||
|
||||
// If bundleTeamIdentifier is nil, then the update isn't code signed so atomic swap is okay
|
||||
_canPerformSafeAtomicSwap = (bundleTeamIdentifier == nil || (installerTeamIdentifier != nil && [installerTeamIdentifier isEqualToString:bundleTeamIdentifier]));
|
||||
}
|
||||
} else {
|
||||
_canPerformSafeAtomicSwap = YES;
|
||||
}
|
||||
|
||||
if (!_canPerformSafeAtomicSwap) {
|
||||
if (updateHasCustomUpdateSecurityPolicy) {
|
||||
SULog(SULogLevelDefault, @"Skipping atomic rename/swap and gatekeeper scan because new update %@ has a custom NSUpdateSecurityPolicy", bundle.bundleURL.lastPathComponent);
|
||||
} else {
|
||||
SULog(SULogLevelDefault, @"Skipping atomic rename/swap and gatekeeper scan because Autoupdate is not signed with same identity as the new update %@", bundle.bundleURL.lastPathComponent);
|
||||
}
|
||||
}
|
||||
|
||||
_newAndOldBundlesOnSameVolume = [fileManager itemAtURL:bundle.bundleURL isOnSameVolumeItemAsURL:_host.bundle.bundleURL];
|
||||
|
||||
// We can do a lot of the installation work ahead of time if the new app update does not need to be copied to another volume
|
||||
if (_newAndOldBundlesOnSameVolume) {
|
||||
[self _performInitialInstallationWithFileManager:fileManager oldBundleURL:_host.bundle.bundleURL newBundleURL:bundle.bundleURL performGatekeeperScan:_canPerformSafeAtomicSwap progressBlock:NULL];
|
||||
}
|
||||
|
||||
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:_installationPath] fromUpdateAtURL:[NSURL fileURLWithPath:_bundlePath] withHost:_host progressBlock:cb error:error];
|
||||
}
|
||||
|
||||
- (void)performCleanup
|
||||
{
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
|
||||
if (_temporaryNewDirectory != nil) {
|
||||
[fileManager removeItemAtURL:_temporaryNewDirectory error:NULL];
|
||||
}
|
||||
|
||||
if (_temporaryOldDirectory != nil) {
|
||||
[fileManager removeItemAtURL:_temporaryOldDirectory error:NULL];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,50 +0,0 @@
|
||||
//
|
||||
// SUSignatureVerifier.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
// Includes code by Zach Waldowski on 10/18/13.
|
||||
// Copyright 2014 Big Nerd Ranch. Licensed under MIT.
|
||||
//
|
||||
// Includes code from Plop by Mark Hamlin.
|
||||
// Copyright 2011 Mark Hamlin. Licensed under BSD.
|
||||
//
|
||||
|
||||
#ifndef SUDSAVERIFIER_H
|
||||
#define SUDSAVERIFIER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
@class SUSignatures;
|
||||
@class SUPublicKeys;
|
||||
@class SPUVerifierInformation;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#ifndef BUILDING_SPARKLE_TESTS
|
||||
#define SUSignatureVerifierDefinitionAttribute SPU_OBJC_DIRECT_MEMBERS
|
||||
#else
|
||||
#define SUSignatureVerifierDefinitionAttribute __attribute__((objc_runtime_name("SUTestSignatureVerifier")))
|
||||
#endif
|
||||
|
||||
SUSignatureVerifierDefinitionAttribute @interface SUSignatureVerifier : NSObject
|
||||
|
||||
// Helper for verifying downloaded updates
|
||||
+ (BOOL)validatePath:(NSString *)path withSignatures:(SUSignatures *)signatures withPublicKeys:(SUPublicKeys *)pkeys verifierInformation:(SPUVerifierInformation * _Nullable)verifierInformation error:(NSError * __autoreleasing *)error;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
- (instancetype)initWithPublicKeys:(SUPublicKeys *)pkeys;
|
||||
|
||||
// Used for verifying downloaded updates
|
||||
- (BOOL)verifyFileAtPath:(NSString *)path signatures:(SUSignatures *)signatures verifierInformation:(SPUVerifierInformation * _Nullable)verifierInformation error:(NSError * __autoreleasing *)error;
|
||||
|
||||
// Used for verifying non-update data (like release notes)
|
||||
- (BOOL)verifyData:(NSData *)data signatures:(SUSignatures *)signatures fileKind:(NSString *)fileKind verifierInformation:(SPUVerifierInformation * _Nullable)verifierInformation error:(NSError * __autoreleasing *)error;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -1,426 +0,0 @@
|
||||
//
|
||||
// SUDSAVerifier.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
// Includes code by Zach Waldowski on 10/18/13.
|
||||
// Copyright 2014 Big Nerd Ranch. Licensed under MIT.
|
||||
//
|
||||
// Includes code from Plop by Mark Hamlin.
|
||||
// Copyright 2011 Mark Hamlin. Licensed under BSD.
|
||||
//
|
||||
|
||||
#import "SUSignatureVerifier.h"
|
||||
#import "SULog.h"
|
||||
#import "SUSignatures.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SPUVerifierInformation.h"
|
||||
#import "SUConstants.h"
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#endif
|
||||
#import "ed25519.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUSignatureVerifier
|
||||
{
|
||||
SUPublicKeys *_pubKeys;
|
||||
}
|
||||
|
||||
+ (BOOL)validatePath:(NSString *)path withSignatures:(SUSignatures *)signatures withPublicKeys:(SUPublicKeys *)pkeys verifierInformation:(SPUVerifierInformation * _Nullable)verifierInformation error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
SUSignatureVerifier *verifier = [(SUSignatureVerifier *)[self alloc] initWithPublicKeys:pkeys];
|
||||
return [verifier verifyFileAtPath:path signatures:signatures verifierInformation:verifierInformation error:error];
|
||||
}
|
||||
|
||||
- (instancetype)initWithPublicKeys:(SUPublicKeys *)pubkeys
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_pubKeys = pubkeys;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
- (SecKeyRef)dsaSecKeyRef SPU_OBJC_DIRECT
|
||||
{
|
||||
NSData *data = [_pubKeys.dsaPubKey dataUsingEncoding:NSASCIIStringEncoding];
|
||||
if (!self || !data.length) {
|
||||
SULog(SULogLevelError, @"Could not read public DSA key");
|
||||
return nil;
|
||||
}
|
||||
|
||||
SecExternalFormat format = kSecFormatOpenSSL;
|
||||
SecExternalItemType itemType = kSecItemTypePublicKey;
|
||||
CFArrayRef items = NULL;
|
||||
|
||||
OSStatus status = SecItemImport((__bridge CFDataRef)data, NULL, &format, &itemType, (SecItemImportExportFlags)0, NULL, NULL, &items);
|
||||
if (status != errSecSuccess || !items) {
|
||||
if (items) {
|
||||
CFRelease(items);
|
||||
}
|
||||
SULog(SULogLevelError, @"Public DSA key could not be imported: %d", status);
|
||||
return nil;
|
||||
}
|
||||
|
||||
SecKeyRef dsaPubKeySecKey = nil;
|
||||
if (format == kSecFormatOpenSSL && itemType == kSecItemTypePublicKey && CFArrayGetCount(items) == 1) {
|
||||
// Seems silly, but we can't quiet the warning about dropping CFTypeRef's const qualifier through
|
||||
// any manner of casting I've tried, including interim explicit cast to void*. The -Wcast-qual
|
||||
// warning is on by default with -Weverything and apparently became more noisy as of Xcode 7.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcast-qual"
|
||||
dsaPubKeySecKey = (SecKeyRef)CFRetain(CFArrayGetValueAtIndex(items, 0));
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
CFRelease(items);
|
||||
return dsaPubKeySecKey;
|
||||
}
|
||||
#endif
|
||||
|
||||
- (BOOL)verifyFileAtPath:(NSString *)path signatures:(SUSignatures *)signatures verifierInformation:(SPUVerifierInformation * _Nullable)verifierInformation error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
// Data is used only in the case where ed25519 signature is present
|
||||
NSData *data;
|
||||
if (signatures.ed25519SignatureStatus != SUSigningInputStatusPresent) {
|
||||
data = nil;
|
||||
} else {
|
||||
NSError *dataError = nil;
|
||||
data = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:&dataError];
|
||||
|
||||
if (data == nil || data.length == 0) {
|
||||
SULog(SULogLevelError, @"Failed to load file %@: %@", path, dataError);
|
||||
|
||||
if (error != NULL) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
||||
userInfo[NSLocalizedDescriptionKey] = [NSString stringWithFormat:@"Failed to load file: %@", path];
|
||||
if (dataError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = dataError;
|
||||
}
|
||||
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:[userInfo copy]];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return [self verifyData:data signatures:signatures fileKind:@"update" fromPath:path verifierInformation:verifierInformation error:error];
|
||||
}
|
||||
|
||||
- (BOOL)verifyData:(NSData *)data signatures:(SUSignatures *)signatures fileKind:(NSString *)fileKind verifierInformation:(SPUVerifierInformation * _Nullable)verifierInformation error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
return [self verifyData:data signatures:signatures fileKind:fileKind fromPath:nil verifierInformation:verifierInformation error:error];
|
||||
}
|
||||
|
||||
// Note the path must be provided for verifying update archives
|
||||
- (BOOL)verifyData:(NSData * _Nullable)data signatures:(SUSignatures *)signatures fileKind:(NSString *)fileKind fromPath:(NSString * _Nullable)path verifierInformation:(SPUVerifierInformation * _Nullable)verifierInformation error:(NSError * __autoreleasing *)error SPU_OBJC_DIRECT
|
||||
{
|
||||
if (!signatures) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"No signatures given to verify data for %@", fileKind] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
switch (_pubKeys.ed25519PubKeyStatus) {
|
||||
case SUSigningInputStatusAbsent:
|
||||
if (signatures.ed25519SignatureStatus != SUSigningInputStatusAbsent) {
|
||||
SULog(SULogLevelDefault, @"The %@ has an EdDSA signature, but it won't be used, because the old app doesn't have an EdDSA public key", fileKind);
|
||||
}
|
||||
break;
|
||||
case SUSigningInputStatusInvalid:
|
||||
if (signatures.ed25519SignatureStatus != SUSigningInputStatusAbsent) {
|
||||
NSString *message = [NSString stringWithFormat:@"The %@ has an EdDSA signature, but the app has an invalid EdDSA public key, so the %@ will automatically be rejected.", fileKind, fileKind];
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
SULog(SULogLevelDefault, @"The app has an invalid EdDSA public key, but there is no EdDSA signature in the %@. Falling back to DSA.", fileKind);
|
||||
break;
|
||||
case SUSigningInputStatusPresent:
|
||||
switch (signatures.ed25519SignatureStatus) {
|
||||
case SUSigningInputStatusAbsent: {
|
||||
NSString *message = [NSString stringWithFormat:@"The app has an EdDSA public key, but there is no EdDSA signature in the %@, so the %@ will be rejected.", fileKind, fileKind];
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
case SUSigningInputStatusInvalid: {
|
||||
NSString *message = [NSString stringWithFormat:@"The %@ has an EdDSA signature, but it's invalid, so the %@ will automatically be rejected.", fileKind, fileKind];
|
||||
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
case SUSigningInputStatusPresent: {
|
||||
assert(data != nil);
|
||||
if (ed25519_verify(signatures.ed25519Signature, (const unsigned char *)data.bytes, data.length, _pubKeys.ed25519PubKey)) {
|
||||
SULog(SULogLevelDefault, @"OK: EdDSA signature is correct for %@", fileKind);
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
// No need to check DSA when EdDSA verification succeeded, unless a DSA signature is provided and it's
|
||||
// erroneously invalid
|
||||
if (signatures.dsaSignatureStatus != SUSigningInputStatusInvalid)
|
||||
#endif
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
} else {
|
||||
NSMutableString *message = [NSMutableString stringWithFormat:@"EdDSA signature does not match. Data of the %@ being checked is different than data that has been signed, or the public key and the private key are not from the same set.", fileKind];
|
||||
|
||||
// Elaborate on the error message if we have more information about the download archive
|
||||
// If there is verifierInformation it must be for a downloaded update (rather than feed or release notes)
|
||||
if (verifierInformation != nil) {
|
||||
BOOL reportedDiscrepancy = NO;
|
||||
|
||||
NSString *downloadedFileDescription = (path != nil) ? [NSString stringWithFormat:@"%@ (%@)", fileKind, path.lastPathComponent] : fileKind;
|
||||
|
||||
if (verifierInformation.expectedContentLength > 0 && verifierInformation.actualContentLength > 0) {
|
||||
if (verifierInformation.expectedContentLength != verifierInformation.actualContentLength) {
|
||||
[message appendFormat:@" The downloaded %@ is likely different than the signed file because the expected content length from the appcast item (%llu bytes) differs from the downloaded file length (%llu bytes).", downloadedFileDescription, verifierInformation.expectedContentLength, verifierInformation.actualContentLength];
|
||||
reportedDiscrepancy = YES;
|
||||
}
|
||||
}
|
||||
|
||||
NSString *actualVersion = verifierInformation.actualVersion;
|
||||
if (actualVersion != nil && ![verifierInformation.expectedVersion isEqualToString:actualVersion]) {
|
||||
[message appendFormat:@" The downloaded %@ also has a CFBundleVersion (%@) which differs from the %@ in the appcast item (%@).", downloadedFileDescription, actualVersion, SUAppcastAttributeVersion, verifierInformation.expectedVersion];
|
||||
reportedDiscrepancy = YES;
|
||||
}
|
||||
|
||||
if (!reportedDiscrepancy && verifierInformation.expectedContentLength > 0) {
|
||||
[message appendFormat:@" The downloaded %@ is likely not signed correctly because the file has the expected content length (%llu bytes)%@ which matches the appcast item.", downloadedFileDescription, verifierInformation.actualContentLength, (actualVersion == nil ? @"" : [NSString stringWithFormat:@" and CFBundleVersion (%@)", actualVersion])];
|
||||
}
|
||||
}
|
||||
|
||||
SULog(SULogLevelError, @"%@", [message copy]);
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
// Legacy DSA verification is only applicable if archive file path is provided
|
||||
if (signatures.dsaSignatureStatus != SUSigningInputStatusAbsent && path != nil) {
|
||||
SULog(SULogLevelDefault, @"DSA signature won't be checked, because EdDSA verification has already failed");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
// Legacy DSA verification is only for downloaded updates
|
||||
switch (_pubKeys.dsaPubKeyStatus) {
|
||||
case SUSigningInputStatusAbsent:
|
||||
if (signatures.dsaSignatureStatus != SUSigningInputStatusAbsent && path != nil) {
|
||||
SULog(SULogLevelDefault, @"The update has a DSA signature, but it can't be used, because the old app doesn't have a DSA public key");
|
||||
}
|
||||
break;
|
||||
case SUSigningInputStatusInvalid:
|
||||
if (signatures.dsaSignatureStatus != SUSigningInputStatusAbsent && path != nil) {
|
||||
// We will have already logged an error for this failure when the public key was read in, so just do an informational log here.
|
||||
NSString *message = @"The update has a DSA signature, but the app has an invalid DSA public key, so the update will automatically be rejected.";
|
||||
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
SULog(SULogLevelDefault, @"The app has an invalid DSA public key, but there is no DSA signature in the update.");
|
||||
break;
|
||||
case SUSigningInputStatusPresent:
|
||||
switch (signatures.dsaSignatureStatus) {
|
||||
case SUSigningInputStatusAbsent:
|
||||
SULog(SULogLevelError, @"There is no DSA signature in the update");
|
||||
break;
|
||||
case SUSigningInputStatusInvalid: {
|
||||
NSString *message = @"The update has a DSA signature, but it's invalid, so the update will automatically be rejected.";
|
||||
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
case SUSigningInputStatusPresent: {
|
||||
NSInputStream *dataInputStream = (path != nil) ? [NSInputStream inputStreamWithFileAtPath:(NSString * _Nonnull)path] : nil;
|
||||
return [self verifyDSASignatureOfStream:dataInputStream dsaSignature:signatures.dsaSignature error:error];
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
switch (_pubKeys.dsaPubKeyStatus) {
|
||||
case SUSigningInputStatusAbsent:
|
||||
break;
|
||||
case SUSigningInputStatusInvalid:
|
||||
// We don't keep track of DSA signatures, so we will ignore this mistake and treat it as if it were absent
|
||||
break;
|
||||
case SUSigningInputStatusPresent:
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: @"The old app has a DSA public key but DSA support is disabled, and the old app does not have an EdDSA public key." }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (error != NULL) {
|
||||
// Use generic failure
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"EdDSA and DSA verification for the %@ has failed", fileKind] }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
- (BOOL)verifyDSASignatureOfStream:(NSInputStream *)stream dsaSignature:(NSData *)dsaSignature error:(NSError * __autoreleasing *)outError SPU_OBJC_DIRECT
|
||||
{
|
||||
if (!stream || !dsaSignature) {
|
||||
SULog(SULogLevelError, @"Invalid arguments to verifyStream");
|
||||
|
||||
if (outError != NULL) {
|
||||
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: @"Invalid arguments to verifyStream" }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
SecKeyRef dsaPubKeySecKey = [self dsaSecKeyRef];
|
||||
if (!dsaPubKeySecKey) {
|
||||
if (outError != NULL) {
|
||||
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to create DSA Sec Key Ref" }];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Sparkle's DSA support is deprecated
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
__block SecGroupTransformRef group = SecTransformCreateGroupTransform();
|
||||
__block SecTransformRef dataReadTransform = NULL;
|
||||
__block SecTransformRef dataDigestTransform = NULL;
|
||||
__block SecTransformRef dataVerifyTransform = NULL;
|
||||
__block CFErrorRef error = NULL;
|
||||
|
||||
BOOL (^cleanup)(void) = ^{
|
||||
if (group) CFRelease(group);
|
||||
if (dataReadTransform) CFRelease(dataReadTransform);
|
||||
if (dataDigestTransform) CFRelease(dataDigestTransform);
|
||||
if (dataVerifyTransform) CFRelease(dataVerifyTransform);
|
||||
if (error) CFRelease(error);
|
||||
if (dsaPubKeySecKey) CFRelease(dsaPubKeySecKey);
|
||||
return NO;
|
||||
};
|
||||
|
||||
dataReadTransform = SecTransformCreateReadTransformWithReadStream((__bridge CFReadStreamRef)stream);
|
||||
if (!dataReadTransform) {
|
||||
if (outError != NULL) {
|
||||
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: @"File containing update archive could not be read (failed to create SecTransform for input stream)" }];
|
||||
}
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA1, CC_SHA1_DIGEST_LENGTH, NULL);
|
||||
if (!dataDigestTransform) {
|
||||
if (outError != NULL) {
|
||||
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: @"File containing update archive could not be read (failed to create SecDigest for input stream)" }];
|
||||
}
|
||||
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
dataVerifyTransform = SecVerifyTransformCreate(dsaPubKeySecKey, (__bridge CFDataRef)dsaSignature, &error);
|
||||
if (!dataVerifyTransform) {
|
||||
SULog(SULogLevelError, @"Could not understand format of the signature: %@; Signature data: %@", error, dsaSignature);
|
||||
if (outError != NULL) {
|
||||
NSError *underlyingError = (__bridge NSError *)error;
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
||||
userInfo[NSLocalizedDescriptionKey] = [NSString stringWithFormat:@"Could not understand format of the signature data %@", dsaSignature];
|
||||
if (underlyingError != NULL) {
|
||||
userInfo[NSUnderlyingErrorKey] = underlyingError;
|
||||
}
|
||||
|
||||
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:[userInfo copy]];
|
||||
}
|
||||
|
||||
return cleanup();
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
SecTransformConnectTransforms(dataReadTransform, kSecTransformOutputAttributeName, dataDigestTransform, kSecTransformInputAttributeName, group, &error);
|
||||
#pragma clang diagnostic pop
|
||||
if (error) {
|
||||
if (outError != NULL) {
|
||||
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{NSLocalizedDescriptionKey : @"Failed to connect data read transform", NSUnderlyingErrorKey: (__bridge NSError *)error}];
|
||||
}
|
||||
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
SecTransformConnectTransforms(dataDigestTransform, kSecTransformOutputAttributeName, dataVerifyTransform, kSecTransformInputAttributeName, group, &error);
|
||||
#pragma clang diagnostic pop
|
||||
if (error) {
|
||||
if (outError != NULL) {
|
||||
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{NSLocalizedDescriptionKey : @"Failed to connect data digest transform", NSUnderlyingErrorKey: (__bridge NSError *)error}];
|
||||
}
|
||||
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
NSNumber *result = CFBridgingRelease(SecTransformExecute(group, &error));
|
||||
#pragma clang diagnostic pop
|
||||
if (error) {
|
||||
SULog(SULogLevelError, @"DSA signature verification failed: %@", error);
|
||||
if (outError != NULL) {
|
||||
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: @"DSA signature verification failed", NSUnderlyingErrorKey: (__bridge NSError *)error}];
|
||||
}
|
||||
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
if (!result.boolValue) {
|
||||
if (outError != NULL) {
|
||||
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: @"DSA signature does not match. Data of the update file being checked is different than data that has been signed, or the public key and the private key are not from the same set"}];
|
||||
}
|
||||
}
|
||||
|
||||
cleanup();
|
||||
return result.boolValue;
|
||||
}
|
||||
#endif
|
||||
|
||||
@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,21 +0,0 @@
|
||||
//
|
||||
// SUUnarchiver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUUnarchiverProtocol;
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUUnarchiver : NSObject
|
||||
|
||||
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// SUUnarchiver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUUnarchiverProtocol.h"
|
||||
#import "SUPipedUnarchiver.h"
|
||||
#import "SUDiskImageUnarchiver.h"
|
||||
#import "SUBinaryDeltaUnarchiver.h"
|
||||
#import "SUFlatPackageUnarchiver.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUUnarchiver
|
||||
|
||||
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType
|
||||
{
|
||||
if ([SUPipedUnarchiver canUnarchivePath:path]) {
|
||||
return [[SUPipedUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory];
|
||||
}
|
||||
else if ([SUDiskImageUnarchiver canUnarchivePath:path]) {
|
||||
return [[SUDiskImageUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory decryptionPassword:decryptionPassword];
|
||||
}
|
||||
else if ([SUBinaryDeltaUnarchiver canUnarchivePath:path]) {
|
||||
assert(hostPath != nil);
|
||||
NSString *nonNullHostPath = hostPath;
|
||||
return [[SUBinaryDeltaUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory updateHostBundlePath:nonNullHostPath];
|
||||
}
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
else if ([SUFlatPackageUnarchiver canUnarchivePath:path]) {
|
||||
// Flat packages are only supported for guided packaage installs
|
||||
return [[SUFlatPackageUnarchiver alloc] initWithFlatPackagePath:path extractionDirectory:extractionDirectory expectingInstallationType:installationType];
|
||||
}
|
||||
#endif
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,25 +0,0 @@
|
||||
//
|
||||
// SUUnarchiverNotifier.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/21/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUUnarchiverNotifier : NSObject
|
||||
|
||||
- (instancetype)initWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock;
|
||||
|
||||
- (void)notifySuccess;
|
||||
|
||||
- (void)notifyFailureWithError:(NSError * _Nullable)reason;
|
||||
|
||||
- (void)notifyProgress:(double)progress;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,64 +0,0 @@
|
||||
//
|
||||
// SUUnarchiverNotifier.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 12/21/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUnarchiverNotifier.h"
|
||||
#import "SULocalizations.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@implementation SUUnarchiverNotifier
|
||||
{
|
||||
void (^_completionBlock)(NSError * _Nullable);
|
||||
void (^ _Nullable _progressBlock)(double);
|
||||
}
|
||||
|
||||
- (instancetype)initWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_completionBlock = [completionBlock copy];
|
||||
_progressBlock = [progressBlock copy];
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)notifySuccess
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->_completionBlock(nil);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)notifyFailureWithError:(NSError * _Nullable)reason
|
||||
{
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:@"An error occurred while extracting the archive. Please try again later." forKey:NSLocalizedDescriptionKey];
|
||||
if (reason) {
|
||||
[userInfo setObject:(NSError * _Nonnull)reason forKey:NSUnderlyingErrorKey];
|
||||
}
|
||||
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:userInfo];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->_completionBlock(error);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)notifyProgress:(double)progress
|
||||
{
|
||||
if (_progressBlock != nil) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->_progressBlock(progress);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,25 +0,0 @@
|
||||
//
|
||||
// SUUnarchiverProtocol.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/26/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUUnarchiverProtocol <NSObject>
|
||||
|
||||
+ (BOOL)mustValidateBeforeExtraction;
|
||||
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock waitForCleanup:(BOOL)waitForCleanup;
|
||||
|
||||
@property (nonatomic, readonly) BOOL needsVerifyBeforeExtractionKey;
|
||||
|
||||
- (NSString *)description;
|
||||
|
||||
@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
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface StatusInfo : NSObject <SUStatusInfoProtocol>
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)bundleIdentifier;
|
||||
|
||||
@property (nonatomic, nullable) NSData *installationInfoData;
|
||||
|
||||
- (void)startListener;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,105 +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"
|
||||
|
||||
#define REPLY_STATUS_INFO_TIMEOUT 2
|
||||
|
||||
@interface StatusInfo () <NSXPCListenerDelegate>
|
||||
@end
|
||||
|
||||
@implementation StatusInfo
|
||||
{
|
||||
NSXPCListener *_xpcListener;
|
||||
NSMutableDictionary *_pendingReplies;
|
||||
|
||||
NSUInteger _pendingReplyCounter;
|
||||
}
|
||||
|
||||
@synthesize installationInfoData = _installationInfoData;
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)bundleIdentifier
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_xpcListener = [[NSXPCListener alloc] initWithMachServiceName:SPUStatusInfoServiceNameForBundleIdentifier(bundleIdentifier)];
|
||||
_xpcListener.delegate = self;
|
||||
_pendingReplies = [NSMutableDictionary dictionary];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startListener
|
||||
{
|
||||
[_xpcListener resume];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
[_xpcListener invalidate];
|
||||
_xpcListener = nil;
|
||||
}
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
|
||||
{
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUStatusInfoProtocol)];
|
||||
newConnection.exportedObject = self;
|
||||
|
||||
[newConnection resume];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)setInstallationInfoData:(NSData *)installationInfoData
|
||||
{
|
||||
_installationInfoData = installationInfoData;
|
||||
|
||||
// Respond to all of our pending replies
|
||||
for (NSNumber *replyKey in _pendingReplies) {
|
||||
void (^replyBlock)(NSData * _Nullable) = self->_pendingReplies[replyKey];
|
||||
replyBlock(_installationInfoData);
|
||||
}
|
||||
|
||||
[_pendingReplies removeAllObjects];
|
||||
}
|
||||
|
||||
- (void)probeStatusInfoWithReply:(void (^)(NSData * _Nullable))reply
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self->_installationInfoData != nil) {
|
||||
reply(self->_installationInfoData);
|
||||
} else {
|
||||
// If we don't have the installation info data currently, we may receive it in a very short window afterwards
|
||||
// In this case wait a bit for the reply. If we receive the data it will be in -setInstallationInfoData:
|
||||
NSUInteger currentReplyCounter = self->_pendingReplyCounter;
|
||||
self->_pendingReplyCounter++;
|
||||
|
||||
NSNumber *currentReplyCounterKey = @(currentReplyCounter);
|
||||
self->_pendingReplies[currentReplyCounterKey] = [reply copy];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(REPLY_STATUS_INFO_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
void (^replyBlock)(NSData * _Nullable) = self->_pendingReplies[currentReplyCounterKey];
|
||||
if (replyBlock != nil) {
|
||||
replyBlock(self->_installationInfoData);
|
||||
[self->_pendingReplies removeObjectForKey:currentReplyCounterKey];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)probeStatusConnectivityWithReply:(void (^)(void))reply
|
||||
{
|
||||
reply();
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,43 +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);
|
||||
// Ignore SIGPIPE because we won't want read or write failures due to broken pipe to unexpectably
|
||||
// terminate the process (e.g, when extracting archives or performing package installs).
|
||||
signal(SIGPIPE, 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, ^{
|
||||
// Don't clear the update directory because the installer may be in middle of installing an update
|
||||
// We still need to set an event handler for receiving SIGTERM though, otherwise our job may not terminate
|
||||
// (This is also recommended from the developer documentation).
|
||||
// Simply exit with SIGTERM if we receive this signal
|
||||
exit(SIGTERM);
|
||||
});
|
||||
dispatch_resume(sigtermSource);
|
||||
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
//
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import "SUBinaryDeltaCreate.h"
|
||||
#import "SPUDeltaArchive.h"
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
@@ -1,228 +0,0 @@
|
||||
//
|
||||
// main.swift
|
||||
// BinaryDelta
|
||||
//
|
||||
// Created by Mayur Pawashe on 1/3/22.
|
||||
// Copyright © 2022 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ArgumentParser
|
||||
|
||||
// Create a patch from an old and new bundle
|
||||
struct Create: ParsableCommand {
|
||||
@Option(name: .long, help: ArgumentHelp("The major version of the patch to generate. Defaults to the latest stable version. Older versions will need to be specified for updating from applications using older versions of Sparkle.", valueName: "version"))
|
||||
var version: Int = Int(SUBinaryDeltaMajorVersionDefault.rawValue)
|
||||
|
||||
@Flag(name: .customLong("verbose"), help: ArgumentHelp("Enable logging of the changes being archived into the generated patch."))
|
||||
var verbose: Bool = false
|
||||
|
||||
@Option(name: .long, help: ArgumentHelp(COMPRESSION_METHOD_ARGUMENT_DESCRIPTION, valueName: "compression"))
|
||||
var compression: String = "default"
|
||||
|
||||
@Option(name: .long, help: .hidden)
|
||||
var compressionLevel: UInt8 = 0
|
||||
|
||||
@Argument(help: ArgumentHelp("Path to original bundle to create a patch from."))
|
||||
var beforeTree: String
|
||||
|
||||
@Argument(help: ArgumentHelp("Path to new bundle to create a patch from."))
|
||||
var afterTree: String
|
||||
|
||||
@Argument(help: ArgumentHelp("Path to new patch file to create."))
|
||||
var patchFile: String
|
||||
|
||||
func validate() throws {
|
||||
var validCompression: ObjCBool = false
|
||||
let compressionMode = deltaCompressionModeFromDescription(compression, &validCompression)
|
||||
guard validCompression.boolValue else {
|
||||
fputs("Error: unrecognized compression \(compression)\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
switch compressionMode {
|
||||
case SPUDeltaCompressionModeDefault:
|
||||
fallthrough
|
||||
case .none:
|
||||
guard compressionLevel == 0 else {
|
||||
fputs("Error: compression level must be 0 for compression \(compression)\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
break
|
||||
case .bzip2:
|
||||
guard compressionLevel >= 0 && compressionLevel <= 9 else {
|
||||
fputs("Error: compression level \(compressionLevel) is not valid.\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
break
|
||||
case .LZMA:
|
||||
fallthrough
|
||||
case .LZFSE:
|
||||
fallthrough
|
||||
case .LZ4:
|
||||
fallthrough
|
||||
case .ZLIB:
|
||||
guard version >= 3 else {
|
||||
fputs("Error: version \(version) patch files do not support compression \(compression)\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
guard compressionLevel == 0 else {
|
||||
fputs("Error: compression level provided must be 0 for compression \(compression)\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
break
|
||||
@unknown default:
|
||||
fputs("Error: unrecognized compression \(compression)\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
guard version >= SUBinaryDeltaMajorVersionFirst.rawValue else {
|
||||
fputs("Error: version provided \(version) is not valid.\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
guard version >= SUBinaryDeltaMajorVersionFirstSupported.rawValue else {
|
||||
fputs("Error: creating version \(version) patches is no longer supported.\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
guard version <= SUBinaryDeltaMajorVersionLatest.rawValue else {
|
||||
fputs("Error: this program is too old to create a version \(version) patch, or the version number provided is invalid.\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
let fileManager = FileManager.default
|
||||
|
||||
var isDirectory: ObjCBool = false
|
||||
if !fileManager.fileExists(atPath: beforeTree, isDirectory: &isDirectory) || !isDirectory.boolValue {
|
||||
fputs("Error: before-tree must be a directory\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
if !fileManager.fileExists(atPath: afterTree, isDirectory: &isDirectory) || !isDirectory.boolValue {
|
||||
fputs("Error: after-tree must be a directory\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run() throws {
|
||||
let compressionMode = deltaCompressionModeFromDescription(compression, nil)
|
||||
|
||||
guard let majorDeltaVersion = SUBinaryDeltaMajorVersion(rawValue: UInt16(version)) else {
|
||||
// We shouldn't reach here
|
||||
fputs("Error: failed to retrieve major version from provided version: \(version)\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
var createDiffError: NSError? = nil
|
||||
if !createBinaryDelta(beforeTree, afterTree, patchFile, majorDeltaVersion, compressionMode, compressionLevel, verbose, &createDiffError) {
|
||||
if let error = createDiffError {
|
||||
fputs("\(error.localizedDescription)\n", stderr)
|
||||
} else {
|
||||
fputs("Error: Failed to create patch due to unknown reason.\n", stderr)
|
||||
}
|
||||
throw ExitCode(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply a patch from an old bundle to generate a new bundle
|
||||
struct Apply: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(abstract: "Apply a patch against an original bundle to generate a new bundle.")
|
||||
|
||||
@Flag(name: .customLong("verbose"), help: ArgumentHelp("Enable logging of changes being applied from the patch."))
|
||||
var verbose: Bool = false
|
||||
|
||||
@Argument(help: ArgumentHelp("Path to original bundle to patch."))
|
||||
var beforeTree: String
|
||||
|
||||
@Argument(help: ArgumentHelp("Path to new bundle to create."))
|
||||
var afterTree: String
|
||||
|
||||
@Argument(help: ArgumentHelp("Path to patch file to apply."))
|
||||
var patchFile: String
|
||||
|
||||
func validate() throws {
|
||||
let fileManager = FileManager.default
|
||||
|
||||
var isDirectory: ObjCBool = false
|
||||
if !fileManager.fileExists(atPath: beforeTree, isDirectory: &isDirectory) || !isDirectory.boolValue {
|
||||
fputs("Error: before-tree must be a directory\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
if !fileManager.fileExists(atPath: patchFile, isDirectory: &isDirectory) || isDirectory.boolValue {
|
||||
fputs("Error: patch-file must be a file\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run() throws {
|
||||
var applyDiffError: NSError?
|
||||
if (!applyBinaryDelta(beforeTree, afterTree, patchFile, verbose, { _ in }, &applyDiffError)) {
|
||||
if let error = applyDiffError {
|
||||
fputs("\(error.localizedDescription)\n", stderr)
|
||||
} else {
|
||||
fputs("Error: patch failed to apply for unknown reason\n", stderr)
|
||||
}
|
||||
throw ExitCode(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output information for BinaryDelta or from a patch file
|
||||
struct Info: ParsableCommand {
|
||||
@Argument(help: ArgumentHelp("Path to patch file to extract information from."))
|
||||
var patchFile : String?
|
||||
|
||||
func run() throws {
|
||||
if let patchFile = patchFile {
|
||||
// Print version of patch file
|
||||
var header: SPUDeltaArchiveHeader? = nil
|
||||
let archive = SPUDeltaArchiveReadPatchAndHeader(patchFile, &header)
|
||||
if let error = archive.error {
|
||||
fputs("Error: Unable to open patch \(patchFile): \(error.localizedDescription)\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
if let header = header {
|
||||
if header.majorVersion < SUBinaryDeltaMajorVersionFirst.rawValue {
|
||||
fputs("Error: major version \(header.majorVersion) is invalid.\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
|
||||
fputs("Patch version \(header.majorVersion).\(header.minorVersion)", stdout)
|
||||
|
||||
// Print out compression info only if it's available
|
||||
// We can't get compression info from version 2 files
|
||||
if header.compression != SPUDeltaCompressionModeDefault, let compressionDescription = deltaCompressionStringFromMode(header.compression) {
|
||||
fputs(" using \(compressionDescription) compression", stdout)
|
||||
|
||||
// Compression level isn't available or applicable for all formats
|
||||
if header.compressionLevel != 0 {
|
||||
fputs(" with level \(header.compressionLevel)", stdout)
|
||||
}
|
||||
}
|
||||
|
||||
fputs("\n", stdout)
|
||||
} else {
|
||||
fputs("Error: Failed to retrieve header due to unknown reason.\n", stderr)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
} else {
|
||||
// Print version of program
|
||||
fputs("BinaryDelta version \(SUBinaryDeltaMajorVersionLatest.rawValue).\(latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersionLatest))\n", stdout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct BinaryDelta: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(commandName: "BinaryDelta", abstract: "Create and apply small and efficient delta patches between an old and new version of a bundle.", subcommands: [Create.self, Apply.self, Info.self])
|
||||
}
|
||||
|
||||
DispatchQueue.global().async(execute: {
|
||||
BinaryDelta.main()
|
||||
CFRunLoopStop(CFRunLoopGetMain())
|
||||
})
|
||||
CFRunLoopRun()
|
||||
@@ -1,74 +0,0 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at kornel+sparkle@geekhood.net. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
@@ -1 +0,0 @@
|
||||
{"1.27.1": "https://github.com/sparkle-project/Sparkle/releases/download/1.27.1/Sparkle-1.27.1.tar.xz", "2.0.0-beta.6": "https://github.com/sparkle-project/Sparkle/releases/download/2.0.0-beta.6/Sparkle-2.0.0-beta.6.tar.xz", "2.0.0-rc.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.0.0-rc.1/Sparkle-2.0.0-rc.1.tar.xz", "2.0.0": "https://github.com/sparkle-project/Sparkle/releases/download/2.0.0/Sparkle-2.0.0.tar.xz", "2.1.0-beta.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.1.0-beta.1/Sparkle-2.1.0-beta.1.tar.xz", "2.1.0-beta.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.1.0-beta.2/Sparkle-2.1.0-beta.2.tar.xz", "2.1.0": "https://github.com/sparkle-project/Sparkle/releases/download/2.1.0/Sparkle-2.1.0.tar.xz", "2.2.0-beta.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.2.0-beta.1/Sparkle-2.2.0-beta.1.tar.xz", "2.2.0-beta.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.2.0-beta.2/Sparkle-2.2.0-beta.2.tar.xz", "2.2.0": "https://github.com/sparkle-project/Sparkle/releases/download/2.2.0/Sparkle-2.2.0.tar.xz", "2.2.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.2.1/Sparkle-2.2.1.tar.xz", "2.2.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.2.2/Sparkle-2.2.2.tar.xz", "2.3.0-beta.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.3.0-beta.1/Sparkle-2.3.0-beta.1.tar.xz", "2.3.0-beta.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.3.0-beta.2/Sparkle-2.3.0-beta.2.tar.xz", "2.3.0": "https://github.com/sparkle-project/Sparkle/releases/download/2.3.0/Sparkle-2.3.0.tar.xz", "2.3.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.3.1/Sparkle-2.3.1.tar.xz", "2.3.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.3.2/Sparkle-2.3.2.tar.xz", "2.4.0-beta.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.4.0-beta.1/Sparkle-2.4.0-beta.1.tar.xz", "2.4.0-beta.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.4.0-beta.2/Sparkle-2.4.0-beta.2.tar.xz", "2.4.0": "https://github.com/sparkle-project/Sparkle/releases/download/2.4.0/Sparkle-2.4.0.tar.xz", "2.4.1-beta.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.4.1-beta.1/Sparkle-2.4.1-beta.1.tar.xz", "2.4.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.4.1/Sparkle-2.4.1.tar.xz", "2.4.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.4.2/Sparkle-2.4.2.tar.xz", "2.5.0-beta.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.5.0-beta.1/Sparkle-2.5.0-beta.1.tar.xz", "2.5.0-beta.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.5.0-beta.2/Sparkle-2.5.0-beta.2.tar.xz", "2.5.0": "https://github.com/sparkle-project/Sparkle/releases/download/2.5.0/Sparkle-2.5.0.tar.xz", "2.5.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.5.1/Sparkle-2.5.1.tar.xz", "2.5.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.5.2/Sparkle-2.5.2.tar.xz", "2.6.0-beta.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.6.0-beta.1/Sparkle-2.6.0-beta.1.tar.xz", "2.6.0-beta.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.6.0-beta.2/Sparkle-2.6.0-beta.2.tar.xz", "2.6.0": "https://github.com/sparkle-project/Sparkle/releases/download/2.6.0/Sparkle-2.6.0.tar.xz", "2.6.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.6.1/Sparkle-2.6.1.tar.xz", "1.27.2": "https://github.com/sparkle-project/Sparkle/releases/download/1.27.2/Sparkle-1.27.2.tar.xz", "2.6.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.6.2/Sparkle-2.6.2.tar.xz", "1.27.3": "https://github.com/sparkle-project/Sparkle/releases/download/1.27.3/Sparkle-1.27.3.tar.xz", "2.6.3": "https://github.com/sparkle-project/Sparkle/releases/download/2.6.3/Sparkle-2.6.3.tar.xz", "2.6.4": "https://github.com/sparkle-project/Sparkle/releases/download/2.6.4/Sparkle-2.6.4.tar.xz", "2.7.0-beta.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.7.0-beta.1/Sparkle-2.7.0-beta.1.tar.xz", "2.7.0": "https://github.com/sparkle-project/Sparkle/releases/download/2.7.0/Sparkle-2.7.0.tar.xz", "2.7.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.7.1/Sparkle-2.7.1.tar.xz", "2.7.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.7.2/Sparkle-2.7.2.tar.xz", "2.7.3": "https://github.com/sparkle-project/Sparkle/releases/download/2.7.3/Sparkle-2.7.3.tar.xz", "2.8.0-beta.1": "https://github.com/sparkle-project/Sparkle/releases/download/2.8.0-beta.1/Sparkle-2.8.0-beta.1.tar.xz", "2.8.0-beta.2": "https://github.com/sparkle-project/Sparkle/releases/download/2.8.0-beta.2/Sparkle-2.8.0-beta.2.tar.xz", "2.8.0-beta.3": "https://github.com/sparkle-project/Sparkle/releases/download/2.8.0-beta.3/Sparkle-2.8.0-beta.3.tar.xz", "2.8.0": "https://github.com/sparkle-project/Sparkle/releases/download/2.8.0/Sparkle-2.8.0.tar.xLine truncated
|
||||
@@ -1,4 +0,0 @@
|
||||
// Generate Appcast Debug
|
||||
|
||||
#include "CommandLineTool-Shared.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
@@ -1,4 +0,0 @@
|
||||
// Generate Appcast Release
|
||||
|
||||
#include "CommandLineTool-Shared.xcconfig"
|
||||
#include "ConfigSwiftRelease.xcconfig"
|
||||
@@ -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_EXTERNALLY=1
|
||||
@@ -0,0 +1,8 @@
|
||||
// BinaryDelta tool only
|
||||
|
||||
PRODUCT_NAME = BinaryDelta
|
||||
GCC_PREFIX_HEADER =
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=i386] = 10.5
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc64] = 10.5
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc] = 10.5
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=x86_64] = 10.5
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigBinaryDelta.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -DDEBUG
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigBinaryDelta.xcconfig"
|
||||
@@ -1,170 +1,52 @@
|
||||
// Common
|
||||
|
||||
// Set to 1 or 0 to build and bundle the provided XPC Services in Sparkle framework
|
||||
// (Note for testing purposes for sandboxed apps, disabling all XPC services and then re-enabling them
|
||||
// may not work on the same login session due to a system caching issue. See comments for setting FRAMEWORK_VERSION for more info)
|
||||
SPARKLE_EMBED_INSTALLER_LAUNCHER_XPC_SERVICE = 1
|
||||
// Embedding the downloader service also enables building legacy WebKit1 support
|
||||
SPARKLE_EMBED_DOWNLOADER_XPC_SERVICE = 1
|
||||
SPARKLE_EMBED_INSTALLER_STATUS_XPC_SERVICE = 0
|
||||
SPARKLE_EMBED_INSTALLER_CONNECTION_XPC_SERVICE = 0
|
||||
|
||||
// Set to 0 to disable building legacy 1.x SUUpdater stub
|
||||
SPARKLE_BUILD_LEGACY_SUUPDATER = 1
|
||||
|
||||
// Set to 0 to not build legacy DSA signing support
|
||||
// Don't disable this if you haven't migrated to EdDSA yet or if you support updating
|
||||
// other developer's applications that haven't migrated to EdDSA yet
|
||||
// If this is disabled, this requires an update to OTHER_SWIFT_FLAGS_COMMON below
|
||||
SPARKLE_BUILD_LEGACY_DSA_SUPPORT = 1
|
||||
|
||||
// Set to 0 to not build legacy DSA signing support for generate_appcast
|
||||
// Don't disable this if you still have items in your appcast feed that still need DSA signatures
|
||||
// If this is disabled, this requires an update to OTHER_SWIFT_FLAGS_COMMON below
|
||||
GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT = 1
|
||||
|
||||
// Set to 0 to not build legacy / xar based delta update support
|
||||
SPARKLE_BUILD_LEGACY_DELTA_SUPPORT = 1
|
||||
|
||||
// Set to 0 to not build bzip2 support for version 3 delta based updates
|
||||
SPARKLE_BUILD_BZIP2_DELTA_SUPPORT = 1
|
||||
|
||||
// Set to 0 to not build support for package (pkg) based installations
|
||||
// If this is disabled, this requires an update to OTHER_SWIFT_FLAGS_COMMON below
|
||||
SPARKLE_BUILD_PACKAGE_SUPPORT = 1
|
||||
|
||||
// Set to 0 to only build all non-UI bits (which means client uses a custom SPUUserDriver)
|
||||
SPARKLE_BUILD_UI_BITS = 1
|
||||
|
||||
// Set to 0 to not use and copy localization / string files to framework
|
||||
SPARKLE_COPY_LOCALIZATIONS = 1
|
||||
|
||||
// Compilation flags for Swift tools and unit tests
|
||||
// If SPARKLE_BUILD_LEGACY_DELTA_SUPPORT is set to 0, remove -DSPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
// If GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT is set to 0, remove -DGENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT
|
||||
// If SPARKLE_BUILD_PACKAGE_SUPPORT is set to 0, remove -DSPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
OTHER_SWIFT_FLAGS_COMMON = -DSPARKLE_BUILD_LEGACY_DSA_SUPPORT -DGENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT -DSPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
// Minimum supported macOS version
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.13
|
||||
|
||||
// Supported architectures
|
||||
ARCHS = $(ARCHS_STANDARD)
|
||||
|
||||
// Default Sparkle names
|
||||
SPARKLE_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle
|
||||
SPARKLE_RELAUNCH_TOOL_NAME = Autoupdate
|
||||
SPARKLE_INSTALLER_PROGRESS_TOOL_NAME = Updater
|
||||
SPARKLE_INSTALLER_PROGRESS_TOOL_BUNDLE_ID = $(SPARKLE_BUNDLE_IDENTIFIER).$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)
|
||||
|
||||
// Set these if you want to use custom name for the XPC Services
|
||||
// For the Installer one in particular, this name may show up in an authorization prompt
|
||||
// when installing an update that requires authorization.
|
||||
INSTALLER_CONNECTION_NAME = InstallerConnection
|
||||
INSTALLER_STATUS_NAME = InstallerStatus
|
||||
INSTALLER_LAUNCHER_NAME = Installer
|
||||
DOWNLOADER_NAME = Downloader
|
||||
|
||||
// Set this to your own prefix if you want to use XPC Service bundle IDs with different prefix
|
||||
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}.DownloaderService
|
||||
|
||||
// The Downloader XPC Service is not sandboxed by default.
|
||||
// Uncomment line to enable Sandboxing for this service.
|
||||
// If this is done, you *must* set a custom XPC_SERVICE_BUNDLE_ID_PREFIX for your app above.
|
||||
// Otherwise sandboxed apps that use the same sandboxed Downloader Service may conflict with each other.
|
||||
//DOWNLOADER_SANDBOXED_ENTITLEMENTS = Downloader/Downloader.entitlements
|
||||
|
||||
|
||||
// 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
|
||||
SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0
|
||||
|
||||
SPARKLE_ICON_NAME = AppIcon
|
||||
|
||||
// If you change any of these version details, you must increase CURRENT_PROJECT_VERSION
|
||||
// These variables must have a space after the '=' too
|
||||
SPARKLE_VERSION_MAJOR = 2
|
||||
SPARKLE_VERSION_MINOR = 9
|
||||
SPARKLE_VERSION_PATCH = 0
|
||||
|
||||
// This should be in SemVer format or empty, ie. "-beta.1"
|
||||
// These variables must have a space after the '=' too
|
||||
SPARKLE_VERSION_SUFFIX =
|
||||
CURRENT_PROJECT_VERSION = 2053
|
||||
|
||||
MARKETING_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)$(SPARKLE_VERSION_SUFFIX)
|
||||
ALWAYS_SEARCH_USER_PATHS = NO
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = YES
|
||||
GCC_INLINES_ARE_PRIVATE_EXTERN = YES
|
||||
PRODUCT_NAME = ${TARGET_NAME}
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle.${PRODUCT_NAME:rfc1034identifier}
|
||||
|
||||
GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPU_OBJC_DIRECT=__attribute__((objc_direct)) SPU_OBJC_DIRECT_MEMBERS=__attribute__((objc_direct_members)) SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_BUILD_UI_BITS=$(SPARKLE_BUILD_UI_BITS) SPARKLE_COPY_LOCALIZATIONS=$(SPARKLE_COPY_LOCALIZATIONS) SPARKLE_BUILD_LEGACY_SUUPDATER=$(SPARKLE_BUILD_LEGACY_SUUPDATER) SPARKLE_BUILD_PACKAGE_SUPPORT=$(SPARKLE_BUILD_PACKAGE_SUPPORT) SPARKLE_BUILD_LEGACY_DELTA_SUPPORT=$(SPARKLE_BUILD_LEGACY_DELTA_SUPPORT) SPARKLE_BUILD_BZIP2_DELTA_SUPPORT=$(SPARKLE_BUILD_BZIP2_DELTA_SUPPORT) SPARKLE_BUILD_LEGACY_DSA_SUPPORT=$(SPARKLE_BUILD_LEGACY_DSA_SUPPORT) GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT=$(GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" CURRENT_PROJECT_VERSION=\"$(CURRENT_PROJECT_VERSION)\" MARKETING_VERSION=\"$(MARKETING_VERSION)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_NAME=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_BUNDLE_ID=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_BUNDLE_ID)\" SPARKLE_ICON_NAME=\"$(SPARKLE_ICON_NAME)\" INSTALLER_LAUNCHER_NAME=\"${INSTALLER_LAUNCHER_NAME}\" INSTALLER_LAUNCHER_BUNDLE_ID=\"${INSTALLER_LAUNCHER_BUNDLE_ID}\" INSTALLER_LAUNCHER_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_LAUNCHER_XPC_SERVICE) INSTALLER_CONNECTION_NAME=\"${INSTALLER_CONNECTION_NAME}\" INSTALLER_CONNECTION_BUNDLE_ID=\"${INSTALLER_CONNECTION_BUNDLE_ID}\" INSTALLER_CONNECTION_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_CONNECTION_XPC_SERVICE) INSTALLER_STATUS_NAME=\"${INSTALLER_STATUS_NAME}\" INSTALLER_STATUS_BUNDLE_ID=\"${INSTALLER_STATUS_BUNDLE_ID}\" INSTALLER_STATUS_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_STATUS_XPC_SERVICE) DOWNLOADER_NAME=\"${DOWNLOADER_NAME}\" DOWNLOADER_BUNDLE_ID=\"${DOWNLOADER_BUNDLE_ID}\" DOWNLOADER_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_DOWNLOADER_XPC_SERVICE)
|
||||
|
||||
CODE_SIGN_IDENTITY = -
|
||||
SDKROOT = macosx
|
||||
ENABLE_HARDENED_RUNTIME = YES
|
||||
CLANG_ENABLE_OBJC_ARC = YES
|
||||
PREBINDING = NO
|
||||
ZERO_LINK = NO
|
||||
CURRENT_PROJECT_VERSION = 1.5
|
||||
SDKROOT = macosx10.9
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc] = 10.4
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc64] = 10.5
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=i386] = 10.4
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=x86_64] = 10.7
|
||||
GCC_C_LANGUAGE_STANDARD = c99
|
||||
GCC_ENABLE_OBJC_EXCEPTIONS = YES
|
||||
GCC_DEBUGGING_SYMBOLS = full
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES
|
||||
GCC_PREFIX_HEADER = $(SDKROOT)/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h
|
||||
GCC_FAST_OBJC_DISPATCH = YES
|
||||
GCC_ENABLE_PASCAL_STRINGS = NO
|
||||
GCC_NO_COMMON_BLOCKS = YES
|
||||
COMBINE_HIDPI_IMAGES = NO
|
||||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0
|
||||
CLANG_LINK_OBJC_RUNTIME = NO
|
||||
|
||||
// Enable warnings
|
||||
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES
|
||||
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES
|
||||
CLANG_ENABLE_MODULES = YES
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
|
||||
CLANG_WARN_ASSIGN_ENUM = YES
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES
|
||||
CLANG_WARN_EMPTY_BODY = YES
|
||||
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES
|
||||
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES
|
||||
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_SUSPICIOUS_IMPLICIT_CONVERSION = YES
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES
|
||||
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES
|
||||
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
|
||||
GCC_WARN_ABOUT_MISSING_NEWLINE = YES
|
||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES
|
||||
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
|
||||
GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES
|
||||
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
|
||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
|
||||
GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES
|
||||
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES
|
||||
GCC_WARN_PEDANTIC = YES
|
||||
GCC_WARN_SHADOW = YES
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
|
||||
GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES
|
||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES
|
||||
GCC_WARN_MISSING_PARENTHESES = YES
|
||||
GCC_WARN_ABOUT_MISSING_NEWLINE = YES
|
||||
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
|
||||
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES
|
||||
GCC_WARN_SIGN_COMPARE = YES
|
||||
GCC_WARN_STRICT_SELECTOR_MATCH = YES
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES
|
||||
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
|
||||
GCC_WARN_UNKNOWN_PRAGMAS = YES
|
||||
GCC_WARN_UNUSED_VARIABLE = YES
|
||||
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES
|
||||
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
|
||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
|
||||
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
|
||||
GCC_WARN_UNUSED_FUNCTION = YES
|
||||
GCC_WARN_UNUSED_LABEL = YES
|
||||
GCC_WARN_UNUSED_VALUE = YES
|
||||
GCC_WARN_UNUSED_PARAMETER = YES
|
||||
GCC_WARN_UNUSED_VARIABLE = YES
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES
|
||||
|
||||
// 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-auto-import -Wno-gnu-zero-variadic-macro-arguments -Wno-format-non-iso -Wno-direct-ivar-access -Wno-declaration-after-statement -Wno-gnu-conditional-omitted-operand -Wno-switch-default -Wno-missing-include-dirs -Werror=undef
|
||||
|
||||
// Prevents spurious warnings based on dependency scan considering Sparkle itself a dependency
|
||||
DIAGNOSE_MISSING_TARGET_DEPENDENCIES = NO
|
||||
COMMON_WARNING_FLAGS = -Wall -Wno-unused-parameter -Wundef -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-format-attribute -Wpacked -Wredundant-decls -Winline -Wdisabled-optimization -Winvalid-pch
|
||||
WARNING_CFLAGS = $(COMMON_WARNING_FLAGS)
|
||||
@@ -1,13 +0,0 @@
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON)
|
||||
OTHER_SWIFT_FLAGS = $(OTHER_SWIFT_FLAGS_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
|
||||
@@ -1,18 +1,11 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
|
||||
// Debug only
|
||||
|
||||
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_OPTIMIZATION_LEVEL = 0
|
||||
DEBUG_INFORMATION_FORMAT = dwarf
|
||||
ENABLE_TESTABILITY = YES
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON) DEBUG=1
|
||||
OTHER_SWIFT_FLAGS = $(OTHER_SWIFT_FLAGS_COMMON)
|
||||
ONLY_ACTIVE_ARCH = YES
|
||||
COPY_PHASE_STRIP = NO
|
||||
SPARKLE_EXTRA_DEBUG_10_5_ONLY = -fstack-protector -D_FORTIFY_SOURCE=2
|
||||
SPARKLE_EXTRA_DEBUG = -DDEBUG
|
||||
OTHER_CFLAGS = $(SPARKLE_EXTRA_DEBUG)
|
||||
CODE_SIGN_IDENTITY = Mac Developer
|
||||
|
||||
// Add $(SPARKLE_EXTRA_DEBUG_10_5_ONLY) to SPARKLE_EXTRA_DEBUG if your deployment is 10.5 or greater.
|
||||
@@ -0,0 +1,4 @@
|
||||
// Common
|
||||
|
||||
ARCHS = x86_64
|
||||
VALID_ARCHS = x86_64
|
||||
@@ -0,0 +1,4 @@
|
||||
// Common
|
||||
|
||||
ARCHS = ppc i386 x86_64
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
|
||||
// Release only
|
||||
|
||||
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_OPTIMIZATION_LEVEL = s
|
||||
DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON) DEBUG=0
|
||||
OTHER_SWIFT_FLAGS = $(OTHER_SWIFT_FLAGS_COMMON)
|
||||
DEAD_CODE_STRIPPING = YES
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = NO
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = YES
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES
|
||||
COPY_PHASE_STRIP = NO
|
||||
DEPLOYMENT_POSTPROCESSING = YES
|
||||
WARNING_CFLAGS = $(COMMON_WARNING_FLAGS) -Wno-deprecated-declarations
|
||||
CODE_SIGN_IDENTITY = Developer ID Application
|
||||
@@ -1,9 +0,0 @@
|
||||
// Downloader
|
||||
|
||||
INFOPLIST_FILE = Downloader/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${DOWNLOADER_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${DOWNLOADER_NAME}
|
||||
CODE_SIGN_ENTITLEMENTS = $(DOWNLOADER_SANDBOXED_ENTITLEMENTS)
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
CLANG_MODULES_AUTOLINK = NO
|
||||
@@ -1,2 +0,0 @@
|
||||
// Downloader Debug
|
||||
#include "ConfigDownloader.xcconfig"
|
||||
@@ -1,29 +1,10 @@
|
||||
// Framework only
|
||||
|
||||
DYLIB_INSTALL_NAME_BASE = @rpath
|
||||
DYLIB_COMPATIBILITY_VERSION = 1.6
|
||||
DYLIB_CURRENT_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)
|
||||
INSTALL_PATH = @rpath
|
||||
DYLIB_COMPATIBILITY_VERSION = 2.0
|
||||
DYLIB_CURRENT_VERSION = 2.1.1
|
||||
PRODUCT_NAME = Sparkle
|
||||
WRAPPER_EXTENSION = framework
|
||||
|
||||
// Sparkle 2 used to support developers embedding XPC Services in their own app bundle
|
||||
// However the Sparkle framework now bundles these XPC Services. Unfortunately this causes
|
||||
// a cache conflict in the system from upgrading from previous to newer versions of Sparkle, and
|
||||
// XPC Services inside Sparkle may not launch (a system reboot would fix this though).
|
||||
// The system cache seems to depend on the Sparkle file path,
|
||||
// so as a better workaround we have changed the FRAMEWORK_VERSION from A to B
|
||||
FRAMEWORK_VERSION = B
|
||||
|
||||
INFOPLIST_FILE = Sparkle/Sparkle-Info.plist
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BUILDING_SPARKLE=1
|
||||
SKIP_INSTALL = YES
|
||||
DEFINES_MODULE = YES
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${SPARKLE_BUNDLE_IDENTIFIER}
|
||||
STRINGS_FILE_OUTPUT_ENCODING = binary
|
||||
|
||||
// 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
|
||||
|
||||
ENABLE_MODULE_VERIFIER = YES
|
||||
MODULEMAP_PRIVATE_FILE = Sparkle/Sparkle.private.modulemap
|
||||
FRAMEWORK_VERSION = A
|
||||
INFOPLIST_FILE = Info.plist
|
||||
GCC_PREFIX_HEADER = Sparkle.pch
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigFramework.xcconfig"
|
||||
|
||||
// Unit tests need access to non-public classes
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO
|
||||
OTHER_CFLAGS = -DDEBUG
|
||||
@@ -1,4 +1,9 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigFramework.xcconfig"
|
||||
|
||||
// Strip all non-global symbols (including debug symbols)
|
||||
STRIP_INSTALLED_PRODUCT = YES
|
||||
DEPLOYMENT_POSTPROCESSING = YES
|
||||
STRIPFLAGS = -u -r
|
||||
STRIP_STYLE = non-global
|
||||
SEPARATE_STRIP = YES
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ConfigFrameworkRelease.xcconfig"
|
||||
|
||||
GCC_ENABLE_OBJC_GC = supported
|
||||
@@ -1,8 +0,0 @@
|
||||
// InstallerConnection
|
||||
|
||||
INFOPLIST_FILE = InstallerConnection/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${INSTALLER_CONNECTION_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${INSTALLER_CONNECTION_NAME}
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
CLANG_MODULES_AUTOLINK = NO
|
||||
@@ -1,3 +0,0 @@
|
||||
// InstallerConnection Debug
|
||||
|
||||
#include "ConfigInstallerConnection.xcconfig"
|
||||
@@ -1,8 +0,0 @@
|
||||
// Installer Launcher
|
||||
|
||||
INFOPLIST_FILE = InstallerLauncher/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${INSTALLER_LAUNCHER_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${INSTALLER_LAUNCHER_NAME}
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
CLANG_MODULES_AUTOLINK = NO
|
||||
@@ -1,2 +0,0 @@
|
||||
// Installer Launcher Debug
|
||||
#include "ConfigInstallerLauncher.xcconfig"
|
||||
@@ -1,8 +0,0 @@
|
||||
// Installer Progress only
|
||||
|
||||
INFOPLIST_FILE = Sparkle/InstallerProgress/InstallerProgress-Info.plist
|
||||
PRODUCT_NAME = $(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)
|
||||
PRODUCT_BUNDLE_IDENTIFIER = $(SPARKLE_INSTALLER_PROGRESS_TOOL_BUNDLE_ID)
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE=0 BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
SKIP_INSTALL = YES
|
||||
CLANG_ENABLE_MODULES = NO
|
||||
@@ -1,8 +0,0 @@
|
||||
// InstallerStatus
|
||||
|
||||
INFOPLIST_FILE = InstallerStatus/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${INSTALLER_STATUS_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${INSTALLER_STATUS_NAME}
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE=0 BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
CLANG_MODULES_AUTOLINK = NO
|
||||
@@ -1,3 +0,0 @@
|
||||
// InstallerStatus Debug
|
||||
|
||||
#include "ConfigInstallerStatus.xcconfig"
|
||||
@@ -1,6 +1,4 @@
|
||||
// Relaunch Tool only
|
||||
|
||||
PRODUCT_NAME = $(SPARKLE_RELAUNCH_TOOL_NAME)
|
||||
PRODUCT_NAME = finish_installation
|
||||
SKIP_INSTALL = YES
|
||||
CLANG_ENABLE_MODULES = NO
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigRelaunch.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -DDEBUG
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigRelaunch.xcconfig"
|
||||
@@ -0,0 +1,10 @@
|
||||
// Sandbox Service only
|
||||
|
||||
WRAPPER_EXTENSION = xpc
|
||||
MACH_O_TYPE = mh_execute
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.7
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=x86_64] = 10.7
|
||||
|
||||
GCC_WARN_SHADOW = NO
|
||||
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = NO
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigService.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -DDEBUG
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigService.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 +0,0 @@
|
||||
SWIFT_VERSION = 5
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
|
||||
@@ -1 +0,0 @@
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Onone
|
||||
@@ -1,2 +0,0 @@
|
||||
SWIFT_OPTIMIZATION_LEVEL = -O
|
||||
SWIFT_COMPILATION_MODE = wholemodule
|
||||
@@ -1,9 +1,6 @@
|
||||
// Test Application
|
||||
// Test Application only
|
||||
|
||||
INFOPLIST_FILE = TestApplication/TestApplication-Info.plist
|
||||
INFOPLIST_FILE = Test Application/Test Application-Info.plist
|
||||
PRODUCT_NAME = Sparkle Test App
|
||||
WRAPPER_EXTENSION = app
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = $(SPARKLE_ICON_NAME)
|
||||
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
|
||||
LD_RUNPATH_SEARCH_PATHS = @loader_path/../Frameworks
|
||||
Loaded 100 of 929 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user