Showing posts with label Security. Show all posts
Showing posts with label Security. Show all posts

Understanding oAuth2

Very nice Article :


http://www.bubblecode.net/en/2016/01/22/understanding-oauth2/


Whatsapp Ground Breaking End to End Encryption - A Paradigm Shift in Digital Security

Whatsapp Introduced new end to end Encryption to its 1 billion users which brought a paradigm shift towards security and privacy in communication. This is kind of state of art ground breaking technology which ensures both channel and message are completely encrypted and  tamper proof using strongest encryption methodology available today. Before we dig into what is the key technology enabler in Whatsapp Security Model, lets understand how whatsapp communication worked so far.

Whatsapp use a customized version XMPP - eXtensible Messaging and Presence Protocol. It is a slightly modified version of XMPP; So WhatsApp server has got ability to listens in on your chat and analyses it for marketing/advertising purposes. And it was really easy to hack system if eavesdropper can decode the customized XMPP protocol.

Hacker
However with new this new end to end Encryption technology, its now impossible hack and tamper the communication between whatsapp chat users.



Now lets understand how this whatsapp ground breaking security model is working. It is a two step process.

1. Established a secured session between two users in two Whatsapp device. Once this secured session is established, it will use same secured for all future chat among those users unless user change the device or uninstall the software.

2. Once a secured session established every messages will be end to end encrypted using a unique different private key which can not be used to decrypt any old or future message. This is called "Rachet" forward. This second step is key differentiation to make this encryption model unique. This will make sure even Whatsapp server will not have ability to read the message in their network as it has only public key and does not have the required private key to decrypt it.

Lets see how in technically an encrypted message is transmit using secured session over customized XMPP protocol:

1. The WhatsApp user sending a message (“sender”) generates an ephemeral 32 byte AES256 key, and an ephemeral 32 byte HMACSHA256 key.

2. The sender encrypts the attachment with the AES256 key in CBC mode with a random IV, then appends a MAC of the ciphertext using HMAC-SHA256.

3. The sender uploads the encrypted attachment to a blob store.

4. The sender transmits a normal encrypted message to the recipient that contains the encryption key, the HMAC key, a SHA256 hash of the encrypted blob, and a pointer to the blob in the blob store.

5. The recipient decrypts the message, retrieves the encrypted blob from the blob store, verifies the SHA256 hash of it, verifies the MAC, and decrypts the plaintext

Please refer here for more details.

The whole encryption technology has been implemented using signal library protocol called Open Whisper System. The core implementation is done using a open source Java Library. Here is maven dependency and code snippet:

Maven Dependency

<dependency>
  <groupId>org.whispersystems</groupId>
  <artifactId>signal-protocol-java</artifactId>
  <version>(latest version number)</version>
</dependency>
Code Implementation

During App Installation:

IdentityKeyPair    identityKeyPair = KeyHelper.generateIdentityKeyPair();
int                registrationId  = KeyHelper.generateRegistrationId();
List<PreKeyRecord> preKeys         = KeyHelper.generatePreKeys(startId, 100);
SignedPreKeyRecord signedPreKey    = KeyHelper.generateSignedPreKey(identityKeyPair, 5);

// Store identityKeyPair somewhere durable and safe.
// Store registrationId somewhere durable and safe.

// Store preKeys in PreKeyStore.
// Store signed prekey in SignedPreKeyStore.
During Secured Session Establishment and Messaging:

SessionStore      sessionStore      = new MySessionStore();
PreKeyStore       preKeyStore       = new MyPreKeyStore();
SignedPreKeyStore signedPreKeyStore = new MySignedPreKeyStore();
IdentityKeyStore  identityStore     = new MyIdentityKeyStore();

// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
                                                   identityStore, recipientId, deviceId);

// Build a session with a PreKey retrieved from the server.
sessionBuilder.process(retrievedPreKey);

SessionCipher     sessionCipher = new SessionCipher(sessionStore, recipientId, deviceId);
CiphertextMessage message      = sessionCipher.encrypt("Hello world!".getBytes("UTF-8"));

deliver(message.serialize());
The library is available in gitbub here.

So Java rocks here too.

This article belongs to part 3 of series on how modern day cryptography works.

Encryption Basics & Quantum Computer Part -2

In part 1 of this series discussed fundamentals of Cryptography in classical computing. In part 2 we will focus on real world case studies which relied on Classical Computing Cryptography. There are many. However one of my recent favorite is Crypto Currencies or Digital Currencies used in Technology like Block-chain.

Digital or Crypto Currency at its fundamental use Hashing Technique to ensure the integrity and Security of the Data. Now before we dig into specific Hash function or algorithm used in this use case, lets understand what actually Hashing is all about and how an  Hash key can be used to validate an Input Data. There is excellent explanation below:



Currently most reliable Hashing function available is SHA-256 . The SHA (Secure Hash Algorithm) is one of a number of cryptographic hash functions. A cryptographic hash is like a signature for a text or a data file. SHA-256 algorithm generates an almost-unique, fixed size 256-bit (32-byte) hash. Hash is a one way function – it cannot be decrypted back. This makes it suitable for password validation, challenge hash authentication, anti-tamper, digital signatures.

SHA-256 is one of the successor hash functions to SHA-1, and is one of the strongest hash functions available.


Please refer this online SHA-256 calculator for further experiment. If you love Java like me you can experiment the same using one my favorite Java Guava library from Google as below:

final String hashed = Hashing.sha256()
        .hashString("your input", StandardCharsets.UTF_8)
        .toString();
Now the question is why is so reliable!!! Why can't hacker crack it using classical computer!!!

The answer is SHA-256 has a time complexity of 2^256 to crack normally. It would take centuries using classical computer of such changes before cracking SHA would be feasible.

SHA-256 is used in Cryptocurrency like Bitcoin or Blockchain's one of the critical step called mining. Please refer my other blog on Blockchain Technologies for further details on this.



Encryption Basics & Quantum Computer Part -1

Recent iPhone Data encryption and controversy over Security vs Privacy debate reminded me my 2003 final project on Quantum Computing. So I just thought of writing a series of post on Security and Encryption. This is part 1

We can rely on today's encryption system because factorization is an intractable problem in Classical Computing model. When the numbers are very large, no efficient, non-quantum integer factorization algorithm is known. These are called NP Complete problem algorithm terms.

This encryption system could be broken if we use a Quantum Computer (At least in theory).

However before we get into detail how Quantum Computer can be used to break current Day Cryptography System and lets refresh the basics.

There are three associated Encryption Strategies possible in Classical Computing paradigm






Symmetric Encryption
  • Same secret Key is being used to encrypt & decrypt the message.
  • Anyone who knows the secret key can decrypt the message.

Asymmetric Encryption

  • Two separate keys being used - one public key broadcast-ed anyone who wants to send encrypted message
  • A second, private key is kept secret
  • Any message (text, binary files, or documents) that are encrypted by using the public key can only be decrypted by applying the same algorithm, but by using the matching private key. Any message that is encrypted by using the private key can only be decrypted by using the matching public key. 
  • To identify the origin of the message a digital certificate is used to sign the message


One of most widely used Data Encryption PGP - Pretty Good Privacy used Asymmetric Encryption Strategy to protect the data and same is used in HTTPS.

Here is how it works:




Please watch this excellent video explaining the same: