GPG Quick Guide

I have many friends who are having a few Issues getting the grips of GPG and public key encryption so I decided to make a quick post to cover the basics.

Firstly a video to explain the concept of public key encryption

diffie-hellman key exchange

A good way to learn is the command line as It requires no front end software and is installed on nearly every linux system by default . The command line? No, it’s not hard as long as you have a basic understanding of how asymmetric cryptography works (i.e. you’ve at least read the wikipedia page), and are comfortable on the command line in the first place. It’s even easier with a helper program like Kgpg or GnuPG. Here are some helpful hints if you want to give the command line version a shot (note this is for linux):

Windows users can check out http://gpg4win.org/

#to create a new key
gpg –gen-key

#to encrypt a message
gpg –recipient recipient –armor –encrypt file

#to decrypt a message
gpg –decrypt file

#to export public key (ascii)
gpg –armor –export name

#to export public key (ascii) to file
gpg –armor –output file –export name

#list public keys
gpg –list-keys

#import a public key
gpg –import file

A good guide can be found in the Ubuntu community documentation

https://help.ubuntu.com/community/GnuPrivacyGuardHowto

Advertisements

HashPass Desktop

In my previous post I introduced the android app HashPass which I made and briefly discussed that there was a command line version available for the desktop. This post is a follow up explaining the modes of operation of the command line version.

Basically it was made to supplement the android app. It has two modes of operation and they are as follows:

method 1: The text is specified inline

python hashPass.py algorithm text_to_be_hashed

tpa@tortoise:~$ python hashPass.py md5 test
098f6bcd4621d373cade4e832627b4f6
tpa@tortoise:~$

method 2: The text is specified at runtime

python hashPass.py algorithm

tpa@tortoise:~$ python hashPass.py md5
Enter the text to be hashed and press enter.
test
098f6bcd4621d373cade4e832627b4f6
tpa@tortoise:~$

The reason there are two methods is that if you normally use the first one listed above the text or password in this case would be saved in your shell history file so the second one is the recommended and safer method to use. The first method is there is case users wishes to hash any text but was mainly added so it can be run inside other scripts . Lets say you wish to hash a lot of passwords and you want to save the output to some file. Assuming pass is the password you wanted to hash, you would save the following to a file

#!/usr/bin/env bash

#sample script to demonstrate the first method of hashPass

printf “pass for site 1: ” ; python ~/bin/hashPass.py md5 pass
printf “pass for site 2: ” ; python ~/bin/hashPass.py sha1 pass
printf “pass for site 3: ” ; python ~/bin/hashPass.py sha256 pass
printf “pass for site 4: ” ; python ~/bin/hashPass.py sha512 pass

Then change the permissions of the file with chmod u+x filename.sh

The output produces

pass for site 1: 1a1dc91c907325c69271ddf0c944bc72
pass for site 2: 9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684
pass for site 3: d74ff0ee8da3b9806b18c877dbf29bbde50b5bd8e4dad7a3a725000feb82e8f1
pass for site 4: 5b722b307fce6c944905d132691d5e4a2214b7fe92b738920eb3fce3a90420a19511c3010a0e7712b
054daef5b57bad59ecbd93b3280f210578f547f4aed4d25

The algorithms are the same one available in the android application. MD5 , SHA1, SHA256 & SHA512.

Installation

Windows

Download and install python from http://www.python.org/download

I tested it with python 2.7 on windows xp

Once installed open up a command prompt.

You then add python to the PATH with

PATH C:\Python27;%PATH%

If you run into trouble in this step see http://docs.python.org/faq/windows#how-do-i-run-a-python-program-under-windows . This way only temporarily adds python to the path

To keep the path in memory right click my computer > properties > advanced > environment Variables and then add ;C:\Python27 on to the PATH variable
like so

MyComputer Properties

MyComputer Properties

Environment Variables

Environment Variables

Add Python to Path

Add Python to Path

Now you can navigate to the directory where the script is with cd. For this example we will assume it is on the desktop

example cd Desktop

Now to run the script we can use the same methods listed above, using the second method we get the same result

python hashPass.py md5
Enter the text to be hashed and press enter.
test
098f6bcd4621d373cade4e832627b4f6

— Linux/unix

Linux users should have python and hashlib installed if no they will be in your distro’s repository.

—  Mac OSX

Like linux python should be installed by default in mac. Instructions are the same to run it in mac as they are in linux.

Hope you find the Hash Pass mobile and desktop versions useful.

Dropbox Daemon Management for KDE

Dropbox in KDE does not offer the same level of integration with the file manager, dolphin, as it does with its gnome equivalent so I installed it and settled on choosing the dropbox daemon whenever I required to run dropbox as opposed to running it every time on startup. This gradually became a pain so I wrote a handy script that can start or stop dropbox easily. I placed this in a binary directory in my home directory.

~/bin

you can make with
mkdir ~/bin

In debian , this is automatically added to to the path via an if clause in the ~/.profile file like so.

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

If for some reason it is different for your distribution you can just add the directory to your path by adding the above if statement to you ~/.profile or adding

export PATH=$PATH:~/bin

at the end of the ~/.profile file.

once done you can reload your .profile by typing


source ~/.bash_profile

Alternatively, if you like saving keystrokes you can type . ~/.bash_profile

Now save the code below to a file called dropbox in the ~/bin directory.
Change the permissions to make it executable
chmod u+x ~/bin/dropbox

now on a terminal you can type dropbox to start the daemon or the stop the daemon. Optionally you could add it to a gui menu.

#!/bin/sh
#script to start or stop the dropbox daemon
#Usage: simply type dropbox to start or stop the dropbox daemon

