S-38.3153 Mikko Särelä keskiviikkona 28. maaliskuuta 2012
Jan 14, 2015
S-38.3153Mikko Särelä
keskiviikkona 28. maaliskuuta 2012
Today’s plan
• Learn about protocols
• Remote login
• How to solve security problems?
• How can cryptography help?
keskiviikkona 28. maaliskuuta 2012
Remote login
• A simple protocol to remotely login to a computer as if you were physically present
keskiviikkona 28. maaliskuuta 2012
Remote login
Alice HalHi Hal! I’m Alice
What’s your password?
It’s BobAteMyCat
Access granted
> run emacs mythesis.txt
keskiviikkona 28. maaliskuuta 2012
What kind of security problems do you see?
keskiviikkona 28. maaliskuuta 2012
Remote login
Alice HalHi Hal! I’m Alice
What’s your password?
It’s BobAteMyCat
Access granted
> run emacs mythesis.txt
keskiviikkona 28. maaliskuuta 2012
Remote login
Alice HalHi Hal! I’m Alice
What’s your password?
It’s BobAteMyCat
Access granted
> run emacs mythesis.txt
Mallory
keskiviikkona 28. maaliskuuta 2012
How would you fix the security problems?
keskiviikkona 28. maaliskuuta 2012
Secure Shell
• Use public key cryptography to authenticate remote end
• Leap of faith for first time connections
• User is authenticated with password or public key crypto
• This communication is encrypted
keskiviikkona 28. maaliskuuta 2012
Cryptography basicsMikko Särelä, Dr. Tech
20 March 2012
keskiviikkona 28. maaliskuuta 2012
Security and cryptologyThe same thing?
keskiviikkona 28. maaliskuuta 2012
Crypto overview
• Public key cryptography
• Key exchange
• Symmetric key cryptography
• Secure hash
keskiviikkona 28. maaliskuuta 2012
Crypto basics
• Plaintext message m
• Crypto-algorithm
• Key k
• Encrypted text
keskiviikkona 28. maaliskuuta 2012
Public key cryptography
keskiviikkona 28. maaliskuuta 2012
Two keys - private and public
keskiviikkona 28. maaliskuuta 2012
Some math
• RSA and Diffie-Hellman based on modulo arithmetics
• the difficulty of division operation, logarithm, and factoring
keskiviikkona 28. maaliskuuta 2012
Modulo0
3
1
2
5
4
9
8 7 6
10
11
12
keskiviikkona 28. maaliskuuta 2012
Addition and multiplication easy
keskiviikkona 28. maaliskuuta 2012
Division is hardFactoring is hard
keskiviikkona 28. maaliskuuta 2012
Example: RSA
• n = p*q, p and q large primes
• Choose public key e as relative prime for (p-1)(q-1)
• Private key d = e-1 mod ((p-1)(q-1))
• Encrypting c = me mod n
• Decrypting m = cd mod n
keskiviikkona 28. maaliskuuta 2012
Problem
• p = 11, q = 3
• e = 3
• What is d?
• Encrypt message m = 7
• Decrypt the result
keskiviikkona 28. maaliskuuta 2012
Solution
• c = me mod n = 73 mod 33 = 343 mod 33 = 13.
• c = 13
• To check decryption:
• m’ = cd = 137 mod 33 = 7
keskiviikkona 28. maaliskuuta 2012
Cipher text for all m
m 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16c 0 1 8 27 31 26 18 13 17 3 10 11 12 19 5 9 4
m 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32c 29 24 28 14 21 22 23 30 16 20 15 7 2 6 25 32
keskiviikkona 28. maaliskuuta 2012
Cipher text for all m
m 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16c 0 1 8 27 31 26 18 13 17 3 10 11 12 19 5 9 4
m 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32c 29 24 28 14 21 22 23 30 16 20 15 7 2 6 25 32
keskiviikkona 28. maaliskuuta 2012
Depends onFactoring being hard!
keskiviikkona 28. maaliskuuta 2012
Usage
• Use public key to encrypt data
• Private key is used to decrypt it
• Or use private key to sign data
• Public key can be used to verify the signature
• Only owner of private key can sign
• Basis for certificates
keskiviikkona 28. maaliskuuta 2012
Diffie-Hellman
keskiviikkona 28. maaliskuuta 2012
(AB)C = Ab*c = (AC)B
keskiviikkona 28. maaliskuuta 2012
Diffie-Hellmanhttp://upload.wikimedia.org/wikipedia/commons/a/a3/Diffie-Hellman-Schlüsselaustausch.png
keskiviikkona 28. maaliskuuta 2012
Symmetric key cryptography
keskiviikkona 28. maaliskuuta 2012
Block cipherStream cipher
keskiviikkona 28. maaliskuuta 2012
Block cipher
Block cipher encryption
Key
Plaintext
Ciphertext
keskiviikkona 28. maaliskuuta 2012
Stream cipher
Plaintext
AIVK
Kstream
Ciphertext
Ciphertext
AIVK
Kstream
PlaintextXOR
keskiviikkona 28. maaliskuuta 2012
Ciphers overview
keskiviikkona 28. maaliskuuta 2012
• Symmetric ciphers• Fast• require separate key exchange• Public key ciphers• Slow• No key exchange required• usage: signatures, certificates, encrypt
symmetric cipher key inside a message• How to get random keys?
keskiviikkona 28. maaliskuuta 2012
Cryptographic hashes
keskiviikkona 28. maaliskuuta 2012
Ideal hash-function
• easy to compute the hash value for any given message• infeasible to generate a message that has a
given hash• infeasible to modify a message without
changing the hash• infeasible to find two different messages
with the same hash
keskiviikkona 28. maaliskuuta 2012
Keyed hash
keskiviikkona 28. maaliskuuta 2012
Applications
• Verifying integrity of a message using keyed hash function
• file or data identifier
• pseudorandom number generation and key generation
• hash chains
keskiviikkona 28. maaliskuuta 2012
Cryptographic Hash functions
• SHA-256 as an example
• Birthday attack
• Keyed hash is usually marked as
• h(k, M)
keskiviikkona 28. maaliskuuta 2012
Secure Shell
keskiviikkona 28. maaliskuuta 2012
What is SSH?
• A set of protocols that is designed to provide a secure communication channel between host and a server
• Covers authentication, encryption, and data integrity
• Originally replacement for telnet/rlogin/rsh
• SFTP also
keskiviikkona 28. maaliskuuta 2012
History
• Tatu Ylönen developed the first version in 1995
• SSH protocol version 2 in 1998 because of protocol vulnerabilities
• Many open and commercial versions available for all operating systems
keskiviikkona 28. maaliskuuta 2012
Protocol details
• Client/server architecture
• Server listens to port 22
• Client wanting to connect executes an ssh command
• port forwarding
keskiviikkona 28. maaliskuuta 2012
SSH Protocol Stack
IP
TCP
SSH Transportation protocol
SSH Connection ProtocolMultiplexes encrypted tunnel into several
logical channels
SSH User Authentication protocolAuthenticates client-side user to the
server
keskiviikkona 28. maaliskuuta 2012
Transport layer
• Initial key exchange
• Server authentication
• Data confidentiality
• Data Integrity
• Compression (optional)
• key re-exchange
keskiviikkona 28. maaliskuuta 2012
Transport layer
• Server authenticates itself to client
• No man-in-the-middle attacks
keskiviikkona 28. maaliskuuta 2012
SSH ProtocolClient Server
TCP connection setup
SSH version string exchange
SSH Key exchange
SSH data exchange
Termination of the TCP connection
keskiviikkona 28. maaliskuuta 2012
SSH key exchange• Client and server send kex_init packet, containing a list
of crypto algorithms they support
• First common key exchange algorithm supported by server is chosen
• Used to negotiate server authentication, encryption, MAC, and compression
• Opportunistic guess allowed
• Establish shared secret k and
• Authenticate server
• with public key signature or shared key authentication with MAC
keskiviikkona 28. maaliskuuta 2012
User authentication
• Client authentication
• password
• public key cryptography
• host based authentication
keskiviikkona 28. maaliskuuta 2012
Connection layer
• Defines logical channels
• Requests for TCP port forwarding, X11 forwarding etc.
keskiviikkona 28. maaliskuuta 2012