本文整理匯總了C++中CFReleaseSafe函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFReleaseSafe函數的具體用法?C++ CFReleaseSafe怎麽用?C++ CFReleaseSafe使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFReleaseSafe函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: SecPKCS12Import
OSStatus SecPKCS12Import(CFDataRef pkcs12_data, CFDictionaryRef options, CFArrayRef *items)
{
pkcs12_context context = {};
SecAsn1CoderCreate(&context.coder);
if (options)
context.passphrase = CFDictionaryGetValue(options, kSecImportExportPassphrase);
context.items = CFDictionaryCreateMutable(kCFAllocatorDefault,
0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
int status = p12decode(&context, pkcs12_data);
if (!status) {
CFMutableArrayRef certs = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
CFDictionaryApplyFunction(context.items, collect_certs, certs);
CFMutableArrayRef identities = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
build_trust_chains_context a_build_trust_chains_context = { identities, certs };
CFDictionaryApplyFunction(context.items, build_trust_chains, &a_build_trust_chains_context);
CFReleaseSafe(certs);
/* ignoring certs that weren't picked up as part of the certchain for found keys */
*items = identities;
}
CFReleaseSafe(context.items);
SecAsn1CoderRelease(context.coder);
switch (status) {
case p12_noErr: return noErr;
case p12_passwordErr: return errSecAuthFailed;
case p12_decodeErr: return errSecDecode;
default: return errSecInternal;
};
return noErr;
}
示例2: securityd_server_trust_evaluate_done
static void
securityd_server_trust_evaluate_done(const void *userData,
SecCertificatePathRef chain, CFArrayRef details, CFDictionaryRef info,
SecTrustResultType result) {
struct securityd_server_trust_evaluation_context *tec =
(struct securityd_server_trust_evaluation_context *)userData;
/* @@@ This code snippit is also in SecTrustServer.c. I'd factor it,
but a better fix would be to change the interfaces here to not use
single in/out args and do all the argument munging in server.c
and client.c. */
CFDictionaryRef args_out;
CFNumberRef resultNumber = NULL;
CFArrayRef chain_certs = NULL;
/* Proccess outgoing results. */
resultNumber = CFNumberCreate(NULL, kCFNumberSInt32Type, &result);
chain_certs = SecCertificatePathCopyArray(chain);
const void *out_keys[] = { kSecTrustChainKey, kSecTrustDetailsKey,
kSecTrustInfoKey, kSecTrustResultKey };
const void *out_values[] = { chain_certs, details, info, resultNumber };
args_out = (CFTypeRef)CFDictionaryCreate(kCFAllocatorDefault, out_keys,
out_values, sizeof(out_keys) / sizeof(*out_keys),
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFReleaseSafe(chain_certs);
CFReleaseSafe(resultNumber);
/* Send back the response to the client. */
securityd_server_send_reply(tec->reply, tec->request_id, noErr, args_out);
free(tec);
}
示例3: tls_create_trust_from_certs
static int tls_create_trust_from_certs(const SSLCertificate *cert, SecTrustRef *trustRef)
{
int err;
CFMutableArrayRef certArray = NULL;
CFDataRef certData = NULL;
SecCertificateRef cfCert = NULL;
if(cert==NULL) {
test_printf("No certs, do not create SecTrustRef\n");
*trustRef = NULL;
return 0;
}
certArray = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
while(cert) {
base64_dump(cert->derCert, "CERTIFICATE");
require_action((certData = CFDataCreate(kCFAllocatorDefault, cert->derCert.data, cert->derCert.length)), out, err = errSecAllocate);
require_action((cfCert = SecCertificateCreateWithData(kCFAllocatorDefault, certData)), out, err = errSecAllocate);
CFArrayAppendValue(certArray, cfCert);
CFReleaseNull(cfCert);
CFReleaseNull(certData);
cert=cert->next;
}
require_noerr((err=SecTrustCreateWithCertificates(certArray, NULL, trustRef)), out);
out:
CFReleaseSafe(certData);
CFReleaseSafe(cfCert);
CFReleaseSafe(certArray);
return err;
}
示例4: sslGetMatchingCertInArray
/* Return the first certificate reference from the supplied array
* whose data matches the given certificate, or NULL if none match.
*/
static
SecCertificateRef
sslGetMatchingCertInArray(
SecCertificateRef certRef,
CFArrayRef certArray)
{
SecCertificateRef matchedCert = NULL;
if (certRef == NULL || certArray == NULL) {
return NULL;
}
CFDataRef certData = SecCertificateCopyData(certRef);
if (certData) {
CFIndex idx, count = CFArrayGetCount(certArray);
for(idx=0; idx<count; idx++) {
SecCertificateRef aCert = (SecCertificateRef)CFArrayGetValueAtIndex(certArray, idx);
CFDataRef aData = SecCertificateCopyData(aCert);
if (aData && CFEqual(aData, certData)) {
matchedCert = aCert;
}
CFReleaseSafe(aData);
if (matchedCert)
break;
}
CFReleaseSafe(certData);
}
return matchedCert;
}
示例5: SecTrustServerEvaluateDone
static void
SecTrustServerEvaluateDone(const void *userData,
SecCertificatePathRef chain, CFArrayRef details, CFDictionaryRef info,
SecTrustResultType result) {
struct SecTrustEvaluationContext *tec =
(struct SecTrustEvaluationContext *)userData;
/* @@@ This code snippit is also in server.c. I'd factor it, but a better
fix would be to chage the interfaces here to not use single in/out args
and do all the argument munging in server.c and client.c. */
CFDictionaryRef args_out;
CFNumberRef resultNumber = NULL;
CFArrayRef chain_certs = NULL;
/* Proccess outgoing results. */
resultNumber = CFNumberCreate(NULL, kCFNumberSInt32Type, &result);
chain_certs = SecCertificatePathCopyArray(chain);
const void *out_keys[] = { kSecTrustChainKey, kSecTrustDetailsKey,
kSecTrustInfoKey, kSecTrustResultKey };
const void *out_values[] = { chain_certs, details, info, resultNumber };
args_out = (CFTypeRef)CFDictionaryCreate(kCFAllocatorDefault, out_keys,
out_values, sizeof(out_keys) / sizeof(*out_keys),
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFReleaseSafe(chain_certs);
CFReleaseSafe(resultNumber);
/* Return the final result. */
tec->args_out = args_out;
if (tec->running) {
/* Stop the runloop in SecTrustServerEvaluate if it is running. */
CFRunLoopStop(CFRunLoopGetCurrent());
}
}
示例6: SecECKeyGeneratePair
OSStatus SecECKeyGeneratePair(CFDictionaryRef parameters,
SecKeyRef *publicKey, SecKeyRef *privateKey) {
OSStatus status = errSecParam;
CFAllocatorRef allocator = NULL; /* @@@ get from parameters. */
SecKeyRef pubKey = NULL;
SecKeyRef privKey = SecKeyCreate(allocator, &kSecECPrivateKeyDescriptor,
(const void*) parameters, 0, kSecGenerateKey);
require(privKey, errOut);
/* Create SecKeyRef's from the pkcs1 encoded keys. */
pubKey = SecKeyCreate(allocator, &kSecECPublicKeyDescriptor,
privKey->key, 0, kSecExtractPublicFromPrivate);
require(pubKey, errOut);
if (publicKey) {
*publicKey = pubKey;
pubKey = NULL;
}
if (privateKey) {
*privateKey = privKey;
privKey = NULL;
}
status = errSecSuccess;
errOut:
CFReleaseSafe(pubKey);
CFReleaseSafe(privKey);
return status;
}
示例7: open_bundle
static FILE *
open_bundle(const char * path, const char * mode)
{
char full_path[1024] = {};
CFStringRef path_cfstring = NULL;
CFURLRef path_url = NULL;
CFBundleRef bundle = NULL;
CFURLRef exec = NULL;
path_cfstring = CFStringCreateWithFileSystemRepresentation(kCFAllocatorDefault, path);
require_quiet(path_cfstring, out);
path_url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path_cfstring, kCFURLPOSIXPathStyle, true);
require_quiet(path_url, out);
bundle = CFBundleCreate(kCFAllocatorDefault, path_url);
require_quiet(bundle, out);
exec = CFBundleCopyExecutableURL(bundle);
require(exec, out);
require(CFURLGetFileSystemRepresentation(exec, true, (uint8_t*)full_path, sizeof(full_path)), out);
out:
CFReleaseSafe(path_cfstring);
CFReleaseSafe(path_url);
CFReleaseSafe(bundle);
CFReleaseSafe(exec);
return fopen(full_path, "r");
}
示例8: SecCreateSignedCertificateTimestampsArrayFromSerializedSCTList
CFArrayRef SecCreateSignedCertificateTimestampsArrayFromSerializedSCTList(const uint8_t *p, size_t listLen)
{
size_t encodedListLen;
CFMutableArrayRef sctArray = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
require_quiet(sctArray, out);
require(listLen > 2 , out);
encodedListLen = SSLDecodeSize(p); p+=2; listLen-=2;
require(encodedListLen==listLen, out);
while (listLen > 0)
{
size_t itemLen;
require(listLen >= 2, out);
itemLen = SSLDecodeSize(p); p += 2; listLen-=2;
require(itemLen <= listLen, out);
CFDataRef sctData = CFDataCreate(kCFAllocatorDefault, p, itemLen);
p += itemLen; listLen -= itemLen;
require(sctData, out);
CFArrayAppendValue(sctArray, sctData);
CFReleaseSafe(sctData);
}
return sctArray;
out:
CFReleaseSafe(sctArray);
return NULL;
}
示例9: testRSAKeyDesc
static void testRSAKeyDesc()
{
SecKeyRef pubKey = NULL;
CFStringRef pubRef = NULL;
long pubLength = 0;
pubKey = SecKeyCreateRSAPublicKey(kCFAllocatorDefault, rsaPubKey, sizeof(rsaPubKey), kSecKeyEncodingBytes);
require_quiet( pubKey, fail);
pubRef = CFCopyDescription(pubKey);
require_quiet(pubRef, fail);
pubLength = CFStringGetLength(pubRef)+1;
char *publicDescription = (char*)malloc(pubLength);
require_quiet(publicDescription != NULL, fail);
if(false == CFStringGetCString(pubRef, publicDescription, pubLength, kCFStringEncodingUTF8))
{
free(publicDescription);
goto fail;
}
ok_status(strncmp(rsaKeyDescription, publicDescription, strlen(rsaKeyDescription)-17), "rsa key descriptions don't match: %s %s", rsaKeyDescription, publicDescription);
free(publicDescription);
fail:
CFReleaseSafe(pubRef);
CFReleaseSafe(pubKey);
}
示例10: asynchttp_timer_proc
static void asynchttp_timer_proc(asynchttp_t *http) {
CFStringRef req_meth = http->request ? CFHTTPMessageCopyRequestMethod(http->request) : NULL;
CFURLRef req_url = http->request ? CFHTTPMessageCopyRequestURL(http->request) : NULL;
secnotice("http", "Timeout during %@ %@.", req_meth, req_url);
CFReleaseSafe(req_url);
CFReleaseSafe(req_meth);
asynchttp_complete(http);
}
示例11: test_add_managedconfiguration_item
static void test_add_managedconfiguration_item(void) {
CFMutableDictionaryRef query = test_create_managedconfiguration_query();
const char *v_data = "public managedconfiguration password history data";
CFDataRef pwdata = CFDataCreate(NULL, (UInt8 *)v_data, strlen(v_data));
CFDictionaryAddValue(query, kSecValueData, pwdata);
ok_status(SecItemAdd(query, NULL), "test_add_managedconfiguration_item");
CFReleaseSafe(pwdata);
CFReleaseSafe(query);
}
示例12: test_add_lockdown_identity_items
static void test_add_lockdown_identity_items(void) {
CFMutableDictionaryRef query = test_create_lockdown_identity_query();
const char *v_data = "lockdown identity data (which should be a cert + key)";
CFDataRef pwdata = CFDataCreate(NULL, (UInt8 *)v_data, strlen(v_data));
CFDictionaryAddValue(query, kSecValueData, pwdata);
ok_status(SecItemAdd(query, NULL), "test_add_lockdown_identity_items");
CFReleaseSafe(pwdata);
CFReleaseSafe(query);
}
示例13: sslCreateSecTrust
OSStatus
sslCreateSecTrust(
SSLContext *ctx,
CFArrayRef certChain,
bool arePeerCerts,
SecTrustRef *pTrust) /* RETURNED */
{
OSStatus status = memFullErr;
CFStringRef peerDomainName = NULL;
CFTypeRef policies = NULL;
SecTrustRef trust = NULL;
if (CFArrayGetCount(certChain) == 0) {
status = errSSLBadCert;
goto errOut;
}
if (arePeerCerts) {
if (ctx->peerDomainNameLen && ctx->peerDomainName) {
CFIndex len = ctx->peerDomainNameLen;
if (ctx->peerDomainName[len - 1] == 0) {
len--;
//secwarning("peerDomainName is zero terminated!");
}
/* @@@ Double check that this is the correct encoding. */
require(peerDomainName = CFStringCreateWithBytes(kCFAllocatorDefault,
(const UInt8 *)ctx->peerDomainName, len,
kCFStringEncodingUTF8, false), errOut);
}
}
/* If we are the client, our peer certificates must satisfy the
ssl server policy. */
bool server = ctx->protocolSide == kSSLClientSide;
require(policies = SecPolicyCreateSSL(server, peerDomainName), errOut);
require_noerr(status = SecTrustCreateWithCertificates(certChain, policies,
&trust), errOut);
/* If we have trustedAnchors we set them here. */
if (ctx->trustedCerts) {
require_noerr(status = SecTrustSetAnchorCertificates(trust,
ctx->trustedCerts), errOut);
require_noerr(status = SecTrustSetAnchorCertificatesOnly(trust,
ctx->trustedCertsOnly), errOut);
}
status = noErr;
errOut:
CFReleaseSafe(peerDomainName);
CFReleaseSafe(policies);
*pTrust = trust;
return status;
}
示例14: SecKeyGenerateAttributeDictionaryFor
static CF_RETURNS_RETAINED CFDictionaryRef SecKeyGenerateAttributeDictionaryFor(SecKeyRef key,
CFTypeRef keyType,
CFDataRef privateBlob)
{
CFAllocatorRef allocator = CFGetAllocator(key);
DICT_DECLARE(25);
CFDataRef pubKeyDigest = NULL, pubKeyBlob = NULL;
CFDictionaryRef dict = NULL;
size_t sizeValue = SecKeyGetSize(key, kSecKeyKeySizeInBits);
CFNumberRef sizeInBits = CFNumberCreate(allocator, kCFNumberLongType, &sizeValue);
/* encode the public key. */
require_noerr(SecKeyCopyPublicBytes(key, &pubKeyBlob), errOut);
require(pubKeyBlob, errOut);
/* Calculate the digest of the public key. */
require(pubKeyDigest = SecSHA1DigestCreate(allocator,
CFDataGetBytePtr(pubKeyBlob), CFDataGetLength(pubKeyBlob)),
errOut);
DICT_ADDPAIR(kSecClass, kSecClassKey);
DICT_ADDPAIR(kSecAttrKeyClass, privateBlob ? kSecAttrKeyClassPrivate : kSecAttrKeyClassPublic);
DICT_ADDPAIR(kSecAttrApplicationLabel, pubKeyDigest);
DICT_ADDPAIR(kSecAttrIsPermanent, kCFBooleanTrue);
DICT_ADDPAIR(kSecAttrIsPrivate, kCFBooleanTrue);
DICT_ADDPAIR(kSecAttrIsModifiable, kCFBooleanTrue);
DICT_ADDPAIR(kSecAttrKeyType, keyType);
DICT_ADDPAIR(kSecAttrKeySizeInBits, sizeInBits);
DICT_ADDPAIR(kSecAttrEffectiveKeySize, sizeInBits);
DICT_ADDPAIR(kSecAttrIsSensitive, kCFBooleanFalse);
DICT_ADDPAIR(kSecAttrWasAlwaysSensitive, kCFBooleanFalse);
DICT_ADDPAIR(kSecAttrIsExtractable, kCFBooleanTrue);
DICT_ADDPAIR(kSecAttrWasNeverExtractable, kCFBooleanFalse);
DICT_ADDPAIR(kSecAttrCanEncrypt, kCFBooleanFalse);
DICT_ADDPAIR(kSecAttrCanDecrypt, kCFBooleanTrue);
DICT_ADDPAIR(kSecAttrCanDerive, kCFBooleanTrue);
DICT_ADDPAIR(kSecAttrCanSign, kCFBooleanTrue);
DICT_ADDPAIR(kSecAttrCanVerify, kCFBooleanFalse);
DICT_ADDPAIR(kSecAttrCanSignRecover, kCFBooleanFalse);
DICT_ADDPAIR(kSecAttrCanVerifyRecover, kCFBooleanFalse);
DICT_ADDPAIR(kSecAttrCanWrap, kCFBooleanFalse);
DICT_ADDPAIR(kSecAttrCanUnwrap, kCFBooleanTrue);
DICT_ADDPAIR(kSecValueData, privateBlob ? privateBlob : pubKeyBlob);
dict = DICT_CREATE(allocator);
errOut:
// @@@ Zero out key material.
CFReleaseSafe(pubKeyDigest);
CFReleaseSafe(pubKeyBlob);
CFReleaseSafe(sizeInBits);
return dict;
}
示例15: SOSCoderCreateFromData
SOSCoderRef SOSCoderCreateFromData(CFDataRef exportedData, CFErrorRef *error) {
SOSCoderRef p = calloc(1, sizeof(struct __OpaqueSOSCoder));
const uint8_t *der = CFDataGetBytePtr(exportedData);
const uint8_t *der_end = der + CFDataGetLength(exportedData);
CFDataRef otr_data = NULL;
ccder_tag tag;
require(ccder_decode_tag(&tag, der, der_end),fail);
switch (tag) {
case CCDER_OCTET_STRING: // TODO: this code is safe to delete?
{
der = der_decode_data(kCFAllocatorDefault, 0, &otr_data, error, der, der_end);
p->waitingForDataPacket = false;
}
break;
case CCDER_CONSTRUCTED_SEQUENCE:
{
const uint8_t *sequence_end = NULL;
der = ccder_decode_sequence_tl(&sequence_end, der, der_end);
require_action_quiet(sequence_end == der_end, fail, SecCFDERCreateError(kSOSErrorDecodeFailure, CFSTR("Extra data in SOS coder"), NULL, error));
der = der_decode_data(kCFAllocatorDefault, 0, &otr_data, error, der, sequence_end);
der = der_decode_bool(&p->waitingForDataPacket, der, sequence_end);
if (der != sequence_end) { // optionally a pending response
der = der_decode_data(kCFAllocatorDefault, 0, &p->pendingResponse, error, der, sequence_end);
}
}
break;
default:
SecCFDERCreateError(kSOSErrorDecodeFailure, CFSTR("Unsupported SOS Coder DER"), NULL, error);
goto fail;
}
require(der, fail);
p->sessRef = SecOTRSessionCreateFromData(NULL, otr_data);
require(p->sessRef, fail);
CFReleaseSafe(otr_data);
return p;
fail:
SOSCoderDispose(p);
CFReleaseSafe(otr_data);
return NULL;
}