(* The system proves the correspondence, as desired *)


free c.
(*

Woo and Lam public-key auth protocol (1997)

A -> B: A
B -> A: N
A -> B: { A, B, N }_skA
B -> S: A
S -> B: A, { A, pkA }_skS

Correct

*)

(* Signatures *)

fun pk/1.
fun sign/2.
reduc getmess(sign(m,k)) = m.
reduc checksign(sign(m,k), pk(k)) = m.

(* Host name / key *)

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

(* Secrecy assumptions *)

not skA.
not skB.
not skS.

query evinj:endBfull(x,y,z) ==> evinj:beginBfull(x,y,z,y) | evinj:beginBfull(x,y,z,z).

let processA = in(c, hostB0); (* Choose B *)
               event beginBparam(hostB0);
               out(c, hostA);
               in(c,(n,n2));
	       event beginBfull(hostA, n, hostB0, n2);
		if n2 = n then
	       out(c,sign((hostA, hostB0, n),skA))
		else if n2 = hostB0 then
	       out(c, sign((hostA, hostB0, n), skA)).

let processB = in(c, hostA0);
               new n; out(c,n);
               in(c,m); 
               out(c, hostA0);
               in(c, (=hostA0, m4)); 
                  let (=hostA0, pkA2) = checksign(m4, pkS) in
                     let (=hostA0, =hostB, =n) = checksign(m,pkA2) in
			(* OK *)
                        if hostA0 = hostA then
			  event endBparam(hostB);
			  event endBfull(hostA0, n, hostB).

let processS = in(c, hostA);
	       out(c, (hostA, sign((hostA, getkey(hostA)), skS))).

process new skA; new skB; new skS;
        let pkA = pk(skA) in
        let pkB = pk(skB) in
        let pkS = pk(skS) in
	let hostA = host(pkA) in
	let hostB = host(pkB) in
	out(c, pkA); out(c, pkB); out(c, pkS);
	out(c, hostA); out(c, hostB);
	((!processA) | (!processB) | (!processS))
