Permalink
Browse files

Merge branch 'new-cmdline-tool' into develop

  • Loading branch information...
2 parents 5334c99 + 32e502f commit 6b5af9f19a802ba78951b1c61751546e316d6c72 Danny Greg committed Aug 24, 2010
Showing with 188 additions and 34 deletions.
  1. +56 −22 objc/cocoafob.m
  2. +132 −5 objc/cocoafob.xcodeproj/project.pbxproj
  3. +0 −7 objc/cocoafob_Prefix.pch
View
78 objc/cocoafob.m
@@ -9,8 +9,9 @@
//
#import <Foundation/Foundation.h>
-#import "CFobLicGenerator.h"
-#import "CFobLicVerifier.h"
+
+#import <CocoaFob/CFobLicGenerator.h>
+#import <CocoaFob/CFobLicVerifier.h>
//#define TEST
@@ -28,9 +29,20 @@ void smoketest()
"keUwLHBtpClnD5E8\n"
"-----END DSA PRIVATE KEY-----\n";
NSString *regName = @"decloner|Joe Bloggs";
- CFobLicGenerator *generator = [CFobLicGenerator generatorWithPrivateKey:privKey];
- generator.regName = regName;
- [generator generate];
+
+ CFobLicGenerator *generator = [[[CFobLicGenerator alloc] init] autorelease];
+
+ NSError *err = nil;
+ if (![generator setPrivateKey:privKey error:&err]) {
+ NSLog(@"Could not set private key: %@", err);
+ return;
+ }
+
+ NSString *regCode = [generator generateRegCodeForName:regName error:&err];
+ if (regCode == nil) {
+ NSLog(@"Could not generate serial number: %@", err);
+ return;
+ }
// Modelled after AquaticPrime's method of splitting public key to obfuscate it.
// It is probably better if you invent your own splitting pattern. Go wild.
@@ -51,15 +63,20 @@ void smoketest()
[pubKeyBase64 appendString:@"MP/+"];
[pubKeyBase64 appendString:@"2Z7ekydHfX0sTMDgkxhtRm6qtcywg01X847Y9ySgNepqleD+Ka2Wbucj1pOr\n"];
[pubKeyBase64 appendString:@"y8MoDQ==\n"];
+
NSString *pubKey = [CFobLicVerifier completePublicKeyPEM:pubKeyBase64];
- CFobLicVerifier *verifier = [CFobLicVerifier verifierWithPublicKey:pubKey];
- verifier.regName = regName;
- verifier.regCode = generator.regCode;
- puts([verifier.regCode UTF8String]);
- if ([verifier verify])
+ CFobLicVerifier *verifier = [[[CFobLicVerifier alloc] init] autorelease];
+ if (![verifier setPublicKey:pubKey error:&err]) {
+ NSLog(@"Could not set public key on verifier %@", err);
+ return;
+ }
+
+ puts([regCode UTF8String]);
+ if ([verifier verifyRegCode:regCode forName:regName error:&err]) {
puts("PASS");
- else
- puts("FAIL");
+ } else {
+ NSLog(@"FAIL: %@", err);
+ }
}
#endif
@@ -68,26 +85,43 @@ void smoketest()
{
NSError *err = nil;
NSString *privKey = [NSString stringWithContentsOfFile:privKeyFileName encoding:NSASCIIStringEncoding error:&err];
- if (!privKey || err)
+ if (privKey == nil)
return nil;
- CFobLicGenerator *generator = [CFobLicGenerator generatorWithPrivateKey:privKey];
- generator.regName = regName;
- if (![generator generate])
+
+ CFobLicGenerator *generator = [[[CFobLicGenerator alloc] init] autorelease];
+ if (![generator setPrivateKey:privKey error:&err]) {
+ NSLog(@"%@", err);
return nil;
- return generator.regCode;
+ }
+
+ NSString *regCode = [generator generateRegCodeForName:regName error:&err];
+ if (regCode == nil) {
+ NSLog(@"%@", err);
+ return nil;
+ }
+
+ return regCode;
}
// Pass public key, registration name and registration code to verify it
BOOL codecheck(NSString *pubKeyFileName, NSString *regName, NSString *regCode)
{
NSError *err = nil;
NSString *pubKey = [NSString stringWithContentsOfFile:pubKeyFileName encoding:NSASCIIStringEncoding error:&err];
- if (!pubKey || err)
+ if (pubKey == nil)
return NO;
- CFobLicVerifier *verifier = [CFobLicVerifier verifierWithPublicKey:pubKey];
- verifier.regName = regName;
- verifier.regCode = regCode;
- return [verifier verify];
+
+ CFobLicVerifier *verifier = [[[CFobLicVerifier alloc] init] autorelease];
+ if (![verifier setPublicKey:pubKey error:&err]) {
+ NSLog(@"%@", err);
+ return NO;
+ }
+
+ BOOL result = [verifier verifyRegCode:regCode forName:regName error:&err];
+ if (!result)
+ NSLog(@"%@", err);
+
+ return result;
}
// Uses NSUserDefaults to parse command-line arguments:
View
137 objc/cocoafob.xcodeproj/project.pbxproj
@@ -25,8 +25,20 @@
303525A81223C19D00AACD22 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 303524D01223BE4D00AACD22 /* libcrypto.dylib */; };
303526851223D4DA00AACD22 /* CFobError.h in Headers */ = {isa = PBXBuildFile; fileRef = 303526831223D4DA00AACD22 /* CFobError.h */; };
303526981223DC9600AACD22 /* CFobError.m in Sources */ = {isa = PBXBuildFile; fileRef = 303526971223DC9600AACD22 /* CFobError.m */; };
+ 303526F41223E4C900AACD22 /* CocoaFob.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 303524081223BB9600AACD22 /* CocoaFob.framework */; };
+ 303526FC1223E56000AACD22 /* cocoafob.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* cocoafob.m */; };
/* End PBXBuildFile section */
+/* Begin PBXContainerItemProxy section */
+ 303526F01223E4C200AACD22 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 303524071223BB9600AACD22 /* CocoaFob */;
+ remoteInfo = CocoaFob;
+ };
+/* End PBXContainerItemProxy section */
+
/* Begin PBXFileReference section */
08FB7796FE84155DC02AAC07 /* cocoafob.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = cocoafob.m; sourceTree = "<group>"; };
303524081223BB9600AACD22 /* CocoaFob.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CocoaFob.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -35,7 +47,7 @@
303524D61223BE6700AACD22 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
303526831223D4DA00AACD22 /* CFobError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFobError.h; sourceTree = "<group>"; };
303526971223DC9600AACD22 /* CFobError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CFobError.m; sourceTree = "<group>"; };
- 32A70AAB03705E1F00C91783 /* cocoafob_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoafob_Prefix.pch; sourceTree = "<group>"; };
+ 303526E91223E45100AACD22 /* cocoafob */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = cocoafob; sourceTree = BUILT_PRODUCTS_DIR; };
C6859EA3029092ED04C91782 /* cocoafob.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = cocoafob.1; sourceTree = "<group>"; };
C7A731670F5F42D500D40AFE /* NSString-Base64Extensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString-Base64Extensions.h"; sourceTree = "<group>"; };
C7A731680F5F42D500D40AFE /* NSString-Base64Extensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString-Base64Extensions.m"; sourceTree = "<group>"; };
@@ -63,13 +75,22 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ 303526E71223E45100AACD22 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 303526F41223E4C900AACD22 /* CocoaFob.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
08FB7794FE84155DC02AAC07 /* cocoafob */ = {
isa = PBXGroup;
children = (
08FB7795FE84155DC02AAC07 /* Source */,
+ 303526E01223E39D00AACD22 /* Tests */,
3035240E1223BC0400AACD22 /* Framework */,
C6859EA2029092E104C91782 /* Documentation */,
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
@@ -81,15 +102,14 @@
08FB7795FE84155DC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
+ 303526E21223E3FF00AACD22 /* Cmd Line Tool */,
C7A731660F5F42C000D40AFE /* Dave Dribin */,
C7E378540F59DB33002061CD /* Base32 */,
C7E378530F59DB1E002061CD /* PECategories */,
C7E378470F59DB15002061CD /* CFobLicGenerator.h */,
C7E378480F59DB15002061CD /* CFobLicGenerator.m */,
C7E378490F59DB15002061CD /* CFobLicVerifier.h */,
C7E3784A0F59DB15002061CD /* CFobLicVerifier.m */,
- 32A70AAB03705E1F00C91783 /* cocoafob_Prefix.pch */,
- 08FB7796FE84155DC02AAC07 /* cocoafob.m */,
303526831223D4DA00AACD22 /* CFobError.h */,
303526971223DC9600AACD22 /* CFobError.m */,
);
@@ -109,6 +129,7 @@
isa = PBXGroup;
children = (
303524081223BB9600AACD22 /* CocoaFob.framework */,
+ 303526E91223E45100AACD22 /* cocoafob */,
);
name = Products;
sourceTree = "<group>";
@@ -121,6 +142,21 @@
name = Framework;
sourceTree = "<group>";
};
+ 303526E01223E39D00AACD22 /* Tests */ = {
+ isa = PBXGroup;
+ children = (
+ );
+ name = Tests;
+ sourceTree = "<group>";
+ };
+ 303526E21223E3FF00AACD22 /* Cmd Line Tool */ = {
+ isa = PBXGroup;
+ children = (
+ 08FB7796FE84155DC02AAC07 /* cocoafob.m */,
+ );
+ name = "Cmd Line Tool";
+ sourceTree = "<group>";
+ };
C6859EA2029092E104C91782 /* Documentation */ = {
isa = PBXGroup;
children = (
@@ -199,6 +235,23 @@
productReference = 303524081223BB9600AACD22 /* CocoaFob.framework */;
productType = "com.apple.product-type.framework";
};
+ 303526E81223E45100AACD22 /* cocoafob */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 303526EE1223E48200AACD22 /* Build configuration list for PBXNativeTarget "cocoafob" */;
+ buildPhases = (
+ 303526E61223E45100AACD22 /* Sources */,
+ 303526E71223E45100AACD22 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ 303526F11223E4C200AACD22 /* PBXTargetDependency */,
+ );
+ name = cocoafob;
+ productName = cocoafob;
+ productReference = 303526E91223E45100AACD22 /* cocoafob */;
+ productType = "com.apple.product-type.tool";
+ };
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@@ -212,6 +265,7 @@
projectRoot = "";
targets = (
303524071223BB9600AACD22 /* CocoaFob */,
+ 303526E81223E45100AACD22 /* cocoafob */,
);
};
/* End PBXProject section */
@@ -242,8 +296,24 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ 303526E61223E45100AACD22 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 303526FC1223E56000AACD22 /* cocoafob.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXSourcesBuildPhase section */
+/* Begin PBXTargetDependency section */
+ 303526F11223E4C200AACD22 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 303524071223BB9600AACD22 /* CocoaFob */;
+ targetProxy = 303526F01223E4C200AACD22 /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
/* Begin XCBuildConfiguration section */
1DEB927908733DD40010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
@@ -298,7 +368,7 @@
);
PREBINDING = NO;
PRODUCT_NAME = CocoaFob;
- SDKROOT = macosx10.6;
+ SDKROOT = macosx10.5;
};
name = Debug;
};
@@ -329,7 +399,55 @@
);
PREBINDING = NO;
PRODUCT_NAME = CocoaFob;
- SDKROOT = macosx10.6;
+ SDKROOT = macosx10.5;
+ ZERO_LINK = NO;
+ };
+ name = Release;
+ };
+ 303526EB1223E45100AACD22 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ INSTALL_PATH = /usr/local/bin;
+ OTHER_LDFLAGS = (
+ "-framework",
+ Foundation,
+ "-framework",
+ AppKit,
+ );
+ PREBINDING = NO;
+ PRODUCT_NAME = cocoafob;
+ };
+ name = Debug;
+ };
+ 303526EC1223E45100AACD22 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_ENABLE_FIX_AND_CONTINUE = NO;
+ GCC_MODEL_TUNING = G5;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ INSTALL_PATH = /usr/local/bin;
+ OTHER_LDFLAGS = (
+ "-framework",
+ Foundation,
+ "-framework",
+ AppKit,
+ );
+ PREBINDING = NO;
+ PRODUCT_NAME = cocoafob;
ZERO_LINK = NO;
};
name = Release;
@@ -355,6 +473,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
+ 303526EE1223E48200AACD22 /* Build configuration list for PBXNativeTarget "cocoafob" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 303526EB1223E45100AACD22 /* Debug */,
+ 303526EC1223E45100AACD22 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
/* End XCConfigurationList section */
};
rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
View
7 objc/cocoafob_Prefix.pch
@@ -1,7 +0,0 @@
-//
-// Prefix header for all source files of the 'cocoafob' target in the 'cocoafob' project.
-//
-
-#ifdef __OBJC__
- #import <Foundation/Foundation.h>
-#endif

0 comments on commit 6b5af9f

Please sign in to comment.