Saturday, October 13, 2012

Email Security

Email encryption and digital signature are ways to protect your emails from spying eyes and to make sure the recipient knows that you are the original sender of the email. Enigmail is an Add-on for the Mozilla Thunderbird mail client that allows you to send securely emails.
The term e-mail is a little misleading. When you send a mail trough the post you write something on a paper and put it into a sealed envelope, so the people handling your mail can't actually see what is inside. Now most people think that the e-mail is similar to this, however in reality its more like a postcard...When going trough the servers, basically anyone who knows how to, can read them. This is where Enigmail and OpenGPG appear and add a layer of security.

Digital signature 

Digital signature is the equivalent of a signature in the computer world. It helps to uniquely identify -in this case- the sender of the email. So if A and B are talking (assuming both of them have the software of course) and A sends an e-mail to B and signs it with his own signature, then B knows for sure that the e-mail came from A and it wasn't altered, the information can be trusted.
Digital signature doesn't prevent others from reading your message on its way, but it cannot be altered and the recipient can be sure that the e-mail comes from the right source. You can also sign e-mails and send to a person who doesn't have the software and they will still be able to read it.

Encryption 

Encryption is encryption. You encrypt the whole message making others unable to read it except for the person you have sent it to. This is considered as secure messaging and the contents of the email remain hidden from spying eyes.
The basics for the encryption used here is the use of encryption keys. So if A and B are e-mailing both of them have a key pair on their system, a private key and a public key.
  • Private key - Must be kept secret and protected from everyone. It is used to decrypt messages sent TO you.
  • Public key - You can share this key with friends and basically anyone. It is used BY OTHERS to send encrypted messages TO YOU.
So for starters A and B have to exchange their public keys, this will identify them and allow to send and receive encrypted e-mails. Here is how it goes briefly:
A takes the public key of B and uses it to encrypt the message and sends it to B. B then receives this message and decrypts it with his own private key. If this private key is secret, only B is able to read the message. Similarly when B replies he encrypts the message with A's public key and A can decrypt it with his own private key.

Step 1. Installing Enigmail for Thunderbird

There are two components to install: Enigmail, the Add-on for Thunderbird and GnuPG encryption software.
Enigmail can be simply downloaded from the Add-on tab of Thunderbird, it is very straightforward, but it uses GnuPG to work so without that it's useless.

  1. Open Mozilla Thunderbird
  2. Go to Tools/Options/Manage Add-Ons
  3. Search for "Enigmail" and download it

