% policy conflict analysis impl

\subsection{Library introduction}
As already introduced in the previous Section~\ref{sec:policy_services}, this security system is strongly integrated with the project \textit{policy tool library} developed by ``TORSEC'' security group in Politecnico di Torino for the past EC-funded project SECURED.

This library is developed to handle and to manage security policies, to resolve rules conflicts and to analyse reachability properties in a given landscape with servers, services and firewalls. The core of the library is the module that implements what the Section~\ref{subsec:policy_analysis} explains, which is to say it bases its policy representation through the \textit{Canonical Form}.

The library also provides all the tools to generate a \textit{Semilattice} representation and the\break possibility to translate a given policy into a \textit{Morphism} form.

Different modules of the library were exploited to solve anomalies and conflicts of the input policies.
\begin{itemize}
	\item 
	Intra-policy conflict analysis: each policy is represented by the Java object \code{PolicyImpl} that offers a ``resolution strategy'', a ``default action'' and a list of ``filtering rules''.
	Starting from this class and following the procedure described in the section ``Policy Analysis, Conflicts and Transformation''~(\ref{subsec:policy_analysis}), the correspondent closure is generated and, from that results, the canonical form is created to have an easy processing of the policy itself.
	
	After this operation the class \code{SemiLatticeGenerator} allows the library to analyse the policy and to discover all the rule anomalies which are solved by the \code{FMRMorphism} object. It generates a morphism representation of the policy from which a new policy could be defined with no conflicts.
	
	\item
	Inter-policy conflict analysis: this process is called ``reconciliation'', because it is done\break between policies.
	The first operation is to create a \code{ComposedPolicy} that contains an ordered list of the policies to be reconciliated.
	
	After this step, the procedure to find all the anomalies and to remove the conflicts is the same of the ``intra-policy conflict analysis'' described in the previous point.
\end{itemize}
\pagebreak

\subsection{Policy - XSD schema}

The XSD schema is defined to model the security policies of different organizations and it is an extension of the DTD schema used in the  policy library. The implementation and the modelling were developed to make them full compatible with the previous schema in order to reuse library's modules.
Moreover XSD language was chosen instead of DTD one, because it is more expressive and it is possible to define and to establish more specific constraints and references.

Additional work is done to make it more compliant with the input model described in\linebreak Section ``High level design''~(\ref{sec:high_level}).
In particular all the policies are nested in a more general node named \textit{EntityElement}, which could express further information.
\newline
This node is characterized by:

\begin{itemize}
	\item 
	\textit{ISP}: it is a boolean variable that identifies if this is the owner entity of the infrastructure. This variables is introduced because it identifies the entity with the higher priority among all the entities;
	\item
	\textit{Label}: it is the uniquely identifier of the entity among all the entities;
	\item
	\textit{Subnet}: it is the network linked to this entity, on which its nodes could be instantiated;
	\item
	\textit{PolicyElement}: it is the entity's policy.
\end{itemize}

\begin{figure}[H]
	\HRule
	\begin{lstlisting}[numbers=left,stepnumber=1, style=XML]
<xsd:complexType name="EntityElement">
	<xsd:sequence>
		<xsd:element name="Policy" type="PolicyElement" />
	</xsd:sequence>
	
	<xsd:attribute name="ISP" type="xsd:boolean" use="required" />
	<xsd:attribute name="Label" type="xsd:string" use="required" />
	<xsd:attribute name="Subnet" type="SubnetElement" use="required" />
</xsd:complexType>
	\end{lstlisting}
	\HRule
	%\caption{z3 used as library in a Java project.
	%\label{fig:z3-code}}
\end{figure}

Each policy is modeled as a ``PolicyElement'', it expresses the security behavior that must be followed by all its instances. It is characterized by:
\begin{itemize}
	\item 
	\textit{PolicyName}: it is the name the policy;
	\item
	\textit{PolicyType}: it is the type of the policy, in this thesis work the only useful policy type is \code{PolicyTypeElement = \{FILTERING\}}, but this feature is kept for compatibility and for additional future work;
	\item
	\textit{DefAction}: it is the default action performed by this policy;
	\item
	\textit{rule list}: it is the ordered filtering rule list.
