If you have ever configured an IPsec VPN between a Cisco and a Juniper SRX you know it can be difficult. Actually, if you ever configured an IPsec VPN in general you know it can be a royal pain in the keester.
In any case, when you configure a Policy-Based IPsec VPN between Juniper and Cisco ISR routers, with more than one network on each side, you will find you will need an extraordinary number of policies on the SRX in order to play nice with the Cisco. If the networks allow, use IP Address Aggregation. Doing this on both sides will greatly simplify your config. In some (most?) cases you will not be this lucky.
You have 5 networks on each side. you have to create one VPN object per each pair of networks. That’s 5 x 5 = 25. In a PBVPN you have to create two policies per each VPN object: one for incoming traffic and one for outgoing. That’s 2 x 25 = 50 security policies. Keeping track of this many objects as you put them in is difficult and stupid, if not impossible. I found a solution: write a python script to do the dirty work.
Now because I am lazy, you will still need to bypass NAT for the networks you are trying to reach (under security nat source) and create the IKE phase 1 and IPsec Phase 2 proposals and pre-shared keys, but at least you don’t have to create the bazillion statements to get all your networks across.
All I can recommend is this: create a simple PBVPN in a lab between a Cisco ASA 5505 or a Cisco ISR and a Juniper SRX100. If you don’t have an ASA 5505 use a Sonicwall with SonicOS 5.6 or greater, or a Fortinet; they handle PBVPNs in almost the same way. But the best way is to use very similar devices to what you will use in the real scenario. If you don’t have a spare SRX, you can create a virtual Juniper Olive to test out your stuff. I have created Olives and it is well documented on the ‘net how to do it.
Please feel free to mock my poor python scripting. This was quick and dirty and also my first python script. You can also see this script on pastebin.
UPDATE Sept 24 2012: I have updated the code below and on the pastebin link above. There were bugs in the code that made it not work; the v1.1 is now tested to work with Juniper JunOS 11.2R4.3.
Python Script for Complex Juniper SRX Policy-Based VPNs (junos-pbvpn.py)download
#!/usr/bin/env python############################################################################### andkorn Sept 21 2012## This script is free to use under the BSD 3-clause license.## this script reads in a few options and creates a juniper config for a policy-based vpn that will work with Cisco's access-list-based vpn.# see also why policy-based VPNs are a pain:# http://forums.juniper.net/t5/SRX-Services-Gateway/srx-route-mode-ipsec-vpn-with-sonicwall-gen3-gen4-standard-and/td-p/33658# http://kb.juniper.net/InfoCenter/index?page=content&id=KB15745&smlogin=true## version 1.1##importsys,reprint("---Configuring VPN Blocks")gateway=raw_input("Enter 'ike gateway' object name:")ipsec_policy=raw_input("Enter 'ipsec-policy' object name:")print("---Configuring network Blocks")trustzone=raw_input("Enter trust zone name (usually 'trust'):")untrustzone=raw_input("Enter untrust zone name (usually 'untrust'):")localprefix=raw_input("Enter local name prefix for objects (anything that makes sense):")remoteprefix=raw_input("Enter remote name prefix for objects (anything that makes sense):")print("Enter local networks in 192.168.1.0/24 format, one per line. Enter Ctrl+Z to end:")localnetworkstxt=sys.stdin.read()localnetworks=localnetworkstxt.split("\n")print("Enter remote networks in 192.168.1.0/24 format, one per line. Enter Ctrl+Z to end:")remotenetworkstxt=sys.stdin.read()remotenetworks=remotenetworkstxt.split("\n")#Clean up the inputted networks; remove invalid IP addresseslocalnetworkstmp=localnetworkslocalnetworks=filter(lambdax:re.search(r'((2[0-5]|1[0-9]|[0-9])?[0-9]\.){3}((2[0-5]|1[0-9]|[0-9])?[0-9])\/[0-3]?[0-9]',x),localnetworkstmp)remotenetworkstmp=remotenetworksremotenetworks=filter(lambdax:re.search(r'((2[0-5]|1[0-9]|[0-9])?[0-9]\.){3}((2[0-5]|1[0-9]|[0-9])?[0-9])\/[0-3]?[0-9]',x),remotenetworkstmp)fsock=open(raw_input("Enter file to save to:"),'w')origstdout=sys.stdoutsys.stdout=fsockprint("##########Below is your config. Load this with 'load merge terminal' in JunOS")print("##junos-pbvpn.py by andkorn Sept 21 2012")print("security {")print(" ipsec {")networkcount=1forlocalnetworkinlocalnetworks[:]:forremotenetworkinremotenetworks[:]:print(" vpn vpn"+localprefix+"-to-"+remoteprefix+"-"+str(networkcount)+" {")print(" ike {")print(" gateway "+gateway+";")print(" ipsec-policy "+ipsec_policy+";")print(" }")print(" establish-tunnels immediately;")print(" }")networkcount+=1print(" }")print(" policies {")networkcount=1print(" from-zone "+trustzone+" to-zone "+untrustzone+" {")forlocalnetworkinlocalnetworks[:]:forremotenetworkinremotenetworks[:]:print(" policy vpn-out-"+localprefix+"-"+localnetwork.replace("/","-").replace(".","-")+"-to-"+remoteprefix+"-"+remotenetwork.replace("/","-").replace(".","-")+" {")print(" match {")print(" source-address "+localprefix+"-"+localnetwork.replace("/","-").replace(".","-")+";")print(" destination-address "+remoteprefix+"-"+remotenetwork.replace("/","-").replace(".","-")+";")print(" application any;")print(" }")print(" then {")print(" permit {")print(" tunnel {")print(" ipsec-vpn vpn"+localprefix+"-to-"+remoteprefix+"-"+str(networkcount)+";")print(" pair-policy vpn-in-"+localprefix+"-"+localnetwork.replace("/","-").replace(".","-")+"-to-"+remoteprefix+"-"+remotenetwork.replace("/","-").replace(".","-")+";")print(" }")print(" }")print(" }")print(" }")networkcount+=1print(" }")networkcount=1print(" from-zone "+untrustzone+" to-zone "+trustzone+" {")forlocalnetworkinlocalnetworks[:]:forremotenetworkinremotenetworks[:]:print(" policy vpn-in-"+localprefix+"-"+localnetwork.replace("/","-").replace(".","-")+"-to-"+remoteprefix+"-"+remotenetwork.replace("/","-").replace(".","-")+" {")print(" match {")print(" source-address "+remoteprefix+"-"+remotenetwork.replace("/","-").replace(".","-")+";")print(" destination-address "+localprefix+"-"+localnetwork.replace("/","-").replace(".","-")+";")print(" application any;")print(" }")print(" then {")print(" permit {")print(" tunnel {")print(" ipsec-vpn vpn"+localprefix+"-to-"+remoteprefix+"-"+str(networkcount)+";")print(" pair-policy vpn-out-"+localprefix+"-"+localnetwork.replace("/","-").replace(".","-")+"-to-"+remoteprefix+"-"+remotenetwork.replace("/","-").replace(".","-")+";")print(" }")print(" }")print(" }")print(" }")networkcount+=1print(" }")print(" }")print(" zones {")print(" security-zone "+trustzone+" {")print(" address-book {")forlocalnetworkinlocalnetworks[:]:print(" address "+localprefix+"-"+localnetwork.replace("/","-").replace(".","-")+" "+localnetwork+";")print(" }")print(" }")print(" security-zone "+untrustzone+" {")print(" address-book {")forremotenetworkinremotenetworks[:]:print(" address "+remoteprefix+"-"+remotenetwork.replace("/","-").replace(".","-")+" "+remotenetwork+";")print(" }")print(" host-inbound-traffic {")print(" system-services {")print(" ike;")print(" }")print(" }")print(" }")print(" }")print("}")print("####END")sys.stdout=origstdoutfsock.close()