Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7653109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:56:35+00:00 2026-05-31T11:56:35+00:00

I’m trying to use the following code to handle SSL connections in iOS. It

  • 0

I’m trying to use the following code to handle SSL connections in iOS. It works fine on a real device and the certificate is issued by a fully trusted CA. It crashes when I try to run it from a unit test. Anyone else seen this sort of behaviour or know a workaround?

- (BOOL) connection:(NSURLConnection *)aConnection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
    NSString *authenticationMethod = protectionSpace.authenticationMethod;
    NSLog(@"Authentication method: %@", authenticationMethod);
    return [authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void) connection:(NSURLConnection *)aConnection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    NSLog(@"Challenge: %@", challenge);
    NSURLCredential *proposedCredential = [challenge proposedCredential];
    NSLog(@"proposedCredential = %@", proposedCredential);

    NSURLProtectionSpace *protectionSpace = challenge.protectionSpace;
    NSLog(@"protectionSpace = %@", protectionSpace);

    NSString *host = protectionSpace.host;
    NSLog(@"Trust host: %@", host);
    id <NSURLAuthenticationChallengeSender> sender = challenge.sender;
    NSLog(@"sender = %@", sender);

    if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        if ([trustedHosts containsObject:host]) {
            SecTrustRef trust = protectionSpace.serverTrust;
            NSLog(@"trust %p", trust);
            NSURLCredential *credential = [NSURLCredential credentialForTrust:trust];
            NSLog(@"Credential: %@", credential);


            SecTrustResultType result;
            OSStatus status = SecTrustEvaluate(trust, &result);
            NSLog(@"Trust result: %lu", result);
            NSLog(@"OSStatus = %li", status);

            NSError *error = [challenge error];
            NSLog(@"error = %@", error);

            [sender useCredential:credential forAuthenticationChallenge:challenge];
            NSLog(@"Using credential");
        } else {
            [sender performDefaultHandlingForAuthenticationChallenge:challenge];
        }
    } else {
        [sender performDefaultHandlingForAuthenticationChallenge:challenge];
    }
}

The test case output in AppCode is as follows:

2012-03-06 14:35:09.656 otest[5696:7803] About to login
2012-03-06 14:35:09.656 otest[5696:7803] AccountVerificationService - postAccountInfo
2012-03-06 14:35:09.658 otest[5696:7803] POST url: https://secure.example.com/user/verify
2012-03-06 14:35:09.662 otest[5696:7803] Login called
2012-03-06 14:35:09.949 otest[5696:7803] Authentication method: NSURLAuthenticationMethodServerTrust
2012-03-06 14:35:09.953 otest[5696:7803] Challenge: <NSURLAuthenticationChallenge: 0x1b8ded0>
2012-03-06 14:35:09.956 otest[5696:7803] proposedCredential = (null)
2012-03-06 14:35:09.956 otest[5696:7803] protectionSpace = <NSURLProtectionSpace: 0x1b8df00>
2012-03-06 14:35:09.957 otest[5696:7803] Trust host: secure.example.com
2012-03-06 14:35:09.958 otest[5696:7803] sender = <NSURLConnection: 0x1b8d0d0>
2012-03-06 14:35:09.958 otest[5696:7803] trust 0x1d8fb90
2012-03-06 14:35:09.962 otest[5696:7803] Credential: <NSURLCredential: 0x1b8e460>: (null)
2012-03-06 14:35:09.983 otest[5696:7803] Trust result: 7
2012-03-06 14:35:10.001 otest[5696:7803] OSStatus = 0
2012-03-06 14:35:10.011 otest[5696:7803] error = (null)

Process finished with exit code 138

