Example #1
0
        internal IkeSecurityAssociation(IKEEXT_SA_DETAILS1 sa_details)
        {
            Id                 = sa_details.saId;
            KeyModuleType      = sa_details.keyModuleType;
            LocalAddress       = FirewallUtils.GetAddress(sa_details.ikeTraffic.ipVersion, sa_details.ikeTraffic.localAddress);
            RemoteAddress      = FirewallUtils.GetAddress(sa_details.ikeTraffic.ipVersion, sa_details.ikeTraffic.remoteAddress);
            InitiatorCookie    = sa_details.cookiePair.initiator;
            ResponderCookie    = sa_details.cookiePair.responder;
            IkePolicyKey       = sa_details.ikePolicyKey;
            VirtualIfTunnelId  = sa_details.virtualIfTunnelId;
            CorrelationKey     = sa_details.correlationKey.ToArray();
            CipherAlgorithm    = sa_details.ikeProposal.cipherAlgorithm.algoIdentifier;
            KeyLength          = sa_details.ikeProposal.cipherAlgorithm.keyLen;
            Rounds             = sa_details.ikeProposal.cipherAlgorithm.rounds;
            IntegrityAlgorithm = sa_details.ikeProposal.integrityAlgorithm.algoIdentifier;
            MaxLifetime        = sa_details.ikeProposal.maxLifetimeSeconds;
            DiffieHellmanGroup = sa_details.ikeProposal.dhGroup;
            QuickModeLimit     = sa_details.ikeProposal.quickModeLimit;

            List <IkeCredentialPair> credentials = new List <IkeCredentialPair>();

            if (sa_details.ikeCredentials.numCredentials > 0)
            {
                SafeHGlobalBuffer buf = new SafeHGlobalBuffer(sa_details.ikeCredentials.credentials, 1, false);
                buf.Initialize <IKEEXT_CREDENTIAL_PAIR1>((uint)sa_details.ikeCredentials.numCredentials);
                var arr = buf.ReadArray <IKEEXT_CREDENTIAL_PAIR1>(0, sa_details.ikeCredentials.numCredentials);
                credentials.AddRange(arr.Select(c => new IkeCredentialPair(c)));
            }
            Credentials = credentials.AsReadOnly();
        }
        private static IReadOnlyList <UserGroup> ReadSids(IntPtr ptr, int count)
        {
            if (ptr == IntPtr.Zero || count == 0)
            {
                return(new List <UserGroup>().AsReadOnly());
            }
            SafeHGlobalBuffer buffer = new SafeHGlobalBuffer(ptr, 1, false);

            buffer.Initialize <SidAndAttributes>((uint)count);
            return(buffer.ReadArray <SidAndAttributes>(0, count).Select(s => s.ToUserGroup()).ToList().AsReadOnly());
        }
Example #3
0
        internal FirewallLayer(FWPM_LAYER0 layer, FirewallEngine engine, Func <SecurityInformation, bool, NtResult <SecurityDescriptor> > get_sd)
            : base(layer.layerKey, layer.displayData, NamedGuidDictionary.LayerGuids.Value, engine, get_sd)
        {
            Flags = layer.flags;
            DefaultSubLayerKey = layer.defaultSubLayerKey;
            LayerId            = layer.layerId;
            List <FirewallField> fields = new List <FirewallField>();

            if (layer.numFields > 0 && layer.field != IntPtr.Zero)
            {
                var buffer = new SafeHGlobalBuffer(layer.field, 1, false);
                buffer.Initialize <FWPM_FIELD0>((uint)layer.numFields);
                fields.AddRange(buffer.ReadArray <FWPM_FIELD0>(0, layer.numFields).Select(f => new FirewallField(f)));
            }
            Fields = fields.AsReadOnly();
        }
        internal FirewallFilter(FWPM_FILTER0 filter, FirewallEngine engine, Func <SecurityInformation, bool, NtResult <SecurityDescriptor> > get_sd)
            : base(filter.filterKey, filter.displayData, new NamedGuidDictionary(), engine, get_sd)
        {
            ActionType = filter.action.type;
            if (ActionType.HasFlag(FirewallActionType.Callout))
            {
                CalloutKey     = filter.action.action.calloutKey;
                CalloutKeyName = NamedGuidDictionary.CalloutGuids.Value.GetName(CalloutKey);
            }
            else
            {
                FilterType = filter.action.action.filterType;
            }
            LayerKey        = filter.layerKey;
            LayerKeyName    = NamedGuidDictionary.LayerGuids.Value.GetName(LayerKey);
            SubLayerKey     = filter.subLayerKey;
            SubLayerKeyName = NamedGuidDictionary.SubLayerGuids.Value.GetName(SubLayerKey);
            Flags           = filter.flags;

            List <FirewallFilterCondition> conditions = new List <FirewallFilterCondition>();

            if (filter.numFilterConditions > 0)
            {
                var conds = new SafeHGlobalBuffer(filter.filterCondition, 1, false);
                conds.Initialize <FWPM_FILTER_CONDITION0>((uint)filter.numFilterConditions);
                conditions.AddRange(conds.ReadArray <FWPM_FILTER_CONDITION0>(0, filter.numFilterConditions).Select(c => new FirewallFilterCondition(c)));
            }
            Conditions      = conditions.AsReadOnly();
            Weight          = new FirewallValue(filter.weight, Guid.Empty);
            EffectiveWeight = new FirewallValue(filter.effectiveWeight, Guid.Empty);
            if (filter.providerKey != IntPtr.Zero)
            {
                ProviderKey = filter.providerKey.ReadGuid() ?? Guid.Empty;
            }
            ProviderData = filter.providerData.ToArray();
            FilterId     = filter.filterId;
        }