(If you can't seem to find it there, download from Mozdev and install, or you can upgrade to the latest Thunderbird version which should be able to find it)

That is Enigmail done.


Step 2. Installing GnuPG

First of all GnuPG depends on the following packages: libgpg-error, libgcrypt, libksba and libassuan.

Now these not installed by default with Ubuntu so if you have not installed them before you will have to do it now. The easiest way to do this is with the synaptic package manager (sudo apt-get install synaptic if you do not have it already). Simply search for each of the above packages and mark them for installation and install them all.

Go to gnupg.org and download GnuPG 2.0 which will come in a .tar.bz2 file. Extract this file and open up a terminal window, cd to the extracted folder and build GnuPG from source as you would do normally:
sudo ./configure
sudo make
sudo make install
If you are still missing a package and error message will warn you at the end of ./congfigure similar to this:
Instructions are straightforward, simply install missing packages and everything will go smoothly. After running make and make install (takes some time) you will get a confirmation of GnuPG installed:

Step 3. Check configuration

First of all Thunderbird and Enigmail need to be set up to use GnuPG, usually it is done by default, but do a manual check. Open Thunderbird and check the new OpenPGP menu point and select Properties and you will be presented the following window
All you have to make sure that the router to gpg is correct (usually it is), however if it is not, specify the correct router in the box below.

DONE.

You can either import you key files from another machine or if this is the first time using Enigmail and OpenGPG then you will need to create a new key pair. This is beyond the installation tutorial, but a step-by-step (quickstart) guide is available on enigmail.net

PirateBox Chat Glitch Fixed

Thanks to conversall2  for spotting a glitch with the chat feature in my new website design.

Due to slightly different design than before, the chat window was embedded into the main page and did not refresh by itself.
This has been fixed by using a simple iframe and chat works normally now.
Please download the fixed design from GitHub

Thanks for spotting & feedback and sorry for this issue.

Sunday, October 7, 2012

Starting lighttpd: (network.c.358) can't bind to port: 80 Address already in use

Recently I had the error message appearing when trying to launch my PB on my Ubuntu machine:
Starting lighttpd: (network.c.358) can't bind to port:  80 Address already in use 

Turns out there are quite a few old forum threads on this topic where the issue comes down to one of 2 things:

  1. Another webserver application is running (like apache)To solve this issue check what is running on port 80 by:
    sudo fuser -v 80/tcp
    And then kill or remove this application.
  2. IPv6 is causing some issues in the lighttpd.conf file
    Open lighttpd.conf file in any text editor and comment the line
    include_shell "/usr/share/lighttpd/use-ipv6.pl"
    with a #, so:
    #include_shell "/usr/share/lighttpd/use-ipv6.pl"
    Although in case of the PirateBox script package, this comes ready and set.

My personal issue was that somehow I had apache2 webserver installed on my system. I do not remember installing it, but now it has been removed and lighttpd is starting/running just fine. So if anyone is having a similar issue, you may want to check out these 2 possible issues.

Thursday, October 4, 2012

How to create, format and mount .img files

Now since I am doing some designs for the PirateBox in the future it will be easier if I would make custom image files that could replace the original one. This would make life easier as there would be no need to mount, backup and change the original image file. 

I am experimenting with some html5 videos in my custom PB design just to see how the server and router handles the "pressure". Also after reading some threads on reddit I am keen to try some browser games on my PB, but these will need a larger container than the default img (20MB). So here is a short note on how to handle these img files.
(Also sorry for the colours, it is just to illustrate parts of the code.)

Creating & formatting img files in Ubuntu


1.   Open terminal and type
dd if=/dev/zero of=file.img bs=1M count=50
This will create a file called "file.img" in your home directory with a size of 50 MB.

What is what?
if=/dev/zero => input file, but since we want an empty container (no input file), we use the "universal" term for "nothing" /dev/zero
of=file.img => output file, file name & location
count=50 => Size of the file in MB

2.   After this image needs to be formatted in some file format (ext4, fat32, ntfs and so on; ext3 for the PirateBox). Now you can either use gparted if you want  some nice GUI or you can use mkfs command:
mkfs ext3 -F file.img
(For a quick and easy way to do this, you can use my script imgKreator from GitHub.)

Mounting the img file


I have tried mounting the PirateBox img file with different software, but that didn't work. So after some help through chat and forums here is the command to mount the img file:

sudo mkdir -p /tmp/mount_tmp/ && sudo mount -o loop,rw,sync piratebox/pbIMG_ws.img /tmp/mount_tmp
What is what?
/tmp/mount_tmp/ => Create the folder where the img will be mounted
piratebox/pbIMG_ws.img => Route to PB image file
/tmp/mount_tmp => Mount location

I personally had issues trying to edit anything in the folder so I am running a mounting script with the second line being:
sudo chmod -R ug+rw /tmp/mount_tmp
Which just gives read+write permission to the folder.(Although this worked for me before, when creating a new file container use sudo chmod 777 otherwise the PB will not recognize the files and although connection to the network can be made, no website will load). After this editing is simple.

To unmount:
sudo unmount piratebox/pbIMG_ws.img

PirateBox: If interested here is a script that will allow you to quickly mount and unmount pbIM_ws.img file that contains the www folder and the UI/html files.

Saturday, September 29, 2012

Another PirateBox UI Design

I took my time and learned a little more about html5 and CSS3 web design and also after reading some comments on reddit for example, I have made yet another UI design for the PirateBox.

Features


  • A cleaner structure than before using html5 and CSS3 design elements
  • 4 pages only: Home, Download, Forum and Mobile, where chat is included on the main page
  • Compatible with Firefox, Chrome, Internet Exlorer plus I have an old Blackberry phone, even on that the layout remained the same and it was displayed just like in my browser
  • Mobile version is available from the menu, however as I said, even my old BlackBerry phone could display the standard site properly. (I could not get my script to work, I will keep on working on that)
  • Dark colour theme (as most people wanted)
  • I have implemented the upload feature in the main page, so no more pop-up (drawback: if someone refreshes the page manually, the upload is interrupted...)
  • Download/Browse opens up in a new browser tab, this does not interrupt the upload or trigger the main page to re-load
  • Site scales with your screen, so it won't case any issues with smaller screens
  • I will publish a slightly different version soon of the same design, which is almost identical, but the chat window is on a different page (more tabs on the top), upload comes still as a pop-up and loads in the background, uninterrupted and some more functions. I am even experimenting with some short html5 video clips on the main page.

Preview


Now initially I wanted to make some screenshots again, but I though it would be nice to put together a short video instead. I have recorded this on my Windows7 machine, because it has a wider screen and it will show and illustrate the features of the site much better than my Ubuntu machine's samaller screen.

Download from GitHub

Again feel free to modify anything on the design, basically any text can be re-written in the html documents (or the logo replaced with your favourite image) as the layout is done by the CSS file. If you don't need the mobile or forum menu elements (if you don't have a forum) simply delete those elements from the nav bar.

