mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-02-16 10:31:02 +00:00
Merge branch 'master' of github.com:limelight-stream/limelight-ios
This commit is contained in:
@@ -12,5 +12,6 @@
|
||||
|
||||
- (void) generateKeyPairUsingSSl;
|
||||
- (NSString*) getUniqueID;
|
||||
- (NSData*) readCertFromFile;
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,6 +17,13 @@
|
||||
|
||||
}
|
||||
|
||||
- (NSData*) readCertFromFile {
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentsDirectory = [paths objectAtIndex:0];
|
||||
NSString *certFile = [documentsDirectory stringByAppendingPathComponent:@"client.crt"];
|
||||
return [NSData dataWithContentsOfFile:certFile];
|
||||
}
|
||||
|
||||
- (void) generateKeyPairUsingSSl {
|
||||
NSLog(@"Generating Certificate: ");
|
||||
CertKeyPair certKeyPair = generateCertKeyPair();
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface HttpManager : NSObject
|
||||
- (id) initWithHost:(NSString*) host uniqueId:(NSString*) uniqueId deviceName:(NSString*) deviceName;
|
||||
- (NSString*) generatePIN;
|
||||
- (NSString*) saltPIN:(NSString*)PIN;
|
||||
- (NSData*) saltPIN:(NSString*)PIN;
|
||||
- (NSURL*) newPairRequestWithSalt:(NSData*)salt andCert:(NSData*)cert;
|
||||
@end
|
||||
|
||||
@@ -28,15 +28,21 @@ static const NSString* PORT = @"47984";
|
||||
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]];
|
||||
- (NSURL*) newPairRequestWithSalt:(NSData*)salt andCert:(NSData*)cert {
|
||||
NSLog(@"host: %@ \nport: %@ \nuniqueID: %@ \ndeviceName: %@ \nsalt: %@ \ncert: %@", _host, PORT, _uniqueId, _deviceName, salt, cert);
|
||||
NSString* urlString = [[NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&phrase=getservercert&salt=%@&clientcert=%@", _baseURL, _uniqueId, _deviceName, [self bytesToHex:salt], [self bytesToHex:cert]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
NSURL* url = [[NSURL alloc] initWithString:urlString];
|
||||
NSLog(@"pair url: %@", url);
|
||||
return url;
|
||||
}
|
||||
|
||||
- (void) initiatePairing {
|
||||
|
||||
- (NSString*) bytesToHex:(NSData*)data {
|
||||
const unsigned char* bytes = [data bytes];
|
||||
NSMutableString *hex = [[NSMutableString alloc] init];
|
||||
for (int i = 0; i < [data length]; i++) {
|
||||
[hex appendFormat:@"%02X" , bytes[i]];
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
- (NSString*) generatePIN {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "MDNSManager.h"
|
||||
|
||||
@interface MainFrameViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, MDNSCallback>
|
||||
@interface MainFrameViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, MDNSCallback, NSURLConnectionDelegate>
|
||||
@property (strong, nonatomic) IBOutlet UIPickerView *HostPicker;
|
||||
- (IBAction)StreamButton:(UIButton *)sender;
|
||||
- (IBAction)PairButton:(UIButton *)sender;
|
||||
|
||||
@@ -88,9 +88,18 @@ MDNSManager* mDNSManager;
|
||||
mDNSManager = [[MDNSManager alloc] initWithCallback:self];
|
||||
[mDNSManager searchForHosts];
|
||||
CryptoManager* cryptMan = [[CryptoManager alloc] init];
|
||||
[cryptMan getUniqueID];
|
||||
HttpManager* hMan = [[HttpManager alloc] init];
|
||||
[hMan saltPIN:[hMan generatePIN]];
|
||||
NSString* uniqueId = [cryptMan getUniqueID];
|
||||
[cryptMan generateKeyPairUsingSSl];
|
||||
NSData* cert = [cryptMan readCertFromFile];
|
||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:hostAddr uniqueId:uniqueId deviceName:@"roth"];
|
||||
NSString* PIN = [hMan generatePIN];
|
||||
NSData* saltedPIN = [hMan saltPIN:PIN];
|
||||
NSLog(@"PIN: %@, saltedPIN: %@", PIN, saltedPIN);
|
||||
NSURL* pairUrl = [hMan newPairRequestWithSalt:saltedPIN andCert:cert];
|
||||
NSURLRequest* pairRequest = [[NSURLRequest alloc] initWithURL:pairUrl];
|
||||
NSLog(@"making pair request: %@", [pairRequest description]);
|
||||
NSData* pairData = [NSURLConnection sendSynchronousRequest:pairRequest returningResponse:nil error:nil];
|
||||
NSLog(@"Pair response: %@", [pairData description]);
|
||||
}
|
||||
|
||||
- (void)updateHosts:(NSArray *)hosts {
|
||||
|
||||
Reference in New Issue
Block a user