wtapack 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/wtapack/CodeSigner.h +2 -0
- data/ext/wtapack/CodeSigner.m +93 -97
- data/ext/wtapack/CodeSigner_c.h +17 -0
- data/ext/wtapack/wtapack.c +10 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d9d3202419f6b5d1b8aba806fe18f57bf17a3ff
|
4
|
+
data.tar.gz: 123691c4df2057a07ac140d66245928cfd545a48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1db327a69e835829946d7fa69a6409e69fada91196a8b2f31bb0aa74400c0abd0ccf0e0be85ad743b479c24c76329e6d1ec63ba556def403a711aabbd68605cb
|
7
|
+
data.tar.gz: 1688b56921229a0c7817e317f14df167a336e192a7a1d29bb176a4096e90ae5a12d164166d0014f5c3adb1bd82d978a36f42efd20970c77e2ce64e44016b9644
|
data/ext/wtapack/CodeSigner.h
CHANGED
data/ext/wtapack/CodeSigner.m
CHANGED
@@ -9,8 +9,7 @@
|
|
9
9
|
#import "CodeSigner.h"
|
10
10
|
#import <objc/runtime.h>
|
11
11
|
#import "ErrorHandler.h"
|
12
|
-
|
13
|
-
void validateSigningIdentity(NSString* identity);
|
12
|
+
#import "CodeSigner_c.h"
|
14
13
|
|
15
14
|
@implementation CodeSigner
|
16
15
|
+ (NSString*)signingIdentity
|
@@ -102,102 +101,99 @@ void validateSigningIdentity(NSString* identity);
|
|
102
101
|
}
|
103
102
|
@end
|
104
103
|
|
105
|
-
// It turned out the Rakefile already does the below, so no point in doing it twice.
|
106
|
-
|
107
104
|
// So the lesson of this function is that the keychain API is very confusing and difficult
|
108
105
|
// to work with. This function loops through all the certificates in the keychain, and checks the
|
109
106
|
// SHA1 digest (which has to be calculated, it cannot be gotten from the keychain API directly)
|
110
107
|
// against the one passed in. If it finds a match, it verifies that the certificate is trusted.
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
//}
|
108
|
+
BOOL validateSigningIdentity(NSString* identity)
|
109
|
+
{
|
110
|
+
NSDictionary* query = @{ (__bridge id)kSecClass : (__bridge id)kSecClassCertificate,
|
111
|
+
(__bridge id)kSecReturnRef : (__bridge id)kCFBooleanTrue,
|
112
|
+
(__bridge id)kSecMatchLimit : (__bridge id)kSecMatchLimitAll };
|
113
|
+
|
114
|
+
CFTypeRef result = NULL;
|
115
|
+
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)(query), &result);
|
116
|
+
if (status)
|
117
|
+
{
|
118
|
+
CFStringRef errorString = SecCopyErrorMessageString(status, 0);
|
119
|
+
NSLog(@"status is %@, result is %@", errorString, (__bridge id)result);
|
120
|
+
CFRelease(errorString);
|
121
|
+
return NO;
|
122
|
+
}
|
123
|
+
|
124
|
+
BOOL certificateFound = NO;
|
125
|
+
|
126
|
+
for (id certificate in (__bridge NSArray*)result)
|
127
|
+
{
|
128
|
+
CFErrorRef error = NULL;
|
129
|
+
SecCertificateRef certificateRef = (__bridge SecCertificateRef)certificate;
|
130
|
+
SecTransformRef transformRef = SecDigestTransformCreate(kSecDigestSHA1, 0, &error);
|
131
|
+
CFDataRef certData = SecCertificateCopyData(certificateRef);
|
132
|
+
SecTransformSetAttribute(transformRef, kSecTransformInputAttributeName, certData, &error);
|
133
|
+
if (error)
|
134
|
+
{
|
135
|
+
NSLog(@"%@", (__bridge NSError*)error);
|
136
|
+
}
|
137
|
+
CFDataRef output = SecTransformExecute(transformRef, &error);
|
138
|
+
if (error)
|
139
|
+
{
|
140
|
+
NSLog(@"%@", (__bridge NSError*)error);
|
141
|
+
}
|
142
|
+
CFRelease(certData);
|
143
|
+
|
144
|
+
NSData* outputData = (__bridge NSData*)output;
|
145
|
+
|
146
|
+
NSCharacterSet* greaterLessSet = [NSCharacterSet characterSetWithCharactersInString:@"<>"];
|
147
|
+
NSString* description = [[outputData.description stringByTrimmingCharactersInSet:greaterLessSet] stringByReplacingOccurrencesOfString:@" "
|
148
|
+
withString:@""];
|
149
|
+
CFRelease(output);
|
150
|
+
CFRelease(transformRef);
|
151
|
+
if(error)
|
152
|
+
{
|
153
|
+
CFRelease(error);
|
154
|
+
}
|
155
|
+
|
156
|
+
if ([description compare:identity options:NSCaseInsensitiveSearch] == NSOrderedSame)
|
157
|
+
{
|
158
|
+
SecTrustRef trustRef = NULL;
|
159
|
+
SecPolicyRef policyRef = SecPolicyCreateBasicX509();
|
160
|
+
status = SecTrustCreateWithCertificates(certificateRef, policyRef, &trustRef);
|
161
|
+
if (status)
|
162
|
+
{
|
163
|
+
CFStringRef errorString = SecCopyErrorMessageString(status, 0);
|
164
|
+
NSLog(@"%@", errorString);
|
165
|
+
CFRelease(errorString);
|
166
|
+
}
|
167
|
+
SecTrustResultType trustResult;
|
168
|
+
status = SecTrustEvaluate(trustRef, &trustResult);
|
169
|
+
if (status)
|
170
|
+
{
|
171
|
+
CFStringRef errorString = SecCopyErrorMessageString(status, 0);
|
172
|
+
NSLog(@"%@", errorString);
|
173
|
+
CFRelease(errorString);
|
174
|
+
}
|
175
|
+
|
176
|
+
if ((trustResult != kSecTrustResultDeny) &&
|
177
|
+
(trustResult != kSecTrustResultFatalTrustFailure) &&
|
178
|
+
(trustResult != kSecTrustResultInvalid) &&
|
179
|
+
(trustResult != kSecTrustResultOtherError) &&
|
180
|
+
(trustResult != kSecTrustResultRecoverableTrustFailure))
|
181
|
+
{
|
182
|
+
certificateFound = YES;
|
183
|
+
}
|
184
|
+
CFRelease(certificateRef);
|
185
|
+
CFRelease(trustRef);
|
186
|
+
CFRelease(policyRef);
|
187
|
+
break;
|
188
|
+
}
|
189
|
+
|
190
|
+
CFRelease(certificateRef);
|
191
|
+
|
192
|
+
}
|
193
|
+
return certificateFound;
|
194
|
+
}
|
195
|
+
|
196
|
+
bool verifyCert(const char* cert_SHA1)
|
197
|
+
{
|
198
|
+
return validateSigningIdentity([NSString stringWithUTF8String: cert_SHA1]);
|
199
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
//
|
2
|
+
// CodeSigner_c.h
|
3
|
+
// WTAPackageApplication
|
4
|
+
//
|
5
|
+
// Created by Robert Thompson on 10/13/14.
|
6
|
+
// Copyright (c) 2014 WillowTree Apps. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef CODESIGNER_C_H
|
10
|
+
#define CODESIGNER_C_H
|
11
|
+
|
12
|
+
#include <stdint.h>
|
13
|
+
#include <stdbool.h>
|
14
|
+
|
15
|
+
bool verifyCert(const char* cert_SHA1);
|
16
|
+
|
17
|
+
#endif
|
data/ext/wtapack/wtapack.c
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include "main.h"
|
3
|
+
#include "CodeSigner_c.h"
|
3
4
|
|
4
5
|
static VALUE hello_world(VALUE mod)
|
5
6
|
{
|
@@ -23,10 +24,19 @@ static VALUE native_pack(VALUE mod, VALUE argc, VALUE argv)
|
|
23
24
|
return rb_main(NUM2INT(argc), real_argv);
|
24
25
|
}
|
25
26
|
|
27
|
+
static VALUE verify_identity(VALUE mod, VALUE identity_SHA1)
|
28
|
+
{
|
29
|
+
struct RString* cert_SHA1_string = RSTRING(identity_SHA1);
|
30
|
+
bool result = verifyCert(RSTRING_PTR(cert_SHA1_string));
|
31
|
+
|
32
|
+
return result ? Qtrue : Qfalse;
|
33
|
+
}
|
34
|
+
|
26
35
|
void Init_wtapack()
|
27
36
|
{
|
28
37
|
VALUE mWtapack = rb_define_module("Wtapack");
|
29
38
|
rb_define_singleton_method(mWtapack, "hello_world", hello_world, 0);
|
30
39
|
rb_define_singleton_method(mWtapack, "native_pack", native_pack, 2);
|
40
|
+
rb_define_singleton_method(mWtapack, "verify_identity", verify_identity, 1);
|
31
41
|
}
|
32
42
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wtapack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Thompson
|
@@ -34,6 +34,7 @@ extra_rdoc_files: []
|
|
34
34
|
files:
|
35
35
|
- ext/wtapack/CodeSigner.h
|
36
36
|
- ext/wtapack/CodeSigner.m
|
37
|
+
- ext/wtapack/CodeSigner_c.h
|
37
38
|
- ext/wtapack/ErrorHandler.h
|
38
39
|
- ext/wtapack/ErrorHandler.m
|
39
40
|
- ext/wtapack/NSArray+WTAMap.h
|