wtapack 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 582fce026d80e037dc9bf7c3e9f60586fb244799
4
- data.tar.gz: 33149c929abcde295969cd485ed36ffb8be8807b
3
+ metadata.gz: 5d9d3202419f6b5d1b8aba806fe18f57bf17a3ff
4
+ data.tar.gz: 123691c4df2057a07ac140d66245928cfd545a48
5
5
  SHA512:
6
- metadata.gz: 29aeddab1aa2f895fe6d0502405d690496f5e95fad9bc603ae9b04e677f65d1889e625100e69b4ce080c4caf84daa7a701fbc4e7f66c9dceb90f7a5439e8688d
7
- data.tar.gz: 34078f7ee1b7f2c1fabfa1f02c0789f08f6a26427435438a5043af9627f43d571308b387af34537598e8b2942b16423382086cc2f66e7202d33196a3c38d59b5
6
+ metadata.gz: 1db327a69e835829946d7fa69a6409e69fada91196a8b2f31bb0aa74400c0abd0ccf0e0be85ad743b479c24c76329e6d1ec63ba556def403a711aabbd68605cb
7
+ data.tar.gz: 1688b56921229a0c7817e317f14df167a336e192a7a1d29bb176a4096e90ae5a12d164166d0014f5c3adb1bd82d978a36f42efd20970c77e2ce64e44016b9644
@@ -13,3 +13,5 @@
13
13
  + (void)signFramework:(NSURL*)frameworkURL;
14
14
  + (void)reset;
15
15
  @end
16
+
17
+ BOOL validateSigningIdentity(NSString* identity);
@@ -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
- //void validateSigningIdentity(NSString* identity)
112
- //{
113
- // NSDictionary* query = @{ (__bridge id)kSecClass : (__bridge id)kSecClassCertificate,
114
- // (__bridge id)kSecReturnRef : (__bridge id)kCFBooleanTrue,
115
- // (__bridge id)kSecMatchLimit : (__bridge id)kSecMatchLimitAll };
116
- //
117
- // CFTypeRef result = NULL;
118
- // OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)(query), &result);
119
- // if (status)
120
- // {
121
- // CFStringRef errorString = SecCopyErrorMessageString(status, 0);
122
- // NSLog(@"status is %@, result is %@", errorString, (__bridge id)result);
123
- // CFRelease(errorString);
124
- // [ErrorHandler fatalErrorWithMessage:@"Could not find signing identity"
125
- // exitCode:status];
126
- // }
127
- //
128
- // BOOL certificateFound = NO;
129
- //
130
- // for (id certificate in (__bridge NSArray*)result)
131
- // {
132
- // CFErrorRef error = NULL;
133
- // SecCertificateRef certificateRef = (__bridge SecCertificateRef)certificate;
134
- // SecTransformRef transformRef = SecDigestTransformCreate(kSecDigestSHA1, 0, &error);
135
- // CFDataRef certData = SecCertificateCopyData(certificateRef);
136
- // SecTransformSetAttribute(transformRef, kSecTransformInputAttributeName, certData, &error);
137
- // if (error)
138
- // {
139
- // NSLog(@"%@", (__bridge NSError*)error);
140
- // }
141
- // CFDataRef output = SecTransformExecute(transformRef, &error);
142
- // if (error)
143
- // {
144
- // NSLog(@"%@", (__bridge NSError*)error);
145
- // }
146
- // CFRelease(certData);
147
- //
148
- // NSData* outputData = (__bridge NSData*)output;
149
- //
150
- // NSCharacterSet* greaterLessSet = [NSCharacterSet characterSetWithCharactersInString:@"<>"];
151
- // NSString* description = [[outputData.description stringByTrimmingCharactersInSet:greaterLessSet] stringByReplacingOccurrencesOfString:@" "
152
- // withString:@""];
153
- // CFRelease(output);
154
- // CFRelease(transformRef);
155
- // if(error)
156
- // {
157
- // CFRelease(error);
158
- // }
159
- //
160
- // if ([description compare:identity options:NSCaseInsensitiveSearch] == NSOrderedSame)
161
- // {
162
- // SecTrustRef trustRef = NULL;
163
- // SecPolicyRef policyRef = SecPolicyCreateBasicX509();
164
- // status = SecTrustCreateWithCertificates(certificateRef, policyRef, &trustRef);
165
- // if (status)
166
- // {
167
- // CFStringRef errorString = SecCopyErrorMessageString(status, 0);
168
- // NSLog(@"%@", errorString);
169
- // CFRelease(errorString);
170
- // }
171
- // SecTrustResultType trustResult;
172
- // status = SecTrustEvaluate(trustRef, &trustResult);
173
- // if (status)
174
- // {
175
- // CFStringRef errorString = SecCopyErrorMessageString(status, 0);
176
- // NSLog(@"%@", errorString);
177
- // CFRelease(errorString);
178
- // }
179
- //
180
- // if ((trustResult != kSecTrustResultDeny) &&
181
- // (trustResult != kSecTrustResultFatalTrustFailure) &&
182
- // (trustResult != kSecTrustResultInvalid) &&
183
- // (trustResult != kSecTrustResultOtherError) &&
184
- // (trustResult != kSecTrustResultRecoverableTrustFailure))
185
- // {
186
- // certificateFound = YES;
187
- // }
188
- // CFRelease(certificateRef);
189
- // CFRelease(trustRef);
190
- // CFRelease(policyRef);
191
- // break;
192
- // }
193
- //
194
- // CFRelease(certificateRef);
195
- //
196
- // }
197
- //
198
- // if (!certificateFound)
199
- // {
200
- // [ErrorHandler fatalErrorWithMessage:[NSString stringWithFormat:@"No valid certificate with SHA1 %@ found", identity]
201
- // exitCode:EX_DATAERR];
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
@@ -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.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