Practical cryptography

Welcome and thanks for joining!

© Course authors (CC BY-SA 4.0) - Image: © Bret Bernhoft (CC0 1.0)

What we will cover

How cryptography makes the modern world go round and how you can practically utilize it.

© Course authors (CC BY-SA 4.0) - Image: © ESA (CC BY-SA 3.0 IGO)

This isn't a math course.

You won't become an expert cryptologist,
but hopefully a power-user!

© Course authors (CC BY-SA 4.0) - Image: © Damien McMahon (CC BY 2.0)

Requires basic knowledge of...

  • Linux shell scripting
  • Python programming
  • Networking
  • Docker and Docker Compose
© Course authors (CC BY-SA 4.0) - Image: © Fritzchens Fritz (CC0 1.0)

How we will do it

  • Lectures and Q&A
  • Individual and group presentations
  • Lab exercises
  • Continuous reflection
  • Quizzes and scored tests
© Course authors (CC BY-SA 4.0) - Image: © Amy Nelson (CC BY 3.0)

For detailed notes, glossary, labs and similar, see:
t.menacit.se/crypto.zip.

These resources should be seen as a complement to an instructor lead course, not a replacement.

© Course authors (CC BY-SA 4.0)

Acknowledgements

Thanks to IT-Högskolan and Särimner for enabling development of the course.

Thanks to Yubico for providing YubiKeys to in-class students for labs!

Hats off to all FOSS developers and free culture contributors making it possible.

© Course authors (CC BY-SA 4.0) - Image: © Sergio Delgado (CC BY 2.0)

Free as in beer and speech

Is anything unclear? Got ideas for improvements? Don't fancy the animals in the slides?

Create an issue or submit a pull request to
the repository on Github!

© Course authors (CC BY-SA 4.0) - Image: © Jorge Franganillo (CC BY 2.0)

Contributors <3

© Course authors (CC BY-SA 4.0) - Image: © Sergio Delgado (CC BY 2.0)

Let us dig in!

© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)

Historic usage and basics

How did we end up here?

© Course authors (CC BY-SA 4.0) - Image: © Torkild Retvedt (CC BY-SA 2.0)

URGHH - SUSSO! KEEF.
HAAAWER NE NE!
FEVA.

Your average caveperson

© Course authors (CC BY-SA 4.0) - Image: © Reid Campbell (CC0 1.0)

Greetings! I'm an excellent hunter. See this fancy fireplace I got here? Let's make some babies!

Your average caveperson

© Course authors (CC BY-SA 4.0) - Image: © Reid Campbell (CC0 1.0)

Neat things about the written word

Allows preservation of complex information.

Enables conversions and relaying of detailed information/instructions over vast distances.

(Kinda necessary for ruling an empire)

© Course authors (CC BY-SA 4.0) - Image: © Ron Cogswell (CC BY 2.0)

Perhaps you want to keep some things a secret?

© Course authors (CC BY-SA 4.0) - Image: © Ron Cogswell (CC BY 2.0)

Let's hide the information!

We call this practice steganography.

© Course authors (CC BY-SA 4.0) - Image: © Miguel Discart (CC BY-SA 2.0)

Other notable examples

© Course authors (CC BY-SA 4.0) - Image: © Miguel Discart (CC BY-SA 2.0)

The downsides

Often requires trust in
courier(s) of the message.

Mayhaps someone is a bit mad
since you ruined their haircut?

© Course authors (CC BY-SA 4.0) - Image: © Miguel Discart (CC BY-SA 2.0)
center
© Course authors (CC BY-SA 4.0)

Enter the "Caesar cipher":

F  T F I I  Y X H B  X  Z X H B
© Course authors (CC BY-SA 4.0) - Image: © Jeena Paradies (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0)
Plain-alphabet:
a b c d e f g h i j k l m →
n o p q r s t u v w x y z

Cipher-alphabet:
X Y Z A B C D E F G H I J →
K L M N O P Q R S T U V W
Plaintext:  i  w i l l  b a k e  a  c a k e
Ciphertext: F  T F I I  Y X H B  X  Z X H B
Plaintext:  m a k e  i t  s o o n  p l e a s e
Ciphertext: J X H B  F Q  P L L K  M I B X P B
© Course authors (CC BY-SA 4.0) - Image: © Jeena Paradies (CC BY 2.0)

Probably confusing at first,
but quite easily broken.

Largely security through obscurity.

© Course authors (CC BY-SA 4.0) - Image: © Jeena Paradies (CC BY 2.0)

Let's not just shift characters,
but substitute them in a random order!

Plain-alphabet:   a b c d e f
Cipher-alphabet:  9 4 7 1 2 5
Plaintext:   d e a d  b e e f
Ciphertext:  1 2 9 1  4 2 2 5
Plaintext:     f e e d  d a d 
Ciphertext:    5 2 2 1  1 9 1
© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

The downsides

Every participant needs to
know the cipher-alphabet.

Languages are not random,
there are patterns and rules.

People who try to break
codes/ciphers are called
cryptanalysts.

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)
> F  T F I I  Y X H B  X  Z X H B
< J X H B  F Q  P L L K  M I B X P B

F and X appear on their own,
probably a and i.

FQ is a two-letter word, limited options.

Four words begin with a different letter
but end with XHB.

B appears five times in the messages,
probably e, o or t.

Method is known as frequency analysis.

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

Introducing keywords

Everyone can remember the
secret word "bad", right?

Let's try using the Vigenère cipher
(anno 1553) to encrypt "cafebabe".

© Course authors (CC BY-SA 4.0) - Image: © Pyntofmyld (CC BY 2.0)
Plaintext:   c  a  f  e  b  a  b  e
Keyword:     B  A  D  B  A  D  B  A
Ciphertext:  ?  ?  ?  ?  ?  ?  ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)
Plaintext:  >c< a  f  e  b  a  b  e
Keyword:    >B< A  D  B  A  D  B  A
Ciphertext: >D< ?  ?  ?  ?  ?  ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)
Plaintext:   c >a< f  e  b  a  b  e
Keyword:     B >A< D  B  A  D  B  A
Ciphertext:  D >A< ?  ?  ?  ?  ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)
Plaintext:   c  a >f< e  b  a  b  e
Keyword:     B  A >D< B  A  D  B  A
Ciphertext:  D  A >C< ?  ?  ?  ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)
Plaintext:   c  a  f >e< b  a  b  e
Keyword:     B  A  D >B< A  D  B  A
Ciphertext:  D  A  C >F< ?  ?  ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)
Plaintext:   c  a  f  e >b< a  b  e
Keyword:     B  A  D  B >A< D  B  A
Ciphertext:  D  A  C  F >B< ?  ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)
Plaintext:   c  a  f  e  b >a< b  e
Keyword:     B  A  D  B  A >D< B  A
Ciphertext:  D  A  C  F  B >D< ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)
Plaintext:   c  a  f  e  b  a >b< e
Keyword:     B  A  D  B  A  D >B< A
Ciphertext:  D  A  C  F  B  D >C< ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)
Plaintext:   c  a  f  e  b  a  b >e<
Keyword:     B  A  D  B  A  D  B >A<
Ciphertext:  D  A  C  F  B  D  C >E<
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)

DACFBDCE!

How about decryption?

© Course authors (CC BY-SA 4.0) - Image: © Nicholas Day (CC BY 2.0)
Plaintext:   ?  ?  ?  ?  ?  ?  ?  ?
Keyword:     B  A  D  B  A  D  B  A
Ciphertext:  D  A  C  F  B  D  C  E
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)
Plaintext:  >c< ?  ?  ?  ?  ?  ?  ?
Keyword:    >B< A  D  B  A  D  B  A
Ciphertext: >D< A  C  F  B  D  C  E
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)
Plaintext:   c >a< ?  ?  ?  ?  ?  ?
Keyword:     B >A< D  B  A  D  B  A
Ciphertext:  D >A< C  F  B  D  C  E
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)
Plaintext:   c  a >f< ?  ?  ?  ?  ?
Keyword:     B  A >D< B  A  D  B  A
Ciphertext:  D  A >C< F  B  D  C  E
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)
Plaintext:   c  a  f >e< ?  ?  ?  ?
Keyword:     B  A  D >B< A  D  B  A
Ciphertext:  D  A  C >F< B  D  C  E
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)

Kerckhoffs' principle

The security of a cipher
must be based on the chosen key,
not keeping the algorithm secret
(AKA "security through obscurity")

© Course authors (CC BY-SA 4.0) - Image: © Rob Hurson (CC BY-SA 2.0)

The cat and mouse game went on,
more or less the same way...

© Course authors (CC BY-SA 4.0) - Image: © Tero Karppinen (CC BY 2.0)

Technologies such as the telegraph
and radio really shook things up.

Even commercial enterprises found
the need for encryption.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Even if the cipher can't be broken, a lot can still be learned.

From where was the message sent? By whom?

We call this metadata.

© Course authors (CC BY-SA 4.0) - Image: © Peter Black (CC BY-SA 2.0)

Cryptography became too
complex for most humans.

If machines maketh,
let machine breaketh.

© Course authors (CC BY-SA 4.0) - Image: © Raphaël Vinot (CC BY 2.0)

While it had evolved significantly,
encryption algorithms worked more
or less the same until the 1970s.

Let me introduce you to
asymmetric cryptography.

© Course authors (CC BY-SA 4.0) - Image: © Pyntofmyld (CC BY 2.0)

Symmetric

Same key is used for encryption and decryption.

Asymmetric

Different keys are used for encryption and decryption
("public key" and "private key").

© Course authors (CC BY-SA 4.0) - Image: © Miguel Discart (CC BY-SA 2.0)

Everyone can encrypt messages to me, but only I can decrypt them.

© Course authors (CC BY-SA 4.0) - Image: © Miguel Discart (CC BY-SA 2.0)

Also enables "digital signatures".

That's right - cryptography can help us
protect the authenticity of messages from
an author, not only their confidentiality.

© Course authors (CC BY-SA 4.0) - Image: © A Loves DC (CC BY 2.0)

Did I mention "cryptographic hash functions"?

Wide range of use-cases, including:

  • Integrity validation
  • "One-way encryption"
  • Proof-of-Work

+ a lot of other exciting things we
shall learn about throughout the course!

© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)

So, my dear modern human -
have you relied on cryptography today?

© Course authors (CC BY-SA 4.0) - Image: © Elly Jonez (CC BY 2.0)

Cryptography helps us ensure
confidentiality and integrity
of information.

Should be infeasible to break,
but it's never impossible.

Modern cryptography operates
on bits, not letters.

© Course authors (CC BY-SA 4.0) - Image: © Gobi (CC BY 2.0)

Lab setup

What you need to know to get started

© Course authors (CC BY-SA 4.0) - Image: © Bill Smith (CC BY 2.0)

You'll need a YubiKey 5 for
some of the non-graded exercises.

© Course authors (CC BY-SA 4.0) - Image: © Yubinerd (CC BY-SA 4.0)

To install/configure tools required for the
course labs, several options are available:

  1. Native setup:
    Recommended for students running Ubuntu 24.04 LTS on a physical/virtual machine
  2. Non-native setup:
    Recommend for students running Windows/MacOS on their physical machine
  3. Manual setup:
    Available for students running other Linux distributions/operating systems

See "resources/labs/README.md" for details!

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Symmetric encryption

An introduction to it's uses

© Course authors (CC BY-SA 4.0) - Image: © Robert Jemimus (CC BY 2.0)

Same key is used for encryption and decryption.

Used primarily for protecting confidentiality
of information at rest and in transit.

How does symmetric encryption of
binary data work?

© Course authors (CC BY-SA 4.0) - Image: © Reid Campbell (CC0 1.0)

XOR logical operator

Many symmetric algorithms relies on
the "Exclusive or logical operator"
to produce ciphertext by mixing a
derived key and plaintext data.

XOR plays the same role as
Vigenère alphabet table.

Let's have a look at the
operator's "truth table"!

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)
Input A (data) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)

Let's encrypt the byte 0 1 0 1 1 0 0 0 ("X")
with the key 0 1 0 0 1 1 0 1 ("M").

© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)
Plaintext:   0  1  0  1  1  0  0  0
Key:         0  1  0  0  1  1  0  1
Ciphertext:  ?  ?  ?  ?  ?  ?  ?  ?
Input A (plaintext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)
Plaintext:  >0< 1  0  1  1  0  0  0
Key:        >0< 1  0  0  1  1  0  1
Ciphertext: >0< ?  ?  ?  ?  ?  ?  ?
Input A (plaintext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)
Plaintext:   0 >1< 0  1  1  0  0  0
Key:         0 >1< 0  0  1  1  0  1
Ciphertext:  0 >0< ?  ?  ?  ?  ?  ?
Input A (plaintext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)
Plaintext:   0  1 >0< 1  1  0  0  0
Key:         0  1 >0< 0  1  1  0  1
Ciphertext:  0  0 >0< ?  ?  ?  ?  ?
Input A (plaintext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)
Plaintext:   0  1  0 >1< 1  0  0  0
Key:         0  1  0 >0< 1  1  0  1
Ciphertext:  0  0  0 >1< ?  ?  ?  ?
Input A (plaintext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)
Plaintext:   0  1  0  1 >1< 0  0  0
Key:         0  1  0  0 >1< 1  0  1
Ciphertext:  0  0  0  1 >0< ?  ?  ?
Input A (plaintext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)
Plaintext:   0  1  0  1  1 >0< 0  0
Key:         0  1  0  0  1 >1< 0  1
Ciphertext:  0  0  0  1  0 >1< ?  ?
Input A (plaintext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)
Plaintext:   0  1  0  1  1  0 >0< 0
Key:         0  1  0  0  1  1 >0< 1
Ciphertext:  0  0  0  1  0  1 >0< ?
Input A (plaintext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)
Plaintext:   0  1  0  1  1  0  0 >0<
Key:         0  1  0  0  1  1  0 >1<
Ciphertext:  0  0  0  1  0  1  0 >1<
Input A (plaintext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Edenpictures (CC BY 2.0)

We got 0 0 0 1 0 1 0 1 as our ciphertext!

How do we perform decryption?

© Course authors (CC BY-SA 4.0) - Image: © Leah Oswald (CC BY-SA 2.0)
Ciphertext:  0  0  0  1  0  1  0  1
Key:         0  1  0  0  1  1  0  1
Plaintext:   ?  ?  ?  ?  ?  ?  ?  ?
Input A (ciphertext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Leah Oswald (CC BY-SA 2.0)
Ciphertext: >0< 0  0  1  0  1  0  1
Key:        >0< 1  0  0  1  1  0  1
Plaintext:  >0< ?  ?  ?  ?  ?  ?  ?
Input A (ciphertext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Leah Oswald (CC BY-SA 2.0)
Ciphertext:  0 >0< 0  1  0  1  0  1
Key:         0 >1< 0  0  1  1  0  1
Plaintext:   0 >1< ?  ?  ?  ?  ?  ?
Input A (ciphertext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Leah Oswald (CC BY-SA 2.0)
Ciphertext:  0  0 >0< 1  0  1  0  1
Key:         0  1 >0< 0  1  1  0  1
Plaintext:   0  1 >0< ?  ?  ?  ?  ?
Input A (ciphertext) Input B (key) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Leah Oswald (CC BY-SA 2.0)

Not that hard, right?

A side effect of using XOR this way is
that we can recover (parts of) the key
if we know (parts of) the plaintext.

Exploiting this fact is called a
known-plaintext attack.

Modern encryption ciphers put a lot
of effort on trying to prevent
it and other similar issues.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)
Plaintext:   0 >1< 0  1  1  0  0  0
Ciphertext:  0 >0< 0  1  0  1  0  1
Key:         0 >1< ?  ?  ?  ?  ?  ?
Input A (plain) Input B (cipher) Result
0 0 0
0 1 1
1 0 1
1 1 0
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Not that hard, right?

A side effect of using XOR this way is
that we can recover (parts of) the key
if we know (parts of) the plaintext.

Exploiting this fact is called a
known-plaintext attack.

Modern encryption ciphers put a lot
of effort on trying to prevent
it and other similar issues.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Let's move on, shall we?

© Course authors (CC BY-SA 4.0) - Image: © Reid Campbell (CC0 1.0)

Most symmetric ciphers are categorized as
block ciphers or stream ciphers.

© Course authors (CC BY-SA 4.0) - Image: © Reid Campbell (CC0 1.0)

Block ciphers split plaintext data into
parts of a fixed size (128 bits, for example)
and encrypts each part ("block") separately.

Most commonly used for "at rest" encryption.

© Course authors (CC BY-SA 4.0) - Image: © Mike Grauer Jr (CC BY 2.0)

Stream ciphers performs encryption of
each bit "independently" in a stream
of plaintext data.

Commonly used for "in transit" encryption.

© Course authors (CC BY-SA 4.0) - Image: © Jonathan Brandt (CC0 1.0)

Which approach is the best?

What are the advantages and disadvantages?

© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)

Hard to answer is a general/honest way.

Historically, many have considered
block ciphers harder to break and
stream ciphers more efficient.

(not necessarily true,
depends on algorithms compared)

© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)

Meet the algos

© Course authors (CC BY-SA 4.0) - Image: © Jonathan Brandt (CC0 1.0)

(3)DES

Data Encryption Standard.

Block cipher algorithm defined in 1977
by the US government as a part of the
Federal Information Processing Standard.

Key size was deemed inadequate as
computer performance increased rapidly,
replaced by "Triple DES" in mid 90s.

If you see it used, assume it's broken*.

© Course authors (CC BY-SA 4.0) - Image: © Rod Waddington (CC BY-SA 2.0)

AES

Advanced Encryption Standard,
also known as "Rijndael".

Block cipher standardized in 2001
by the US National Institute of
Standards and Technology
after a public competition.

Supports different key sizes and "modes"
(more about that later).

Resource hungry, but accelerated in
hardware by most processors ("AES-NI").

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

(A)RC4

Rivest Cipher 4
(or perhaps "Ron's Code 4").

Proprietary stream cipher developed
by Ron Rivest in 1987, later leaked
and reversed engineered.

Historically used in network protocols
like WEP/WPA, SSL/TLS and RDP.

Highly efficient, but considered
insecure by modern standards.

© Course authors (CC BY-SA 4.0) - Image: © Bruno Cordioli (CC BY 2.0)

ChaCha20

Successor to the "Salsa20" stream cipher,
developed by Daniel J. Bernstein.

Used in several network protocols,
like TLS, standardized by the
Internet Engineering Task Force.

Relatively simple to
implement correctly ("securely").

Fast/efficient even without
hardware acceleration.

© Course authors (CC BY-SA 4.0) - Image: © Wolfgang Stief (CC0 1.0)

Woah, that's a lot of acronyms!

Let's look at how we can utilize
"at rest" encryption to protect
our precious information.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Data encryption can be implemented at...

  • File level
  • File system layer
  • Block layer
  • Hardware layer
© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

File level

Cherry-pick files and encrypt em'!

Built-in support in several file formats,
like PDF, DOCX and XLSX.

Encrypted ZIP archives are a popular option
(often using broken ciphers like 3DES).

Useful for transferring sensitive data
over untrusted networks or easily lost
storage mediums, like USB drives.

© Course authors (CC BY-SA 4.0) - Image: © Pumpkinmook (CC BY 2.0)

File system layer

Modern file systems like
EXT4, BTRFS, ZFS and APFS natively support
encrypting selective parts file system tree,
like specific directories.

Used to provide per-user data encryption
on Android and MacOS.

Efficient and seamless, but may leak
metadata about encrypted files and
leave traces in unencrypted parts
of the file system.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Block layer

Application/OS provides a
virtual block device (storage disk)
that transparently encrypts data
before storage on physical disk.

Popular option for
Full Disk Encryption-solutions
like BitLocker, VeraCrypt and LUKS.

All data is encrypted, regardless of
sensitivity (for good and bad).

© Course authors (CC BY-SA 4.0) - Image: © Kevin Dooley (CC BY 2.0)

Hardware layer

Encryption is handled in the
storage drive without assistance
from the host's operating system.

"Opal" is a common standard for
Self-Encrypting Drives developed by
the Trusted Computing Group.

~No performance overhead, but require
trust in a proprietary black box.

© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)

