Thursday, November 30, 2017

The whole shebang on Cryptography, SSL Certificates, IPSec, SSH - Part 1

The whole shebang on Cryptography

Part 1 >  Part 2 > Part 3 > Part 4

This will be the first part of a series of posts on Cryptography /SSL Certificates / IPSec /SSH and will cover the useful facts/tools/commands as well.

How everything starts ...  :)

Me : Shall we have pizza for lunch?
Tommy : Oh yeah, lets order online. Shall we use your card?
Me :  
(I'm afraid to expose my credit card information to an online pizza website)


What is Cryptography?

Cryptography is a method of storing and transmitting data in a particular form so that only those for whom it is intended can read and process it.

Var
Description(PlainText)
m
Message (Plain-text)
c
Cipher-text
E
Encryption Algorithm
D
Decryption Algorithm
ke
Encryption Key
kd
Decryption Key


Goal of Cryptography : (Privacy) Thieves should not be able to learn m (message / plain-text)


1| Symmetric Key Cryptography /Private Key Encryption


  • Same key is used to encrypt data as well as to decrypt data. 
    • : Everyone shares same secret key. (k = ke = kd
  • Faster than Asymmetric key/Public key Encryption.
Problem: Secured channel must be used to transfer the only available key.

- Wait ... Encryption is NOT All !!!

*| Message Authenticity and Integrity - Message Authentication Code (MAC) 

Message Authentication Code (MAC) is a short piece of information used to confirm that the message came from the stated sender (its authenticity) and has not been changed.

  • A MAC requires two inputs: a message and a secret key known only to the originator of the message and its intended recipient(s). 
  • This allows the recipient of the message to verify the integrity of the message and authenticate that the message's sender has the shared secret key. 
  • If a sender doesn’t know the secret key, the hash value would then be different, which would tell the recipient that the message was not from the original sender. 


2| Asymmetric key Cryptography /Public key Encryption




  • Two keys are used in the process (public key and private key) 
    • : Only one party has the secret key. ( ke != kd)
  • Slower when compared to Symetric Key Encription.
Like a lot of things in computing, it comes to a trade off between performance and computing when you have to decide whether to use Symmetric key encryption or asymmetric key encryption .
- Wait ... Encryption is NOT All !!!

*| Message Authenticity and Integrity - Digital signature

Digital signature is a mechanism by which a message is authenticated proving that a message is  coming from a given sender.

E.g : Much like a signature on a paper document.

Suppose that Rose wants to digitally sign a message to Jack.  To do so,
  • she uses her private-key to encrypt the message; 
  • she then sends the message along with her public-key (typically, the public key is attached to the signed message). 
Since Rose’s public-key is the only key that can decrypt that message, a successful decryption constitutes a Digital Signature Verification, meaning that there is no doubt that it is Rose’s private key that encrypted the message.

Key Types, Key Sizes and Algorithms used to generate Keys

Public key
  • A large numerical value that is used to encrypt data. 
  • The key can be generated by a software program, but more often, it is provided by a trusted, designated authority.
  • Made available to everyone through a publicly accessible repository or directory.

Private Key
  • Another large numerical value that is mathematically linked to the public key.
  • In asymmetric cryptography, whatever is encrypted with a public key may only be decrypted by its corresponding private key and vice versa.
Algorithms
RSA and DSA are two of the algorithms which are used to encrypt public/private keys in cryptography.

  • RSA - (Rivest, Shamir, & Adleman public key encryption technology)
  • DSA - (Digital Signature Algorithm)
Key Sizes


The key size (bit-length) of a public and private key pair decides how easily the key can be exploited with a brute force attack.
  • There is no requirement for the key length to match the block size in any way; 
  • However, cryptographers are in love with binary, so key length will usually be a power of 2 like 128 or 256, and so will block size be.

The more computing power increases year after year, it requires more strong keys to secure transmitting data.
  • RSA claims that 1024-bit keys are likely to become crack-able some time between 2006 and 2010 and that 2048-bit keys are sufficient until 2030. 
  • An RSA key length of 3072 bits should be used if security is required beyond 2030.

For Advanced Learners

Public Key Encryption and Digital Signature:How do they work?



If you want to learn about SSL certificates > Part 2 - The whole shebang on SSL Certificates
If you want to learn about IPSec > Part 3 - The whole shebang on IPSec
If you want to learn about SSH > Part 4 - The whole shebang on SSH

The whole shebang on Cryptography, SSL Certificates, IPSec, SSH - Part 4

The whole shebang on SSH

Part 1 Part 2 > Part 3  >  Part 4

How SSL Certificates / IPSec / SSH differentiates ...

SSH (Secure Shell)


If you want to learn about Cryptography > Part 1 - The whole shebang on SSL certificates
If you want to learn about SSL certificates > Part 2 - The whole shebang on Cryptography
If you want to learn about SSH > Part 3 - The whole shebang on IPSec

The whole shebang on Cryptography, SSL Certificates, IPSec, SSH - Part 3

The whole shebang on IPSec

Part 1 Part 2 > Part 3 Part 4

How SSL Certificates / IPSec / SSH differentiates ...

IP Sec (Internet Protocol Security)


If you want to learn about Cryptography > Part 1 - The whole shebang on SSL certificates
If you want to learn about SSL certificates > Part 2 - The whole shebang on Cryptography
If you want to learn about SSH > Part 4 - The whole shebang on SSH

The whole shebang on Cryptography, SSL Certificates, IPSec, SSH - Part 2

The whole shebang on SSL Certificates

Part 1 > Part 2 > Part 3 > Part 4

How SSL Certificates / IPSec / SSH differentiates ...

SSL certificates

What is a SSL certificate?
  • Certificate is simply a way of validating that site really is what is says.
  • Certificates are used when you have decided you use Asymmetric encryption for your data exchange process
  • Certificates are used to hold public keys, not private keys. (You will not be able to store/find a private key inside a certificate)
A legitimate company (Pizza Hut) would,

  1. submit its company information to a registered certification authority.
  2. obtain a SSL certificate from a CA.
  3. Install the SSL Certificate on their web site.

When a client accesses their website (Pizza Hut Web Site) via a Web-Browser,

  1. Browser will perform SSL handshake between customers browser and web server.
  2. In the SSL handshake, the client browser requests the web server to prove its authenticity.
  3. In response, the server sends certificate chain(root, primary and intermediate certificate) to the client browser.
  4. Then browser checks this certificate chain against the local stored certificates as every browser has legitimate root certificate of authorities for verifying SSL handshake.
    E.g : Mozilla Included CA Certificate List    Apple Included CA Certificate List



Trusted Certificate Authority (CA)?

  • Certificate Authorities / CAs, issue Digital Certificates. 
  • Operating systems (OSes) and browsers maintain lists of trusted CA root certificates to verify certificates that a CA has issued and signed.

Certificate chain?

A certificate chain is an ordered list of certificates containing,
  • User Certificate /End entity Certificate /Leaf Certificate
  • Intermediary Certificate/s 
  • Root Certificate
The chain or path begins with the User certificate, and each certificate in the chain is signed by the entity identified by the next certificate in the chain.

Use SSL Checker to identify the certificate chain installed on a site.
SSL Checker on https://www.pizzahut.com/


Types of Certificates?
-User Certificate /End entity Certificate /Leaf Certificate

  • Is a digitally-signed statement issued by a Certificate Authority to a person or system.
  • It cannot be used to sign other certificates.
  • Its the certificate which will be installed on a site. (E.g: https://pizzahut.com)

-Intermediate Certificate/s

  • Any certificate that sits between the User Certificate and the Root Certificate is called a chain or Intermediate Certificate. 
  • A certificate used to sign other certificates, which is not self-signed. 
  • An intermediate certificate must be signed by another intermediate certificate, or a root certificate.
-Root Certificate

  • The Root CA Certificate is always signed by the CA itself.
  • A self-signed certificate used to sign other certificates.
  • The root certificate carries critical importance; The signatures of all certificates in the chain must be verified up to the Root CA Certificate.


Self Signed Certificate ?

  • A certificate which is not signed by a CA.
  • A certificate with a subject that matches its issuer, and a signature that can be verified by its own public key. 

Certificate standards
Certificate Standard defines the format of public key certificates.

X509 standard (format for public key certificates)

  • Certificate
    • Version Number
    • Serial Number
    • Signature Algorithm ID
    • Issuer Name
    • Validity period
      • Not Before
      • Not After
    • Subject name
    • Subject Public Key Info
      • Public Key Algorithm
      • Subject Public Key
    • Issuer Unique Identifier (optional)
    • Subject Unique Identifier (optional)
    • Extensions (optional)
      • ...
  • Certificate Signature Algorithm
  • Certificate Signature

CSR (Certificate Signing Request) ?
  • CSR contains information such as your domain name, your organization’s name, your location, and is filled out and submitted to a Certificate Authority(CA) such as SSL.com.

  • The information in a CSR is used to verify and create your SSL certificate. 
  • Most importantly, it also contains the public key that will be included in your certificate.
A CSR (Certificate Signing Request) which needs to be submitted to a Certificate Authority(CA) looks like (Most CSRs are created in the Base-64 encoded PEM format),



How do I generate a CSR and private key?

If you are familiar with OpenSSL,
you can use the following command to generate a CSR and private key
openssl req -new -newkey rsa:2048 -nodes -out servername.csr -keyout servername.key

Or else,
you can use one of the guidelines provided in the links and use the GUI tool,


Note : The private key must not be shared with any party (Not even with the CA) except your intended parties. CA only requires the CSR to provide you with a SSL certificate.

Certificate Containers / Key Stores

Certificate container standards

PKCS#12(.p12 extension) : a standard for a container which can hold an X509certificates and the corresponding private keys.


E.g : If you're examining a PKCS#12 file (typically .p12 extension), then you already know:
  • It contains at least one X509 client certificate, which contains a public key; and
  • It contains the corresponding private keys.

What are types of key stores?


Useful facts when working with Certificates

Useful commands in private key/certificate conversion




For Advanced Learners


If you want to learn about Cryptography > Part 1 - The whole shebang on Cryptography
If you want to learn about IPSec > Part 3 - The whole shebang on IPSec
If you want to learn about SSH > Part 4 - The whole shebang on SSH


Things to be learned before learning Load Balancing

Network Layers (Keep in mind when working with diffrent protocols) Difference between HTTPS and SSL SSL (Secure Socket Layer...