Category Archives: Tutorials & Tips

Easy guide to protect your personal information privacy with encryption

Secure Cloud Computing

Political scandals have always been about leaked information. Don’t you wonder why sensitive data has been passed around in clear text on the leaked cables that Wikileaks has been making public, while your latest SpongeBob Blu-ray or DVD disc is encrypted with DRM locks and transactions like your book purchase at Amazon is secured and encrypted by SSL certificates?

Encryption has been overlooked by general public all the time. You only hear about it in “hacker” films or breaking news scandals. Although encryption is commonly associated with hiding secrets, when in fact it’s more about securing information. When you change the mindset you’ll start considering encryption as something more relevant for your everyday digital life.

For example, the cloud storage service Mega has encryption built in, after the lessons learned on the data kidnapping of MegaUpload servers. This is for the protection of both parties, the service providers and yourself, the user. This way, only you can open the files and not even Mega employees can know what is in your storage account. Dropbox, Google Drive and other services don’t provide the same level of security, so basically anyone that has access to those servers can see your personal information.

There are many types of encryption methods. One of them is called GPG (initially PGP but the free software version is known as GPG).

GPG is a two key system, where you hold a private key and a public key. The way it works is that you encrypt a file with someone’s public key and send it. On the receiving end, the other person has a private key, and only with the private key the message can be deciphered.

Public keys can be obtained from the person directly through a file transfer or email attachment prior to encrypted communication. Some people, like me, publish their public keys on their personal web page. The most common method to get a public key is to search it on key servers. Most GPG GUI programs have the option to search, download and upload public keys on key servers.

Encryption jargon

So to get started with protecting our data using encryption, you’ll need to learn the basic concept words:

Encrypt

A blue lock for George

Encryption will protect the contents of the file, image, text or whatever is being encrypted, so that only the owner of the private key can view it.

If you want to protect a file only for your eyes, encrypt it with your own public key.

Decrypt

Lock

This is the process of removing the encryption so that you can view the contents of the protected file. This can only be done if the contents were encrypted with the public key of the person who’s supposed to see the information.

If someone sends you a file that was encrypted with your public key, only you, who has the private key, can decrypt the file.

Sign

Autograph

Sometimes the only layer of protection you need, is to make sure the contents of a file or email were not altered between the time you send it and the time it is received by the other person.

It also works as a way to make sure that a message is coming from you, since you need your private key to sign the file and only you have access to it.

Signing a file or text is a mechanism to know that the contents are intact. This does not hide the message itself, it only adds a signature to the file to ensure that every bit is in place with no modifications.

Verify

Goodbye, Sammy. (With Flickr notes)

This is how you check a file or message’s signature for authenticity and integrity. If the signature doesn’t match, it means that the file has been altered or didn’t came from the right person.

You can sign or encrypt a message or file. Signing doesn’t hide the information but it helps to certify that the information hasn’t been modified by anyone else before reaching you. Encrypting will hide the information so no one can see the message or file’s contents.

Setup

SSL

To setup GPG on your system, you’ll need to generate your public and private keys. Any GNU based system is compatible with GPG (GNU Privacy Guard). Most GNU/Linux distributions are already bundled with the gpg command-line tool. If not, on a Debian-based distribution you can install it with:

sudo aptitude install gpg

Generating your keys

Keys.

After you installed gpg on your system, to create your keys for the first time, all you need to do is open a terminal and type:

gpg --gen-key

This will start a step by step process with some simple questions. When in doubt, use the default options by just pressing Enter. Don’t fear the command line, it’s just text.

When asked for a passphrase, note that GPG is not asking for a pass word, it’s asking for a pass phrase so make sure it is longer than one word and an easy to remember sentence.

Once that is done, you can check your list of keys with

gpg --list-keys

Key search and import

If someone hands you their public key on a file, you’ll need to import it to your keyring to use it:

gpg --import key.asc

The key.asc is the file with the public key.

You can also search for someone’s public key on key servers

gpg --search-keys myfriend@email.com

After the results, the GPG will ask which key you want to import. Select the key from the results list by their number at the beginning.

