mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2025-07-23 12:44:19 +00:00
56 lines
2.0 KiB
Objective-C
56 lines
2.0 KiB
Objective-C
//
|
|
// CryptoManager.m
|
|
// Limelight
|
|
//
|
|
// Created by Diego Waxemberg on 10/14/14.
|
|
// Copyright (c) 2014 Limelight Stream. All rights reserved.
|
|
//
|
|
|
|
#import "CryptoManager.h"
|
|
#import "mkcert.h"
|
|
#import <AdSupport/ASIdentifierManager.h>
|
|
|
|
@implementation CryptoManager
|
|
|
|
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
|
|
|
|
|
|
}
|
|
|
|
- (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();
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
NSString *documentsDirectory = [paths objectAtIndex:0];
|
|
NSString *certFile = [documentsDirectory stringByAppendingPathComponent:@"client.crt"];
|
|
NSString *keyPairFile = [documentsDirectory stringByAppendingPathComponent:@"client.key"];
|
|
|
|
NSLog(@"Writing cert and key to: \n%@\n%@", certFile, keyPairFile);
|
|
saveCertKeyPair([certFile UTF8String], [keyPairFile UTF8String], certKeyPair);
|
|
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
|