NEVPNProtocolIPsec No VPN Shared Secret was provided

Hello I am developing a react native VPN app. Also I'm new to Native Modules and Swift.

Depending on the related documents, I've tried to create IPSEC VPN and connect automatically from my application.

I've used the code below to create and connect IPSEC VPN but it is returning "No VPN Shared Secret was provided" error.

If I try to add VPN configuration from my Iphone with same parameters it's connecting successfully.

This is the swift code: import Foundation import NetworkExtension import KeychainAccess

@objc(VPNManager) class VPNManager: NSObject {

@objc static func requiresMainQueueSetup() -> Bool { return true }

@objc func connectToVPN(_ config: NSDictionary, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) { print("Received config: (config)") guard let serverAddress = config["serverAddress"] as? String, let account = config["account"] as? String, let password = config["password"] as? String, let sharedSecret = config["sharedSecret"] as? String else { rejecter("error", "Invalid configuration", nil) return }

print("Server Address: \(serverAddress)")
  print("Account: \(account)")
  print("Password: \(password)")
  print("Shared Secret: \(sharedSecret)")

let vpnManager = NEVPNManager.shared()
vpnManager.loadFromPreferences { error in
  if let error = error {
    rejecter("error", "Failed to load preferences: \(error.localizedDescription)", error)
    return
  }

  let p = NEVPNProtocolIPSec()
  p.serverAddress = serverAddress
  p.authenticationMethod = .sharedSecret
  p.localIdentifier = account
  p.remoteIdentifier = serverAddress
  p.username = account

  // Store shared secret and password in Keychain
  let keychain = Keychain(service: "com.yourcompany.FreeVpnApp")
  do {
    try keychain.set(sharedSecret, key: "VPN_SHARED_SECRET")
    guard let sharedSecretData = try keychain.getData("VPN_SHARED_SECRET") else {
      rejecter("error", "No VPN shared secret was found", nil)
      return
    }
    p.sharedSecretReference = sharedSecretData

    try keychain.set(password, key: "VPN_PASSWORD")
    guard let passwordData = try keychain.getData("VPN_PASSWORD") else {
      rejecter("error", "No VPN password was found", nil)
      return
    }
    p.passwordReference = passwordData
  } catch let keychainError {
    rejecter("error", "Failed to store password or shared secret: \(keychainError.localizedDescription)", keychainError)
    return
  }

  p.useExtendedAuthentication = true
  p.disconnectOnSleep = false

  vpnManager.protocolConfiguration = p
  vpnManager.localizedDescription = "AGVPN"
  vpnManager.isEnabled = true

  vpnManager.saveToPreferences { error in
    if let error = error {
      rejecter("error", "Failed to save preferences: \(error.localizedDescription)", error)
      return
    }

    do {
      try vpnManager.connection.startVPNTunnel()
      resolver("Connected to VPN")
    } catch {
      rejecter("error", "Failed to start VPN tunnel: \(error.localizedDescription)", error)
    }
  }
}

}

@objc func disconnectFromVPN(_ resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) { let vpnManager = NEVPNManager.shared() vpnManager.connection.stopVPNTunnel() resolver("Disconnected from VPN") } }

It sounds like you’re trying to configure the built-in VPN transports, a concept known as Personal VPN. In that case I recommend that you start by creating a VPN configuration profile for your VPN service. An easy way to do that is with Apple Configurator.

Are you able to get that to work? Because it’s vital that you verify this before you start trying to debug your code.

If you are, please post your configuration profile here. If you change the extension to .txt you can attach it rather than trying to post it inline. Make sure to redact any info you don’t want to share with the world, like the shared secret (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

NEVPNProtocolIPsec No VPN Shared Secret was provided
 
 
Q