Basic usage

Security

Encrypt

To encrypt a file, first you need to import the receiver’s public key, then you can use it like this:

gpg --encrypt --recipient myfriend@email.com my_message.txt

This will generate a file my_message.txt.gpg which is the encrypted file you’ll want to send.

Decrpyt

To decrypt a file, the sender must have used your public key. You can use whatever name you want for the output file, in this case “my_message.txt”

gpg --output my_message.txt --decrypt my_message.txt.gpg

Sign

To sign a file you use this command:

gpg --armor --detach-sign myverifiedfile.zip

This will create an additional file called ‘myverifiedfile.zip.asc’ which is the signature to verify the file. Send both files to the receiving end.

Verify

You receive two files: the data file and the signature file. You can verify the signature with this command:

gpg --verify signature_file.asc myverifiedfile.zip

Frontend tools

If you’re on GNU/Linux and using KDE you can install the user interface KGPG

sudo aptitude install kgpg

On Gnome, you can use Seahorse

sudo aptitude install seahorse

For graphical user interface options on Mac OS X and Windows, you can check the GPG website.

These GUI front ends will integrate well with your desktop environments, so you can easily encrypt, decrypt, sign or verify files from the file manger right-click menu options.

GPG and Email

The easiest way I can recommend to use encryption with email, is with Enigmail, an extension for the Mozilla Thunderbird email client. It integrates very well and makes it easy to sign, encrypt, verify and decrypt email messages.

In case you haven’t generated any keys, Enigmail will help you generate them with an easy step by step graphical Wizard.

locks

I hope this guide helps you know more about encryption and how to use it. And remember: Encryption is not only about hiding secrets; It’s about protecting your personal information.

Using Git with Subversion repository subdirectory

Git logo

Interacting a local git repository with a subversion one has been very useful and is very common on old projects. The way to do that is by using the git svn commands. But sometimes there are situations where there is one large repository with several projects as subfolders in that repo.

Using the standard svn cloning command:

git clone my_svn_repo_server.com/repository

Will checkout the whole SVN repository (all subfolders, hence, all projects) into your local machine. This can be very large if the codebase and history is big, and very slow to interact with, since getting your local repository updated will involve getting changes from all other projects.

To make git clone a subdirectory from an SVN repository, use the following:

git svn init http://my_svn_server.com/repository/path/to/directory/of/project
git svn fetch

This way you not only clone that subdirectory, but also you will get updates from only that folder, making faster code pulls and pushes to the central SVN repository.

While I consider a very bad practice to have one large Subversion repository with several projects inside it as subfolders, I’ve come across such setups several times and it drove me crazy to have to checkout the whole thing. Hope this helps out.

darkylogo

Upgrading Samsung Galaxy S from Telcel to Darky’s Rom v10.1 with Android Gingerbread

This upgrade took my whole Saturday so this post might save you a lot of time searching through forums to get the Darky ROM 10.1 on the Samsung Galaxy S. My phone came originally with a ripped off version of Samsung’s official 2.1 Eclair Android release, since Telcel, the main carrier in Mexico, removed all the google apps and replaced them with Yahoo! and Bing alternatives. So I’ve been using Darky Rom which is based on the 2.2.1 Froyo release. Now that Darky has recently released its 10.1 version, based on the 2.3 Android release, Gingerbread, I wanted to give it a try and do my upgrade.

So to install this version of Darky ROM, you need to have Ficeto’s JVH base ROM installed first. If you already have that, you can then follow the simple step by step guide. If not, like me, you’ll need to flash Ficeto’s JVH using Odin (MS Windows only) or Heimdall.

In the case of my phone, turns out that my carrier Telcel has modified the Sbl.bin file (secondary boot loader) and I cannot install this as easily since Odin will stop flashing at Sbl.bin and will not continue any progress. If this is your case, the way I solved it was using Darky’s ROM Resurrection edition. Flash it using Odin or Heimdall, then flash Ficeto’s JVH base ROM, finally follow the step by step guide to install Darky’s ROM 10.1 using ClockworkMod’s Rom Manager or the Darky ROM Configurator app.

