diff --git a/Limelight/Crypto/CryptoManager.h b/Limelight/Crypto/CryptoManager.h index ba384d3..493ae59 100644 --- a/Limelight/Crypto/CryptoManager.h +++ b/Limelight/Crypto/CryptoManager.h @@ -11,7 +11,6 @@ @interface CryptoManager : NSObject + (void) generateKeyPairUsingSSl; -+ (NSString*) getUniqueID; + (NSData*) readCertFromFile; + (NSData*) readKeyFromFile; + (NSData*) readP12FromFile; diff --git a/Limelight/Crypto/CryptoManager.m b/Limelight/Crypto/CryptoManager.m index 62144b0..7e2aa4d 100644 --- a/Limelight/Crypto/CryptoManager.m +++ b/Limelight/Crypto/CryptoManager.m @@ -8,7 +8,6 @@ #import "CryptoManager.h" #import "mkcert.h" -#import #include #include @@ -229,18 +228,4 @@ static NSData* p12 = nil; }); } -+ (NSString*) getUniqueID { - // generate a UUID - NSUUID* uuid = [ASIdentifierManager sharedManager].advertisingIdentifier; - NSString* idString = [NSString stringWithString:[uuid UUIDString]]; - - // we need a 16byte hex-string so we take the last 17 characters - // and remove the '-' to get a 16 character string - NSMutableString* uniqueId = [NSMutableString stringWithString:[idString substringFromIndex:19]]; - [uniqueId deleteCharactersInRange:NSMakeRange(4, 1)]; - - //Log(LOG_D, @"Unique ID: %@", uniqueId); - return [NSString stringWithString:uniqueId]; -} - @end diff --git a/Limelight/Crypto/IdManager.h b/Limelight/Crypto/IdManager.h new file mode 100644 index 0000000..3fc5fae --- /dev/null +++ b/Limelight/Crypto/IdManager.h @@ -0,0 +1,15 @@ +// +// IdManager.h +// Moonlight +// +// Created by Diego Waxemberg on 10/31/15. +// Copyright © 2015 Moonlight Stream. All rights reserved. +// + +#import + +@interface IdManager : NSObject + ++ (NSString*) getUniqueId; + +@end diff --git a/Limelight/Crypto/IdManager.m b/Limelight/Crypto/IdManager.m new file mode 100644 index 0000000..25c6551 --- /dev/null +++ b/Limelight/Crypto/IdManager.m @@ -0,0 +1,33 @@ +// +// IdManager.m +// Moonlight +// +// Created by Diego Waxemberg on 10/31/15. +// Copyright © 2015 Moonlight Stream. All rights reserved. +// + +#import "IdManager.h" +#import "DataManager.h" + +@implementation IdManager + ++ (NSString*) getUniqueId { + DataManager* dataMan = [[DataManager alloc] init]; + Settings* prefs = [dataMan retrieveSettings]; + + NSString* uniqueId = prefs.uniqueId; + if (uniqueId == nil) { + uniqueId = [IdManager generateUniqueId]; + prefs.uniqueId = uniqueId; + [dataMan saveData]; + Log(LOG_I, @"No UUID found. Generated new UUID: %@", uniqueId); + } + return uniqueId; +} + ++ (NSString*) generateUniqueId { + UInt64 uuidLong = ((UInt64) arc4random() << 32) | arc4random(); + return [NSString stringWithFormat:@"%016llx", uuidLong]; +} + +@end diff --git a/Limelight/Database/Settings.h b/Limelight/Database/Settings.h index 480024b..39aaa5b 100644 --- a/Limelight/Database/Settings.h +++ b/Limelight/Database/Settings.h @@ -17,5 +17,6 @@ @property (nonatomic, retain) NSNumber * height; @property (nonatomic, retain) NSNumber * width; @property (nonatomic, retain) NSNumber * onscreenControls; +@property (nonatomic, retain) NSString * uniqueId; @end diff --git a/Limelight/Database/Settings.m b/Limelight/Database/Settings.m index 8294ba7..0ad9ad8 100644 --- a/Limelight/Database/Settings.m +++ b/Limelight/Database/Settings.m @@ -16,5 +16,6 @@ @dynamic height; @dynamic width; @dynamic onscreenControls; +@dynamic uniqueId; @end diff --git a/Limelight/Limelight-Info.plist b/Limelight/Limelight-Info.plist index 27eb58a..c499866 100644 --- a/Limelight/Limelight-Info.plist +++ b/Limelight/Limelight-Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.9.2 + 1.0.0 CFBundleSignature ???? CFBundleVersion diff --git a/Limelight/Limelight.xcdatamodeld/.xccurrentversion b/Limelight/Limelight.xcdatamodeld/.xccurrentversion index f988e70..2346a99 100644 --- a/Limelight/Limelight.xcdatamodeld/.xccurrentversion +++ b/Limelight/Limelight.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - Moonlight v1.0.xcdatamodel + Moonlight v1.0-2.xcdatamodel diff --git a/Limelight/Limelight.xcdatamodeld/Moonlight v1.0-2.xcdatamodel/contents b/Limelight/Limelight.xcdatamodeld/Moonlight v1.0-2.xcdatamodel/contents new file mode 100644 index 0000000..6844893 --- /dev/null +++ b/Limelight/Limelight.xcdatamodeld/Moonlight v1.0-2.xcdatamodel/contents @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Limelight/Limelight.xcdatamodeld/Moonlight v1.0.xcdatamodel/contents b/Limelight/Limelight.xcdatamodeld/Moonlight v1.0.xcdatamodel/contents index 3c95341..f116d13 100644 --- a/Limelight/Limelight.xcdatamodeld/Moonlight v1.0.xcdatamodel/contents +++ b/Limelight/Limelight.xcdatamodeld/Moonlight v1.0.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -21,11 +21,12 @@ + - + \ No newline at end of file diff --git a/Limelight/Network/AppAssetRetriever.m b/Limelight/Network/AppAssetRetriever.m index 1fe102c..07cd1a0 100644 --- a/Limelight/Network/AppAssetRetriever.m +++ b/Limelight/Network/AppAssetRetriever.m @@ -11,6 +11,7 @@ #import "CryptoManager.h" #import "AppAssetResponse.h" #import "HttpRequest.h" +#import "IdManager.h" @implementation AppAssetRetriever static const double RETRY_DELAY = 2; // seconds @@ -21,7 +22,7 @@ static const int MAX_ATTEMPTS = 5; int attempts = 0; while (![self isCancelled] && appImage == nil && attempts++ < MAX_ATTEMPTS) { - HttpManager* hMan = [[HttpManager alloc] initWithHost:_host.activeAddress uniqueId:[CryptoManager getUniqueID] deviceName:deviceName cert:[CryptoManager readCertFromFile]]; + HttpManager* hMan = [[HttpManager alloc] initWithHost:_host.activeAddress uniqueId:[IdManager getUniqueId] deviceName:deviceName cert:[CryptoManager readCertFromFile]]; AppAssetResponse* appAssetResp = [[AppAssetResponse alloc] init]; [hMan executeRequestSynchronously:[HttpRequest requestForResponse:appAssetResp withUrlRequest:[hMan newAppAssetRequestWithAppId:self.app.id]]]; diff --git a/Limelight/Network/DiscoveryManager.m b/Limelight/Network/DiscoveryManager.m index f2c4dea..0e756a6 100644 --- a/Limelight/Network/DiscoveryManager.m +++ b/Limelight/Network/DiscoveryManager.m @@ -13,6 +13,7 @@ #import "DataManager.h" #import "DiscoveryWorker.h" #import "ServerInfoResponse.h" +#import "IdManager.h" @implementation DiscoveryManager { NSMutableArray* _hostQueue; @@ -48,7 +49,7 @@ _opQueue = [[NSOperationQueue alloc] init]; _mdnsMan = [[MDNSManager alloc] initWithCallback:self]; [CryptoManager generateKeyPairUsingSSl]; - _uniqueId = [CryptoManager getUniqueID]; + _uniqueId = [IdManager getUniqueId]; _cert = [CryptoManager readCertFromFile]; return self; } diff --git a/Limelight/Stream/StreamManager.m b/Limelight/Stream/StreamManager.m index d9087c3..1ec6f10 100644 --- a/Limelight/Stream/StreamManager.m +++ b/Limelight/Stream/StreamManager.m @@ -15,6 +15,7 @@ #import "ServerInfoResponse.h" #import "HttpResponse.h" #import "HttpRequest.h" +#import "IdManager.h" @implementation StreamManager { StreamConfiguration* _config; @@ -36,7 +37,7 @@ - (void)main { [CryptoManager generateKeyPairUsingSSl]; - NSString* uniqueId = [CryptoManager getUniqueID]; + NSString* uniqueId = [IdManager getUniqueId]; NSData* cert = [CryptoManager readCertFromFile]; HttpManager* hMan = [[HttpManager alloc] initWithHost:_config.host diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index f93568b..d786661 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -24,6 +24,7 @@ #import "LoadingFrameViewController.h" #import "ComputerScrollView.h" #import "TemporaryApp.h" +#import "IdManager.h" @implementation MainFrameViewController { NSOperationQueue* _opQueue; @@ -488,7 +489,7 @@ static NSMutableSet* hostList; // Set up crypto [CryptoManager generateKeyPairUsingSSl]; - _uniqueId = [CryptoManager getUniqueID]; + _uniqueId = [IdManager getUniqueId]; _cert = [CryptoManager readCertFromFile]; _appManager = [[AppAssetManager alloc] initWithCallback:self]; diff --git a/Moonlight.xcodeproj/project.pbxproj b/Moonlight.xcodeproj/project.pbxproj index 1e2ea39..360ba77 100644 --- a/Moonlight.xcodeproj/project.pbxproj +++ b/Moonlight.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ FB4678FF1A565DAC00377732 /* WakeOnLanManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FB4678FE1A565DAC00377732 /* WakeOnLanManager.m */; }; FB4679011A57048000377732 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FB4679001A57048000377732 /* CoreFoundation.framework */; }; FB4A23B81A9D3637004D2EF2 /* LoadingFrameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FB4A23B71A9D3637004D2EF2 /* LoadingFrameViewController.m */; }; + FB53E1431BE5DC4400CD6ECE /* IdManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FB53E1421BE5DC4400CD6ECE /* IdManager.m */; }; FB6549561A57907E001C8F39 /* DiscoveryWorker.m in Sources */ = {isa = PBXBuildFile; fileRef = FB6549551A57907E001C8F39 /* DiscoveryWorker.m */; }; FB7E794419C8B71B00A15F68 /* libiconv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = FB7E794319C8B71B00A15F68 /* libiconv.dylib */; }; FB89462819F646E200339C8A /* CryptoManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FB89460619F646E200339C8A /* CryptoManager.m */; }; @@ -136,6 +137,9 @@ FB4679001A57048000377732 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; FB4A23B61A9D3637004D2EF2 /* LoadingFrameViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadingFrameViewController.h; sourceTree = ""; }; FB4A23B71A9D3637004D2EF2 /* LoadingFrameViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoadingFrameViewController.m; sourceTree = ""; }; + FB53E1411BE5DC4400CD6ECE /* IdManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IdManager.h; sourceTree = ""; }; + FB53E1421BE5DC4400CD6ECE /* IdManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IdManager.m; sourceTree = ""; }; + FB53E1441BE5DCBC00CD6ECE /* Moonlight v1.0-2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.0-2.xcdatamodel"; sourceTree = ""; }; FB6549541A57907E001C8F39 /* DiscoveryWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiscoveryWorker.h; sourceTree = ""; }; FB6549551A57907E001C8F39 /* DiscoveryWorker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DiscoveryWorker.m; sourceTree = ""; }; FB6549621A60B4A9001C8F39 /* Limelight 0.3.1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Limelight 0.3.1.xcdatamodel"; sourceTree = ""; }; @@ -432,6 +436,8 @@ FB89460619F646E200339C8A /* CryptoManager.m */, FB89460719F646E200339C8A /* mkcert.c */, FB89460819F646E200339C8A /* mkcert.h */, + FB53E1411BE5DC4400CD6ECE /* IdManager.h */, + FB53E1421BE5DC4400CD6ECE /* IdManager.m */, ); path = Crypto; sourceTree = ""; @@ -836,6 +842,7 @@ FB89462F19F646E200339C8A /* Connection.m in Sources */, FB9AFD321A7D867C00872C98 /* AppAssetRetriever.m in Sources */, FB4678FF1A565DAC00377732 /* WakeOnLanManager.m in Sources */, + FB53E1431BE5DC4400CD6ECE /* IdManager.m in Sources */, FB89462919F646E200339C8A /* mkcert.c in Sources */, FB9AFD281A7C84ED00872C98 /* HttpResponse.m in Sources */, FBDE86E019F7A837001C18A8 /* UIComputerView.m in Sources */, @@ -1056,12 +1063,13 @@ FB290D0519B2C406004C83CF /* Limelight.xcdatamodeld */ = { isa = XCVersionGroup; children = ( + FB53E1441BE5DCBC00CD6ECE /* Moonlight v1.0-2.xcdatamodel */, FBB460391B50ACE400F3099C /* Moonlight v1.0.xcdatamodel */, FB6549621A60B4A9001C8F39 /* Limelight 0.3.1.xcdatamodel */, FB4678F21A51BDCB00377732 /* Limelight 0.3.0.xcdatamodel */, FB290D0619B2C406004C83CF /* Limelight.xcdatamodel */, ); - currentVersion = FBB460391B50ACE400F3099C /* Moonlight v1.0.xcdatamodel */; + currentVersion = FB53E1441BE5DCBC00CD6ECE /* Moonlight v1.0-2.xcdatamodel */; path = Limelight.xcdatamodeld; sourceTree = ""; versionGroupType = wrapper.xcdatamodel;