2

I want to connect Vpn via Code Using Network Extension framework .

I have a P12 Certificate to make VPN Connection also a Root CA (Crt) Certificate to Verify the P12 Certificate .

My problem is to verify The P12 certificate programatically .

I am Using below code to connect to VPN .

 let p = NEVPNProtocolIKEv2()

        p.authenticationMethod = NEVPNIKEAuthenticationMethod.None
        p.useExtendedAuthentication = true
        p.serverAddress = "102.xxx.xxx.xx"
        p.remoteIdentifier = "102.xxx.xxx.xx"
        p.disconnectOnSleep = false
        p.deadPeerDetectionRate = NEVPNIKEv2DeadPeerDetectionRate.Medium
        // TODO: Add an option into config page

        manager.localizedDescription = "VPN On - \(title)"

        if let grp = group {
            p.localIdentifier = grp
        } else {
            p.localIdentifier = "VPN"
        }

        if let username = account {
            p.username = username
        }



        if let certficiateData = certificate {
            p.authenticationMethod = NEVPNIKEAuthenticationMethod.Certificate
            p.serverCertificateCommonName = server
            p.serverCertificateIssuerCommonName = "Root-CA"
            if #available(iOSApplicationExtension 8.3, *) {
                p.certificateType = NEVPNIKEv2CertificateType.RSA
            } else {
                // Fallback on earlier versions
            }


// Here i Provide Certificate Data . 

                   let rootCertPath = NSBundle.mainBundle().pathForResource("certificate", ofType: "p12")
                    let certficiateData  = NSData(contentsOfFile: rootCertPath!)

// I need to verify above P12 Certificate with rootCA.crt  before Passing to identityData 

            p.identityData = certficiateData
        }

        manager.enabled = true
        manager.`protocol` = p
rmaddy
  • 314,917
  • 42
  • 532
  • 579
h.kishan
  • 681
  • 6
  • 20

0 Answers0