mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
612120a933 | ||
|
|
adebd9f18e | ||
|
|
4f2c269e80 | ||
|
|
f5d3cb4500 | ||
|
|
ece2b2e642 | ||
|
|
744d67c6ed | ||
|
|
094b242f97 | ||
|
|
b3afccee9d | ||
|
|
cd57836ca5 | ||
|
|
3f2d37486f | ||
|
|
e308867767 | ||
|
|
9715e82a82 | ||
|
|
cc75f340e8 | ||
|
|
17c51da8af | ||
|
|
48e3a4277e |
No files matched your search
@@ -18,7 +18,8 @@ SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0
|
|||||||
SPARKLE_VERSION_MAJOR = 1
|
SPARKLE_VERSION_MAJOR = 1
|
||||||
SPARKLE_VERSION_MINOR = 18
|
SPARKLE_VERSION_MINOR = 18
|
||||||
SPARKLE_VERSION_PATCH = 0
|
SPARKLE_VERSION_PATCH = 0
|
||||||
SPARKLE_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)
|
TUNNELBEAR_ID = TB
|
||||||
|
SPARKLE_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)$(TUNNELBEAR_ID)
|
||||||
|
|
||||||
CURRENT_PROJECT_VERSION = $(SPARKLE_VERSION)
|
CURRENT_PROJECT_VERSION = $(SPARKLE_VERSION)
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO
|
ALWAYS_SEARCH_USER_PATHS = NO
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = "Sparkle"
|
s.name = "Sparkle"
|
||||||
s.version = "1.18.0"
|
s.version = "1.18.0TB"
|
||||||
s.summary = "A software update framework for macOS"
|
s.summary = "A software update framework for macOS"
|
||||||
s.description = "Sparkle is an easy-to-use software update framework for Cocoa developers."
|
s.description = "Sparkle is an easy-to-use software update framework for Cocoa developers."
|
||||||
s.homepage = "http://sparkle-project.org"
|
s.homepage = "http://sparkle-project.org"
|
||||||
@@ -19,7 +19,7 @@ Pod::Spec.new do |s|
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.platform = :osx, '10.7'
|
s.platform = :osx, '10.7'
|
||||||
s.source = { :http => "https://github.com/sparkle-project/Sparkle/releases/download/#{s.version}/Sparkle-#{s.version}.tar.bz2" }
|
s.source = { :http => "https://s3.amazonaws.com/tunnelbear/sparkle/Sparkle-#{s.version}.tar.bz2" }
|
||||||
s.source_files = 'Sparkle.framework/Versions/A/Headers/*.h'
|
s.source_files = 'Sparkle.framework/Versions/A/Headers/*.h'
|
||||||
|
|
||||||
s.preserve_paths = 'bin/*'
|
s.preserve_paths = 'bin/*'
|
||||||
|
|||||||
Vendored
+25
@@ -46,6 +46,15 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
|||||||
|
|
||||||
- (void)showUpdateAlert
|
- (void)showUpdateAlert
|
||||||
{
|
{
|
||||||
|
id<SUUpdaterPrivate> updater = self.updater;
|
||||||
|
id<SUUpdaterDelegate> updaterDelegate = [updater delegate];
|
||||||
|
if ([updaterDelegate suppressSparkleUI])
|
||||||
|
{
|
||||||
|
[self automaticUpdateAlertFinishedWithChoice:SUInstallLaterChoice];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// NSLog(@"[Sparkle showUpdateAlert]");
|
||||||
|
|
||||||
self.interruptible = NO;
|
self.interruptible = NO;
|
||||||
[self invalidateShowUpdateAlertTimer];
|
[self invalidateShowUpdateAlertTimer];
|
||||||
|
|
||||||
@@ -96,10 +105,26 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
|||||||
|
|
||||||
[updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation];
|
[updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation];
|
||||||
}
|
}
|
||||||
|
//For Swift
|
||||||
|
else if ([updaterDelegate respondsToSelector:@selector(updater: willInstallUpdateOnQuit:immediateInstallationBlock:)])
|
||||||
|
{
|
||||||
|
BOOL relaunch = YES;
|
||||||
|
BOOL showUI = NO;
|
||||||
|
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:displayingUserInterface:)]];
|
||||||
|
[invocation setSelector:@selector(installWithToolAndRelaunch:displayingUserInterface:)];
|
||||||
|
[invocation setArgument:&relaunch atIndex:2];
|
||||||
|
[invocation setArgument:&showUI atIndex:3];
|
||||||
|
[invocation setTarget:self];
|
||||||
|
|
||||||
|
[updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationBlock:^{
|
||||||
|
[invocation invoke];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
// If this is marked as a critical update, we'll prompt the user to install it right away.
|
// If this is marked as a critical update, we'll prompt the user to install it right away.
|
||||||
if ([self.updateItem isCriticalUpdate])
|
if ([self.updateItem isCriticalUpdate])
|
||||||
{
|
{
|
||||||
|
// NSLog(@"[Sparkle update deemed critical]");
|
||||||
[self showUpdateAlert];
|
[self showUpdateAlert];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Vendored
+5
-1
@@ -212,7 +212,11 @@
|
|||||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
|
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
|
||||||
object:self.updater
|
object:self.updater
|
||||||
userInfo:@{ SUUpdaterAppcastItemNotificationKey: self.updateItem }];
|
userInfo:@{ SUUpdaterAppcastItemNotificationKey: self.updateItem }];
|
||||||
[self downloadUpdate];
|
|
||||||
|
|
||||||
|
// TB: Always download update.
|
||||||
|
// Stadard accounts will recieve an auth prompt before installation
|
||||||
|
[self downloadUpdate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didNotFindUpdate
|
- (void)didNotFindUpdate
|
||||||
|
|||||||
Vendored
+1
@@ -31,6 +31,7 @@ typedef NS_ENUM(OSStatus, SUError) {
|
|||||||
// Download phase errors.
|
// Download phase errors.
|
||||||
SUTemporaryDirectoryError = 2000,
|
SUTemporaryDirectoryError = 2000,
|
||||||
SUDownloadError = 2001,
|
SUDownloadError = 2001,
|
||||||
|
SUHostDirectoryNotWritable = 2002,
|
||||||
|
|
||||||
// Extraction phase errors.
|
// Extraction phase errors.
|
||||||
SUUnarchivingError = 3000,
|
SUUnarchivingError = 3000,
|
||||||
|
|||||||
Vendored
+25
-47
@@ -59,42 +59,16 @@
|
|||||||
- (void)didFindValidUpdate
|
- (void)didFindValidUpdate
|
||||||
{
|
{
|
||||||
id<SUUpdaterPrivate> updater = self.updater;
|
id<SUUpdaterPrivate> updater = self.updater;
|
||||||
if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
|
if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:respondWithChoice:)]) {
|
||||||
[[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
|
[[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem respondWithChoice:^(SUDUpdateAlertChoice choice) {
|
||||||
|
[self updateAlertFinishedWithChoice:(SUUpdateAlertChoice)choice];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
else if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
|
||||||
if (self.automaticallyInstallUpdates) {
|
[[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
|
||||||
[self updateAlertFinishedWithChoice:SUInstallUpdateChoice];
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) {
|
|
||||||
[self updateAlertFinishedWithChoice:choice];
|
|
||||||
}];
|
|
||||||
|
|
||||||
id<SUVersionDisplay> versDisp = nil;
|
|
||||||
if ([[updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) {
|
|
||||||
versDisp = [[updater delegate] versionDisplayerForUpdater:self.updater];
|
|
||||||
}
|
|
||||||
[self.updateAlert setVersionDisplayer:versDisp];
|
|
||||||
|
|
||||||
// If the app is a menubar app or the like, we need to focus it first and alter the
|
|
||||||
// update prompt to behave like a normal window. Otherwise if the window were hidden
|
|
||||||
// there may be no way for the application to be activated to make it visible again.
|
|
||||||
if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) {
|
|
||||||
[[self.updateAlert window] setHidesOnDeactivate:NO];
|
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only show the update alert if the app is active; otherwise, we'll wait until it is.
|
|
||||||
if ([NSApp isActive]) {
|
|
||||||
NSWindow *window = [self.updateAlert window];
|
|
||||||
if ([self shouldDisableKeyboardShortcutForInstallButton]) {
|
|
||||||
[self.updateAlert disableKeyboardShortcutForInstallButton];
|
|
||||||
}
|
|
||||||
[window makeKeyAndOrderFront:self];
|
|
||||||
} else
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)shouldDisableKeyboardShortcutForInstallButton {
|
- (BOOL)shouldDisableKeyboardShortcutForInstallButton {
|
||||||
@@ -135,7 +109,7 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SUOpenInfoURLChoice:
|
case SUOpenInfoURLChoice:
|
||||||
[[NSWorkspace sharedWorkspace] openURL:[self.updateItem infoURL]];
|
[[NSWorkspace sharedWorkspace] openURL:[self.updateItem releaseNotesURL]];
|
||||||
[self abortUpdate];
|
[self abortUpdate];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -152,18 +126,22 @@
|
|||||||
|
|
||||||
- (void)downloadUpdate
|
- (void)downloadUpdate
|
||||||
{
|
{
|
||||||
BOOL createdStatusController = NO;
|
id<SUUpdaterPrivate> updater = self.updater;
|
||||||
if (self.statusController == nil) {
|
if(![[updater delegate] suppressSparkleUI])
|
||||||
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
|
{
|
||||||
createdStatusController = YES;
|
BOOL createdStatusController = NO;
|
||||||
}
|
if (self.statusController == nil) {
|
||||||
|
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
|
||||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
createdStatusController = YES;
|
||||||
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
|
}
|
||||||
[self.statusController setButtonEnabled:YES];
|
|
||||||
|
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
||||||
if (createdStatusController) {
|
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
|
||||||
[self.statusController showWindow:self];
|
[self.statusController setButtonEnabled:YES];
|
||||||
|
|
||||||
|
if (createdStatusController) {
|
||||||
|
[self.statusController showWindow:self];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[super downloadUpdate];
|
[super downloadUpdate];
|
||||||
|
|||||||
Vendored
+6
@@ -53,6 +53,12 @@ SU_EXPORT @interface SUUpdater : NSObject
|
|||||||
*/
|
*/
|
||||||
- (instancetype)initForBundle:(NSBundle *)bundle;
|
- (instancetype)initForBundle:(NSBundle *)bundle;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Suppress sparkle UI. This should prevent any Sparkle UI from popping up.
|
||||||
|
Updates should be handled by the host.
|
||||||
|
*/
|
||||||
|
-(BOOL)suppressSparkleUI;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Explicitly checks for updates and displays a progress dialog while doing so.
|
Explicitly checks for updates and displays a progress dialog while doing so.
|
||||||
|
|
||||||
|
|||||||
Vendored
+19
-3
@@ -10,6 +10,7 @@
|
|||||||
#import "SUUpdaterDelegate.h"
|
#import "SUUpdaterDelegate.h"
|
||||||
#import "SUUpdaterPrivate.h"
|
#import "SUUpdaterPrivate.h"
|
||||||
|
|
||||||
|
#import "SUErrors.h"
|
||||||
#import "SUHost.h"
|
#import "SUHost.h"
|
||||||
#import "SUUpdatePermissionResponse.h"
|
#import "SUUpdatePermissionResponse.h"
|
||||||
#import "SUUpdatePermissionPrompt.h"
|
#import "SUUpdatePermissionPrompt.h"
|
||||||
@@ -283,7 +284,17 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
|
|||||||
- (void)checkForUpdatesInBackground
|
- (void)checkForUpdatesInBackground
|
||||||
{
|
{
|
||||||
// Do not use reachability for a preflight check. This can be deceptive and a bad idea. Apple does not recommend doing it.
|
// Do not use reachability for a preflight check. This can be deceptive and a bad idea. Apple does not recommend doing it.
|
||||||
SUUpdateDriver *theUpdateDriver = [[([self automaticallyDownloadsUpdates] ? [SUAutomaticUpdateDriver class] : [SUScheduledUpdateDriver class])alloc] initWithUpdater:self];
|
|
||||||
|
SUUpdateDriver *theUpdateDriver;
|
||||||
|
|
||||||
|
if ([self.delegate suppressSparkleUI])
|
||||||
|
{
|
||||||
|
theUpdateDriver = [[SUAutomaticUpdateDriver alloc] initWithUpdater:self];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
theUpdateDriver = [[SUScheduledUpdateDriver alloc] initWithUpdater:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[self checkForUpdatesWithDriver:theUpdateDriver];
|
[self checkForUpdatesWithDriver:theUpdateDriver];
|
||||||
}
|
}
|
||||||
@@ -307,6 +318,8 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
|
|||||||
|
|
||||||
- (void)installUpdatesIfAvailable
|
- (void)installUpdatesIfAvailable
|
||||||
{
|
{
|
||||||
|
// NSLog(@"[Sparkle installUpdatesIfAvailable]");
|
||||||
|
|
||||||
if (self.driver && [self.driver isInterruptible]) {
|
if (self.driver && [self.driver isInterruptible]) {
|
||||||
if ([self.driver resumeUpdateInteractively]) {
|
if ([self.driver resumeUpdateInteractively]) {
|
||||||
return;
|
return;
|
||||||
@@ -425,9 +438,12 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
|
|||||||
if (![SUSystemUpdateInfo systemAllowsAutomaticUpdatesForHost:self.host]) {
|
if (![SUSystemUpdateInfo systemAllowsAutomaticUpdatesForHost:self.host]) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, automatically downloading updates is allowed. Does the user want it?
|
// Otherwise, automatically downloading updates is allowed. Does the user want it?
|
||||||
return [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey];
|
|
||||||
|
BOOL automatic = [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey];
|
||||||
|
// NSLog(@"Automatic updates %@", automatic ? @"enabled" : @"disabled");
|
||||||
|
|
||||||
|
return automatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFeedURL:(NSURL *)feedURL
|
- (void)setFeedURL:(NSURL *)feedURL
|
||||||
|
|||||||
Vendored
+32
@@ -14,6 +14,13 @@
|
|||||||
|
|
||||||
#import "SUExport.h"
|
#import "SUExport.h"
|
||||||
|
|
||||||
|
typedef NS_ENUM(NSInteger, SUDUpdateAlertChoice) {
|
||||||
|
SUDInstallUpdateChoice,
|
||||||
|
SUDRemindMeLaterChoice,
|
||||||
|
SUDSkipThisVersionChoice,
|
||||||
|
SUDOpenInfoURLChoice
|
||||||
|
};
|
||||||
|
|
||||||
@protocol SUVersionComparison, SUVersionDisplay;
|
@protocol SUVersionComparison, SUVersionDisplay;
|
||||||
@class SUUpdater, SUAppcast, SUAppcastItem;
|
@class SUUpdater, SUAppcast, SUAppcastItem;
|
||||||
|
|
||||||
@@ -45,6 +52,12 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
|
|||||||
@protocol SUUpdaterDelegate <NSObject>
|
@protocol SUUpdaterDelegate <NSObject>
|
||||||
@optional
|
@optional
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Suppress sparkle UI. This should prevent any Sparkle UI from popping up.
|
||||||
|
Updates should be handled by the host.
|
||||||
|
*/
|
||||||
|
-(BOOL)suppressSparkleUI;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns whether to allow Sparkle to pop up.
|
Returns whether to allow Sparkle to pop up.
|
||||||
|
|
||||||
@@ -121,6 +134,16 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
|
|||||||
*/
|
*/
|
||||||
- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item;
|
- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Called when a valid update is found by the update driver and provides delegate ability to respond.
|
||||||
|
|
||||||
|
\param updater The SUUpdater instance.
|
||||||
|
\param item The appcast item corresponding to the update that is proposed to be installed.
|
||||||
|
\param responseBlock The block carrying the users response to update.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item respondWithChoice:(void (^)(SUDUpdateAlertChoice))responseBlock;
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Called when a valid update is not found.
|
Called when a valid update is not found.
|
||||||
|
|
||||||
@@ -253,6 +276,15 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
|
|||||||
*/
|
*/
|
||||||
- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation;
|
- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Called when an update is scheduled to be silently installed on quit. Swift compatible.
|
||||||
|
|
||||||
|
\param updater the SUUpdater instance.
|
||||||
|
\param item The appcast item corresponding to the udpate that is proposed to be installed.
|
||||||
|
\param restartBlock Can be used to trigger an immediate silent install and relaunch.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationBlock:(void (^)()) restartBlock;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Calls after an update that was scheduled to be silently installed on quit has been canceled.
|
Calls after an update that was scheduled to be silently installed on quit has been canceled.
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
@@ -20,4 +20,6 @@
|
|||||||
|
|
||||||
@property (strong, readonly) NSBundle *sparkleBundle;
|
@property (strong, readonly) NSBundle *sparkleBundle;
|
||||||
|
|
||||||
|
@property BOOL automaticallyDownloadsUpdates;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -7,48 +7,48 @@ import Foundation
|
|||||||
|
|
||||||
func loadPrivateKey(privateKeyPath: URL) throws -> SecKey {
|
func loadPrivateKey(privateKeyPath: URL) throws -> SecKey {
|
||||||
let data = try Data(contentsOf: privateKeyPath);
|
let data = try Data(contentsOf: privateKeyPath);
|
||||||
|
|
||||||
var cfitems: CFArray? = nil;
|
var cfitems: CFArray? = nil;
|
||||||
var format = SecExternalFormat.formatOpenSSL;
|
var format = SecExternalFormat.formatOpenSSL;
|
||||||
var type = SecExternalItemType.itemTypePrivateKey;
|
var type = SecExternalItemType.itemTypePrivateKey;
|
||||||
|
|
||||||
let status = SecItemImport(data as CFData, nil, &format, &type, SecItemImportExportFlags(rawValue: UInt32(0)), nil, nil, &cfitems);
|
let status = SecItemImport(data as CFData, nil, &format, &type, SecItemImportExportFlags(rawValue: UInt32(0)), nil, nil, &cfitems);
|
||||||
if (status != errSecSuccess || cfitems == nil) {
|
if (status != errSecSuccess || cfitems == nil) {
|
||||||
print("Private DSA key could not be imported", status);
|
print("Private DSA key could not be imported", status);
|
||||||
throw NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(SUError.signatureError.rawValue)), userInfo: nil);
|
throw NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(SUError.signatureError.rawValue)), userInfo: nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format != SecExternalFormat.formatOpenSSL || type != SecExternalItemType.itemTypePrivateKey) {
|
if (format != SecExternalFormat.formatOpenSSL || type != SecExternalItemType.itemTypePrivateKey) {
|
||||||
throw makeError(code: .signatureError, "Not an OpensSSL private key \(format) \(type)");
|
throw makeError(code: .signatureError, "Not an OpensSSL private key \(format) \(type)");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (cfitems as! NSArray)[0] as! SecKey;
|
return (cfitems as! NSArray)[0] as! SecKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
func dsaSignature(path: URL, privateKey: SecKey) throws -> String {
|
func dsaSignature(path: URL, privateKey: SecKey) throws -> String {
|
||||||
|
|
||||||
var error: Unmanaged<CFError>?;
|
var error: Unmanaged<CFError>?;
|
||||||
|
|
||||||
let stream = InputStream(fileAtPath:path.path)!;
|
let stream = InputStream(fileAtPath:path.path)!;
|
||||||
let dataReadTransform = SecTransformCreateReadTransformWithReadStream(stream);
|
let dataReadTransform = SecTransformCreateReadTransformWithReadStream(stream);
|
||||||
|
|
||||||
let dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA1, 20, nil);
|
let dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA1, 20, nil);
|
||||||
guard let dataSignTransform = SecSignTransformCreate(privateKey, &error) else {
|
guard let dataSignTransform = SecSignTransformCreate(privateKey, &error) else {
|
||||||
print("can't use the key");
|
print("can't use the key");
|
||||||
throw error!.takeRetainedValue();
|
throw error!.takeRetainedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
let group = SecTransformCreateGroupTransform();
|
let group = SecTransformCreateGroupTransform();
|
||||||
SecTransformConnectTransforms(dataReadTransform, kSecTransformOutputAttributeName, dataDigestTransform, kSecTransformInputAttributeName, group, &error);
|
SecTransformConnectTransforms(dataReadTransform, kSecTransformOutputAttributeName, dataDigestTransform, kSecTransformInputAttributeName, group, &error);
|
||||||
if (error != nil) {
|
if (error != nil) {
|
||||||
throw error!.takeRetainedValue();
|
throw error!.takeRetainedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
SecTransformConnectTransforms(dataDigestTransform, kSecTransformOutputAttributeName, dataSignTransform, kSecTransformInputAttributeName, group, &error);
|
SecTransformConnectTransforms(dataDigestTransform, kSecTransformOutputAttributeName, dataSignTransform, kSecTransformInputAttributeName, group, &error);
|
||||||
if (error != nil) {
|
if (error != nil) {
|
||||||
throw error!.takeRetainedValue();
|
throw error!.takeRetainedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = SecTransformExecute(group, &error) as! Data;
|
let result = SecTransformExecute(group, &error) as! Data;
|
||||||
return result.base64EncodedString();
|
return result.base64EncodedString();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user