示例#1
0
        static void Main(string[] args)
        {
            //netsh ipsec static add policy Example Policy
            IpSecPolicy.Policy policy = new IpSecPolicy.Policy("ExamplePolicy", "ExamplePolicyDescription");

            //netsh ipsec static add filterlist ExampleFilterList
            IpSecPolicy.FilterList filterList = new IpSecPolicy.FilterList("ExampleFilterList", "ExampleFilterList Description");

            //netsh ipsec static add filter filterlist=lag srcaddr=any dstaddr=any protocol=tcp dstport=8080
            IpSecPolicy.Filter filter = new IpSecPolicy.Filter(filterList);

            //netsh ipsec static add filteraction ExampleLagAction action=block
            IpSecPolicy.FilterAction filterAction = new IpSecPolicy.FilterAction();

            //netsh ipsec static add rule name=ExampleRule policy=ExamplePolicy filterlist=ExampleFilterList filteraction=ExampleLagAction

            IpSecPolicy.Rule filterRule = new IpSecPolicy.Rule("ExampleRule", policy.ipsecNegPol, filterList, policy);

            //netsh ipsec static set policy lag assign=y
            throw new NotImplementedException();

            //netsh ipsec static set policy lag assign=y
            throw new NotImplementedException();
        }
示例#2
0
 public void CreateRuleKey(string ipsecName, Policy.IpsecNegotiationPolicy ipsecNegPol, FilterList ipsecFilterList, IpSecPolicy.Policy ipsecPolicy)
 {
     WriteRegistryEntries(ruleSubKey, new object[, ]
     {
         { "className", "ipsecNFA", RegistryValueKind.String },
         { "ipsecData", new byte[]
           {
               0x00, 0xac, 0xbb, 0x11, 0x8d, 0x49, 0xd1, 0x11,
               0x86, 0x39, 0x00, 0xa0, 0x24, 0x8d, 0x30, 0x21,
               0x2a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
               0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
               0x00, 0x00, 0xfd, 0xff, 0xff, 0xff, 0x02, 0x00,
               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
               0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
               0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
               0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
               0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
               0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
               0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
               0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
               0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
               0x00, 0x00, 0x00
           }, RegistryValueKind.Binary },
         { "ipsecDataType", IPSEC_DATA_TYPE_256, RegistryValueKind.DWord },
         { "ipsecFilterReference", new string[] { ipsecFilterList.filterListSubKey.Name.Substring(ipsecFilterList.filterListSubKey.Name.IndexOf("\\")).Remove(0, 1) }, RegistryValueKind.MultiString },
         { "ipsecID", ipSecID, RegistryValueKind.String },
         { "ipsecName", ipsecName, RegistryValueKind.String },
         { "ipsecNegotiationPolicyReference", ipsecNegPol.ipsecNegPolicyKey.Name.Substring(ipsecNegPol.ipsecNegPolicyKey.Name.IndexOf("\\")).Remove(0, 1), RegistryValueKind.String },
         { "ipsecOwnersReference", new string[] { ipsecPolicy.policySubKey.Name.Substring(ipsecPolicy.policySubKey.Name.IndexOf("\\")).Remove(0, 1) }, RegistryValueKind.MultiString },
         { "name", name, RegistryValueKind.String },
         { "whenChanged", GetUnixTimeStamp(), RegistryValueKind.DWord }
     });
     ipsecFilterList.filterListSubKey.SetValue("ipsecOwnersReference", new string[] { ruleSubKey.Name.Substring(ruleSubKey.Name.IndexOf("\\")).Remove(0, 1) }, RegistryValueKind.MultiString);
     ipsecPolicy.policySubKey.SetValue("ipsecNFAReference", new string[] { ruleSubKey.Name.Substring(ruleSubKey.Name.IndexOf("\\")).Remove(0, 1) }, RegistryValueKind.MultiString);
 }