Any feedback is more than welcome and I am happy to take some tips of what kind of design YOU want for a PirateBox.

IMPORTANT (Edit)
There was a glitch with the chat as it did not refresh itself. I have fixed this, so please re-download the files from GitHub to apply the changes.
Please check the update of this post: UPDATE

Sunday, September 23, 2012

Updating to PirateBox v0.5.1 on the MR3020

Updating an existing PirateBox to a newer version on the MR3020 is somewhat different than making a clean install. It is very similar, but one must pay attention to some details that can slow down the process.
The version 0.5.1 comes with the lighttpd web sever that allows an easy design of an user interface that is presented to users. The web pages ("UI" in this case) can be simply created using html and CSS and easily uploaded to the PirateBox whereas with previous versions there was only a limited area for changes.

What you will need


Known I guess from the previous installation process, but just for the sake of completeness:
  • MR3020 with previous PB installation (obviously...)
  • 1 x Ethernet cable
  • 1 x USB flash drive for the MR3020 (external HDD etc also fine)
  • Linux based computer
  • Home router with Internet access
Moreover you should know:
  • The IP address of your home router
  • The root password of your MR3020 (this was set when you installed PB for the first time, find it)
Also you will need some knowledge about the "vi" editor, if you have not used it too much before here is a quick guide with the functions you will need:
  • i - Enter edit mode
  • ESC - Exit current mode, e.g. exit edit mode
  • :q! - Quit without saving the changes
  • ZZ - Save changes & quit

Updating


OpenWRT is already installed so those first steps can be ignored here, only the PirateBox package needs to be removed and updated with a new one. Note that you will need Internet connection and hence direct access to your home router for this, off-line installation does not work! (The package downloaded later on is a script package that downloads other packages and configures them, hence Internet access is necessary)

Step 1.


Set a fixed IP address to you PC in the same subnet as your PirateBox, assuming it has the IP 192.168.1.1 set your PC to 192.168.1.xxx
You can set a fixed IP by going to "Edit Connections/Wired/Edit", refer to the image below (I renamed my wired connection to "Cable", this is only personal preference).

 Step 2.


