callback handlers for remote attestation

pull/1/head
Michael Kirk 7 years ago
parent e27e45e661
commit dedfea78da

@ -4,6 +4,8 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class RemoteAttestation;
@interface ContactDiscoveryService : NSObject @interface ContactDiscoveryService : NSObject
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
@ -11,7 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)sharedService; + (instancetype)sharedService;
- (void)testService; - (void)testService;
- (void)performRemoteAttestationWithSuccess:(void (^)(RemoteAttestation *_Nonnull remoteAttestation))successHandler
failure:(void (^)(NSError *_Nonnull error))failureHandler;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -8,6 +8,7 @@
#import "Cryptography.h" #import "Cryptography.h"
#import "NSData+OWS.h" #import "NSData+OWS.h"
#import "NSDate+OWS.h" #import "NSDate+OWS.h"
#import "OWSError.h"
#import "OWSRequestFactory.h" #import "OWSRequestFactory.h"
#import "TSNetworkManager.h" #import "TSNetworkManager.h"
#import <Curve25519Kit/Curve25519.h> #import <Curve25519Kit/Curve25519.h>
@ -219,34 +220,48 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testService - (void)testService
{ {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self performRemoteAttestation]; [self
performRemoteAttestationWithSuccess:^(RemoteAttestation *_Nonnull remoteAttestation) {
DDLogDebug(@"%@ in %s succeeded", self.logTag, __PRETTY_FUNCTION__);
}
failure:^(NSError *_Nonnull error) {
DDLogDebug(@"%@ in %s failed with error: %@", self.logTag, __PRETTY_FUNCTION__, error);
}];
}); });
} }
- (void)performRemoteAttestation - (void)performRemoteAttestationWithSuccess:(void (^)(RemoteAttestation *_Nonnull remoteAttestation))successHandler
failure:(void (^)(NSError *_Nonnull error))failureHandler
{ {
[self performRemoteAttestationAuth]; [self
getRemoteAttestationAuthWithSuccess:^(RemoteAttestationAuth *_Nonnull auth) {
[self performRemoteAttestationWithAuth:auth success:successHandler failure:failureHandler];
}
failure:failureHandler];
} }
// TODO: Add success and failure? - (void)getRemoteAttestationAuthWithSuccess:(void (^)(RemoteAttestationAuth *))successHandler
- (void)performRemoteAttestationAuth failure:(void (^)(NSError *_Nonnull error))failureHandler
{ {
TSRequest *request = [OWSRequestFactory remoteAttestationAuthRequest]; TSRequest *request = [OWSRequestFactory remoteAttestationAuthRequest];
[[TSNetworkManager sharedManager] makeRequest:request [[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseDict) { success:^(NSURLSessionDataTask *task, id responseDict) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
RemoteAttestationAuth *_Nullable auth = [self parseAuthToken:responseDict]; RemoteAttestationAuth *_Nullable auth = [self parseAuthToken:responseDict];
if (!auth) { if (!auth) {
DDLogError(@"%@ remote attestation auth could not be parsed: %@", self.logTag, responseDict); DDLogError(@"%@ remote attestation auth could not be parsed: %@", self.logTag, responseDict);
NSError *error = OWSErrorMakeUnableToProcessServerResponseError();
failureHandler(error);
return; return;
} }
[self performRemoteAttestationWithAuth:auth];
successHandler(auth);
}); });
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
DDLogVerbose(@"%@ remote attestation auth failure: %zd", self.logTag, response.statusCode); DDLogVerbose(@"%@ remote attestation auth failure: %zd", self.logTag, response.statusCode);
failureHandler(error);
}]; }];
} }
@ -276,6 +291,8 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (void)performRemoteAttestationWithAuth:(RemoteAttestationAuth *)auth - (void)performRemoteAttestationWithAuth:(RemoteAttestationAuth *)auth
success:(void (^)(RemoteAttestation *_Nonnull remoteAttestation))successHandler
failure:(void (^)(NSError *_Nonnull error))failureHandler
{ {
ECKeyPair *keyPair = [Curve25519 generateKeyPair]; ECKeyPair *keyPair = [Curve25519 generateKeyPair];
@ -290,15 +307,24 @@ NS_ASSUME_NONNULL_BEGIN
success:^(NSURLSessionDataTask *task, id responseJson) { success:^(NSURLSessionDataTask *task, id responseJson) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// TODO: Handle result. // TODO: Handle result.
[self parseAttestationResponseJson:responseJson RemoteAttestation *_Nullable attestation = [self parseAttestationResponseJson:responseJson
response:task.response response:task.response
keyPair:keyPair keyPair:keyPair
enclaveId:enclaveId]; enclaveId:enclaveId];
if (!attestation) {
NSError *error = OWSErrorMakeUnableToProcessServerResponseError();
failureHandler(error);
return;
}
successHandler(attestation);
}); });
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
DDLogVerbose(@"%@ remote attestation failure: %zd", self.logTag, response.statusCode); DDLogVerbose(@"%@ remote attestation failure: %zd", self.logTag, response.statusCode);
failureHandler(error);
}]; }];
} }

Loading…
Cancel
Save