예제 #1
0
/* This needs to be exported to make it callable from Foundation. */
CF_EXPORT CFReadStreamRef CFReadStreamCreateWithData(CFAllocatorRef alloc, CFDataRef data) {
    _CFReadDataStreamContext ctxt;
    CFReadStreamRef result = NULL;
    
    CFDataRef copiedData = CFDataCreateCopy(alloc, data);
    ctxt.data =  copiedData;
    result = (CFReadStreamRef)_CFStreamCreateWithConstantCallbacks(alloc, &ctxt, (struct _CFStreamCallBacks *)(&readDataCallBacks), TRUE);
    CFRelease(copiedData);
    return result;
}
CFDataRef SOSRecoveryKeyCopyKeyForAccount(CFAllocatorRef allocator, SOSAccountRef account, SOSRecoveryKeyBagRef recoveryKeyBag, CFErrorRef *error) {
    CFDataRef retval = NULL;
    require_action_quiet(recoveryKeyBag && recoveryKeyBag->recoveryKeyBag && recoveryKeyBag->accountDSID,
                         errOut, SOSCreateError(kSOSErrorDecodeFailure, CFSTR("Null recoveryKeyBag Object"), NULL, error));
    CFStringRef dsid = asString(SOSAccountGetValue(account, kSOSDSIDKey, NULL), error);
    require_action_quiet(dsid, errOut, SOSCreateError(kSOSErrorDecodeFailure, CFSTR("No DSID in Account"), NULL, error));
    require_action_quiet(CFEqual(dsid, recoveryKeyBag->accountDSID), errOut, SOSCreateError(kSOSErrorDecodeFailure, CFSTR("Account/RecoveryKeybag DSID miss-match"), NULL, error));
    retval = CFDataCreateCopy(allocator, recoveryKeyBag->recoveryKeyBag);
errOut:
    return retval;
}
static CFDataRef
createIVFromPassword(CFStringRef password)
{
    CFDataRef 		   hashedPassword, retval;
    CFMutableDataRef   iv;
 	if((hashedPassword = digestString(password)) == NULL) return NULL;
    iv = CFDataCreateMutableCopy(kCFAllocatorDefault, CFDataGetLength(hashedPassword)+1, hashedPassword);
    CFDataDeleteBytes(iv, CFRangeMake(IVBYTECOUNT, CFDataGetLength(iv)-IVBYTECOUNT));
    retval = CFDataCreateCopy(kCFAllocatorDefault, iv);
    CFRelease(hashedPassword);
    CFRelease(iv);
    return retval;
}
예제 #4
0
파일: plist.cpp 프로젝트: aosm/samba
CFDataRef Preferences::create_signature(void) const
{
    if (this->m_plist) {
	return get_path_signature(this->m_pspec.c_str());
    }

    if (this->m_scpref) {
	CFDataRef sig;

	/* Copy the signature so we adhere to the get rule. */
	if ((sig = SCPreferencesGetSignature(m_scpref))) {
	    return CFDataCreateCopy(kCFAllocatorDefault, sig);
	}
    }

    return NULL;
}
예제 #5
0
파일: server.c 프로젝트: JustSid/extip
static void IPStreamCallback(CFReadStreamRef stream, CFStreamEventType eventType, void *clientCallBackInfo)
{
	CFMutableDataRef responseData = (CFMutableDataRef)clientCallBackInfo;

	if(eventType & kCFStreamEventHasBytesAvailable)
	{
		UInt8 buffer[1024];
		CFIndex read;

		do {
			read = CFReadStreamRead(stream, buffer, sizeof(buffer));
			if(read > 0)
				CFDataAppendBytes(responseData, buffer, read);

		} while(read > 0);
	}

	if(eventType & (kCFStreamEventEndEncountered | kCFStreamEventErrorOccurred))
	{
		if((eventType & kCFStreamEventEndEncountered) && publicIPState == IPStateFetching)
		{
			if(publicIPData)
				CFRelease(publicIPData);

			publicIPData = CFDataCreateCopy(kCFAllocatorDefault, responseData);
			publicIPState = IPStateFetched;
		}

		if(eventType & kCFStreamEventErrorOccurred)
		{
			if(publicIPData)
				CFRelease(publicIPData);

			publicIPData = NULL;
			publicIPState = IPStateInvalid;
		}

		CFReadStreamClose(stream);
		CFReadStreamSetClient(stream, 0, NULL, NULL);
		CFReadStreamUnscheduleFromRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
		CFRelease(stream);

		CFRelease(responseData);
	}
}
SOSRecoveryKeyBagRef SOSRecoveryKeyBagCreateForAccount(CFAllocatorRef allocator, SOSAccountRef account, CFDataRef pubData, CFErrorRef *error) {
    SOSRecoveryKeyBagRef retval = NULL;
    SOSGenCountRef gencount = NULL;
    require_action_quiet(account, errOut, SOSCreateError(kSOSErrorEncodeFailure, CFSTR("Null Account Object"), NULL, error));
    CFStringRef dsid = asString(SOSAccountGetValue(account, kSOSDSIDKey, NULL), error);
    gencount = SOSGenerationCreate();
    
    require_action_quiet(pubData && dsid && gencount, errOut, SOSCreateError(kSOSErrorEncodeFailure, CFSTR("Couldn't get recovery keybag components"), NULL, error));
    retval = CFTypeAllocate(SOSRecoveryKeyBag, struct __OpaqueSOSRecoveryKeyBag, allocator);
    require_action_quiet(retval, errOut, SOSCreateError(kSOSErrorEncodeFailure, CFSTR("Couldn't get memory for recoveryKeyBag"), NULL, error));
    retval->rkbVersion = CURRENT_RKB_VERSION;
    retval->accountDSID = CFStringCreateCopy(allocator, dsid);
    CFRetainAssign(retval->generation, gencount);
    retval->recoveryKeyBag = CFDataCreateCopy(allocator, pubData);
errOut:
    CFReleaseNull(gencount);
    return retval;
}
예제 #7
0
static inline TStringIRep* TSICTStringCreateWithDataOfTypeAndFormat(CFDataRef data, TSITStringTag type, TSITStringFormat format)
{
    if (format == kTSITStringFormatDefault) {
        format = TSICTStringGetDefaultFormat();
    }

    TStringIRep* rep = calloc(1, sizeof(TStringIRep));
    rep->data = CFDataCreateCopy(kCFAllocatorDefault, data);
    rep->type = type;
    rep->format = format;
    rep->length = calloc(10, sizeof(char));

    CFIndex len = CFDataGetLength(rep->data);
    if (snprintf(rep->length, 10, "%lu", len)) {
        return rep;
    } else {
        TSICTStringDestroy(rep);
        return NULL;
    }
}
CFErrorRef accumulate_data(CFMutableArrayRef *a, CFDataRef d) {
	if (!*a) {
		*a = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
		if (!*a) {
			return GetNoMemoryError();
		}
	}
	CFDataRef dc = CFDataCreateCopy(NULL, d);
	if (!dc) {
		return GetNoMemoryError();
	}
	CFIndex c = CFArrayGetCount(*a);
	CFArrayAppendValue(*a, dc);
	CFRelease(dc);
	if (CFArrayGetCount(*a) != c+1) {
		return GetNoMemoryError();
	}
	
	return NULL;
}
OSStatus CMPVideoFormatDescriptionCopyExtradata(CFAllocatorRef allocator, CMVideoFormatDescriptionRef formatDescription, CFDataRef *outExtradata)
{
	const FourCharCode mediaSubType = CMFormatDescriptionGetMediaSubType(formatDescription);
	if(mediaSubType == kCMVideoCodecType_MPEG4Video || mediaSubType == kCMVideoCodecType_H264)
	{
		CFDictionaryRef atoms = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms);
		
		CFDataRef extradata = CFDictionaryGetValue(atoms, CFSTR("avcC"));
		if(extradata == nil)
		{
			return CMPParameterError;
		}
		
		*outExtradata = CFDataCreateCopy(allocator, extradata);
		return noErr;
	}
	else
	{
		*outExtradata = NULL;
		return noErr;
	}
}
예제 #10
0
static inline CFDataRef TSICTStringCreateDataFromIntermediateRepresentation(TStringIRep* rep)
{
    CFIndex len = CFDataGetLength(rep->data);
    CFMutableDataRef buffer = CFDataCreateMutableCopy(kCFAllocatorDefault, (len + 12), rep->data);
    UInt8* bufferBytes = CFDataGetMutableBytePtr(buffer);

    size_t prefixLength = strlen(rep->length) + 1;
    CFDataReplaceBytes(buffer, BeginningRange, (const UInt8*)rep->length, (CFIndex)prefixLength);

    if (rep->format == kTSITStringFormatTNetstring) {
        const UInt8 ftag = (UInt8)TNetstringTypes[rep->type];
        CFDataAppendBytes(buffer, &ftag, 1);
        bufferBytes[(prefixLength - 1)] = TNetstringSeparator;
    } else if (rep->format == kTSITStringFormatOTNetstring) {
        const UInt8 ftag = (UInt8)OTNetstringTypes[rep->type];
        bufferBytes[(prefixLength - 1)] = ftag;
    }

    CFDataRef dataRep = CFDataCreateCopy(kCFAllocatorDefault, buffer);
    CFRelease(buffer);

    return dataRep;
}
예제 #11
0
Status genUnlockIdent(CFDataRef& uuid) {
  auto chosen =
      IORegistryEntryFromPath(kIOMasterPortDefault, kIODeviceTreeChosenPath_);
  if (chosen == MACH_PORT_NULL) {
    return Status(1, "Could not open IOKit DeviceTree");
  }

  CFMutableDictionaryRef properties = nullptr;
  auto kr = IORegistryEntryCreateCFProperties(
      chosen, &properties, kCFAllocatorDefault, kNilOptions);
  IOObjectRelease(chosen);

  if (kr != KERN_SUCCESS) {
    return Status(1, "Could not get IOKit chosen properties");
  }

  if (properties == nullptr) {
    return Status(1, "Could not load IOKit properties");
  }

  CFTypeRef unlock_ident = nullptr;
  if (CFDictionaryGetValueIfPresent(
          properties, CFSTR("efilogin-unlock-ident"), &unlock_ident)) {
    if (CFGetTypeID(unlock_ident) != CFDataGetTypeID()) {
      return Status(1, "Unexpected data type for unlock ident");
    }
    uuid = CFDataCreateCopy(kCFAllocatorDefault, (CFDataRef)unlock_ident);
    if (uuid == nullptr) {
      return Status(1, "Could not get UUID");
    }
    CFRelease(properties);
    return Status(0, "ok");
  }

  return Status(1, "Could not get unlock ident");
}