class: center, middle, title

Cryptography and Security

How to keep your data safe (a bit)

.height_8em[Chihuahua Security]

Chris Wilson, Aptivate, AfNOG 2014


Credits

Based on presentations by:

You can access this presentation at: http://afnog.github.io/sse/crypto/presentation

Download or edit this presentation on GitHub.


Conventions

Commands to enter are shown like this:

openssl smime -encrypt -binary -aes-256-cbc -in message3.txt -out message3.txt.enc yourpartner.crt.pem
openssl smime -decrypt -binary -in encrypted.zip.enc -out decrypted.zip -inkey private.key -passin pass:your_password

Please note:


What we can talk about


What do you care about?

What is security?

What do you want to prevent? What is the threat?

???


Examples of security measures

Make a list of measures that you actually use.

For example:


How secure are you?

How would you crack the defensive measures that we just listed?


Absolute security

The only truly secure system is one that is powered off, cast in a block of concrete and sealed in a lead-lined room with armed guards - and even then I have my doubts. - Gene Spafford

Security is impossible if:


Living with insecurity


Reducing specific risks


Goals of system security

Why do you lock your doors?


Confidentiality (secrecy)


Integrity (anti-tampering)


Authentication


Non-repudiation


How do we use cryptography?


Applied Cryptography

Written by Bruce Schneier. Perhaps the best book around if you want to understand how cryptography works.

https://www.schneier.com/book-applied.html


class: small

Cryptographic Tools


Ciphers → Ciphertext

Cryptography process

The foundation of all of cryptography:


Symmetric Ciphers (Conventional)

.center.height_8em[Symmetric decryption]

The same key is used to encrypt the document before sending and to decrypt it once it is received.


Common Symmetric Ciphers


Problems with Conventional Cryptography

Key Management


Public Key Cryptography

Different related keys are used to encrypt the document before sending and to decrypt it once it is received.

.center.height_8em[Public key cryptography]


Problems with Public Key Crypto

Solutions?


Hash Functions

Algorithms that take any amount of input and return a fixed-size output string, which is called the hash value or hash.

Hash function


Ideal hash function

Has these properties:

What does infeasible mean?


Perfect hash function

A hash function that maps each valid input to a different hash value is said to be perfect.


Practicals


layout: true

Hash Practical 1


Exercise

Using this hash function:

Perform the following exercise:


Analysis

Does this hash function meet our ideal properties?

  1. easy to compute the hash value for any given message
  2. infeasible to find a message that has a given hash
  3. infeasible to modify a message without changing its hash
  4. infeasible to find two different messages with the same hash

Analysis

Not really!

  1. Easy to compute.
  2. Easy to find another message with the same hash (string of 1s)
  3. Easy to modify a message without changing its hash (rearrange the letters)

layout: false

Hashes in real life

ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/i386/ISO-IMAGES/10.0/

The checksums of the large binary files in that directory.


Hash Practical 1

Verifying downloads

fetch http://mini1.sse.ws.afnog.org/~inst/FreeBSD-10.0-RELEASE-i386-bootonly.iso
md5 FreeBSD-10.0-RELEASE-i386-bootonly.iso
sha256 FreeBSD-10.0-RELEASE-i386-bootonly.iso

layout: true

Hash Practical 2


Hashing your own message

scp message1.txt afnog@pcYY.sse.ws.afnog.org:/tmp

Verifying the Hash


layout: true

Encryption Practical 1


Basic Encryption

openssl aes-256-cbc -a -salt -in message2.txt -out message2.txt.enc

Basic Decryption

openssl aes-256-cbc -d -a -in message2.txt.enc -out message2.txt.new

???

Credit: http://tombuntu.com/index.php/2007/12/12/simple-file-encryption-with-openssl/


Questions


layout: true

Encryption Practical 2


Certificate Generation

openssl req -x509 -new -out yourname.crt.pem -keyout yourname.key.pem

Questions:


Certificate Exchange

openssl x509 -in yourpartner.crt.pem -noout -text

Questions:


Encryption

openssl smime -encrypt -binary -aes-256-cbc -in message3.txt -out message3.txt.enc yourpartner.crt.pem

Questions:

???

Credit: http://stackoverflow.com/a/12233688/648162


Decryption

openssl smime -decrypt -binary -in message3.txt.enc -out message3.txt.dec -inkey yourname.key.pem

Questions:


Questions


Weaknesses


layout: false

Passwords

.center[XKCD on Password Strength]


layout: true

Secure Shell


Host Keys

Why do we verify host keys?

.height_8em.center[A Man-in-the-Middle Attack]


Host Key Demonstration

When you SSH to your partner’s computer for the first time, what do you see?

The authenticity of host ‘pc34.sse.ws.afnog.org (196.200.219.134)’ can’t be established. ECDSA key fingerprint is ae:09:ce:83:09:fc:d5:ca:69:ae:df:7d:c6:92:1e:e5. Are you sure you want to continue connecting (yes/no)?

What should you do about it?

ssh-keygen -lf /etc/ssh/ssh_host_ecdsa_key.pub

Key Caching

What happens after the first time you connect? Why?


Attack Demonstration

To see what happens, replace your host key:

sudo /etc/rc.d/sshd keygen

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
ae:09:ce:83:09:fc:d5:ca:69:ae:df:7d:c6:92:1e:e5.
Please contact your system administrator.
Add correct host key in /home/chris/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/chris/.ssh/known_hosts:228
  remove with: ssh-keygen -f "/home/chris/.ssh/known_hosts" -R pc34.sse.ws.afnog.org
ECDSA host key for pc34.sse.ws.afnog.org has changed and you have requested strict checking.
Host key verification failed.

Implications


Recovery

For now, fix it on your client by running:

ssh-keygen -R pcYY.sse.ws.afnog.org

And test that you can SSH without this warning.


Key Authentication

Passwords, and don’t use them!

???

Two-factor authentication.


Key Generation

If you don’t already have an SSH key, generate one:

ssh-keygen

Questions


Answers

  1. Unprotected key allows login to server with no password!
  2. The passphrase is not sent to the server, only used to decrypt the key.
  3. You need an agent to cache your passphrase and forward through servers.
  4. So you can tell whether you’re being asked for the password or the passphrase!

Key Distribution

Copy the key to your partner’s server:

ssh-copy-id -i ~/.ssh/id_rsa.pub pcYY.sse.ws.afnog.org

Now try logging in to their server. What’s different?

ssh pcYY.sse.ws.afnog.org

You should be prompted for your passphrase instead of a password:

Enter passphrase for key ‘/home/afnog/.ssh/id_rsa’:


layout: false

FIN

Any questions?