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.


authquery Aparam/1.
authquery Akey/3.
authquery Bparam/1.
authquery Bkey/3.

let processA = in(c, hostB0);
	       begin Bparam(hostB0);
	       new C; new Na;
               out(c, (C, hostA, hostB0, encrypt((Na, C, hostA, hostB0), kA)));
	       in(c, m);
	       let (C2, m2) = m in
	       if C2 = C then
		  let (Na2, k) = decrypt(m2, kA) in
		  begin Bkey(hostA, hostB0, k);
		  if Na2 = Na then
		     (* OK *)
		     if hostB0 = hostB then 
                       end Aparam(hostA);
		       end Akey(hostA, hostB0, k).


let processB = in(c, m);
	       let (C1, hostA1, hostB1, m2) = m in
	       begin Aparam(hostA1);
               if hostB1 = hostB then
		  new Nb;
		  out(c, (C1, hostA1, hostB1, m2, 
		          encrypt((Nb, C1, hostA1, hostB1), kB)));
		  in(c, m);
                  let (C2, m3, m4) = m in
                  if C2 = C1 then
	             let (Nb2, k) = decrypt(m4, kB) in
		     begin Akey(hostA1, hostB, k);
                     if Nb2 = Nb then
		        out(c, (C2, m3));
			(* OK *)
			if hostA1 = hostA then
			  end Bparam(hostB);
			  end Bkey(hostA1, hostB, k).


let processS = in(c, m);
	       let (C1, hostA1, hostB1, m2, m3) = m in
	       let (Na1, C2, hostA2, hostB2) = decrypt(m2, getkey(hostA1)) in
	       let (Nb1, C3, hostA3, hostB3) = decrypt(m3, getkey(hostB1)) in
	       if hostA1 = hostA2 then
	       if hostA1 = hostA3 then
               if hostB1 = hostB2 then
               if hostB1 = hostB3 then
	       if C1 = C2 then
               if C1 = C3 then
	       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))
