FRAOathMechanismFactory.m revision caa9e77dc369fea8df9ae2c598d3c83b7214c1cf
/*
* 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.
*/
#include "base32.h"
#import "FRAError.h"
#import "FRAHotpOathMechanism.h"
#import "FRAIdentity.h"
#import "FRAIdentityDatabase.h"
#import "FRAIdentityModel.h"
#import "FRAMechanismFactory.h"
#import "FRAOathMechanismFactory.h"
#import "FRAQRUtils.h"
#import "FRATotpOathMechanism.h"
- (FRAMechanism *) buildMechanism:(NSURL *)uri database:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel error:(NSError *__autoreleasing *)error {
return nil; // TODO: Error handling integration
}
return nil; // TODO: Error handling integration
}
return nil; // TODO: Error handling integration
}
// TODO: handle Errors or nil values for mechanism and identity
counterString:c];
FRAIdentity *identity = [self identityWithIssuer:issuer accountName:label identityModel:identityModel backgroundColor:bgColor image:image database:database];
return nil;
}
return mechanism;
}
if (scheme == nil || !([scheme isEqualToString:@"otpauth"] || [scheme isEqualToString:@"pushauth"])) {
return nil;
}
if (_type == nil || (![_type isEqualToString:[FRATotpOathMechanism mechanismType]] && ![_type isEqualToString:[FRAHotpOathMechanism mechanismType]])) {
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;
}
/*!
* 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 [FRAHotpOathMechanism mechanismWithDatabase:database identityModel:identityModel secretKey:key HMACAlgorithm:algorithm codeLength:codeLength counter:counter];
} else {
return [FRATotpOathMechanism mechanismWithDatabase:database identityModel:identityModel secretKey:key HMACAlgorithm:algorithm codeLength:codeLength period:period];
}
}
- (FRAIdentity *)identityWithIssuer:(NSString *)issuer accountName:(NSString *)accountName identityModel:(FRAIdentityModel *)identityModel backgroundColor:(NSString *)backgroundColor image:(NSString *)image database:(FRAIdentityDatabase *)database {
if (!identity) {
identity = [FRAIdentity identityWithDatabase:database identityModel:identityModel accountName:accountName issuer:issuer image:[NSURL URLWithString:image] backgroundColor:backgroundColor];
}
}
return identity;
}
// 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