#check if daemon is already running
procs=`ps aux | grep -i "dropbox-dist" |grep -v grep | wc -l`

if [ "$procs" -eq "1" ];

then
echo "Stopping dropbox daemon"

killall dropbox

echo "daemon stopped"

exit

else

echo "Starting Dropbox Daemon . . "

~/.dropbox-dist/dropboxd &

echo "Running . ."

exit
fi

Preparing Debian Squeeze for Android development

Today I am going to discuss how to set up the Eclipse IDE with the Android SDK  for Android development on Debian squeeze.

To begin make sure you have the Java Development Kit  installed. I usually use sun’s Java but apparently openjdk works just as well although its not officially supported for android development. There are a few steps to go through but the commands  below will make it quick.

Step 1: Install Java

To install suns Java make sure you have edited your sources list to include the non-free repository . In order  to do this open a terminal  login as root . I will use “as root” to denote where root is required. To login as root use

su

then enter your root password.

To return to normal user mode type exit

To begin

nano  /etc/apt/sources.list  as root

add non-free beside main in your main source line

deb http://http.us.debian.org/debian stable main contrib non-free

save the file and do an apt-get update as root

now do  apt-get install sun-java6-jdk as root

choose yes to install and accept the agreement

Java should now be installed you can test by running javac in a terminal.

Step 2: Install Eclipse

Next , we must download eclipse from http://www.eclipse.org/downloads/

I use the classic version but any will do . For this tutorial I will be using the helios build for 64 bit architectures but its the same instructions for 32 bit ones.

download the build for you architecture and extract it when done using.

tar -xf eclipse-SDK-6.2-linux-gtk-x86_64.tar.gz

then move it to the /opt directory with the following command

mv ~/eclipse /opt as root

Step 3: Download the Android SDK

Next download the Android SDK from http://developer.android.com/sdk/index.html

once downloaded extract in the same way as we did with eclipse

tar -xf android-sdk_r11-linux_x86.tgz

then move it to the /opt directory  like so

mv android-sdk-linux_x86/ /opt as root

you should now have both the Android SDK and Eclipse in the opt directory now

the next step is to add the android developer toolkit to eclipse

Step 4: ADT Plugin

Start Eclipse, ( /opt/eclipse/eclipse) then select Help > Install New Software….
Click Add, in the top-right corner.
In the Add Repository dialog that appears, enter “ADT Plugin” for the Name and the following URL for the Location:

https://dl-ssl.google.com/android/eclipse/

Add ADT Repository

Click OK. Note: If you have trouble acquiring the plugin, try using “http” in the Location URL, instead of “https” (https is preferred for security reasons).
In the Available Software dialog, select the checkbox next to Developer Tools and click Next. In the next window, you’ll see a list of the tools to be downloaded. Click Next. Read and accept the license agreements, then click Finish.Note: If you get a security warning saying that the authenticity or validity of the software can’t be established, click OK. When the installation completes, restart Eclipse.

Next in a terminal type

/opt/android-sdk-linux_x86/tools/android

This will bring up the AVD and SDK manager  go to the available Packages in the side bar and select the API versions you wish. I usually select all of them to test against different revisions of the API. Proceed to install the selected packages  which can take a long time depending on how many you have selected and you connection speed.

Step 5: Set up a virtual device

Once that’s completed we need to make a virtual device to develop our programs on.

In Eclipse go to Window>Android SDK and AVD Manager and select new , fill out the details as required and click create.

Android Virtual Device

NOTE: it’s a good idea to make several AVD’s against the various API’s so you can thoroughly test your device.

You can now create a new android project by opening eclipse and selecting File>New>Other>Android>Android Project

(Optional )Step 6: Setting up a physical device

All credit for this section goes to unforgivin512

Source: http://unforgivendevelopment.com/2011/05/20/udev-headaches-on-debian-testing-wheezy/

On the android developers website the guide for setting up a device under Ubuntu says to create the file “/etc/udev/rules.d/51-android.rules” , this does not work in the case of Debian. What you have to do in this case is

nano /lib/udev/rules.d/91-permissions.rules as root

Find the text similar to this

# usbfs-like devices SUBSYSTEM==”usb”, ENV{DEVTYPE}==”usb_device”, \ MODE=”0664″

Then change the mode to 0666 like below

# usbfs-like devices SUBSYSTEM==”usb”, ENV{DEVTYPE}==”usb_device”, \ MODE=”0666

This allows adb to work, however we still need to set up the device so it can be recognized. We need to create the file

nano /etc/udev/rules.d/99-android.rules as root

and enter

SUBSYSTEM==”usb”, ENV{DEVTYPE}==”usb_device”, ATTRS{idVendor}==”0bb4″, MODE=”0666″

NOTE: “0bb4” in this case is your vendors model (HTC in my case).

A full listing can be found here http://developer.android.com/guide/developing/device.html

Save the file and then restart udev as root /super user

/etc/init.d/udev restart as root

Connect the phone via USB and it should be detected when you compile and run a project.

That concludes this tutorial for today.

Fix Android Console Error: requires .class compatibility error

I recently ran into this error when migrating between versions of eclipse (due to a reinstall ), specifically from helios to indigo builds. The problem occurs due to the project being compiled against a particular Java version specified in the eclipse settings. Then when using a newer version of eclipse one will get a . class compatibility error complaining .

The error message states to select “fix project in android tools” (access by right clicking on the project folder). This did not work for me however.

I checked the Java bytecode format in “Window/Preferences”, “Java/Compiler/Compiler Compliance Level” to make sure version 1.6 was set (the version I was building against). This also did not solve the problem.

I eventually solved the problem by rebuilding the project