2011/07/19

Truecrypt in Debian GNU/Linux Lenny x64

Sometimes you need to encrypt some files like documents, passwords, etc. and puntual encryption maybe just the solution with gpg. However, if you need to encrypt lots of files you should try TrueCrypt for a masive encryption.

So, what about a virtual encrypted partition containing all your files?

The following procedure was done in a remote machine through ssh: 

First, you need to download the installer from here according to your architecture.

uname -a
Linux felix 2.6.32-bpo.5-xen-amd64 #1 SMP Thu Oct 21 13:52:59 UTC 2010 x86_64 GNU/Linux

In my case: truecrypt-7.0a-linux-console-x64.tar.gz

Second, you need some dependencies (?):

apt-get install fuse-utils libdevmapper dmsetup

Third, you must install TrueCrypt:

tar xzf truecrypt-7.0a-linux-console-x64.tar.gz
./truecrypt-7.0a-setup-console-x64

TrueCrypt 7.0a Setup
____________________


Installation options:

 1) Install truecrypt_7.0a_console_amd64.tar.gz
 2) Extract package file truecrypt_7.0a_console_amd64.tar.gz and place it to /tmp

To select, enter 1 or 2: 1

Before you can use, extract, or install TrueCrypt, you must accept the
terms of the TrueCrypt License.

Press Enter to display the license terms...

Press Enter or space bar to see the rest of the license.


TrueCrypt License Version 3.0

Software distributed under this license is distributed on an "AS
IS" BASIS WITHOUT WARRANTIES OF ANY KIND. THE AUTHORS AND
DISTRIBUTORS OF THE SOFTWARE DISCLAIM ANY LIABILITY. ANYONE WHO
USES, COPIES, MODIFIES, OR (RE)DISTRIBUTES ANY PART OF THE
SOFTWARE IS, BY SUCH ACTION(S), ACCEPTING AND AGREEING TO BE
BOUND BY ALL TERMS AND CONDITIONS OF THIS LICENSE. IF YOU DO NOT
ACCEPT THEM, DO NOT USE, COPY, MODIFY, NOR (RE)DISTRIBUTE THE
SOFTWARE, NOR ANY PART(S) THEREOF.


I. Definitions

1. "This Product" means the work (including, but not limited to,
source code, graphics, texts, and accompanying files) made
available under and governed by this version of this license
("License"), as may be indicated by, but is not limited to,
copyright notice(s) attached to or included in the work.

2. "You" means (and "Your" refers to) an individual or a legal
entity (e.g., a non-profit organization, commercial
organization, government agency, etc.) exercising permissions
granted by this License.

3. "Modification" means (and "modify" refers to) any alteration
of This Product, including, but not limited to, addition to or
deletion from the substance or structure of This Product,
translation into another language, repackaging, alteration or
removal of any file included with This Product, and addition of
any new files to This Product.

... ([q] to skip)
..
.

Do you accept and agree to be bound by the license terms? (yes/no): yes

Uninstalling TrueCrypt:
-----------------------

To uninstall TrueCrypt, please run 'truecrypt-uninstall.sh'.

Installing package...
usr/bin/truecrypt
usr/bin/truecrypt-uninstall.sh
usr/share/truecrypt/doc/License.txt
usr/share/truecrypt/doc/TrueCrypt User Guide.pdf

Press Enter to exit...


Four, let's create a virtual disk "Private.tc":


truecrypt Private.tc


Volume type:
 1) Normal
 2) Hidden
Select [1]: 1

Enter volume path: Private.tc

Enter volume size (sizeK/size[M]/sizeG): 1G

Encryption algorithm:
 1) AES
 2) Serpent
 3) Twofish
 4) AES-Twofish
 5) AES-Twofish-Serpent
 6) Serpent-AES
 7) Serpent-Twofish-AES
 8) Twofish-Serpent
Select [1]: 1

Hash algorithm:
 1) RIPEMD-160
 2) SHA-512
 3) Whirlpool
Select [1]: 2

Filesystem:
 1) None
 2) FAT
 3) Linux Ext2
 4) Linux Ext3
 5) Linux Ext4
Select [2]: 4

Enter password: ***********************************
Re-enter password: ***********************************

Enter keyfile path [none]:

Please type at least 320 randomly chosen characters and then press Enter:
Characters remaining: 30 (Press [ENTER] to end or know how much is left)


Done: 100.000%  Speed:   29 MB/s  Left: 0 s

The TrueCrypt volume has been successfully created.


To mount our disk:

truecrypt --mount Private.tc /mnt/truecrypt0

root:/mnt/truecrypt0# ls -ltr
total 16
drwx------ 2 root root 16384 2011-07-19 02:17 lost+found



