title: Using SSLSetEnabledCiphers with AFNetworking to disable weak ciphers
body: <p>I am trying to disable some ciphers (weak) such as single DES, single DES 40 bit etc. </p>
  
  <p>I've tried using this bit of code from <a href="https://stackoverflow.com/questions/1954971/how-does-one-set-ssl-ciphers-when-using-cfsocket-cfstream-in-cocoa">How does one set SSL ciphers when using CFSocket/CFStream in Cocoa?</a> and from mailing list message <a href="http://lists.apple.com/archives/Apple-cdsa/2008/Oct/msg00007.html" rel="nofollow noreferrer">CFNetwork SSL and long blocking delays</a> but I need access to socket data to get the <code>CFDataRef</code>.</p>
  
  <p>Here is the code that I tried to insert in the handshake method in <code>AFURLConnectionOperation</code> class:</p>
  
  <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge (NSURLAuthenticationChallenge *)challenge{
      CFReadStreamRef stream = [sock getCFReadStream];
      CFDataRef data = CFReadStreamCopyProperty(stream, kCFStreamPropertySocketSSLContext);
  
      // Extract the SSLContextRef from the CFData
      SSLContextRef sslContext;
      CFDataGetBytes(data, CFRangeMake(0, sizeof(SSLContextRef)), &amp;sslContext);
  
      // Get all enabled ciphers
      size_t numCiphers;
      SSLGetNumberEnabledCiphers(sslContext,&amp;numCiphers);
      SSLCipherSuite ciphers[numCiphers];
      SSLGetEnabledCiphers(sslContext,ciphers,&amp;numCiphers);
  
      // Create a new cipher array with only non-DH ciphers, and set it
      SSLCipherSuite finalCiphers[numCiphers];
      int numFinalCiphers = 0;
      for(int i=0; i&lt;numCiphers; i++) {
          SSLCipherSuite suite = ciphers[i];
          if(!cipherSuiteUsesDH(suite)) {
              finalCiphers[numFinalCiphers] = suite;
              numFinalCiphers++;
          }
      }
      SSLSetEnabledCiphers(sslContext,finalCiphers,numFinalCiphers);
  }
  </code></pre>
  
  <p>Any and all help would be appreciated. </p>
  
  <p>EDIT: Unfortunately this is an existing project and it still uses version 1 of AFNetworking. </p>