Skip to content

Commit

Permalink
cer record
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakey committed Feb 27, 2017
1 parent eebcbac commit fd70dac
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 49 deletions.
14 changes: 14 additions & 0 deletions SmartPush.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
A276B6FC1AB53781009EF649 /* HelpViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A276B6FB1AB53781009EF649 /* HelpViewController.m */; };
A276B6FF1AB53816009EF649 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A276B6FE1AB53816009EF649 /* Cocoa.framework */; };
A276B7011AB5381B009EF649 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A276B7001AB5381B009EF649 /* WebKit.framework */; };
B89258D91E63C831005E9F27 /* Sec.m in Sources */ = {isa = PBXBuildFile; fileRef = B89258D81E63C831005E9F27 /* Sec.m */; };
B8F2D8FF1E5D1D320029D63C /* SecManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B8F2D8FE1E5D1D320029D63C /* SecManager.m */; };
B8F2D9021E5D2B600029D63C /* DragPopUpButton.m in Sources */ = {isa = PBXBuildFile; fileRef = B8F2D9011E5D2B600029D63C /* DragPopUpButton.m */; };
/* End PBXBuildFile section */
Expand All @@ -39,6 +40,8 @@
A276B6FB1AB53781009EF649 /* HelpViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HelpViewController.m; sourceTree = "<group>"; };
A276B6FE1AB53816009EF649 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
A276B7001AB5381B009EF649 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
B89258D71E63C831005E9F27 /* Sec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sec.h; sourceTree = "<group>"; };
B89258D81E63C831005E9F27 /* Sec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sec.m; sourceTree = "<group>"; };
B8F2D8FD1E5D1D320029D63C /* SecManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecManager.h; sourceTree = "<group>"; };
B8F2D8FE1E5D1D320029D63C /* SecManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecManager.m; sourceTree = "<group>"; };
B8F2D9001E5D2B600029D63C /* DragPopUpButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragPopUpButton.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -78,6 +81,7 @@
A276B6C91AB51A6F009EF649 /* SmartPush */ = {
isa = PBXGroup;
children = (
B89258D61E63C821005E9F27 /* Model */,
B8F2D8FC1E5D1CF90029D63C /* Manager */,
A276B6ED1AB51AEE009EF649 /* View */,
A276B6EE1AB51AEE009EF649 /* Library */,
Expand Down Expand Up @@ -133,6 +137,15 @@
name = Frameworks;
sourceTree = "<group>";
};
B89258D61E63C821005E9F27 /* Model */ = {
isa = PBXGroup;
children = (
B89258D71E63C831005E9F27 /* Sec.h */,
B89258D81E63C831005E9F27 /* Sec.m */,
);
path = Model;
sourceTree = "<group>";
};
B8F2D8FC1E5D1CF90029D63C /* Manager */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -211,6 +224,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B89258D91E63C831005E9F27 /* Sec.m in Sources */,
A276B6D31AB51A6F009EF649 /* PushViewController.m in Sources */,
A276B6FC1AB53781009EF649 /* HelpViewController.m in Sources */,
B8F2D9021E5D2B600029D63C /* DragPopUpButton.m in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions SmartPush/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>LSApplicationCategoryType</key>
<string></string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand Down
3 changes: 2 additions & 1 deletion SmartPush/Manager/SecManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
//

#import <Foundation/Foundation.h>

#import "Sec.h"
@interface SecManager : NSObject
+ (NSArray *)allPushCertificatesWithEnvironment:(BOOL)isDevelop;
+ (SecCertificateRef)certificatesWithPath:(NSString*)path;
+ (BOOL)isPushCertificate:(SecCertificateRef)sec;
+ (NSString *)subjectSummaryWithCertificate:(SecCertificateRef)certificate;
+ (NSDate *)expirationWithCertificate:(SecCertificateRef)certificate;
+ (NSArray *)allKeychainCertificatesWithError:(NSError *__autoreleasing *)error;
+ (Sec*)secModelWithRef:(SecCertificateRef)sec;
@end
43 changes: 38 additions & 5 deletions SmartPush/Manager/SecManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,54 @@
//

#import "SecManager.h"

#import "Sec.h"
@implementation SecManager
+ (NSArray *)allPushCertificatesWithEnvironment:(BOOL)isDevelop{
+ (NSArray<Sec*> *)allPushCertificatesWithEnvironment:(BOOL)isDevelop{
NSError *error;
NSArray *allCertificates = [self allKeychainCertificatesWithError:&error];
NSMutableArray *pushs = [NSMutableArray array];

for (int i =0; i<[allCertificates count]; i++) {
SecCertificateRef sec = (__bridge SecCertificateRef)([allCertificates objectAtIndex:i]);
if ([self isPushCertificate:sec]) {
[pushs addObject:(__bridge id _Nonnull)(sec)];
id obj = [allCertificates objectAtIndex:i];

if(obj != NULL){
// CFBridgingRetain
Sec *secModel = [self secModelWithRef:(__bridge_retained void *)(obj)];
if ([self isPushCertificateWithName:secModel.name]) {
[pushs addObject:secModel];
}
}
}
return pushs;
}
+ (Sec*)secModelWithRef:(SecCertificateRef)sec{
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
Sec *secModel = [[Sec alloc]init];
secModel.certificateRef = sec;

secModel.name = [self subjectSummaryWithCertificate:sec];
secModel.key = secModel.name;
secModel.date = [SecManager expirationWithCertificate:sec];
secModel.expire = [NSString stringWithFormat:@" [%@]", secModel.date ? [formatter stringFromDate: secModel.date] : @"expired"];

return secModel;
}
+ (BOOL)isPushCertificateWithName:(NSString*)name{

if ([name rangeOfString:@"Apple Development IOS Push Services:"].location != NSNotFound ||
[name rangeOfString:@"Apple Production IOS Push Services:"].location != NSNotFound||
[name rangeOfString:@"Apple Development Mac Push Services:"].location != NSNotFound||
[name rangeOfString:@"Apple Production Mac Push Services:"].location != NSNotFound||
[name rangeOfString:@"Apple Push Services:"].location != NSNotFound||
[name rangeOfString:@"Website Push ID:"].location != NSNotFound||
[name rangeOfString:@"VoIP Services:"].location != NSNotFound||
[name rangeOfString:@"WatchKit Services:"].location != NSNotFound ) {
return YES;
}
return NO;
}
+ (BOOL)isPushCertificate:(SecCertificateRef)sec{
NSString *name = [self subjectSummaryWithCertificate:sec];

Expand Down
19 changes: 19 additions & 0 deletions SmartPush/Model/Sec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Sec.h
// SmartPush
//
// Created by runlin on 2017/2/27.
// Copyright © 2017年 www.skyfox.org. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Sec : NSObject
@property (nonatomic) SecCertificateRef certificateRef;
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) NSString *key;

@property (nonatomic,strong) NSDate *date;
@property (nonatomic,copy) NSString *expire;

@end
13 changes: 13 additions & 0 deletions SmartPush/Model/Sec.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Sec.m
// SmartPush
//
// Created by runlin on 2017/2/27.
// Copyright © 2017年 www.skyfox.org. All rights reserved.
//

#import "Sec.h"

@implementation Sec

@end
7 changes: 4 additions & 3 deletions SmartPush/PushViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@
#import "ioSock.h"
#import "TextFieldDrag.h"
#import "DragPopUpButton.h"
#import "Sec.h"
@interface PushViewController : NSViewController<NSTextFieldDelegate>
{

NSString *_token;
NSString *_cerPath;
NSString *_lastCerPath;
NSString *_cerName;

otSocket socket;
OSStatus _connectResult;
OSStatus _closeResult;

SSLContextRef _context;
SecKeychainRef _keychain;
SecCertificateRef _certificate;
Sec *_currentSec;
SecIdentityRef _identity;
NSUserDefaults *_defaults;
NSMutableArray *_certificates;

}
@property (weak) IBOutlet NSTextField *payload;
@property (unsafe_unretained) IBOutlet NSTextView *logTextView;
Expand Down
Loading

0 comments on commit fd70dac

Please sign in to comment.