]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/tests/CloudKitKeychainSyncingMockXCTest.h
Security-58286.20.16.tar.gz
[apple/security.git] / keychain / ckks / tests / CloudKitKeychainSyncingMockXCTest.h
1 /*
2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 #import "CloudKitMockXCTest.h"
24 #import "keychain/ckks/CKKS.h"
25 #import "keychain/ckks/CKKSCurrentKeyPointer.h"
26
27 @class CKKSKey;
28 @class CKKSCurrentKeyPointer;
29
30 @interface ZoneKeys : CKKSCurrentKeySet
31 @property CKKSKey* rolledTLK;
32 @end
33
34 /*
35 * Builds on the CloudKit mock infrastructure and adds keychain helper methods.
36 */
37
38 @interface CloudKitKeychainSyncingMockXCTest : CloudKitMockXCTest
39
40 @property id mockCKKSKey;
41
42 @property NSMutableDictionary<CKRecordZoneID*, ZoneKeys*>* keys;
43
44 // Pass in an oldTLK to wrap it to the new TLK; otherwise, pass nil
45 - (ZoneKeys*)createFakeKeyHierarchy: (CKRecordZoneID*)zoneID oldTLK:(CKKSKey*) oldTLK;
46 - (void)saveFakeKeyHierarchyToLocalDatabase: (CKRecordZoneID*)zoneID;
47 - (void)putFakeKeyHierarchyInCloudKit: (CKRecordZoneID*)zoneID;
48 - (void)saveTLKMaterialToKeychain: (CKRecordZoneID*)zoneID;
49 - (void)deleteTLKMaterialFromKeychain: (CKRecordZoneID*)zoneID;
50 - (void)saveTLKMaterialToKeychainSimulatingSOS: (CKRecordZoneID*)zoneID;
51 - (void)SOSPiggyBackAddToKeychain:(NSDictionary*)piggydata;
52 - (NSMutableDictionary*)SOSPiggyBackCopyFromKeychain;
53 - (NSMutableArray<NSData *>*) SOSPiggyICloudIdentities;
54
55 - (void)saveClassKeyMaterialToKeychain: (CKRecordZoneID*)zoneID;
56
57 // Call this to fake out your test: all keys are created, saved in cloudkit, and saved locally (as if the key state machine had processed them)
58 - (void)createAndSaveFakeKeyHierarchy: (CKRecordZoneID*)zoneID;
59
60 - (void)rollFakeKeyHierarchyInCloudKit: (CKRecordZoneID*)zoneID;
61
62 - (NSDictionary*)fakeRecordDictionary:(NSString*) account zoneID:(CKRecordZoneID*)zoneID;
63 - (CKRecord*)createFakeRecord: (CKRecordZoneID*)zoneID recordName:(NSString*)recordName ;
64 - (CKRecord*)createFakeRecord: (CKRecordZoneID*)zoneID recordName:(NSString*)recordName withAccount: (NSString*) account;
65 - (CKRecord*)createFakeRecord: (CKRecordZoneID*)zoneID recordName:(NSString*)recordName withAccount: (NSString*) account key:(CKKSKey*)key;
66
67 - (CKRecord*)newRecord: (CKRecordID*) recordID withNewItemData:(NSDictionary*) dictionary;
68 - (CKRecord*)newRecord: (CKRecordID*) recordID withNewItemData:(NSDictionary*) dictionary key:(CKKSKey*)key;
69 - (NSDictionary*)decryptRecord: (CKRecord*) record;
70
71 // Do keychain things:
72 - (void)addGenericPassword: (NSString*) password account: (NSString*) account;
73 - (void)addGenericPassword: (NSString*) password account: (NSString*) account viewHint:(NSString*)viewHint;
74 - (void)addGenericPassword: (NSString*) password account: (NSString*) account viewHint: (NSString*) viewHint access:(NSString*)access expecting: (OSStatus) status message: (NSString*) message;
75 - (void)addGenericPassword: (NSString*) password account: (NSString*) account expecting: (OSStatus) status message: (NSString*) message;
76
77 - (void)updateGenericPassword: (NSString*) newPassword account: (NSString*)account;
78 - (void)updateAccountOfGenericPassword:(NSString*)newAccount account:(NSString*)account;
79
80 - (void)checkNoCKKSData: (CKKSKeychainView*) view;
81
82 - (void)deleteGenericPassword: (NSString*) account;
83
84 - (void)findGenericPassword: (NSString*) account expecting: (OSStatus) status;
85 - (void)checkGenericPassword: (NSString*) password account: (NSString*) account;
86
87 - (void)createClassCItemAndWaitForUpload:(CKRecordZoneID*)zoneID account:(NSString*)account;
88 - (void)createClassAItemAndWaitForUpload:(CKRecordZoneID*)zoneID account:(NSString*)account;
89
90 // Pass the blocks created with these to expectCKModifyItemRecords to check if all items were encrypted with a particular class key
91 - (BOOL (^) (CKRecord*)) checkClassABlock: (CKRecordZoneID*) zoneID message:(NSString*) message;
92 - (BOOL (^) (CKRecord*)) checkClassCBlock: (CKRecordZoneID*) zoneID message:(NSString*) message;
93
94 - (BOOL (^) (CKRecord*)) checkPasswordBlock:(CKRecordZoneID*)zoneID
95 account:(NSString*)account
96 password:(NSString*)password;
97
98 - (void)checkNSyncableTLKsInKeychain:(size_t)n;
99
100 // Returns an expectation that someone will send an NSNotification that this view changed
101 -(XCTestExpectation*)expectChangeForView:(NSString*)view;
102 @end