1 #include <SecureObjectSync/SOSAccountPriv.h>
2 #include <SecureObjectSync/SOSTransport.h>
3 #include <SecureObjectSync/SOSTransportKeyParameter.h>
4 #include <SecureObjectSync/SOSTransportKeyParameterKVS.h>
5 #include <SecureObjectSync/SOSKVSKeys.h>
6 #include <SOSCloudKeychainClient.h>
7 #include <utilities/SecCFWrappers.h>
9 static bool SOSTransportKeyParameterKVSPublishCloudParameters(SOSTransportKeyParameterKVSRef transport
, CFDataRef newParameters
, CFErrorRef
*error
);
10 static bool publishCloudParameters(SOSTransportKeyParameterRef transport
, CFDataRef data
, CFErrorRef
* error
);
11 static bool SOSTransportKeyParameterKVSUpdateKVS(CFDictionaryRef changes
, CFErrorRef
*error
);
12 static void destroy(SOSTransportKeyParameterRef transport
);
14 struct __OpaqueSOSTransportKeyParameterKVS
{
15 struct __OpaqueSOSTransportKeyParameter k
;
18 static bool handleKeyParameterChanges(SOSTransportKeyParameterRef transport
, CFDataRef data
, CFErrorRef error
){
19 SOSAccountRef account
= transport
->account
;
20 return SOSAccountHandleParametersChange(account
, data
, &error
);
24 static bool setToNewAccount(SOSTransportKeyParameterRef transport
){
25 SOSAccountRef account
= transport
->account
;
26 SOSAccountSetToNew(account
);
30 SOSTransportKeyParameterKVSRef
SOSTransportKeyParameterKVSCreate(SOSAccountRef account
, CFErrorRef
*error
) {
31 SOSTransportKeyParameterKVSRef tkvs
= (SOSTransportKeyParameterKVSRef
) SOSTransportKeyParameterCreateForSubclass(sizeof(struct __OpaqueSOSTransportKeyParameterKVS
) - sizeof(CFRuntimeBase
), account
, error
);
33 tkvs
->k
.publishCloudParameters
= publishCloudParameters
;
34 tkvs
->k
.handleKeyParameterChanges
= handleKeyParameterChanges
;
35 tkvs
->k
.setToNewAccount
= setToNewAccount
;
36 tkvs
->k
.destroy
= destroy
;
37 SOSRegisterTransportKeyParameter((SOSTransportKeyParameterRef
)tkvs
);
42 static void destroy(SOSTransportKeyParameterRef transport
){
43 SOSUnregisterTransportKeyParameter(transport
);
46 bool SOSTransportKeyParameterKVSHandleCloudParameterChange(SOSTransportKeyParameterRef transport
, CFDataRef data
, CFErrorRef
* error
){
47 SOSTransportKeyParameterKVSRef tkvs
= (SOSTransportKeyParameterKVSRef
)transport
;
48 SOSAccountRef account
= tkvs
->k
.account
;
50 return SOSAccountHandleParametersChange(account
, data
, error
);
54 bool SOSTransportKeyParameterKVSAppendKeyInterests(SOSTransportKeyParameterKVSRef transport
, CFMutableArrayRef alwaysKeys
, CFMutableArrayRef afterFirstUnlockKeys
, CFMutableArrayRef unlockedKeys
, CFErrorRef
*error
){
56 CFArrayAppendValue(alwaysKeys
, kSOSKVSKeyParametersKey
);
61 static bool publishCloudParameters(SOSTransportKeyParameterRef transport
, CFDataRef data
, CFErrorRef
* error
)
63 return SOSTransportKeyParameterKVSPublishCloudParameters((SOSTransportKeyParameterKVSRef
)transport
, data
, error
);
66 static bool SOSTransportKeyParameterKVSUpdateKVS(CFDictionaryRef changes
, CFErrorRef
*error
){
67 CloudKeychainReplyBlock log_error
= ^(CFDictionaryRef returnedValues __unused
, CFErrorRef error
) {
69 secerror("Error putting: %@", error
);
74 SOSCloudKeychainPutObjectsInCloud(changes
, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT
, 0), log_error
);
78 static bool SOSTransportKeyParameterKVSPublishCloudParameters(SOSTransportKeyParameterKVSRef transport
, CFDataRef newParameters
, CFErrorRef
*error
)
80 CFDictionaryRef changes
= CFDictionaryCreateForCFTypes(kCFAllocatorDefault
,
81 kSOSKVSKeyParametersKey
, newParameters
,
84 bool success
= SOSTransportKeyParameterKVSUpdateKVS(changes
, error
);
86 CFReleaseNull(changes
);