handouts/ho01.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 25 Sep 2014 07:49:22 +0100
changeset 179 1cacbe5c67cf
parent 178 13c6bd6e3477
child 180 a95782c2f046
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
     1
\documentclass{article}
158
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\usepackage{../style}
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
     3
\usepackage{../langs}
158
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
     5
\lstset{language=JavaScript}
158
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
\begin{document}
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
167
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
     9
\section*{Handout 1 (Security Engineering)}
158
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
Much of the material and inspiration in this module is taken
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
from the works of Bruce Schneier, Ross Anderson and Alex
159
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    13
Halderman. I think they are the world experts in the area of
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    14
security engineering. I especially like that they argue that a
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    15
security engineer requires a certain \emph{security mindset}.
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    16
Bruce Schneier for example writes:
158
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
\begin{quote} 
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
\it ``Security engineers --- at least the good ones --- see
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
the world differently. They can't walk into a store without
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
noticing how they might shoplift. They can't use a computer
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
without wondering about the security vulnerabilities. They
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
can't vote without trying to figure out how to vote twice.
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
They just can't help it.''
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
\end{quote}
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
\begin{quote}
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
\it ``Security engineering\ldots requires you to think
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
differently. You need to figure out not how something works,
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
but how something can be made to not work. You have to imagine
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
an intelligent and malicious adversary inside your system
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
\ldots, constantly trying new ways to
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
subvert it. You have to consider all the ways your system can
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
fail, most of them having nothing to do with the design
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
itself. You have to look at everything backwards, upside down,
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
and sideways. You have to think like an alien.''
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
\end{quote}
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
159
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    39
\noindent In this module I like to teach you this security
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    40
mindset. This might be a mindset that you think is very
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    41
foreign to you---after all we are all good citizens and not
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    42
hack into things. I beg to differ: You have this mindset
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    43
already when in school you were thinking, at least
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    44
hypothetically, about ways in which you can cheat in an exam
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    45
(whether it is about hiding notes or looking over the
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    46
shoulders of your fellow pupils). Right? To defend a system,
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    47
you need to have this kind mindset and be able to think like
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    48
an attacker. This will include understanding techniques that
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    49
can be used to compromise security and privacy in systems.
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    50
This will many times result in insights where well-intended
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    51
security mechanisms made a system actually less
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    52
secure.\smallskip
158
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
159
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    54
{\Large\bf Warning!} However, don’t be evil! Using those
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    55
techniques in the real world may violate the law or King’s
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    56
rules, and it may be unethical. Under some circumstances, even
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    57
probing for weaknesses of a system may result in severe
160
4cbd6ca025e6 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 159
diff changeset
    58
penalties, up to and including expulsion, fines and
159
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    59
jail time. Acting lawfully and ethically is your
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    60
responsibility. Ethics requires you to refrain from doing
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    61
harm. Always respect privacy and rights of others. Do not
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    62
tamper with any of King's systems. If you try out a technique,
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    63
always make doubly sure you are working in a safe environment
160
4cbd6ca025e6 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 159
diff changeset
    64
so that you cannot cause any harm, not even accidentally.
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    65
Don't be evil. Be an ethical hacker.\medskip
158
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    67
\noindent
169
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    68
In this lecture I want to make you familiar with the security mindset
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    69
and dispel the myth that encryption is the answer to all security
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    70
problems (it is certainly often part of an answer, but almost always
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    71
never a sufficient one). This is actually an important thread going
159
77cf0362b87a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 158
diff changeset
    72
