FRAOathMechanismFactory.m revision f877f6ca2428244a6d0954a1dbef471577b32c60
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2016 ForgeRock AS.
*/
#import "FRAOathMechanismFactory.h"
#import "FRAMechanismFactory.h"
#import "FRAOathMechanism.h"
#import "FRAIdentity.h"
#import "FRAIdentityDatabase.h"
#import "FRAIdentityModel.h"
#import "FRAQRUtils.h"
#include "base32.h"
- (FRAMechanism *) buildMechanism:(NSURL *)uri database:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel {
return nil; // TODO: Error handeling integration
}
return nil; // TODO: Error handeling integration
}
return nil; // TODO: Error handling integration
}
// TODO: handle Errors or nil values for mechanism and identity
counterString:c];
FRAIdentity *identity = [self getIdentity:uri database:database identityModel:identityModel image:image issuer:issuer label:label backgroundColor:bgColor];
FRAIdentity *search = [identityModel identityWithIssuer:[identity issuer] accountName:[identity accountName]];
}
} else {
// TODO: populate NSError
return nil;
}
}
}
return mechanism;
}
if (scheme == nil || !([scheme isEqualToString:@"otpauth"] || [scheme isEqualToString:@"pushauth"])) {
return nil;
}
return nil;
}
// Get the path and strip it of its leading '/'
return nil;
}
}
return nil;
}
// Get issuer and label
return nil;
}
} else {
_issuer = @"";
}
// Parse query
// Value can contain '=' symbols, so look for first symbol.
continue;
}
}
return query;
}
return false;
}
/*!
* Make a mechanism from the required data
*/
// verify
return nil;
}
// get period
if (nil == periodString) {
period = 30;
} else {
}
if (0 == period) {
period = 30;
}
// Get counter
}
// TODO: Implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long')
// to 'NSUInteger' (aka 'unsigned int')
return [FRAOathMechanism oathMechanismWithDatabase:database identityModel:identityModel type:type usingSecretKey:key andHMACAlgorithm:algo withKeyLength:digits andEitherPeriod:period orCounter:counter];
}
/*!
* Resolves the Identity from the URL that has been provided.
* @return an initialised but not persisted Identity.
*/
- (FRAIdentity *)getIdentity:(NSURL*)uri database:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel image:(NSString *)image issuer:(NSString *)issuer label:(NSString *)label backgroundColor:(NSString*)bgColor{
// Get image
// TODO: get real image from url
NSURL* _image = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"forgerock-logo" ofType:@"png"]];
return [FRAIdentity identityWithDatabase:database identityModel:identityModel accountName:label issuer:issuer image:_image backgroundColor:bgColor];
}
// TODO: Currently hardcoded to one scheme, upgrade to support multiple.
return false;
}
return true;
}
- (NSString *) getSupportedProtocol {
return @"otpauth";
}
return nil;
}
return nil;
}
return nil;
}
}
static struct {
const char *name;
} algomap[] = {
{ "md5", kCCHmacAlgMD5 },
{ "sha1", kCCHmacAlgSHA1 },
{ "sha256", kCCHmacAlgSHA256 },
{ "sha512", kCCHmacAlgSHA512 },
};
return kCCHmacAlgSHA1;
}
return kCCHmacAlgSHA1;
}
}
}
return kCCHmacAlgSHA1;
}
return 6;
}
return 6;
}
return val;
}
@end