Another tip: Even the guide says you don’t need to wipe the cache or data, I always find it better to do so. When I don’t, I get either lots of apps crashing upon booting the phone, or I can’t make any calls; they get cut off (hang up) before I get the first ring. So backup your apps and data with apps like Titanum Backup and do a wipe of both data and cache. Also remember to do wipe battery stats and flash the new rom with a full charge for better battery life.

Chromium Logo

Change your default browser to Chromium in Debian and Emacs

Chromium Logo

The web browser is nowadays the most important and frequently used tool in a computer. Recently I’ve been using more the Chromium browser than Firefox, on in Debian’s case, Iceweasel. This is for several reasons:

  • Better memory management (doesn’t eat up all my RAM)
  • Extensions are also available for Chromium
  • Faster browser startup
  • Faster page loads
  • Full HTML5 support, which is lacking in Debian Wheezy’s Firefox (err… Iceweasel) which is still on version 3.5.19 at the time of this writing.

So I decided to change my default browser to open in Chromium for all applications. To do the change, at the terminal, type:

sudo update-alternatives --set x-www-browser /usr/bin/chromium

and

sudo update-alternatives --set www-browser /usr/bin/chromium

If you’re using KDE 4 you also need to open the System Settings, click on Default Applications, Select Web Browser and choose the second radio button option so it reads: “Open http and https URLs in the following browser” and type “chromium” in the text box. Click the Apply button and close the window.

Since I do almost everything with Emacs, I also needed to configure it to use Chromium as its default browser. To set that, you just need to add the following to your .emacs file:

(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "chromium-browser")

I still love Firefox, but it has staled away from the cool minimalistic and fast browser it was when it started. Chromium is now filling that gap, so I hope that in future versions (maybe the new Firefox 5?) memory handling gets better as well as loading times.

Post to WordPress blogs with Emacs & Org-mode

Recently I’ve discovered Org2blog, an Emacs mode to write your blog posts locally using org-mode post them to your WordPress blog in a very fast and easy way.

I’ve written before on how to write your blog posts and publish them using Emacs. Previously, my method of choice was using Weblogger mode. I even wrote some enhancements to it.

The problem I found with this method is that it uses message-mode as its base mode. So you’re basically writing an email. The shortcomings of it were that whenever I wanted to write links, bold text, or any custom formatting generally done through HTML tags, I had to either type out the HTML or temporarily switch to html-mode. That sometimes gave me some problems converting the HTML code into entities, and ended up with a mess to fix at the WordPress editing textarea.

Org-mode (included in Emacs since about version 22.1), if you haven’t heard about it already, is a very good way to take notes, organize your tasks, among other day to day useful things. You also get some basic formatting like bold text and italics, as well as links among many other useful things. Nowadays, I find myself typing things in org files constantly throughout my day, and with all its long list of qualities, it became a more suitable way for me to write blog posts.

Org2blog provides a way to post your Org files or post a subsection of your file with a few keystrokes. All you need to do is clone the repository on your load path directory

git clone http://github.com/punchagan/org2blog.git

Then, add this to your .emacs file

  (setq load-path (cons "~/.emacs.d/org2blog/" load-path))
  (require 'org2blog-autoloads)

Finally set up you blog(s) settings in you .emacs file

     (setq org2blog/wp-blog-alist
           '(("wordpress"
              :url "http://username.wordpress.com/xmlrpc.php"
              :username "username"
:default-title "Hello World" :default-categories ("org2blog" "emacs") :tags-as-categories nil) ("my-blog"
:url "http://username.server.com/xmlrpc.php" :username "admin")))

To start wrigint a new post, you can now use M-x org2blog/wp-new-entry

Or, as I more frequently use, post a subtree of an existing org file using: M-x org2blog/wp-post-subtree

I hope you enjoy writing and posting your blog posts within Emacs and Org-mode. I certainly do and has turned out to be a very fast way to quickly draft and later on (even offline) elaborate on the blog post details in a comfortable editing environment. Also you get the added benefit of having a local copy (backup) of your blog posts as Org files.

