85 properly, and also the motive that the attackers have to try |
85 properly, and also the motive that the attackers have to try |
86 to defeat your policy). The last point is often overlooked, |
86 to defeat your policy). The last point is often overlooked, |
87 but plays an important role. To illustrate this lets look at |
87 but plays an important role. To illustrate this lets look at |
88 an example. |
88 an example. |
89 |
89 |
90 The questions is whether the Chip-and-PIN system with credit |
90 \subsubsection*{Chip-and-PIN is Surely More Secure?} |
91 cards is more secure than the older method of signing receipts |
91 |
92 at the till. On first glance Chip-and-PIN seems obviously more |
92 The questions is whether the Chip-and-PIN system used with |
93 secure and improved security was also the central plank in the |
93 modern credit cards is more secure than the older method of |
94 ``marketing speak'' of the banks behind Chip-and-PIN. The |
94 signing receipts at the till. On first glance the answer seems |
95 earlier system was based on a magnetic stripe or a mechanical |
95 obvious: Chip-and-PIN must be more secure and indeed improved |
96 imprint on the card and required customers to sign receipts at |
96 security was the central plank in the ``marketing speak'' of |
97 the till whenever they bought something. This signature |
97 the banks behind Chip-and-PIN. The earlier system was based on |
98 authorised the transactions. Although in use for a long time, |
98 a magnetic stripe or a mechanical imprint on the cards and |
99 this system had some crucial security flaws, including making |
99 required customers to sign receipts at the till whenever they |
100 clones of credit cards and forging signatures. |
100 bought something. This signature authorised the transactions. |
|
101 Although in use for a long time, this system had some crucial |
|
102 security flaws, including making clones of credit cards and |
|
103 forging signatures. |
101 |
104 |
102 Chip-and-PIN, as the name suggests, relies on data being |
105 Chip-and-PIN, as the name suggests, relies on data being |
103 stored on a chip on the card and a PIN number for |
106 stored on a chip on the card and a PIN number for |
104 authorisation. Even though the banks involved trumpeted their |
107 authorisation. Even though the banks involved trumpeted their |
105 system as being absolutely secure and indeed fraud rates |
108 system as being absolutely secure and indeed fraud rates |
106 initially went down, security researchers were not convinced |
109 initially went down, security researchers were not convinced |
107 (especially the group around Ross Anderson). To begin with, |
110 (especially the group around Ross Anderson). To begin with, |
108 the Chip-and-PIN system introduced a ``new player'' that |
111 the Chip-and-PIN system introduced a ``new player'' that |
109 needed to be trusted: the PIN terminals and their |
112 needed to be trusted: the PIN terminals and their |
110 manufacturers. It was claimed that these terminals are |
113 manufacturers. It was claimed that these terminals were |
111 tamper-resistant, but needless to say this was a weak link in |
114 tamper-resistant, but needless to say this was a weak link in |
112 the system, which criminals successfully attacked. Some |
115 the system, which criminals successfully attacked. Some |
113 terminals were even so skilfully manipulated that they |
116 terminals were even so skilfully manipulated that they |
114 transmitted skimmed PIN numbers via built-in mobile phone |
117 transmitted skimmed PIN numbers via built-in mobile phone |
115 connections. To mitigate this flaw in the security of |
118 connections. To mitigate this flaw in the security of |
116 Chip-and-PIN, you need to vet quite closely the supply chain |
119 Chip-and-PIN, you need to vet quite closely the supply chain |
117 of such terminals. |
120 of such terminals. |
118 |
121 |
119 Later on Ross Anderson and his group managed to launch a |
122 Later on Ross Anderson and his group were able to perform |
120 man-in-the-middle attacks against Chip-and-PIN. Essentially |
123 man-in-the-middle attacks against Chip-and-PIN. Essentially |
121 they made the terminal think the correct PIN was entered and |
124 they made the terminal think the correct PIN was entered and |
122 the card think that a signature was used. This was a more |
125 the card think that a signature was used. This is a kind of |
123 serious security problem. The flaw was mitigated by requiring |
126 \emph{protocol failure}. After discovery, the flaw was |
124 that a link between the card and the bank is established at |
127 mitigated by requiring that a link between the card and the |
125 every time the card is used. Even later this group found |
128 bank is established at every time the card is used. Even later |
126 another problem with Chip-and-PIN and ATMs which do not |
129 this group found another problem with Chip-and-PIN and ATMs |
127 generate random enough numbers (nonces) on which the security |
130 which did not generate random enough numbers (nonces) on which |
128 of the underlying protocols relies. |
131 the security of the underlying protocols relies. |
129 |
132 |
130 The problem with all this is that the banks who introduced |
133 The problem with all this is that the banks who introduced |
131 Chip-and-PIN managed with the new system to shift the |
134 Chip-and-PIN managed with the new system to shift the |
132 liability for any fraud and the burden of proof onto the |
135 liability for any fraud and the burden of proof onto the |
133 customer. In the old system, the banks had to prove that the |
136 customer. In the old system, the banks had to prove that the |
154 This is a classic example where a security design principle |
157 This is a classic example where a security design principle |
155 was violated: Namely, the one who is in the position to |
158 was violated: Namely, the one who is in the position to |
156 improve security, also needs to bear the financial losses if |
159 improve security, also needs to bear the financial losses if |
157 things go wrong. Otherwise, you end up with an insecure |
160 things go wrong. Otherwise, you end up with an insecure |
158 system. In case of the Chip-and-PIN system, no good security |
161 system. In case of the Chip-and-PIN system, no good security |
159 engineer would claim that it is secure beyond reproach: the |
162 engineer would dare claim that it is secure beyond reproach: |
160 specification of the EMV protocol (underlying Chip-and-PIN) is |
163 the specification of the EMV protocol (underlying |
161 some 700 pages long, but still leaves out many things (like |
164 Chip-and-PIN) is some 700 pages long, but still leaves out |
162 how to implement a good random number generator). No human |
165 many things (like how to implement a good random number |
163 being is able to scrutinise such a specification and ensure it |
166 generator). No human being is able to scrutinise such a |
164 contains no flaws. Moreover, banks can add their own |
167 specification and ensure it contains no flaws. Moreover, banks |
165 sub-protocols to EMV. With all the experience we already have, |
168 can add their own sub-protocols to EMV. With all the |
166 it is as clear as day that criminals were eventually able to |
169 experience we already have, it is as clear as day that |
167 poke holes into it and measures need to be taken to address |
170 criminals were eventually able to poke holes into it and |
168 them. However, with how the system was set up, the banks had |
171 measures need to be taken to address them. However, with how |
169 no real incentive to come up with a system that is really |
172 the system was set up, the banks had no real incentive to come |
170 secure. Getting the incentives right in favour of security is |
173 up with a system that is really secure. Getting the incentives |
171 often a tricky business. |
174 right in favour of security is often a tricky business. From a |
|
175 customer point of view the system was much less secure than |
|
176 the old signature-based method. |
172 |
177 |
173 \subsection*{Of Cookies and Salts} |
178 \subsection*{Of Cookies and Salts} |
174 |
179 |
175 Lets look at another example which should helps with |
180 Lets look at another example which will help with |
176 understanding how passwords should be verified and stored. |
181 understanding how passwords should be verified and stored. |
177 Imagine you need to develop a web-application that has the |
182 Imagine you need to develop a web-application that has the |
178 feature of recording how many times a customer visits a page. |
183 feature of recording how many times a customer visits a page. |
179 For example to give a discount whenever the customer visited a |
184 For example in order to give a discount whenever the customer |
180 webpage some $x$ number of times (say $x$ equal $5$). There is |
185 visited a webpage some $x$ number of times (say $x$ equal |
181 one more constraint: we want to store the information about |
186 $5$). There is one more constraint: we want to store the |
182 the number of times a customer has visited inside a cookie. I |
187 information about the number of visits as a cookie on the |
183 think, for a number of years the webpage of the New York Times |
188 browser. I think, for a number of years the webpage of the New |
184 operated in this way: it allowed you to read ten articles per |
189 York Times operated in this way: it allowed you to read ten |
185 months for free; if you wanted to read more, you had to pay. |
190 articles per month for free; if you wanted to read more, you |
186 My guess is it used cookies for recording how many times their |
191 had to pay. My best guess is that it used cookies for |
187 pages was visited, because if you switched browsers you could |
192 recording how many times their pages was visited, because if I |
188 easily circumvent the restriction about ten articles. |
193 switched browsers I could easily circumvent the restriction |
|
194 about ten articles. |
189 |
195 |
190 To implement our web-application it is good to look under the |
196 To implement our web-application it is good to look under the |
191 hood what happens when a webpage is requested. A typical |
197 hood what happens when a webpage is displayed in a browser. A |
192 web-application works as follows: The browser sends a GET |
198 typical web-application works as follows: The browser sends a |
193 request for a particular page to a server. The server answers |
199 GET request for a particular page to a server. The server |
194 this request. A simple JavaScript program that realises a |
200 answers this request with a webpage in HTML (we can here |
195 ``hello world'' webpage is as follows: |
201 ignore these details). A simple JavaScript program that |
|
202 realises a ``hello world'' webpage is as follows: |
196 |
203 |
197 \begin{center} |
204 \begin{center} |
198 \lstinputlisting{../progs/ap0.js} |
205 \lstinputlisting{../progs/ap0.js} |
199 \end{center} |
206 \end{center} |
200 |
207 |
201 \noindent The interesting lines are 4 to 7 where the answer to |
208 \noindent The interesting lines are 4 to 7 where the answer to |
202 the GET request is generated\ldots in this case it is just a |
209 the GET request is generated\ldots in this case it is just a |
203 simple string. This program is run on the server and will be |
210 simple string. This program is run on the server and will be |
204 executed whenever a browser initiates such a GET request. |
211 executed whenever a browser initiates such a GET request. You |
|
212 can run this program on your computer and then direct a |
|
213 browser to the address \pcode{localhost:8000} in order to |
|
214 simulate a request over the internet. |
|
215 |
205 |
216 |
206 For our web-application of interest is the feature that the |
217 For our web-application of interest is the feature that the |
207 server when answering the request can store some information |
218 server when answering the request can store some information |
208 at the client's side. This information is called a |
219 on the client's side. This information is called a |
209 \emph{cookie}. The next time the browser makes another GET |
220 \emph{cookie}. The next time the browser makes another GET |
210 request to the same webpage, this cookie can be read by the |
221 request to the same webpage, this cookie can be read again by |
211 server. We can use cookies in order to store a counter that |
222 the server. We can use cookies in order to store a counter |
212 records the number of times our webpage has been visited. This |
223 that records the number of times our webpage has been visited. |
213 can be realised with the following small program |
224 This can be realised with the following small program |
214 |
225 |
215 \begin{center} |
226 \begin{center} |
216 \lstinputlisting{../progs/ap2.js} |
227 \lstinputlisting{../progs/ap2.js} |
217 \end{center} |
228 \end{center} |
218 |
229 |
237 client's browser (which is not under our control). Depending |
248 client's browser (which is not under our control). Depending |
238 on this value we want to unlock a resource (like a discount) |
249 on this value we want to unlock a resource (like a discount) |
239 when it reaches a threshold. If the client deletes the cookie, |
250 when it reaches a threshold. If the client deletes the cookie, |
240 then the counter will just be reset to zero. This does not |
251 then the counter will just be reset to zero. This does not |
241 bother us, because the purported discount will just not be |
252 bother us, because the purported discount will just not be |
242 granted. In this way we do not lose us any (hypothetical) |
253 granted. In this way we do not lose any (hypothetical) money. |
243 money. What we need to be concerned about is, however, when a |
254 What we need to be concerned about is, however, when a client |
244 client artificially increases this counter without having |
255 artificially increases this counter without having visited our |
245 visited our web-page. This is actually a trivial task for a |
256 web-page. This is actually a trivial task for a knowledgeable |
246 knowledgeable person, since there are convenient tools that |
257 person, since there are convenient tools that allow one to set |
247 allow one to set a cookie to an arbitrary value, for example |
258 a cookie to an arbitrary value, for example above our |
248 above our threshold for the discount. |
259 threshold for the discount. |
249 |
260 |
250 There seems to be no real way to prevent this kind of |
261 There seems to be no real way to prevent this kind of |
251 tampering with cookies, because the whole purpose of cookies |
262 tampering with cookies, because the whole purpose of cookies |
252 is that they are stored on the client's side, which from the |
263 is that they are stored on the client's side, which from the |
253 the server's perspective is a potentially hostile environment. |
264 the server's perspective is a potentially hostile environment. |
294 \noindent That means it is not predictable what the output |
305 \noindent That means it is not predictable what the output |
295 will be from just looking at input that is ``close by''. |
306 will be from just looking at input that is ``close by''. |
296 |
307 |
297 We can use hashes in our web-application and store in the |
308 We can use hashes in our web-application and store in the |
298 cookie the value of the counter in plain text but together |
309 cookie the value of the counter in plain text but together |
299 with its hash. We need to store both pieces of data such we |
310 with its hash. We need to store both pieces of data in such a |
300 can extract both components (below I will just separate them |
311 way that we can extract both components (below I will just |
301 using a \pcode{"-"}). If we now read back the cookie when the |
312 separate them using a \pcode{"-"}). If we now read back the |
302 client visits our webpage, we can extract the counter, hash it |
313 cookie when the client visits our webpage, we can extract the |
303 again and compare the result to the stored hash value inside |
314 counter, hash it again and compare the result to the stored |
304 the cookie. If these hashes disagree, then we can deduce that |
315 hash value inside the cookie. If these hashes disagree, then |
305 the cookie has been tampered with. Unfortunately, if they |
316 we can deduce that the cookie has been tampered with. |
306 agree, we can still not be entirely sure that not a clever |
317 Unfortunately, if they agree, we can still not be entirely |
307 hacker has tampered with the cookie. The reason is that the |
318 sure that not a clever hacker has tampered with the cookie. |
308 hacker can see the clear text part of the cookie, say |
319 The reason is that the hacker can see the clear text part of |
309 \pcode{3}, and also its hash. It does not take much trial and |
320 the cookie, say \pcode{3}, and also its hash. It does not take |
310 error to find out that we used the SHA-1 hashing functions and |
321 much trial and error to find out that we used the SHA-1 |
311 then graft a cookie accordingly. This is eased by the fact |
322 hashing functions and then the hacker can graft a cookie |
312 that for SHA-1 many strings and corresponding hashvalues are |
323 accordingly. This is eased by the fact that for SHA-1 many |
313 precalculated. Type, for example, into Google the hash value |
324 strings and corresponding hash-values are precalculated. Type, |
314 for \pcode{"hello world"} and you will actually pretty quickly |
325 for example, into Google the hash value for \pcode{"hello |
315 find that it was generated by input string \pcode{"hello |
326 world"} and you will actually pretty quickly find that it was |
316 wolrd"}. This defeats the purpose of a hashing functions and |
327 generated by input string \pcode{"hello wolrd"}. This defeats |
317 thus would not help us for our web-applications. |
328 the purpose of a hashing functions and thus would not help us |
|
329 for our web-applications. |
318 |
330 |
319 |
331 |
320 |
332 |
321 There is one ingredient missing, which happens to be called |
333 There is one ingredient missing, which happens to be called |
322 \emph{salts}. Salts are random keys, which are added to the |
334 \emph{salts}. Salts are random keys, which are added to the |