Some final notes

Throughout the course, we'll dig deeper into
tools for symmetric data encryption
at the file and block layer.

Passphrase is not the same as encryption key,
typically used to derive/unlock it.

The devices used to encrypt and decrypt
data must still be trusted.

© Course authors (CC BY-SA 4.0) - Image: © Forsaken Fotos (CC BY 2.0)

Symmetric file encryption lab

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Lab description

Non-graded exercise to implement symmetric file encryption in a simple backup script.

For detailed instructions, see:
"resources/labs/sym_crypt/README.md".

No screenshots of text, please - they make the polar bear very sad!

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Group exercise

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

Exercise: Let's warm up!

Participants are split into two or more groups.

Group members should discuss:

  • What cryptographic tools/technologies/software they are already familiar with
  • What areas/use-cases they are most interested in learning about
  • What has been good/bad with the previous course and what would they like to change

After presentation, send notes to
courses+crypto_010501@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

Cryptography basics recap

© Course authors (CC BY-SA 4.0) - Image: © Mathias Appel (CC0 1.0)

Cryptography helps us ensure
confidentiality, authenticity and integrity
of sensitive information.

Steganography is a related practice in which information is hidden/obscured.

These have historically been used in unison.

© Course authors (CC BY-SA 4.0) - Image: © Wolfgang Stief (CC0 1.0)
center

Caesar cipher

© Course authors (CC BY-SA 4.0)
Plain-alphabet:
a b c d e f g h i j k l m →
n o p q r s t u v w x y z

Cipher-alphabet:
X Y Z A B C D E F G H I J →
K L M N O P Q R S T U V W
Plaintext:  i  w i l l  b a k e  a  c a k e
Ciphertext: F  T F I I  Y X H B  X  Z X H B
Plaintext:  m a k e  i t  s o o n  p l e a s e
Ciphertext: J X H B  F Q  P L L K  M I B X P B
© Course authors (CC BY-SA 4.0) - Image: © Theo Crazzolara (CC BY 2.0)

Let's encrypt "cafe"
with the keyword "bad"
using the Vigenère cipher.

© Course authors (CC BY-SA 4.0) - Image: © Steven Kay (CC BY-SA 2.0)
Plaintext:   c  a  f  e
Keyword:     B  A  D  B
Ciphertext:  ?  ?  ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Steven Kay (CC BY-SA 2.0)
Plaintext:  >c< a  f  e
Keyword:    >B< A  D  B
Ciphertext: >D< ?  ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Steven Kay (CC BY-SA 2.0)
Plaintext:   c >a< f  e
Keyword:     B >A< D  B
Ciphertext:  D >A< ?  ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Steven Kay (CC BY-SA 2.0)
Plaintext:   c  a >f< e
Keyword:     B  A >D< B
Ciphertext:  D  A >C< ?
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Steven Kay (CC BY-SA 2.0)
Plaintext:   c  a  f >e<
Keyword:     B  A  D >B<
Ciphertext:  D  A  C >F<
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Steven Kay (CC BY-SA 2.0)

DACF!

How about decryption?

© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)
Plaintext:   ?  ?  ?  ?
Keyword:     B  A  D  B
Ciphertext:  D  A  C  F
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Asparukh Akanayev (CC BY 2.0)
Plaintext:  >c< ?  ?  ?
Keyword:    >B< A  D  B
Ciphertext: >D< A  C  F
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Asparukh Akanayev (CC BY 2.0)
Plaintext:   c >a< ?  ?
Keyword:     B >A< D  B
Ciphertext:  D >A< C  F
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Asparukh Akanayev (CC BY 2.0)
Plaintext:   c  a >f< ?
Keyword:     B  A >D< B
Ciphertext:  D  A >C< F
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Asparukh Akanayev (CC BY 2.0)
Plaintext:   c  a  f >e<
Keyword:     B  A  D >B<
Ciphertext:  D  A  C >F<
A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C
E E F A B C D
F F A B C D E
© Course authors (CC BY-SA 4.0) - Image: © Asparukh Akanayev (CC BY 2.0)

Kerckhoffs' principle

The security of a cipher
must be based on the chosen key,
not keeping the algorithm secret
(AKA "security through obscurity")

© Course authors (CC BY-SA 4.0) - Image: © Sergei F (CC BY 2.0)

Symmetric cryptography

Same key is used for encryption and decryption.

Asymmetric cryptography

Different keys are used for
encryption and decryption.
Can also be used for "digital signatures".

Cryptographic hash functions

The same plaintext always result in
the same ciphertext, but the ciphertext
should not be reversable to plaintext
(AKA "One-way encryption").

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

Symmetric cryptography

Used primarily for protecting confidentiality
of information at rest and in transit.

Modern ciphers operators on bits,
not letters (typically using XOR operator).

Most symmetric ciphers are categorized
as block ciphers or stream ciphers.

© Course authors (CC BY-SA 4.0) - Image: © Wendelin Jacober (CC0 1.0)

Block ciphers split plaintext data into
parts of a fixed size and encrypts
each part/block separately.

Most commonly used for
"at rest" encryption.

DES is bad example and
AES is a good one.

© Course authors (CC BY-SA 4.0) - Image: © Mike Grauer Jr (CC BY 2.0)

Stream ciphers performs encryption of
each bit in a stream of plaintext.

Most commonly used for
"in transit" encryption.

RC4 is bad example and
ChaCha20 is a good one.

© Course authors (CC BY-SA 4.0) - Image: © Scott Merrill (CC BY-SA 2.0)

The US government entity
National Institute of
Standards and Technology
are heavily involved standardization
of cryptography.

They are responsible for
Federal Information
Processing Standards,
such as FIPS 46-3 (DES) and FIPS 197 (AES).

Modern cryptographic algorithms
are commonly audited/chosen through
international competitions.

© Course authors (CC BY-SA 4.0) - Image: © Kristina Hoeppner (CC BY-SA 2.0)

Let's move forward!

© Course authors (CC BY-SA 4.0) - Image: © Jonathan Torres (CC BY 4.0)

Symmetric encryption tools

Let there be demos!

© Course authors (CC BY-SA 4.0) - Image: © Fritzchens Fritz (CC0 1.0)

Simple file encryption

$ cat my_secrets.txt 
I didn't shoot the sheriff...

$ ccrypt --encrypt --key "hunter2" my_secrets.txt 
$ file my_secrets.txt.cpt 
my_secrets.txt.cpt: data

$ ccrypt --decrypt --key "hunter2" my_secrets.txt.cpt
$ cat my_secrets.txt 
I didn't shoot the sheriff...
© Course authors (CC BY-SA 4.0) - Image: © Fritzchens Fritz (CC0 1.0)

LUKS

  • Standard for encryption at the block layer
  • "Full Disk Encryption" on Linux
  • Supports multiple "keyslots"
  • Typically used via the "cryptsetup" CLI utility
© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

BitLocker

  • Introduced in Windows Vista (2007)
  • Not available in "Home" editions*
  • Supports encryption of boot and data drives
© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

VeraCrypt

  • Fork of "TrueCrypt"
  • FOSS and publicly audited
  • Cross-platform/Multi OS support
  • Supports encryption of boot*, data drives and "virtual devices"
© Course authors (CC BY-SA 4.0) - Image: © Jonathan Torres (CC BY 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

XKCD: 538

© Course authors (CC BY-SA 4.0) - Image: © Helsinki Hacklab (CC BY 2.0)

KeePassXC

  • Offline password/secrets manager
  • FOSS and cross-platform
  • Compatible with other KeePass variants*
© Course authors (CC BY-SA 4.0) - Image: © George N (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

Up1

  • Web-based file hosting service
  • FOSS!
  • Try it at "Riseup Share"
  • Performs cryptography tasks in the browser ("client-side")
© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

share.riseup.net/#6nV4VONZwLr7nhBkd5gML

© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

Bonus tip! ("fulhack")

© Course authors (CC BY-SA 4.0) - Image: © RoboticSpider (CC BY 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

Symmetric security

Good, bad and the ugly

© Course authors (CC BY-SA 4.0) - Image: © Scott Skippy (CC BY-SA 2.0)

We want our encryption to be...

  • Fast to use, slow to break
  • Safe against "known-plaintext" attacks
  • Immune to frequency analysis
© Course authors (CC BY-SA 4.0) - Image: © Scott Skippy (CC BY-SA 2.0)

Keys are key

Symmetric ciphers depend on a key for
encryption and decryption.

Fixed size(s) in bits,
defined per algorithm.

© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)

Key != Password.

Typically created using a
Random Number Generator or
Key Derivation Function
(more about these later).

© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

Example key sizes

  • DES: 56 bits
  • 3DES: 168 bits
  • AES: 128, 192 or 256 bits
  • ChaCha20: 128 or 256 bits

What do these numbers mean?!

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

A two bit key can be either
"00", "01", "10" or "11" (4 possibilities).

A four bit key can be either
"0000", "0001", "0011", "0111", "1111",
"1000", "1100", "1110", "1111", "1001"...
(16 possibilities).

A fifty-six bit key can be arranged in
72 057 594 037 927 936 possible ways!

© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

Seventy-two quadrillion,
fifty-seven trillion,
five hundred and ninety-four billion,
thirty-seven million, nine hundred and
twenty-seven thousand and nine hundred
and thirty-six.

© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

With one guess per second,
it would take 2283368000 years.

The difficulty of key size
doesn't scale linearly.

Sorry, humans -
that's waaay out of your league!

Is this a big number for computers?

© Course authors (CC BY-SA 4.0) - Image: © The Preiser Project (CC BY 2.0)

Cracking DES

Got a gaming rig at home?
An Nvidia 4090 GPU can try
~six billion keys per second.

The ten-year old "crack.sh-system".
can try ~seven-and-a-half trillion
keys per second.

That's the whole key-space in
twenty-six hours! \o/

© Course authors (CC BY-SA 4.0) - Image: © Asparukh Akanayev (CC BY 2.0)

26 hours < 2283368000 years.

© Course authors (CC BY-SA 4.0) - Image: © Randy Adams (CC BY-SA 2.0)

Size doesn't matter (that much)

Larger keys are nice,
but with diminishing returns
and performance penalties.

How much more secure is AES 256
compared to AES 128?

Design issues in algorithms and
faulty implementations are the
primary ways modern cryptography
is broken.

3DES keys are 168 bits, but in
practice only provides 112 bits.

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

But AES is fine right?
Isn't it MILITARY GRADE ENCRYPTION?

Let me introduce you to block cipher modes.

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

AES cipher modes

  • ECB
  • CBC
  • PCBC
  • CFB
  • CCM
  • GCM
  • XTS

....

© Course authors (CC BY-SA 4.0) - Image: © Kevin Dooley (CC BY 2.0)

CBC

Oldie but goldie typically okay!

XTS

Most commonly used for
Full Disk Encryption.

GCM

Fast and integrity protected,
but tricky to implement from scratch.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Many block cipher modes exist.

Most are in practice okay - avoid ECB!

Typically require a randomly generated
Initialization Vector that
should not be lost or reused
(AKA "nonce").

Except for lab purposes,
don't roll your own crypto!

© Course authors (CC BY-SA 4.0) - Image: © Asparukh Akanayev (CC BY 2.0)

Reflections exercise

What we learned so far?

© Course authors (CC BY-SA 4.0) - Image: © Jon Evans (CC BY 2.0)

Answer the following questions

  • What are your most important take-aways?
  • Did you have any "Ahaaa!"-moments?
  • Was anything unclear or were there specifics you didn't understand?

courses+crypto_010901@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Jon Evans (CC BY 2.0)

Bonus task

Already finished all other labs/tasks?

Attach an additional (virtual) disk to
your lab system and utilize cryptsetup
to setup Full Disk Encryption
with keyslots for a password and a "key file".

Format volume as EXT4 and send lab notes to
courses+crypto_010902@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Sbmeaper1 (CC0 1.0)

Cryptographic hashing

AKA "one-way encryption"

© Course authors (CC BY-SA 4.0) - Image: © David Revoy (CC BY 3.0)

Before we dig into cryptographic hashing,
let's talk about check digits and checksums.

© Course authors (CC BY-SA 4.0) - Image: © Gytis B (CC BY-SA 2.0)

Check digits provide input error detection.

Used for credit card numbers, Bitcoin addresses, patient identifiers, social security numbers...

The Luhn algorithm is a common solution.

© Course authors (CC BY-SA 4.0) - Image: © Gytis B (CC BY-SA 2.0)

Checksums allows data integrity verification.

Detect if information/files have been corrupted during network transfer or disk storage.

The same input data should always result in the same output checksum.

CRCs are commonly utilized.

© Course authors (CC BY-SA 4.0) - Image: © Gytis B (CC BY-SA 2.0)
$ cksum /etc/passwd
1530034959 1930 /etc/passwd

$ echo "Polar bears are cool" | cksum
3234477472 21
© Course authors (CC BY-SA 4.0) - Image: © Gytis B (CC BY-SA 2.0)
$ echo "Polar bears are cool" | cksum
3234477472 21

$ echo "Polar beers are cool" | cksum
3688108819 21
© Course authors (CC BY-SA 4.0) - Image: © Gytis B (CC BY-SA 2.0)

The downsides

Different input values may produce the same output checksum.

Not likely a problem, unless someone actively tries to find collisions.

Used to attack data authenticity controls.

Cryptographic hashing to the rescue!

© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)

Cryptographic hash functions are like checksums,
but designed to never collide in practice.

Produces a digest as output,
more commonly called "hash".

Output shouldn't be predictable,
unless fully computed.

Output shouldn't help you guess
contents of input data.

The output digest will be the same size
regardless if input data is 1kB or 10TB.

© Course authors (CC BY-SA 4.0) - Image: © Mauricio Snap (CC BY 2.0)
$ echo "Polar bears are cool" | sha256sum
09c123f289f05677dbfa38dad697ae86ab2f3ef25c8935cfc8cd68a59f2f4d0a

$ echo "Polar beers are cool" | sha256sum
f170488bc43c691d3b9055567952d05d1cd43fbebd54c2098a0d5d7685d2eaa1

$ head --bytes 5G /dev/zero | sha256sum
7f06c62352aebd8125b2a1841e2b9e1ffcbed602f381c3dcb3200200e383d1d5
© Course authors (CC BY-SA 4.0)

Use-cases for hashing

  • Data integrity checking
  • Password storage/validation
  • Authentication
  • Fingerprinting
  • Pseudo-random number generators
  • Append-only databases/ledgers
  • Proof of Knowledge
  • Proof of Work

....

© Course authors (CC BY-SA 4.0) - Image: © Mauricio Snap (CC BY 2.0)

Notable families

  • MD: Historically common, now broken
  • SHA: Standards specified by NIST
  • BLAKE: Commonly used in KDFs
© Course authors (CC BY-SA 4.0) - Image: © Mauricio Snap (CC BY 2.0)

Like other cryptography methods, hashing algorithms have a best-before date.

Check out "SHAttered":

$ shasum shattered-1.pdf 
38762cf7f55934b34d179ae6a4c80cadccbb7f0a

$ shasum shattered-2.pdf 
38762cf7f55934b34d179ae6a4c80cadccbb7f0a

If you wanna learn more about collision techniques and play with them, have a look at:
github.com/corkami/collisions.

© Course authors (CC BY-SA 4.0) - Image: © Elly Jonez (CC BY 2.0)

TL;DR

Avoid MD4, MD5 and SHA-1.

SHA-2 (AKA SHA256), SHA-3 (AKA Keccak)
and BLAKE* are fine!

© Course authors (CC BY-SA 4.0) - Image: © Elly Jonez (CC BY 2.0)

Hashing for integrity validation

© Course authors (CC BY-SA 4.0) - Image: © Kojach (CC BY 2.0)

Running "shasum" to get file hashes - is that it?

Let's take a look at some example use-cases.

© Course authors (CC BY-SA 4.0) - Image: © Kojach (CC BY 2.0)

FIM

Background services continuously checking hashes of executables, configuration files, etc.

Commonly used as a detection mechanism for malicious/unapproved systems changes.

Wanna give it a try? Take a look at:

© Course authors (CC BY-SA 4.0) - Image: © Jeena Paradies (CC BY 2.0)

Runtime allow-listing

Let's take it one step further - block execution of binaries that doesn't match permitted hashes.

Enables enforcement of computer usage policies and several forms of malware.

Checkout Airlock Digital and
fapolicyd.

© Course authors (CC BY-SA 4.0) - Image: © Wolfgang Stief (CC0 1.0)

Software download mirrors

Lots of FOSS projects rely on third-party mirror sites for downloads as bandwidth is not free.

Mirrors may be compromised or run by a malicious actor that modifies executables.

Hashes can be published on a project's official website to mitigate the problem.

© Course authors (CC BY-SA 4.0) - Image: © Martin Fisch (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0)

Supply-chain security

Most systems/code bases rely on software published by a vendor or FOSS project.

Remote modification of dependencies could lead malicious code being baked into the application.

Pinning using hashes is common solution:

$ docker pull hashicorp/vault:1.12.4@sha256:03d1[...]5cda
© Course authors (CC BY-SA 4.0) - Image: © David Revoy (CC BY 3.0)

A small sample of how cryptographic hashing
can be utilized to protect data integrity.

Questions? :-)

