Changeset 2049

Show
Ignore:
Timestamp:
04/07/08 11:17:40 (8 months ago)
Author:
dsugar
Message:

work on generating iptables (secmark) network rules from CDS Framework policy.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/networking/resources/cdsframework.spt

    r1978 r2049  
    5151') 
    5252 
     53define(`SEFramework_secmark_resource',` 
     54        ifdef(`corenet_client_packet', 
     55                `corenet_client_packet($1)') 
     56') 
     57 
    5358define(`SEFramework_read_boolean',` 
    5459        allow $1 $2:file { read getattr }; 
  • branches/networking/resources/dictionary/dictionary.fdic

    r2045 r2049  
    211211 
    212212rdef secmark 
    213 [desc: "An IPTables (secmark} configured network connection"] 
     213[desc: "An IPTables (secmark) configured network connection"] 
    214214{ 
    215215        requires { secmark } 
  • branches/networking/src/com/tresys/framework/compiler/Compiler.java

    r2032 r2049  
    1515package com.tresys.framework.compiler; 
    1616 
     17import java.io.ByteArrayOutputStream; 
    1718import java.io.FileOutputStream; 
    1819import java.io.FileNotFoundException; 
     
    3435import com.tresys.framework.compiler.policy.SystemResourceValidator; 
    3536import com.tresys.framework.compiler.systemResources.SystemResources; 
     37import com.tresys.framework.compiler.translator.NetworkSecmark; 
    3638import com.tresys.framework.compiler.translator.SELinuxDictionary; 
    3739import com.tresys.framework.compiler.translator.SELinuxPolicy; 
     
    7678        private static String customPolicyFileName; 
    7779 
     80        static String secmarkFilename = null; 
     81         
     82        static String ipsecFilename = null; 
     83         
    7884        private static void getOpt (String[] args) 
    7985        { 
     
    246252                                { 
    247253                                        customPolicyFileName = args[x];  
     254                                } 
     255                                else 
     256                                { 
     257                                        printUsage (); 
     258                                        System.exit (1); 
     259                                } 
     260                        } 
     261                        else if ( args[x].equals ("-secmark")) 
     262                        { 
     263                                x++; 
     264                                if (x < args.length) 
     265                                { 
     266                                        secmarkFilename = args[x];  
     267                                } 
     268                                else 
     269                                { 
     270                                        printUsage (); 
     271                                        System.exit (1); 
     272                                } 
     273                        } 
     274                        else if ( args[x].equals ("-ipsec")) 
     275                        { 
     276                                x++; 
     277                                if (x < args.length) 
     278                                { 
     279                                        ipsecFilename = args[x];  
    248280                                } 
    249281                                else 
     
    339371                System.out.println ("       (defaults to stdout if not specified)"); 
    340372                System.out.println (); 
     373                System.out.println ("Network arguments:"); 
     374                System.out.println ("  -ipsec <output file> specify output file for generated ipsec "); 
     375                System.out.println ("           (Labeled Networking) Security Associations"); 
     376                System.out.println ("  -secmark <output file> specify output file for generated secmark"); 
     377                System.out.println ("           (IPTables Networking) rules"); 
     378                System.out.println (); 
    341379                System.out.println ("Output arguments (repeated here for reference):"); 
    342380                System.out.println ("  -do <dictionary output> specify destination for dictionary (spt) support file"); 
     
    689727                        System.exit (1); 
    690728                } 
     729 
     730                if (secmarkFilename != null) 
     731                { 
     732                        NetworkSecmark networkInfo = new NetworkSecmark (); 
     733                        policy.Accept (networkInfo); 
     734                         
     735                        ByteArrayOutputStream networkData = networkInfo.GetConfiguration (); 
     736                        if (networkData != null && networkData.size () > 0) 
     737                        { 
     738                                try 
     739                                { 
     740                                        File secmarkFile = new File (secmarkFilename); 
     741                                        PrintStream secmarkStream = new PrintStream (secmarkFile); 
     742                                        secmarkStream.print (networkData.toString ()); 
     743                                        secmarkStream.flush (); 
     744                                        secmarkStream.close (); 
     745                                } 
     746                                catch (FileNotFoundException e) 
     747                                { 
     748                                        e.printStackTrace(); 
     749                                } 
     750                        } 
     751                } 
     752                 
    691753                // hopefully this will trigger the finalize() methods and save us memory 
    692754                // and cpu cycles 
  • branches/networking/src/com/tresys/framework/compiler/systemResources/IPTablesNetworkResource.java

    r2045 r2049  
    3939                m_sProtocol = i_sProtocol; 
    4040        } 
     41 
     42        public NetworkInfo getLocalInfo () 
     43        { 
     44                return m_netLocal; 
     45        } 
     46         
     47        public NetworkInfo getRemoteInfo () 
     48        { 
     49                return m_netRemote; 
     50        } 
     51         
     52        public String getProtocol () 
     53        { 
     54                return m_sProtocol; 
     55        } 
    4156} 
  • branches/networking/src/com/tresys/framework/compiler/systemResources/NetworkInfo.java

    r2045 r2049  
    1616 * 
    1717 */ 
    18 class NetworkInfo 
     18public class NetworkInfo 
    1919{ 
    2020        protected final String m_sNode; 
     
    2727                m_sIPAddr = i_sIP; 
    2828                m_nPorts = i_aPorts; 
     29        } 
     30         
     31        public String getNode () 
     32        { 
     33                return m_sNode; 
     34        } 
     35         
     36        public String getIPAddr () 
     37        { 
     38                return m_sIPAddr; 
     39        } 
     40         
     41        public int [] getPorts () 
     42        { 
     43                return m_nPorts; 
    2944        } 
    3045         
  • branches/networking/src/com/tresys/framework/compiler/translator/SELinuxPolicy.java

    r2035 r2049  
    272272                                        } 
    273273                                } 
     274                                else if (rdef.GetSysResourceState (SystemResourceTypes.secmark) != SysResourceState.No) 
     275                                { 
     276                                        MakeSecmarkType (sType, outStream, sIndent); 
     277                                } 
    274278                        } 
    275279 
     
    19291933 
    19301934        /** 
     1935         * Assign a type to packet type. 
     1936         *  
     1937         * @param       String type 
     1938         * @return  Assignment statement 
     1939         */ 
     1940        private void MakeSecmarkType (String sType, PrintStream ps, String i_sLinePrefix) 
     1941        { 
     1942                if (i_sLinePrefix != null) 
     1943                        ps.print (i_sLinePrefix); 
     1944                ps.println ("SEFramework_secmark_resource(" + sType + ")"); 
     1945        } 
     1946 
     1947        /** 
    19311948         * Makes a file context entry for a directory 
    19321949         *  
  • branches/networking/src/com/tresys/framework/plugin/editor/policy/text/PolicyOutlinePage.java

    r2029 r2049  
    193193//              } 
    194194                 
    195                 theOutlineTree.setInput (m_editor.getSystem ().getPolicy ()); 
     195                Object input = null; 
     196                if (m_editor != null && m_editor.getSystem () != null) 
     197                        input = m_editor.getSystem ().getPolicy (); 
     198                 
     199                theOutlineTree.setInput (input); 
    196200        } 
    197201         
  • branches/networking/src/com/tresys/framework/plugin/wizards/shape/ResourceShapePropertyPage.java

    r2030 r2049  
    363363        { 
    364364                private boolean m_bShowControlRdef; 
     365                private boolean m_bShowFile = true; 
     366                private boolean m_bShowDir = true; 
     367                private boolean m_bShowNetwork = false; 
    365368                 
    366369                RDEFFilter (boolean i_bShowControlRdef) 
     
    373376                        if (element instanceof Rdef) 
    374377                        { 
    375                                 if (((Rdef) element).isControlRdef ()) 
     378                                Rdef rdef = (Rdef) element; 
     379                                 
     380                                if (rdef.isControlRdef ()) 
    376381                                        return m_bShowControlRdef; 
     382                                 
     383                                if (rdef.GetSysResourceState (SystemResourceTypes.dir) != SysResourceState.No) 
     384                                        return m_bShowDir; 
     385 
     386                                if (rdef.GetSysResourceState (SystemResourceTypes.file) != SysResourceState.No) 
     387                                        return m_bShowFile; 
     388 
     389                                if (rdef.GetSysResourceState (SystemResourceTypes.ipsec) != SysResourceState.No) 
     390                                        return m_bShowNetwork; 
     391 
     392                                if (rdef.GetSysResourceState (SystemResourceTypes.secmark) != SysResourceState.No) 
     393                                        return m_bShowNetwork; 
     394 
    377395                                return true; 
    378396                        }