aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DomeKey/LicenseHandler.h4
-rw-r--r--DomeKey/LicenseHandler.m77
-rw-r--r--DomeKey/errors.h5
-rw-r--r--DomeKey/main.m3
4 files changed, 87 insertions, 2 deletions
diff --git a/DomeKey/LicenseHandler.h b/DomeKey/LicenseHandler.h
index 6634f28..fb3ab51 100644
--- a/DomeKey/LicenseHandler.h
+++ b/DomeKey/LicenseHandler.h
@@ -8,6 +8,10 @@
#import <Foundation/Foundation.h>
+#import "AquaticPrime.h"
+#import "XDG.h"
+#import "errors.h"
+
@interface LicenseHandler : NSObject
+ (void)check;
diff --git a/DomeKey/LicenseHandler.m b/DomeKey/LicenseHandler.m
index b875842..52c5bcf 100644
--- a/DomeKey/LicenseHandler.m
+++ b/DomeKey/LicenseHandler.m
@@ -8,20 +8,93 @@
#import "LicenseHandler.h"
+static NSString * const LICENSE_FILE_NAME = @"license.plist";
+
@implementation LicenseHandler
+ (void)check
{
- if (/* license file exists */) {
- // validate license
+ if ([self licenseFileExists]) {
+ if (![self validateLicense]) {
+ eprintf(
+ "The license file '%s' is invalid. "
+ "Try adding your license again using the `--license` flag.\n",
+ [[[self licensePath] path] UTF8String]
+ );
+
+ // TODO: then do trial
+ }
}
else {
// run do_trial();
+ printf("TODO: do trial\n");
}
}
+ (void)addLicense
{
+ // Copy license file into path
+ // Validate license
+ // If license doesn't validate, remove copied file
+ // If license does validate, print a success message
+}
+
++ (NSURL *)licensePath
+{
+ return [[XDG domeKeyDataPath]
+ URLByAppendingPathComponent:LICENSE_FILE_NAME
+ isDirectory:NO];
+}
+
++ (BOOL)licenseFileExists
+{
+ NSURL *path = [self licensePath];
+
+ return [[NSFileManager defaultManager]
+ fileExistsAtPath:[path path]];
+}
+
++ (BOOL)validateLicense
+{
+ NSURL *path = [self licensePath];
+ CFURLRef cf_path = CFBridgingRetain(path);
+
+ CFMutableStringRef key = CFStringCreateMutable(NULL, 0);
+ CFStringAppend(key, CFSTR("0xD536F17DA75620927B"));
+ CFStringAppend(key, CFSTR("D"));
+ CFStringAppend(key, CFSTR("D"));
+ CFStringAppend(key, CFSTR("029DDFF1"));
+ CFStringAppend(key, CFSTR("E"));
+ CFStringAppend(key, CFSTR("3"));
+ CFStringAppend(key, CFSTR("3"));
+ CFStringAppend(key, CFSTR("F620B3AFEE024F3A8FC724BF93A"));
+ CFStringAppend(key, CFSTR("906AF20712D39EB5C931BF63068612"));
+ CFStringAppend(key, CFSTR("B0741791485D470745E7C71DC8287A"));
+ CFStringAppend(key, CFSTR(""));
+ CFStringAppend(key, CFSTR("1"));
+ CFStringAppend(key, CFSTR("1"));
+ CFStringAppend(key, CFSTR("9517FC3C60CC3FBF6DA13A0A2F0C"));
+ CFStringAppend(key, CFSTR(""));
+ CFStringAppend(key, CFSTR("D"));
+ CFStringAppend(key, CFSTR("D"));
+ CFStringAppend(key, CFSTR("5F14977DEEB6E32C3B039AADCD3D"));
+ CFStringAppend(key, CFSTR("0C97BD94FC4E0714C2F"));
+ CFStringAppend(key, CFSTR("8"));
+ CFStringAppend(key, CFSTR("8"));
+ CFStringAppend(key, CFSTR("B010622D2"));
+ CFStringAppend(key, CFSTR("36FB7"));
+ CFStringAppend(key, CFSTR("5"));
+ CFStringAppend(key, CFSTR("5"));
+ CFStringAppend(key, CFSTR("9AEF648830DA73C584DE402"));
+ CFStringAppend(key, CFSTR("4AFD071F4F4E90021B"));
+
+ // TODO: returns false on failure
+ APSetKey(key);
+ BOOL validated = APVerifyLicenseFile(cf_path);
+
+ CFRelease(cf_path);
+
+ return validated;
}
@end
diff --git a/DomeKey/errors.h b/DomeKey/errors.h
new file mode 100644
index 0000000..d1a97ce
--- /dev/null
+++ b/DomeKey/errors.h
@@ -0,0 +1,5 @@
+#define eprintf(...) fprintf( \
+ stderr, \
+ "dome-key: error: " \
+ __VA_ARGS__ \
+)
diff --git a/DomeKey/main.m b/DomeKey/main.m
index 8a9011c..2263bac 100644
--- a/DomeKey/main.m
+++ b/DomeKey/main.m
@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "DKApplication.h"
#import "AppDelegate.h"
+#import "LicenseHandler.h"
#import "Mappings.h"
#import "dome_key_map.h"
@@ -22,6 +23,8 @@ int main(int argc, const char * argv[]) {
config = c_parse_args(argv, argc, config);
+ [LicenseHandler check];
+
if (config->args.reload) {
return [Mappings dispatchReload];
} else if (config->args.daemon) {