forked from sparkle-project/Sparkle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Holy restructuring, batman! Watch out for falling folders.
- Loading branch information
andym
committed
Jul 10, 2007
0 parents
commit 9fa3da5
Showing
42 changed files
with
4,181 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>English</string> | ||
<key>CFBundleExecutable</key> | ||
<string>${EXECUTABLE_NAME}</string> | ||
<key>CFBundleName</key> | ||
<string>${PRODUCT_NAME}</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>org.andymatuschak.Sparkle</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundlePackageType</key> | ||
<string>FMWK</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1.1</string> | ||
<key>NSPrincipalClass</key> | ||
<string></string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2006 Andy Matuschak | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.PHONY: all localizable-strings | ||
|
||
localizable-strings: | ||
rm English.lproj/Sparkle.strings || TRUE | ||
genstrings -o English.lproj -s SULocalizedString *.m *.h | ||
mv English.lproj/Localizable.strings English.lproj/Sparkle.strings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// NSApplication+AppCopies.h | ||
// Sparkle | ||
// | ||
// Created by Andy Matuschak on 3/16/06. | ||
// Copyright 2006 Andy Matuschak. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface NSApplication (SUAppCopies) | ||
- (int)copiesRunning; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// NSApplication+AppCopies.m | ||
// Sparkle | ||
// | ||
// Created by Andy Matuschak on 3/16/06. | ||
// Copyright 2006 Andy Matuschak. All rights reserved. | ||
// | ||
|
||
#import "NSApplication+AppCopies.h" | ||
#import "SUUtilities.h" | ||
|
||
@implementation NSApplication (SUAppCopies) | ||
|
||
- (int)copiesRunning | ||
{ | ||
id appEnumerator = [[[NSWorkspace sharedWorkspace] launchedApplications] objectEnumerator], currentApp; | ||
int count = 0; | ||
while ((currentApp = [appEnumerator nextObject])) | ||
{ | ||
// Potential gotcha: the new version of your app better have the same NSApplicationName. | ||
if([[currentApp objectForKey:@"NSApplicationName"] isEqualToString:SUHostAppName()]) | ||
count++; | ||
} | ||
return count; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// | ||
// NSFileManager+Authentication.m | ||
// Sparkle | ||
// | ||
// Created by Andy Matuschak on 3/9/06. | ||
// Copyright 2006 Andy Matuschak. All rights reserved. | ||
// | ||
|
||
@interface NSFileManager (SUAuthenticationAdditions) | ||
- (BOOL)movePathWithAuthentication:(NSString *)src toPath:(NSString *)dst; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// NSFileManager+Authentication.m | ||
// Sparkle | ||
// | ||
// Created by Andy Matuschak on 3/9/06. | ||
// Copyright 2006 Andy Matuschak. All rights reserved. | ||
// | ||
|
||
// This code based on generous contribution from Allan Odgaard. Thanks, Allan! | ||
|
||
#import "sys/stat.h" | ||
#import <Security/Security.h> | ||
|
||
#import <unistd.h> | ||
#import <sys/stat.h> | ||
#import <dirent.h> | ||
|
||
@implementation NSFileManager (SUAuthenticationAdditions) | ||
|
||
- (BOOL)currentUserOwnsPath:(NSString *)oPath | ||
{ | ||
char *path = (char *)[oPath fileSystemRepresentation]; | ||
unsigned int uid = getuid(); | ||
bool res = false; | ||
struct stat sb; | ||
if(stat(path, &sb) == 0) | ||
{ | ||
if(sb.st_uid == uid) | ||
{ | ||
res = true; | ||
if(sb.st_mode & S_IFDIR) | ||
{ | ||
DIR* dir = opendir(path); | ||
struct dirent* entry = NULL; | ||
while(res && (entry = readdir(dir))) | ||
{ | ||
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) | ||
continue; | ||
|
||
char descend[strlen(path) + 1 + entry->d_namlen + 1]; | ||
strcpy(descend, path); | ||
strcat(descend, "/"); | ||
strcat(descend, entry->d_name); | ||
res = [self currentUserOwnsPath:[NSString stringWithUTF8String:descend]]; | ||
} | ||
closedir(dir); | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
|
||
- (BOOL)_movePathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst | ||
{ | ||
NSString *tmp = [[[dst stringByDeletingPathExtension] stringByAppendingString:@".old"] stringByAppendingPathExtension:[dst pathExtension]]; | ||
BOOL res = NO; | ||
struct stat sb; | ||
if((stat([src UTF8String], &sb) != 0) || (stat([tmp UTF8String], &sb) == 0) || stat([dst UTF8String], &sb) != 0) | ||
return false; | ||
|
||
char* buf = NULL; | ||
asprintf(&buf, | ||
"mv -f \"$DST_PATH\" \"$TMP_PATH\" && " | ||
"mv -f \"$SRC_PATH\" \"$DST_PATH\" && " | ||
"rm -rf \"$TMP_PATH\" && " | ||
"chown -R %d:%d \"$DST_PATH\"", | ||
sb.st_uid, sb.st_gid); | ||
|
||
if(!buf) | ||
return false; | ||
|
||
AuthorizationRef auth; | ||
if(AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth) == errAuthorizationSuccess) | ||
{ | ||
setenv("SRC_PATH", [src UTF8String], 1); | ||
setenv("DST_PATH", [dst UTF8String], 1); | ||
setenv("TMP_PATH", [tmp UTF8String], 1); | ||
sig_t oldSigChildHandler = signal(SIGCHLD, SIG_DFL); | ||
char const* arguments[] = { "-c", buf, NULL }; | ||
if(AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, (char**)arguments, NULL) == errAuthorizationSuccess) | ||
{ | ||
int status; | ||
int pid = wait(&status); | ||
if(pid != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0) | ||
res = YES; | ||
} | ||
signal(SIGCHLD, oldSigChildHandler); | ||
} | ||
AuthorizationFree(auth, 0); | ||
free(buf); | ||
return res; | ||
} | ||
|
||
- (BOOL)movePathWithAuthentication:(NSString *)src toPath:(NSString *)dst | ||
{ | ||
if ([[NSFileManager defaultManager] isWritableFileAtPath:dst] && [[NSFileManager defaultManager] isWritableFileAtPath:[dst stringByDeletingLastPathComponent]]) | ||
{ | ||
int tag = 0; | ||
BOOL result = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[dst stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[dst lastPathComponent]] tag:&tag]; | ||
result &= [[NSFileManager defaultManager] movePath:src toPath:dst handler:NULL]; | ||
return result; | ||
} | ||
else | ||
{ | ||
return [self _movePathWithForcedAuthentication:src toPath:dst]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// NSFileManager+Verification.h | ||
// Sparkle | ||
// | ||
// Created by Andy Matuschak on 3/16/06. | ||
// Copyright 2006 Andy Matuschak. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
// For the paranoid folks! | ||
@interface NSFileManager (SUVerification) | ||
- (BOOL)validatePath:(NSString *)path withMD5Hash:(NSString *)hash; | ||
- (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// | ||
// NSFileManager+Verification.m | ||
// Sparkle | ||
// | ||
// Created by Andy Matuschak on 3/16/06. | ||
// Copyright 2006 Andy Matuschak. All rights reserved. | ||
// | ||
|
||
// DSA stuff adapted from code provided by Allan Odgaard. Thanks, Allan! | ||
|
||
#import "NSFileManager+Verification.h" | ||
#import "SUUtilities.h" | ||
#import "md5.h" | ||
|
||
#import <stdio.h> | ||
#import <openssl/evp.h> | ||
#import <openssl/bio.h> | ||
#import <openssl/pem.h> | ||
#import <openssl/rsa.h> | ||
#import <openssl/sha.h> | ||
|
||
int b64decode(unsigned char* str) | ||
{ | ||
unsigned char *cur, *start; | ||
int d, dlast, phase; | ||
unsigned char c; | ||
static int table[256] = { | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 00-0F */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 10-1F */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, /* 20-2F */ | ||
52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, /* 30-3F */ | ||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, /* 40-4F */ | ||
15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, /* 50-5F */ | ||
-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, /* 60-6F */ | ||
41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, /* 70-7F */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-8F */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 90-9F */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* A0-AF */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* B0-BF */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* C0-CF */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* D0-DF */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* E0-EF */ | ||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */ | ||
}; | ||
|
||
d = dlast = phase = 0; | ||
start = str; | ||
for (cur = str; *cur != '\0'; ++cur ) | ||
{ | ||
if(*cur == '\n' || *cur == '\r'){phase = dlast = 0; continue;} | ||
d = table[(int)*cur]; | ||
if(d != -1) | ||
{ | ||
switch(phase) | ||
{ | ||
case 0: | ||
++phase; | ||
break; | ||
case 1: | ||
c = ((dlast << 2) | ((d & 0x30) >> 4)); | ||
*str++ = c; | ||
++phase; | ||
break; | ||
case 2: | ||
c = (((dlast & 0xf) << 4) | ((d & 0x3c) >> 2)); | ||
*str++ = c; | ||
++phase; | ||
break; | ||
case 3: | ||
c = (((dlast & 0x03 ) << 6) | d); | ||
*str++ = c; | ||
phase = 0; | ||
break; | ||
} | ||
dlast = d; | ||
} | ||
} | ||
*str = '\0'; | ||
return str - start; | ||
} | ||
|
||
EVP_PKEY* load_dsa_key(char *key) | ||
{ | ||
EVP_PKEY* pkey = NULL; | ||
BIO *bio; | ||
if((bio = BIO_new_mem_buf(key, strlen(key)))) | ||
{ | ||
DSA* dsa_key = 0; | ||
if(PEM_read_bio_DSA_PUBKEY(bio, &dsa_key, NULL, NULL)) | ||
{ | ||
if((pkey = EVP_PKEY_new())) | ||
{ | ||
if(EVP_PKEY_assign_DSA(pkey, dsa_key) != 1) | ||
{ | ||
DSA_free(dsa_key); | ||
EVP_PKEY_free(pkey); | ||
pkey = NULL; | ||
} | ||
} | ||
} | ||
BIO_free(bio); | ||
} | ||
return pkey; | ||
} | ||
|
||
@implementation NSFileManager (SUVerification) | ||
|
||
- (BOOL)validatePath:(NSString *)path withMD5Hash:(NSString *)hash | ||
{ | ||
NSData *data = [NSData dataWithContentsOfFile:path]; | ||
if (!data) { return NO; } | ||
|
||
md5_state_t md5_state; | ||
md5_init(&md5_state); | ||
md5_append(&md5_state, [data bytes], [data length]); | ||
unsigned char digest[16]; | ||
md5_finish(&md5_state, digest); | ||
|
||
int di; | ||
char hexDigest[32]; | ||
for (di = 0; di < 16; di++) | ||
sprintf(hexDigest + di*2, "%02x", digest[di]); | ||
|
||
return [hash isEqualToString:[NSString stringWithCString:hexDigest]]; | ||
} | ||
|
||
- (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature | ||
{ | ||
EVP_PKEY* pkey; | ||
if(!encodedSignature || !SUInfoValueForKey(SUPublicDSAKeyKey) || !(pkey = load_dsa_key((char *)[SUInfoValueForKey(SUPublicDSAKeyKey) UTF8String]))) | ||
return NO; | ||
|
||
// Now, the signature is in base64; we have to decode it into a binary stream. | ||
unsigned char *signature = (unsigned char *)[encodedSignature UTF8String]; | ||
long length = b64decode(signature); | ||
|
||
NSData *pathData = [NSData dataWithContentsOfFile:path]; | ||
if (!pathData) { return NO; } | ||
unsigned char md[SHA_DIGEST_LENGTH]; | ||
SHA1([pathData bytes], [pathData length], md); | ||
|
||
BOOL res = false; | ||
EVP_MD_CTX ctx; | ||
if(EVP_VerifyInit(&ctx, EVP_dss1()) == 1) | ||
{ | ||
EVP_VerifyUpdate(&ctx, md, SHA_DIGEST_LENGTH); | ||
res = EVP_VerifyFinal(&ctx, signature, length, pkey) == 1; | ||
} | ||
EVP_PKEY_free(pkey); | ||
return res; | ||
} | ||
|
||
@end |
Oops, something went wrong.