<?xml version="1.0"?>
<!--
    Dedicated ant "build" file for signing eXist jar files.
    
    The eXist client can now be started via java 'Webstart'. For this,
    all jarfiles (at least the ones used by the swing client: exist.jar
    and lib/core/*.jar) must be signed *with the same* keys..
    
    This script is invoked by the main 'build.xml' file, but the 'core'
    jars need to be signed once manually.
    
    The certificates are stored in the file referred as "keystore.file".
    If the file is already available, it is not overwritten. The main idea
    is that you can supply your own certs. A real certificate will give you
    less warnings / messages during startup.
    
    DWE 2005-05-29
    
    $Id: jarsigner.xml 4072 2006-08-14 17:18:44Z dizzzz $
-->
<project name="Sign eXist jarfiles" default="jnlp-sign-all" basedir="../..">

    <description>Sign jarfiles for eXist webstart application</description>
           
    <!-- Set sign properties -->
    <property name="keystore.alias" value="exist"/>
    <property name="keystore.password" value="secret"/>
    <property name="keystore.file" value="key.store"/>
    <property name="keystore.validity" value="100000"/>
    
    <!-- Check wether the keystore already exists -->
    <available file="${keystore.file}" property="keystore.present"/>

    <!-- Shared task -->
    <target name="jnlp-prepare">
        <tstamp/>
    </target> 
    
    <!-- Clean up files that have been copied or generated by this script -->
    <target name="jnlp-clean" description="Delete new files."
        depends="jnlp-prepare">
        <delete file="${keystore.file}"/>
    </target> 

    <!-- Sign Jar files created by eXist -->
    <target name="jnlp-sign-exist" description="Sign all EXIST jar files."
        depends="jnlp-prepare,jnlp-keygen">

        <signjar alias="${keystore.alias}" storepass="${keystore.password}"
            keystore="${keystore.file}">
            <fileset dir=".">
                <include name="exist*.jar"/>
                <include name="start.jar"/>
            </fileset>
        </signjar>
    </target>

    <!-- Sign Jar files used by eXist -->
    <target name="jnlp-sign-core" description="Sign all CORE jar files."
        depends="jnlp-prepare,jnlp-keygen">

        <signjar alias="${keystore.alias}" storepass="${keystore.password}"
            keystore="${keystore.file}">
            <fileset dir="lib/core">
                <include name="*.jar"/>
            </fileset>
        </signjar>
    </target>
    
    <!-- Generate FAKE CERTIFICATE for signing JAR-files -->
    <target name="jnlp-keygen" unless="keystore.present"
        description="Generate keystore for signing jars." depends="jnlp-prepare">
        <genkey alias="${keystore.alias}" storepass="${keystore.password}"
            keystore="${keystore.file}" validity="${keystore.validity}">
            <dname>
                <param name="CN" value="eXist XML database"/>
                <param name="OU" value="Anonymous"/>
                <param name="O" value="exist-db.org"/>
                <param name="C" value="DE"/>
            </dname>
        </genkey>
    </target>
    
    <!-- Generate FAKE CERTIFICATE for SSL -->
    <target name="jetty-keygen" description="Generate keystore for jetty.">
        <genkey alias="jetty" storepass="${keystore.password}"
            keystore="tools/jetty/etc/demokeystore"
            validity="${keystore.validity}">
            <dname>
                <param name="CN" value="eXist XML database"/>
                <param name="OU" value="Anonymous"/>
                <param name="O" value="exist-db.org"/>
                <param name="C" value="DE"/>
            </dname>
        </genkey>
    </target>

    <!-- All tasks, in the best sequence -->
    <target name="jnlp-sign-all"
         depends="jnlp-prepare,jnlp-keygen,jnlp-sign-exist,jnlp-sign-core"
     description="Perform all sign tasks."/>

    <!-- Special task for unsigning jar files -->
    <taskdef name="unsignjars" classname="nl.ow.dilemma.ant.jar.UnsignJarTask" classpath="${asocat-exist.jar}"/>

    <target name="jnlp-unsign-all">
        <unsignjars>
            <fileset dir=".">
                <include name="exist*.jar"/>
                <include name="start.jar"/>
            </fileset>
            <fileset dir="lib/core">
                <include name="*.jar"/>
            </fileset>
        </unsignjars>
    </target>
</project>