Debug backtrace:

  thread #4: tid = 0x3603, 0x0039a841 CoreFoundation`CFArrayGetCount + 17, stop reason = EXC_BAD_ACCESS (code=2, address=0x0)
    frame #0: 0x0039a841 CoreFoundation`CFArrayGetCount + 17
    frame #1: 0x00dad4f4 Security`SecTrustCopyExceptions + 35
    frame #2: 0x00b318e4 CFNetwork`SocketStream::securityAcceptPeerTrust_NoLock(unsigned char) + 150
    frame #3: 0x00b3a154 CFNetwork`SocketStream::setProperty(void const*, __CFString const*, void const*) + 2754
    frame #4: 0x00b39688 CFNetwork`virtual thunk to SocketStream::setProperty(void const*, __CFString const*, void const*) + 43
    frame #5: 0x00b3ad3b CFNetwork`ReadStreamCallbacks::_setProperty(__CFReadStream*, __CFString const*, void const*, void*) + 53
    frame #6: 0x00429b40 CoreFoundation`CFReadStreamSetProperty + 160
    frame #7: 0x00b3acee CFNetwork`HTTPReadFilter::streamSetProperty(__CFReadStream*, __CFString const*, void const*) + 266
    frame #8: 0x00bd4381 CFNetwork`non-virtual thunk to HTTPReadFilter::streamSetProperty(__CFReadStream*, __CFString const*, void const*) + 41
    frame #9: 0x00b37488 CFNetwork`CFNetworkReadStream::httpStreamSetProperty(__CFReadStream*, __CFString const*, void const*, void*) + 38
    frame #10: 0x00429b40 CoreFoundation`CFReadStreamSetProperty + 160
    frame #11: 0x00b41b88 CFNetwork`HTTPNetStreamInfo::streamSetProperty(__CFReadStream*, __CFString const*, void const*) + 404
    frame #12: 0x00b419ec CFNetwork`non-virtual thunk to HTTPNetStreamInfo::streamSetProperty(__CFReadStream*, __CFString const*, void const*) + 41
    frame #13: 0x00b37488 CFNetwork`CFNetworkReadStream::httpStreamSetProperty(__CFReadStream*, __CFString const*, void const*, void*) + 38
    frame #14: 0x00429b40 CoreFoundation`CFReadStreamSetProperty + 160
    frame #15: 0x00be3e7b CFNetwork`HTTPProtocol::useCredential(_CFURLCredential const*, _CFURLAuthChallenge*) + 125
    frame #16: 0x00bfa9e3 CFNetwork`URLConnectionLoader::loaderUseCredential(_CFURLCredential const*) + 117
    frame #17: 0x00bfa4ce CFNetwork`URLConnectionLoader::LoaderConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XLoaderEvent, XLoaderEventParams>*, long) + 140
    frame #18: 0x00b228b7 CFNetwork`URLConnectionLoader::processEvents() + 107
    frame #19: 0x00bf716b CFNetwork`non-virtual thunk to URLConnectionInstanceData::multiplexerClientPerform() + 21
    frame #20: 0x00b21137 CFNetwork`MultiplexerSource::perform() + 259
    frame #21: 0x0045e97f CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    frame #22: 0x003c1b73 CoreFoundation`__CFRunLoopDoSources0 + 243
    frame #23: 0x003c1454 CoreFoundation`__CFRunLoopRun + 1012
    frame #24: 0x003c0db4 CoreFoundation`CFRunLoopRunSpecific + 212
    frame #25: 0x003c0ccb CoreFoundation`CFRunLoopRunInMode + 123
    frame #26: 0x00108e40 Foundation`+[NSURLConnection(Loader) _resourceLoadLoop:] + 398
    frame #27: 0x0001a4e6 Foundation`-[NSThread main] + 76
    frame #28: 0x0001a457 Foundation`__NSThread__main__ + 1258
    frame #29: 0x94d8fed9 libsystem_c.dylib`_pthread_start + 335
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:56:36+00:00Added an answer on May 31, 2026 at 11:56 am

    The problem seems to have resolved itself through some combination of iOS 5.1, Xcode 4.3.1 and AppCode 1.5.15 EAP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.