Self-signed configuration HTTPS

Source: Internet
Author: User

Tagged with:. com elf res date URI wildcard SETW encapsulated color

Based on AFN3.0

1. Save the. cer file file provided in the background to the local

2. Assign a value to the Afsecuritypolicy property of AFN in the Encapsulated Network Request tool class

-(Afsecuritypolicy *) customsecuritypolicy{//first import the certificate, in this add the certificate, the general situation applies to the individual authentication//path to the certificateNSString *cerpath = [[NSBundle mainbundle] Pathforresource:@"app"OfType:@"cer"]; NSData*cerdata =[NSData Datawithcontentsoffile:cerpath]; if(Cerdata = =Nil) {        returnNil; } Nsset*setdata =[Nsset Setwithobject:cerdata]; //afsslpinningmodecertificate Using certificate validation modeAfsecuritypolicy *securitypolicy =[Afsecuritypolicy policywithpinningmode:afsslpinningmodecertificate]; //allowinvalidcertificates whether to allow invalid certificates (that is, self-built certificates), default to No//If you need to validate your self-built certificate, you need to set it to YesSecuritypolicy.allowinvalidcertificates =YES; //Validatesdomainname If you need to verify the domain name, the default is yes; //if the domain name of the certificate does not match the domain name you requested, you need to set the entry to no, and if it is set to No, the server can also establish a connection by using a certificate issued by another trusted authority, which is very dangerous and recommended to open. //set to No, mainly used in this case: the client requests the thing subdomain, and the certificate is another domain name.    Because the domain name on the SSL certificate is independent, if the domain name registered on the certificate is www.google.com, then mail.google.com cannot be verified, and of course the rich can register the wildcard domain name *.google.com, but this is still relatively expensive. //if set to No, it is recommended that you add the check logic for the corresponding domain name. Securitypolicy.validatesdomainname =NO;        [SecurityPolicy Setpinnedcertificates:setdata]; returnsecuritypolicy;}

3. Set when the network request tool is initialized

-(ID) Initwithbaseurl: (Nsurl *) URL {    = [Super Initwithbaseurl:url];     if (! Self ) {        return  nil;    }    [Self setsecuritypolicy:[self customsecuritypolicy]];     return Self ;}

Self-signed configuration HTTPS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.