Tamarins are cute, adorable little monkeys which look like this:




Unfortunately, we will not be talking much about tamarins today :(. On the upside, we will be talking about this tamarin (the TAMARIN prover tool, developed by David Basin, Cas Cremers, Jannik Dreier, Simon Meier, Ralf Sasse and Benedikt Schmidt):

The Tamarin Prover is not as good-looking as the mustachioed monkeys above. However, it can perform a very neat trick: given a good model for a security protocol, it will prove its security or provide a flaw.
Now what is a security protocol and why would anyone (beyond some cryptographers) care about proofs for security protocols? I’ll admit, as a hardware engineer, I was very close to napping at the very start of the lecture.
Protocol basics (skip this if you know basic cryptography)
Let’s therefore start with the basics. According to my Introduction to Cryptography course, “A (cryptographic) protocol is a multi-party algorithm, defined by a sequence of steps precisely specifying the actions required of two or more parties in order to achieve a specified objective”.
That’s a very broad definition! It means lots of communications are protocols! When you put your bank card in a terminal, there’s a protocol with your card, the terminal and the bank as parties.
Session keys? Why do we care? (Symmetric Key Cryptography)
The specified objective in the examples I saw was usually “establishing a session key”. What is a session key? Well, imagine it’s WW2, and you’re a brave member of the resistance. You need to let the Royal Air Force in London know that the Gestapo has put its headquarters in a building in Brussels. But of course, you don’t want the Gestapo to read your messages. Else they might move their headquarters before the RAF gets a chance to strafe them.

So how do you communicate without them eavesdropping on you? You need some way of turning your messages into seemingly random noise. For this you use a “cryptographic” key. A key in this case is just a short series of bits (or in the case of WW2, a big booklet full of letters) which you can use (in various ways) to turn the message “GESTAPPO MOVED HEADQUARTERS TO 453 AVENUE LOUISE BRUSSELS” into something like “RELSBXQWQUDNJIDFUAAPGOSVNFABXCCYLYPWDMLCXDBUMDE”.
One big problem with keys: you need to agree on them beforehand, or you need some way to send them. If London doesn’t have your key, then you might as well try to shout your information across the Channel. (Because they are receiving “RELSB…BUMDE”, which is nonsense without the key). So, we need a protocol to establish a key. We call this a “session” key because it’s a good idea to get a new key every time we start a new chat “session”.
Ok fine, we’ll send our key to London first, then we’ll send the rest of our message… oh wait. If we are able to send our key safely, we might as well just send the whole message. The Gestapo is listening in! If they hear our key, they can decrypt our message!
Public Key Encryption
Luckily there is something out there called a “public encryption scheme” where, if London publishes its “public key”, anyone can safely send keys to them. This “public key” is known to everyone, including the Gestapo, but it is only useful if you want to turn messages into random noise. The public key cannot be used to turn the random noise back into a message. Only London can turn the random noise back into the message because they have something called a “secret key”.

Think of it as follows: I own a locker at my local swimming pool. I want anyone to be able to send me stuff securely, so I post the number of this locker on my Twitter and leave the locker door open, putting the key in my pocket.

Anyone with this number (i.e., anyone who saw my twitter message, which is everyone in the world approximately) can now send me messages. This number is basically my “public key”. The locker door key is my “private key”. It guarantees that I’m the only person capable of opening the locker and receiving what was put in the locker.
There’s an obvious problem with this system. Anything sent to me has to fit in the locker, which is rather small. Public key encryption has the same problem, but instead of too little space, you have the problem of doing too many calculations to send even short messages.
So, instead of asking people send their full message using this system, I only want them to send the “session key”, i.e., the small piece of information that we can use to turn messages both into pieces of seemingly random noise and back again. Then we’re in business! Only the people with this “session key” can communicate, and communication with the session key is much faster than bothering with the locker system all the time, so we only have to use the locker system (i.e., public key cryptography) at the start, and then we can just use our session key for communicating.
How this “public key cryptography” works in practice will not be explained here, but for now, just remember that I (from now on I shall be known as “Alice”) have access to London’s public key (who from now is known under the pseudonym “Bob”). This is basically the same as if I/Alice know London/Bob’s locker number. In the same way, London/Bob has access to my personal public key (=locker number). I/Alice can put stuff in London’s locker, but I/Alice cannot get stuff out.
Similarly, London/Bob can put stuff in my/Alice’s locker (i.e., they can send me short messages which look like random noise but actually contain useful information) but they cannot retrieve whatever they’ve put in it (i.e., they cannot turn this seemingly random noise back into their original message, they would need Alice’s/my help).
Real protocols
So, what’s an example of a protocol? Take a look at the following:

(From now on, Alice will be sitting on the left, and Bob will be sitting on the right). Alice has Bob’s Public Key Pb which Alice has found received from Bob beforehand, this public key has been derived by Bob from Bob’s secret key SB and these steps have been done before the protocol starts.
The protocol itself has only one step: Alice uses Bob’s public key to encrypt a session key which she wishes to use. She then sends Bob the encrypted session key (she also appends a timestamp to the session key, so that Bob will know when she sent the key).
This seems like a perfectly simple and logical algorithm, right? Alice has Bob’s public key but wants to have the advantages of symmetric key cryptography, so rather than encrypting all her data using Bob’s public key, she only sends him her session key (plus timestamp). Once Bob’s receives the session key, he and Alice are the only one holding the session key (assuming Alice hasn’t leaked information). Alice knows only Bob could be holding the session key, because only Bob could have decrypted Alice’s encrypted secret key (+ timestamp) EPB (k||t). After all, we are (for now) assuming only Bob will ever hold Bob’s private key.
Given this, surely they can communicate securely, right? What could possibly go wrong with such a simple algorithm? Well, anyone could pretend to be Alice, and send Bob a session key. Bob has no way of knowing who is sending him session keys. Alice knows that only Bob could have found the session key but she has no way of knowing whether Bob actually received the session key, because Bob hasn’t sent anything back.
To go back to our example: The Gestapo (from now on known as “Eve”) can pretend to be a resistance fighter to London/Bob and offer “the latest information” on German troop movements, if only London/Bob accepts their session key as coming from a valid source. Since London/Bob does not know who they are talking too, any information sent to them using this session key is effectively useless without some external way to confirm that the session key they just received was valid. In brief, they don’t know whether they are talking to the right person. They need authentication.
Ok, fine: let’s fix this:

Now, both Alice and Bob need to have each other’s public keys. If we assume this is true, Alice can send Bob k1, concatenated with her name (encrypted under Bob’s public key). Bob then sends k1 concatenated with k2 (encrypted under Alice’s public key). Finally, Alice sends k2 back (encrypted under Bob’s public key). Both parties can now calculate the session key k using k1 and k2.
Both sides now have implicit key authentication: they know that only the other party could have received the full session key. They also know that the other side has the required ingredients to calculate the session key (but they don’t actually know whether the hash has been calculated). Additionally, both sides have some control over how the key is generated: by changing k1, Alice can change the session key, and Bob can do the same thing by changing k2. Key control for both sides is a nice feature since now both sides can avoid key reuse if they choose to. Ensuring keys are not reused is in turn important to prevent the leaking of a session key from compromising future communication.
To go back to our example: it’s possible that the Gestapo/Eve captures one of the keys we used for communication. Luckily for us, we (Alice) have been smart, and we have used these keys as “session keys”, so since we use a new key for every session, the Gestapo/Eve doesn’t actually gain anything. However, just like people reusing passwords, there are plenty of lazy resistance fighters who always use the same key. The nice thing about this protocol is that it allows London/Bob to ensure that the “session key” is never the same.
Ok, so it seems that this protocol has many nice features. Surely this is secure?

Consider the above. (The devil in the middle is Eve). Eve starts communicating with Alice and identifies herself honestly as Eve. Meanwhile, she also starts communicating with Bob, and identifies herself falsely as Alice. Bob happily sends the session keys encrypted under Alice’s public keys to Eve. Eve can’t use these, but she can pass them on to Alice, who will send back Bob’s k2. Eve finishes communicating with Bob, because she wants Bob to believe that he has successfully started a session with Alice using k=hash(k1||k2). In reality, his session key k is not secure at all, because he has been talking to Eve this whole time!
The Needham Schroeder protocol was published in 1978. It was taught in university courses and widely studied. The flaw described above was however only found in 1995! While the protocol looked secure, it was not, and it took 17 years before people noticed!
Enter the Tamarin
The Tamarin prover is a program which allows a given protocol to be modeled and verified. This effectively means that Tamarin will look for flaws in the protocol, and if it doesn’t find any, will try to prove that the protocol is secure.
You absolutely want this proof, because as we’ve just seen, just “looking over” the protocol is not enough. This solver treats the system as going through a series of states and tries to find out whether the attacker can extract any useful information it shouldn’t have as the protocol plays out.
Bank Robbery time
Now that we have this prover installed on our computers, robbing banks will be a breeze. The research group which developed Tamarin made an attempt to find vulnerabilities in the EMV standard, which is the international protocol standard for smartcard payment.
The EMV standard is quite long (2000 pages) and has a lot of parameters (which means there’s a lot of variation possible in how the protocol is implemented). At its most basic, there are three parties: the Card, the Terminal and the Bank. The attack focused on contactless payment, using a relay attack (where messages from the protocol are sent on without the original party’s knowledge).
Now you might think: surely if all this is so complex, no criminal is really going to bother? On the contrary! In 2010-2011, 600 000 euros worth of fraudulent transactions were carried out using man in the middle attacks. To do this, the criminals either looked up a paper published in 2010 (or found the vulnerability independently).


If protocols flaws can allow criminals to use cards without PIN’s, clearly these protocols have to be fixed. Therefore, the authors went through the trouble of modeling EMV in Tamarin. After letting Tamarin go over the possibilities, they found a fatal flaw: the verification method which is used is not authenticated. In other words, you can make an Android app which tells the terminal not to worry about PIN verification because the transaction is performed on the consumer’s device. Effectively, from the card’s point of view, an online PIN is required, but from the terminal’s point of view, a consumer device is used (such as a phone). This makes life even easier for criminals than the attack described above: they no longer have to bother with soldering one chip on top of another, simply writing an android app suffices.
The EMV attack on Visa

First, our attackers steal a credit card. Now that they’ve stolen this, they use two Android phones. The one closest to the card is used as Point-Of-Sale emulator. In other words, it pretends to be a terminal. The one closest to the terminal acts as a card emulator. In other words, it pretends to be a card.
The fatal flaw in the protocol, is that when the terminal asks information about how the transaction will proceed, there is no way for the terminal to tell whether the response came from the card or from a middleman. Therefore the middleman can just claim that “no, you do not need a pin code for this transaction”, and the terminal will believe this. So, while the card is telling the terminal “I’m going to do PIN verification”, the terminal instead hears “we’re doing a high-value contactless payment”. The research team showed a working attack in this video (scroll down).
Conclusion
Luckily for Visa, and the world at large, the people behind Tamarin have only good intentions and let Visa know about the various flaws in the EMV protocol (there were multiple). The Tamarin Prover is freely available and can be used by anyone to check their own protocols for flaws. People designing protocols therefore have no excuse not to verify their protocols. In this way, Tamarin makes the world a safer place.