Now we can move/copy our stuff!


To unmount our disk:

truecrypt -d Private.tc 

References

http://www.howtoforge.com/truecrypt_data_encryption
http://esaucairn-almuric.blogspot.com/2009/03/truecrypt-on-debian.html

2011/07/14

Assembling an executable jar into a timestamped package

I needed to build a package for an executable jar containing all its dependencies, in bzip2 format and with a time stamp in the file-name. This is how a did it:

To generate the time stamp I chose gmaven-plugin but you can use the buildnumber-maven-plugin if you need to relate some build number with your control version system (svn maybe?). Futhermore gmaven is a whole new tool box for a developer!

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>set-timestamp</id>
            <phase>initialize</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>
                    def timestamp = new Date().format('yyyyMMdd-HHmmss')
                    project.properties.setProperty('timestamp', timestamp)
                </source>
            </configuration>
        </execution>
    </executions>
</plugin>


To assembly the package the job is done in two parts: first, the jar must be generated with a manifest declaring the main class to execute and the jar must contain all the dependencies needed to run. Second, the compressed file containing the jar and some shell scripts must be named using a time stamp


<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <executions>
        <execution>
            <id>jar-with-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>org.project.bla.bla.bla.ui.cli.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </execution>

        <execution>
            <id>dist</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <finalName>ProjectXYZ-${project.version}-${timestamp}</finalName>
                <descriptors>
                    <descriptor>src/main/assembly/distributable.xml</descriptor>
                </descriptors>
            </configuration>
        </execution>
    </executions>
</plugin>

Here an assembly descriptor comes to help, we include some shell scripts and specify output format:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>dist</id>
    <includeBaseDirectory>true</includeBaseDirectory>
    <formats>
        <format>tar.bz2</format>
    </formats>
    <fileSets>
        <fileSet>
            <includes>
                <include>**/**jar-with-dependencies.jar</include>
            </includes>
            <outputDirectory>bin</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>${project.basedir}/misc/shellScripts</directory>
            <fileMode>0755</fileMode>
            <lineEnding>lf</lineEnding>
            <includes>
                <include>*</include>
            </includes>
            <outputDirectory>bin</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

Of course, the assembly descriptor must located in the place declared:

















This, you can build packages like this: ProjectXYZ/target/ProjectXYZ-1.0-SNAPSHOT-20110714-221041-dist.tar.bz2

mvn package

The jar would be called like this:

java -jar ProjectXYZ-1.0-SNAPSHOT-jar-with-dependencies.jar

What a ugly name, maybe I need a installer or a shell script as a wrapper:

#!/bin/bash
java -Xms300M -Xmx300M -jar $PROJECTXYZ_HOME/ProjectXYZ-1.0-SNAPSHOT-jar-with-dependencies.jar $*

Ok, I need a installer.

Deploying with maven-antrun-plugin

I really like to use maven in my software projects but sometimes it can be a real pain in the "keyboard".

After trying to deploy a package using the maven-deploy-plugin into a ssh/sftp server without success I changed the tactical for old and very known tool: ant

Well, it just worked!

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <dependencies>
        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant-jsch</artifactId>
            <version>1.6.5</version>
        </dependency>
        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.44</version>
        </dependency>
    </dependencies>               
    <executions>
        <execution>
            <id>upload</id>
            <phase>deploy</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <scp
                        todir="username:password@hostname:/path/destiny"
                        port="22" trust="true" verbose="true"
                        file="${basedir}/target/ProjectXYZ-${project.version}-dist.tar.bz2">
                    </scp>
                </target>
            </configuration>
        </execution>                   
    </executions>
</plugin>  

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <skip>true</skip>
    </configuration>

</plugin> 


The maven-antrun-plugin calls the ant task scp to do the transfer to the remote site and needs the declared dependencies.
The trust attribute allows me to accept unknown machines and avoid the exception if it is the case.
The verbose attribute show some progress (useful when the file is big).

The transference must be done every time I release a version of the project and so I attached it to the deploy phase. As I only need the package I deactivated the maven-deploy-plugin using the skip declaration in the configuration.
The file being transferred was build using the maven-assembly-plugin.

mvn deploy

Good, no more manual sftp.

2011/06/08

ECJ mavenized!

ECJ v20 has finally been mavenized and now lives in the Maven's central repository, enjoy!

<dependency>
        <groupId>edu.gmu.cs</groupId>
        <artifactId>ecj</artifactId>
        <version>20.0</version>
        <type>jar</type>
</dependency>

The project is hosted by The Open Source Project Repository Hosting at Sonatype.