swift afnetworking ssl pinning

时间:2016-01-29 19:58:51

标签: swift ssl afnetworking pinning

var manager:AFHTTPSessionManager

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String time1 = sc.nextLine();
        String time2 = sc.nextLine();
        String[] time1parse = time1.split(":");
        String hour1 = time1parse[0];
        int hour1int = Integer.parseInt(hour1);
        String minutes1 = time1parse[1];
        int minutes1int = Integer.parseInt(minutes1)(
        String time2parse = time2.split(":");
        String hour2 = time2parse[0];
        int hour2int = Integer.parseInt(hour2);
        String minutes2 = time2parse[1];
        int minutes2int = Integer.parseInt(minutes2);



        //Math
        int minutes=minutes1int+minutes2int;
        int hours=hours1int+hours2int;
        hours+=minutes%60;
        minutes-=(minutes%60)*60;
        System.out.println(hours+":"+minutes);
    }
}

我一直试图让这个工作一段时间。 Swift文档是sparce,但我在阅读obj-c方面变得更好。证书是PEM格式,我已经尝试过并转换为.der格式。 Der格式在init()中爆炸,.PEM格式在evaluateServerTrust中爆炸。我试过AFNetworking 2.5.1并升级到3.0.4 - 同样的问题。我已经尝试过以下各种真假的组合。

securityPolicy.validatesDomainName = false securityPolicy.allowInvalidCertificates = false

非常感谢任何见解。谢谢

1 个答案:

答案 0 :(得分:0)

After much research and trial ... I decide to move to Alamofire 3.0 and the solution came. Note the following: The certificate must be in .der format. Mine was in .pem format. My certifcate was for the "leaf" i.e, the certificate chain was not included. For iOS 9.0 I had to add the ATS transport for my server.

Working example:

@IBAction func primeBack(sender: UIButton) {
    self.performSegueWithIdentifier("primeBack", sender: nil)
}
@IBOutlet var start: UIButton!

@IBOutlet var primeNum: UILabel!

    var num = 1
    var check = Double()
    var temp2 = Double()

    let lower : UInt32 = 1
    let upper : UInt32 = 100

override func viewDidLoad() {
    super.viewDidLoad()
    primeNum.hidden = true
    start.hidden = false

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func start(sender: UIButton) {

    primeNum.hidden = false

    let temp1 = (arc4random_uniform(upper - lower) + lower)
    primeNum.text = String(temp1)

    while num <= 12
    {
        check = Double(temp1) / Double(num)
        temp2 = check % 1

        if temp2 == 0
        {
            num++
        }
        else
        {
            num = 12
        }
    }
    start.hidden = true

}

@IBAction func prime(sender: UIButton) {
    if temp2 == 0
    {
        self.performSegueWithIdentifier("primeCorrect", sender: nil)
    }
    else
    {
        self.performSegueWithIdentifier("primeIncorrect", sender: nil)
    }
}
@IBAction func notPrime(sender: UIButton) {
    if temp2 == 0
    {
        self.performSegueWithIdentifier("primeIncorrect", sender: nil)
    }
    else
    {
        self.performSegueWithIdentifier("primeCorrect", sender: nil)
    }
}