2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 #import "CloudKitMockXCTest.h"
24 #import "keychain/ckks/CKKS.h"
25 #import "keychain/ckks/CKKSCurrentKeyPointer.h"
28 @
class CKKSCurrentKeyPointer
;
30 @interface ZoneKeys
: CKKSCurrentKeySet
31 @property CKKSKey
* rolledTLK
;
35 * Builds on the CloudKit mock infrastructure and adds keychain helper methods.
38 @interface CloudKitKeychainSyncingMockXCTest
: CloudKitMockXCTest
40 @property id mockCKKSKey
;
42 @property NSMutableDictionary
<CKRecordZoneID
*, ZoneKeys
*>* keys
;
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
;
55 - (void)saveClassKeyMaterialToKeychain
: (CKRecordZoneID
*)zoneID
;
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
;
60 - (void)rollFakeKeyHierarchyInCloudKit
: (CKRecordZoneID
*)zoneID
;
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
;
67 - (CKRecord
*)newRecord
: (CKRecordID
*) recordID withNewItemData
:(NSDictionary
*) dictionary
;
68 - (CKRecord
*)newRecord
: (CKRecordID
*) recordID withNewItemData
:(NSDictionary
*) dictionary key
:(CKKSKey
*)key
;
69 - (NSDictionary
*)decryptRecord
: (CKRecord
*) record
;
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
;
77 - (void)updateGenericPassword
: (NSString
*) newPassword account
: (NSString
*)account
;
78 - (void)updateAccountOfGenericPassword
:(NSString
*)newAccount account
:(NSString
*)account
;
80 - (void)checkNoCKKSData
: (CKKSKeychainView
*) view
;
82 - (void)deleteGenericPassword
: (NSString
*) account
;
84 - (void)findGenericPassword
: (NSString
*) account expecting
: (OSStatus
) status
;
85 - (void)checkGenericPassword
: (NSString
*) password account
: (NSString
*) account
;
87 - (void)createClassCItemAndWaitForUpload
:(CKRecordZoneID
*)zoneID account
:(NSString
*)account
;
88 - (void)createClassAItemAndWaitForUpload
:(CKRecordZoneID
*)zoneID account
:(NSString
*)account
;
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
;
94 - (BOOL (^) (CKRecord
*)) checkPasswordBlock
:(CKRecordZoneID
*)zoneID
95 account
:(NSString
*)account
96 password
:(NSString
*)password
;
98 - (void)checkNSyncableTLKsInKeychain
:(size_t)n
;
100 // Returns an expectation that someone will send an NSNotification that this view changed
101 -(XCTestExpectation
*)expectChangeForView
:(NSString
*)view
;