free c.
(* Otway Rees protocol.
   Version of Otway Rees, Operating Systems Review Vol 21 no 1, p 8-10, 1987 

A -> B: (C, A, B, { Na, C, A, B }_kA)
B -> S: (C, A, B, { Na, C, A, B }_kA, { Nb, C, A, B }_kB)
S -> B: (C, { Na, k }_kA, { Nb, k }_kB)
B -> A: (C, { Na, k }_kA)

Correct

Full agreement is wrong, the adversary can make B see something else as
{ Na, C, A, B }_kA, but it is not a real attack.

The protocol should rather be written:
A -> B,S: C, A, B
A -> S: { Na, C, A, B }_kA
B -> S: { Nb, C, A, B }_kB
S -> A: { Na, k }_kA
S -> B: { Nb, k }_kB

Bparam injective agreement is wrong:
A -> B: (C, A, B, { Na, C, A, B }_kA)
B -> S: (C, A, B, { Na, C, A, B }_kA, { Nb, C, A, B }_kB)
S -> B: (C, { Na, k }_kA, { Nb, k }_kB)
B -> A: (C, { Na, k }_kA)

I -> B: (C, A, B, { Na, C, A, B }_kA)
B -> S: (C, A, B, { Na, C, A, B }_kA, { Nb', C, A, B }_kB)
S -> B: (C, { Na, k' }_kA, { Nb', k' }_kB)
B ->  : (C, { Na, k' }_kA)

Moreover, A and B can get different keys k ! 
(Strand spaces: Proving Security Protocols Correct, 
Thayer, Herzog, Gutmman, JCS 99, p 36)
ThayerFabregaHerzogGuttman-JCS1999.ps.gz

A -> B: (C, A, B, { Na, C, A, B }_kA)
B -> S: (C, A, B, { Na, C, A, B }_kA, { Nb, C, A, B }_kB)
S -> B: (C, { Na, k }_kA, { Nb, k }_kB)  ===> B has key k
I -> S: (C, A, B, { Na, C, A, B }_kA, { Nb, C, A, B }_kB)
S -> I: (C, { Na, k' }_kA, { Nb, k' }_kB)
I -> A: (C, { Na, k' }_kA)               ===> A has key k'

*)

(* Shared-key cryptography *)

fun encrypt/2.
reduc decrypt(encrypt(m,k),k) = m.

(* Host name / key *)

fun host/1.
private reduc getkey(host(x)) = x.

(* Secrecy assumptions *)

not kA.
not kB.

private free secretA, secretB.
query attacker:secretA;
      attacker:secretB.
query evinj:endAparam(x) ==> evinj:beginAparam(x).
query evinj:endAkey(x,y,z) ==> evinj:beginAkey(x,y,z).
query evinj:endBparam(x) ==> evinj:beginBparam(x).
query evinj:endBkey(x,y,z) ==> evinj:beginBkey(x,y,z).

let processA = 
	in(c, hostB0);
	event beginBparam(hostB0);
	new C; new Na;
        out(c, (C, hostA, hostB0, encrypt((Na, C, hostA, hostB0), kA)));
	in(c, (=C, m2));
	let (=Na, k) = decrypt(m2, kA) in
	event beginBkey(hostA, hostB0, k);
	(* OK *)
	if hostB0 = hostB then 
        event endAparam(hostA);
	event endAkey(hostA, hostB0, k);
	out(c, encrypt(secretA, k)).


let processB = 
	in(c, (C1, hostA1, =hostB, m2));
	event beginAparam(hostA1);
	new Nb;
	out(c, (C1, hostA1, hostB, m2, encrypt((Nb, C1, hostA1, hostB), kB)));
	in(c, (=C1, m3, m4));
	let (=Nb, k) = decrypt(m4, kB) in
	event beginAkey(hostA1, hostB, k);
	out(c, (C1, m3));
	(* OK *)
	if hostA1 = hostA then
	event endBparam(hostB);
	event endBkey(hostA1, hostB, k);
	out(c, encrypt(secretB, k)).


let processS = in(c, (C1, hostA1, hostB1, m2, m3));
	       let (Na1, =C1, =hostA1, =hostB1) = decrypt(m2, getkey(hostA1)) in
	       let (Nb1, =C1, =hostA1, =hostB1) = decrypt(m3, getkey(hostB1)) in
	       new k;
               out(c, (C1, encrypt((Na1, k), getkey(hostA1)), 
                           encrypt((Nb1, k), getkey(hostB1)))).


process new kA; new kB;
	let hostA = host(kA) in 
	let hostB = host(kB) in
	out(c, hostA); out(c, hostB);
	((!processA) | (!processB) | (!processS))

(* EXPECTPV
RESULT not attacker:secretA[] is true.
RESULT not attacker:secretB[] is true.
RESULT evinj:endAparam(x) ==> evinj:beginAparam(x) is true.
RESULT evinj:endAkey(x,y,z) ==> evinj:beginAkey(x,y,z) is false.
RESULT (even ev:endAkey(x,y,z) ==> ev:beginAkey(x,y,z) is false.)
RESULT evinj:endBparam(x) ==> evinj:beginBparam(x) is false.
RESULT (but ev:endBparam(x) ==> ev:beginBparam(x) is true.)
RESULT evinj:endBkey(x,y,z) ==> evinj:beginBkey(x,y,z) is false.
RESULT (even ev:endBkey(x,y,z) ==> ev:beginBkey(x,y,z) is false.)
0.112s (user 0.068s + system 0.044s), max rss 9756K
END *)
