2 * Copyright (c) 2015 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@
25 @header SOSBackupSliceKeyBag.h - View Bags - backup bags for views
28 #ifndef _sec_SOSBackupSliceKeyBag_
29 #define _sec_SOSBackupSliceKeyBag_
31 #include <CoreFoundation/CoreFoundation.h>
32 #include <Security/SecureObjectSync/SOSPeerInfo.h>
34 extern CFStringRef bskbRkbgPrefix
;
36 CFDataRef
SOSRKNullKey(void);
38 // We don't have a portable header (particularly for the SIM) so for now we define the one type we need.
39 // This should be fixed when we get a portable AKS interface.
40 typedef int32_t bskb_keybag_handle_t
;
42 typedef struct CF_BRIDGED_TYPE(id
) __OpaqueSOSBackupSliceKeyBag
*SOSBackupSliceKeyBagRef
;
44 SOSBackupSliceKeyBagRef
SOSBackupSliceKeyBagCreate(CFAllocatorRef allocator
, CFSetRef peers
, CFErrorRef
* error
);
45 SOSBackupSliceKeyBagRef
SOSBackupSliceKeyBagCreateDirect(CFAllocatorRef allocator
, CFDataRef aks_bag
, CFErrorRef
*error
);
47 SOSBackupSliceKeyBagRef
SOSBackupSliceKeyBagCreateWithAdditionalKeys(CFAllocatorRef allocator
,
48 CFSetRef
/*SOSPeerInfoRef*/ peers
,
49 CFDictionaryRef
/*CFStringRef (prefix) CFDataRef (keydata) */ additionalKeys
,
52 SOSBackupSliceKeyBagRef
SOSBackupSliceKeyBagCreateFromData(CFAllocatorRef allocator
, CFDataRef data
, CFErrorRef
*error
);
54 CFDataRef
SOSBSKBCopyEncoded(SOSBackupSliceKeyBagRef BackupSliceKeyBag
, CFErrorRef
* error
);
57 bool SOSBSKBIsDirect(SOSBackupSliceKeyBagRef backupSliceKeyBag
);
59 CFSetRef
SOSBSKBGetPeers(SOSBackupSliceKeyBagRef backupSliceKeyBag
);
61 int SOSBSKBCountPeers(SOSBackupSliceKeyBagRef backupSliceKeyBag
);
63 bool SOSBSKBPeerIsInKeyBag(SOSBackupSliceKeyBagRef backupSliceKeyBag
, SOSPeerInfoRef pi
);
64 bool SOSBKSBKeyIsInKeyBag(SOSBackupSliceKeyBagRef backupSliceKeyBag
, CFDataRef publicKey
);
65 bool SOSBKSBPeerBackupKeyIsInKeyBag(SOSBackupSliceKeyBagRef backupSliceKeyBag
, SOSPeerInfoRef pi
);
66 bool SOSBSKBAllPeersBackupKeysAreInKeyBag(SOSBackupSliceKeyBagRef backupSliceKeyBag
, CFSetRef peers
);
67 bool SOSBKSBPrefixedKeyIsInKeyBag(SOSBackupSliceKeyBagRef backupSliceKeyBag
, CFStringRef prefix
, CFDataRef publicKey
);
70 CFDataRef
SOSBSKBCopyAKSBag(SOSBackupSliceKeyBagRef backupSliceKeyBag
, CFErrorRef
* error
);
74 const uint8_t* der_decode_BackupSliceKeyBag(CFAllocatorRef allocator
,
75 SOSBackupSliceKeyBagRef
* BackupSliceKeyBag
, CFErrorRef
*error
,
76 const uint8_t* der
, const uint8_t *der_end
);
78 size_t der_sizeof_BackupSliceKeyBag(SOSBackupSliceKeyBagRef BackupSliceKeyBag
, CFErrorRef
*error
);
79 uint8_t* der_encode_BackupSliceKeyBag(SOSBackupSliceKeyBagRef BackupSliceKeyBag
, CFErrorRef
*error
,
80 const uint8_t *der
, uint8_t *der_end
);
82 bskb_keybag_handle_t
SOSBSKBLoadLocked(SOSBackupSliceKeyBagRef backupSliceKeyBag
,
85 bskb_keybag_handle_t
SOSBSKBLoadAndUnlockWithPeerIDAndSecret(SOSBackupSliceKeyBagRef backupSliceKeyBag
,
86 CFStringRef peerID
, CFDataRef peerSecret
,
89 bskb_keybag_handle_t
SOSBSKBLoadAndUnlockWithPeerSecret(SOSBackupSliceKeyBagRef backupSliceKeyBag
,
90 SOSPeerInfoRef peer
, CFDataRef peerSecret
,
93 bskb_keybag_handle_t
SOSBSKBLoadAndUnlockWithDirectSecret(SOSBackupSliceKeyBagRef backupSliceKeyBag
,
94 CFDataRef directSecret
,
97 bskb_keybag_handle_t
SOSBSKBLoadAndUnlockWithWrappingSecret(SOSBackupSliceKeyBagRef backupSliceKeyBag
,
98 CFDataRef wrappingSecret
,
101 // Utilities for backup keys
102 bool SOSBSKBIsGoodBackupPublic(CFDataRef publicKey
, CFErrorRef
*error
);
104 CFDataRef
SOSBSKBCopyRecoveryKey(SOSBackupSliceKeyBagRef bskb
);
105 bool SOSBSKBHasRecoveryKey(SOSBackupSliceKeyBagRef bskb
);
106 bool SOSBSKBHasThisRecoveryKey(SOSBackupSliceKeyBagRef bskb
, CFDataRef backupKey
);
108 #endif /* defined(_sec_SOSBackupSliceKeyBag_) */