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@
26 #import <Foundation/Foundation.h>
28 #import "keychain/ckks/CKKS.h"
29 #import "keychain/ckks/CKKSItem.h"
30 #import "keychain/ckks/CKKSKey.h"
31 #import "keychain/ckks/CKKSPeer.h"
32 #import "keychain/ckks/CKKSTLKShare.h"
34 #import <SecurityFoundation/SFEncryptionOperation.h>
35 #import <SecurityFoundation/SFKey.h>
37 NS_ASSUME_NONNULL_BEGIN
39 @interface CKKSTLKShareRecord
: CKKSCKRecordHolder
40 @property CKKSTLKShare
* share
;
42 // Passthroughs to the underlying share
43 @
property (readonly
) NSString
* tlkUUID
;
45 @
property (readonly
) NSString
* senderPeerID
;
47 @
property (readonly
) NSInteger epoch
;
48 @
property (readonly
) NSInteger poisoned
;
50 @
property (readonly
, nullable
) NSData
* wrappedTLK
;
51 @
property (readonly
, nullable
) NSData
* signature
;
53 - (instancetype
)init NS_UNAVAILABLE
;
55 - (CKKSKey
* _Nullable
)recoverTLK
:(id
<CKKSSelfPeer
>)recoverer trustedPeers
:(NSSet
<id
<CKKSPeer
>>*)peers error
:(NSError
**)error
;
57 + (CKKSTLKShareRecord
* _Nullable
)share
:(CKKSKey
*)key
58 as
:(id
<CKKSSelfPeer
>)sender
59 to
:(id
<CKKSPeer
>)receiver
60 epoch
:(NSInteger
)epoch
61 poisoned
:(NSInteger
)poisoned
62 error
:(NSError
**)error
;
64 - (bool)signatureVerifiesWithPeerSet
:(NSSet
<id
<CKKSPeer
>>*)peerSet error
:(NSError
**)error
;
66 - (NSData
*)dataForSigning
;
69 + (instancetype _Nullable
)fromDatabase
:(NSString
*)uuid
70 receiverPeerID
:(NSString
*)receiverPeerID
71 senderPeerID
:(NSString
*)senderPeerID
72 zoneID
:(CKRecordZoneID
*)zoneID
73 error
:(NSError
* __autoreleasing
*)error
;
74 + (instancetype _Nullable
)tryFromDatabase
:(NSString
*)uuid
75 receiverPeerID
:(NSString
*)receiverPeerID
76 senderPeerID
:(NSString
*)senderPeerID
77 zoneID
:(CKRecordZoneID
*)zoneID
78 error
:(NSError
**)error
;
79 + (NSArray
<CKKSTLKShareRecord
*>*)allFor
:(NSString
*)receiverPeerID
80 keyUUID
:(NSString
*)uuid
81 zoneID
:(CKRecordZoneID
*)zoneID
82 error
:(NSError
* __autoreleasing
*)error
;
83 + (NSArray
<CKKSTLKShareRecord
*>*)allForUUID
:(NSString
*)uuid zoneID
:(CKRecordZoneID
*)zoneID error
:(NSError
**)error
;
84 + (NSArray
<CKKSTLKShareRecord
*>*)allInZone
:(CKRecordZoneID
*)zoneID error
:(NSError
**)error
;
85 + (instancetype _Nullable
)tryFromDatabaseFromCKRecordID
:(CKRecordID
*)recordID error
:(NSError
**)error
;
87 // Returns a prefix that all every CKKSTLKShare CKRecord will have
88 + (NSString
*)ckrecordPrefix
;
91 - (CKKSKey
* _Nullable
)unwrapUsing
:(id
<CKKSSelfPeer
>)localPeer error
:(NSError
**)error
;
92 - (NSData
* _Nullable
)signRecord
:(SFECKeyPair
*)signingKey error
:(NSError
**)error
;
93 - (bool)verifySignature
:(NSData
*)signature verifyingPeer
:(id
<CKKSPeer
>)peer error
:(NSError
**)error
;