mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-15 21:21:45 +00:00
implemented crypto and started pairing
This commit is contained in:
@@ -11,5 +11,6 @@
|
||||
@interface CryptoManager : NSObject <NSURLConnectionDelegate>
|
||||
|
||||
- (void) generateKeyPairUsingSSl;
|
||||
- (NSString*) getUniqueID;
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#import "CryptoManager.h"
|
||||
#import "mkcert.h"
|
||||
|
||||
#import <AdSupport/ASIdentifierManager.h>
|
||||
|
||||
@implementation CryptoManager
|
||||
|
||||
@@ -31,4 +31,18 @@
|
||||
freeCertKeyPair(certKeyPair);
|
||||
}
|
||||
|
||||
- (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)];
|
||||
|
||||
//NSLog(@"Unique ID: %@", uniqueId);
|
||||
return [NSString stringWithString:uniqueId];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// HttpManager.h
|
||||
// Limelight
|
||||
//
|
||||
// Created by Diego Waxemberg on 10/16/14.
|
||||
// Copyright (c) 2014 Limelight Stream. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface HttpManager : NSObject
|
||||
- (NSString*) generatePIN;
|
||||
- (NSString*) saltPIN:(NSString*)PIN;
|
||||
@end
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// HttpManager.m
|
||||
// Limelight
|
||||
//
|
||||
// Created by Diego Waxemberg on 10/16/14.
|
||||
// Copyright (c) 2014 Limelight Stream. All rights reserved.
|
||||
//
|
||||
|
||||
#import "HttpManager.h"
|
||||
|
||||
@implementation HttpManager {
|
||||
NSString* _baseURL;
|
||||
NSString* _host;
|
||||
NSString* _uniqueId;
|
||||
NSString* _deviceName;
|
||||
}
|
||||
|
||||
static const NSString* PORT = @"47984";
|
||||
|
||||
|
||||
- (id) initWithHost:(NSString*) host uniqueId:(NSString*) uniqueId deviceName:(NSString*) deviceName {
|
||||
self = [super init];
|
||||
_host = host;
|
||||
_uniqueId = uniqueId;
|
||||
_deviceName = deviceName;
|
||||
_baseURL = [[NSString stringWithFormat:@"https://%@:%@", host, PORT]
|
||||
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSURL*) newPairRequestWithSalt:(NSString*)salt andCert:(NSString*)cert {
|
||||
NSURL* url = [[NSURL alloc] initWithString:
|
||||
[NSString stringWithFormat:@"http://%@:%@/pair?uniqueid=%@&devicename=%@&updateState=1&phrase=getservercert&salt=%@&clientcert=%@",
|
||||
_host, PORT, _uniqueId, _deviceName, salt, cert]];
|
||||
return url;
|
||||
}
|
||||
|
||||
- (void) initiatePairing {
|
||||
|
||||
}
|
||||
|
||||
- (NSString*) generatePIN {
|
||||
NSString* PIN = [NSString stringWithFormat:@"%d%d%d%d",
|
||||
arc4random() % 10, arc4random() % 10,
|
||||
arc4random() % 10, arc4random() % 10];
|
||||
NSLog(@"PIN: %@", PIN);
|
||||
return PIN;
|
||||
}
|
||||
|
||||
- (NSData*) saltPIN:(NSString*)PIN {
|
||||
NSMutableData* saltedPIN = [[NSMutableData alloc] initWithCapacity:20];
|
||||
[saltedPIN appendData:[self randomBytes:16]];
|
||||
[saltedPIN appendBytes:[PIN UTF8String] length:4];
|
||||
|
||||
NSLog(@"Salted PIN: %@", [saltedPIN description]);
|
||||
|
||||
return saltedPIN;
|
||||
}
|
||||
|
||||
- (NSData*) randomBytes:(NSInteger)length {
|
||||
char* bytes = malloc(length);
|
||||
arc4random_buf(bytes, length);
|
||||
NSData* randomData = [NSData dataWithBytes:bytes length:length];
|
||||
free(bytes);
|
||||
return randomData;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -11,6 +11,7 @@
|
||||
#import "ConnectionHandler.h"
|
||||
#import "Computer.h"
|
||||
#import "CryptoManager.h"
|
||||
#import "HttpManager.h"
|
||||
|
||||
@implementation MainFrameViewController
|
||||
NSString* hostAddr;
|
||||
@@ -87,7 +88,10 @@ MDNSManager* mDNSManager;
|
||||
|
||||
mDNSManager = [[MDNSManager alloc] initWithCallback:self];
|
||||
[mDNSManager searchForHosts];
|
||||
[[[CryptoManager alloc] init] generateKeyPairUsingSSl];
|
||||
CryptoManager* cryptMan = [[CryptoManager alloc] init];
|
||||
[cryptMan getUniqueID];
|
||||
HttpManager* hMan = [[HttpManager alloc] init];
|
||||
[hMan saltPIN:[hMan generatePIN]];
|
||||
}
|
||||
|
||||
- (void)updateHosts:(NSArray *)hosts {
|
||||
|
||||
Reference in New Issue
Block a user