© Course authors (CC BY-SA 4.0) - Image: © Kojach (CC BY 2.0)

Symmetric encryption exercise

Can you crack the cipher?

© Course authors (CC BY-SA 4.0) - Image: © Jan Hrdina (CC BY-SA 2.0)

Vigenère cipher

Manually decrypt ciphertext "DACFDBBDEFEC"
using the key "BAD"

A B C D E F
A A B C D E F
B B C D E F A
C C D E F A B
D D E F A B C

courses+crypto_011201@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Jan Hrdina (CC BY-SA 2.0)

Hashing for password storage

© Course authors (CC BY-SA 4.0) - Image: © Lord Jaraxxus (CC BY-SA 4.0)

What happens when we login to a website?

  1. Client submit their username and password
  2. Server checks if the submitted password matches the one stored for the user
© Course authors (CC BY-SA 4.0) - Image: © Lord Jaraxxus (CC BY-SA 4.0)

Okay, so the server must store all passwords.

Can't we just symmetrically encrypt them?

© Course authors (CC BY-SA 4.0) - Image: © Nicholas A. Tonelli (CC BY 2.0)

Server needs plaintext passwords
to enable comparison.

Encrypted data must be "unlocked",
which means that the key is typically
stored on disk or in memory.

Sounds scary.

© Course authors (CC BY-SA 4.0) - Image: © Nicholas A. Tonelli (CC BY 2.0)

Storing passwords using hashing

The same hash function input data should always result in the same output, right?

Wasn't a nick-name for hashing
"one-way encryption"?

© Course authors (CC BY-SA 4.0) - Image: © Rod Waddington (CC BY-SA 2.0)

Pseudo-code for password hashing

if (
sha256($submitted_password) ==
$stored_password_hash) {

	accept_login()

} else {
	deny_login()
}
© Course authors (CC BY-SA 4.0) - Image: © Rod Waddington (CC BY-SA 2.0)

Boom! Let's call it day, shall we?

Not quite.

© Course authors (CC BY-SA 4.0) - Image: © Jennifer Morrow (CC BY 2.0)

Problems with basic password hashing

Users using the same password will have the generated same hash.

Hashes can be pre-calculated ("rainbow tables").

© Course authors (CC BY-SA 4.0) - Image: © Jennifer Morrow (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0)

Problems with basic password hashing

Users using the same password will have the same hash.

Hashes can be pre-calculated ("rainbow tables").

© Course authors (CC BY-SA 4.0) - Image: © Jennifer Morrow (CC BY 2.0)

Let me introduce you to salting!

Random data mixed into the password hashing.

© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

Pseudo-code for password hashing

if (
sha256($stored_salt + $submitted_password) ==
$stored_password_hash) {

	accept_login()

} else {
	deny_login()
}
© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

Salt should be...

  • Quite random
  • Unique per user
  • Accessible to application in plaintext
© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

Operating systems use it too

$ sudo head --lines 1 /etc/shadow

root:$y$j9T$P.lVRC/J.KNiBHMob7uli[...]

$ man shadow

© Course authors (CC BY-SA 4.0) - Image: © Fandrey (CC BY 2.0)

Choosing the right hash function

Guessing the password that matches a hash
("hash cracking") should require lots of compute.

The same hash function can be used multiple times
("rounds") to increase cost.

Consider using a purpose built solution,
like Argon2 or
yescrypt.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Doesn't fully mitigate the risks of password theft.

An attacker with system access may be able to modify the application to log password input.

© Course authors (CC BY-SA 4.0) - Image: © Andrew Hart (CC BY-SA 2.0)

Client-side hashing

Effectively turns generated hash into a password.

Allows server to never gain access to plaintext password, minimizing consequences of breach.

Beware that the client-side code can be modified by a compromised server in web apps.

© Course authors (CC BY-SA 4.0) - Image: © Bruno Cordioli (CC BY 2.0)

Password hashing lab

© Course authors (CC BY-SA 4.0) - Image: © David Revoy (CC BY 4.0)

Lab description

Graded exercise to implement hashing of passwords in simple web application.

For detailed instructions, see:
"resources/labs/pwd_hash/README.md".

Remember the deadline and
lab report requirements.

© Course authors (CC BY-SA 4.0) - Image: © David Revoy (CC BY 4.0)

Proof of Knowledge

An introduction of hashing for PoK

© Course authors (CC BY-SA 4.0) - Image: © David Revoy (CC BY 3.0)

Why do we sometimes see
people tweet or toot out a hash?

© Course authors (CC BY-SA 4.0) - Image: © David Revoy (CC BY 3.0)
$ echo "${SALT} Looptroop killed Palme" | shasum

f2f095c3b414335fdf98ed96f128e37705dca7ce
© Course authors (CC BY-SA 4.0) - Image: © Jesse James (CC BY 2.0)

Why not just use symmetric encryption
and publish the key when time arrives?

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Most cryptographically secure hashes
are fixed-length.

Knowledge of terabytes can be proven with
a short string that fits inside a toot/tweet/SMS.

© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

Uses for authentication

Remote authentication without
sending password over network.

One-time/rolling passwords.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Pseudo-code for hash authentication

$challenge = get_auth_challenge($username)
$response = sha256($challenge + $password)

login($challenge, $response)
© Course authors (CC BY-SA 4.0) - Image: © Bruno Cordioli (CC BY 2.0)

Rolling password (counter-based)

$counter = $counter + 1
$one_time_code = sha256($counter + $password)

login($username, $one_time_code)
© Course authors (CC BY-SA 4.0) - Image: © Rick Harris (CC BY-SA 2.0)

Rolling password (time-based)

$time = get_current_minute()
$one_time_code = sha256($time + $password)

login($username, $one_time_code)

(somewhat similar to the
"Time-based One-time Password" standard,
used by applications like Google Authenticator)

© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

Many other use-cases exist -
this is just an appetizer.

If you wanna play around
and got the time, check out
"resources/labs/extras/otp_auth/README.md".

© Course authors (CC BY-SA 4.0) - Image: © Lars Juhl Jensen (CC BY 2.0)

Proof of Work

An introduction of hashing for PoW

© Course authors (CC BY-SA 4.0) - Image: © ORNL (CC BY 2.0)

What enables email spam,
and how could we solve it?

© Course authors (CC BY-SA 4.0) - Image: © ORNL (CC BY 2.0)

Anyone can send anyone a message
at (almost) zero cost.

© Course authors (CC BY-SA 4.0) - Image: © Nicholas A. Tonelli (CC BY 2.0)

Couldn't we just charge a tiny fee per message?

How would you even implement that?

Any other ways we could introduce cost?

© Course authors (CC BY-SA 4.0) - Image: © Jason Thibault (CC BY 2.0)

Computations require processing.

Processing requires hardware and electricity.

Hardware and electricity ain't free!

© Course authors (CC BY-SA 4.0) - Image: © OLCF at ORNL (CC BY 2.0)

Calculating a hash requires
quite many CPU cycles.

How can we prove that the user has
wasted processing power on hashing?

© Course authors (CC BY-SA 4.0) - Image: © Roy Luck (CC BY 2.0)

Let's steal a few tricks from
hash-based authentication!

© Course authors (CC BY-SA 4.0) - Image: © Kuhnmi (CC BY 2.0)

Sender:
I got some email for you!

Receiver:
Stop right there! Before I accept your email,
I want you to provide a hash of some data
prefixed with "fiskburk" that ends with "ff".

Sender:
Okay - hold on a second... *crunching*...
If I hash "fiskburk24077-29047-32326"
I get a hash ending with "ff"!

Receiver:
I get the same result -
handover that email, will you?

© Course authors (CC BY-SA 4.0) - Image: © Rob Hurson (CC BY-SA 2.0)

Costly to find proof,
but cheap to very!*

© Course authors (CC BY-SA 4.0) - Image: © Martin Fisch (CC BY 2.0)

resources/misc/pow.sh

#!/usr/bin/env bash

# Validate that at least two command line arguments are provided
if [[ -z "${2}" ]]; then
	echo "Usage: ${0} <PREFIX_SEED> <EXPECTED_SUFFIX>"
	exit 1
fi

PREFIX_SEED="${1}"
EXPECTED_SUFFIX="${2}"

# Loop until solution for PoW is found
time while true; do
	# Grab some random data to include in hash calculation
	INPUT_DATA="${RANDOM}-${RANDOM}-${RANDOM}"

	# Hash specified seed together with random input data, only include hash from output
	HASH="$(echo -n ${PREFIX_SEED} ${INPUT_DATA} | sha256sum | cut -d ' ' -f 1)"

	# If the suffix of the generated hash matches the specified suffix, challenge is solved
	if [[ "${HASH}" == *${EXPECTED_SUFFIX} ]]; then
		echo "${EXPECTED_SUFFIX}: sha256(${PREFIX_SEED} + ${INPUT_DATA}) == ${HASH}"
		# Stop loop once finished
		break
	fi
done
© Course authors (CC BY-SA 4.0)
$ resources/misc/pow.sh
Usage: resources/misc/pow.sh <PREFIX_SEED> <EXPECTED_SUFFIX>

$ resources/misc/pow.sh "asdasdasdasd" "ff"

ff: sha256(asdasdasdasd + 16083-12281-837) == d60ee[...]3b13e1ff
real	0m0.138s

$ resources/misc/pow.sh "asdasdasdasd" "fff"

fff: sha256(asdasdasdasd + 22132-31048-7135) == 3be[...]37371fff
real	0m22.333s

$ resources/misc/pow.sh "asdasdasdasd" "ffff"

ffff: sha256(asdasdasdasd + 19378-5998-4075) == fb8[...]370ffff
real	1m23.770s
© Course authors (CC BY-SA 4.0)

Other use-cases

  • Online rate-limiting
  • Alternative to captcha
  • Anti-scraping
  • "Mining" in cryptocurrencies

Whatever you can imagine!

© Course authors (CC BY-SA 4.0) - Image: © Marco Verch (CC BY 2.0)

Done with your other tasks
and wanna try implementing PoW?

Modify the client and server
from "pwd_hash" lab to utilize
PoW instead of/in addition to
password-based authentication.

courses+crypto_011601@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Fritzchens Fritz (CC0 1.0)

Reflections exercise

What we learned so far?

© Course authors (CC BY-SA 4.0) - Image: © Carl Davies, CSIRO (CC BY 3.0)

Answer the following questions

  • What are your most important take-aways?
  • Did you have any "Ahaaa!"-moments?
  • Was anything unclear or were there specifics you didn't understand?

courses+crypto_011701@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Carl Davies, CSIRO (CC BY 3.0)

Course recap

Basics, symmetric crypto and hashing

© Course authors (CC BY-SA 4.0) - Image: © Jesse James (CC BY 2.0)

Cryptography helps us ensure
confidentiality, authenticity and integrity
of information.

Steganography is a related practice in which information is hidden/obscured.

These have historically been used in unison.

© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)

Symmetric ciphers

AES and ChaCha20 are good options.

Stay away from (3)DES and RC4.

Key Derivation Functions are
used to generate fixed-size keys from passwords.

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

AES and other block-ciphers
supports several different
"cipher modes".

The "ECB" mode is generally considered insecure.

In addition to a key and plain-/cipher-text, most
modes require an "initialization vector"
for secure operations.

© Course authors (CC BY-SA 4.0) - Image: © Filippo Valsorda (CC BY-SA 4.0)

Cryptographic hash functions are like checksums,
but designed to never collide in practice
(different inputs shouldn't produce same output).

A digest (AKA "hash") shouldn't help an
attacker guess the input/"plain text" data.

The output hash will be the same size regardless
if input data is 1kB or 10TB.

© Course authors (CC BY-SA 4.0) - Image: © ESA (CC BY 3.0 IGO)

The "Secure Hash Algorithm"-family
of hash functions are standardized by NIST.

SHA-2 (AKA "SHA256") is still widely used.
SHA-3 (AKA "Keccak") is recommended
for new sensitive applications.

Avoid SHA-1 and especially MD* algorithms
as they suffer from known security flaws.

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Hashes are commonly used for
ensuring the integrity of data
(detect manipulation).

Some examples are
File Integrity Monitoring systems
and "software allow-listing" applications.

© Course authors (CC BY-SA 4.0) - Image: © Brendan J (CC BY 2.0)

Password hashing is used to avoid
storing passwords in plaintext.

Users using the same password will
have the generated same hash.

Hashes can be pre-calculated
("rainbow tables").

To mitigate these issues, passwords are salted
(mixed with other data) before being hashed.

In order to avoid handling users "real passwords",
"client-side hashing" may be utilized in unison.

© Course authors (CC BY-SA 4.0) - Image: © Fredrik Rubensson (CC BY-SA 2.0)

Hashes can be used for
Proof of Knowledge.

Provide proof that you know
something without disclosing it.

Commonly used in authentication protocols,
similar to "Time-based One-time Password".

© Course authors (CC BY-SA 4.0) - Image: © Alan Levine (CC0 1.0)

Hashes can be used for
Proof of Work.

Perform computationally-expensive
hashing to find a digest containing
some peer-specified data/pattern.

Costly to produce, cheap to verify.

Enables things like bot/spam protection,
rate-limiting and cryptocurrencies.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Challenge

Find some input data with the prefix
"quite_r4ndom" that produces a
hex digest ending with "4e".

Attempts

hash(quite_r4ndom-abc123) == 3e64[...]ca
hash(quite_r4ndom-abc124) == 910c[...]1c
[...]
hash(quite_r4ndom-abc982) == aad6[...]4e

Result

859 rounds of hashing to solve challenge,
1 round to verify it.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Cryptography tools won't hold
their promises forever.

There are always "best-before" dates.

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

Asymmetric cryptography

A somewhat gentle introduction

© Course authors (CC BY-SA 4.0) - Image: © RoboticSpider (CC BY 4.0)

Also known as "public-key cryptography".

Spooks and researches have been
using it since the late 70s.

Requires usage of electronic computers
(sorry, humans!).

© Course authors (CC BY-SA 4.0) - Image: © RoboticSpider (CC BY 4.0)

This is not a math course.

We won't cover how the
algorithms actually work
under the hood.

Neither do we need to,
thankfully!

© Course authors (CC BY-SA 4.0) - Image: © Greg Lloy (CC BY 2.0)

A key pair consists of a
private key and a public key.

Holder of the private key
can decrypt and sign/authenticate data.

The corresponding public key
can be used to encrypt data and
verify authenticity of signed data.

The ability to sign/decrypt data
can be used for authentication
(prove "ownership" of private key).

© Course authors (CC BY-SA 4.0) - Image: © Greg Lloy (CC BY 2.0)

RSA is a commonly
used asymmetric algorithm.

Created by Rivest, Shamir and Adleman.

Not to be confused with
the company "RSA Security".

Patented in 1983,
freely usable since 2000.

Algorithm/Implementation guidance described
in Public-Key Cryptography Standards #1.

Typically key size is between 512 bit (weak)
and 8192 bit (overkill).

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

Wait a second, those are much
larger than the keys used
for symmetric algorithms!

Unlike when used by symmetric ciphers,
not all combinations of bits are
possible to use as keys.

To get a better idea, we can check out
NIST's table of "security levels".

TL;DR: 2048 bits OK-ish, >=3072 recommended.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Digital Signature Algorithm.

Standardized by NIST in 1994,
usable without license trouble.

Focused on signatures/authentication,
not encryption.

Several design flaws and
insufficient key size - avoid it!

© Course authors (CC BY-SA 4.0) - Image: © Nick Watts (CC BY-SA 2.0)

Solutions based on
Elliptic-Curve Cryptography
are steadily replacing RSA.

ECDSA, for example.

It's faster, requires smaller keys and
is generally considered easier
to correctly/safely implement.

RSA still has better
software/hardware support.

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)
$ time ssh-keygen -q -N '' \
  -t rsa -f /tmp/key_rsa

real	0m1.022s

$ time ssh-keygen -q -N '' \
  -t ed25519 -f /tmp/key_ed

real	0m0.008s
© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)
$ cat /tmp/key_rsa.pub | cut -d ' ' -f 2 
AAAAB3NzaC1yc2EAAAADAQABAAABgQC0KDu1jlpyMbqGNAU5NEPmN8LXNeybJHRHiLHg
aMRVTsmOsQzBlQhC8GAxHCvrQDpfqDVRtp0eepJtYTHuu7RZPOvHEMH7U35/xP/jRUMM
Z81k1DAQ6LoezQKj7bKJuvJo3P/JTdrWwMVejwNAXL4IIDce3G/TQx6HQlF3YmW8hCFZ
j30frRqVPF/KT9Zgh4IyeEdWnlAP0bLA9x/lvsZuTDIGy3D89aPW41z0jQbcVVFips1v
QGWrSQZYGgBeX8TUqTcg0Zuu9K19MZx6Jdnu+Qdxukk+omkDmSODvRQ6U/LGY3Cx8NEY
fZZfeXo+TVmKHUQwNntuvpW074UqVedOfrrN8lsJmnjjPivXG2MHVF6fDAYe0WubPUEv
ZZIzyTZFEOpt9tPeOg6s38mhF/cgr17p8lapMHx4HFn0ljlgejgKNzm5rI4AqNWjgj1+
HvcX3BkhU91xDiTV5sAIqAPddk3ePsiFZiBpvzrlQagiY+VNf/VJq8x4vN98aTtGMqc=

