Inherits from NSObject
Declared in AFSecurityPolicy.h

Overview

AFSecurityPolicy evaluates server trust against pinned X.509 certificates and public keys over secure connections.

Adding pinned SSL certificates to your app helps prevent man-in-the-middle attacks and other vulnerabilities. Applications dealing with sensitive customer data or financial information are strongly encouraged to route all communication over an HTTPS connection with SSL pinning configured and enabled.

Tasks

Other Methods

  •   SSLPinningMode

    The criteria by which server trust should be evaluated against the pinned SSL certificates. Defaults to AFSSLPinningModeNone.

    property
  •   validatesCertificateChain

    Whether to evaluate an entire SSL certificate chain, or just the leaf certificate. Defaults to YES.

    property
  •   pinnedCertificates

    The certificates used to evaluate server trust according to the SSL pinning mode. By default, this property is set to any (.cer) certificates included in the app bundle.

    property
  •   allowInvalidCertificates

    Whether or not to trust servers with an invalid or expired SSL certificates. Defaults to NO.

    property
  •   validatesDomainName

    Whether or not to validate the domain name in the certificate’s CN field. Defaults to YES.

    property

Getting Specific Security Policies

  • + defaultPolicy

    Returns the shared default security policy, which does not allow invalid certificates, does not validate domain name, and does not validate against pinned certificates or public keys.

Initialization

Evaluating Server Trust

Properties

SSLPinningMode

@property (readonly, nonatomic, assign) AFSSLPinningMode SSLPinningMode
Discussion

The criteria by which server trust should be evaluated against the pinned SSL certificates. Defaults to AFSSLPinningModeNone.

Declared In

AFSecurityPolicy.h

allowInvalidCertificates

@property (nonatomic, assign) BOOL allowInvalidCertificates
Discussion

Whether or not to trust servers with an invalid or expired SSL certificates. Defaults to NO.

Declared In

AFSecurityPolicy.h

pinnedCertificates

@property (nonatomic, strong) NSArray *pinnedCertificates
Discussion

The certificates used to evaluate server trust according to the SSL pinning mode. By default, this property is set to any (.cer) certificates included in the app bundle.

Declared In

AFSecurityPolicy.h

validatesCertificateChain

@property (nonatomic, assign) BOOL validatesCertificateChain
Discussion

Whether to evaluate an entire SSL certificate chain, or just the leaf certificate. Defaults to YES.

Declared In

AFSecurityPolicy.h

validatesDomainName

@property (nonatomic, assign) BOOL validatesDomainName
Discussion

Whether or not to validate the domain name in the certificate’s CN field. Defaults to YES.

Declared In

AFSecurityPolicy.h

Class Methods

defaultPolicy

+ (instancetype)defaultPolicy
Discussion

Returns the shared default security policy, which does not allow invalid certificates, does not validate domain name, and does not validate against pinned certificates or public keys.

Return Value

The default security policy.

Declared In

AFSecurityPolicy.h

policyWithPinningMode:

+ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode
Discussion

Creates and returns a security policy with the specified pinning mode.

Parameters

pinningMode

The SSL pinning mode.

Return Value

A new security policy.

Declared In

AFSecurityPolicy.h

Instance Methods

evaluateServerTrust:

- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
Discussion

Whether or not the specified server trust should be accepted, based on the security policy.

This method should be used when responding to an authentication challenge from a server.

Warning: This method has been deprecated in favor of evaluateServerTrust:forDomain:.

Parameters

serverTrust

The X.509 certificate trust of the server.

Return Value

Whether or not to trust the server.

Declared In

AFSecurityPolicy.h

evaluateServerTrust:forDomain:

- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain
Discussion

Whether or not the specified server trust should be accepted, based on the security policy.

This method should be used when responding to an authentication challenge from a server.

Parameters

serverTrust

The X.509 certificate trust of the server.

domain

The domain of serverTrust. If nil, the domain will not be validated.

Return Value

Whether or not to trust the server.

Declared In

AFSecurityPolicy.h