Network Extension フレームワークを使用したコードを介して VPN に接続したい。
VPN 接続を作成するための P12 証明書と、P12 証明書を検証するためのルート CA (Crt) 証明書があります。
私の問題は、プログラムで P12 証明書を検証することです。
以下のコードを使用して 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