mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Make SecKeyRef as needed
This commit is contained in:
1 parent
68856e074b
commit
1006326157
1 file changed
+23
-13
Vendored
+23
-13
@@ -20,10 +20,15 @@
|
|||||||
|
|
||||||
#include "AppKitPrevention.h"
|
#include "AppKitPrevention.h"
|
||||||
|
|
||||||
|
@interface SUSignatureVerifier ()
|
||||||
|
@property (readonly) SUPublicKeys *pubKeys;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation SUSignatureVerifier {
|
@implementation SUSignatureVerifier {
|
||||||
SecKeyRef _secKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@synthesize pubKeys = _pubKeys;
|
||||||
|
|
||||||
+ (BOOL)validatePath:(NSString *)path withSignatures:(SUSignatures *)signatures withPublicKeys:(SUPublicKeys *)pkeys
|
+ (BOOL)validatePath:(NSString *)path withSignatures:(SUSignatures *)signatures withPublicKeys:(SUPublicKeys *)pkeys
|
||||||
{
|
{
|
||||||
if (!signatures || !signatures.dsaSignature) {
|
if (!signatures || !signatures.dsaSignature) {
|
||||||
@@ -52,8 +57,14 @@
|
|||||||
- (instancetype)initWithPublicKeys:(SUPublicKeys *)pubkeys
|
- (instancetype)initWithPublicKeys:(SUPublicKeys *)pubkeys
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
_pubKeys = pubkeys;
|
||||||
|
|
||||||
NSData *data = [pubkeys.dsaPubKey dataUsingEncoding:NSASCIIStringEncoding];
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (SecKeyRef)dsaSecKeyRef {
|
||||||
|
|
||||||
|
NSData *data = [self.pubKeys.dsaPubKey dataUsingEncoding:NSASCIIStringEncoding];
|
||||||
if (!self || !data.length) {
|
if (!self || !data.length) {
|
||||||
SULog(SULogLevelError, @"Could not read public DSA key");
|
SULog(SULogLevelError, @"Could not read public DSA key");
|
||||||
return nil;
|
return nil;
|
||||||
@@ -72,26 +83,19 @@
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SecKeyRef dsaPubKeySecKey = nil;
|
||||||
if (format == kSecFormatOpenSSL && itemType == kSecItemTypePublicKey && CFArrayGetCount(items) == 1) {
|
if (format == kSecFormatOpenSSL && itemType == kSecItemTypePublicKey && CFArrayGetCount(items) == 1) {
|
||||||
// Seems silly, but we can't quiet the warning about dropping CFTypeRef's const qualifier through
|
// 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
|
// 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.
|
// warning is on by default with -Weverything and apparently became more noisy as of Xcode 7.
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wcast-qual"
|
#pragma clang diagnostic ignored "-Wcast-qual"
|
||||||
_secKey = (SecKeyRef)CFRetain(CFArrayGetValueAtIndex(items, 0));
|
dsaPubKeySecKey = (SecKeyRef)CFRetain(CFArrayGetValueAtIndex(items, 0));
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(items);
|
CFRelease(items);
|
||||||
|
return dsaPubKeySecKey;
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)dealloc
|
|
||||||
{
|
|
||||||
if (_secKey) {
|
|
||||||
CFRelease(_secKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)verifyFileAtPath:(NSString *)path signatures:(SUSignatures *)signatures
|
- (BOOL)verifyFileAtPath:(NSString *)path signatures:(SUSignatures *)signatures
|
||||||
@@ -112,6 +116,11 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SecKeyRef dsaPubKeySecKey = [self dsaSecKeyRef];
|
||||||
|
if (!dsaPubKeySecKey) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
__block SecGroupTransformRef group = SecTransformCreateGroupTransform();
|
__block SecGroupTransformRef group = SecTransformCreateGroupTransform();
|
||||||
__block SecTransformRef dataReadTransform = NULL;
|
__block SecTransformRef dataReadTransform = NULL;
|
||||||
__block SecTransformRef dataDigestTransform = NULL;
|
__block SecTransformRef dataDigestTransform = NULL;
|
||||||
@@ -124,6 +133,7 @@
|
|||||||
if (dataDigestTransform) CFRelease(dataDigestTransform);
|
if (dataDigestTransform) CFRelease(dataDigestTransform);
|
||||||
if (dataVerifyTransform) CFRelease(dataVerifyTransform);
|
if (dataVerifyTransform) CFRelease(dataVerifyTransform);
|
||||||
if (error) CFRelease(error);
|
if (error) CFRelease(error);
|
||||||
|
if (dsaPubKeySecKey) CFRelease(dsaPubKeySecKey);
|
||||||
return NO;
|
return NO;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -140,7 +150,7 @@
|
|||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
||||||
dataVerifyTransform = SecVerifyTransformCreate(_secKey, (__bridge CFDataRef)dsaSignature, &error);
|
dataVerifyTransform = SecVerifyTransformCreate(dsaPubKeySecKey, (__bridge CFDataRef)dsaSignature, &error);
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
if (!dataVerifyTransform || error) {
|
if (!dataVerifyTransform || error) {
|
||||||
SULog(SULogLevelError, @"Could not understand format of the signature: %@; Signature data: %@", error, dsaSignature);
|
SULog(SULogLevelError, @"Could not understand format of the signature: %@; Signature data: %@", error, dsaSignature);
|
||||||
|
|||||||
Reference in new issue
Block a user