<?Pub UDT _bookmark _target?><?Pub EntList bsol dash hellip gt lt minus?><?Pub CX solbook(book(title()bookinfo()chapter()?><chapter id="javatxlabelapis"><title>Experimental Java Bindings for the Solaris Trusted Extensions Label APIs</title><highlights><para>This chapter describes an experimental set of <trademark>Java</trademark> classes and methods that mirror the label application programming interfaces (APIs) that are provided with the Solaris Trusted Extensions software. The Java implementation of the Trusted Extensions label APIs is intended to be used to create label-aware applications. As a result, all of the label APIs provided by Trusted Extensions are not part of the Java implementation.</para><para>The presentation of these experimental Java APIs (Java bindings) demonstrate how the Solaris Trusted Extensions features can be expanded into the Java development environment.</para><caution><para>These experimental Java bindings are <emphasis>not</emphasis> a supported part of the Solaris Trusted Extensions software.</para>
</caution><itemizedlist><para>This chapter covers the following topics:</para><listitem><para><olink targetptr="javabindingsoverview" remap="internal">Java Bindings Overview</olink></para>
</listitem><listitem><para><olink targetptr="javalabelapistructure" remap="internal">Structure of the Experimental Java Label Interfaces</olink></para>
</listitem><listitem><para><olink targetptr="javalabelapis" remap="internal">Java Bindings</olink></para>
</listitem>
</itemizedlist>
</highlights><sect1 id="javabindingsoverview"><title>Java Bindings Overview</title><para>The Java language is an untapped resource for creating label-aware applications that run in secure, multilevel arenas. These experimental Java bindings provide a foundation on which to develop more applications, such as system audit log generation and system resource controls.</para><para>Adding platform services to the Java environment will enable Java applications to handle sensitive multilevel data.</para><para>Solaris Trusted Extensions provides label services through the label daemon, <command>labeld</command>. This daemon is available to processes that run in the global zone and in labeled zones.</para><para>The Java bindings described in this chapter are Java Native Interface (<trademark>JNI</trademark>) implementations of some of the Solaris Trusted Extensions label APIs. The experimental JNI code calls the Solaris Trusted Extensions label library functions to extend some of the label functionality to the Java language. Constructors and methods in these Java classes call private JNI interfaces, written in C, that in turn call the Trusted Extensions APIs. For example, the <methodname>SolarisLabel.dominates</methodname> method calls a private JNI interface written in C that calls the <function>bldominates</function> routine. These experimental Java bindings have been developed using Java 2 Platform, Standard Edition 5.0. For more information about JNI, see <ulink url="http://java.sun.com/j2se/1.5.0/docs/guide/jni/" type="text_url">Java Native Interface Documentation</ulink>.</para><para>You can download this experimental code from the Solaris Trusted Extensions project page of the <trademark>OpenSolaris</trademark> <ulink url="http://www.opensolaris.org/os/community/security/projects/tx/" type="text_url">web site</ulink>.</para>
</sect1><sect1 id="javalabelapistructure"><title>Structure of the Experimental Java Label Interfaces</title><indexterm><primary>Java bindings</primary><secondary>classes</secondary>
</indexterm><itemizedlist><para>The JNI implementation of the Trusted Extensions label APIs introduces several label-related classes that relate to each other in this way:</para><listitem><para><classname>SolarisLabel</classname> abstract class</para><itemizedlist><listitem><para><classname>ClearanceLabel</classname> subclass</para>
</listitem><listitem><para><classname>SensitivityLabel</classname> subclass</para>
</listitem>
</itemizedlist>
</listitem><listitem><para><classname>Range</classname> class</para>
</listitem>
</itemizedlist><sect2 id="labelclassdesc"><title><classname>SolarisLabel</classname> Abstract Class</title><indexterm><primary><classname>SolarisLabel</classname> abstract class</primary><secondary>description of</secondary>
</indexterm><indexterm><primary>Java bindings</primary><secondary><classname>SolarisLabel</classname> abstract class</secondary>
</indexterm><para>The <classname>SolarisLabel</classname> abstract class provides the foundation for common and native methods related to Solaris Trusted Extensions labels. The <classname>SensitivityLabel</classname> and <classname>ClearanceLabel</classname> subclasses inherit members from this abstract class. Static factories for creating sensitivity labels and clearance labels are also provided by the abstract class.</para><para>Static factories and methods throw exceptions when errors are encountered to ensure that no mandatory access control-related errors occur silently.</para><itemizedlist><para><indexterm><primary><classname>SolarisLabel</classname> abstract class</primary><secondary>methods and static factories</secondary></indexterm>This abstract class defines the following general-purpose methods that are used to compare labels and to translate labels to strings:</para><listitem><para><methodname>dominates</methodname></para>
</listitem><listitem><para><methodname>equals</methodname></para>
</listitem><listitem><para><methodname>setFileLabel</methodname></para>
</listitem><listitem><para><methodname>strictlyDominates</methodname></para>
</listitem><listitem><para><methodname>toColor</methodname></para>
</listitem><listitem><para><methodname>toInternal</methodname></para>
</listitem><listitem><para><methodname>toRootPath</methodname></para>
</listitem><listitem><para><methodname>toString</methodname></para>
</listitem><listitem><para><methodname>toText</methodname></para>
</listitem><listitem><para><methodname>toTextLong</methodname></para>
</listitem><listitem><para><methodname>toTextShort</methodname></para>
</listitem>
</itemizedlist><para>The <methodname>equals</methodname>, <methodname>dominates</methodname>, and <methodname>strictlyDominates</methodname> methods are analogous to the <function>blequal</function>, <function>bldominates</function>, and <function>blstrictdom</function> label APIs currently available with Solaris Trusted Extensions. The <methodname>setFileLabel</methodname> method is analogous to the <function>setflabel</function> routine currently available with Solaris Trusted Extensions.</para><para>The rest of the methods (such as <methodname>toText</methodname>, <methodname>toInternal</methodname>, and <methodname>toColor</methodname>) are related in function to the <function>label_to_str</function> routine that is currently available with Solaris Trusted Extensions. These methods enable you to translate a label to a particular type of string. Depending on the label relationship of the process and the object, you might need privileges in your effective set to translate a label to a human-readable form. For instance, the Java Virtual Machine (<trademark>JVM</trademark>) process must be running with the <literal>sys_trans_label</literal> privilege to translate labels that it does not dominate.</para><itemizedlist><para>The <classname>SolarisLabel</classname> abstract class also includes the following static factories:</para><listitem><para><methodname>getClearanceLabel</methodname></para>
</listitem><listitem><para><methodname>getFileLabel</methodname></para>
</listitem><listitem><para><methodname>getSensitivityLabel</methodname></para>
</listitem><listitem><para><methodname>getSocketPeer</methodname></para>
</listitem>
</itemizedlist><itemizedlist><para>The string that you pass as a label to <methodname>getSensitivityLabel</methodname> or <methodname>getClearanceLabel</methodname> can be in one of the following forms:</para><listitem><para>Human-readable form of the label, such as <constant>PUBLIC</constant></para>
</listitem><listitem><para>Internal form of the label, such as <constant>0x0002-08-08</constant></para>
</listitem>
</itemizedlist><para>Only the internal form of the label is suitable for storage and for transmission over a network connection, as the internal form does not reveal the actual label. For more information, see <olink targetptr="labelapi-28" remap="internal">Readable Versions of Labels</olink>.</para><para>The <classname>ClearanceLabel</classname> and <classname>SensitivityLabel</classname> subclasses extend the <classname>SolarisLabel</classname> abstract class. These subclasses each inherit the common methods provided by the <classname>SolarisLabel</classname> abstract class.</para><sect3 id="clearancelabelclassdesc"><title><classname>ClearanceLabel</classname> Subclass</title><indexterm><primary><classname>ClearanceLabel</classname> subclass</primary>
</indexterm><indexterm><primary>Java bindings</primary><secondary><classname>ClearanceLabel</classname> subclass</secondary>
</indexterm><para>The <classname>ClearanceLabel</classname> subclass extends the <classname>SolarisLabel</classname> abstract class and defines the <methodname>getMaximum</methodname> and <methodname>getMinimum</methodname> methods, which return the <literal>ClearanceLabel</literal> object that represents the least upper bound and the greatest lower bound, respectively.</para>
</sect3><sect3 id="sensitivitylabelclassdesc"><title><classname>SensitivityLabel</classname> Subclass</title><indexterm><primary><classname>SensitivityLabel</classname> subclass</primary><secondary>description of</secondary>
</indexterm><indexterm><primary>Java bindings</primary><secondary><classname>SensitivityLabel</classname> subclass</secondary>
</indexterm><para>The <classname>SensitivityLabel</classname> subclass extends the <classname>SolarisLabel</classname> abstract class and defines the <methodname>getMaximum</methodname> and <methodname>getMinimum</methodname> methods, which return the <literal>SensitivityLabel</literal> object that represents the least upper bound and the greatest lower bound, respectively.</para><itemizedlist><para><indexterm><primary><classname>SensitivityLabel</classname> subclass</primary><secondary>methods</secondary></indexterm>The <classname>SensitivityLabel</classname> subclass introduces the following methods that provide information suitable for labeled printer banner pages:</para><listitem><para><methodname>toCaveats</methodname></para>
</listitem><listitem><para><methodname>toChannels</methodname></para>
</listitem><listitem><para><methodname>toFooter</methodname></para>
</listitem><listitem><para><methodname>toHeader</methodname></para>
</listitem><listitem><para><methodname>toProtectAs</methodname></para>
</listitem>
</itemizedlist>
</sect3>
</sect2><sect2 id="rangeclassdesc"><title><classname>Range</classname> Class</title><indexterm><primary><classname>Range</classname> class</primary><secondary>description of</secondary>
</indexterm><indexterm><primary>Java bindings</primary><secondary><classname>Range</classname> class</secondary>
</indexterm><para>The <classname>Range</classname> class represents a Java version of a Solaris Trusted Extensions label range.</para><itemizedlist><para><indexterm><primary><classname>Range</classname> class</primary><secondary>methods and static factories</secondary></indexterm>This class defines the following general-purpose methods that are used to obtain the upper and lower labels in a label range and to determine whether a label is within a specified label range:</para><listitem><para><methodname>getLower</methodname></para>
</listitem><listitem><para><methodname>getUpper</methodname></para>
</listitem><listitem><para><methodname>inRange</methodname></para>
</listitem>
</itemizedlist><itemizedlist><para>The <classname>Range</classname> class also includes the following static factories that create range objects:</para><listitem><para><methodname>getDeviceRange</methodname></para>
</listitem><listitem><para><methodname>getLabelRange</methodname></para>
</listitem><listitem><para><methodname>getUserRange</methodname></para>
</listitem>
</itemizedlist><para>The <methodname>getDeviceRange</methodname> and <methodname>getUserRange</methodname> static factories create range objects based on the range for the specified device and the specified user, respectively. The <methodname>getLabelRange</methodname> static factory enables you to create a label range where you specify the upper and lower bounds for the range.</para>
</sect2>
</sect1><sect1 id="javalabelapis"><title>Java Bindings</title><para>The Java implementation of the Trusted Extensions label APIs is intended to be used to create label-aware applications. As a result, not all of the label APIs provided by Trusted Extensions are part of the Java implementation.</para><itemizedlist><para>The Java classes and methods that are presented in this chapter mimic the following general label functionality shown in <olink targetptr="labelapi-22" remap="internal">Label APIs</olink>:</para><listitem><para>Detecting a Trusted Extensions system</para>
</listitem><listitem><para>Accessing the process sensitivity label</para>
</listitem><listitem><para>Allocating and freeing memory for label objects</para>
</listitem><listitem><para>Obtaining and setting the label of a file</para>
</listitem><listitem><para>Obtaining label range objects</para>
</listitem><listitem><para>Accessing labels in zones</para>
</listitem><listitem><para>Obtaining the remote host type</para>
</listitem><listitem><para>Translating between labels and strings</para>
</listitem><listitem><para>Comparing label objects</para>
</listitem>
</itemizedlist><sect2 id="jnidetecttxsystem"><title>Detecting a Trusted Extensions System</title><indexterm><primary>detecting a Trusted Extensions system</primary>
</indexterm><indexterm><primary>Trusted Extensions system, detecting</primary>
</indexterm><para>These Java bindings do not include methods to determine whether a system is labeled. Rather, the library will fail to load if Trusted Extensions is not enabled.</para>
</sect2><sect2 id="jniaccesslabel"><title>Accessing the Process Sensitivity Label</title><para>These Java bindings do not include methods to obtain the label of a process. In Trusted Extensions, a process that runs in a labeled zone has the same label as the zone.</para>
</sect2><sect2 id="jniallocatefreelabelmemory"><title>Allocating and Freeing Memory for Label Objects</title><para>These Java bindings take advantage of the Java &ldquo;garbage-collection&rdquo; functionality. As a result, you do not need to explicitly free the memory used by label objects as you do for the label APIs described in <olink targetptr="labelapi-29" remap="internal">Obtaining and Setting the Label of a File</olink>.</para>
</sect2><sect2 id="jniobtainsetfilelabels"><title>Obtaining and Setting the Label of a File</title><indexterm><primary><methodname>getFileLabel</methodname> static factory</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary>Java static factories</primary><secondary><methodname>getFileLabel</methodname></secondary>
</indexterm><indexterm><primary><methodname>getSocketPeer</methodname> static factory</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary>Java static factories</primary><secondary><methodname>getSocketPeer</methodname></secondary>
</indexterm><indexterm><primary><methodname>setFileLabel</methodname> method</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary>Java methods</primary><secondary><methodname>setFileLabel</methodname></secondary>
</indexterm><para>These Java bindings use the Java <literal>File</literal> object to obtain and set file labels. Use the <methodname>getFileLabel</methodname> static factory to obtain the label from the file's <literal>File</literal> object. To set a file label to another specified label, use the <methodname>setFileLabel</methodname> method on the file's <literal>File</literal> object.</para><para>In addition to obtaining the sensitivity label of a file, the <methodname>getSocketPeer</methodname> static factory enables you to obtain the sensitivity label for the peer endpoint of a socket.</para><para>The <methodname>getFileLabel</methodname> static factory and the <methodname>setFileLabel</methodname> method correspond to the <function>getlabel</function> system call and the <function>setflabel</function> routine, respectively. For more information, see <olink targetptr="labelapi-29" remap="internal">Obtaining and Setting the Label of a File</olink> and the <olink targetdoc="refman" targetptr="getlabel-2" remap="external"><citerefentry><refentrytitle>getlabel</refentrytitle><manvolnum>2</manvolnum></citerefentry></olink> and <olink targetdoc="refman" targetptr="setflabel-3tsol" remap="external"><citerefentry><refentrytitle>setflabel</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man pages.</para><para>The following descriptions include the prototype declarations for the static factories and the method:</para><variablelist termlength="wholeline"><varlistentry><term><literal>public static SensitivityLabel getFileLabel(java.io.File file)</literal></term><listitem><para><indexterm><primary>Java static factories</primary><secondary><methodname>getFileLabel</methodname></secondary></indexterm><indexterm><primary><methodname>getFileLabel</methodname> static factory</primary><secondary>declaration</secondary></indexterm>The <methodname>getFileLabel</methodname> static factory obtains the label of a Java <literal>File</literal> object that is specified by <replaceable>file</replaceable>.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public static SensitivityLabel getSocketPeer(java.net.Socket socket)</literal></term><listitem><para>The <methodname>getSocketPeer</methodname> static factory obtains a sensitivity label object from the specified socket, <replaceable>socket</replaceable>.</para><para>The following code fragment obtains the sensitivity label object of the socket, <replaceable>s</replaceable>:</para><screen>SensitivityLabel sl = SolarisLabel.getSocketPeer(s);</screen><para><indexterm><primary>code examples</primary><secondary>obtain socket peer label</secondary></indexterm><indexterm><primary>code examples</primary><secondary><classname>getSocketPeer</classname> static factory</secondary><tertiary>obtaining socket peer label</tertiary></indexterm><indexterm><primary><methodname>getSocketPeer</methodname> static factory</primary><secondary>code example</secondary></indexterm>The following example code shows how to create a server socket on port 9090 and then obtain the sensitivity label of the peer end of the accepted connection. This code example also outputs the internal and human-readable forms, the color, and the root path of the obtained socket peer label.</para><screen>import java.io.*;
import java.net.*;
import solarismac.*;

public class ServerSocketTest
{

    public static void main (String args[]) {

        System.out.println("ServerSocketTest Start");

        CreateListner();

        System.out.println("ServerSocketTest End");

    }

    /*
     * Listen for connections on port then print the peer connection label.
     * You can use telnet host 9090 to create a client connection.
     */
    private static void CreateListner() {
        int port = 9090;

        ServerSocket acceptSocket;
        Socket s;
        try {
            System.out.println("Creating ServerSocket on port " + port);

            acceptSocket = new ServerSocket(port);

            System.out.println("ServerSocket created, waiting for connection");

            s = acceptSocket.accept();

            /*
             * Get the Sensitivity Label for the peer end of the socket.
             */
            SensitivityLabel socksl = SolarisLabel.getSocketPeer(s);

            System.out.println("Client connected...");
            System.out.println(" toInternal: " + socksl.toInternal());
            System.out.println(" toText: " + socksl.toText());
            System.out.println(" toString: " + socksl.toString());
            System.out.println(" toColor: " + socksl.toColor());
            System.out.println(" toRootPath: " + socksl.toRootPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}</screen>
</listitem>
</varlistentry><varlistentry><term><literal>public static void setFileLabel(java.io.File file, SensitivityLabel label)</literal></term><listitem><para><indexterm><primary>labels</primary><secondary>objects</secondary></indexterm>The <methodname>setFileLabel</methodname> method changes the sensitivity label of the specified file to the specified label. When the sensitivity label of a file changes, the file is moved to the zone that corresponds to the new label. The file is moved to a new path name that is relative to the root of the other zone.</para><para>For example, if you use the <methodname>setFileLabel</methodname> method to change the label of the file <filename>/zone/internal/documents/designdoc.odt</filename> from <constant>INTERNAL</constant> to <constant>RESTRICTED</constant>, the new path of the file will be <filename>/zone/restricted/documents/designdoc.odt</filename>. Note that if the destination directory does not exist, the file is not moved.</para><para>The following code fragment shows how you might change the label of the file:</para><screen>SolarisLabel.setFileLabel(new File("/zone/internal/documents/designdoc.odt"),
    SolarisLabel.getSensitivityLabel("RESTRICTED"));</screen><para>When you change the sensitivity label of a file, the original file is deleted. The only exception occurs when the source and destination file systems are loopback-mounted from the same underlying file system. In this case, the file is renamed.</para><para>The Java virtual machine must be running with the appropriate privilege (<literal>file_upgrade_sl</literal> or <literal>file_downgrade_sl</literal>) to relabel a file.</para><para>For more information about setting privileges, see <citetitle remap="chapter">Developing Privileged Applications,</citetitle> in <citetitle remap="book">Solaris Security for Developers Guide</citetitle>. See also the <olink targetdoc="refman" targetptr="setflabel-3tsol" remap="external"><citerefentry><refentrytitle>setflabel</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man page.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2><sect2 id="jniobtainlabelranges"><title>Obtaining Label Range Objects</title><indexterm><primary><methodname>getUserRange</methodname> static factory</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary><methodname>getDeviceRange</methodname> static factory</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary><methodname>getLabelRange</methodname> static factory</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary>Java static factories</primary><secondary><methodname>getUserRange</methodname></secondary>
</indexterm><indexterm><primary>Java static factories</primary><secondary><methodname>getDeviceRange</methodname></secondary>
</indexterm><indexterm><primary>Java static factories</primary><secondary><methodname>getLabelRange</methodname></secondary>
</indexterm><indexterm><primary><methodname>getUpper</methodname> method</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary><methodname>getLower</methodname> method</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary>Java methods</primary><secondary><methodname>getUpper</methodname></secondary>
</indexterm><indexterm><primary>Java methods</primary><secondary><methodname>getLower</methodname></secondary>
</indexterm><para>The <methodname>getLabelRange</methodname> static factory creates a label range object. The <methodname>getUserRange</methodname> and <methodname>getDeviceRange</methodname> static factories obtain label range objects for a user and a device, respectively. The <methodname>getUpper</methodname> and <methodname>getLower</methodname> methods are used to obtain the upper and lower labels of the range, respectively. In addition, the <methodname>inRange</methodname> method determines whether the specified label is in a range. For more information about the <methodname>inRange</methodname> method, see <olink targetptr="jnicomparelabel" remap="internal">Comparing Label Objects</olink>.</para><para>The <methodname>getUserRange</methodname> and <methodname>getDeviceRange</methodname> static factories correspond to the <function>getuserrange</function> and <function>getdevicerange</function> routines. For more information, see <olink targetptr="obtaininglabelranges" remap="internal">Obtaining Label Ranges</olink> and the <olink targetdoc="refman" targetptr="getdevicerange-3tsol" remap="external"><citerefentry><refentrytitle>getdevicerange</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man page.</para><para>The following constructor and method descriptions include the prototype declaration for each constructor:</para><variablelist termlength="wholeline"><varlistentry><term><literal>public static Range getDeviceRange(java.lang.String device)</literal></term><listitem><para>The <methodname>getDeviceRange</methodname> static factory obtains the label range of a user-allocatable device. If no label range is specified for the device, the default range has an upper bound of <constant>ADMIN_HIGH</constant> and a lower bound of <constant>ADMIN_LOW</constant>.</para><para>You can use the <command>list_devices</command> command to show the label range for a device. See the <olink targetdoc="refman" targetptr="list-devices-1" remap="external"><citerefentry><refentrytitle>list_devices</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> and <olink targetdoc="refman" targetptr="getdevicerange-3tsol" remap="external"><citerefentry><refentrytitle>getdevicerange</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man pages.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public static &lt;L extends SolarisLabel,U extends SolarisLabel&gt; Range getLabelRange(L lower, U upper)</literal></term><listitem><para>The <methodname>getLabelRange</methodname> static factory creates a label range. The static factory takes the lower bound value in the range and the upper bound, or clearance, as parameters. An exception is thrown if <replaceable>upper</replaceable> does not dominate <replaceable>lower</replaceable>.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public L getLower()</literal></term><listitem><para>The <methodname>getLower</methodname> method returns the lower portion of the range.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public U getUpper()</literal></term><listitem><para>The <methodname>getUpper</methodname> method returns the upper portion of the range.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public static Range getUserRange(java.lang.String user)</literal></term><listitem><para>The <methodname>getUserRange</methodname> static factory obtains the label range of the specified user. The lower bound in the range is used as the initial workspace label when a user logs in to a multilevel desktop. The upper bound, or clearance, is used as an upper limit to the available labels that a user can assign to labeled workspaces.</para><para>The default value for a user's label range is specified in the <filename>label_encodings</filename> file. The value can be overridden by the <filename>user_attr</filename> file.</para><para>For more information, see the <olink targetdoc="refman" targetptr="getuserrange-3tsol" remap="external"><citerefentry><refentrytitle>getuserrange</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man page.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2><sect2 id="jniaccesszonelabels"><title>Accessing Labels in Zones</title><para>The following description includes the prototype declaration for the method:</para><variablelist termlength="wholeline"><varlistentry><term><literal>public final java.lang.String toRootPath()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toRootPath</methodname></secondary></indexterm><indexterm><primary><methodname>toRootPath</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns the root path name of the zone for the specified sensitivity label.</para><para>The following code excerpt shows how to obtain the root path for the <constant>PUBLIC</constant> sensitivity label:</para><screen>SensitivityLabel sl = SolarisLabel.getSensitivityLabel("PUBLIC");
System.out.println("toRootPath: " + sl.toRootPath();</screen><para>This method throws a <exceptionname>java.io.IOException</exceptionname> if an invalid label is specified or if no zone is configured for the specified label.</para><para>This method mimics the <function>getzonerootbylabel</function> routine. See the <olink targetdoc="refman" targetptr="getzonerootbylabel-3tsol" remap="external"><citerefentry><refentrytitle>getzonerootbylabel</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man page. See also <olink targetptr="accessinglabelsinzones" remap="internal">Accessing Labels in Zones</olink>.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2><sect2 id="jniobtainremotehosttype"><title>Obtaining the Remote Host Type</title><para>The Java implementation of the Trusted Extensions label APIs does not include interfaces for obtaining the remote host type.</para>
</sect2><sect2 id="jnitranslatelabels"><title>Translating Between Labels and Strings</title><para>The <classname>SolarisLabel</classname> abstract class includes methods for translating between labels and strings, which are inherited by its subclasses.</para><para>These methods translate the internal representation of a label (<structname>m_label_t</structname>) to <literal>String</literal> objects.</para><para>You can use the <methodname>toInternal</methodname> method to translate a label into a string that hides the classification name. This format is suitable for storing labels in public objects.</para><para>The running Java virtual machine must dominate the label to be translated, or it must have the <constant>sys_trans_label</constant> privilege. See the <olink targetdoc="refman" targetptr="label-to-str-3tsol" remap="external"><citerefentry><refentrytitle>label_to_str</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man page.</para><para>Some of the label values are based on data in the <filename>label_encodings</filename> file.</para><para>The following methods mimic the <function>label_to_str</function> routine. See the <olink targetdoc="refman" targetptr="label-to-str-3tsol" remap="external"><citerefentry><refentrytitle>label_to_str</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man page.</para><variablelist termlength="wholeline"><varlistentry><term><literal>public final java.lang.String toColor()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toColor</methodname></secondary></indexterm><indexterm><primary><methodname>toColor</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns the color of the <literal>SolarisLabel</literal> object. The value is suitable for use by HTML.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public final java.lang.String toInternal()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toInternal</methodname></secondary></indexterm><indexterm><primary><methodname>toInternal</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns the internal representation of the label that is safe for storing in a public object. An internal conversion can later be parsed to its same value. This is the same as using the <methodname>toString</methodname> method.</para><para>These two methods differ in the way that they handle errors. If the <methodname>toInternal</methodname> method encounters an error, it returns a <exceptionname>java.io.IOException</exceptionname>. However, if the <methodname>toString</methodname> method encounters an error, it returns a null.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public java.lang.String toString()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toString</methodname></secondary></indexterm><indexterm><primary><methodname>toString</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns the internal hexadecimal version of the label in string form, which is the same as using the <methodname>toInternal</methodname> method.</para><para>These two methods differ in the way that they handle errors. If the <methodname>toString</methodname> method encounters an error, it returns a null. However, if the <methodname>toInternal</methodname> method encounters an error, it returns a <exceptionname>java.io.IOException</exceptionname>.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public java.lang.String toText()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toText</methodname></secondary></indexterm><indexterm><primary><methodname>toText</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns a human-readable text string of the <literal>SolarisLabel</literal> object.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public java.lang.String toTextLong()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toTextLong</methodname></secondary></indexterm><indexterm><primary><methodname>toTextLong</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns the long human-readable text string of the <literal>SolarisLabel</literal> object.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public java.lang.String toTextShort()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toTextShort</methodname></secondary></indexterm><indexterm><primary><methodname>toTextShort</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns the short human-readable text string of the <literal>SolarisLabel</literal> object.</para>
</listitem>
</varlistentry>
</variablelist><para>The following methods perform label translations that are suitable for creating multilevel printer banner pages. These methods mimic some of the functionality of the <function>label_to_str</function> routine. See the <olink targetdoc="refman" targetptr="label-to-str-3tsol" remap="external"><citerefentry><refentrytitle>label_to_str</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> and <olink targetdoc="refman" targetptr="m-label-3tsol" remap="external"><citerefentry><refentrytitle>m_label</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man pages.</para><variablelist termlength="wholeline"><varlistentry><term><literal>public java.lang.String toCaveats()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toCaveats</methodname></secondary></indexterm><indexterm><primary><methodname>toCaveats</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns a human-readable text string that is suitable for the caveats section of the banner page.</para><para>This method is only available for <literal>SensitivityLabel</literal> objects, not for <literal>ClearanceLabel</literal> objects.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public java.lang.String toChannels()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toChannels</methodname></secondary></indexterm><indexterm><primary><methodname>toChannels</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns a human-readable text string that is suitable for the handling channels section of the banner page.</para><para>This method is only available for <literal>SensitivityLabel</literal> objects, not for <literal>ClearanceLabel</literal> objects.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public java.lang.String toFooter()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toFooter</methodname></secondary></indexterm><indexterm><primary><methodname>toFooter</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns a human-readable text string that is appropriate for use as the sensitivity label. This sensitivity label appears at the bottom of banner and trailing pages.</para><para>This method is only available for <literal>SensitivityLabel</literal> objects, not for <literal>ClearanceLabel</literal> objects.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public java.lang.String toHeader()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toHeader</methodname></secondary></indexterm><indexterm><primary><methodname>toHeader</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns a human-readable text string that is appropriate for use as the sensitivity label. This sensitivity label appears at the top of banner and trailing pages.</para><para>This method is only available for <literal>SensitivityLabel</literal> objects, not for <literal>ClearanceLabel</literal> objects.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public java.lang.String toProtectAs()</literal></term><listitem><para><indexterm><primary>Java methods</primary><secondary><methodname>toProtectAs</methodname></secondary></indexterm><indexterm><primary><methodname>toProtectAs</methodname> method</primary><secondary>declaration</secondary></indexterm>This method returns a human-readable text string that is suitable for the page downgrade section of the banner page.</para><para>This method is only available for <literal>SensitivityLabel</literal> objects, not for <literal>ClearanceLabel</literal> objects.</para>
</listitem>
</varlistentry>
</variablelist><example id="javaprinterbanner"><title>Using the Java Bindings to Create a Banner Page</title><indexterm><primary><classname>SensitivityLabel</classname> subclass</primary><secondary>code example</secondary>
</indexterm><indexterm><primary>printer banner page</primary><secondary>label translation</secondary>
</indexterm><indexterm><primary>code examples</primary><secondary>printer banner</secondary>
</indexterm><indexterm><primary>code examples</primary><secondary><filename>label_encodings</filename> file</secondary><tertiary>creating printer banner</tertiary>
</indexterm><indexterm><primary><methodname>toHeader</methodname> method</primary><secondary>code example</secondary>
</indexterm><indexterm><primary><methodname>toFooter</methodname> method</primary><secondary>code example</secondary>
</indexterm><indexterm><primary><methodname>toProtectAs</methodname> method</primary><secondary>code example</secondary>
</indexterm><indexterm><primary><methodname>toCaveats</methodname> method</primary><secondary>code example</secondary>
</indexterm><indexterm><primary><methodname>toChannels</methodname> method</primary><secondary>code example</secondary>
</indexterm><indexterm><primary><methodname>getSensitivityLabel</methodname> static factory</primary><secondary>code example</secondary>
</indexterm><para>The following example code shows how to use the Java bindings to create a banner page similar to the one described in <olink targetptr="labelcode-22" remap="internal">Obtaining Printer Banner Information</olink>.</para><screen>import solarismac.*;
import java.io.*;

/*
 * Banner page example
 */
public class PrintTest1
{

   public static void main (String args[]) {

      try {

         // Pick a valid label using the label_encodings.example
         SensitivityLabel sl = SolarisLabel.getSensitivityLabel("TOP SECRET A B SA");

         // "Protect as classification"
         System.out.println(sl.toHeader());
         System.out.println();

         // "Protect as classification plus compartments"
         System.out.println("This output must be protected as:");
         System.out.println(sl.toProtectAs());
         System.out.println("unless manually reviewed and downgraded.");
         System.out.println();

         // Handling instructions specified in PRINTER BANNERS
         System.out.println(sl.toCaveats());
         System.out.println();

         // Handling instructions specified in CHANNELS
         System.out.println(sl.toChannels());
         System.out.println();

         // "Protect as classification"
         System.out.println(sl.toFooter());
         System.out.println();

      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}</screen><para>For a process label of <literal>TOP SECRET A B SA</literal>, the text output might be the following:</para><screen>		TOP SECRET

This output must be protected as:

TOP SECRET A B SA

unless manually reviewed and downgraded.

   (FULL SA NAME)
   HANDLE VIA (CH B)/(CH A) CHANNELS JOINTLY

		TOP SECRET</screen>
</example><para>Methods such as <methodname>toText</methodname>, <methodname>toInternal</methodname>, and <methodname>toColor</methodname> do not translate from a string to a label. To translate a string to a sensitivity label or to a clearance label, you must call the <methodname>getSensitivityLabel</methodname> or <methodname>getClearanceLabel</methodname> static factories, respectively. The following static factories mimic the <function>str_to_label</function> routine. See the <olink targetdoc="refman" targetptr="str-to-label-3tsol" remap="external"><citerefentry><refentrytitle>str_to_label</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> and <olink targetdoc="refman" targetptr="m-label-3tsol" remap="external"><citerefentry><refentrytitle>m_label</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man pages.</para><variablelist termlength="wholeline"><varlistentry><term><literal>public static ClearanceLabel getClearanceLabel(java.lang.String label)</literal></term><listitem><para><indexterm><primary>Java static factories</primary><secondary><methodname>getClearanceLabel</methodname></secondary></indexterm><indexterm><primary><methodname>getClearanceLabel</methodname> static factory</primary><secondary>declaration</secondary></indexterm>This static factory creates a clearance label from the specified string. The following examples create new clearance labels based on a label name and the internal hexadecimal name of a label:</para><screen>ClearanceLabel cl = SolarisLabel.getClearanceLabel("PUBLIC");
ClearanceLabel cl = SolarisLabel.getClearanceLabel("0x0002-08-08");</screen>
</listitem>
</varlistentry><varlistentry><term><literal>public static SensitivityLabel getSensitivityLabel(java.lang.String label)</literal></term><listitem><para><indexterm><primary>Java static factories</primary><secondary><methodname>getSensitivityLabel</methodname></secondary></indexterm><indexterm><primary><methodname>getSensitivityLabel</methodname> static factory</primary><secondary>declaration</secondary></indexterm>This static factory creates a sensitivity label from the specified string. The following examples create new sensitivity labels based on a label name and the internal hexadecimal name of a label:</para><screen>SensitivityLabel sl = SolarisLabel.getSensitivityLabel("PUBLIC");
SensitivityLabel sl = SolarisLabel.getSensitivityLabel("0x0002-08-08");</screen>
</listitem>
</varlistentry>
</variablelist>
</sect2><sect2 id="jnicomparelabel"><title>Comparing Label Objects</title><indexterm><primary><methodname>dominates</methodname> method</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary><methodname>equals</methodname> method</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary><methodname>strictlyDominates</methodname> method</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary><methodname>inRange</methodname> method</primary><secondary>declaration</secondary>
</indexterm><indexterm><primary>Java methods</primary><secondary><methodname>inRange</methodname></secondary>
</indexterm><indexterm><primary>Java methods</primary><secondary><methodname>dominates</methodname></secondary>
</indexterm><indexterm><primary>Java methods</primary><secondary><methodname>equals</methodname></secondary>
</indexterm><indexterm><primary>Java methods</primary><secondary><methodname>strictlyDominates</methodname></secondary>
</indexterm><para>The following <methodname>equals</methodname>, <methodname>dominates</methodname>, and <methodname>strictlyDominates</methodname> methods are used to compare labels, and correspond to the <function>blequal</function>, <function>bldominate</function>, and <function>blstrictdom</function> routines. The <methodname>inRange</methodname> method is used to determine whether a label is within a specified label range, and corresponds to the <function>blinrange</function> routine. In these methods, a <emphasis>label</emphasis> refers to a classification and a set of compartments in a sensitivity label or in a clearance label. For more information, see <olink targetptr="labelapi-38" remap="internal">Comparing Labels</olink> and the <olink targetdoc="refman" targetptr="blcompare-3tsol" remap="external"><citerefentry><refentrytitle>blcompare</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man page.</para><variablelist termlength="wholeline"><varlistentry><term><literal>public boolean dominates(SolarisLabel label)</literal></term><listitem><para>The <methodname>dominates</methodname> method compares two labels to determine whether one label dominates the other.</para><para>The following example code shows how you can make the comparison. The <literal>CNF : INTERNAL</literal> label is being compared to check its dominance over the <literal>PUBLIC</literal> label.</para><screen>SensitivityLabel sl = SolarisLabel.getSensitivityLabel("CNF : INTERNAL");
boolean isDominant = sl.dominates(SolarisLabel.getSensitivityLabel("PUBLIC"));</screen>
</listitem>
</varlistentry><varlistentry><term><literal>public boolean equals(java.lang.Object obj)</literal></term><listitem><para>The <methodname>equals</methodname> method compares two labels to determine whether they are equal.</para><para>The following example code shows how you can make the comparison:</para><screen>SensitivityLabel sl = SolarisLabel.getSensitivityLabel("CNF : INTERNAL");
boolean isSame = sl.equals(SolarisLabel.getSensitivityLabel("PUBLIC"));</screen>
</listitem>
</varlistentry><varlistentry><term><literal>public boolean Range inRange(SensitivityLabel label)</literal></term><listitem><para><indexterm><primary><methodname>inRange</methodname> method</primary><secondary>declaration</secondary></indexterm><indexterm><primary>Java methods</primary><secondary><methodname>inRange</methodname></secondary></indexterm>The <methodname>inRange</methodname> method determines whether the specified label is within the range. This method belongs to the <classname>Range</classname> class.</para><para>The following code fragment shows how you can verify that a file is within a user's clearance range:</para><screen>import solarismac.*;
import java.io.*;

public class Example1
{
    public static void main (String args[]) {

        try {
	    Range range;

            range = Range.getUserRange("jweeks");
            SensitivityLabel fsl =
                SolarisLabel.getFileLabel(new File("/etc/passwd"));
            boolean isInRange;

            isInRange = Range.inRange(fsl);

            if (isInRange)
                System.out.println("File is within user's range");
            else
                System.out.println("File is not within user's range");

        }
        catch (Exception e) {
            e.PrintStackTrace();
        }
    }
}</screen>
</listitem>
</varlistentry><varlistentry><term><literal>public boolean strictlyDominates(SolarisLabel label)</literal></term><listitem><para>The <methodname>strictlyDominates</methodname> method compares two labels to determine whether one label strictly dominates the other. When a label strictly dominates another, it dominates the other label, but is not equal to the other label.</para><para>The following example code shows how you can make the comparison. The <literal>CNF : INTERNAL</literal> label is being compared to check its strict dominance over the <literal>PUBLIC</literal> label.</para><screen>SensitivityLabel sl = SolarisLabel.getSensitivityLabel("CNF : INTERNAL");
boolean isStrictlyDominant =
    sl.strictlyDominates(SolarisLabel.getSensitivityLabel("PUBLIC"));</screen>
</listitem>
</varlistentry>
</variablelist><para>For more information about label relationships, see <olink targetptr="labelrelationships" remap="internal">Label Relationships</olink>.</para><para><indexterm><primary><methodname>getMinimum</methodname> method</primary><secondary>declaration</secondary></indexterm><indexterm><primary><methodname>getMaximum</methodname> method</primary><secondary>declaration</secondary></indexterm><indexterm><primary>Java methods</primary><secondary><methodname>getMaximum</methodname></secondary></indexterm><indexterm><primary>Java methods</primary><secondary><methodname>getMinimum</methodname></secondary></indexterm>The <methodname>getMaximum</methodname> and <methodname>getMinimum</methodname> methods are used to determine the least upper bound and the greatest lower bound of the specified label range, respectively. These methods mirror the functionality of the <function>blmaximum</function> and <function>blminimum</function> routines. For more information, see <olink targetptr="labelapi-38" remap="internal">Comparing Labels</olink> and the <olink targetdoc="refman" targetptr="blminmax-3tsol" remap="external"><citerefentry><refentrytitle>blminmax</refentrytitle><manvolnum>3TSOL</manvolnum></citerefentry></olink> man page.</para><para>For instance, use the <methodname>getMaximum</methodname> method to determine the label to use when creating a new labeled object that combines information from two other labeled objects. The label of the new object will dominate both of the original labeled objects. Each method is defined by the <classname>ClearanceLabel</classname> and <classname>SensitivityLabel</classname> subclasses.</para><variablelist termlength="wholeline"><varlistentry><term><literal>public ClearanceLabel getMaximum(ClearanceLabel bounding)</literal></term><listitem><para><indexterm><primary><methodname>getMaximum</methodname> method</primary><secondary>declaration</secondary></indexterm><indexterm><primary>Java methods</primary><secondary><methodname>getMaximum</methodname></secondary></indexterm>The <methodname>getMaximum</methodname> method creates a new clearance label object that is the lowest label that can dominate two label objects you specify. The resulting object is the least upper bound of the range. <methodname>getMaximum</methodname> returns an object in the internal form of the clearance label.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public ClearanceLabel getMinimum(ClearanceLabel bounding)</literal></term><listitem><para><indexterm><primary><methodname>getMinimum</methodname> method</primary><secondary>declaration</secondary></indexterm><indexterm><primary>Java methods</primary><secondary><methodname>getMinimum</methodname></secondary></indexterm>The <methodname>getMinimum</methodname> method creates a new clearance label object that is the highest label that is dominated by two labels you specify. The resulting object is the greatest lower bound of the range. <methodname>getMinimum</methodname> returns an object in the internal form of the clearance label.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public SensitivityLabel getMaximum(SensitivityLabel bounding)</literal></term><listitem><para><indexterm><primary><methodname>getMaximum</methodname> method</primary><secondary>declaration</secondary></indexterm><indexterm><primary>Java methods</primary><secondary><methodname>getMaximum</methodname></secondary></indexterm>The <methodname>getMaximum</methodname> method creates a new sensitivity label object that is the lowest label that can dominate two label objects you specify. The resulting object is the least upper bound of the range. <methodname>getMaximum</methodname> returns an object in the internal form of the sensitivity label.</para>
</listitem>
</varlistentry><varlistentry><term><literal>public SensitivityLabel getMinimum(SensitivityLabel bounding)</literal></term><listitem><para><indexterm><primary><methodname>getMinimum</methodname> method</primary><secondary>declaration</secondary></indexterm><indexterm><primary>Java methods</primary><secondary><methodname>getMinimum</methodname></secondary></indexterm>The <methodname>getMinimum</methodname> method creates a new sensitivity label object that is the highest label that is dominated by two labels you specify. The resulting object is the greatest lower bound of the range. <methodname>getMinimum</methodname> returns an object in the internal form of the sensitivity label.</para>
</listitem>
</varlistentry>
</variablelist><para>The following table shows label input and output from the <methodname>getMaximum</methodname> and <methodname>getMinimum</methodname> methods.</para><table frame="topbot" id="getminimumgetmaximumtable"><title>Using the <methodname>getMinimum</methodname> and <methodname>getMaximum</methodname> Methods</title><tgroup cols="3" colsep="0" rowsep="0"><colspec colname="column1" colwidth="33.00*"/><colspec colname="column2" colwidth="33.00*"/><colspec colname="column3" colwidth="33.00*"/><thead><row rowsep="1"><entry><para>Input Labels</para>
</entry><entry><para><methodname>getMinimum</methodname> Output</para>
</entry><entry><para><methodname>getMaximum</methodname> Output</para>
</entry>
</row>
</thead><tbody><row rowsep="1"><entry><para><literal>SECRET A B</literal></para><para><literal>TOP SECRET A B SA SB CC</literal></para>
</entry><entry><para><literal>SECRET A B</literal></para>
</entry><entry><para><literal>TOP SECRET A B SA SB CC</literal></para>
</entry>
</row><row rowsep="1"><entry><para><literal>SECRET A B</literal></para><para><literal>TOP SECRET A SA CC</literal></para>
</entry><entry><para><literal>SECRET A</literal></para>
</entry><entry><para><literal>TOP SECRET A B SA CC</literal></para>
</entry>
</row><row rowsep="1"><entry><para><literal>SECRET A B</literal></para><para><literal>TOP SECRET</literal></para>
</entry><entry><para><literal>SECRET</literal></para>
</entry><entry><para><literal>TOP SECRET A B</literal></para>
</entry>
</row><row rowsep="1"><entry><para><literal>SECRET A</literal></para><para><literal>TOP SECRET B</literal></para>
</entry><entry><para><literal>SECRET</literal></para>
</entry><entry><para><literal>TOP SECRET A B</literal></para>
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
</sect1>
</chapter>