encryption

PGP Cryptography With The Legion of the Bouncy Castle – Part 5

Posted on

We’re back! Back to PGP Cryptography tutorials!! Because when I want to learn something new I learn faster by writing a tutorial about it, sharing code and receiving feedback.

So in Part 4 I apologized that I did not have a lot of time and just showed how to integrate Bouncy Castle with Android by using SpongyCastle. Now I will go through how to generate and verify detached signatures. This has become important since Part 2 did teach how to sign and verify files, but the signature was embedded inside the file. Though this works, it did not work when trying to verify the file using a regular program like GPG / Kleopatra. Also not all PGP clients support ZLIB compression which could break compatibility. So I decided that the need to generate detached signatures was important.

Continuing with the previous examples we have the PGPTools file which I wrote to make cryptography easier with BC (Full source can be found here). Generating a detached signature file needs the following:

  • The file you want to sign
  • The name of signature file that will be generated
  • The PGP Key ring that contains your secret and public keys

Another interesting thing to know to go by is the naming convention of these files. Most programs look for it and makes it easier for the user to utilize and for programs to find. Supposed there is a file called “TheFile.txt”, below is how the signature file would be named:

  • ASCII Armored Signature: TheFile.txt.asc
  • Binary Signature: TheFile.txt.sig

This is not mandatory, but a nice convention to follow.

Read the rest of this entry »

WhatsApp ? WhatsCryptography? WhatsEncryption? Answer is: I don’t know

Posted on

And it happens again to WhatsApp, being further embarrassed by researchers showing that they do not know how to implement encryption correctly. Recently Help-Net Security published an article about a Dutch Computer Science and Mathematics student (Thijs Alkemade) at Utrecht University has discovered how WhatsApp encrypts and authenticats its messages.

we know that not only does WhatsApp use the same (RC4) encryption key for the messages in both directions, but also the same HMAC key to authenticate messages.

The main problem being:

“But a MAC by itself is not enough to detect all forms of tampering: an attacker could drop specific messages, swap them or even transmit them back to the sender,”

But also points out that there is a simple solution which is using TLS. So in conclusion

  • All WhatsApp users are still not safe
  • Your messages can be sniffed out
  • Your message can be decrypted
  • Your only protection is to stop using WhatsApp
  • Wait for WhatsApp to learn how Encryption works so they can implement it correctly

I’ll end this post with a quote from Thijs Alkemade:

“solution that has been reviewed, updated and fixed for more than 15 years, like TLS.”

PGP Cryptography With The Legion of the Bouncy Castle – Part 4

Posted on

Before starting I would like to thank all the people who have viewed my posts on using Bouncy Castle. I have been monitoring the hits on my blog and I’ve noticed that my series on encryption with Bouncy Castle has been getting a lot of attention. I did promise to make Part 4 about encrypting and signing a single file all in one, but from lack of time I do not think it will make it to Part 4.

One of the main reasons is that Bouncy Castle is largely undocumented and what little documentation there exists on the net is not enough. The way I have created my posts where by reading the unit test cases from the Bouncy Castle source package and doing some trial and error and testing with PGP Desktop and GPG. So there isn’t enough time for me to continue to do that. So for Part 4 I have decided to show how we add Bouncy Castle support to Android!

Read the rest of this entry »

PGP Cryptography With The Legion of the Bouncy Castle – Part 3

Posted on Updated on

Continuing my 5 part series on using the Bouncy Castle API to create your own Java library to manage Private / Public key pairs. Part 2 went over digitally signing and verifying messages using the generated key pair from Part 1. Also, just a note, the signature generation from Part 2 are not detached signatures, they’re embedded within the information. I’ll talk about why I prefer to do this when we get to Part 4.

Encryption is done using the recipients public key and does not require us to enter a pass phrase. When the recipient receives the encrypted message they will need to enter their pass phrase in order to decrypt the message. This is mainly so because their public key is protected by password based symmetric encryption inside the key ring.

Below we add the encrypt and decrypt methods to our PGPCryptoTools source file.

Read the rest of this entry »

PGP Cryptography With The Legion of the Bouncy Castle – Part 1

Posted on Updated on

Some of my favorite things to do in software engineering is use libraries with cool names. Nothing beats The Legion of the Bouncy Castle. I like that name so much that I decided to just start using it! Well actually I really needed to use PGP cryptography in one of my projects and though it would be nice to blog about it, but yeah cool name though.

So one of the tricky issues with using Bouncy Castle (we seriously do it a disservice by shortening its amazing name to just 2 words) is the lack of proper, complete and friendly documentation. You may find many articles on the net or tutorials, but I found them way too complex and some just didn’t know what they were doing.

The best option was to look at the Bouncy Castle source code and go directly to their examples package. There they give some pretty good examples and enough to build your own tools for their API. In this part of my series I will go over generating a full fledged DSA/El Gamal PGP Key Ring that is importable into PGP.

Read the rest of this entry »

XOR is NOT Cryptography

Posted on Updated on

During my many years of developing software, working with opensource projects and using GNU/Linux systems you tend to do something odd. Yes, at times you tend to do something that causes your eyes to skim through letters and words dedicated to educating you about a subject. Well I’ll be damned, they call this “reading documentation” 🙂

So yes, I assume many other developers spend as much time as I do, or anyone else, doing expected things like reading Linux MAN pages, manuals and all sorts of technical docs to gain a better understanding of a topic at hand.

Then what happens, you find the most retarded practice ever being used by some of the largest and most trusted software companies in the world. During my work I have encountered a financial software that was purchased (company names shall not be mentioned) that was written in Java. Being curious about how these things work I browsed the files and found a file named PasswordCryptography.class … Yeah, that’s what I’m talking about. Lets take a look.

So we whip up JAD and decompile that class file. I was expecting to see amazing algorithms being used or maybe some sort of custom crypto methods … you know, things like that. What did I see…

  • AES256 ? …… no
  • Blowfish ? ….. no
  • TripleDES ? ….. no
  • Not even regular DES ?? …. nope

What did I see? I saw XOR OBFUSCATION of passwords using a key that was embedded right into the java class file. At this point I was ready to jump out any window given it was open and large enough.

This is their idea of “cryptography”

for(int i = 0; i < aa.length; i++)
{
    int k = aa[i] ^ key[j];
    int l = (k & 0xf) << 4;
    int i1 = (k & 0xf0) >> 4;
    aa1[i] = l | i1;
    if(j < key.length - 1)
         j++;
    else
         j = 0;
}

WTF? And here’s the part that really kills me. Why call it “PasswordCryptography” ?? I would have been perfectly fine if the file was called “InsecurePasswordXorObfuscation” … ok ok too harsh, how about “PasswordObfuscation” Of course, you know the programmer must have spent a lot of time coding, testing, coding and re-testing this that it was sooooo hard it had to have been cryptography! And thus decides to name the class “PasswordCryptography” and then this somehow passes all engineering stages, peer review, unit tests …etc and ends up being a part of one of the largest financial software solutions in the world and your password is protected by cryptography XOR obfuscation. Anyone after reading Encryption Matters will know how to reverse the obfuscation.

Even when I was a beginner it took no less than 1 hour to google “password encryption” and figure out that I could just download a jar file, import it and make a 1 line function call to encrypt a password using REAL encryption.