Data Security 2 - Encryption - TLS
References for this Part
Jean-Philippe Aumasson. Serious Cryptography. No Starch Press, 2018. Chapters 2-5, 13.
(https://cryptojs.gitbook.io/docs/)
(https://www.thesslstore.com/blog/difference-encryption-hashing-salting/)
(https://www.ssl2buy.com/wiki/ssl-tls-handshake-how-does-it-work)
(https://developer.mozilla.org/en-US/docs/Web/Security/Transport_Layer_Security)
Transport Layer Security, TLS 1.2 and 1.3 (Explained by Example) – YouTube
Model Solutions Previous Lesson
The required functions are written in a library file (JS):
|
|
and the testing program:
|
|
Encryption
The are four cornerstones of modern data security, they are:
- Confidentiality
- When or if we need to restict knowledge of certain data to a limited target group, the technology must make it possible.
- Authenticity
- We must be able to ascertain that the source of data is who they claim to be, and the source must be able to trust that the recipients who can read the data, are indeed entitled to that.
- Integrity
- The software involved must be able to substantiate that data has not been interfered with while in transit from the source to the intended target.
- Non Repudiation
- The source of the data must not be able to deny being the source.
Intro, Getting Started
Modern cryptography is based on discoveries made in the late 60’s and 70’s. These principles have been implemented into software that has not changed substantially since then. The algorithms are well know by now, and on principle they must be. The element that makes ciphers har to crack are the keys involved. The longer the safer. The idea is that if it takes so long to crack the code, so to speak, that the result is no longer relevant, we have won.
In latter years there has been discussions about the effects of the upcoming quantom computing on the cryptographical security. There are indications that we might eventually have to think again, but hard facts remain to be seen. On that background let us dive in.
The basis of this walk through is an implementation of the principles called GnuPG, standing on the shoulders of Phil Zimmermann’s PGP, Pretty Good Privacy.
Generate Keypair
|
|
The result of the above is a directory in your home directory
|
|
Exchange Keys - Exporting a Public Key
|
|
Exchange Keys - Importing a Public Key
|
|
The prerequisite is, of course, that someone mailed you their public key.
After importing a key, you should confirm it:
|
|
Encrypt Document
You encrypt with the recipients public key:
|
|
Decrypt Document
Upon receiving encrypted messages you decrypt with
|
|
which wil decrypt directly to the terminal screen. If you want to save the received message after decryption, you do:
|
|
Making and Verifying Signatures
Signing a document is done with the signer’s private key:
|
|
The output document is now signed, ie encrypted with the owners private key. The owners public key, which is obtainable by anyone is now the only key in the world that can make plaintext out of the signed document.
The recipient may verify:
|
|
or, if you want to read the message, you must decrypt it too:
|
|
Assymmetric Encryption ctr Signing
To highlight the differences between encryption and signing:
- Encryption
- You encrypt with recipients public key. Only one person, the intended recipient, can decrypt with his corresponding private key. This ensures confidentiality.
- Signing
- You sign with your own private key. Then you may send the signed document to one or to many recipients. They may all either just verify, or decrypt with your public key. This ensures authenticity, integrity, and non repudiation.
The GNU Privacy Handbook has much useful information about
- Symmetric Encryption
- Assymmetric, aka Public Key Encryption
- Reality Hits, Hybrid Encryption
- Digital Signatures
- Key Management
TLS, Transport Layer Security
Whatis?
The webpage https://en.wikipedia.org/wiki/Transport_Layer_Security has in its description section a brief overview of what Transport Layer Security, TLS, is. Then it adds history from the SSL ancestor til today, as well as schematically showing current browser coverage.
The transport layer is a layer in the reference model describing the way the internet software is organized. The name of that model, TCP/IP, is coined by the two protocol names that makes it all possible. TCP is a transport protocol, and the TLS is active on the same layer of the protocol. It provides a service to the layer above it, where the HTTP resides.
Howto?
Easy! We don’t do a thing as developers except using the https protocol over http. This requires a certificate from a certificate vendor. The certificate, like trust for someone’s public key, enables the user to trust that your site really belongs to you.
The actual setup of a TLS communication is done via a TLS handshake that plays as follows(https://www.ssl2buy.com/wiki/ssl-tls-handshake-how-does-it-work)
- The user starts the handshake process by sending a “Hello” message. This message contains the TLS type and cipher suites that the user supports. It also includes a string of arbitrary bytes, called “client random.”
- In its reply, the server sends the text with its SSL certificate. The text also contains the cipher suite chosen for this process and a string of random bytes generated by the server referred to as “server random.”
- The user’s browser authenticates the SSL certificate provided by the server and the certificate authority that has issued it. This proves that the server is who it states to be, and the client is interacting with the license holder.
- The client sends another message (premaster secret) encoded with the SSL certificate’s public key that can only be decoded by the private key, which is held by the server.
- The server reads the message using its private key.
- After this, a session key is created using client random, server random, and the premaster secret.
- Both server and client send a “finished” message, encoded with the session key.
- The SSL handshake is completed successfully, and both parties continue communicating safely, using the session keys.
Using TLS
In order to use TLS, there is really not much developer work involved. Links to own pages need to substitute https for http in order to invoke TLS. Then it happens automatically. There is a prerequisite involved, the site must have a certificate installed. This is really not developer work, but rather the job of the site administration. I highly recommend that you take a detailed look at https://letsencrypt.org/ for details on that.
Generally you may be able to buy certificates from your hosting provider. They are not free, normally. You may have noticed, btw, that in some clouds, your hosted site will automatically be an https site.
Exercises
The rules for handing in assignments may be found in the README
Exercise DS.2.0
Download and install GnuPG from https://www.gnupg.org/download/, find the appropriate version in the section: GnuPG binary releases.
Generate a keypair for yourself, and export your public key to an asc, ASCII Armored, file. Use your regular email address when generating your keypair.
Then publish your exported public key to either:
If you get a verification email, don’t ignore it.
Exercise DS.2.1
Create a text file, and encrypt it with your own public key,
use your email as recipient. Give the encrypted file the name
SecE1.enc.txt
. Then open the encrypted file in your favorite
editor. What happens?
Then decrypt the file into a file differently name than the original file. Verify that the content has become itself again.
Finally, encrypt the original file with arosano@protonmail.com as the
recipient. You may get the public key from: https://keys.openpgp.org
Name the output SecE1a.enc.txt
.
Both encrypted files go into the repo.
Exercise DS.2.2
Take the text of this assignment, and put it into a txt document.
Then sign it with a regular digital signature, name the
output SecE2.sign.txt
, and put it into the repo.
Exercise DS.2.3
Create a short document, and clearsign it into
SecE3.sig.txt
.
The document should give a possible use case for clearsign.
Exercise DS.2.4
Create a short document, and detached sign it into
SecE4.det.sig.txt
. The document should give a possible
use case for detached signatures.