through the whole course: We will assume that encryption works
169
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    73
perfectly, but still attack ``things''. By ``works perfectly'' we mean
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    74
that we will assume encryption is a black box and, for example, will
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    75
not look at the underlying mathematics and break the 
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    76
algorithms.\footnote{Though fascinating this might be.}
158
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
 
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    78
For a secure system, it seems, four requirements need to come
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    79
together: First a security policy (what is supposed to be
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    80
achieved?); second a mechanism (cipher, access controls,
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    81
tamper resistance etc); third the assurance we obtain from the
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    82
mechanism (the amount of reliance we can put on the mechanism)
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    83
and finally the incentives (the motive that the people
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    84
guarding and maintaining the system have to do their job
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    85
properly, and also the motive that the attackers have to try
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    86
to defeat your policy). The last point is often overlooked,
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    87
but plays an important role. To illustrate this lets look at
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    88
an example. 
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    89
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    90
The questions is whether the Chip-and-PIN system with credit
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    91
cards is more secure than the older method of signing receipts
177
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
    92
at the till. On first glance Chip-and-PIN seems obviously more
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
    93
secure and improved security was also the central plank in the
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    94
``marketing speak'' of the banks behind Chip-and-PIN. The
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    95
earlier system was based on a magnetic stripe or a mechanical
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    96
imprint on the card and required customers to sign receipts at
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    97
the till whenever they bought something. This signature
177
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
    98
