Merge pull request #1854 from sparkle-project/xpc-sha

Validate XPC Service versions
This commit is contained in:
Mayur Pawashe authored and GitHub committed 2021-05-10 19:11:57 -07:00
commit 91e71c219c
5 files changed
+108 -7

No files matched your search

+1
View File
@@ -27,6 +27,7 @@ jobs:
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
- name: Build Unit Tests
env:
DEVELOPER_DIR: ${{ matrix.xcode-path }}
+76
View File
@@ -2626,6 +2626,7 @@
724BB3681D31D0B7005D534A /* Sources */,
724BB3691D31D0B7005D534A /* Frameworks */,
724BB36A1D31D0B7005D534A /* Resources */,
7269E49E264919CD0088C213 /* Run Script: Set Git Version Info */,
);
buildRules = (
);
@@ -2643,6 +2644,7 @@
724BB38F1D333832005D534A /* Sources */,
724BB3901D333832005D534A /* Frameworks */,
724BB3911D333832005D534A /* Resources */,
7269E49F264919D40088C213 /* Run Script: Set Git Version Info */,
);
buildRules = (
);
@@ -2678,6 +2680,7 @@
726E07A91CAF08D6001A286B /* Sources */,
726E07AA1CAF08D6001A286B /* Frameworks */,
721D8A711D4950910032E472 /* Copy Tools */,
7269E49D264919C20088C213 /* Run Script: Set Git Version Info */,
);
buildRules = (
);
@@ -2697,6 +2700,7 @@
726E07EB1CAF37BD001A286B /* Sources */,
726E07EC1CAF37BD001A286B /* Frameworks */,
726E07ED1CAF37BD001A286B /* Resources */,
7269E4A0264919D90088C213 /* Run Script: Set Git Version Info */,
);
buildRules = (
);
@@ -3207,6 +3211,78 @@
shellPath = /bin/sh;
shellScript = "\"$SRCROOT/Configurations/link-tools.sh\"\n";
};
7269E49D264919C20088C213 /* Run Script: Set Git Version Info */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run Script: Set Git Version Info";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"$SRCROOT/Configurations/set-git-version-info.sh\"\n";
};
7269E49E264919CD0088C213 /* Run Script: Set Git Version Info */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run Script: Set Git Version Info";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"$SRCROOT/Configurations/set-git-version-info.sh\"\n";
};
7269E49F264919D40088C213 /* Run Script: Set Git Version Info */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run Script: Set Git Version Info";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"$SRCROOT/Configurations/set-git-version-info.sh\"\n";
};
7269E4A0264919D90088C213 /* Run Script: Set Git Version Info */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run Script: Set Git Version Info";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"$SRCROOT/Configurations/set-git-version-info.sh\"\n";
};
72A5D5F11D692C860009E5AC /* Run Script: Set Git Version Info */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
+8
View File
@@ -268,6 +268,14 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
}
}
// Check XPC Services are functional
NSBundle *sparkleBundle = [NSBundle bundleForClass:[self class]];
for (NSString *xpcServiceID in @[@INSTALLER_LAUNCHER_BUNDLE_ID, @DOWNLOADER_BUNDLE_ID, @INSTALLER_CONNECTION_BUNDLE_ID, @INSTALLER_STATUS_BUNDLE_ID]) {
if (!SPUXPCValidateServiceIfBundleExists(xpcServiceID, sparkleBundle, error)) {
return NO;
}
}
return YES;
}
+2
View File
@@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
BOOL SPUXPCServiceExists(NSString *bundleName);
BOOL SPUXPCValidateServiceIfBundleExists(NSString *bundleName, NSBundle *sparkleBundle, NSError * __autoreleasing *error);
NSBundle * _Nullable SPUXPCServiceBundle(NSString *bundleName);
NS_ASSUME_NONNULL_END
+21 -7
View File
@@ -7,23 +7,37 @@
//
#import "SPUXPCServiceInfo.h"
#import "SUErrors.h"
#import "SUConstants.h"
#include "AppKitPrevention.h"
BOOL SPUXPCServiceExists(NSString *bundleName)
{
NSBundle *xpcBundle = SPUXPCServiceBundle(bundleName);
return (xpcBundle != nil);
}
BOOL SPUXPCValidateServiceIfBundleExists(NSString *bundleName, NSBundle *sparkleBundle, NSError * __autoreleasing *error)
{
NSBundle *xpcBundle = SPUXPCServiceBundle(bundleName);
if (xpcBundle == nil) {
return NO;
return YES;
}
NSString *version = [xpcBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey];
NSString *projectVersion = @""CURRENT_PROJECT_VERSION;
if (version == nil || ![version isEqualToString:projectVersion]) {
// Use NSLog instead of SULog here because this is a developer configuration error...
NSLog(@"Error: XPC Version mismatch. Framework version is %@ but XPC Service (%@) version is %@", projectVersion, xpcBundle.bundlePath, version);
NSLog(@"Not using XPC Service...");
// Sometimes in debug the short version where we append a git hash is not available,
// so if our CFBundleVersion == CFBundleShortVersionString, we will compare to CURRENT_PROJECT_VERSION,
// Otherwise if git hash is correctly appended, we will compare to short version string of Sparkle framework
NSString *bundleVersion = [xpcBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey];
NSString *version = [xpcBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *projectVersion = [bundleVersion isEqualToString:version] ? @""CURRENT_PROJECT_VERSION : [sparkleBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
if (version == nil || projectVersion == nil || ![version isEqualToString:projectVersion]) {
if (error != NULL) {
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInvalidUpdaterError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"XPC Version mismatch. Framework display version is %@ but XPC Service (%@) display version is %@. Bundled XPC Service cannot be used.", projectVersion, xpcBundle.bundlePath, version] }];
}
return NO;
}