$ cat /tmp/key_ed.pub | cut -d ' ' -f 2 
AAAAC3NzaC1lZDI1NTE5AAAAIFmgY7uVLZqx/tOLPJ22JBi7TAJwmmClu66+mb2sOfUA
© Course authors (CC BY-SA 4.0)

Several different "curves" can be utilized.
(~think different algorithms).

Common examples are
NIST P-256/P-384 and
Curve25519.

For some (biased) guidance,
checkout the "SafeCurves" project.

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

Asymmetric cryptography
is relatively slow.

Most often combined with
hashing (digital signatures) and
symmetric cryptography (key exchange).

Curious about how these type of
algorithms actually work?
Check out "KidRSA".

© Course authors (CC BY-SA 4.0) - Image: © RoboticSpider (CC BY 4.0)

Certificates and trust models

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Asymmetric cryptography enables us to
share secrets and sign/validate data
without a shared secret key.

But how do we get hold of the
public key of our peer?

(both other humans and network services)

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)
$ ssh 141.95.102.166

The authenticity of host '141.95.102.166 (141.95.102.166)' can't be established.
ED25519 key fingerprint is SHA256:wzzjNa+3VIhoxAEc1W9KfWzW8APaB3O6OSBFki66jEU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
© Course authors (CC BY-SA 4.0)
$ for KEY in /etc/ssh/ssh_host_*_key.pub; do ssh-keygen -l -f "${KEY}"; done

1024 SHA256:IrBaPa6k+uPe1SMeshWaX8SMomgCxWthfjxtR0jjBfY root@w2 (DSA)
256 SHA256:VBBjYJyshoJU1x63APDVjTyzZu8TG4XUGGu1HxMEXSM root@w2 (ECDSA)
256 SHA256:wzzjNa+3VIhoxAEc1W9KfWzW8APaB3O6OSBFki66jEU root@w2 (ED25519)
3072 SHA256:4CiF9f8vMP2a8cGG5OjW0lmH1xWMXwgwjx9oUvPzYbI root@w2 (RSA
© Course authors (CC BY-SA 4.0)

What does the "known_hosts" file
created by our SSH client contain?

Hostnames/IP addresses ("server identities")
and "key fingerprints" (hash of public key).

(the "server identities" are often hashed
to minimize information disclosure if
file is stolen/leaked)

© Course authors (CC BY-SA 4.0) - Image: © Egill Egilsson (CC BY 2.0)

We can't go around and ask everyone/everything
on the Internet what their public key is.

Mayhaps your bank could write it on a sign
in their lobby, but what about
a random web shop?

There must be a better way...

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Common "trust models"

  • None ("YOLO!")
  • Trust On First Use (TOFU)
  • Certificates and Certificate Authorities (CA)
  • Web of Trust (WoT)
© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

TOFU

$ ssh -o StrictHostKeyChecking=accept-new 141.95.102.166
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Common "trust models"

  • None ("YOLO!")
  • Trust On First Use (TOFU)
  • Certificates and Certificate Authorities (CA)
  • Web of Trust (WoT)
© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

What are "certificates"?

sign(public key + metadata)

Only requires us to know the
signer's public key in advance.

Examples of metadata:

  • Identity (hostname, email, etc)
  • Portrait photo
  • Expiry date
© Course authors (CC BY-SA 4.0) - Image: © Elly Jonez (CC BY 2.0)

Common standards

  • X.509
  • SSH certificates
  • OpenPGP
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Certificate Authorities

Trust store contains public keys which are
blessed to sign other certificates.

Web of Trust

Any key can sign others certificates,
users can choose how to "weight" keys
and how much risk they are willing to take.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)
center
© Course authors (CC BY-SA 4.0)

We'll re-visit this topic and
take a deeper look at how X.509
utilize certificate authorities
to establish trust.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Asymmetric cryptography

A somewhat quick recap

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Symmetric

Same key is used for encryption and decryption.

Asymmetric

Different keys are used for encryption and decryption.

© Course authors (CC BY-SA 4.0) - Image: © Fritzchens Fritz (CC0 1.0)

An asymmetric key pair consists of a
public key and a private key.

The private key can be used by
the key holder to decrypt and
digitally sign data.

The public key can be used by
anyone to encrypt and
verify signed data.

© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)

The most common solutions are RSA and
those based on Elliptic-Curve Cryptography.

RSA keys bigger than 2048 bits are
usually considered acceptable,
but NIST recommends 3072.

ECC is more resource efficient and
easier to correctly/safely implement
than RSA - thereby replacing it.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Several different curves are available for ECC.

Common examples are
NIST P-256/P-384 and Curve25519.

For guidance, checkout the "SafeCurves" project.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

A certificate (typically) contains
a public key and metadata.

Examples of metadata are expiry time
and "identities" tied to the key,
such as an email address or a DNS hostname.

They are cryptographically signed
by one or more third-parties,
depending on trust model.

© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)

Any questions? :-)

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Tool demonstration: age

Lean and mean file encryption

© Course authors (CC BY-SA 4.0) - Image: © Jonathan Miske (CC BY-SA 2.0)

What is "age"?

  • FOSS tool (and format) for symmetric and asymmetric file encryption
  • Fast and modern (~secure)
  • Compatible with (some) SSH keys
  • Support for key storage on hardware token
© Course authors (CC BY-SA 4.0) - Image: © Jonathan Miske (CC BY-SA 2.0)

Generate key pair

$ age-keygen | tee my_private.key

AGE-SECRET-KEY-1MQ5U9HTKKAP[...]Y92RTHKH7ASQ5LVL2Q
$ age-keygen -y my_private.key | tee my_public.key

age14z423we7r3ze5rkjy4[...]uwfy9pxxvmnxy2yrq6rr74p
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Let's encrypt some data

$ cat secret.txt

I shot the sheriff :-/
$ cat secret.txt | \
	age --encrypt --recipients-file my_public.key \
	> secret.txt.age
© Course authors (CC BY-SA 4.0)

...and decrypt it

$ cat secret.txt.age | \
	age --decrypt --identity my_private.key \
	> secret.txt
$ cat secret.txt

I shot the sheriff :-/
© Course authors (CC BY-SA 4.0)

Encrypt to multiple keys

$ cat alice.key.pub bob.key.pub | tee friends.keys

age1uw4mjkc9ma5tvs5[...]2ywm69kru2rspacst0jdnczqacx2s5
age1eut64dvujqfmw6e[...]uuddd7hdxsrw3csu3dzh6amswhyr3v
$ cat secret.txt | \
	age --encrypt --recipients-file friends.keys \
	> secret.txt.age
© Course authors (CC BY-SA 4.0)

Generate / store key on YubiKey

$ age-plugin-yubikey \
	--generate \
	--pin-policy never \
	--touch-policy always \
	> my_yubikey.plugin

[...]

! Please touch the YubiKey
Recipient: age1yubikey1q0[...]q6
© Course authors (CC BY-SA 4.0) - Image: © Yubinerd (CC BY-SA 4.0)

Encrypt and decrypt data using YubiKey

$ age-plugin-yubikey \
	--identity --slot $SLOT > my_yubikey.pub

$ cat secret.txt | \
	age --encrypt --recipients-file my_yubikey.pub \
	> secret.txt.age
$ cat secret.txt.age | \
	age --decrypt --identity my_yubikey.plugin \
	> secret.txt
	
! Please touch the YubiKey
© Course authors (CC BY-SA 4.0)

Wanna give it a spin?

Try replacing tar/7-Zip in the
"sym_crypt" lab backup script with age!

Take it a step further and use your
YubiKey for storing the private key.

courses+crypto_012201@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Jonathan Miske (CC BY-SA 2.0)

OpenPGP basics

Pretty Good Privacy since 1991

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

What is PGP?

Tool suite for asymmetric cryptography
developed by Phil Zimmermann
in the early 90s.

"OpenPGP" acts as the umbrella for
attempts to formally standardize PGP.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Common use-cases for PGP

Securing message-based communication
methods, such as E2E for email.

File encryption.

Software authenticity validation on Linux.

© Course authors (CC BY-SA 4.0) - Image: © Indrora (CC BY 2.0)

Used for package metadata signing

$ cat /etc/apt/sources.list.d/github-cli.list 

deb [signed-by=/etc/keys/github.pub] https://cli.github.com/packages stable main
© Course authors (CC BY-SA 4.0)

OpenPGP certificates are signed ("certified")
by the "key holder" and potentially others.

Pioneered the "Web of Trust model for
identity/certificate validation.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Implementations

  • GnuPG: Swiss army knife, AKA "GPG"
  • Sequoia: Modern CLI tools and Rust libraries
  • GopenPGP: PGP in your Go applications
  • OpenPGP.js: Client- and server-side library
© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)

'Nuff talk, more demos.

© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)

Let me introduce you to "sq"!

$ sq --help

sq 0.25.0 (sequoia-openpgp 1.7.0)
A command-line frontend for Sequoia,
an implementation of OpenPGP
[...]
© Course authors (CC BY-SA 4.0)

Key / certificate generation

$ sq key generate \
	--userid 'Test Labsson <test@example.com>' \
	--export test.private \
	--expires-in 5y 

$ sq key extract-cert test.private --output test.cert 
© Course authors (CC BY-SA 4.0)

Basic file encryption

$ cat todo.md 

## My TODO list
- [X]: Learn about PGP
- [ ]: Conquer the world

$ cat todo.md | sq encrypt \
	--recipient-cert test.cert \
	> todo.md.pgp
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Basic file decryption

$ cat todo.md.pgp | \
	sq decrypt \
	--recipient-key test.private 

Encrypted using AES with 256-bit key
Compressed using ZIP

## My TODO list
- [X]: Learn about PGP
- [ ]: Conquer the world
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Digitally signing a message

$ cat proclamation.txt

I hereby promise to never put
meatballs in my nose again!

$ cat proclamation.txt | \
	sq sign \
	--cleartext-signature \
	--signer-key test.private \
	> proclamation.txt.pgp
© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)

Digitally signed message

$ cat proclamation.txt.pgp

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

I hereby promise to never put
meatballs in my nose again!

-----BEGIN PGP SIGNATURE-----

wr0EARYKAG8FgmQX9m0JELNUBDJO1RxQAA
LnNlcXVvaWEtcGdwLm9yZzku8htwo/JCHZ
FiEEo62bZCb5bbX3wxfDs1QEOm7UAAHJnA
EY3QZRMCQZ8S5CwDUgEAqtSrWEvEa[...]
-----END PGP SIGNATURE-----
© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)

Verifying signed message

$ cat proclamation.txt.pgp | \
	sq verify \
	--signer-cert test.cert 

Good signature from B354043A692893B5
1 good signature.

I hereby promise to never put
meatballs in my nose again!
© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)

Let's create some more test keys

$ for NAME in alice bob charlie; do 
	sq key generate \
		--userid "${NAME} <${NAME}@example.com>" \
		--expires-in 5y --export "${NAME}.private"

	sq key extract-cert \
		"${NAME}.private" \
		--output "${NAME}.cert"
done
© Course authors (CC BY-SA 4.0)

Multi-signing a message

$ cat the_truth.txt

Oceania was at war with Eastasia

$ cat the_truth.txt | \
	sq sign \
	--signer-key alice.private \
	> the_truth.txt.pgp
$ cat the_truth.txt.pgp | \
	sq sign \
	--signer-key bob.private \
	--append | \
	sponge the_truth.txt.pgp
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Verify multi-signed message

$ cat the_truth.txt.pgp | \
	sq verify \
	--signer-cert alice.cert \
	--signer-cert bob.cert \
	--signer-cert charlie.cert

Good signature from F89E9C4294F51777
Good signature from 5CF0C96FD9C6DC05
2 good signatures.

Oceania was at war with Eastasia
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Verify multi-signed message

$ cat the_truth.txt.pgp | \
	sq verify \
	--signer-cert alice.cert \
	--signer-cert bob.cert \
	--signer-cert charlie.cert \
	--signatures 3

Good signature from F89E9C4294F51777
Good signature from 5CF0C96FD9C6DC05
2 good signatures.
Error: Verification failed
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Certify third-party key

$ sq certify \
	alice.private \
	charlie.cert \
	'charlie <charlie@example.com>' | \
	sponge charlie.cert

$ sq certify \
	bob.private \
	charlie.cert \
	'charlie <charlie@example.com>' \
	--amount 60 | \
	sponge charlie.cert
© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Peaking at the certificate

$ sq inspect --certifications charlie.cert 

charlie.cert: OpenPGP Certificate.

Fingerprint: 63887435C2B865DBBA537AA0BC80AE1A45B83D65
Public-key algo: EdDSA Edwards-curve Digital Signature Algorithm
[...]
UserID: charlie <charlie@example.com>
Alleged certifier: D36E658BA221819AD35F80484047E2EF12270FAD
Alleged certifier: 06FE1C00440DD227E7EAE81B1B2D8E573AD890CF
[...]
© Course authors (CC BY-SA 4.0)

Create a keyring

$ sq keyring join --output alice.keyring *.cert

$ sq keyring list alice.keyring

0. 06FE1C0[...]573AD890CF alice@example.com
1. D36E658[...]EF12270FAD bob@example.com
2. 6388743[...]1A45B83D65 charlie@example.com
© Course authors (CC BY-SA 4.0)

But wait a minute, how do I know
that a key for test@example.com
belongs to the real Test Labsson?

© Course authors (CC BY-SA 4.0) - Image: © Jan Helebrant (CC0 1.0)

Strategies for key verification

  • Praying / hoping for the best
  • Key signing parties
  • Web of Trust
  • DOIP / Keyoxide
© Course authors (CC BY-SA 4.0) - Image: © Jan Helebrant (CC0 1.0)
center
© Course authors (CC BY-SA 4.0)

Just for cool cats/terminal dwellers?

Let me introduce you to Gpg4win.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Gpg4win

  • GnuPG: Where the magic happens
  • Kleopatra: GUI for management/encryption
  • GpgOL: Integration for Outlook and Office
  • GpgEX: Add-on for file explorer

FOSS with professional support available.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

Hope this piqued your interest.

All tools (except the original PGP) described
are freely available for you to play with.

Grab a few classmates and
try creating a "Web of Trust".

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

X.509 basics

A somewhat gentle introduction

© Course authors (CC BY-SA 4.0) - Image: © Kristoffer Trolle (CC BY 2.0)

What is "X.509"?

Standard for cryptographic certificates.

When people talk about "PKI",
they typically talk about X.509.

Used for encrypted/signed email ("S/MIME"),
securing key exchange in network protocols,
validating software authenticity and similar.

© Course authors (CC BY-SA 4.0) - Image: © Kristoffer Trolle (CC BY 2.0)

CSR

Certificate Signing Request, contains public key
and metadata to be included in certificate signing.

CA

Certificate Authority, key pair used to sign
other certificates after some validation.

© Course authors (CC BY-SA 4.0) - Image: © Matthias Ripp (CC BY 2.0)

Truststore

File containing public keys for trusted CAs,
typically shipped with OS/applications.

Root CA

Included in truststores, typically only used
for signing intermediate CAs. Very sensitive.

Intermediate CA

CA whose certificate is signed by another CA,
commonly used to sign client/server CSRs.

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

CRL

Certificate Revocation List, signed file listing
certificates which should no longer be trusted.

OCSP

Online Certificate Status Protocol,
like CRL but provided as a network service.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

FOSS tools

  • OpenSSL CLI: Toolbox for all-things X.509
  • Easy-RSA: Handy wrapper for OpenSSL CA
  • CFSSL: Server/CLI tools for setting up a CA
© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

We'll use CFSSL CLI tools
in the following demos.

Try to keep things simple,
only rely on a root CA
(no intermediate CA).

© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

Generate base configuration file

$ mkdir my_ca && cd my_ca
$ cfssl print-defaults config > config.json
[...]
"profiles": {
  "server": {
    "expiry": "2160h",
    "usages": [
      "signing",
      "key encipherment",
      "server auth"
    ]
  }
}
[...]
© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

ca-csr.json

{
  "CN": "My Lab Certificate Authority",
  "key": {"algo": "ecdsa", "size": 256},
  "ca": {"expiry": "26298h"},
  "names": [
    {
      "C": "SE",
      "L": "Stockholm",
      "O": "Department Of Labs"
    }
  ]
}
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Generate CA certificate / key

$ cfssl gencert -initca ca-csr.json | cfssljson -bare ca

2023/03/03 13:37:42 [INFO] generating a new CA key and certificate from CSR
2023/03/03 13:37:42 [INFO] generate received request
2023/03/03 13:37:42 [INFO] received CSR
2023/03/03 13:37:42 [INFO] generating key: ecdsa-256
2023/03/03 13:37:42 [INFO] encoded CSR
2023/03/03 13:37:42 [INFO] signed certificate with serial number 23[...]301

$ ls *.csr *.pem

ca.csr ca.pem ca-key.pem
© Course authors (CC BY-SA 4.0)

my_server-csr.json

{
  "CN": "my-server.example.test",
  "hosts": [
    "my-server.example.test",
    "localhost"],
  "names": [
    {
      "C": "SE",
      "L": "Stockholm",
      "O": "Department Of Labs",
      "OU": "Server Management Team"
    }
  ]
}
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Generate server certificate / key

$ cfssl gencert \
	-config config.json -profile server \
	-ca ca.pem -ca-key ca-key.pem \
	my_server-csr.json | cfssljson -bare my_server

[...]
2023/03/03 13:38:42 [INFO] signed certificate
with serial number 23[...]302

$ ls *.csr *.pem

my_server.csr my_server.pem my_server-key.pem
© Course authors (CC BY-SA 4.0)

Quite neat! But now what?

Let's take the certificate for a
spin using the Caddy web server.

© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

Configure and restart web server

$ ls /etc/caddy/
Caddyfile  my_server-key.pem  my_server.pem

$ cat /etc/caddy/Caddyfile 

https://localhost {
  tls /etc/caddy/my_server.pem /etc/caddy/my_server-key.pem
  respond "Here comes all the juicy secrets!"
}

$ sudo systemctl restart caddy.service
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

Let's do it programmatically!

#!/usr/bin/env python3
import requests

response = requests.get(
    'https://localhost',
    verify='ca.pem'
)

print(response.text)
$ ./app.py

Here comes all the juicy secrets!
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

X.509 for software signing

© Course authors (CC BY-SA 4.0) - Image: © Kristoffer Trolle (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

Digging into certificates

$ openssl x509 -in my_server.pem -text

Version: 3 (0x2)
Serial Number:
  63:f2:19:d6:bd:[...]:d7:01:fe:c6
Signature Algorithm: ecdsa-with-SHA256
Issuer:
  C = SE, L = Stockholm,
  O = Department Of Labs,
  CN = My Lab Certificate Authority
Validity
    Not Before: Mar 19 17:02:00 2023 GMT
    Not After : Jun 17 17:02:00 2023 GMT
[...]
X509v3 extensions:
    X509v3 Key Usage: critical
        Digital Signature, Key Encipherment
    X509v3 Basic Constraints: critical
        CA:FALSE
    X509v3 Subject Alternative Name: 
        DNS:my-server.example.test, DNS:localhost
[...]
© Course authors (CC BY-SA 4.0)

Transport Layer Security

An introduction to SSL / TLS

© Course authors (CC BY-SA 4.0) - Image: © Bret Bernhoft (CC0 1.0)

Network traffic may be intercepted.

Malicious actors can manipulate and
spy on sensitive communication.

How can we protect it?

© Course authors (CC BY-SA 4.0) - Image: © Bret Bernhoft (CC0 1.0)

Secure Sockets Layer was
introduced by Netscape in the late 90s
to enable e-commerce/"exciting things".

Wraps existing clear text TCP protocols,
like HTTP and SMTP, with a layer of encryption.

Replaced by Transport Layer Security,
properly standardized by the IETF.

Protects confidentiality and integrity
of network communication at the
OSI model's "presentation layer"
("application layer" in TCP/IP).

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

TLS typically use...

  • X.509 for "identity validation"
  • Asymmetric cryptography for key exchange
  • Symmetric encryption for confidentiality
  • Hashing for integrity protection

Different combinations algorithms
are known as "cipher suites".

TLS 1.2 supports 37 different ones,
TLS 1.3 merely 5.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Example cipher suites

TLS_RSA_EXPORT_WITH_RC4_40_MD5

TLS_DHE_RSA_WITH_AES_128_CBC_SHA256

TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305

TLS_GOSTR341112_256_WITH_NULL_GOSTR3411
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Configuring a web server

$ cat /etc/caddy/Caddyfile 

https://localhost {
  tls /etc/caddy/my_server.pem /etc/caddy/my_server-key.pem
  respond "Let me tell you a secret, friend!"
}
© Course authors (CC BY-SA 4.0)

Configuring a client

#!/usr/bin/env python3
import requests

response = requests.get('https://localhost', verify='ca.pem')

print(response.text)
© Course authors (CC BY-SA 4.0)

What is "mTLS"?

In TLS, both connection peers
(client and server) may
present certificates.

We call this "mutual TLS", AKA
"client-certificate authentication".

Can be used as replacement
for username + password login,
application can grab user identifier
from the certificate's common name.

(similar to "key authentication" in SSH)

© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

my_ca/config.json

[...]
"profiles": {
  "server": {
    "expiry": "2160h",
    "usages": [
      "signing",
      "key encipherment",
      "server auth"
    ]
  },
  "client": {
    "expiry": "8760h",
    "usages": [
      "signing",
      "key encipherment",
      "client auth"
    ]
  }
}
[...]
© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

Reconfigure Caddy for mTLS

$ cat /etc/caddy/Caddyfile 

https://localhost {
  tls /etc/caddy/my_server.pem /etc/caddy/my_server-key.pem {
    client_auth {
      mode require_and_verify
      trusted_ca_cert_file /etc/caddy/ca.pem
    }
  }
  respond "Let me tell you a secret, {tls_client_subject}!"
}
© Course authors (CC BY-SA 4.0)

Access denied!

#!/usr/bin/env python3
import requests

response = requests.get(
    'https://localhost',
    verify='ca.pem'
)

print(response.text)
$ ./app.py

[...]
SSL: SSLV3_ALERT_BAD_CERTIFICATE
© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

Configure client certificate

#!/usr/bin/env python3
import requests

response = requests.get(
    'https://localhost',
    verify='ca.pem',
    cert=(
        'my_client.pem',
        'my_client-key.pem'
    )
)

print(response.text)
© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

Access granted!

$ ./app.py

Let me tell you a secret,
CN=my_client,OU=User Support Team,
O=Department Of Labs,L=Stockholm,C=SE!
© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0)

Unfortunately, browsers typically don't
support directly importing PEM files
with the client certificate/key.

We need to package them into a
PKCS #12 archive first.

$ openssl pkcs12 \
	-in my_client.pem \
	-inkey my_client-key.pem \
	-export -out my_client.p12
© Course authors (CC BY-SA 4.0) - Image: © Loco Steve (CC BY-SA 2.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

Wrapping up

TLS provides a relatively simple method
for wrapping clear text protocols
in a "layer of encryption" and
enables mutual authentication.

Supports different combinations of
algorithms using "cipher suites".

Several different versions exist,
avoid SSL and TLS version <1.2.

Designed for TCP, use DTLS for UDP.

© Course authors (CC BY-SA 4.0) - Image: © Bret Bernhoft (CC0 1.0)

X.509 / TLS lab

© Course authors (CC BY-SA 4.0) - Image: © Rising Damp (CC BY 2.0)

Lab description

Graded exercise to setup a X.509 CA
and protect a web server using mTLS.

For detailed instructions, see:
"resources/labs/x509_tls/README.md".

© Course authors (CC BY-SA 4.0) - Image: © Rising Damp (CC BY 2.0)

X.509 / TLS recap

© Course authors (CC BY-SA 4.0) - Image: © ESA (CC BY 3.0 IGO)

X.509 is a standard for
cryptographic certificates ("PKI").

These certificates contain a public key
and metadata, such as expiry time
and "identity information" like a
hostname or email address.

Relies on certificate authorities
to sign/certify certificates.

© Course authors (CC BY-SA 4.0) - Image: © Peter Black (CC BY-SA 2.0)

Certificates for root CAs are typically included
in OS/application trust stores.

© Course authors (CC BY-SA 4.0) - Image: © Peter Black (CC BY-SA 2.0)

Used for encrypted/signed email ("S/MIME"),
securing key exchange in network protocols,
validating software authenticity and similar.

© Course authors (CC BY-SA 4.0) - Image: © Peter Black (CC BY-SA 2.0)

TLS is used to secure
network communication
between client and server
applications.

Replaces the outdated SSL protocol,
an acronym that has become a synonym.

Commonly used to wrap/tunnel
cleartext protocols like
HTTP(S) and SMTP(S).

© Course authors (CC BY-SA 4.0) - Image: © Kuhnmi (CC BY 2.0)

Mutual TLS ("mTLS") is used to
authenticate both peers in
a session (client and server).

© Course authors (CC BY-SA 4.0) - Image: © Kuhnmi (CC BY 2.0)

TLS typically use...

  • X.509 for "identity validation"
  • Asymmetric encryption for key exchange
  • Symmetric encryption for confidentiality
  • Hashing for integrity protection

Different combinations of these
(symmetric, asymmetric and hashing algorithms)
are known as "cipher suites".

© Course authors (CC BY-SA 4.0) - Image: © Kuhnmi (CC BY 2.0)

Network encryption tools

Working one to seven

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Network traffic can be intercepted
anywhere between your phone in a café
and TikTok's fancy data center in Shenzhen.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0) - Image: © TeleGeography (CC BY-SA 4.0)

Cryptography is used to protect confidentiality and integrity of communication.

We've talked about TLS, let's have a look at the other network layers.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

OSI model recap

  1. Physical layer
  2. Data link layer
  3. Network layer
  4. Transport layer
  5. Session layer
  6. Presentation layer
  7. Application layer

Common vocabulary, not reality.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Alternative: "TCP/IP model"

  1. Application layer
  2. Transport layer
  3. Internet layer
  4. Data link layer
  5. Physical layer

OCI model still acts as Interlingua.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

"L1": Signal level encryption

Used to protect high-bandwidth/legacy links.

"Transparent encryption" provided by pricey HW.

Easy to implement, suitable for legacy networks and compliance checkboxes.

© Course authors (CC BY-SA 4.0) - Image: © Bret Bernhoft (CC0 1.0)

"L2": MACsec / IEEE 802.1AE

Open standard extending Ethernet with encryption.

Supported in fancy switches at line-rate.

Uses AES-GCM for confidentiality and integrity.

© Course authors (CC BY-SA 4.0) - Image: © Jan Hrdina (CC BY-SA 2.0)

"L3": IPsec

Family of open standards to provide a
secure version of IP.

Supported by most OSes and network appliances.

Act in "host-to-host" or "routed" mode.

Quiet a mess with gazillion different options for
encryption, integrity checking and authentication.

© Course authors (CC BY-SA 4.0) - Image: © Nacho Jorganes (CC BY-SA 2.0)

"L4-L6": QUIC

Performant alternative to TCP initially developed by Google.

Uses UDP and a subset of TLS version 1.3.

~Used by HTTP version 3.

© Course authors (CC BY-SA 4.0) - Image: © Fritzchens Fritz (CC0 1.0)

Let's talk about VPNs!

© Course authors (CC BY-SA 4.0) - Image: © Jesse James (CC BY 2.0)

Virtual Private Network.

Creates a virtual network link between computers.

Access is restricted and traffic encrypted.

"Site-to-site" or "user-to-site".

© Course authors (CC BY-SA 4.0) - Image: © Jesse James (CC BY 2.0)

What about VPNs for anonymity?

Network traffic is routed through VPN provider and forwarded to the Internet.

Typically sold as penicillin for security, don't believe the marketing.

© Course authors (CC BY-SA 4.0) - Image: © Jesse James (CC BY 2.0)

What about VPNs for anonymity?

Network traffic is routed through VPN provider and forwarded to the Internet.

Typically sold as penicillin for security, don't believe the marketing.

© Course authors (CC BY-SA 4.0) - Image: © Jesse James (CC BY 2.0)

Give me some examples!

© Course authors (CC BY-SA 4.0) - Image: © Jesse James (CC BY 2.0)

IPsec in "routed" mode

© Course authors (CC BY-SA 4.0) - Image: © Jesse James (CC BY 2.0)

OpenVPN

Oldie but goldie!

Supports tunneling of L2 and L3 traffic.

PSK or X.509 for peer authentication.

Supports storing client credentials
on HW token such as the YubiKey.

Tons of configuration options,
for better or worse.

© Course authors (CC BY-SA 4.0) - Image: © Mathias Appel (CC0 1.0)

WireGuard

Fast, modern and minimal.

Only L3.

Built-in support in Linux and *BSD kernels.

© Course authors (CC BY-SA 4.0) - Image: © Fritzchens Fritz (CC0 1.0)

Enterprise VPN appliances

Physical and virtual appliances
providing VPN functionality.

Easy setup and lots of
management tools.

Often decent cryptography,
but riddled with other vulnerabilities.

You don't want your
edge security products to be broken.

© Course authors (CC BY-SA 4.0) - Image: © Bixentro (CC BY 2.0)

Which option should I choose?

Well, that depends on your use-case -
likely more than one!

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Onion routing

A tear-free introduction

© Course authors (CC BY-SA 4.0) - Image: © Dan Revoy (CC BY 4.0)

VPN providers claim to offer bullet-proof anonymity and protection against hackers.

Things are not that simple, as we've talked about.

© Course authors (CC BY-SA 4.0) - Image: © Dan Revoy (CC BY 4.0)

Hmmm... can't we just run a VPN tunnel
inside another VPN tunnel?

© Course authors (CC BY-SA 4.0) - Image: © Dan Revoy (CC BY 4.0)

Onion routing

Technique for anonymous
messaging/communication over a network.

Protects the source address of the sender.

Relies on heavily on asymmetric cryptography.

© Course authors (CC BY-SA 4.0) - Image: © Dan Revoy (CC BY 4.0)

Ada wants to send a message to Dan without
revealing her identity (source IP address).

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Ada knows the public keys for
Bob, Charlie and Dan.

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Ada encrypts her message against
Dan's public key:

I know what you did last summer.

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Ada encrypts the encrypted message for Dan against Charlie's public key
with a message added:

Please forward this to Dan!

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Ada encrypts the encrypted message for Charlie against Bob's public key with a message added:

Please forward this to Charlie!

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Inner layer

Encrypted against Dan's public key:

I know what you did last summer.

Middle layer

Encrypted against Charlie's public key:

Please forward this to Dan!

Outer layer

Encrypted against Bob's public key:

Please forward this to Charlie!

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Message transfer

  1. Ada sends encrypted message to Bob
  2. Bob decrypts the outer layer and forwards the message to Charlie
  3. Charlie decrypts the middle layer and forwards the message to Dan
  4. Dan decrypts the inner layer and is terrified that his secret is known
© Course authors (CC BY-SA 4.0)

Bob knows that Ada (or rather her source address) wants to send an encrypted message to Charlie.

Charlie knows that Bob sent him an encrypted message that should be forwarded to Dan.

Dan knows that he got an encrypted message from Charlie.

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Bob can't tell that he is "first" in
the forwarding chain.

Granted that chain members aren't gossiping with each other, Ada's involvement remains unknown
to Charlie and Dan.

We could lower the risk by involving
Erin and Frank.

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Sounds neat! But can I actually use it?

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Meet the "Tor project"

Largest onion routing network.

Thousands of relays run by volunteers forward encrypted traffic around the globe.

Provides anonymous access to the Internet and "hidden/onion services".

Best enjoyed with Tails or Whonix.

© Course authors (CC BY-SA 4.0) - Image: © Kenny Cole (CC BY 2.0)

Be aware that...

  • Relays can collaborate to lower anonymity
  • "Exit nodes" can (and do) intercept traffic
  • Usage may by itself be incriminating
  • It is damn slow!
© Course authors (CC BY-SA 4.0) - Image: © Kenny Cole (CC BY 2.0)

Reflections exercise

What we learned so far?

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

Answer the following questions

  • How could PoW be used to combat spam?
  • Why do some backup solutions make use of public key cryptography?
  • Why do software devs publish file hashes?
  • Why is asymmetric cryptography used for "COVID vaccination certificates" printed on paper?

Take the chance to be a bit --verbose!

courses+crypto_013001@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

Password cracking

Introduction to tools and techniques

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Passwords -
can't live with 'em, can't live without em -
am I right, right?

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Online VS Offline cracking.

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

In this course, we'll focus on offline cracking.

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

It's all about the hashes

Passwords are typically stored using
one-way hash functions.

Keys for symmetric encryption are typically generated by a KDF (basically a hash function).

Asymmetric private keys are often stored using symmetric cryptography.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

How do operating systems
store user credentials?

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Linux / UNIX password storage

Historically, "/etc/passwd" used to contain the
(weakly) hashed passwords for users on a system.

These days salted and hashed passwords are
stored in "/etc/shadow".

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

$ head -n 2 /etc/shadow

root:$6$JMmGEYGBqvCpg.w5$eDg[...]LiUc/:19443:0:::::
bob:$6$t/k/DNYlcQYMgVNJ$PvGi[...]zUA0:19443:0:99999:7:::

What the heck?

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Each line of this file contains
9 fields, separated by colons (“:”)

$ man shadow

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Shadow file fields

  • Login name
  • "Encrypted password"
  • Date of last password change
  • Minimum password age

[...]

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Refer to crypt(3) for details on
how this string is interpreted.

— "Encrypted password field" section

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

"Encrypted" password for root user

$6$t/k/DNYlcQYMgVNJ$PvGi[...]zUA0

Sub-fields explained

$hash_type$salt$password_hash
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Hash types

  • "1": MD5
  • "2a": Blowfish
  • "2y": Eksblowfish
  • "5": SHA-256 crypt
  • "6": SHA-512 crypt
    ....
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Many applications store passwords
in similar ways, often in a SQL database.

SELECT * FROM user_accounts;

| email           | salt     | hash     |
|-----------------|----------|----------|
| ada@example.com | feab40e1 | fca77c63 |
| bob@example.com | ca1481bb | ca1481bb |
© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Widows password storage

Credentials for local and "cached" users are
stored in the "SAM database".

Also loves storing credentials for authenticated users in memory.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

What the hash?!

LM or NTLM/NTHash

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

LM "hash"

Window's legacy method for storing passwords.

Disabled by default in Windows Vista,
but still lingers around in some
enterprise environments.

Why replace it, you may ask?

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

LM "hash"

  1. Convert all lower case to upper case
  2. "Pad" password to 14 characters with NULL characters, if needed
  3. Split the password to two 7 character chunks
  4. Create two DES keys from each chunk
  5. DES encrypt the string "KGS!@#$%" with each chuck as the key
  6. Concatenate the two DES encrypted strings.
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

NTLM/NTHash

Current method used to store passwords.

The secret sauce?

md4(password)

Notice anything odd?

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

For all things related to stealing
credentials on a Windows box,
checkout Mimikatz.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

How does "password/hash cracking work?

  1. Calculate hash for password candidate
  2. Compare computed hash with stored hash
  3. If equal, you've likely found the password, if not repeat with new candidate.
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Hash cracking tools

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

When you say "fast", what does that mean?

Well, let's run a test with a RTX 4090:

$ hashcat --benchmark-all
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

The results

Hash function Crack rate
SHA512 7409 MH/s
SHA1 37901 MH/s
MD5 164 GH/s
NTLM/NTHash 288 GH/s
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Let's throw a few of 'em in a server!

What's that - can't afford it?

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

For ~2$/per hour you can get a "g5.12xlarge"
which cracks 368 GH/s of NTLM/NTHash.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

That's neat, but can we get away cheaper?

There are some other people who have
showed great interest in abusing GPUs...

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0)

(288GH * 8) * 3600 ==
~8294 TH!

For $2.3, you get
eight quadrillion
two hundred ninety-four trillion
four hundred billion
attempts to break a
Windows password hash.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Beware of the risks when cracking
hashes on other peoples' computers.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Can we make it go even faster?

FPGAs and ASICs to the rescue!

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0)

Putting things in perspective

Bitcoin uses SHA2-256.

RTX 4090 * 5 can do ~110 GH/s.
S21 Hyd. can do ~355000 GH/s.

Brasklapp: PoW != Password cracking.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Our only option isn't just to
throw more compute at the problem.

We can crack smarter.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Example of permutations

  • Prepend/Append years
  • Change letter casing
  • Prepend/Append "lucky numbers"
  • Convert letters to leet-speak
  • Prepend/Append one + exclamation mark
  • Prepend/Append "keyboard row sequences"
    ....
© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Curious to learn more and
perfect the art of password cracking?

Check out previous talks
from "PasswordCon"!

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Password cracking lab

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Lab description

Graded exercise to recover cleartext passwords from stored hashes.

For detailed instructions, see:
"resources/labs/pwd_crack/README.md".

Remember to read the guidance!

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Attacking Net-NTLM

Abusing protocol design flaws

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Proof of Knowledge is used in
many network authentication protocols.

Was especially popular before
SSL/TLS became commonly used.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Meet NTLMv1 / NTLMv2

Authentication mechanism popular in
Windows environments.

Provides seamless authentication for access to file shares, internal web applications, etc.

Relies on challenge/response to avoid sending credentials in clear-text.

© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

Wait a second - wasn't "NTLM"
used for password hashing?

© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

Well, yes. It's confusing.

NTMLM / NTHash: Password storage.

NTLMv1 / NTLMv2: Network authenticaiton.

To keep things simple, usually called
Net-NTLMv1 / Net-NTLMv2.

© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

Authentication flow: Net-NTLMv1

  1. User connects to network server
  2. Server responds with eight random bytes as an authentication challenge
  3. User takes their password hash, splits it up and use it as keys to DES encrypt the challenge
  4. Server takes stored password hash for user and performs the same procedure
  5. If client challenge response matches server generated result, consider user authenticated
© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

Authentication flow: Net-NTLMv2

  1. User connects to network server
  2. Server responds with eight random bytes as a "server challenge"
  3. User generates eight random bytes as a "client challenge"
  4. User responds with ~md5(password hash + server/client challenge) and client challenge
  5. Server calculate ~md5(stored password hash + server/client challenge)
  6. If client response matches server generated result, consider user authenticated
© Course authors (CC BY-SA 4.0) - Image: © Egill Egilsson (CC BY 2.0)

Hmmm, doesn't seem right?

© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

We just turned the password hash into a
password equivalent.

© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

Furthermore, eight random bytes, DES and MD5 doesn't sound like a solid foundation.

© Course authors (CC BY-SA 4.0) - Image: © Guilhem Vellut (CC BY 2.0)

At least we can't just sniff network traffic and reuse the client response for impersonation.

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Let me introduce you to
"NTLM relaying attacks".

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

I mentioned the
seamless authentication thing, right?

Server challenge doesn't actually contain any information about the server's identity.

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

NTLM relaying attack

  1. Attacker sets up malicious website
  2. Victim user connects to malicious site
  3. Attacker connects to target server
  4. Target server returns challenge
© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

NTLM relaying attack

  1. Attacker website returns the same challenge to the victim user
  2. Victim user generates challenge response
  3. Attacker takes response from victim user and reuse it against the target server
  4. Target server validates that challenge response, attacker is authenticated as victim user.
© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Doesn't necessarily require user interaction -
Windows loves likes to do it by itself!

Some mitigations available,
but usually not enforced!

If you wanna play around, check out
"responder" on GitHub.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Randomness

Uses in cryptography and security

© Course authors (CC BY-SA 4.0) - Image: © Julie Cotinaud (CC BY-SA 2.0)

We rely on randomness to keep competitions
fun and fair (and legal, in some cases).

Predictable VS Random.

Human actions/choices are quite predictable,
tools like dice and tombolas can help us.

© Course authors (CC BY-SA 4.0) - Image: © Julie Cotinaud (CC BY-SA 2.0)

The security of computer systems
often rely on it as well.

Generation of salt/IV,
site-unique passwords,
asymmetric private keys,
ephemeral symmetric keys...

Digital computers are however
designed to be very predictable.

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

Yet we can run Math.random(). But how?

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

To help us fight predictability,
we rely on Random Number Generators.

Despite their name, they often produce
(more or less) random bits.

RNGs are typically divided into a few
different categories, depending on their
implementation and security promises...

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

PRNG

Pseudo-random AKA
"Not really but let's pretend".

Can be implemented in pure software.

Fast and useful to make things fun,
unsuitable for security applications.

© Course authors (CC BY-SA 4.0) - Image: © Jusotil_1943 (CC0 1.0)

CSPRNG

Cryptographically secure pseudo-randomness.

Relies on multiple semi-unpredictable inputs,
such as mouse movement, CPU temperature,
disk latency and WiFi signal strength.

~AKA "sources of entropy".

Guessing the state of one input may
be trivial, but not all at the same time.

© Course authors (CC BY-SA 4.0) - Image: © Mike Grauer Jr (CC BY 2.0)

HWRNG

Hardware Random Number Generator.

Let some external device provide
us with those random bits.

Provided by modern chipsets/CPUs,
typically quite fast!

TRNG

Measuring something we think is
"truly random", like radioactive decay.

Purpose-built peripherals,
some available as "open hardware".

© Course authors (CC BY-SA 4.0) - Image: © Yellowcloud (CC BY 2.0)

You got a HWRNG in your pocket!

$ gpg-connect-agent --hex "SCD RANDOM 1000" /bye

D[0000]  63 F8 73 4A 25 32 35 B0  21 3F 57 [...]
© Course authors (CC BY-SA 4.0) - Image: © Yubinerd (CC BY-SA 4.0)

In practice, we typically utilize a
HWRNG as an entropy input to a CSPRNG.

The more sources of unpredictable
input, the better output randomness!

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Many PRNGs need an initial seed
to get started producing output.

(what we use our multiple inputs for)

We can abuse this to generate
"deterministic randomness"! :S

Useful for key derivation and creating
easily sharable worlds in Minecraft!

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

You want some decent randomness on Linux?

Use /dev/random or /dev/urandom.

$ head \
    --bytes 1000 /dev/random \
    > /tmp/unpredictable_bytes

/dev/random may (temporarily) run out
of random data - unless you're very
paranoid, utilize /dev/urandom instead.

© Course authors (CC BY-SA 4.0) - Image: © Ninara (CC BY 2.0)

Sometimes your CSPRNG need a bit of
extra help gathering its initial seed.

Freshly spawned virtual machines in
the public cloud are a common example.

Checkout "RNG forwarding",
Pollinate and
Haveged.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Wrapping up

Unpredictable randomness is a key
component in computer security.

Don't rely on a home-grown RNG,
unless you're doing it for fun!

Standard libraries in programming
languages typically provide both
a PRNG and a CSPRNG - make sure
you know which one you're using!

© Course authors (CC BY-SA 4.0) - Image: © Julie Cotinaud (CC BY-SA 2.0)

Group exercise

Putting knowledge to use

© Course authors (CC BY-SA 4.0) - Image: © Martin Fisch (CC BY 2.0)

Exercise: Sell 'em crypto!

Participants are split into four or more groups.

Group members should discuss how cryptography
could be used to help a fictional organization.

Focus on the specific organization's needs and
challenges. Try involving as much cryptography
as possible, modify the scenario if needed.
Suggest use of specific tools, if applicable.

After presentation, send your fancy slides to
courses+crypto_013501@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Martin Fisch (CC BY 2.0)

Fictional organizations

  1. Exemplum Press
  2. Xample Industries
  3. Department of Examples
  4. Examplify Inc.
© Course authors (CC BY-SA 4.0) - Image: © Martin Fisch (CC BY 2.0)

Org. 1: Exemplum Press

  • Works with investigative journalism, focusing on rich and politically powerful individuals
  • Has journalists and sources spread all over the world, including in "hostile countries"
  • Publishes their news and "news flashes" using many different channels (X, TikTok, etc.)
  • Wants to help readers from "hostile countries" to access their news safely
  • Wants to offer the ability for anonymous whistleblowers to share sensitive information

(feel free to extend fictional scenario!)

© Course authors (CC BY-SA 4.0)

Org. 2: Xample Industries

  • Well-established company in "heavy-manufacturing"
  • Designs and builds digital equipment for the mining industry
  • Relies on legacy IT systems spread over multiple sites for the manufacturing line
  • Utilizes software from third-party vendors in their products
  • Worries about industrial espionage and intrusions affecting production capacity

(feel free to extend fictional scenario!)

© Course authors (CC BY-SA 4.0)

Org. 3: Department of Examples

  • Spy agency working with intelligence gathering
  • Provides sensitive information to governmental agencies, diplomats and foreign allies
  • Has agents and sources spread all over the world that need to report information securely
  • May only utilize free software due to budget restraints enforce by CATZ

(feel free to extend fictional scenario!)

© Course authors (CC BY-SA 4.0)

Org. 4: Examplify Inc.

  • Consultancy company with employees spread all over the world
  • Works with software development and maintenance of IT systems for payroll management
  • Needs remote access to customer environments for support
  • Has many employees in sales and support roles with limited technical skills
  • Worries about economically motivated hackers and insider threats

(feel free to extend fictional scenario!)

© Course authors (CC BY-SA 4.0)

Key management

Protecting storage and usage of keys

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

We talk about Alice, Bob and Charlie.

They are merely key holders
(and hopefully the only ones).

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Revocation is not perfect.

May not be a practical option.

How do you even know that a key has been compromised?

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Let's slap some symmetric encryption on the asymmetric private key!

Key may still be stolen by malware
once decrypted.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Should we change key every time a team member or sysadmin leaves/becomes untrusted?

Should we really trust everyone equally?

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Meet the CAB!

CA/Browser Forum.

Sets baseline security/policy requirements for CAs that want to be included in trust stores.

If you're a public CA and the forum doesn't like you, you're in big trouble.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0) - Image: © CA/Browser Forum (CC BY-SA 4.0)

Some try to push things a bit further,
like Google with Certificate Transparency.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)
center
© Course authors (CC BY-SA 4.0)
center
© Course authors (CC BY-SA 4.0)

"Hardware Security Module"

Purpose designed hardware devices
for cryptographic operations.

Typically used to generate/store keys
and sign/decrypt data.

Comes in many shapes and sizes:

  • Rack units
  • Key fobs
  • Smart / SIM cards
© Course authors (CC BY-SA 4.0)

Security promise

Keys that are generated and/or stored in HSM may never leave.

© Course authors (CC BY-SA 4.0)

Secure key storage

Device should be tamper resistant.

Device should not leak key material through
side-channels (see "TEMPEST").

© Course authors (CC BY-SA 4.0)

Restricted key usage

Key operations may be restricted by
authentication requirements,
rate limiting, datetime, etc.

PIN code/password, biometrics, "two-man rule",
actual physical keys, etc.

Logging of all usage.

© Course authors (CC BY-SA 4.0)

They may even be quite fast!

© Course authors (CC BY-SA 4.0)

YubiKey

Continuously improved for ~15 years.

Built to survive on your keyring.

Manufactured in Sweden and USA.

Well-supported by applications and community.

© Course authors (CC BY-SA 4.0) - Image: © Yubinerd (CC BY-SA 4.0)

Nitrokey

Open source SW and HW design.

Made in Germany.

Upgradable firmware.

© Course authors (CC BY-SA 4.0)

Let's try 'em out!

© Course authors (CC BY-SA 4.0)

Generate key on device

$ ykman piv keys generate 9a - | tee ada.pub

*BLINK BLINK BLINK BLINK*

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9[...]w0BAQEFyq/16vg95xrygi
JZ1//C5/06HCMJpNh[...]zplpr5oUBD3PLirNgCk+x
BEZb7ie5/EA5nU8TT[...]99w5e5MKthaFWFTPV6XIQ
kpapkPJ0cEkbryn+2[...]/30GwvHb5emaaS+fcllI/
APvi/+WqNLrR6H5WC[...]9mJ2hr+56w1RA+pJAIhmu
ZgJHnKUWq2NgDieVI[...]bNC7ps/Xuehjbsnxatj3v
-----END PUBLIC KEY-----
© Course authors (CC BY-SA 4.0)

Create a CSR

$ ykman \
	piv certificates request \
	--subject "ada" 9a ada.pub - \
	| tee ada.csr

? Enter PIN: ********

-----BEGIN CERTIFICATE REQUEST-----
MIICZDCCAUwCAQ[...]AwkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQ[...]EAJpNhzplpr5oqRUc
udwm0lg07JtlrH[...]SvU8TT99w5e5Mruvl
cAL8mWmuKqD6dH[...]CJyn+2/30GwvHts6d
nrTmp83Oj+ilIc[...]nvpQtueZ/BDzft+Ot
gGoUBZGw01hmq8[...]+ZxCLc2dmO7bTcYro
-----END CERTIFICATE REQUEST-----
© Course authors (CC BY-SA 4.0)

Import CSR and issue certificate

$ e import-req ada.csr ada

[...]
The request has been successfully
imported with a short name of: ada

$ e sign-req client ada

[...]
Request subject, to be signed as a
client certificate for 825 days:

subject=
  commonName = ada

[...]
Certificate created at:
/home/lab_user/pki/issued/ada.crt
© Course authors (CC BY-SA 4.0)

Import certificate in YubiKey

$ ykman \
	piv certificates import \
	9a pki/issued/ada.crt --verify

? Enter PIN: **********
© Course authors (CC BY-SA 4.0)

Show device / key slot information

$ ykman piv info

PIV version: 5.4.3
PIN tries remaining: 3/3
Management key algorithm: TDES
CHUID:	3019d4e73a[...]739ced39ce739d83
CCC: 	No data available.
Slot 9a:
  Algorithm:	RSA2048
  Subject DN:	CN=ada
  Issuer DN:	CN=Easy-RSA CA
  Serial:	231896777[...]612734602
  Fingerprint:	900b3b050[...]f0ebd65b9
  Not before:	2023-04-01 13:37:42
  Not after:	2025-07-01 13:37:42
© Course authors (CC BY-SA 4.0)

What just happened?

© Course authors (CC BY-SA 4.0)

That's quite neat. But how do you use it?

Several different "interfaces" and "protocols" exist for usage of a HSM/smart-card.

In this case,
the application (or cryptography library) uses
the standardized PKCS #11 interface
for access to cryptographic operations.

© Course authors (CC BY-SA 4.0)

List available PKCS #11 tokens

$ p11tool --list-tokens

Token 0:
  URL: pkcs11:model=PKCS%231[...];token=ada
  Label: ada
  Type: Hardware token
  Flags: RNG, Requires login
  Manufacturer: piv_II
  Model: PKCS#15 emulated
  Serial: 75d007d3196b0e74
  Module: opensc-pkcs11.so
© Course authors (CC BY-SA 4.0)

Use YubiKey for HTTPS with curl

$ curl \
  --cacert pki/ca.crt \
  --cert "$(p11tool --list-token-urls | grep token=ada)" \
  https://nuke-mgmt.example.test/status.cgi

? Enter PKCS#11 token PIN for ada: *******

Status: NUKES ARMED AND READY! :-O
© Course authors (CC BY-SA 4.0)

Works in many web browsers as well.

Use PKCS #11 to store your CA/email signing key more securely.

Play around with "ykman" to configure touch/physical interaction policies for key usage.

Supports other cryptographic interfaces,
such as "OpenPGP card".

© Course authors (CC BY-SA 4.0)

Moving on...

© Course authors (CC BY-SA 4.0) - Image: © Pixelmenschen (CC BY 2.0)

TPMs / Secure enclaves

Used for a wide variety of tasks,
including "verified boot" and FDE.

© Course authors (CC BY-SA 4.0) - Image: © Pixelmenschen (CC BY 2.0)

HSMaaS

Offered in most public clouds.

Some argue against its value, but usage is required by security standards such as
PCI DSS.

Some legal jurisdictions make it appealing.

© Course authors (CC BY-SA 4.0) - Image: © Jason Hall (CC BY 2.0)

SoftHSM and emulated TPMs

Perhaps you want to play around without access to real hardware?

Useful in CI/CD pipelines and for testing.

© Course authors (CC BY-SA 4.0) - Image: © A. Gerst, ESA (CC BY-SA 2.0)

What are you signing right now?

Your HSM may require a PIN, physical interaction and/or biometrics to perform operations.

But what are you actually
signing / decrypting / authenticating?

© Course authors (CC BY-SA 4.0) - Image: © David Leo Veksler (CC BY-SA 2.0)

Should you trust
"battle-hardened software" or a
"secure black box"?

What about malware, key backups and
bad randomness?

Mayhaps both or neither.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Introduction to SSS(S)

Shamir's Secret Sharing (Scheme)

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

We've talked about multi-signing in OpenPGP and some of its use-cases.

Wouldn't it be cool if we could do the same thing for encryption?

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

But we can already encrypt a message
to several recipients?

Yes, but every single one of them can
decrypt the message on their own.

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

Let's say that you write a will.
Maybe you do have a favorite child?

You sign it and symmetrically encrypt it.

Now what?

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

Perhaps we could use a HSM?

Hmmm, yes - but there is another option...

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

Shamir got you covered!

With SSS, a secret (such as a password)
can be encrypted and split into
several shares.

In order to decrypt the secret,
a configurable number of shares must be known.

An analogy would be RAID5/6.

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

You have four children and a lawyer.

You use SSS to encrypt a passphrase
into five shares.

You set a requirement that three shares
are required to decrypt the passphrase.

In order to decrypt the passphrase/will,
at least/any three of the shareholders
must collaborate.

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

Sounds like a neat trick,
but does anyone use it?

HashiCorp Vault is one example.

Useful for many
"break glass in case of emergency"-solutions.

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

Exercise: Hidden treasure

Use the tool "ssss-split" to encrypt:

My gold is buried under the dog house

Split secret into three shares and require two of them for decryption.

Send a share each and
decryption instructions to:

courses+crypto_ssss-1@0x00.lt,
courses+crypto_ssss-2@0x00.lt and
courses+crypto_ssss-3@0x00.lt.

© Course authors (CC BY-SA 4.0) - Image: © Warren LeMay (CC BY-SA 2.0)

WebAuthn and FIDO2

A somewhat gentle introduction

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Passwords suck

Choosing a good decent one seems tricky.

Avoiding reusal (unique per site/systems).

Constantly worrying about where you write it.

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Let's throw in some 2FA, you may say.

One-time codes don't provide bulletproof protection against phishing.

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Shame that we'll never get rid of them.

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

Wait a second, what is that shining beacon?

© Course authors (CC BY-SA 4.0) - Image: © Quinn Dombrowski (CC BY-SA 2.0)

The heroes we need right now

FIDO Alliance is an industry association working
to kill reduce reliance on passwords.

W3C is one of the main organizations working
on development of web standards.

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

"FIDO2" consist of...

WebAuthn allows users to
cryptographically authenticate against sites/systems.

CTAP 2.0 acts as a standardised protocol for
applications/OSes to communicate with
external authentication devices.

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

The promise

Phishing-resistant authentication based on
hardware-backed cryptography for everyone!

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

Ehmm... less fluff, please.

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)
center
© Course authors (CC BY-SA 4.0)

How is this different from mTLS + HSM?

No CA/X.509 required, generates unique
keypair per site ("origin").

Simpler and provides better privacy.

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

What makes it "phishing-resistant"?

Unique key for each site/origin.

Browser/application includes origin in authentication request against (hardware) token.

You may not be able to tell the different,
but "g00Ige.com" isn't "google.com".

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

Not just for web browsing

$ ssh-keygen \
	-t ed25519-sk \
	-f ~/.ssh/my_fido2_key

Generating public/private ed25519-sk key pair.
You may need to touch your authenticator
to authorize key generation.

Enter passphrase (empty for no passphrase): ****
Enter same passphrase again: ****
© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

A note about "passkeys"

Marketing term used by companies
like Google and Apple.

Prioritizes multi-device synchronization
instead of the "HSM approach"
("the key may never leave!").

Utilizes Webauthn under the hood.

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

OpenPGP / HSM lab

© Course authors (CC BY-SA 4.0) - Image: © David Revoy (CC BY 4.0)

Lab description

Non-graded exercise covering usage of OpenPGP and private key storage/generation on a HSM.

For detailed instructions, see:
"resources/labs/pgp/README.md".

© Course authors (CC BY-SA 4.0) - Image: © David Revoy (CC BY 4.0)

Key attestation

An adventure into X.509 and attestation

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

On an otherwise boring day, a new co-worker
asks you to sign a CSR.

The certificate/key will be used for mTLS to
restrict access to The Super Sensitive Database.

You check the certificate subject/CN and
everything looks fine. Yet...

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

How can you be sure that another copy of the private key hasn't been saved/leaked?

Introducing key attestation.

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

Method to validate that a (non-exportable)
key has been generated on the HSM.

Vendor typically injects a key into HSM
during manufacturing for signing
of user generated keys.

Third-parties can validate the
"attestation certificate"
(user generated public key signed by vendor key).

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

Less talk, more demos!

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

TODO list

  • Ask co-worker to provide att. certificate
  • Compare public key in CSR with public key in att. certificate
  • Cryptographically validate att. certificate
© Course authors (CC BY-SA 4.0) - Image: © Johan Neven (CC BY 2.0)

Generating attestation certificate

$ ykman \
	piv keys attest 9a - \
	| tee bob_key_attest.crt

-----BEGIN CERTIFICATE-----
MIIDIDCCAg[...]igAwIBAgIQASCKKnz
MA0GCSqGSI[...]b3DQEBCwUAA4IBAQB
L2o5iekWDP[...]/fitZkP6L2xoF08Ss
qYr94bzO0e[...]i8pt+7XOA6GuvcTxK
IzMYtx270j[...]JCjZqOIzP52HLVuL3
CPqkcz0qen[...]WB9IMbjU8D1yCaj+1
-----END CERTIFICATE-----
© Course authors (CC BY-SA 4.0) - Image: © Nikki Tysoe (CC BY 2.0)

Exporting device-unique attestation CA

$ ykman \
	piv certificates export f9 - \
	| tee bob_yk_attest_ca.crt

-----BEGIN CERTIFICATE-----
MIIC+jCCAeKg[...]AwIBAgIJAPhUUgoBnzOkM
BAMMIFl1Ymlj[...]byBQSVYgUm9vdCBDQSBTZ
MDAwMFoYDzIw[...]NTIwNDE3MDAwMDAwWjAhM
dGVzdGF0aW9u[...]MIIBIjANBgkqhkiG9w0BA
Yuy5chbl+IiZ[...]j/3EviuaEaza/T2jnoWuS
0Ubv/FwK//RR[...]OjlBx6nuhxIZ9nomPVb57
-----END CERTIFICATE-----
© Course authors (CC BY-SA 4.0) - Image: © Nikki Tysoe (CC BY 2.0)

TODO list

  • Ask co-worker to provide att. certificate
  • Compare public key in CSR with public key in att. certificate
  • Cryptographically validate att. certificate
© Course authors (CC BY-SA 4.0) - Image: © Johan Neven (CC BY 2.0)

Comparing CSR with att. certificate

$ openssl \
	req -in bob.csr \
	-noout -pubkey \
	| sha256sum 

2cb1760a955ea5c4[...]f58b57cca15408bb

$ openssl \
	x509 -in bob_key_attest.crt \
	-noout -pubkey \
	| sha256sum

2cb1760a955ea5c4[...]f58b57cca15408bb
© Course authors (CC BY-SA 4.0) - Image: © Johan Neven (CC BY 2.0)

TODO list

  • Ask co-worker to provide att. certificate
  • Compare public key in CSR with public key in att. certificate
  • Cryptographically validate att. certificate
© Course authors (CC BY-SA 4.0) - Image: © Johan Neven (CC BY 2.0)

Fetching root att. certificate

$ wget \
  --output-document root_yk_attest_ca.crt \
  https://developers.yubico.com/PIV/Introduction/piv-attestation-ca.pem
© Course authors (CC BY-SA 4.0)

Validating device-unique att. CA

$ openssl \
	verify \
	-CAfile root_yk_attest_ca.crt \
	bob_yk_attest_ca.crt 

bob_yk_attest_ca.crt: OK
© Course authors (CC BY-SA 4.0) - Image: © Johan Neven (CC BY 2.0)

Validating att. certificate

$ cat \
	bob_yk_attest_ca.crt \
	root_yk_attest_ca.crt \
	> bob_yk_attest_ca_chain.crt

$ openssl \
	verify \
	-CAfile bob_yk_attest_ca_chain.crt \
	bob_key_attest.crt

bob_key_attest.crt: OK
© Course authors (CC BY-SA 4.0) - Image: © Johan Neven (CC BY 2.0)

TODO list

  • Ask co-worker to provide att. certificate
  • Compare public key in CSR with public key in att. certificate
  • Cryptographically validate att. certificate

Yatta yatta!

© Course authors (CC BY-SA 4.0) - Image: © Johan Neven (CC BY 2.0)

If validation succeeded, it means:

A) Key was generated on/by the YubiKey :D

B) Integrity of
attestation CAs, HSM or cryptography software
has been compromised :-/

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

Peaking into att. certificate

$ openssl x509 -in bob_key_attest.crt -text

[...]
Issuer: CN = Yubico PIV Attestation
Validity
    Not Before: Mar 14 00:00:00 2016 GMT
    Not After : Apr 17 00:00:00 2052 GMT
Subject: CN = YubiKey PIV Attestation 9a
[...]
X509v3 extensions:
    1.3.6.1.4.1.41482.3.3: 
        ...
    1.3.6.1.4.1.41482.3.7: 
        ...c..
    1.3.6.1.4.1.41482.3.8: 
        ..
[...]
© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

Extensions in the generated certificate:
1.3.6.1.4.1.41482.3.3:
Firmware version, encoded as 3 bytes, like: 040300 for 4.3.0
1.3.6.1.4.1.41482.3.7:
Serial number of the YubiKey, encoded as an integer.
1.3.6.1.4.1.41482.3.8:
Two bytes, the first encoding pin policy and the second touch policy
[...]

YK PIV att. documentation.

© Course authors (CC BY-SA 4.0)

Validating key usage restrictions

$ yk-attest-verify \
	piv \
	--allowed-pin-policies once,always \
	--allowed-touch-policies always \
	bob_key_attest.crt \
	bob_yk_attest_ca_chain.crt 

YubiKey PIV Attestation:
 - Key slot       : 9a
 - YubiKey Version: v5.4.3
 - Serial #       : 23316682
 - Formfactor     : USB-A Keychain
 - PIN Policy     : Once
 - Touch Policy   : Always

Attestation Policy Checks:
✔ All policy checks OK
© Course authors (CC BY-SA 4.0) - Image: © Johan Neven (CC BY 2.0)

Validating key usage restrictions

$ yk-attest-verify \
	piv \
	--allowed-pin-policies once,always \
	--allowed-touch-policies always \
	ada_key_attest.crt \
	ada_yk_attest_ca_chain.crt 

YubiKey PIV Attestation:
 - Key slot       : 9a
 - YubiKey Version: v5.4.3
 - Serial #       : 23316676
 - Formfactor     : USB-A Keychain
 - PIN Policy     : Once
 - Touch Policy   : Never

Attestation Policy Checks:
✖ Touch Policy 'Never' is not allowed
© Course authors (CC BY-SA 4.0) - Image: © Johan Neven (CC BY 2.0)

What if it was externally generated?

$ ykman \
	piv keys attest 9a - \
	| tee charlie_key_attest.crt

Error: Attestation failed.
© Course authors (CC BY-SA 4.0) - Image: © Nikki Tysoe (CC BY 2.0)

Many other use-cases for attestation.

Let this be a teaser.

© Course authors (CC BY-SA 4.0) - Image: © Pelle Sten (CC BY 2.0)

Hash chains

An introduction to its uses

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

You got a fancy suit and
work with IT security at a bank.

Protecting the customers'
transaction history against
manipulation would be greeeeat.

Useful for detecting theft/fraud
and in customer disputes.

Can cryptography help us?

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Our example log

INFO: μBank process started
INFO: Alice deposit 1000€
INFO: Alice transfer 500€ to Bob
INFO: Alice's account balance is 500€
© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Cryptographic hashes can be used to
detect changes ("tampering") in data.

Problem solved, right?

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Every time a single bit changes,
the hash digest changes completely
(as it should to be considered secure).

It doesn't tell us what has changed.

We expect new transactions to be added
to the log all the time - what we really
want to protect is historic transaction data.

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Can't we just split the data into
multiple parts (per log entry, for example),
hash each independently and store the digests?

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Sure, but what about ordering?

Kinda important to validate
account balance and similar.

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Let's just throw the
transaction data hashes
in a file, append new hashes
and store the file's own digest!

Anyone who wants to validate the
history could just compute hashes
and check for themselves, right?!

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

How do you cryptographically prove
that you only appended a transaction
and didn't manipulate any historic ones?

© Course authors (CC BY-SA 4.0) - Image: © Cory Doctorow (CC BY-SA 2.0)

Wouldn't it be nice if there was
an efficient way to protect and
validate (historical) integrity
of append-only data structures,
like our transaction log file?

Hash chains to the rescue!

© Course authors (CC BY-SA 4.0) - Image: © Christian Siedler (CC BY-SA 2.0)

We're talking about links in a chain,
not hyperlinks.

Each link in our chain consists of
hash($PREVIOUS_LINK_HASH + $DATA).

Confusing? Let's look at an example.

© Course authors (CC BY-SA 4.0) - Image: © Christian Siedler (CC BY-SA 2.0)

Split log per line

$ ls

1.log  2.log  3.log  4.log

$ cat *.log

INFO: μBank process started
INFO: Alice deposit 1000€
INFO: Alice transfer 500€ to Bob
INFO: Alice's account balance is 500€
© Course authors (CC BY-SA 4.0) - Image: © Christian Siedler (CC BY-SA 2.0)

Generating initial hash chain

#!/usr/bin/env bash
LAST_LINK_HASH="<nothing>"

for LOG_ENTRY_FILE in *.log; do
  LOG_ENTRY_DATA="$(cat "${LOG_ENTRY_FILE}")"
  
  LAST_LINK_DATA="${LAST_LINK_HASH} + ${LOG_ENTRY_DATA}"
  
  LAST_LINK_HASH="$(echo "${LAST_LINK_DATA}" | sha256sum | cut -d ' ' -f 1)"
  echo "Digest of last link \"${LAST_LINK_DATA}\" is \"${LAST_LINK_HASH}\""
  
done

echo "Hash digest to store:"
echo "${LAST_LINK_HASH}" | tee hash_chain.txt
© Course authors (CC BY-SA 4.0)
Digest of last link "<nothing> + INFO: μBank process started" is "f7d6[...]c280"
Digest of last link "f7d6[...]c280 + INFO: Alice deposit 1000€" is "2c11[..]7e26"
Digest of last link "2c11[...]7e26 + INFO: Alice transfer 500€ to Bob" is "ac5b[...]fd0e"
Digest of last link "ac5b[...]fd0e + INFO: Alice's account balance is 500€" is "c075[...]8b5d"

Hash digest to store:
c075e5268bacae128f7ee1c897a6f15f3980d02f3ff2aa3d72583cf36ad08b5d
© Course authors (CC BY-SA 4.0)

c075[...]8b5d is the last
link of the hash chain.

Manipulation of historic data
can be detected, as it will change
the hash for all following links
and thereby also the last.

Confused? Let's look at some examples.

© Course authors (CC BY-SA 4.0) - Image: © Christian Siedler (CC BY-SA 2.0)

Our baseline transaction log

Previous link digest Log entry
<nothing> INFO: μBank process started
f7d6[...]c280 INFO: Alice deposit 1000€
2c11[...]7e26 INFO: Alice transfer 500€ to Bob
ac5b[...]fd0e INFO: Alice's account balance is 500€
c075[...]8b5d

(c075[...]8b5d is the expected digest of the last link)

© Course authors (CC BY-SA 4.0)

Changing last log entry

Previous link digest Log entry
<nothing> INFO: μBank process started
f7d6[...]c280 INFO: Alice deposit 1000€
2c11[...]7e26 INFO: Alice transfer 500€ to Bob
ac5b[...]fd0e INFO: Alice's account balance is 500£
a1f5[...]6c82

(c075[...]8b5d is the expected digest of the last link)

© Course authors (CC BY-SA 4.0)

Changing an earlier log entry

Previous link digest Log entry
<nothing> INFO: μBank process started
f7d6[...]c280 INFO: Alice deposit 1000€
2c11[...]7e26 INFO: Alice transfer 5000€ to Bob
8705[...]d4b3 INFO: Alice's account balance is 500€
9dc6[...]4b21

(c075[...]8b5d is the expected digest of the last link)

© Course authors (CC BY-SA 4.0)

Removing a log entry

Previous link digest Log entry
<nothing> INFO: μBank process started
f7d6[...]c280 INFO: Alice deposit 1000€
2c11[...]7e26 INFO: Alice transfer 500€ to Bob
2c11[...]7e26 INFO: Alice's account balance is 500€
9135[...]cc83

(c075[...]8b5d is the expected digest of the last link)

© Course authors (CC BY-SA 4.0)

Any limitations with our approach?

Can only prevent manipulation of
previous links in the chain,
a fraudulent transaction
could be appended.

Requires the latest link digest
and all previous log entries
for proper validation.

Gotta be careful with storage of
the last link hash, as a thief may
be able to "crack" the last entry.

© Course authors (CC BY-SA 4.0) - Image: © Christian Siedler (CC BY-SA 2.0)
#!/usr/bin/env bash
PREVIOUS_LINK_HASH="ac5b[...]fd0e"
CURRENT_LINK_HASH="c075[..]8b5d"

ATTEMPTS=0

for NAME in Ada Alice Bob Boris Charlie Connie; do
  AMOUNT=0

  while [[ ${AMOUNT} -le 5000 ]]; do
    (( ATTEMPTS++ ))

    CANDIDATE="INFO: ${NAME}'s account balance is ${AMOUNT}€"
    CANDIDATE_DATA="${PREVIOUS_LINK_HASH} + ${CANDIDATE}"

    CANDIDATE_HASH="$(echo "${CANDIDATE_DATA}" | sha256sum | cut -d ' ' -f 1)"

    if [[ "${CANDIDATE_HASH}" == "${CURRENT_LINK_HASH}" ]]; then
      echo "Cracked log entry after ${ATTEMPTS} attempts: ${CANDIDATE}"
      exit 0
    fi

    (( AMOUNT++ ))
  done
done
© Course authors (CC BY-SA 4.0)
$ ./crack_that_log_entry.sh

Cracked log entry after 5502 attempts: INFO: Alice's account balance is 500€
© Course authors (CC BY-SA 4.0)
Log entry Per-entry salt
INFO: μBank process started 13e61749
INFO: Alice deposit 1000€ fd3dd804
INFO: Alice transfer 500€ to Bob 58a762cb
INFO: Alice's account balance is 500€ c004de54

To append new chain links,
hash($PREVIOUS_LINK_HASH + hash($ENTRY_SALT + $LOG_ENTRY)).

The last link digests can be publicly available,
as they don't reveal any sensitive information.

Anyone with access to a log entry, its associated salt
and the previous link digests can validate the log.

© Course authors (CC BY-SA 4.0)

Can we make it more efficient?

Yes, using a Merkle tree.

© Course authors (CC BY-SA 4.0) - Image: © Christian Siedler (CC BY-SA 2.0)
center
© Course authors (CC BY-SA 4.0) - Image: © © David Göthberg (CC0 1.0)

Sounds neat,
but is anyone using it?

Guardtime digests in newspapers
are one example.

The chain part of blockchain.