authorised the transactions. Although in use for a long time,
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    99
this system had some crucial security flaws, including making
177
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   100
clones of credit cards and forging signatures. 
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   101
177
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   102
Chip-and-PIN, as the name suggests, relies on data being
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   103
stored on a chip on the card and a PIN number for
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   104
authorisation. Even though the banks involved trumpeted their
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   105
system as being absolutely secure and indeed fraud rates
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   106
initially went down, security researchers were not convinced
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   107
(especially the group around Ross Anderson). To begin with,
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   108
the Chip-and-PIN system introduced a ``new player'' that
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   109
needed to be trusted: the PIN terminals and their
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   110
manufacturers. It was claimed that these terminals are
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   111
tamper-resistant, but needless to say this was a weak link in
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   112
the system, which criminals successfully attacked. Some
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   113
terminals were even so skilfully manipulated that they
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   114
transmitted skimmed PIN numbers via built-in mobile phone
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   115
connections. To mitigate this flaw in the security of
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   116
Chip-and-PIN, you need to vet quite closely the supply chain
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   117
of such terminals.
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   118
177
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   119
Later on Ross Anderson and his group managed to launch a
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   120
man-in-the-middle attacks against Chip-and-PIN. Essentially
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   121
they made the terminal think the correct PIN was entered and
177
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   122
the card think that a signature was used. This was a more
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   123
serious security problem. The flaw was mitigated by requiring
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   124
that a link between the card and the bank is established at
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   125
every time the card is used. Even later this group found
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   126
another problem with Chip-and-PIN and ATMs which do not
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   127
generate random enough numbers (nonces) on which the security
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   128
of the underlying protocols relies. 
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   129
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   130
The problem with all this is that the banks who introduced
177
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   131
Chip-and-PIN managed with the new system to shift the
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   132
liability for any fraud and the burden of proof onto the
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   133
customer. In the old system, the banks had to prove that the
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   134
customer used the card, which they often did not bother with.
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   135
In effect, if fraud occurred the customers were either refunded
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   136
fully or lost only a small amount of money. This
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   137
taking-responsibility-of-potential-fraud was part of the
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   138
``business plan'' of the banks and did not reduce their
177
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   139
profits too much. 
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   140
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   141
Since banks managed to successfully claim that their
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   142
Chip-and-PIN system is secure, they were under the new system
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   143
able to point the finger at the customer when fraud occurred:
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   144
they must have been negligent loosing their PIN. The customer
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   145
had almost no means to defend themselves in such situations.
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   146
That is why the work of \emph{ethical} hackers like Ross
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   147
Anderson's group was so important, because they and others
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   148
established that the bank's claim that their system is secure
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   149
and it must have been the customer's fault, was bogus. In 2009
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   150
for example the law changed and the burden of proof went back
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   151
to the banks. They need to prove whether it was really the
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   152
customer who used a card or not.
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   153
177
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   154
This is a classic example where a security design principle
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   155
was violated: Namely, the one who is in the position to
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   156
improve security, also needs to bear the financial losses if
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   157
things go wrong. Otherwise, you end up with an insecure
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   158
system. In case of the Chip-and-PIN system, no good security
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   159
engineer would claim that it is secure beyond reproach: the
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   160
specification of the EMV protocol (underlying Chip-and-PIN) is
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   161
some 700 pages long, but still leaves out many things (like
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   162
how to implement a good random number generator). No human
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   163
being is able to scrutinise such a specification and ensure it
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   164
contains no flaws. Moreover, banks can add their own
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   165
sub-protocols to EMV. With all the experience we already have,
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   166
it is as clear as day that criminals were eventually able to
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   167
poke holes into it and measures need to be taken to address
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   168
them. However, with how the system was set up, the banks had
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   169
no real incentive to come up with a system that is really
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   170
secure. Getting the incentives right in favour of security is
46e581d66f3a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   171
often a tricky business.
173
9126c13a7d93 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 169
diff changeset
   172
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   173
\subsection*{Of Cookies and Salts}
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   174
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   175
Lets look at another example which should helps with
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   176
understanding how passwords should be verified and stored.
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   177
Imagine you need to develop a web-application that has the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   178
feature of recording how many times a customer visits a page.
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   179
For example to give a discount whenever the customer visited a
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   180
webpage some $x$ number of times (say $x$ equal $5$). There is
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   181
one more constraint: we want to store the information about
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   182
the number of times a customer has visited inside a cookie. I
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   183
think, for a number of years the webpage of the New York Times
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   184
operated in this way: it allowed you to read ten articles per
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   185
months for free; if you wanted to read more, you had to pay.
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   186
My guess is it used cookies for recording how many times their
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   187
pages was visited, because if you switched browsers you could
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   188
easily circumvent the restriction about ten articles.
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   189
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   190
To implement our web-application it is good to look under the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   191
hood what happens when a webpage is requested. A typical
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   192
web-application works as follows: The browser sends a GET
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   193
request for a particular page to a server. The server answers
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   194
this request. A simple JavaScript program that realises a
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   195
``hello world'' webpage is as follows:
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   196
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   197
\begin{center}
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   198
\lstinputlisting{../progs/ap0.js}
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   199
\end{center}
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   200
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   201
\noindent The interesting lines are 4 to 7 where the answer to
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   202
the GET request is generated\ldots in this case it is just a
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   203
simple string. This program is run on the server and will be
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   204
executed whenever a browser initiates such a GET request.
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   205
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   206
For our web-application of interest is the feature that the
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   207
server when answering the request can store some information
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   208
at the client's side. This information is called a
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   209
\emph{cookie}. The next time the browser makes another GET
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   210
request to the same webpage, this cookie can be read by the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   211
server. We can use cookies in order to store a counter that
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   212
records the number of times our webpage has been visited. This
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   213
can be realised with the following small program
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   214
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   215
\begin{center}
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   216
\lstinputlisting{../progs/ap2.js}
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   217
\end{center}
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   218
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   219
\noindent The overall structure of this program is the same as
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   220
the earlier one: Lines 7 to 17 generate the answer to a
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   221
GET-request. The new part is in Line 8 where we read the
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   222
cookie called \pcode{counter}. If present, this cookie will be
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   223
send together with the GET-request from the client. The value
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   224
of this counter will come in form of a string, therefore we
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   225
use the function \pcode{parseInt} in order to transform it
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   226
into an integer. In case the cookie is not present, we default
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   227
the counter to zero. The odd looking construction \code{...||
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   228
0} is realising this defaulting in JavaScript. In Line 9 we
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   229
increase the counter by one and store it back to the client
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   230
(under the name \pcode{counter}, since potentially more than
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   231
one value could be stored). In Lines 10 to 15 we test whether
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   232
this counter is greater or equal than 5 and send accordingly a
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   233
specially grafted message back to the client.
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   234
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   235
Let us step back and analyse this program from a security
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   236
point of view. We store a counter in plain text on the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   237
client's browser (which is not under our control). Depending
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   238
on this value we want to unlock a resource (like a discount)
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   239
when it reaches a threshold. If the client deletes the cookie,
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   240
then the counter will just be reset to zero. This does not
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   241
bother us, because the purported discount will just not be
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   242
granted. In this way we do not lose us any (hypothetical)
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   243
money. What we need to be concerned about is, however, when a
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   244
client artificially increases this counter without having
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   245
visited our web-page. This is actually a trivial task for a
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   246
knowledgeable person, since there are convenient tools that
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   247
allow one to set a cookie to an arbitrary value, for example
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   248
above our threshold for the discount. 
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   249
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   250
There seems to be no real way to prevent this kind of
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   251
tampering with cookies, because the whole purpose of cookies
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   252
is that they are stored on the client's side, which from the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   253
the server's perspective is a potentially hostile environment.
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   254
What we need to ensure is the integrity of this counter in
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   255
this hostile environment. We could think of encrypting the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   256
counter. But this has two drawbacks to do with the key for
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   257
encryption. If you use a single, global key for all the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   258
clients that visit our site, then we risk that our whole
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   259
``business'' might collapse in the event this key gets known
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   260
to the outside world. Then all cookies we might have set in
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   261
the past, can now be decrypted and manipulated. If, on the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   262
other hand, we use many ``private'' keys for the clients, then
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   263
we have to solve the problem of having to securely store this
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   264
key on our server side (obviously we cannot store the key with
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   265
the client because then the client again has all data to
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   266
tamper with the counter; and obviously we also cannot encrypt
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   267
the key, lest we can solve a chicken-and-egg problem). So
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   268
encryption seems to not solve the problem we face with the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   269
integrity of our counter.
169
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   270
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   271
Fortunately, \emph{hash functions} seem to be more suitable
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   272
for our purpose. Like encryption, hash functions scramble data
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   273
in such a way that it is easy to calculate the output of a has
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   274
function from the input. But it is hard (i.e.~practically
175
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   275
impossible) to calculate the input from knowing the output.
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   276
Therefore hash functions are often called \emph{one-way
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   277
functions}. There are several such hashing function. For
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   278
example SHA-1 would hash the string \pcode{"hello world"} to
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   279
produce
175
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   280
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   281
\begin{center}
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   282
\pcode{2aae6c35c94fcfb415dbe95f408b9ce91ee846ed}
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   283
\end{center}
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   284
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   285
\noindent Another handy feature of hash functions is that if
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   286
the input changes only a little, the output changes
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   287
drastically. For example \pcode{"iello world"} produces under
175
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   288
SHA-1 the output
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   289
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   290
\begin{center}
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   291
\pcode{d2b1402d84e8bcef5ae18f828e43e7065b841ff1}
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   292
\end{center}
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   293
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   294
\noindent That means it is not predictable what the output
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   295
will be from just looking at input that is ``close by''. 
175
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   296
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   297
We can use hashes in our web-application and store in the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   298
cookie the value of the counter in plain text but together
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   299
with its hash. We need to store both pieces of data such we
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   300
can extract both components (below I will just separate them
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   301
using a \pcode{"-"}). If we now read back the cookie when the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   302
client visits our webpage, we can extract the counter, hash it
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   303
again and compare the result to the stored hash value inside
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   304
the cookie. If these hashes disagree, then we can deduce that
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   305
the cookie has been tampered with. Unfortunately, if they
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   306
agree, we can still not be entirely sure that not a clever
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   307
hacker has tampered with the cookie. The reason is that the
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   308
hacker can see the clear text part of the cookie, say
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   309
\pcode{3}, and also its hash. It does not take much trial and
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   310
error to find out that we used the SHA-1 hashing functions and
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   311
then graft a cookie accordingly. This is eased by the fact
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   312
that for SHA-1 many strings and corresponding hashvalues are
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   313
precalculated. Type, for example, into Google the hash value
179
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   314
for \pcode{"hello world"} and you will actually pretty quickly
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   315
find that it was generated by input string \pcode{"hello
175
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   316
wolrd"}. This defeats the purpose of a hashing functions and
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   317
thus would not help us for our web-applications. 
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   318
175
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   319
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   320
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   321
There is one ingredient missing, which happens to be called
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   322
\emph{salts}. Salts are random keys, which are added to the
176
5336ad2fd3fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 175
diff changeset
   323
counter before the hash is calculated. In our case we need to
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   324
keep the salt secret. As can be see in Figure~\ref{hashsalt},
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   325
we now need to extract from the cookie the counter value and
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   326
the hash (Lines 19 and 20). But before has the counter again
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   327
(Line 22) we need to add the secret salt. Similarly, when we
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   328
set the new increased counter, we will need to add the salt
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   329
before hashing (this is done in Line 15). Our web-application
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   330
will now store cookies like 
175
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   331
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   332
\begin{figure}[p]
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   333
\lstinputlisting{../progs/App4.js}
176
5336ad2fd3fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 175
diff changeset
   334
\caption{\label{hashsalt}}
175
4ebc97e6fdf0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 174
diff changeset
   335
\end{figure}
169
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   336
179
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   337
\begin{center}\tt
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   338
\begin{tabular}{l}
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   339
1 + salt - 8189effef4d4f7411f4153b13ff72546dd682c69\\
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   340
2 + salt - 1528375d5ceb7d71597053e6877cc570067a738f\\
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   341
3 + salt - d646e213d4f87e3971d9dd6d9f435840eb6a1c06\\
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   342
4 + salt - 5b9e85269e4461de0238a6bf463ed3f25778cbba\\
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   343
...\\
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   344
\end{tabular}
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   345
\end{center}
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   346
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   347
\noindent These hashes allow us to read and set the value of
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   348
the counter and give us confidence that the counter has not
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   349
been tampered with. This of course depends on being able to
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   350
keep the salt secret. 
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   351
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   352
There is an interesting point to note with respect to the New
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   353
York Times' way of checking the number visits. Essentially
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   354
they have their `resource' unlocked at the beginning and lock
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   355
it only when the data in the cookie states the allowed free
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   356
number of visits are up. This can be easily circumvented by
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   357
just deleting the cookie or by switching the browser. This
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   358
would mean the New York Times will loose revenue whenever this
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   359
kind of tampering occurs. In contrast, our web-application has
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   360
the resource (discount) locked at the beginning and only
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   361
unlocks it if the cookie data says so. If the cookie is
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   362
deleted, well then the resource just does not get unlocked.
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   363
No mayor harm will result.
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   364
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   365
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   366
\subsection*{How to Store Passwords}
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   367
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   368
While admittedly silly, the simple web-application in the
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   369
previous section should help with the more important question
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   370
of how passwords should be verified and stored. It is
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   371
unbelievable that nowadays systems still do this with
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   372
passwords in plain text. The idea behind such plain-text
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   373
passwords is of course that if the user typed in \emph{foobar}
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   374
as password, we need to verify whether it matches with the
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   375
password that is stored for this user in the system. But doing
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   376
this verification in plain text is really a bad idea.
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   377
Unfortunately, evidence suggests, however, it is still a
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   378
widespread practice. I leave you to it to think about why
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   379
verifying passwords in plain text is a bad idea.
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   380
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   381
Using hash functions we can do better.
1cacbe5c67cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   382
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   383
%The corresponding attack is called \emph{dictionary
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   384
%attack}\ldots hashes are not reversed by brute force
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   385
%calculations, that is trying out all possible combinations.
169
2866fae8c1cf updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   386
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   387
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   388
%We have to make sure the salt does not get known.
174
e2180cead443 updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   389
178
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   390
13c6bd6e3477 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   391
%Note ....NYT 
158
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
\end{document}
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
%%% Local Variables: 
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
%%% mode: latex
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
%%% TeX-master: t
702fea7754eb added handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   397
%%% End: