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

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

Loading…
Cancel
Save