Category Archives: Cryptography

Verifying the signature of linux kernel using gpg

Digital signatures functions as the electronic equivalent of  handwritten signatures. It can be used to authenticate the source of data as well as verify its identity.

Linux kernel releases are signed by the person who makes the release. This signature helps us in verifying whether the files have been tampered by any intruder. The process of signing and verification uses public-key cryptography.

All Linux kernel releases are cryptographically signed by OpenPGP compliant signatures. PGP signatures would be hard to forge since the attacker requires the private key of the developer who made the release. We can verify the integrity of the downloaded version of kernel using GPG.

Step 1:

Fetch the source code and the corresponding signature key from kernel.org.


$ wget https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.5.tar.xz
$ wget https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.5.tar.sign

Uncompress the tar file.

unxz linux-3.1.5.tar.xz

Step 2:

Verify the signature of the downloaded kernel

$ gpg --verify linux-3.1.5.tar.sign

Signature made Friday 09 December 2011 10:46:46 PM IST using RSA key ID 6092693E
gpg: Can't check signature: public key not found

Step 3:

In order to accomplish our task of verifying, we need to get the public key from PGP Keyserver with the help of RSA key ID that we got 6092693E .

$ gpg --recv-keys 6092693E
gpg: requesting key 6092693E from hkp server keys.gnupg.net
gpg: /home/sowcat/.gnupg/trustdb.gpg: trustdb created
gpg: key 6092693E: public key "Greg Kroah-Hartman (Linux kernel stable release signing key) <greg@kroah.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

 Step 4:

Now verify the signature again:

$ gpg --verify linux-3.1.5.tar.sign
gpg: Signature made Friday 09 December 2011 10:46:46 PM IST using RSA key ID 6092693E
gpg: Good signature from "Greg Kroah-Hartman (Linux kernel stable release signing key) <greg@kroah.com>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 647F 2865 4894 E3BD 4571  99BE 38DB BDC8 6092 693E

The signature seems to be a Good Signature! This means that the public key that we got earlier belongs to the person who made the release.
Instead of gpg: Good signature from “Greg Kroah-Hartman, if it was BAD signature, then:
1) It could be because of incomplete download
2) The downloaded file is not truncated
3) The files might be corrupted

Even though our verification says ‘Good signature’, we can see a warning. This because we did not verify whether the key comes from the person ‘Greg’.
One way of checking is by mailing the people in the list of signature ask them to check if the signature can be trusted. We can see the list of signature by entering the command gpg --list-sigs. Another way is checking with the Kernel web of trust.

This seems to be  a long task to verify the authenticity. So, it is better to ignore the warning and trust the signature.

References: http://www.kernel.org/signature.html

Advertisements

Encrypting and decrypting a file with symmetric key

This post explains how to encrypt and decrypt a file using symmetric key. In symmetric algorithms the security depends on the strength of the key as the encryption and decryption key is the same. The strength of the key depends on the key size. Key size is the number of bits in the key. This key has to be agreed by both the sender and receiver before the communication starts. The security of the algorithm depends on the secrecy of the key.

Consider a file ‘secret.txt’ with the following content

Secret key is 98234

Now, we encrypt it with a symmetric key using gpg.

gpg --symmetric secret.txt

This asks for a pass-phrase, which is the key.
The cipher algorithm used here is CAST5. CAST5(or CAST-128) is a block cipher. Block ciphers divides the message into blocks and each block is encrypted at a time. The key used for encrypting each block is the same. CAST5 has a fixed block size of 8 bytes. You can read more about CAST5 here.

Now, the encrypted file ‘secret.txt.gpg’ is created.
The content of secret.txt.gpg is:

