MQTTClient
an Objective-C Framework for MQTT
Properties | List of all members
MQTTSSLSecurityPolicy Class Reference

#import <MQTTSSLSecurityPolicy.h>

Inheritance diagram for MQTTSSLSecurityPolicy:

Instance Methods

Evaluating Server Trust


(BOOL) - evaluateServerTrust:forDomain:
 

Class Methods

Getting Specific Security Policies


(instancetype) + defaultPolicy
 
Initialization


(instancetype) + policyWithPinningMode:
 

Properties

MQTTSSLPinningMode SSLPinningMode
 
BOOL validatesCertificateChain
 
NSArray * pinnedCertificates
 
BOOL allowInvalidCertificates
 
BOOL validatesDomainName
 

Detailed Description

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

If your app using security model which require pinning SSL certificates to helps prevent man-in-the-middle attacks and other vulnerabilities. you need to set securityPolicy to properly value(see MQTTSSLSecurityPolicy.h for more detail).

NOTE: about self-signed server certificates: if your server using Self-signed certificates to establish SSL/TLS connection, you need to set property: MQTTSSLSecurityPolicy.allowInvalidCertificates=YES.

If SSL is enabled, by default it only evaluate server's certificates using CA infrastructure, and for most case, this type of check is enough. However, if your app using security model which require pinning SSL certificates to helps prevent man-in-the-middle attacks and other vulnerabilities. you may need to set securityPolicy to properly value(see MQTTSSLSecurityPolicy.h for more detail).

NOTE: about self-signed server certificates: In CA infrastructure, you may establish a SSL/TLS connection with server which using self-signed certificates by install the certificates into OS keychain(either programmatically or manually). however, this method has some disadvantages:

  1. every socket you app created will trust certificates you added.
  2. if user choice to remove certificates from keychain, you app need to handling certificates re-adding.

If you only want to verify the cert for the socket you are creating and for no other sockets in your app, you need to use MQTTSSLSecurityPolicy. And if you use self-signed server certificates, your need to set property: MQTTSSLSecurityPolicy.allowInvalidCertificates=YES

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 SSL/TLS connection with SSL pinning configured and enabled.

Method Documentation

§ defaultPolicy()

+ (instancetype) defaultPolicy

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

Returns
The default security policy.

§ evaluateServerTrust:forDomain:()

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

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
serverTrustThe X.509 certificate trust of the server.
domainThe domain of serverTrust. If nil, the domain will not be validated.
Returns
Whether or not to trust the server.

§ policyWithPinningMode:()

+ (instancetype) policyWithPinningMode: (MQTTSSLPinningMode)  pinningMode

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

Parameters
pinningModeThe SSL pinning mode.
Returns
A new security policy.

Property Documentation

§ allowInvalidCertificates

- (BOOL) allowInvalidCertificates
readwritenonatomicassign

Whether or not to trust servers with an invalid or expired SSL certificates. Defaults to NO. Note: If your server-certificates are self signed, your should set this property to 'YES'.

§ pinnedCertificates

- (NSArray*) pinnedCertificates
readwritenonatomicstrong

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. Note: Array item type: NSData - Bytes of X.509 certificate file in der format. Note that if you create an array with duplicate certificates, the duplicate certificates will be removed.

§ SSLPinningMode

- (MQTTSSLPinningMode) SSLPinningMode
readnonatomicassign

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

§ validatesCertificateChain

- (BOOL) validatesCertificateChain
readwritenonatomicassign

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

§ validatesDomainName

- (BOOL) validatesDomainName
readwritenonatomicassign

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


The documentation for this class was generated from the following file: