FRAOathMechanism.h revision 415243fbc81341293a852ff6aa14e9608d08685c
78a072e1b56619e3230735ae073668311232ec94vboxsync/*
78a072e1b56619e3230735ae073668311232ec94vboxsync * The contents of this file are subject to the terms of the Common Development and
78a072e1b56619e3230735ae073668311232ec94vboxsync * Distribution License (the License). You may not use this file except in compliance with the
78a072e1b56619e3230735ae073668311232ec94vboxsync * License.
78a072e1b56619e3230735ae073668311232ec94vboxsync *
78a072e1b56619e3230735ae073668311232ec94vboxsync * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
78a072e1b56619e3230735ae073668311232ec94vboxsync * specific language governing permission and limitations under the License.
78a072e1b56619e3230735ae073668311232ec94vboxsync *
78a072e1b56619e3230735ae073668311232ec94vboxsync * When distributing Covered Software, include this CDDL Header Notice in each file and include
78a072e1b56619e3230735ae073668311232ec94vboxsync * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
78a072e1b56619e3230735ae073668311232ec94vboxsync * Header, with the fields enclosed by brackets [] replaced by your own identifying
78a072e1b56619e3230735ae073668311232ec94vboxsync * information: "Portions copyright [year] [name of copyright owner]".
78a072e1b56619e3230735ae073668311232ec94vboxsync *
78a072e1b56619e3230735ae073668311232ec94vboxsync * Copyright 2016 ForgeRock AS.
78a072e1b56619e3230735ae073668311232ec94vboxsync *
78a072e1b56619e3230735ae073668311232ec94vboxsync * Portions Copyright 2014 Nathaniel McCallum, Red Hat
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync@class FRAIdentity;
78a072e1b56619e3230735ae073668311232ec94vboxsync@class FRAOathCode;
78a072e1b56619e3230735ae073668311232ec94vboxsync#import "FRAMechanism.h"
78a072e1b56619e3230735ae073668311232ec94vboxsync#include <CommonCrypto/CommonHMAC.h>
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync/*!
78a072e1b56619e3230735ae073668311232ec94vboxsync * An OATH authentication mechanism capable of generating HMAC- and Time-based One-Time Passwords.
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync@interface FRAOathMechanism : FRAMechanism
78a072e1b56619e3230735ae073668311232ec94vboxsync/*!
78a072e1b56619e3230735ae073668311232ec94vboxsync * The version number of this OATH mechanism.
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync@property (nonatomic, readonly) NSInteger version;
78a072e1b56619e3230735ae073668311232ec94vboxsync/*!
78a072e1b56619e3230735ae073668311232ec94vboxsync * The type of this OATH mechanism (totp or hotp).
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync@property (nonatomic, readonly) NSString* type;
78a072e1b56619e3230735ae073668311232ec94vboxsync/*!
78a072e1b56619e3230735ae073668311232ec94vboxsync * The length of the OATH code generated by this mechanism. Always 6 or 8; defaults to 6.
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync@property (nonatomic, readonly) NSUInteger digits;
78a072e1b56619e3230735ae073668311232ec94vboxsync/*!
78a072e1b56619e3230735ae073668311232ec94vboxsync * The current login code for this OATH mechanism.
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync@property (nonatomic, readonly) FRAOathCode* code;
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync#pragma mark -
78a072e1b56619e3230735ae073668311232ec94vboxsync#pragma mark Lifecyle
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync/*!
78a072e1b56619e3230735ae073668311232ec94vboxsync * Initialize an OATH Mechanism with all required field to describe either
78a072e1b56619e3230735ae073668311232ec94vboxsync * a HOTP or a TOTP mechanism.
78a072e1b56619e3230735ae073668311232ec94vboxsync *
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param database The database to which this mechanism can be persisted.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param type The OTP type (either "hotp" or "totp").
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param secretKey The secret key bytes used to generate HMAC.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param algorithm The HMAC algorithm to use. Currently only MD5, SHA256, SHA512 and SHA1 are supported.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param digits The length of the key.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param period TOTP based refresh period.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param counter HOTP hash counter.
78a072e1b56619e3230735ae073668311232ec94vboxsync *
78a072e1b56619e3230735ae073668311232ec94vboxsync * @return The initialized mechanism or nil if initialization failed.
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync- (instancetype)initWithDatabase:(FRAIdentityDatabase *)database type:(NSString *)type usingSecretKey:(NSData *)secretKey andHMACAlgorithm:(CCHmacAlgorithm)algorithm withKeyLength:(NSUInteger)digits andEitherPeriod:(NSUInteger)period orCounter:(NSUInteger)counter;
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync/*!
78a072e1b56619e3230735ae073668311232ec94vboxsync * Allocate and initialize an OATH Mechanism with all required field to describe either
78a072e1b56619e3230735ae073668311232ec94vboxsync * a HOTP or a TOTP mechanism.
78a072e1b56619e3230735ae073668311232ec94vboxsync *
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param database The database to which this mechanism can be persisted.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param type The OTP type (either "hotp" or "totp").
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param secretKey The secret key bytes used to generate HMAC.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param algorithm The HMAC algorithm to use. Currently only MD5, SHA256, SHA512 and SHA1 are supported.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param digits The length of the key.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param period TOTP based refresh period.
78a072e1b56619e3230735ae073668311232ec94vboxsync * @param counter HOTP hash counter.
78a072e1b56619e3230735ae073668311232ec94vboxsync *
78a072e1b56619e3230735ae073668311232ec94vboxsync * @return The initialized mechanism or nil if initialization failed.
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync+ (instancetype)oathMechanismWithDatabase:(FRAIdentityDatabase *)database type:(NSString *)type usingSecretKey:(NSData *)secretKey andHMACAlgorithm:(CCHmacAlgorithm)algorithm withKeyLength:(NSUInteger)digits andEitherPeriod:(NSUInteger)period orCounter:(NSUInteger)counter;
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync/*!
78a072e1b56619e3230735ae073668311232ec94vboxsync * Generates the next code for this OATH mechanism.
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync- (void)generateNextCode;
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync@end
78a072e1b56619e3230735ae073668311232ec94vboxsync