Connect your computer with the ethernet cable to your MR3020 and SSH into your PirateBox on the address 192.168.1.1 (providing you didn't change this after the previous install). In Ubuntu you will need root access to ssh, so

     sudo ssh root@192.168.1.1

After providing your root password and the root password to your router you should now be presented the OpenWRT screen:

 Step 3.


Now edit the network file and check that your settings are OK there. You have to make sure that your MR3020 is on the same subnet as your home router. Now at this point it is likely that your home router will be the dominant, hence check your home router. (Example: if your home router is 192.168.0.1 then you will have to set the MR3020 to 192.168.0.xxx and reboot it for the changes to take effect. "Option gateway" is the home router)
Also an important aspect that if the last 2 DNS entries were removed from the bottom of the file (for most users it has caused redirect errors and hence was often removed) then these need to be put back for the duration of the update. These are necessary to connect to the Internet later on.

     vi /etc/config/network

And make it look similar:
Where 192.168.1.1 is the IP address of the MR3020, 192.168.1.254 is the address of the home router and 8.8.8.8 is a google public DNS.

Step 4.


I assume that if the first time you managed to connect to the Internet and install a previous version of the PB your firewall settings are OK. Again just to make sure it is fine, refer to the image below

     vi /etc/config/firewall


Step 5.


If all these settings are OK disconnect you PC and connect your PB to your home router via ethernet cable. Connect to it through wi-fi and SSH into it just like before.
Firstly PirateBox needs to be stopped and the old image removed, type

     /etc/init.d/piratebox stop
     opkg remove piratebox

Step 6.


Now just to make sure you are connected to the Internet, ping google.com

     ping -c 5 google.com

If you are getting a response it's OK. if not, then you are not reaching the Internet for some reason, in this case go back a few steps and make sure that your settings are OK. (primarily IP subnet and DNS entries in /etc/config/network)

Step 7.

The last step now is to install the new PirateBox image:

     cd /tmp
     wget http://piratebox.aod-rpg.de/piratebox_0.5.1_all.ipk
     opkg install piratebox *

"wget" will download the new PB package and opkg will install it (yes you need the * at the end of the command). Wait until it finishes, reboot when prompted and you are done.

Tuesday, September 18, 2012

Mobile website for PirateBox and more - Plans

Just a quick update on the PirateBox website design and my further plans.
Concerning the idea of having a mobile website to which all mobile phones would be redirected, I think it would be viable and a good idea to have a clear, easy to navigate and fast-loading small website for mobile users (I am aware that my current web design is, well let's say not ideal for mobile browsing). My aims are to have a minimalist, but cool mobile website with all the functions of the standard PirateBox start page.
My first idea was to carry on with the default PB website, but recently I had another much cooler idea for the graphical design.

My plan is the following:

  • Have a main menu with just 4 icons in the middle (or text?) that will lead to further pages with possibly a faded PirateBox logo behind them
  • OR a PirateBox logo on the screen with a drop-down menu from the top
  • Main menu page will only hold these 4 menu points for fast loading and easy of navigation. Also the aim was to avoid the use of complicated elements like iframes just in case if some mobile phones had difficulties with them.
  • 4 mobile websites besides the mobile start page will be: "About", Chat, Browse & Upload
  • As I do not really want to copy any icons from anyone, I will try to "design" some on my own (see how it goes...). Plan B is that I download some from some free websites or databases.
  • Pages will have return buttons to the main menu.
  • I have to put a script to piratebox.lan that will identify mobile browsers and redirect them to the mobile site (This will be a hard nut to crack...) But I am thinking of an index.html which holds the scripts that will differentiate between a mobile device and a web browser at the very first stage.

My plans relating to the upload function:

  • Have a graphical indicator of the upload progress.
  • Multiple uploads at a time OR upload sequences that start after each other (aka you can add 5 files, but they are not uploaded simultaneously)
  • Remove popup style and have it integrated in the website.