Restore Samsung Galaxy S to Original ROM from Telcel Mexico

Flash Samsung Galaxy S with Odin

Two weeks ago, I messed up my Galaxy S phone. I was having trouble with the back key activating by itself without touching it. As I’ve said before, I use Darky’s ROM instead of the crappy Samsung/Telcel default one. So searching for a possible solution, I found out that you could update your touchkeys firmware.

Well, I went ahead and updated it. To my surprise, it completely disabled my touch keys (the back and menu buttons). So, if you have the same problem with you back button key, DO NOT upgrade your firmware if you’re using a custom or unofficial ROM…or keep reading… Now my problem was worse than before! I then searched for a solution on that, and the only answer was: return to the default ROM and upgrade the touchkeys again, then revert back to your custom ROM.

That’s when my long journey began. Back when I changed to Darky’s ROM, I used Clockwork Recovery to do so. And of course, I made a backup of my current ROM. Turns out that, to restore from a backup, you need to be on the original ROM (or the ROM that backup has). And well, I had no other place to get that, since I thought my backup would solve it all. So I ended up spending almost all saturday looking for the original Samsung Galaxy S ROM from Telcel Mexico, until I finally found it!

To flash your Android device, you’ll need a program called Odin which is a leaked Samsung application that unfortunately runs only on Windows machines. There’s an open source, cross platform flashing software called Heimdall, but I couldn’t get it to work correctly, there’s not much documentation, so I couldn’t figure out my problem. I hope that project grows and evolves into a more stable alternative to Odin. So, I had to borrow a Windows XP netbook from a co-worker for a day so I could use the Odin software to Flash my phone.

I wanted to share my finding with some friends who have asked me about the same problem. So follow this forum post if you need to revert back to the original ROM, or recover your phone from a backup and you have a Galaxy S from Telcel. The post makes reference to this unofficial guide to upgrade to Froyo in case you loose your 850Mhz band.

I hope this solves your problems and helps you save all the time I had to invest to get to this solution. Changing the original ROM on your Android device is a risky move, but I find it worth it.

Photo is Creative Commons by fraencko on Flickr.

Quick search and replace recursively in multiple files

Lately I’ve been working with a lot of static HTML files with lots of repeating text structures. In the past I’ve talked about editing multiple files with Emacs. This approach works very well when the number of multiple files and text matches in each file is manageable, since you need to confirm pressing “y” on every text match in each file.

On other cases, like the one I had to solve, you can have 84,000 text files where each file can have more than 5 matches. This case, doing it with Emacs wouldn’t reduce much time. So to do a quick search and replace recursively in multiple files, another “old” tool comes very handy.

GNU Sed

Quoting from the GNU Sed project page, sed is:

Sed (streams editor) isn’t really a true text editor or text processor. Instead, it is used to filter text, i.e., it takes text input and performs some operation (or set of operations) on it and outputs the modified text. Sed is typically used for extracting part of a file using pattern matching or substituting multiple occurrences of a string within a file.

The way to tell sed to do a search and replace on some given text, the syntax is the following: sed -n -e 's/regex/text/g' filename

The -n switch makes Sed not to output its results to the standard output and overwrite the file with the results. The -e switch specifies that the following string is a command to perform on the file. The regex part is the regular expression to use for searching in your text. The text part is the text you want to replace your search with.

So Sed recieves streams of text as input, makes some operations on it and outputs the results. This way of seeing it, makes it very obvious to understand that the natural way to use it is through bash calls using pipes.

The find tool will help us get a list of all the files that we need to pipe into sed. In the same way we used find from within Emacs, we can call it from bash: find path/to/folder -iname "filenamepattern"

So a combination of find with sed can be used in the following way: find myprojectfolder -iname "*.html" | sed -n -e 's/searchregex/replacementtext/g'

As easy as that, and you have edited 84,000 files with one single line of bash.

Hope its useful for anyone. It has been very useful to me. If you have other methods or other sed tips, I’d like to know in the comments.