(**************************************************************
 *                                                            *
 * This file is modified from ProVerif 2.00.                  *
 *                                                            *
 * ProVerif 2.00 is by                                        *
 *  Bruno Blanchet, Vincent Cheval, and Marc Sylvestre        *
 *  Copyright (C) INRIA, CNRS 2000-2018                       *
 *                                                            *
 * The authors of the changes since ProVerif 2.00 are left    *
 * anonymous for submission to IEEE Security and Privacy 2021 *
 *                                                            *
 **************************************************************)

(*

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details (in file LICENSE).

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*)
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:endBparam(x) ==> evinj:beginBparam(x).
query evinj:endBfull(x,y,z) ==> evinj:beginBfull(x,y,z).

let processA = in(c, hostB0); (* Choose B *)
               event beginBparam(hostB0);
               out(c, hostA);
               in(c,n);
	       event beginBfull(hostA, n, hostB0);
	       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))