\end{itemize}

\begin{figure}[H]
	\HRule
	\begin{lstlisting}[numbers=left,stepnumber=1, style=XML]
<xsd:complexType name="PolicyElement">
	<xsd:sequence>
		<xsd:element name="PolicyName" type="xsd:string" />
		<xsd:element name="PolicyType" type="PolicyTypeElement" />
		<xsd:element name="DefAction" type="xsd:string" />
		<xsd:element name="Rule" type="RuleElement" minOccurs="0" maxOccurs="unbounded" />
	</xsd:sequence>
</xsd:complexType>
	\end{lstlisting}
	\HRule
	%\caption{z3 used as library in a Java project.
	%\label{fig:z3-code}}
\end{figure}
\clearpage

The ``rule'' item is the last one modelled, it has the task to describe what traffic pattern needs to be matched by this filtering rules and what action has to be performed on it. 

It is defined as:

\begin{itemize}
	\item 
	\textit{Priority}: it sets the rule priority in the policy;
	\item
	\textit{Selector list}: it is the list of selectors, which means the fields in a packet that need to be checked to be matched with the rules;
	\item
	\textit{Transformation}: it is ignored, it is present for compatibility, but it may be used in future for extensions;
	\item
	\textit{Action}: it represents the action to be performed on the matched traffic;
	\item
	\textit{Label}: it is the uniquely identifier of the rule.
\end{itemize}

\begin{figure}[H]
	\HRule
	\begin{lstlisting}[numbers=left,stepnumber=1, style=XML]
<xsd:complexType name="RuleElement">
	<xsd:sequence>
		<xsd:element name="Priority" type="PriorityElement" />
		<xsd:element name="Selector" type="SelectorElement" minOccurs="1" maxOccurs="unbounded" />
		<xsd:element name="Transformation" type="TransformationElement" minOccurs="0" maxOccurs="1" />
	</xsd:sequence>
	
	<xsd:attribute name="Action" use="required">
		<xsd:simpleType>
			<xsd:restriction base="xsd:string">
				<xsd:enumeration value="ALLOW" />
				<xsd:enumeration value="DENY" />
			</xsd:restriction>
		</xsd:simpleType>
	</xsd:attribute>
	
	<xsd:attribute name="Label" type="xsd:string" />
</xsd:complexType>
	\end{lstlisting}
	\HRule
	%\caption{z3 used as library in a Java project.
	%\label{fig:z3-code}}
\end{figure}
\clearpage

The following Listing~\ref{list:xml_entities} shows a complete XML file, which defines an example of policies definition.

\begin{figure}[H]
	\HRule
	\begin{lstlisting}[numbers=left,stepnumber=1, style=XML]
<Entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xml_policy.xsd">

	<Entity Label="ISP" ISP="true" Subnet="10.0.0.0/24">
		<Policy>
			<PolicyName>policy1</PolicyName>
			<PolicyType>FILTERING</PolicyType>
			<DefAction>DENY</DefAction>
			
			<Rule Action="ALLOW" Label="policy1.R1">
				<Priority>1</Priority>
				<Selector Label="Source Port">11</Selector>
				<Selector Label="Source Address">10.0.0.56</Selector>
			</Rule>
			
			<Rule Action="ALLOW" Label="policy1.R2">
				<Priority>1</Priority>
				<Selector Label="Destination Port">80</Selector>
				<Selector Label="Destination Address">10.0.0.56</Selector>
			</Rule>
		</Policy>
	</Entity>

	<Entity Label="entity2" ISP="false" Subnet="20.0.0.0/24">
		<Policy>
			<PolicyName>policy2</PolicyName>
			<PolicyType>FILTERING</PolicyType>
			<DefAction>DENY</DefAction>
		
			<Rule Action="ALLOW" Label="policy2.R1">
				<Priority>1</Priority>
				<Selector Label="Source Address">20.0.0.38</Selector>
				<Selector Label="Destination Address">192.168.0.0-192.168.0.255</Selector>
			</Rule>
		</Policy>
	</Entity>

</Entities>
	\end{lstlisting}
	\HRule
	\caption{XML file describing the entity's policies.
		\label{list:xml_entities}}
\end{figure}