© Course authors (CC BY-SA 4.0) - Image: © Christian Siedler (CC BY-SA 2.0)

Other use-cases

Efficient error detection and data replication.

Cornerstone of Git repositories.

Used to provide "measured and attested boot" -
checkout Joel's talk from SEC-T for details.

© Course authors (CC BY-SA 4.0) - Image: © Christian Siedler (CC BY-SA 2.0)

If you see the term
"trusted timestamping service/authority",
some type of hash chaining is likely used.

© Course authors (CC BY-SA 4.0) - Image: © Christian Siedler (CC BY-SA 2.0)

Ransomware

Use-case study of cryptography

© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)

What is ransomware?

Malware that makes files/data inaccessible, typically using encryption.

Intruders demand payment to release files/data.

Hard to estimate total global damages,
some predict it to reach 50B USD in 2025.

© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)

What makes it a good showcase?

Basically all cryptography techniques we've talked about are involved.

© Course authors (CC BY-SA 4.0) - Image: © John K. Thorne (CC0 1.0)

Let's dig in!

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

Initial access / intrusion

The malicious code needs to be deployed somewhere, preferably on a business critical system.

Initial access brokers specialize in selling access to user accounts and systems.

Foothold is usually obtained by:

  • Credential phishing
  • Password leaks and reuse
  • Exploitation of vulnerable systems
© Course authors (CC BY-SA 4.0) - Image: © Andrew Hart (CC BY-SA 2.0)

Bypassing security controls

Various different methods to stay under the radar and avoid detection.

One is to steal or fraudulently obtain code-signing certificates.

© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)

Increasing recovery cost

Delete/corrupt backup archives.

Steal sensitive/embarrassing information
for "double extortion".

Target firmware/lower-level code that is tricky
to detect/recover from, especially with
"secure boot" or "measured boot".

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Encrypting the data

Symmetric encryption of (all) files
with randomly generated key.

Randomly generated symmetric key is
encrypted against intruder's public key.

Commonly use established standards,
such as AES and RSA.

Often relies on the same cryptography
libraries as everyone else, because
it is hard to get right.

© Course authors (CC BY-SA 4.0) - Image: © Mike Grauer Jr (CC BY 2.0)

Establishing contact

So-called "ransom notes" are left of the affected systems.

Instructions describing how victims can get their data back.

Typically contains an .onion-link for more details, payment information and "customer support".

© Course authors (CC BY-SA 4.0) - Image: © Kevin Dooley (CC BY 2.0)

Getting paid

Ransom must typically be paid in a cryptocurrency.

Bitcoin and Monero are the most common options.

Cashing out safely is not trivial,
may require tumbling and trickery.

© Course authors (CC BY-SA 4.0) - Image: © Marco Verch (CC BY 2.0)

Wrapping up

Organizations take security and disaster
recovery way more seriously these days.

"RaaS" is enabling specialization.

"Cyber insurance" has... interesting side-effects.

© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)

Cryptography in the future

A peak into what's next

© Course authors (CC BY-SA 4.0) - Image: © Bill Stafford, NASA (CC BY 2.0)

We cannot (yet) foresee the future.

Let's talk about some trends and
insights into what may be next.

© Course authors (CC BY-SA 4.0) - Image: © Bill Stafford, NASA (CC BY 2.0)

Post-quantum cryptography

Theoretically possible to efficiently break
asymmetric encryption/signing.

Hard to know exactly how close we are,
but sunsetting cryptography solutions
takes plenty of time.

Work-around is to wrap asymmetric ciphers
in symmetric encryption like AES,
but not always a good option.

© Course authors (CC BY-SA 4.0) - Image: © IAEA (CC BY 2.0)

Post-quantum cryptography

NIST and other actors are working on
new publicly-audited standards
for quantum-resistant ciphers.

"CRYSTALS-Kyber" (encryption) and
"CRYSTALS-Dilithium" (signing)
are currently being implemented in
cryptography libraries/toolkits.

Most solutions opt to use them
in unison with "traditional ciphers",
like "ECDHE-MLKEM" (X25519MLKEM768).

© Course authors (CC BY-SA 4.0) - Image: © IAEA (CC BY 2.0)

Open implementations

Publicly available cryptography standards
have been the norm for a long time.

Moving towards demand for
open/publicly auditable implementations.

Affects both software and hardware.

OpenTitan and the TKey
are interesting examples.

© Course authors (CC BY-SA 4.0) - Image: © Dennis van Zuijlekom (CC BY-SA 2.0)

Post-hype technologies

Cryptocurrencies, web3, NFTs and
other blockchain technologies use
lots of very interesting cryptography.

Starting to slowly and sensibly be
cherry-picked into other solutions.

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

Law and order

Fewer attempts to restrict
usage of cryptography.

Focus on jurisdiction to enable
lawful interception through
endpoint backdoors and CSS.

Targeting "crime-supporting" functions,
like cryptocurrency exchanges/tumblers.

© Course authors (CC BY-SA 4.0) - Image: © William Warby (CC BY 2.0)

Regardless, the future is very exciting!

© Course authors (CC BY-SA 4.0) - Image: © Steve Jurvetson (CC BY 2.0)

Obtaining certificates

Getting 'em signed by public CAs

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Setting up your own CA
is not that hard.

Getting users to trust it
is a whole other deal.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Most operating systems ship with a
trust store containing CA certificates.

The CA/Browser Forum agree on
what it takes to be included*.

How do we get our CSR signed by
a publicly-trusted CA?

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

The dark ages

Fork up a few (hundred) USD
and specify the email address
(admin|administrator|webmaster|
hostmaster|postmaster)@$YOUR_DOMAIN.

Wait...

Here is (hopefully) a certificate!

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Does that sound a bit fragile?

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Introducing "Let's Encrypt"

Publicly-trusted CA launched in 2014
with the goal of providing certificates
to every website for free (as in beer).

Developed and run by the nonprofit
Internet Security Research Group.

Invented and uses the
ACME protocol to
validate CSRs.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

The limitations

No email (S/MIME) or
code signing certificates (yet).

(Sigstore may help you with the latter)

Not trusted in very old/outdated
trust stores (which you probably
shouldn't be trusting anyway!).

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

The certificate aims to
prove control over a domain,
not a brand/company/organization.

"Extended Validation certificates"
were introduced in 2005 to
address the problem.

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Bitcoin

Use-case study of cryptography

© Course authors (CC BY-SA 4.0) - Image: © Bill Badzo (CC BY-SA 2.0)

What is Bitcoin?

Digital currency and
decentralized payment network.

First widely used example of cryptocurrency.

Released as FOSS in 2009 by the
mysterious pseudonym "Satoshi Nakamoto".

Let's have a peak at how it works
(and not discuss if it's the devil/our savior).

© Course authors (CC BY-SA 4.0) - Image: © Bill Badzo (CC BY-SA 2.0)

Addresses and keys

No registration or
"know your customer"-process is required
to perform transactions on the network.

Relies on user-generated asymmetric key pairs.

The public key acts as the participant's
"account number", known in Bitcoin as "address".

The private key is used to sign transactions.
An analogy would be a physical wallet with cash.

© Course authors (CC BY-SA 4.0) - Image: © Austin Design (CC BY-SA 2.0)

Key considerations

ECC is used due to its great performance and
small key size - no need for "fingerprints"
(hash digest of public key).

Parties with access to the private key
controls Bitcoins associated with
the public key/address.

To minimize the risk of theft, utilize
"cold wallets" (offline key storage) or
"hardware wallets" (basically a HSM).

© Course authors (CC BY-SA 4.0) - Image: © David Leo Veksler (CC BY-SA 2.0)

Initializing transactions

James wanna pay Ross for some "consulting".

James gets hold of Ross' address
from an email/instant messaging chat,
by scanning a QR code or similar.

James opens his "wallet application" and
commands it to sign a transaction:

Transfer 0.42 BTC from address
bc1qmxje[...]54g3y7wp to
bc1qa5wk[...]x9ek9hz6

And then what?

© Course authors (CC BY-SA 4.0) - Image: © Nicholas A. Tonelli (CC0 1.0)

Distributing transactions

The signed transaction data is
distributed to all nodes in the network
using a peer-to-peer "gossip" protocol.

Nodes are responsible for verifying that
transactions are signed by the private key
associated with the specified source address
and keep track of historic transactions to
validate "account balance".

Anyone can setup a node and monitor
current/historic transactions.

© Course authors (CC BY-SA 4.0) - Image: © Carl Davies (CSIRO) (CC BY 3.0)

Validating transactions

Every ~few minutes, nodes save the
observed and validated transactions,
sorts them and calculates a hash of the data.

The hash digest of transactions is hashed
together with the previous link
in a hash chain.

In order to disincentivize attempts to
include fraudulent transactions in the
hash chain, nodes must provide a
proof of work.

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

PoW in Bitcoin

Take SHA-2 256 hash of transaction data,
previous link hash and a few random bytes.

Find a hash ending with X zeroes,
where X is dynamically and democratically
adjusted by nodes in the network to
account for available compute power.

Once the challenge has been solved by a
node, it signs the solution and
distributes it to the network.

© Course authors (CC BY-SA 4.0) - Image: © Marcin Wichary (CC BY 2.0)

Block creation

Nodes receive and validate the proof.

If ~51% of nodes agree that the correct
transactions were included and that
the PoW challenge was solved,
the data ("called block") is
included in the hash chain.

To incentivize nodes for properly
verifying transactions and PoW,
X Bitcoins are awarded to
the address (public key)
of the solving node.

© Course authors (CC BY-SA 4.0) - Image: © Mike Grauer Jr (CC BY 2.0)

Wrapping up

Bitcoin does not protect
confidentiality of transactions.

Other cryptocurrencies use
"zero-knowledge proofs" to solve this.

I hope you learned something new!

© Course authors (CC BY-SA 4.0) - Image: © Kurayba (CC BY-SA 2.0)

Forward secrecy

Long-term protection of confidentiality

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

When protecting network communication,
we typically combine symmetric and
asymmetric cryptography.

Client connects to a target server,
extracts public key from verified certificate,
generates a random symmetric key,
encrypts it against the extracted public key.

Once the symmetric key (AKA "session key")
has been sent to the server, both peers can
use it to encrypt/decrypt transferred data.

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

The server's private key may be
accidentally leaked or stolen.

How would it affect the confidentiality
of historic communication?

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

An attacker who has recorded historic
network traffic could use the private key
to decrypt the exchanged session key.

With access to the session key,
they could decrypt all transferred data.

The described method for key exchange does
not provide "perfect forward secrecy".

Yikes.... any ideas?

© Course authors (CC BY-SA 4.0) - Image: © Adam Lusch (CC BY-SA 2.0)

The server could generate a new asymmetric
key pair per connection and throw away the
private key once the connection is closed.

This key would be ephemeral and if leaked
only permit decryption of one session.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

...but the server's public key is
embedded in the certificate.

Without a verifiable certificate,
the connection is vulnerable against
active man-in-the-middle attacks.

(an attacker who can manipulate
network traffic, that is)

Some suggestions?

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Let's generate a new key pair
per connection to the server.

We could then use the private key
associated with the certificate
(let us call it "long-term key")
to sign our newly generated public key
before returning it to the client.

Client's could verify the signature
of the ephemeral public key using
the server's trusted certificate.

The long-term key is only used to
establish trust, not for confidentiality.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

In practice, we typically do this using
Ephemeral Diffie-Hellman key exchange
(sometimes turned around and called "DHE").

Algorithm specifically designed for...
well, key exchange!

Enable two parties to derive the same
key without sending it over the network.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

"Message authentication codes"

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

We've talked about how tools like
cryptographic hashing can be used
to protect the integrity of data.

Would be neat to make sure that
network traffic hasn't been
maliciously manipulated.

But how is it done in practice?
We can't simply send the expected
digest in plain-text over the wire.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Perhaps we could
asymmetric_sign(hash($data))
and send the resulting signature
along with our transferred data?

Sure, but asymmetric cryptography
is typically quite slow.

© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

Another option would be
symmetric_encrypt(hash($data)).

Hmm, yes - but there is another
option just based on hashing...

© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

What if we would simply
hash($data + $secret)?

The receiver of traffic could
do something checking like:

if (
  $received_integrity_digest !=
  hash($received_data + $secret)):

  return 'Verification failed! :('
© Course authors (CC BY-SA 4.0) - Image: © Halfrain (CC BY-SA 2.0)

All of these solutions aim to provide a
"Message Authentication Code".

The last example was a primitive
Hash-based Message Authentication Code.

Relatively cheap/low overhead, but can
be tricky to get right depending
on the hash function used.

Stick with purpose built solutions,
like Python's "hmac" module.

© Course authors (CC BY-SA 4.0) - Image: © Stig Nygaard (CC BY 2.0)

Course outro

Wrap-up and summary

© Course authors (CC BY-SA 4.0) - Image: © Helsinki Hacklab (CC BY 2.0)

We've dipped our toes into what
cryptography has to offer.

Large field with lots of exciting applications.

Some suggestions for further explorations.

© Course authors (CC BY-SA 4.0) - Image: © Helsinki Hacklab (CC BY 2.0)

Wanna learn more about the history of cryptography and how it actually works?

Checkout Simon Singh's "The Code Book".

© Course authors (CC BY-SA 4.0)

Interested in how cryptography can be used to solve problems?

Read/Listen to
Phil Champagne's "The Book Of Satoshi".

© Course authors (CC BY-SA 4.0) - Image: © Marco Verch (CC BY 2.0)

Want to try implementing and attacking cryptography?

Checkout NCC's "cryptopals"!

© Course authors (CC BY-SA 4.0) - Image: © Kenny Cole (CC BY 2.0)

Answer the following questions

  • What were your course highlights?
  • How would you re-balance the course (more/less time for lectures, labs, etc.)
  • Any "Ahaaa!"-moments you remember?
  • What would you've liked to learn more about?
  • Anything we should forward to Yubico? :-)
  • Other thoughts/comments/suggestions?

Take the chance to be a bit --verbose!

courses+crypto_014801@0x00.lt

© Course authors (CC BY-SA 4.0) - Image: © Helsinki Hacklab (CC BY 2.0)

DE_END2

© Course authors (CC BY-SA 4.0) - Image: © Helsinki Hacklab (CC BY 2.0)

Welcome participants and wait for everyone to get settled. Introduction of the lecturers and their background. Segue: In this part of the course we'll talk about cryptography...

- Sounds quite hyperbolic, doesn't it? - Examples of how you already relied on it today - Did you go to take the bus/subway this morning? Did you check your bank account? Did you send a nude/talk to your psychologist online? Did you buy a sandwich? Did you connect to school wifi? Then you've relied on cryptography. So do spooks, dissidents, mega-corps and criminals. - What first comes to mind when talking about cryptography is encryption, that is to keep information secret, but as we'll see throughout the course there are many other use-cases.

- Cryptography relies on a lot of mathematical voodoo - While important knowledge, the mathematical/technical implementation details isn't necessarily required to make use of the technology - The are lots of great resources online for those interested in dark magic behind cryptography, but the focus on this course will be highly practical and the majority of time will be spent on how various cryptographic primitives/technologies can be used and when they shouldn't be - It's a huge subject, we won't be able to go into details regarding everything but instead focus on the most relevant areas

- We'll cover lots of things in a short amount of time - In order to be able to do this we'll use scientifically proven methods to Make It Stick - Basically what the slide says - Don't forget to have fun! - If available, show detailed course schedule

- There are several resources to help you learn - Speaker notes in slides are heavily recommended for recaps/deep diving - May also be available through LMS, depending on how the course is consumed - The course is designed to be instructor lead, won't make the most of it on your own, see as aid - Presentations may be recorded, but only the speaker side for good and bad

The course wouldn't be available if it wasn't for financial support - Thanks!

- Encourage participants to make the course better - Learners are likely the best to provide critique, lecturers are likely a bit home-blind - No cats or dogs allowed! - Feel free to share it with friends or use it yourself later in your career

People who have contributed to the course

Histiaeus (Greece, 500 BC): https://www.tattoolife.com/wp-content/uploads/2021/11/Detail-of-an-illustration-by-Giorgio-De-Gaspari.jpeg

- Used by ancient Greeks/Spartans - Requires rod with the same diameter for "decryption"

https://en.wikipedia.org/wiki/Enigma_machine

- Sent a private message to anyone? - Logged in to a sensitive service over the big bad Internet? - Signed something with BankID? - Took the bus or subway? ....

- For labs and experiments, students will need a Yubikey - Thankfully, Yubico has provided them to the in-class students - A nimble device that can be used to increase cryptographic security, more about it later!

- We'll need some software and a lab environments for the course - For now, just make sure that the software is installed and seem to be working. - Check out the presentation links: I will however not provide a step-by-step guide, you won't get it in real life. - Have a look at the README.md, contains several tips for solving common issues

https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg https://upload.wikimedia.org/wikipedia/commons/d/d6/ECB_encryption.svg https://upload.wikimedia.org/wikipedia/commons/9/96/Tux_encrypted_ecb.png https://upload.wikimedia.org/wikipedia/commons/8/80/CBC_encryption.svg https://upload.wikimedia.org/wikipedia/commons/0/00/Tux_encrypted_ctr.png https://upload.wikimedia.org/wikipedia/commons/e/ef/BlockCipherModesofOperation.svg

https://simplycalc.com/luhn-calculate.php https://simplycalc.com/luhn-validate.php

https://shattered.io/static/shattered.png

https://upload.wikimedia.org/wikipedia/commons/d/d6/ECB_encryption.svg https://upload.wikimedia.org/wikipedia/commons/8/80/CBC_encryption.svg

https://www.keylength.com/en

https://keyoxide.org/2c364aa0ede8b0d744ec22e7225f62af3f13c95f

That is 288 billion Windows hashes per second!

Stuffed with x4 Nvidia A10G

https://i.redd.it/w4gz0wzz1i821.png

https://leetronics.de/en/shop/infinite-noise-trng/ https://opentrng.org/

https://dl.acm.org/cms/attachment/53f3a0fa-d90c-49e5-82bd-09e2ca003487/f3.jpg

https://www.manageengine.com/key-manager/what-is-automated-certificate-management-environment-acme.html