]> git.saurik.com Git - apple/security.git/blobdiff - OSX/sec/SOSCircle/SecureObjectSync/SOSPeerInfoV2.c
Security-57740.20.22.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / SecureObjectSync / SOSPeerInfoV2.c
index 6cb352537eed54cf70e04d9c92c63d680117aac2..d48a7b91f917d67fa807b1a9a3b05b0e4c256d05 100644 (file)
@@ -26,6 +26,7 @@ CFStringRef sSecurityPropertiesKey      = CFSTR("SecurityProperties");
 CFStringRef kSOSHsaCrKeyDictionary      = CFSTR("HSADictionary");
 CFStringRef sRingState                  = CFSTR("RingState");
 CFStringRef sBackupKeyKey               = CFSTR("BackupKey");
+CFStringRef sEscrowRecord               = CFSTR("EscrowRecord");
 
 #if TARGET_OS_IPHONE
 
@@ -75,6 +76,13 @@ void SOSPeerInfoSetSerialNumber(SOSPeerInfoRef pi) {
     CFReleaseNull(serialNumber);
 }
 
+const CFStringRef SOSSerialUnknown = CFSTR("Unknown");
+
+CFStringRef SOSPeerInfoCopySerialNumber(SOSPeerInfoRef pi) {
+    CFStringRef retval = SOSPeerInfoV2DictionaryCopyString(pi, sSerialNumberKey);
+    return (retval ? retval : CFRetain(SOSSerialUnknown));
+}
+
 static bool SOSPeerInfoV2SanityCheck(SOSPeerInfoRef pi) {
     if(!pi) {
         return false;
@@ -87,7 +95,7 @@ static bool SOSPeerInfoV2SanityCheck(SOSPeerInfoRef pi) {
 
 static CFDataRef SOSPeerInfoGetV2Data(SOSPeerInfoRef pi) {
     if(SOSPeerInfoV2SanityCheck(pi) == false) return NULL;
-    return CFDictionaryGetValue(pi->description, sV2DictionaryKey);
+    return asData(CFDictionaryGetValue(pi->description, sV2DictionaryKey), NULL);
 }
 
 static CFMutableDictionaryRef SOSCreateDictionaryFromDER(CFDataRef v2Data, CFErrorRef *error) {
@@ -152,21 +160,17 @@ bool SOSPeerInfoUpdateToV2(SOSPeerInfoRef pi, CFErrorRef *error) {
     if(serialNumber == NULL) {
         secnotice("signing", "serialNumber was returned NULL\n");
     }
-    CFMutableSetRef views = SOSViewsCreateDefault(false, error);
+    CFMutableSetRef views = SOSViewCopyViewSet(kViewSetDefault);
     CFMutableSetRef secproperties = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks);
     if(serialNumber) CFDictionaryAddValue(v2Dictionary, sSerialNumberKey, serialNumber);
     CFDictionaryAddValue(v2Dictionary, sViewsKey, views);
     CFDictionaryAddValue(v2Dictionary, sSecurityPropertiesKey, secproperties);
-    if(whichTransportType == kSOSTransportPresent){
-        CFDictionaryAddValue(v2Dictionary, sDeviceID, CFSTR(""));
-        CFDictionaryAddValue(v2Dictionary, sTransportType, SOSTransportMessageTypeKVS);
-        CFDictionaryAddValue(v2Dictionary, sPreferIDS, kCFBooleanTrue);
-    }
-    else if (whichTransportType == kSOSTransportFuture || whichTransportType == kSOSTransportIDS){
-        CFDictionaryAddValue(v2Dictionary, sDeviceID, CFSTR(""));
-        CFDictionaryAddValue(v2Dictionary, sTransportType, SOSTransportMessageTypeIDS);
-        CFDictionaryAddValue(v2Dictionary, sPreferIDS, kCFBooleanTrue);
-    }
+    
+    CFDictionaryAddValue(v2Dictionary, sDeviceID, CFSTR(""));
+    CFDictionaryAddValue(v2Dictionary, sTransportType, SOSTransportMessageTypeIDSV2);
+    CFDictionaryAddValue(v2Dictionary, sPreferIDS, kCFBooleanFalse);
+    CFDictionaryAddValue(v2Dictionary, sPreferIDSFragmentation, kCFBooleanTrue);
+    
     require_action_quiet((v2data = SOSCreateDERFromDictionary(v2Dictionary, error)), out, SOSCreateError(kSOSErrorAllocationFailure, CFSTR("No Memory"), NULL, error));
     CFDictionaryAddValue(pi->description, sV2DictionaryKey, v2data);
     SOSPeerInfoExpandV2Data(pi, error);
@@ -335,3 +339,11 @@ errOut:
     return NULL;
 }
 
+const CFMutableDictionaryRef SOSPeerInfoV2DictionaryCopyDictionary(SOSPeerInfoRef pi, const void *key) {
+    require_quiet(SOSPeerInfoExpandV2Data(pi, NULL), errOut);
+    CFDictionaryRef value = asDictionary(CFDictionaryGetValue(pi->v2Dictionary, key), NULL);
+    if(value != NULL)
+        return CFDictionaryCreateMutableCopy(kCFAllocatorDefault, CFDictionaryGetCount(value), value);
+errOut:
+    return NULL;
+}