]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/tests/CloudKitKeychainSyncingMockXCTest.h
Security-58286.240.4.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
24 #if OCTAGON
25
26 #import "CloudKitMockXCTest.h"
27 #import "keychain/ckks/CKKS.h"
28 #import "keychain/ckks/CKKSControl.h"
29 #import "keychain/ckks/CKKSCurrentKeyPointer.h"
30 #import "keychain/ckks/CKKSItem.h"
31
32 NS_ASSUME_NONNULL_BEGIN
33
34 @class CKKSKey;
35 @class CKKSCurrentKeyPointer;
36
37 @interface ZoneKeys : CKKSCurrentKeySet
38 @property CKKSKey* rolledTLK;
39
40 - (instancetype)initLoadingRecordsFromZone:(FakeCKZone*)zone;
41 @end
42
43 /*
44 * Builds on the CloudKit mock infrastructure and adds keychain helper methods.
45 */
46
47 @interface CloudKitKeychainSyncingMockXCTest : CloudKitMockXCTest
48
49 @property CKKSControl* ckksControl;
50
51 @property (nullable) id mockCKKSKey;
52
53 @property (nullable) CKKSSOSSelfPeer* currentSelfPeer;
54 @property (nullable) NSError* currentSelfPeerError;
55 @property (nullable) NSMutableSet<id<CKKSPeer>>* currentPeers;
56 @property (nullable) NSError* currentPeersError;
57
58 @property (nullable) NSError* keychainFetchError;
59
60 // A single trusted SOSPeer, but without any CKKS keys
61 @property CKKSSOSPeer* remoteSOSOnlyPeer;
62
63 @property NSMutableSet<CKKSKeychainView*>* ckksViews;
64 @property NSMutableSet<CKRecordZoneID*>* ckksZones;
65 @property (nullable) NSMutableDictionary<CKRecordZoneID*, ZoneKeys*>* keys;
66
67 // Pass in an oldTLK to wrap it to the new TLK; otherwise, pass nil
68 - (ZoneKeys*)createFakeKeyHierarchy:(CKRecordZoneID*)zoneID oldTLK:(CKKSKey* _Nullable)oldTLK;
69 - (void)saveFakeKeyHierarchyToLocalDatabase:(CKRecordZoneID*)zoneID;
70 - (void)putFakeKeyHierarchyInCloudKit:(CKRecordZoneID*)zoneID;
71 - (void)saveTLKMaterialToKeychain:(CKRecordZoneID*)zoneID;
72 - (void)deleteTLKMaterialFromKeychain:(CKRecordZoneID*)zoneID;
73 - (void)saveTLKMaterialToKeychainSimulatingSOS:(CKRecordZoneID*)zoneID;
74 - (void)putFakeDeviceStatusInCloudKit:(CKRecordZoneID*)zoneID;
75 - (void)putFakeDeviceStatusInCloudKit:(CKRecordZoneID*)zoneID
76 zonekeys:(ZoneKeys*)zonekeys;
77
78 - (void)SOSPiggyBackAddToKeychain:(NSDictionary*)piggydata;
79 - (NSMutableDictionary*)SOSPiggyBackCopyFromKeychain;
80 - (NSMutableArray<NSData*>*)SOSPiggyICloudIdentities;
81
82 - (void)putTLKShareInCloudKit:(CKKSKey*)key
83 from:(CKKSSOSSelfPeer*)sharingPeer
84 to:(id<CKKSPeer>)receivingPeer
85 zoneID:(CKRecordZoneID*)zoneID;
86 - (void)putTLKSharesInCloudKit:(CKKSKey*)key from:(CKKSSOSSelfPeer*)sharingPeer zoneID:(CKRecordZoneID*)zoneID;
87 - (void)putSelfTLKSharesInCloudKit:(CKRecordZoneID*)zoneID;
88 - (void)saveTLKSharesInLocalDatabase:(CKRecordZoneID*)zoneID;
89
90 - (void)saveClassKeyMaterialToKeychain:(CKRecordZoneID*)zoneID;
91
92 // 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)
93 - (void)createAndSaveFakeKeyHierarchy:(CKRecordZoneID*)zoneID;
94
95 - (void)rollFakeKeyHierarchyInCloudKit:(CKRecordZoneID*)zoneID;
96
97 - (NSDictionary*)fakeRecordDictionary:(NSString* _Nullable)account zoneID:(CKRecordZoneID*)zoneID;
98 - (CKRecord*)createFakeRecord:(CKRecordZoneID*)zoneID recordName:(NSString*)recordName;
99 - (CKRecord*)createFakeRecord:(CKRecordZoneID*)zoneID recordName:(NSString*)recordName withAccount:(NSString* _Nullable)account;
100 - (CKRecord*)createFakeRecord:(CKRecordZoneID*)zoneID
101 recordName:(NSString*)recordName
102 withAccount:(NSString* _Nullable)account
103 key:(CKKSKey* _Nullable)key;
104
105 - (CKKSItem*)newItem:(CKRecordID*)recordID withNewItemData:(NSDictionary*) dictionary key:(CKKSKey*)key;
106 - (CKRecord*)newRecord:(CKRecordID*)recordID withNewItemData:(NSDictionary*)dictionary;
107 - (CKRecord*)newRecord:(CKRecordID*)recordID withNewItemData:(NSDictionary*)dictionary key:(CKKSKey*)key;
108 - (NSDictionary*)decryptRecord:(CKRecord*)record;
109
110 // Do keychain things:
111 - (void)addGenericPassword:(NSString*)password account:(NSString*)account;
112 - (void)addGenericPassword:(NSString*)password account:(NSString*)account viewHint:(NSString* _Nullable)viewHint;
113 - (void)addGenericPassword:(NSString*)password
114 account:(NSString*)account
115 viewHint:(NSString* _Nullable)viewHint
116 access:(NSString*)access
117 expecting:(OSStatus)status
118 message:(NSString*)message;
119 - (void)addGenericPassword:(NSString*)password account:(NSString*)account expecting:(OSStatus)status message:(NSString*)message;
120
121 - (void)updateGenericPassword:(NSString*)newPassword account:(NSString*)account;
122 - (void)updateAccountOfGenericPassword:(NSString*)newAccount account:(NSString*)account;
123
124 - (void)checkNoCKKSData:(CKKSKeychainView*)view;
125
126 - (void)deleteGenericPassword:(NSString*)account;
127
128 - (void)findGenericPassword:(NSString*)account expecting:(OSStatus)status;
129 - (void)checkGenericPassword:(NSString*)password account:(NSString*)account;
130
131 - (void)createClassCItemAndWaitForUpload:(CKRecordZoneID*)zoneID account:(NSString*)account;
132 - (void)createClassAItemAndWaitForUpload:(CKRecordZoneID*)zoneID account:(NSString*)account;
133
134 // Pass the blocks created with these to expectCKModifyItemRecords to check if all items were encrypted with a particular class key
135 - (BOOL (^)(CKRecord*))checkClassABlock:(CKRecordZoneID*)zoneID message:(NSString*)message;
136 - (BOOL (^)(CKRecord*))checkClassCBlock:(CKRecordZoneID*)zoneID message:(NSString*)message;
137
138 - (BOOL (^)(CKRecord*))checkPasswordBlock:(CKRecordZoneID*)zoneID account:(NSString*)account password:(NSString*)password;
139
140 - (void)checkNSyncableTLKsInKeychain:(size_t)n;
141
142 // Returns an expectation that someone will send an NSNotification that this view changed
143 - (XCTestExpectation*)expectChangeForView:(NSString*)view;
144
145 // Establish an assertion that CKKS will cause a server extension error soon.
146 - (void)expectCKReceiveSyncKeyHierarchyError:(CKRecordZoneID*)zoneID;
147
148 // Add expectations that CKKS will upload a single TLK share
149 - (void)expectCKKSTLKSelfShareUpload:(CKRecordZoneID*)zoneID;
150 @end
151
152 NS_ASSUME_NONNULL_END
153
154 #endif /* OCTAGON */