<8c>^M^D^C^C^BÊÏñT<96>ÅGc`É1    7NA!áW<95>i^Y<98>s1 -lÐ^\j°ã[;$qs^GsÛ^?^<9d>    /n<99>ÞÜ<87>äâýD,^OM£¸ù

To decrypt, type the following command

gpg --decrypt secret.txt.gpg

This outputs the following

gpg: CAST5 encrypted data
gpg: encrypted with 1 passphrase
Secret key is 98234
gpg: WARNING: message was not integrity protected

Symmetric keys are useful when to protect any files in your own PC.

References: http://www.noah.org/wiki/GPG_notes

Gpg Key-Pair Encryption and Decryption

Using GPG we can generate private and public keys which can be used to encrypt and decrypt files. Here, the private key should be kept confidential. Even if the public key is made available, the message cannot be decrypted.

Consider a person A wants to send a secret message to person B. B’s public key is known to A and A encrypts the message using this. However, this encrypted message can be decrypted only by B since B alone knows the private key.

Let’s see how to generate a key pair and thereby performing encryption and decryption.

Step 1: Key pair generation

$ gpg --gen-key
gpg (GnuPG) 1.4.11; Copyright (C) 2010 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 3000
Requested keysize is 3000 bits
rounded up to 3008 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0) 5
Key expires at Wednesday 23 January 2013 07:01:08 PM IST
Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

Real name: sowmya
Email address: sowmya@gmail.com
Comment: This is my OS assignment
You selected this USER-ID:
"sowmya (This is my OS assignment) <sowmya@gmail.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.

The Passphrase that we provide is our private key.

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
.....+++++
.......+++++
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.

Not enough random bytes available.  Please do some other work to give
the OS a chance to collect more entropy! (Need 171 more bytes)
...+++++

Not enough random bytes available.  Please do some other work to give
the OS a chance to collect more entropy! (Need 63 more bytes)
.+++++
gpg: key 014D1F5E marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: next trustdb check due at 2013-01-23
pub   3008R/014D1F5E 2013-01-18 [expires: 2013-01-23]
      Key fingerprint = 26AE 91CA E577 C4C4 F168  16D5 4A83 6C5D 014D 1F5E
uid                  sowmya (This is my OS assignment) <sowmya@gmail.com>
sub   3008R/D39FA9A6 2013-01-18 [expires: 2013-01-23]

014D1F5E is our public key.

Step 2: Exporting the key

gpg --export sowmya@gmail.com > sowmya-pub.gpg
gpg --armor --export sowmya@gmail.com > sowmya-pub-asc.gpg

Importing other’s public key

gpg --import FileName

Send encrypted message

gpg --recipient 'public_key' --armor --encrypt secret.txt

Decrypt the encrypted message

Consider a file ‘secret.txt’ which is encrypted as secret.txt.asc. To decrypt secret.txt.asc:


$ gpg --decrypt secret.txt.asc > secret.txt

You need a passphrase to unlock the secret key for
user: "sowmya (This is my OS assignment) <sowmya@gmail.com>"
3008-bit RSA key, ID D39FA9A6, created 2013-01-18 (main key ID 014D1F5E)

gpg: encrypted with 3008-bit RSA key, ID D39FA9A6, created 2013-01-18
      "sowmya (This is my OS assignment) <sowmya@gmail.com>"

References: http://linux.101hacks.com/unix/gpg-command-examples/

DareYourMind: MorseCode

 

So this is the Question:

We don’t get any clue with this pic. But analyse it carefully. It contains some morse code.

.– . .-.. -.. -.. — -. . – …. . .–. .- … … .– — .-. -.. .. … … .- — ..- . .-.. — — .-. … .

Then the problem becomes easier. Decode it using http://www.onlineconversion.com/morse_code.htm
And you will get the password 🙂

 

DareYourMind: Md5 crack

Question: http://www.dareyourmind.net/menu.php?page=crypto5

You are provided with a picture and you need to crack the md5 of it.

Well … Just try saving the pic. By default it will be saved with md5 value as the name.
We could try decrypting it using http://www.md5decrypter.co.uk/. This would give you the solution 😀

 

Fermats Factorizing method

This is a really nice algorithm to find out factors of an odd integer, which could be represented as the difference
between two squares. This algorithm works even when n is a large integer.  So, this could be an easy way to determine p and q in RSA decryption when n is sufficiently large.

Method:

Given a number n.
Fermat’s factorization methods look for integers x and y such that n=x^2-y^2. Then it can be represented as

 n=(x-y)(x+y)
(1)

and n is factored.

Every positive odd integer can be represented in the form n=x^2-y^2 by writing n=ab (with a>b) and noting that this gives

a = x+y
(2)
b = x-y.
(3)

Adding and subtracting,

a+b = 2x
(4)
a-b = 2y,
(5)

so solving for x and y gives

x = 1/2(a+b)
(6)
y = 1/2(a-b).
(7)

Therefore,

 x^2-y^2=1/4[(a+b)^2-(a-b)^2]=ab.

Consider an example:

Let, n=15
So, n can be represented as:

n=4^2 – 1^2

n=(4+1)(4-1) = 5*3
a=4+1
b=4-1
a+b=2*4
a-b=2*1
x=4
y=1
x=1/2(a+b) = 4
y=1/2(a-b) = 1
x^2 – y^2 = 16 – 1 = 15 = ab.

source: http://mathworld.wolfram.com/FermatsFactorizationMethod.html

OverTheWire-Krypton:Level 2

Now, ssh krypton2@krypton.labs.overthewire.org
The password is R****N.

Level Info:

Krypton 2

Substitution ciphers are a simple replacement algorithm. In this example of a substitution cipher, we will explore a ‘monoalphebetic’ cipher. Monoalphebetic means, literally, “one alphabet” and you will see why.

This level contains an old form of cipher called a ‘Caesar Cipher’. A Caesar cipher shifts the alphabet by a set number. For example:

plain: a b c d e f g h i j k … cipher: G H I J K L M N O P Q …

In this example, the letter ‘a’ in plaintext is replaced by a ‘G’ in the ciphertext so, for example, the plaintext ‘bad’ becomes ‘HGJ’ in ciphertext.

The password for level 3 is in the file krypton3. It is in 5 letter group ciphertext. It is encrypted with a Caesar Cipher. Without any further information, this cipher text may be difficult to break. You do not have direct access to the key, however you do have access to a program that will encrypt anything you wish to give it using the key. If you think logically, this is completely easy.

One shot can solve it!

Have fun.

Alrite! Question seems to be a bit long. So we need to perform caesar shift to get the password.
The file Krypton3 contains the encrypted password: OMQEMDUEQMEK
Use the code https://sowmyaravidas.wordpress.com/2012/09/15/encryption-code-for-caesar-cipher/ here
with proper indentation to decrypt it. This helps you generate all the possibilities:
PNRFNEVFRNFL
QOSGOFWGSOGM
RPTHPGXHTPHN
SQUIQHYIUQIO
TRVJRIZJVRJP
USWKSJAKWSKQ
VTXLTKBLXTLR
WUYMULCMYUMS
XVZNVMDNZVNT
YWAOWNEOAWOU
ZXBPXOFPBXPV
AYCQYPGQCYQW
BZDRZQHRDZRX
CAESARISEASY
DBFTBSJTFBTZ
ECGUCTKUGCUA
FDHVDULVHDVB
GEIWEVMWIEWC
HFJXFWNXJFXD
IGKYGXOYKGYE
JHLZHYPZLHZF
KIMAIZQAMIAG
LJNBJARBNJBH
MKOCKBSCOKCI
NLPDLCTDPLDJ

You got the password for next level!!