/*
* 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 "FMDatabase.h"
#import "FRAError.h"
#import "FRAFMDatabaseConnectionHelper.h"
#import "FRAOathCode.h"
#import "FRAIdentity.h"
#import "FRAModelObjectProtected.h"
#import "FRAModelsFromDatabase.h"
#import "FRANotification.h"
#import "FRAHotpOathMechanism.h"
#import "FRATotpOathMechanism.h"
#import "FRAPushMechanism.h"
#import "FRASerialization.h"
/*!
*/
/*!
* The parsing logic operates as follows:
*
* Perform SQL query to fetch all Identities, Mechanisms and Notifications where each
* Identity may have multiple associated Mechanisms and PushMechanisms may have multiple
* associated Notifications.
*
* The function will re-use matching Identities and Push Mechanisms as appropriate.
*
* TODO: Split into smaller functions.
*/
+ (NSArray<FRAIdentity*> *)allIdentitiesWithDatabase:(FRAFMDatabaseConnectionHelper *)sqlDatabase identityDatabase:(FRAIdentityDatabase *)identityDatabase identityModel:(FRAIdentityModel *)identityModel error:(NSError *__autoreleasing *)error {
if (!sql) {
return nil;
}
// Open Database
@try {
if (!database) {
return nil;
}
// Perform update
if (!results) {
if (error) {
}
return nil;
}
// Output rows for debugging purposes.
NSLog(@"Reading all rows from the database:");
int row = 0;
// Identity
// Mechanism
// Notification
NSLog(@"[%d] %@ %@ %@ %@ %@ %ld %@ %@ %@ %d %d",
row,
type,
(long)version,
approved);
row++;
// Create an Identity
// Check if we already have generated this identity, in which case re-use.
if ([newIdentity.issuer isEqualToString:identity.issuer] && [newIdentity.accountName isEqualToString:identity.accountName]) {
add = false;
break;
}
}
if (add) {
}
// Formatter for parsing numbers from Strings.
// Create the Mechanism
// Options Map is a String to String mapping stored in JSON.
return nil;
}
// Secret Key - Base 64 encoded bytes
// Algorithm - String enumeration
// Code Length - String value of Integer
// Counter - String value of unsigned Long Long
// Note: We are not de-duplicating OATH Mechanism because they will not be duplicated in the SQL results.
return nil;
}
// Options Map is a String to String mapping stored in JSON.
return nil;
}
// Secret Key - Base 64 encoded bytes
// Algorithm - String enumeration
// Code Length - String value of Integer
// Period - String value of unsigned Integer
// Note: We are not de-duplicating OATH Mechanism because they will not be duplicated in the SQL results.
return nil;
}
// Options Map is a String to String mapping stored in JSON.
return nil;
}
// Secret stored as String (Base64?)
// Auth Endpoint as string
// Version as string
// Check to see if we already have this PushMechanism present, otherwise add it in.
add = false;
break;
}
}
}
if (add) {
return nil;
}
}
// If we have a notification, parse and create the Notification for the Push Mechanism.
// Note: Notifications can only currently exist for PushMechanisms.
// Extract notifcation data from database
return nil;
}
NSString *challenge = [[NSString alloc] initWithData:[FRASerialization deserializeBytes:[dataMap valueForKey:NOTIFICATION_PUSH_CHALLENGE]] encoding:NSUTF8StringEncoding];
// recreate notificaiton
return nil;
}
}
} else {
}
}
// As we have read the objects from the database, marked them as stored.
}
}
}
return identities;
}
@finally {
}
}
@end