GCDAsyncSocket Client Public Key

I made a simple TLS server with GCDAsyncSocket and want to get the clients public key. I tried using this:

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
    SSLContextRef ref = [sock sslContext];
    SecTrustRef trust;
    SSLCopyPeerTrust(ref, &trust);

    SecKeyRef key = SecTrustCopyPublicKey(trust);
    NSLog(@"%@",key);
}

but I get exc_bad_access in the SecTrustCopyPublicKey method. How can I get the public key as NSString / NSData?

+4
source share
1 answer
  • Are you sure you have an SSL connection? Is the delegate method called didSecure?
  • Check that your trustlink is not NULLafter the function has completed SSLCopyPeerTrust.
  • Discussed SecTrustCopyPublicKeyin the Certificate, Keys, and Trust Services Guide provided by Apple.

SecTrustEvaluate . , , . , NULL - , - - .

0

Source: https://habr.com/ru/post/1538860/


All Articles